Mapper
edit_stations.c
Go to the documentation of this file.
1 #include <sqlhdr.h>
2 #include <sqliapi.h>
3 #line 1 "edit_stations.ec"
4 #include "prototypes.h"
5 
6 float mult;
7 Widget dialog;
8 int isave;
10 
11 void edit_stations(int win_x,int win_y,unsigned int win_button)
12 {
13 extern char saved_hb5[6];
14 extern int saved_j;
15 extern struct saved *fsaved;
16 /*
17 extern struct custom custom[6000];
18 */
19 extern struct custom custom[9000];
20 extern unsigned long cmap[16];
21 extern Widget drawing_area;
22 extern Font font[10];
23 extern int npoint[2],zoom;
24 extern struct display_set display_set[4];
25 extern Display *display;
26 extern GC gc;
27 extern int mmap[10];
28 extern void kill_widget();
29 extern struct dval dval;
30 extern int dflag[10];
32 void change_custom_file();
33 Widget rowcol,rowcol3,pbutton,rowcol1;
34 float conv=.0174;
35 int MY=10;
36 Arg args[10];
37 Cardinal argcount;
38 int i;
39 double testdist,maxdist;
40 int x,y;
41 XmString t;
42 Dimension width,height;
43 signed long XSIZE,YSIZE;
44 float xrat,yrat;
46 long lint1,lint2;
47 float dmult,lat,lon;
48 char *st[5],buf[100],muf[10];
49 char shb5[6],spc[8];
50 long r,s;
51 short int initial_toggle;
52 struct saved *saved;
53 int sxadd,syadd;
54 int j;
55 int sj;
56 
57 XSetFont(display,gc,font[3]);
58 
59 /* need to set flag to plot */
60 
61 /* need to set resource in widget also */
62 
63 XSetFunction(display,gc,GXcopy);
64 
65 XtSetArg(args[0],XtNwidth,&width);
66 XtSetArg(args[1],XtNheight,&height);
67 XtGetValues(drawing_area,args,2);
68 
69 XSIZE=(long)width*10L;
70 YSIZE=(long)height*10L;
71 
72 xrat=(float)XSIZE/(float)12800;
73 yrat=(float)YSIZE/(float)9600;
74 
75 if(xrat < yrat)
76  mult=xrat;
77 else
78  mult=yrat;
79 
80 display_flag=0;
81 h=0;
82 
90 
91 lint1=(long)npoint[0]*(long)MY;
92 lint2=(long)npoint[1]*(long)MY;
93 
94 x=win_x;
95 y=win_y;
96 
97 saved_win_x=win_x;
98 saved_win_y=win_y;
99 
100 if(zoom==1)
101 {
102  win_x=x*MY/mult;
103  win_y=y*MY/mult;
104 }
105 else
106 {
107  win_x=((x*MY-xcen)/zoom + lint1)/mult;
108  win_y=((y*MY-ycen)/zoom + lint2)/mult;
109 }
110 
111 shb5[0]=0;
112 maxdist=9999;
113 
114 saved=fsaved;
115 j=-1;
116 
117 while( saved!=NULL) {
118 
119  j++;
120  if(saved_j >=0 && strcmp(saved->hb5,saved_hb5)!=0)
121  goto nextseg;
122 
123  if(j <= saved_j)
124  goto nextseg;
125 
126  lat=saved->lat;
127  lon=saved->lon;
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  r=dval.a * cos(lat*conv)/(1+sin(lat*conv))
145  * cos((lon-dval.lo-90)*conv) + dval.xo +.5;
146 
147  s=dval.a * cos(lat*conv)/(1+sin(lat*conv))
148  * sin((lon-dval.lo-90)*conv) + dval.yo + .5;
149 
150  testdist= pow((double)(win_x-r),2) + pow((double)(win_y-s),2);
151  testdist= pow(testdist,.5);
152 
153  if(testdist < maxdist) {
154 
155  strcpy(shb5,saved->hb5);
156  strcpy(spc,saved->pc);
157  sxadd=saved->xadd;
158  syadd=saved->yadd;
159  maxdist=testdist;
160  sj=j;
161 
162  }
163 
164 
165  nextseg:
166 
167  saved=saved->next;
168 
169  if(saved==NULL)
170  break;
171 
172  }
173 
174 
175 if(shb5[0]==0) {
176 
177  saved_j=-1;
178  return;
179 
180  }
181 
182 strcpy(saved_hb5,shb5);
183 saved_j=sj;
184 
185 i=0;
186 isave=-1;
187 
188 while(custom[i].hb5[0] != 0) {
189 
190  if(strcmp(shb5,custom[i].hb5)==0 &&
191  strcmp(spc,custom[i].pc)==0) {
192 
193  isave=i;
194  break;
195 
196  }
197 
198  i++;
199 
200  }
201 
202 if(isave==-1) {
203 
204  strcpy(custom[i].hb5,shb5);
205  strcpy(custom[i].pc,spc);
206 
207  custom[i].xadd=sxadd;
208  custom[i].yadd=syadd;
209 
210  isave=i;
211 
212  i++;
213  custom[i].hb5[0]=0;
214 
215  }
216 
217 if(sxadd==-1 && syadd==-1)
218  initial_toggle=0;
219 
220 else if(sxadd==0 && syadd==-1)
221  initial_toggle=2;
222 
223 else if(sxadd==-1 && syadd==0)
224  initial_toggle=1;
225 
226 else if(sxadd==0 && syadd==0)
227  initial_toggle=3;
228 
229 sprintf(buf,"%s %s",shb5,spc);
230 
231 t=XmStringLtoRCreate(buf,XmSTRING_DEFAULT_CHARSET);
232 
233 argcount=0;
234 XtSetArg(args[argcount],XmNmessageString,t);argcount++;
235 XtSetArg(args[argcount],XmNwidth, 250);argcount++;
236 XtSetArg(args[argcount],XmNheight,225);argcount++;
237 XtSetArg(args[argcount],XmNbackground,mmap[1]);argcount++;
238 XtSetArg(args[argcount],XmNforeground,mmap[0]);argcount++;
239 XtSetArg(args[argcount],XmNdialogStyle,
240  XmDIALOG_FULL_APPLICATION_MODAL);argcount++;
241 dialog=XmCreateMessageDialog(drawing_area,"Edit Stations",args,argcount);
242 
243 XtUnmanageChild(XmMessageBoxGetChild(dialog,XmDIALOG_HELP_BUTTON));
244 XtAddCallback(dialog,XmNokCallback,change_custom_file,(XtPointer)isave);
245 XtAddCallback(dialog,XmNhelpCallback,change_custom_file,(XtPointer)isave);
246 
247 argcount=0;
248 XtSetArg(args[argcount],XmNbackground,mmap[1]);argcount++;
249 XtSetArg(args[argcount],XmNforeground,mmap[0]);argcount++;
250 XtSetArg(args[argcount],XmNorientation,XmVERTICAL);argcount++;
251 rowcol=XmCreateRowColumn(dialog,"Edit Stations",args,argcount);
252 
253 t=XmStringLtoRCreate("Station Location",XmSTRING_DEFAULT_CHARSET);
254 argcount=0;
255 XtSetArg(args[argcount],XmNlabelString,t);argcount++;
256 pbutton=XmCreateLabel(rowcol,"Label",args,argcount);
257 XtManageChild(pbutton);
258 
259 argcount=0;
260 XtSetArg(args[argcount],XmNbackground,mmap[1]);argcount++;
261 XtSetArg(args[argcount],XmNforeground,mmap[0]);argcount++;
262 XtSetArg(args[argcount],XmNpacking,XmPACK_COLUMN); argcount++;
263 XtSetArg(args[argcount],XmNnumColumns,2);argcount++;
264 XtSetArg(args[argcount],XmNorientation,XmVERTICAL);argcount++;
265 rowcol3=XmCreateRadioBox(rowcol,"Edit Stations",args,argcount);
266 
267 st[0]="upper left";
268 st[1]="lower left";
269 st[2]="upper right";
270 st[3]="lower right";
271 
272 for(i=0;i<4;i++)
273 {
274  argcount=0;
275  XtSetArg(args[argcount],XmNbackground,mmap[1]);argcount++;
276  XtSetArg(args[argcount],XmNforeground,mmap[0]);argcount++;
277  XtSetArg(args[argcount],XmNselectColor,cmap[4]);argcount++;
278 
279  if(i==initial_toggle)
280  XtSetArg(args[argcount],XmNset,True);
281 
282  else
283  XtSetArg(args[argcount],XmNset,False);
284 
285  argcount++;
286 
287  pbutton=XmCreateToggleButton(rowcol3,st[i],args,argcount);
288  XtAddCallback(pbutton,XmNvalueChangedCallback,change_station_location,(XtPointer)(i));
289  XtManageChild(pbutton);
290 }
291 
292 XtManageChild(rowcol3);
293 XtManageChild(rowcol);
294 XtManageChild(dialog);
295 XmStringFree(t);
296 }
297 
298 void change_station_location(Widget w,XtPointer data,XtPointer call_data)
299 {
300 /*
301 extern struct custom custom[6000];
302 */
303 extern struct custom custom[9000];
304 /* declare informix host variables */
305 /*
306  * exec sql begin declare section;
307  */
308 #line 302 "edit_stations.ec"
309 #line 303 "edit_stations.ec"
310  char line[256];
311  char id[6];
312  char pe1[2];
313  char pe2[2];
314  char dur[2];
315  char t[2];
316  char s[2];
317  char e[2];
318  char p[2];
319 int xoff;
320 int yoff;
321 /*
322  * exec sql end declare section;
323  */
324 #line 314 "edit_stations.ec"
325 
326 
327  if((int)data==0)
328  {
329  custom[isave].xadd=-1;
330  custom[isave].yadd=-1;
331  }
332  else if((int)data==2)
333  {
334  custom[isave].xadd=0;
335  custom[isave].yadd=-1;
336  }
337  else if((int)data==1)
338  {
339  custom[isave].xadd=-1;
340  custom[isave].yadd=0;
341  }
342  else if((int)data==3)
343  {
344  custom[isave].xadd=0;
345  custom[isave].yadd=0;
346  }
347 
348  strcpy(id,custom[isave].hb5);
349  strncpy(pe1,custom[isave].pc+0,1);
350  *(pe1+1)='\0';
351  strncpy(pe2,custom[isave].pc+1,1);
352  *(pe2+1)='\0';
353  strncpy(dur,custom[isave].pc+2,1);
354  *(dur+1)='\0';
355  strncpy(t,custom[isave].pc+3,1);
356  *(t+1)='\0';
357  strncpy(s,custom[isave].pc+4,1);
358  *(s+1)='\0';
359  strncpy(e,custom[isave].pc+5,1);
360  *(e+1)='\0';
361  strncpy(p,custom[isave].pc+6,1);
362  *(p+1)='\0';
363  xoff=custom[isave].xadd;
364  yoff=custom[isave].yadd;
365 
366 /*
367  * $insert into mapper_offsets values
368  * ($id,$pe1,$pe2,$dur,$t,$s,$e,$p,$xoff,$yoff);
369  */
370 #line 355 "edit_stations.ec"
371  {
372 #line 356 "edit_stations.ec"
373  static const char *sqlcmdtxt[] =
374 #line 356 "edit_stations.ec"
375  {
376 #line 356 "edit_stations.ec"
377  "insert into mapper_offsets values ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )",
378  0
379  };
380 #line 356 "edit_stations.ec"
381  static ifx_statement_t _SQ0 = {0};
382  static ifx_sqlvar_t _sqibind[] =
383  {
384  { 100, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
385  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
386  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
387  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
388  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
389  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
390  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
391  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
392  { 102, sizeof(xoff), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
393  { 102, sizeof(yoff), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
394 #line 356 "edit_stations.ec"
395  };
396 #line 356 "edit_stations.ec"
397 #line 356 "edit_stations.ec"
398  _sqibind[0].sqldata = id;
399 #line 356 "edit_stations.ec"
400  _sqibind[1].sqldata = pe1;
401 #line 356 "edit_stations.ec"
402  _sqibind[2].sqldata = pe2;
403 #line 356 "edit_stations.ec"
404  _sqibind[3].sqldata = dur;
405 #line 356 "edit_stations.ec"
406  _sqibind[4].sqldata = t;
407 #line 356 "edit_stations.ec"
408  _sqibind[5].sqldata = s;
409 #line 356 "edit_stations.ec"
410  _sqibind[6].sqldata = e;
411 #line 356 "edit_stations.ec"
412  _sqibind[7].sqldata = p;
413 #line 356 "edit_stations.ec"
414  _sqibind[8].sqldata = (char *) &xoff;
415 #line 356 "edit_stations.ec"
416  _sqibind[9].sqldata = (char *) &yoff;
417  sqli_stmt(ESQLINTVERSION, &_SQ0, sqlcmdtxt, 10, _sqibind, (struct value *)0, (ifx_literal_t *)0, (ifx_namelist_t *)0, (ifx_cursor_t *)0, 6, 0, 0);
418 #line 356 "edit_stations.ec"
419  }
420  if(sqlca.sqlcode)
421  {
422 /*
423  * $update mapper_offsets set(xoff,yoff)=($xoff,$yoff)
424  * where id=$id and pe1=$pe1 and pe2=$pe2 and dur=$dur
425  * and t=$t and s=$s and e=$e and p=$p;
426  */
427 #line 359 "edit_stations.ec"
428  {
429 #line 361 "edit_stations.ec"
430  static const char *sqlcmdtxt[] =
431 #line 361 "edit_stations.ec"
432  {
433 #line 361 "edit_stations.ec"
434  "update mapper_offsets set ( xoff , yoff ) = ( ? , ? ) where id = ? and pe1 = ? and pe2 = ? and dur = ? and t = ? and s = ? and e = ? and p = ?",
435  0
436  };
437 #line 361 "edit_stations.ec"
438  static ifx_statement_t _SQ0 = {0};
439  static ifx_sqlvar_t _sqibind[] =
440  {
441  { 102, sizeof(xoff), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
442  { 102, sizeof(yoff), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
443  { 100, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
444  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
445  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
446  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
447  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
448  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
449  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
450  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
451 #line 361 "edit_stations.ec"
452  };
453 #line 361 "edit_stations.ec"
454 #line 361 "edit_stations.ec"
455  _sqibind[0].sqldata = (char *) &xoff;
456 #line 361 "edit_stations.ec"
457  _sqibind[1].sqldata = (char *) &yoff;
458 #line 361 "edit_stations.ec"
459  _sqibind[2].sqldata = id;
460 #line 361 "edit_stations.ec"
461  _sqibind[3].sqldata = pe1;
462 #line 361 "edit_stations.ec"
463  _sqibind[4].sqldata = pe2;
464 #line 361 "edit_stations.ec"
465  _sqibind[5].sqldata = dur;
466 #line 361 "edit_stations.ec"
467  _sqibind[6].sqldata = t;
468 #line 361 "edit_stations.ec"
469  _sqibind[7].sqldata = s;
470 #line 361 "edit_stations.ec"
471  _sqibind[8].sqldata = e;
472 #line 361 "edit_stations.ec"
473  _sqibind[9].sqldata = p;
474  sqli_stmt(ESQLINTVERSION, &_SQ0, sqlcmdtxt, 10, _sqibind, (struct value *)0, (ifx_literal_t *)0, (ifx_namelist_t *)0, (ifx_cursor_t *)0, 4, 0, 0);
475 #line 361 "edit_stations.ec"
476  }
477  }
478  return;
479 }
480 
481 
482 void change_custom_file(Widget w,XtPointer data, XtPointer call_data)
483 {
484  extern int data_type;
485  extern int indexx;
486  extern char station_list_file[256];
487  int i;
488 /*
489  extern struct custom custom[6000];
490 */
491  extern struct custom custom[9000];
492  FILE *fp;
493 
494 /* declare informix host variables */
495 /*
496  * exec sql begin declare section;
497  */
498 #line 380 "edit_stations.ec"
499 #line 381 "edit_stations.ec"
500  char line[256];
501  char id[6];
502  char pe1[2];
503  char pe2[2];
504  char dur[2];
505  char t[2];
506  char s[2];
507  char e[2];
508  char p[2];
509 int xoff;
510 int yoff;
511 /*
512  * exec sql end declare section;
513  */
514 #line 392 "edit_stations.ec"
515 
516 
517  fp=fopen(station_list_file,"w");
518  if(fp==NULL)
519  return;
520 
521  i=0;
522  while(custom[i].hb5[0] != 0)
523  {
524 
525 /* one time only for initial population of mapper_offsets
526 
527  if(custom[i].xadd || custom[i].yadd)
528  {
529  strcpy(id,custom[i].hb5);
530  strncpy(pe1,custom[i].pc+0,1);
531  *(pe1+1)='\0';
532  strncpy(pe2,custom[i].pc+1,1);
533  *(pe2+1)='\0';
534  strncpy(dur,custom[i].pc+2,1);
535  *(dur+1)='\0';
536  strncpy(t,custom[i].pc+3,1);
537  *(t+1)='\0';
538  strncpy(s,custom[i].pc+4,1);
539  *(s+1)='\0';
540  strncpy(e,custom[i].pc+5,1);
541  *(e+1)='\0';
542  strncpy(p,custom[i].pc+6,1);
543  *(p+1)='\0';
544 
545  xoff=custom[i].xadd;
546  yoff=custom[i].yadd;
547 
548  $insert into mapper_offsets values
549  ($id,$pe1,$pe2,$dur,$t,$s,$e,$p,$xoff,$yoff);
550  if(sqlca.sqlcode)
551  $update mapper_offsets set(xoff,yoff)=($xoff,$yoff)
552  where id=$id and pe1=$pe1 and pe2=$pe2 and dur=$dur
553  and t=$t and s=$s and e=$e and p=$p;
554  }
555 */
556 
557  fprintf(fp,"%s %s %d %d\n",custom[i].hb5,custom[i].pc,custom[i].xadd,custom[i].yadd);
558  i++;
559  }
560 
561  fclose(fp);
563  write_screen();
565 
566  return;
567 }
568 
569 #line 444 "edit_stations.ec"
static int i
struct sqlca_s sqlca
unsigned long mmap[16]
Definition: mapper.c:117
Display * display
Definition: mapper.c:159
Font font[10]
Definition: mapper.c:161
int isave
Definition: edit_stations.c:8
float mult
Definition: edit_stations.c:6
int saved_win_y
Definition: edit_stations.c:9
Widget dialog
Definition: edit_stations.c:7
void edit_stations(int win_x, int win_y, unsigned int win_button)
Definition: edit_stations.c:11
void change_custom_file(Widget w, XtPointer data, XtPointer call_data)
void change_station_location(Widget w, XtPointer data, XtPointer call_data)
int saved_win_x
Definition: edit_stations.c:9
struct stat buf
Definition: is_file_closed.c:8
void write_screen(void)
Definition: mapper.c:1082
void kill_widget(Widget, XtPointer, XtPointer)
Definition: mapper.c:4806
fclose(fp)
sprintf(fbuf,"/usr/mapper/nexrad/ngrid.%02d-%02d-%02d-%02d", year, month, day, hour)
fp
Definition: make_NEXRAD.c:339
fprintf(fp,"%d %d %d %d 1\n", iminx, iminy, maxi, maxj)
int j
Definition: mapp2h.h:48
double lat
Definition: mapp2h.h:41
double lon
Definition: mapp2h.h:41
int indexx
Definition: mapper.c:60
char saved_hb5[6]
Definition: mapper.c:6
struct saved * fsaved
Definition: mapper.c:128
int data_type
Definition: mapper.c:63
char station_list_file[256]
Definition: mapper.c:18
int dflag[10]
Definition: mapper.c:106
int saved_j
Definition: mapper.c:35
unsigned long cmap[16]
Definition: mapper.c:117
int display_flag
Definition: mapper.c:100
void render_data(int, int)
Definition: render_data.c:3
float xrat
long xmax
float value
float yrat
long ymax
long lint1
GC gc
Definition: mapper.c:163
signed long xcen
Dimension height
signed long ycen
Dimension width
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
Definition: misc.h:30
int xadd
Definition: misc.h:34
char hb5[10]
Definition: misc.h:32
int yadd
Definition: misc.h:35
char pc[10]
Definition: misc.h:33
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 yadd
Definition: misc.h:372
char hb5[10]
Definition: misc.h:363
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
struct saved * next
Definition: misc.h:379
float lon
Definition: misc.h:377
long sqlcode
Definition: db.c:44