1
/***********************************************************************
3
Copyright (c) 2001-2004 Fritz Ganter <ganter@ganter.at>
5
Website: www.gpsdrive.de
7
Disclaimer: Please do not use for navigation.
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
*********************************************************************
25
$Log: gpsnasamap.c,v $
26
Revision 1.15 2004/02/08 17:16:25 ganter
27
replacing all strcat with g_strlcat to avoid buffer overflows
29
Revision 1.14 2004/02/08 16:35:10 ganter
30
replacing all sprintf with g_snprintf to avoid buffer overflows
32
Revision 1.13 2004/02/06 22:29:24 ganter
33
updated README and man page
35
Revision 1.12 2004/02/04 14:47:10 ganter
36
added GPGSA sentence for PDOP (Position Dilution Of Precision).
38
Revision 1.11 2004/02/03 07:11:21 ganter
39
working on problems if gpsdrive is not installed
41
Revision 1.10 2004/02/01 22:48:01 ganter
42
added output to gpsnasamap.c
44
Revision 1.9 2004/02/01 05:24:59 ganter
45
missing nasamaps should now really work!
46
upload again 2.08pre9!
48
Revision 1.8 2004/02/01 05:10:12 ganter
49
fixed bug if 1 nasamap is missing
51
Revision 1.7 2004/02/01 01:57:03 ganter
52
it seems that nasamaps now working fine
54
Revision 1.6 2004/01/31 14:48:03 ganter
57
Revision 1.5 2004/01/31 13:43:57 ganter
58
nasamaps are working better, but still bugs
60
Revision 1.4 2004/01/31 08:27:22 ganter
61
i hope the nasa maps work all over the world
62
I expect it works not in australia, will see after i get a little bit sleep
64
Revision 1.3 2004/01/31 06:24:21 ganter
65
nasa maps at lon=0 works now
67
Revision 1.2 2004/01/31 04:16:49 ganter
70
Revision 1.1 2004/01/31 04:11:01 ganter
71
oh, forgot to add to CVS
73
Revision 1.1 2004/01/30 22:20:44 ganter
74
convnasamap creates mapfiles from the big nasa map files
79
#include <sys/types.h>
89
/* Defines for gettext I18n */
91
# define _(String) gettext(String)
93
# define N_(String) gettext_noop(String)
95
# define N_(String) (String)
98
static char mybuffer[10000];
99
extern char homedir[500], mapdir[500];
100
extern GtkWidget *mainwindow;
101
static GtkWidget *nasawindow = NULL;
103
static int fdin_w, fdin_e;
104
static char outfilename[100], inputfilename_e[255], inputfilename_w[255];
105
static int havenasamaps;
110
havenasamaps = FALSE;
112
if (mapdir[strlen (mapdir) - 1] != '/')
113
g_strlcat (mapdir, "/", sizeof(mapdir));
116
g_snprintf (outfilename, sizeof (outfilename), "%stop_NASA_IMAGE.ppm",
119
g_snprintf (inputfilename_e, sizeof (inputfilename_e),
120
"%snasamaps/top_nasamap_east.raw", homedir);
122
g_snprintf (inputfilename_w, sizeof (inputfilename_w),
123
"%snasamaps/top_nasamap_west.raw", homedir);
125
fdin_e = open (inputfilename_e, O_RDONLY);
128
fdin_w = open (inputfilename_w, O_RDONLY);
136
cleanup_nasa_mapfile ()
145
create_nasa_mapfile (double lat, double lon, int test, char *fn)
147
/* lat,lon= koordinates */
148
/* test= test if maps are present */
149
/* fn = filename of the generated file */
151
int scale, e, xsize_e, xsize_w;
152
int xstart, ystart, y, x_w, x_e;
154
GtkWidget *myprogress, *text, *vbox;
163
g_strlcpy (fn, "nofile.sorry", 255);
165
/* return if no map found */
168
xstart = (int) (21600.0 * (lon / 180.0));
169
if (((xstart < 1280) || (xstart > 20320)) && (fdin_w < 0))
177
xstart = (int) (21600.0 * (lon / 180.0));
178
if (((xstart < 1280) || (xstart > 20320)) && (fdin_e < 0))
186
fdout = open (outfilename, O_RDWR | O_TRUNC | O_CREAT, 0644);
189
fprintf (stderr, _("could not create output map file %s!\n"),
194
nasawindow = gtk_window_new (GTK_WINDOW_POPUP);
195
vbox = gtk_vbox_new (FALSE, 6);
196
gtk_container_add (GTK_CONTAINER (nasawindow), vbox);
197
/* gtk_window_set_transient_for (GTK_WINDOW (nasawindow), */
198
/* GTK_WINDOW (mainwindow)); */
199
gtk_window_set_position (GTK_WINDOW (nasawindow), GTK_WIN_POS_CENTER);
201
/* g_signal_connect (window, "destroy", */
202
/* G_CALLBACK (gtk_widget_destroyed), &window); */
204
gtk_window_set_title (GTK_WINDOW (nasawindow), _("Creating map..."));
205
gtk_container_set_border_width (GTK_CONTAINER (nasawindow), 20);
207
myprogress = gtk_progress_bar_new ();
208
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (myprogress), 0.0);
209
gtk_box_pack_start (GTK_BOX (vbox), myprogress, TRUE, TRUE, 2);
212
("Creating a temporary map from NASA satellite images"));
213
gtk_box_pack_start (GTK_BOX (vbox), text, TRUE, TRUE, 2);
215
/* gtk_widget_show_all (nasawindow); */
216
gtk_widget_show_all (nasawindow);
219
_("converting map for latitude: %f and longitude: %f ...\n"),
223
/* lon = 180.0 + lon; */
224
g_strlcpy (fn, "top_NASA_IMAGE.ppm", 255);
227
g_snprintf (mybuffer, sizeof (mybuffer),
228
"P6\n# CREATOR: GpsDrive\n1280 1024\n255\n");
230
e = write (fdout, mybuffer, strlen (mybuffer));
233
xstart = (int) (21600.0 * (lon / 180.0));
235
ystart = 3 * 21600 * (int) (10800 - 10800.0 * (lat / 90.0));
237
/* fprintf (stdout, "xstart: %d, ystart: %d\n", xstart, ystart); */
239
ystart = ystart - 512 * 21600 * 3;
242
xsize_w = xsize_e = 1280;
246
x_w = 21600 + xstart;
258
xsize_w = 21600 - x_w;
259
xsize_e = 1280 - xsize_w;
261
else if (xstart > 20320)
263
x_w = (xstart + 1280) - 21600;
270
xsize_e = 1280 - xsize_w;
286
for (y = 0; y < 1024; y++)
290
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (myprogress),
292
g_snprintf (textbuf, sizeof (textbuf), "%d%%",
293
(int) (100.0 * y / 1024));
294
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (myprogress),
296
while (gtk_events_pending ())
297
gtk_main_iteration ();
303
e = lseek (fdin_w, x_w + ystart + y * 21600 * 3, SEEK_SET);
304
e = read (fdin_w, mybuffer, xsize_w * 3);
305
e = write (fdout, mybuffer, xsize_w * 3);
310
e = lseek (fdin_e, x_e + ystart + y * 21600 * 3, SEEK_SET);
311
e = read (fdin_e, mybuffer, xsize_e * 3);
312
e = write (fdout, mybuffer, xsize_e * 3);
316
/* fprintf (stderr, "wrote %d bytes (%.1f MB) to mapfile\n", uc, */
317
/* uc / (1024.0 * 1024.0)); */
319
gtk_widget_destroy (GTK_WIDGET (nasawindow));
321
g_strlcpy (mybuffer, g_basename (outfilename), sizeof (mybuffer));
324
("\nYou can permanently add this map file with following line in your\nmap_koord.txt (rename the file!):\n"));
325
fprintf (stdout, "\n%s %f %f %d\n", mybuffer, lat, lon, scale);
327
} /* End of if !test */