Mapper
plot_data.c
Go to the documentation of this file.
1 #include "prototypes.h"
2 void plot_data(Drawable pix,int plot_view,int type,int h,int display_flag)
3 {
4 extern int zoom_mode;
5 extern int rfs_flag;
6 extern float filter_value;
7 extern int elevation_filter_value;
8 extern time_t ditime[],xtime[500],htime[500],dtime[500];
9 extern char *legend[100];
10 extern int indexx;
11 extern time_t qtime;
12 extern struct saved *fsaved;
13 extern char find_station_buf[10];
14 extern struct dval dval;
15 extern int npoint[2],zoom;
16 extern GC gc;
17 extern unsigned long qmap[16];
18 extern Widget drawing_area;
19 extern Display *display;
20 extern Font font[10];
21 extern XFontStruct *info_font[10];
22 extern struct station station[1500];
23 extern int max_stations;
24 extern int dflag[10];
25 extern long amap[16];
26 int i,xc,yc,text_width,text_width2,length;
27 int x1,y1,xadd,yadd,MY=10;
28 float xrat,yrat,mult,dmult,cmult;
29 long xmin,xmax,ymin,ymax;
30 signed long xcen,ycen,lint1,lint2;
31 Dimension width,height;
32 Arg args[10];
33 signed long XSIZE,YSIZE;
34 extern struct display_set display_set[4];
35 long r,s;
36 float conv=.0174,fval;
37 float lat,lon;
38 char tbuf[100];
39 int yheight,ival;
40 struct tm *gm;
41 time_t ntime;
42 struct saved *saved;
43 int hour;
44 int year,yearp;
45 int mon;
46 int day;
47 char mbuf[100];
48 char *month[]=
49 {
50 "December","January","February","March","April",
51 "May","June","July","August","September",
52 "October","November","December"
53 };
54 
55 
56 if(type==-1)
57  return;
58 
59 XSetFont(display,gc,font[4]);
60 
61 yheight=info_font[4]->ascent;
62 XSetForeground(display,gc,qmap[15]);
63 
64 XtSetArg(args[0],XtNwidth,&width);
65 XtSetArg(args[1],XtNheight,&height);
66 XtGetValues(drawing_area,args,2);
67 
68 XSIZE=(long)width*10L;
69 YSIZE=(long)height*10L;
70 
71 xrat=(float)XSIZE/(float)12800;
72 yrat=(float)YSIZE/(float)9600;
73 
74 if(xrat < yrat)
75  mult=xrat;
76 else
77  mult=yrat;
78 
86 
87 lint1=(long)npoint[0]*(long)MY;
88 lint2=(long)npoint[1]*(long)MY;
89 
91 
93 
94 while( saved!=NULL)
95 {
96  lat=saved->lat;
97  lon=saved->lon;
98 
99  r=dval.a * cos(lat*conv)/(1+sin(lat*conv))
100  * cos((lon-dval.lo-90)*conv) + dval.xo +.5;
101 
102  s=dval.a * cos(lat*conv)/(1+sin(lat*conv))
103  * sin((lon-dval.lo-90)*conv) + dval.yo + .5;
104 
105  if(zoom==1)
106  {
107  x1=(xmin+(float)r * cmult)/MY;
108  y1=(ymin+(float)s * cmult)/MY;
109  }
110  else
111  {
112  x1=(((xmin+(float)r*cmult)-lint1)*zoom+xcen)/MY;
113  y1=(((ymin+(float)s*cmult)-lint2)*zoom+ycen)/MY;
114  }
115 
116  if(saved->pparm==1)
117  XSetForeground(display,gc,qmap[11]);
118  else if(saved->pparm==2 )
119  XSetForeground(display,gc,qmap[13]);
120  else if(saved->data < -98)
121  XSetForeground(display,gc,qmap[1]);
122  else if(saved->parm==1)
123  XSetForeground(display,gc,qmap[11]);
124  else if(saved->parm==2 )
125  XSetForeground(display,gc,qmap[13]);
126  else
127  XSetForeground(display,gc,qmap[15]);
128 
129  if(strncmp(&saved->pc[4],"P",1)==0 && dflag[1] != 1)
130  goto nextseg;
131 
132  if(strncmp(&saved->pc[4],"M",1)==0 && dflag[2] != 1)
133  goto nextseg;
134 
135  if(strncmp(&saved->pc[4],"R",1)==0 && dflag[3] != 1)
136  goto nextseg;
137 
138  if(strncmp(&saved->pc[4],"G",1)==0 && dflag[4] != 1)
139  goto nextseg;
140 
141  if(strncmp(&saved->pc[4],"Z",1)==0 && dflag[5] != 1)
142  goto nextseg;
143 
144  if((type==3 || type==4 || type==5 || type==6) && rfs_flag==1 &&
145  saved->rfs!=1)
146  goto nextseg;
147 
148  if(elevation_filter_value > 0 &&
150  goto nextseg;
151 
152 /* locate station in data stream */
153 
154  if(plot_view==6 && saved->data < -98 &&
155  saved->fparm < 1 && saved->pparm < 1)
156  goto nextseg;
157 
158  XDrawLine(display,pix,gc,x1+1,y1+1,x1+1,y1-1);
159  XDrawLine(display,pix,gc,x1+1,y1-1,x1-1,y1-1);
160  XDrawLine(display,pix,gc,x1-1,y1-1,x1-1,y1+1);
161  XDrawLine(display,pix,gc,x1-1,y1+1,x1+1,y1-1);
162 
163  if(plot_view==1)
164  strcpy(tbuf,saved->hb5);
165  else if(plot_view==2)
166  strcpy(tbuf,saved->snum);
167  else if(plot_view==3)
168  strcpy(tbuf,saved->pc);
169  else if(plot_view==4)
170  strcpy(tbuf,saved->name);
171  else if(plot_view==5)
172  {
173  if(saved->elev < 0)
174  goto nextseg;
175  sprintf(tbuf,"%d",saved->elev);
176  }
177  else if(plot_view==6)
178  {
179  if(filter_value > -9998 && saved->data < filter_value)
180  goto nextseg;
181 
182  if(saved->data < -98)
183  {
184  sprintf(tbuf,"M");
185  }
186 
187  else if(type==0 || type==1 || type==2 || type==6 || type==7 ||
188  type==8 || type==9 || type==10 || type==30)
189  {
190  if(saved->data >= 0)
191  ival=saved->data+.5;
192  else
193  ival=saved->data -.5;
194 
195  sprintf(tbuf,"%d",ival);
196  }
197 
198  else if(type==3 || type==5)
199  {
200  if(saved->data >= 0)
201  fval=saved->data+.0005;
202  else
203  fval=saved->data-.0005;
204  sprintf(tbuf,"%5.2f",fval);
205  }
206 
207  else if(type==4)
208  {
209  if(saved->pc[1]=='G' || saved->pc[1]=='P' || saved->pc[0]=='Q')
210  fval=(saved->data+0.0005)/1000.;
211  else
212  fval=saved->data;
213  sprintf(tbuf,"%6.2f",fval);
214  }
215 
216  else if(type==24 || type==26 || type==28 || type==29)
217  {
218  fval=saved->data+.5;
219  sprintf(tbuf,"%4d",(int)fval);
220  }
221 
222  else if(type==21 || type==22 || type==23 || type==25 ||
223  type==13 || type==14 || type==15 || type==16)
224  {
225  fval=saved->data+.0005;
226  sprintf(tbuf,"%5.2f",fval);
227  }
228 
229  else if(type==17 || type==18 || type==27)
230  {
231  if(saved->data >= 0)
232  fval=saved->data+.05;
233  else
234  fval=saved->data-.05;
235  sprintf(tbuf,"%5.1f",fval);
236  }
237 
238  else
239  strcpy(tbuf,"dummy");
240 
241  for(i=0;i<strlen(tbuf);i++)
242  if(tbuf[i]!=' ')
243  break;
244 
245  strcpy(tbuf,&tbuf[i]);
246  }
247 
248  if(plot_view==6 && type==11)
249  {
250  draw_wind(pix,x1,y1,saved->data);
251  goto nextseg;
252  }
253 
254  length=strlen(tbuf);
255  text_width=XTextWidth(info_font[4],tbuf,length);
256  text_width2= 0;
257 
258  if(saved->fparm==1 || saved->fparm==2)
259  {
260  text_width2=XTextWidth(info_font[4],"^",1);
261  }
262 
263  xadd=saved->xadd;
264  yadd=saved->yadd;
265 
266  if(xadd < 0)
267  xc=x1 - text_width;
268  else
269  xc=x1+3+text_width2;
270 
271  if(yadd < 0)
272  yc=y1;
273  else
274  yc=y1+yheight;
275 
276  XDrawString(display,pix,gc,xc,yc,tbuf,length);
277 
278  if(saved->fparm==1 || saved->fparm==2)
279  {
280  if(saved->fparm==1)
281  XSetForeground(display,gc,qmap[11]);
282 
283  else if(saved->fparm==2)
284  XSetForeground(display,gc,qmap[13]);
285 
286  if(xadd < 0)
287  XDrawString(display,pix,gc,x1-text_width-text_width2,yc,"^",1);
288 
289  else
290  XDrawString(display,pix,gc,x1+3,yc,"^",1);
291  }
292 
293  if(strcmp(find_station_buf,saved->hb5)==0)
294  {
295  find_station_buf[0]=0;
296  XDrawLine(display,pix,gc,xc,yc,xc+text_width,yc);
297  }
298 
299  nextseg:
300  saved=saved->next;
301  if(saved==NULL)
302  break;
303 }
304 
305 /* build legend &/
306 
307 /* hourly instantaneous - 0,1,3,4,5,6,8,9,10,11 */
308 
309  if(type==0 || type==1 || type==3 || type==4 || type==5 ||
310  type==6 || type==8 || type==9 || type==10 || type==11 || type==30)
311  {
312  ntime=qtime - indexx*3600;
313  gm=gmtime(&ntime);
314  sprintf(tbuf,"%02d-%02d-%04d %02dZ",gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900,gm->tm_hour);
315  }
316 
317  /* daily instantaneous 2,7 */
318  else if(type==2 || type==7)
319  {
320  gm=gmtime(&qtime);
321  ntime=qtime - indexx*3600*24;
322  if(gm->tm_hour <= 8)
323  ntime=ntime-3600*24;
324 
325  gm=gmtime(&ntime);
326  sprintf(tbuf,"%02d-%02d-%04d",gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900);
327  }
328 
329  else if(type==13)
330  {
331  if(indexx==0)
332  sprintf(tbuf,"Last 30 minutes");
333  else
334  {
335  hour=ditime[indexx]/60;
336  sprintf(tbuf,"Last %d hours",hour);
337  }
338  }
339 
340  else if(type==14)
341  {
342  if(indexx > 0)
343  {
344 /*
345  gm=gmtime(&htime[indexx+1]);
346  sprintf(tbuf,"%02d-%02d-%04d %02dZ to ",
347  gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900,gm->tm_hour);
348 */
349  sprintf(tbuf,"Ending ");
350  gm=gmtime(&htime[indexx]);
351  sprintf(mbuf,"%02d-%02d-%04d %02dZ",
352  gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900,gm->tm_hour);
353  strcat(tbuf,mbuf);
354  }
355  else
356  {
357  gm=gmtime(&htime[indexx]);
358  sprintf(tbuf,"Since %02d-%02d-%04d %02dZ",
359  gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900,gm->tm_hour);
360  }
361  }
362 
363  else if(type==15)
364  {
365  gm=gmtime(&xtime[indexx+1]);
366  if(!indexx)
367  sprintf(tbuf,"%02d-%02d-%04d %02dZ to ",
368  gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900,gm->tm_hour);
369  else
370  sprintf(tbuf,"Ending ");
371  gm=gmtime(&xtime[indexx]);
372  sprintf(mbuf,"%02d-%02d-%04d %02dZ",
373  gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900,gm->tm_hour);
374  strcat(tbuf,mbuf);
375  }
376 
377  else if(type==16)
378  {
379  gm=gmtime(&dtime[indexx+1]);
380  if(!indexx)
381  sprintf(tbuf,"%02d-%02d-%04d 12Z to ",
382  gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900);
383  else
384  sprintf(tbuf,"Ending ");
385 
386  gm=gmtime(&dtime[indexx]);
387  if(!indexx)
388  sprintf(mbuf,"%02d-%02d-%04d %02dZ",
389  gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900,gm->tm_hour);
390  else
391  sprintf(mbuf,"%02d-%02d-%04d 12Z",
392  gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900);
393  strcat(tbuf,mbuf);
394  }
395 
396  else if(type==21)
397  {
398  gm=gmtime(&xtime[indexx+1]);
399  if(!indexx)
400  sprintf(tbuf,"%02d-%02d-%04d %02dZ to ",
401  gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900,gm->tm_hour);
402  else
403  sprintf(tbuf,"Ending ");
404  gm=gmtime(&xtime[indexx]);
405  sprintf(mbuf,"%02d-%02d-%04d %02dZ",
406  gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900,gm->tm_hour);
407  strcat(tbuf,mbuf);
408  }
409 
410  else if(type==22)
411  {
412  gm=gmtime(&dtime[indexx+1]);
413  if(!indexx)
414  sprintf(tbuf,"%02d-%02d-%04d 12Z to ",
415  gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900);
416  else
417  sprintf(tbuf,"Ending ");
418 
419  gm=gmtime(&dtime[indexx]);
420  if(!indexx)
421  sprintf(mbuf,"%02d-%02d-%04d %02dZ",
422  gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900,gm->tm_hour);
423  else
424  sprintf(mbuf,"%02d-%02d-%04d 12Z",
425  gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900);
426  strcat(tbuf,mbuf);
427  }
428 
429  else if(type==23 || type==24)
430  {
431  gm=gmtime(&dtime[0]);
432  year=gm->tm_year+1900;
433  mon=gm->tm_mon+1;
434  if(!indexx)
435  sprintf(tbuf,"%s %4d (to date)",month[mon],year);
436  else
437  {
438  mon=mon-indexx;
439  while(mon<=0)
440  {
441  mon=mon+12;
442  year=year-1;
443  }
444  sprintf(tbuf,"%s %4d",month[mon],year);
445  }
446  }
447 
448  else if(type==25 || type==26)
449  {
450  gm=gmtime(&dtime[0]);
451  year=gm->tm_year+1900;
452  mon=gm->tm_mon+1;
453  day=gm->tm_mday;
454  if(indexx==0)
455  {
456  if(mon>=10)
457  yearp=year;
458  else
459  yearp=year-1;
460  sprintf(tbuf,"October %04d thru %s %02d %04d",yearp,month[mon],day,year);
461  }
462 
463  if(indexx==1)
464  {
465  mon=mon-1;
466  if(mon<=0)
467  year--;
468  if(mon>=10)
469  yearp=year;
470  else
471  yearp=year-1;
472  sprintf(tbuf,"October %04d thru %s %04d",yearp,month[mon],year);
473  }
474 
475  if(indexx==2)
476  {
477  if(mon<=10)
478  year--;
479  sprintf(tbuf,"October %04d thru September %04d",year-1,year);
480  }
481  }
482 
483  else if(type==27 || type==28 || type==29)
484  {
485  gm=gmtime(&dtime[0]);
486  year=gm->tm_year+1900;
487  mon=gm->tm_mon+1;
488  mon=mon-indexx;
489  while(mon<=0)
490  {
491  mon=mon+12;
492  year=year-1;
493  }
494  if(mon==12)
495  {
496  indexx=indexx+6;
497  mon=6;
498  }
499  if(mon==7)
500  {
501  indexx=indexx-6;
502  if(indexx < 0)
503  indexx=0;
504  mon=1;
505  year=year+1;
506  }
507  sprintf(tbuf,"%s 1 %4d",month[mon],year);
508  }
509 
510  else if(type==17)
511  {
512  gm=gmtime(&dtime[indexx+1]);
513  sprintf(tbuf,"%02d-%02d-%04d 12Z",gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900);
514  }
515 
516  else if(type==18)
517  {
518  sprintf(tbuf,"%2d day change",indexx+1);
519  }
520 
521  XSetForeground(display,gc,qmap[15]);
522  XSetBackground(display,gc,0);
523  XSetFont(display,gc,font[2]);
524  yheight=info_font[2]->ascent+2;
525 
526  XDrawString(display,pix,gc,30,ymax/10-yheight*2,tbuf,strlen(tbuf));
527  XDrawString(display,pix,gc,30,ymax/10-yheight*3,legend[type],strlen(legend[type]));
528 
529  if(zoom_mode==1)
530  strcpy(tbuf,"Mode=zoom");
531  else
532  strcpy(tbuf,"Mode=edit");
533 
534  XDrawString(display,pix,gc,30,ymax/10-yheight,tbuf,strlen(tbuf));
535  gm=gmtime(&qtime);
536 
537  sprintf(tbuf,"Last Update %02d-%02d-%04d %02d:%02dZ",
538  gm->tm_mon+1,gm->tm_mday,gm->tm_year+1900,gm->tm_hour,gm->tm_min);
539 
540  XSetForeground(display,gc,qmap[15]);
541  XSetBackground(display,gc,0);
542  XSetFont(display,gc,font[4]);
543  yheight=info_font[4]->ascent+2;
544  XDrawString(display,pix,gc,30,yheight*2,tbuf,strlen(tbuf));
545 
546  return;
547 }
static int i
int hour
Definition: display_data.c:26
XFontStruct * info_font[10]
Definition: mapper.c:195
int day
Definition: display_data.c:26
Display * display
Definition: mapper.c:159
Font font[10]
Definition: mapper.c:161
int year
Definition: display_data.c:26
int month
Definition: display_data.c:26
void draw_wind(Pixmap pix, int r, int s, double data)
Definition: draw_wind.c:4
float mult
Definition: edit_stations.c:6
char * mon[]
sprintf(fbuf,"/usr/mapper/nexrad/ngrid.%02d-%02d-%02d-%02d", year, month, day, hour)
double lat
Definition: mapp2h.h:41
double lon
Definition: mapp2h.h:41
int ditime[]
Definition: mapper.c:51
int plot_view
Definition: mapper.c:65
int indexx
Definition: mapper.c:60
int max_stations
Definition: mapper.c:64
time_t dtime[500]
Definition: mapper.c:150
struct saved * fsaved
Definition: mapper.c:128
int elevation_filter_value
Definition: mapper.c:47
int dflag[10]
Definition: mapper.c:106
char find_station_buf[10]
Definition: mapper.c:16
unsigned long qmap[16]
Definition: mapper.c:116
int rfs_flag
Definition: mapper.c:36
float filter_value
Definition: mapper.c:29
unsigned long amap[16]
Definition: mapper.c:117
time_t qtime
Definition: mapper.c:151
char * legend[100]
Definition: mapper.c:15
time_t htime[500]
Definition: mapper.c:150
int display_flag
Definition: mapper.c:100
int zoom_mode
Definition: mapper.c:90
time_t xtime[500]
Definition: mapper.c:150
void plot_data(Drawable pix, int plot_view, int type, int h, int display_flag)
Definition: plot_data.c:2
float xrat
long xmax
float yrat
long ymax
long lint1
GC gc
Definition: mapper.c:163
float cmult
signed long xcen
Dimension height
signed long ycen
Dimension width
int yheight
long lint2
Arg args[10]
long xmin
unsigned long XSIZE
int MY
int zoom
float dmult
Widget drawing_area
Definition: mapper.c:185
int npoint[2]
Definition: mapper.c:105
long ymin
unsigned long YSIZE
float dmult[4]
Definition: misc.h:613
long xmin[4]
Definition: misc.h:607
long xmax[4]
Definition: misc.h:609
long ymax[4]
Definition: misc.h:610
long ymin[4]
Definition: misc.h:608
long ycen[4]
Definition: misc.h:612
long xcen[4]
Definition: misc.h:611
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:361
int parm
Definition: misc.h:373
int yadd
Definition: misc.h:372
int pparm
Definition: misc.h:375
char hb5[10]
Definition: misc.h:363
int elev
Definition: misc.h:367
char snum[10]
Definition: misc.h:365
int xadd
Definition: misc.h:371
char pc[10]
Definition: misc.h:364
double data
Definition: misc.h:378
float lat
Definition: misc.h:376
int r
Definition: misc.h:369
int s
Definition: misc.h:370
int fparm
Definition: misc.h:374
int rfs
Definition: misc.h:368
struct saved * next
Definition: misc.h:379
char name[40]
Definition: misc.h:366
float lon
Definition: misc.h:377
Definition: misc.h:296
int yadd
Definition: misc.h:310
int xadd
Definition: misc.h:309