Mapper
read_maps_new.c
Go to the documentation of this file.
1 
2 #include "prototypes.h"
3 
4 void read_maps(char *sfname,int smonth,int emonth)
5 
6 {
7 
8 extern double max_lat,min_lat,cen_lon;
9 extern int isohyets_used;
10 extern int fgbgflag;
11 extern Widget top_level;
12 extern int posit;
13 extern Widget s_text;
14 extern void topo_select();
15 extern void isohyet_select();
16 extern unsigned car[100];
17 extern struct maplayer *smaplayer[100];
18 extern struct MenuItem ktems[100];
19 extern struct dval dval;
20 extern void get_hrap_coord();
21 extern Widget scrollbar;
22 int i,j,ier,no,zoom,color,ii,lflag,xadd,yadd,type,k,len,jj;
23 char kbuf[120],*p,*sname[20],nm[50],dbuf[100],fname[50];
24 char name[50],ebuf[120];
25 int num[100];
26 FILE *ft;
27 long xsize=12800,ysize=9600;
28 double f1,f2,xo,yo,a,conv=.0174,lat,lon;
29 struct maplayer *maplayer;
30 FILE *fp;
31 int slider_size,scrollm,ivalue,increment,page_increment;
32 
33 /* this will free memory if necessary */
34 
35 isohyets_used=0;
36 
37 for(j=0;j<100;j++)
38  num[j]=j;
39 
40 j=0;
41 jj=0;
42 
43 fp=fopen(sfname,"r");
44 if(fp==NULL)
45  printf("fp is NULL\n");
46 
47 fgets(kbuf,110,fp);
48 
49 p=pars_line(kbuf,"maximum_latitude=",dbuf);
50 
51 if(p!=NULL)
52  max_lat=atof(dbuf);
53 
54 else {
55 
56  printf("maximum_latitude not specified\n");
57  exit(1);
58 
59  }
60 
61 p=pars_line(kbuf,"minimum_latitude=",dbuf);
62 if(p!=NULL)
63  min_lat=atof(dbuf);
64 
65 else {
66 
67  printf("minimum_latitude not specified\n");
68  exit(1);
69 
70  }
71 
72 p=pars_line(kbuf,"center_longitude=",dbuf);
73 if(p!=NULL)
74  cen_lon=atof(dbuf);
75 
76 
77 else {
78 
79  printf("center_longitude not specified\n");
80  exit(1);
81 
82  }
83 
84 
85 f1=cos(max_lat*conv)/(1+sin(max_lat*conv));
86 f2=cos(min_lat*conv)/(1+sin(min_lat*conv));
87 
88 a=ysize/(f1-f2);
89 yo=a*f1;
90 xo=xsize/2;
91 
92 dval.a=a;
93 dval.yo=yo;
94 dval.xo=xo;
96 lflag=0;
97 
98 for(ii=0;ii<100;ii++) {
99 
100  p=fgets(kbuf,110,fp);
101  if(p==NULL)
102  break;
103 
104  ier=strlen(kbuf);
105  kbuf[ier-1]=0;
106 
107  nm[0]=0;
108 
109  p=pars_line(kbuf,"name=",nm);
110  fname[0]=0;
111 
112  p=pars_line(kbuf,"topography=",fname);
113  if(p!=NULL) {
114 
115  sname[j]=calloc(1,strlen(nm)+1);
116  strcpy(sname[j],nm);
117  ktems[j].label=sname[j];
119  ktems[j++].callback_data=NULL;
120  strcat(nm,"\n");
121  posit=posit+strlen(nm);
122  XmTextInsert(s_text,posit,nm);
123 
124  XtVaGetValues(scrollbar,XmNmaximum,&scrollm,NULL);
125  XmScrollBarGetValues(scrollbar,&ivalue,&slider_size,
126  &increment,&page_increment);
127  XmScrollBarSetValues(scrollbar,scrollm-slider_size,
128  slider_size,increment,page_increment,True);
129 
130  XmUpdateDisplay(top_level);
132 
133  continue;
134 
135  }
136 
137  p=pars_line(kbuf,"isohyets=",fname);
138  if(p!=NULL) {
139 
140  sname[j]=calloc(1,strlen(nm)+1);
141  strcpy(sname[j],nm);
142  ktems[j].label=sname[j];
144  ktems[j++].callback_data=NULL;
145  strcat(nm,"\n");
146  posit=posit+strlen(nm);
147  XmTextInsert(s_text,posit,nm);
148 
149  XtVaGetValues(scrollbar,XmNmaximum,&scrollm,NULL);
150 
151  XmScrollBarGetValues(scrollbar,&ivalue,&slider_size,
152  &increment,&page_increment);
153 
154 
155  XmScrollBarSetValues(scrollbar,scrollm-slider_size,
156  slider_size, increment,page_increment,True);
157  XmUpdateDisplay(top_level);
158 
159  get_isohyet_coord(fname,smonth,emonth);
160 
161  continue;
162 
163  }
164 
165  p=pars_line(kbuf,"fmap=",fname);
166  if(p!=NULL)
167  continue;
168 
169  p=pars_line(kbuf,"background=",fname);
170  if(p==NULL)
171  continue;
172 
173  ft=fopen(fname,"r");
174 
175  if(ft==NULL)
176  continue;
177 
178 
179  p=fgets(ebuf,100,ft);
180 
181  ier=sscanf(ebuf,"%s %s %s %s %s",dbuf,dbuf,dbuf,dbuf,dbuf);
182 
183  type=0;
184  if(ier > 4)
185  type=1;
186 
187  rewind(ft);
188 
189  p=pars_line(kbuf,"char=",dbuf);
190  if(p!=NULL) {
191 
192  *p=toupper(*p);
193 
194  car[j]=*p;
195 
196  }
197 
198  else
199  car[j]=-1;
200 
201  color=8;
202  p=pars_line(kbuf,"color=",dbuf);
203  if(p!=NULL)
204  color=atoi(dbuf);
205 
206 
207  if(lflag==1){
208 
209  maplayer->nextseg=(struct maplayer *)calloc(1,sizeof(struct maplayer));
210  if(maplayer->nextseg==NULL)
211  printf("no memory\n");
212 
214 
215  }
216 
217  else {
218 
219  sname[j]=calloc(1,strlen(nm)+1);
220  strcpy(sname[j],nm);
221  ktems[j].label=sname[j];
223  ktems[j].callback_data=(XtPointer)num[jj];
224  j++;
225  maplayer=(struct maplayer *) calloc(1,sizeof(struct maplayer));
226  smaplayer[jj++]=maplayer;
227 
228  }
229 
230  if(lflag==0) {
231 
232  strcat(nm,"\n");
233  posit=posit+strlen(nm);
234  XmTextInsert(s_text,posit,nm);
235 
236  XtVaGetValues(scrollbar,XmNmaximum,&scrollm,NULL);
237  XmScrollBarGetValues(scrollbar,&ivalue,&slider_size,
238  &increment,&page_increment);
239  XmScrollBarSetValues(scrollbar,scrollm-slider_size,slider_size,
240  increment,page_increment,True);
241 
242  XmUpdateDisplay(top_level);
243 
244  }
245 
246 
247  lflag=0;
248  p=pars_line(kbuf,"link",dbuf);
249  if(p!=NULL)
250  lflag=1;
251 
252  p=fgets(kbuf,100,ft);
253 
254  if(p==NULL)
255  continue;
256 
257  for(;;) {
258 
259  if(type==0) {
260 
261  sscanf(kbuf,"%d %d",&no,&zoom);
262 
263  maplayer->name=NULL;
264  maplayer->zoom=zoom;
265  maplayer->number=no;
267 
268  maplayer->points=(struct mappoints *)calloc(no,sizeof(struct mappoints));
269 
270  if(maplayer->points==NULL)
271  printf("no memory\n");
272 
273  for(i=0;i<no;i++) {
274 
275  p=fgets(kbuf,100,ft);
276  if(p==NULL) {
277 
278  maplayer->nextseg=NULL;
279  break;
280 
281  }
282 
283  sscanf(kbuf,"%lf %lf",&lon,&lat);
284  lon=-lon;
285 
286  maplayer->points[i].x=a * cos(lat*conv)/(1+sin(lat*conv))*
287  cos((lon-cen_lon-90)*conv) + xo;
288 
289  maplayer->points[i].y=a * cos(lat*conv)/(1+sin(lat*conv))*
290  sin((lon-cen_lon-90)*conv) + yo;
291 
292 
293  }
294 
295 
296 
297  }
298 
299  else {
300 
301  i=0;
302  k=0;
303 
304  while(kbuf[i] != 0)
305  if(kbuf[i++] != ' ')
306  break;
307 
308  while(kbuf[i] !=0)
309  if(kbuf[i++] == ' ')
310  break;
311 
312  while(kbuf[i] != 0 )
313  if(kbuf[i++] != ' ')
314  break;
315  i--;
316  while(kbuf[i] != 0) {
317 
318  name[k]=kbuf[i];
319 
320  if(kbuf[i+1]==' ' && kbuf[i+2]==' ')
321  break;
322  i++;
323  k++;
324 
325  }
326 
327  if(kbuf[i]==0){
328  printf("error in format %s\n",sname[j]);
329 
330  break;
331 
332  }
333 
334  name[k+1]=0;
335 
336  ier=sscanf(&kbuf[i+1],"%d %d %d",&xadd,&yadd,&zoom);
337 
338  if(ier != 3) {
339  printf("error in format %s\n",sname[j]);
340 
341  break;
342 
343  }
344 
345  p=pars_line(kbuf,"-center",dbuf);
346 
347  if(p==NULL)
348  maplayer->number=0;
349 
350  else
351  maplayer->number=1;
352 
353  p=fgets(kbuf,100,ft);
354  if(p==NULL)
355  break;
356 
357 
358  maplayer->zoom=zoom;
359  maplayer->xmax=xadd;
360  maplayer->ymax=yadd;
362  sscanf(kbuf,"%lf %lf",&lon,&lat);
363  lon=-lon;
364 
365  maplayer->points=(struct mappoints *)calloc(1,sizeof(struct mappoints));
366  maplayer->points[0].x=a * cos(lat*conv)/(1+sin(lat*conv))*
367  cos((lon-cen_lon-90)*conv) + xo;
368 
369  maplayer->points[0].y=a * cos(lat*conv)/(1+sin(lat*conv))*
370  sin((lon-cen_lon-90)*conv) + yo;
371 
372  len=strlen(name);
373 
374  maplayer->name=(char *) calloc(len + 1,sizeof(char));
375  strcpy(maplayer->name,name);
376 
377  }
378 
379  p=fgets(kbuf,100,ft);
380  if(p==NULL) {
381 
382  maplayer->nextseg=NULL;
383  break;
384 
385  }
386 
387  maplayer->nextseg=(struct maplayer *)calloc(1,sizeof(struct maplayer));
388  if(maplayer->nextseg==NULL)
389  printf("no memory\n");
391 
392  }
393 
394 
395 
396  fclose(ft);
397 
398  }
399 
400 ktems[j].label="Maps Foreground";
402 ktems[j++].callback_data=(XtPointer)fgbgflag;
403 ktems[j].label=NULL;
404 
405 return;
406 
407 }
408 
409 
char name[35][30]
Definition: borshef.c:10
static int i
Widget top_level
Definition: display_rec.c:5
double f1[]
Definition: ffg.c:35
void get_hrap_coord(double maximum_latitude, double minimum_latitude, double center_longitude)
Definition: get_hrap_coord.c:4
void get_isohyet_coord(char *fname, int smonth, int emonth)
void get_topo_coord(char *fname)
Definition: get_topo_coord.c:3
char * pars_line(char *buf, char *s, char *sbuf)
Definition: pars_line.c:3
void isohyet_select(void)
void topo_select(void)
Definition: mapper.c:4005
void foreground_select(void)
Definition: mapper.c:3972
void map_select(Widget, XtPointer, XmDrawingAreaCallbackStruct *)
Definition: mapper.c:4020
fclose(fp)
printf("fbuf is %s\n", fbuf)
fp
Definition: make_NEXRAD.c:339
int j
Definition: mapp2h.h:48
double lat
Definition: mapp2h.h:41
double lon
Definition: mapp2h.h:41
int k
Definition: mapp2h.h:48
double cen_lon
Definition: mapper.c:22
double min_lat
Definition: mapper.c:22
Widget scrollbar
Definition: mapper.c:185
int posit
Definition: mapper.c:93
struct MenuItem ktems[100]
Definition: mapper.c:136
int fgbgflag
Definition: mapper.c:79
Widget s_text
Definition: mapper.c:185
struct maplayer * smaplayer[100]
Definition: mapper.c:145
unsigned car[100]
Definition: mapper.c:111
double max_lat
Definition: mapper.c:22
int color
int zoom
void read_maps(char *sfname, int smonth, int emonth)
Definition: read_maps_new.c:4
char fname[100]
Definition: send_afos.c:6
Definition: misc.h:459
char * label
Definition: misc.h:461
void(* callback)()
Definition: misc.h:463
XtPointer callback_data
Definition: misc.h:464
Definition: misc.h:470
double lo
Definition: misc.h:475
double a
Definition: misc.h:472
double yo
Definition: misc.h:474
double xo
Definition: misc.h:473
Definition: misc.h:443
short int xmax
Definition: misc.h:448
short int number
Definition: misc.h:447
int type
Definition: misc.h:452
char * name
Definition: misc.h:453
struct maplayer * nextseg
Definition: misc.h:455
short int color
Definition: misc.h:445
short int zoom
Definition: misc.h:446
short int ymax
Definition: misc.h:449
struct mappoints * points
Definition: misc.h:454
int x
Definition: misc.h:438
int y
Definition: misc.h:439