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