Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
specplot.c
Go to the documentation of this file.
1 #include "ds_extern.h"
2 
3 #include "dataserv.bmp"
4 
5 #include "sp_proto.h"
6 
7 #define ROW0 (0.96)
8 #define ROW1 (0.92)
9 #define ROW2 (0.88)
10 #define ROW3 (0.84)
11 #define DATASPREAD (0.000001)
12 
13 int debug = 0;
14 int zerodata = 0;
16 
17 int (*sock_callback)() = NULL;
18 char inMsg[16384];
19 
20 static int font0 = FONT_SIZE_SMALL;
21 
24 
25 char *months[] = { "Jan","Feb","Mar","Apr","May","Jun",
26  "Jul","Aug","Sep","Oct","Nov","Dec" };
27 
28 extern int lockScale;
29 extern struct XGR_HEAD xgr_head;
30 struct XGR_ *server;
31 
32 extern int insque(), remque();
33 
34 char deadServer[256], prgName[256], localHost[256], tfile[256],
35  title[256], mainFrameTitle[256];
36 static char *spaces = " ";
37 
38 struct SOCK *dataserv, *helper;
39 
40  /* DO NOT FORGET TO ADD A HANDLER FOR ANY EXTRA MASKS ADDED, processEvent() */
41 long frame_mask = KeyPressMask | ExposureMask | StructureNotifyMask;
42 
43 struct OTF_STRUCT *myotf;
44 
45 struct MAIL_PARSE {
46  char *msg;
47  int log;
48  int save_config;
49  int count;
50  int type;
51  char *format;
52  void *ptr;
53  int len;
54  int (*fctn)();
55  char *help;
56 };
57 
58 
59 struct MAIL_PARSE parse_table[] = {
60  /* Commands that change internal variables and are saved to dataserv.conf */
61 /* msg, log, save, cnt, type, fmt, *ptr, len, fctn(), *help */
62  { "help", 0, 0, 0, 0, NULL, NULL, 4, do_help, "Displays this list"},
63  { "quit", 0, 0, 0, 0, NULL, NULL, 4, do_quit, "Exit program"},
64  { NULL, 0, 0, 0, 0, NULL, NULL, 0, (void *)0, NULL }
65 };
66 
67 struct STURCT_KEYSYMS {
68  KeySym sym;
69  int win;
70  char *key;
71  char *help;
72 };
73 
74 struct STURCT_KEYSYMS keysyms[] = {
75  { XK_Up, 1, "Up-Arrow", "Move Integration Region Up" },
76  { XK_Down, 1, "Down-Arrow", "Move Integration Region Down" },
77  { XK_Up, 1, "<Control> Up-Arrow", "Move Upper Integration Channel Up" },
78  { XK_Down, 1, "<Control> Down-Arrow", "Move Upper Integration Channel Down" },
79  { XK_Up, 1, "<shift> Up-Arrow", "Move Lower Integration Channel Up" },
80  { XK_Down, 1, "<shift> Down-Arrow", "Move Lower Integration Channel Down" },
81  { XK_p, 1, "<control> + p", "Screen Capture Spectrum Plot" }
82 };
83 
84 #define MAX_KEYSYMS (sizeof(keysyms) / sizeof(struct STURCT_KEYSYMS))
85 
86 int to_helper(buf)
87 char *buf;
88 {
89  if(buf)
90  {
91  log_msg("To HELPER: '%s'", buf);
92 
93  sock_send(helper, buf);
94  }
95 
96  return(0);
97 }
98 
99 
100 int to_dataserv(buf)
101 char *buf;
102 {
103  if(buf)
104  {
105  log_msg("To DATASERV: '%s'", buf);
106 
107  sock_send(dataserv, buf);
108  }
109 
110  return(0);
111 }
112 
113 
114 int do_quit()
115 {
116  signalHandler();
117 
118  return(0);
119 }
120 
122 {
123  int i;
124  char tbuf[256];
125  struct STURCT_KEYSYMS *k;
126 
127  sprintf(tbuf, "Press the Following Keys in Either the OTF or Spectral Plot Windows\n");
128 
129  printf("\n%s\n", tbuf);
130  log_msg(" ");
131  log_msg(tbuf);
132  log_msg(" ");
133 
134  k = &keysyms[0];
135  for(i=0;i<MAX_KEYSYMS;i++,k++)
136  {
137  if(k->win == 0)
138  {
139  sprintf(tbuf, "Press %s key for %s", k->key, k->help);
140  printf("%s\n", tbuf);
141 
142  log_msg(tbuf);
143  }
144  }
145 
146  sprintf(tbuf, "Press the Following Keys Spectral Plot Windows\n");
147 
148  printf("\n%s\n", tbuf);
149  log_msg(" ");
150  log_msg(tbuf);
151  log_msg(" ");
152 
153  k = &keysyms[0];
154  for(i=0;i<MAX_KEYSYMS;i++,k++)
155  {
156  if(k->win == 1)
157  {
158  sprintf(tbuf, "Press %s key for %s", k->key, k->help);
159  printf("%s\n", tbuf);
160 
161  log_msg(tbuf);
162  }
163  }
164 
165  return(0);
166 }
167 
168 
169 int do_help(buf)
170 char *buf;
171 {
172  struct MAIL_PARSE *p;
173  char tbuf[128];
174  char *cp;
175 
176  cp = strtok(buf, " \n\t");
177 
178  sprintf(tbuf, "Command Arguments\n");
179  printf("\n%s\n", tbuf);
180 
181  log_msg(tbuf);
182 
183  for(p=parse_table;p->msg;p++)
184  {
185  if(cp)
186  {
187  if(!strncmp(p->msg, cp, strlen(cp)))
188  {
189  sprintf(tbuf, "%s: %s", p->msg, spaces);
190  strcpy(tbuf+18, p->help);
191  printf("%s\n", tbuf);
192 
193  log_msg(tbuf);
194  }
195  }
196  else
197  {
198  sprintf(tbuf, "%s: %s", p->msg, spaces);
199  strcpy(tbuf+18, p->help);
200  printf("%s\n", tbuf);
201 
202  log_msg(tbuf);
203  }
204  }
205 
206  printKeySymHelp();
207 
208  return(0);
209 }
210 
212 {
213  if(debug)
214  {
215  log_msg("doSpecWinRepaint()");
216  }
217 
218  if(last_image.freqres > 0.0)
219  {
221  }
222 
223  return(0);
224 }
225 
226 
228 {
229  if(debug)
230  {
231  log_msg("doSpecWinReSize()");
232  }
233 
234  return(0);
235 }
236 
237 
238 int putChanTemp(c, t)
239 int c;
240 float t;
241 {
242  char tbuf[256];
243 
245 
246  sprintf(tbuf, "Chan: %4d; Intensity: %6.3fK", c, t);
247  xgr_drawTextClear(0.05, ROW3, tbuf, MAGENTA, font0);
248 
249  xgr_pixmapToWindow("Spectral Plot Window");
250 
252 
253  return(0);
254 }
255 
256 
257 int checkKeyPress(event)
258 XEvent *event;
259 {
260  KeySym keysym;
261  XComposeStatus compose;
262  char buffer[1], tbuf[256];
263  char fname[256], sysBuf[256];
264  int bufsize=1, change = 0;
265 
266  int int_chans[2];
267  int noint;
268 
269  if(last_image.freqres == 0.0)
270  {
271  log_msg("No map to plot");
272 
273  return(1);
274  }
275 
276  int_chans[0] = last_image.int_beg;
277  int_chans[1] = last_image.int_end;
278  noint = last_image.noint;
279 
280  XLookupString((XKeyEvent *)event, buffer, bufsize, &keysym, &compose);
281 
282  if(keysym == XK_p && event->xkey.state & ControlMask)
283  {
284  if(event->xkey.state & ControlMask) /* Print screen */
285  {
286  sprintf(fname, "SpectralPlot-%s.png", getLogDate(0));
287 
288  sprintf(sysBuf, "import -w 0x%x %s", (unsigned int)event->xany.window, fname);
289 
290  log_msg("%s", sysBuf);
291 
292  system(sysBuf);
293 
294  printf("Created file: %s\n", fname);
295  }
296  }
297  else
298  if(keysym == XK_Up && event->xkey.state & ControlMask) /* Raise the upper channel only */
299  {
300  int_chans[1]++;
301 
302  if(int_chans[1] > noint-1) /* Don't exceed number of chans */
303  {
304  int_chans[1] = noint -1;
305  }
306 
307  change = 1;
308  }
309  else
310  if(keysym == XK_Down && event->xkey.state & ControlMask) /* Lower the upper channel only */
311  {
312  int_chans[1]--;
313 
314  if(int_chans[1] < int_chans[0]) /* Don't go below lower chan */
315  {
316  int_chans[1] = int_chans[0];
317  }
318 
319  change = 1;
320  }
321  else
322  if(keysym == XK_Up && event->xkey.state & ShiftMask) /* Raise the lower channel only */
323  {
324  int_chans[0]++;
325 
326  if(int_chans[0] > int_chans[1]) /* Don't exceed upper chan */
327  {
328  int_chans[0] = int_chans[1];
329  }
330 
331  change = 1;
332  }
333  else
334  if(keysym == XK_Down && event->xkey.state & ShiftMask) /* Lower the lower channel only */
335  {
336  int_chans[0]--;
337 
338  if(int_chans[0] < 0) /* Don't go below 0 */
339  {
340  int_chans[0] = 0;
341  }
342 
343  change = 1;
344  }
345  else
346  if(keysym == XK_Up)
347  {
348  int_chans[0]++;
349  int_chans[1]++;
350 
351  if(int_chans[1] > noint-1)
352  {
353  int_chans[1] = noint -1;
354  }
355 
356  if(int_chans[0] > int_chans[1])
357  {
358  int_chans[0] = int_chans[1];
359  }
360 
361  change = 1;
362  }
363  else
364  if(keysym == XK_Down)
365  {
366  int_chans[0]--;
367  int_chans[1]--;
368 
369  if(int_chans[0] < 0)
370  {
371  int_chans[0] = 0;
372  }
373 
374  if(int_chans[1] < int_chans[0])
375  {
376  int_chans[1] = int_chans[0] +1;
377  }
378 
379  change = 1;
380  }
381  else
382  if(keysym == XK_P)
383  {
384  log_msg("Shift P pressed");
385  }
386 
387  if(change)
388  {
389  sprintf(tbuf, "otfchans %d %d", int_chans[0], int_chans[1]);
390  to_dataserv(tbuf);
391 
392  sprintf(tbuf, "otf_bint_chan = %d /q", int_chans[0]);
393  to_helper(tbuf);
394  sprintf(tbuf, "otf_eint_chan = %d /q", int_chans[1]);
395  to_helper(tbuf);
396 
397  }
398 
399  return(0);
400 }
401 
402 
403 
404 int doSpecPlotWinEvent(event, mask)
405 XEvent *event;
406 unsigned int mask;
407 {
408  int chan;
409  struct WINDOW *w;
410  float x,y, fchan;
411  struct DS_IMAGE_INFO *im;
412 
413  im = &last_image;
414 
415  if(debug)
416  {
417  log_msg("doSpecPlotWinEvent()");
418  }
419 
420  if(im->freqres == 0.0)
421  {
422  log_msg("No Spectral Plot");
423  return(1);
424  }
425 
426  switch(event->type)
427  {
428  case MotionNotify:
429  case ButtonPressMask:
430  break;
431 
432  case KeyPress:
433  checkKeyPress(event);
434  return(1);
435  break;
436 
437  default:
438  return(1);
439  break;
440  }
441 
442  if( xgr_findWindow(event->xbutton.display, event->xbutton.window, &w))
443  {
444  log_msg("xgr_findWindow() returned Non Zero");
445 
446  return(1);
447  }
448 
449  x = ((float)w->plotxe - (float)w->plotxb);
450  x = ((float)event->xbutton.x - (float)w->plotxb) / x - 0.5;
451 
452  y = ((float)w->plotye - (float)w->plotyb);
453  y = ((float)w->plotye - (float)event->xbutton.y) / y - 0.5;
454 
455  fchan = (float)im->noint;
456 
457  fchan = x * fchan + (fchan / 2.0);
458 
459  chan = floor(fchan);
460 
461  if(chan < 0)
462  {
463  chan = 0;
464  }
465  else
466  if(chan > im->noint-1)
467  {
468  chan = im->noint-1;
469  }
470 
471  if(debug)
472  {
473  log_msg("X = %f, Y = %f, Chan = %.2f, %d = %f", x, y, fchan, chan, im->ydata[chan]);
474  }
475 
476  putChanTemp(chan, im->ydata[chan]);
477 
478  return(0);
479 }
480 
481 
482 char *vxstrtok(string, last_token, delim)
483 char *string, *last_token, *delim;
484 
485 /* char *vxstrtok(char *string, char *last_token, char *delim) --
486  * Like strtok, but can be used in VxWorks. The first call passes a non-NULL
487  * "string". A pointer to the first character in "string" not in "delim" is
488  * returned (or NULL if none). The next occurance of a character in "delim"
489  * past this first character is set to NUL and a second NUL is appended to
490  * "string". Subsequent calls must pass a NULL pointer "string" and the
491  * previous return value ("last_token"). In these calls, the NUL following
492  * last_token is replaced by the first character in "delim" and the scan
493  * continues until the next non-"delim" past this point is found or the
494  * end of the string is found (NULL returned). Again, if a non-"delim"
495  * character is found, the next "delim" character following it is replaced by
496  * a NUL.
497  */
498 
499 {
500  int n, i;
501  char *ptr, *ret;
502 
503  if(string) {
504  /* First call on a new string */
505  string[strlen(string)+1] = '\0'; /* Add a second NUL to the end */
506  ptr = string;
507  } else if(!last_token || !*last_token || !delim || !*delim)
508  return NULL;
509  else {
510  /* A subsequent call on the same string */
511  ptr = last_token + strlen(last_token); /* End of previous token */
512  *ptr++ = delim[0]; /* Put a delimiter back */
513  }
514  /* Scan for the next non-"delim" character */
515  for(n=strlen(delim); *ptr; ptr++) {
516  for(i=0; i < n && *ptr != delim[i]; i++)
517  continue;
518  if(i == n)
519  break; /* Found one */
520  }
521  if(!*ptr)
522  return NULL; /* End of string */
523 
524  ret = ptr++; /* Save beginning of token */
525 
526  /* Scan for next "delim" character */
527  for( ; *ptr; ptr++) {
528  for(i=0; i < n && *ptr != delim[i]; i++)
529  continue;
530  if(i != n)
531  break; /* Found one */
532  }
533  *ptr = '\0'; /* Mark the end */
534  return ret; /* Return the beginning */
535 }
536 
537 
538 
539 int readMail(buf, len)
540 char *buf;
541 int len;
542 {
543  char *cp;
544  static char cmdbuf[4096];
545 
546  if(len == sizeof(struct DS_IMAGE_INFO))
547  {
548 // log_msg("Got IMAGE struct");
549 
550  bcopy(buf, (char *)&last_image, len);
551 
553 
554  return(0);
555  }
556 
557  log_msg("readMail(): Got %d bytes, %s", len, buf);
558 
559  if(buf || len < sizeof(cmdbuf))
560  {
561  cp = vxstrtok(buf, NULL, "\n");
562  while(cp)
563  {
564  strcpy(cmdbuf, cp);
565  parseMail(cmdbuf);
566  cp = vxstrtok(NULL, cp, "\n");
567  }
568  }
569 
570  return(0);
571 }
572 
573 
574 int parseMail(buf)
575 char *buf;
576 {
577  char *s;
578  struct MAIL_PARSE *p;
579 
580  deNewLineIt(buf);
581 
582  strlwr(buf);
583 
584  for(p=parse_table;p->msg;p++)
585  {
586  if(!strncmp(p->msg, buf, p->len))
587  {
588  if(p->log && strlen(buf) < 2048)
589  {
590  s = (char *)sock_name(last_msg());
591  if(s)
592  log_msg("%s: (%s) %s", prgName, sock_name(last_msg()), buf);
593  else
594  log_msg("%s: %s", prgName, buf);
595  }
596 
597  p->fctn(buf+p->len);
598 
599  return(0);
600  }
601  }
602 
603  log_msg("Command %s NOT found", buf);
604 
605  return(0);
606 }
607 
608 
609 int myIOErrorHandler(display, myerr)
610 Display *display;
611 XErrorEvent *myerr;
612 {
613  if(display)
614  {
615  log_msg("Server %s caused IO Trap", DisplayString(display));
616  strcpy(deadServer, DisplayString(display));
617  }
618  else
619  {
620  log_msg("Server: Unknown Server caused IO Trap");
621  strcpy(deadServer, "Unknown Server");
622  }
623  exit(2);
624 }
625 
626 
627 
628 int myErrorHandler(display, myerr)
629 Display *display;
630 XErrorEvent *myerr;
631 {
632  if(display)
633  {
634  log_msg("Server %s caused Xlib Error", DisplayString(display));
635  strcpy(deadServer, DisplayString(display));
636  }
637  else
638  {
639  log_msg("Server: Unknown Server caused Xlib Error");
640  strcpy(deadServer, "Unknown Server");
641  }
642  return(0);
643 }
644 
645 
646 
648 {
649  struct XGR_HEAD *p;
650  struct XGR_ *s;
651 
652  exit(1);
653 
654  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
655  {
656  s = (struct XGR_ *)p;
657  if(s->dpy)
658  {
659  log_msg("Signal: Shuting Down Server %s", DisplayString(s->dpy));
660  XFlush(s->dpy);
661  XCloseDisplay(s->dpy);
662  }
663  }
664 }
665 
666 int exitProc(status)
667 int status;
668 {
669  log_msg("Exiting with status %d", status);
670 
671  return(status);
672 }
673 
674 
676 struct XGR_ *s;
677 {
678  XEvent event;
679 /*
680  struct WINDOW *xgr_getWin();
681  */
682 
683  while(XPending(s->dpy))
684  {
685  XNextEvent(s->dpy, &event);
686 
687  switch( event.type )
688  {
689  case Expose:
690  /* Filter down to the last Expose event */
691  while (XCheckTypedWindowEvent(s->dpy, event.xany.window, Expose, &event))
692  {
693  ;
694  }
695 
696  xgr_rePaintProc(event.xexpose.window);
697 
698  break;
699 
700  case ConfigureNotify:
701 
702  /* Filter down to the last ConfigureNotify event */
703  while (XCheckTypedWindowEvent(s->dpy, event.xany.window, ConfigureNotify, &event))
704  {
705  ;
706  }
707 
708  if(event.xconfigure.window && !event.xconfigure.send_event)
709  {
710  xgr_reSizeProc(event.xconfigure.window, event.xconfigure.width, event.xconfigure.height);
711  }
712 
713  break;
714 
715  case ButtonPress:
716  xgr_eventProc(&event, event.xbutton.window, ButtonPress);
717  break;
718 
719  case MotionNotify:
720  xgr_eventProc(&event, event.xbutton.window, MotionNotify);
721  break;
722 
723  case KeyPress:
724  xgr_eventProc(&event, event.xbutton.window, KeyPress);
725  break;
726 
727  case UnmapNotify:
728  break;
729 
730  case DestroyNotify:
731  log_msg("Destroy");
732 
733  exit((int)3);
734 
735  break;
736 
737  default:
738  break;
739  }
740  }
741 
742  return(0);
743 }
744 
745 
746  /* Create an X11 image given a desired width, height and depth. */
747 XImage *createXimage(display, w, h, depth)
748 Display *display;
749 int w, h, depth;
750 {
751  Visual *visual;
752  XImage *xi;
753  unsigned ui;
754 
755  visual = DefaultVisual(display, DefaultScreen(display));
756 
757  if(depth == 1)
758  {
759  return((XImage *)NULL);
760  }
761 
762  xi = XCreateImage(display, visual, (unsigned int)depth, ZPixmap,0,
763  (char *)NULL, (unsigned int)w, (unsigned int)h, 16, 0);
764  if(xi == NULL)
765  {
766  log_msg("XCreateImage failed");
767  return((XImage *)NULL);
768  }
769 
770  ui = (unsigned)(xi->height*xi->bytes_per_line*sizeof(char));
771  if((xi->data=(char *)malloc(ui))==NULL)
772  {
773  log_msg("Unable to malloc(%d) ximage in createXimage()", ui);
774  XDestroyImage(xi);
775  return((XImage *)NULL);
776  }
777 
778  bzero((char *)xi->data, xi->height * xi->bytes_per_line * sizeof(char));
779 
780  return(xi);
781 }
782 
783 
784 
786 float *ydata;
787 int dl;
788 float scan;
789 {
790  int i;
791 
792  if(ydata == NULL)
793  return(1);
794  /* redetermine min and max */
795  datamax = -9999999999.9;
796  datamin = 9999999999.0;
797 
798  for(i=0;i<dl;i++)
799  {
800  if(ydata[i] > datamax)
801  datamax = ydata[i];
802  if(ydata[i] < datamin)
803  datamin = ydata[i];
804  }
805 
806  if(fabs(datamax - datamin) < DATASPREAD)
807  {
808  log_msg("determine_min_max(): Scan #%7.2f is all %.4f", scan, datamin);
809 
810  datamin -= 1.0;
811  datamax += 1.0;
812 
813  return(1);
814  }
815  return(0);
816 }
817 
818 
819 int putHeader(image)
820 struct DS_IMAGE_INFO *image;
821 {
822  int mon, day, yr;
823  char raStr[20], decStr[20], timeStr[20], mapStr[60], buf[256];
824  extern struct XGR_ *server;
825 
826  xgr_setFont(server, font0);
827 
828  sexagesimal(image->time / 3600, timeStr, DDD_MM_SS_S100);
829  strcmprs(timeStr);
830 
831  sexagesimal(image->ra, raStr, DD_MM_SS);
832  sexagesimal(image->dec, decStr, DD_MM_SS);
833 
834  yr = (int)image->date;
835  mon = (int)((image->date - (float)yr) * 100.0);
836  day = (int)((image->date - (float)yr) * 10000.0 +0.5)-mon*100.0;
837 
838  sprintf(buf, "%16.16s %3d SCANS: %7.2f-%7.2f INT=%s DATE: %2d %s %2.2d",
839  image->source,
840  image->scanct,
841  image->bscan,
842  image->escan,
843  timeStr, day, months[mon-1], yr-2000);
844 
845  xgr_drawText(0.05, ROW0, buf, MAGENTA, font0);
846 
847  if(image->col >=0)
848  {
849  sprintf(mapStr," Col %3d Row %3d ", image->col,image->row);
850  }
851  else
852  {
853  sprintf(mapStr, "( %s %s )", raStr, decStr);
854  }
855 
856  sprintf(buf, "%s=%s %s %s CAL= %5.1f TSYS= %5.0f",
857  image->coordcd,
858  raStr,
859  decStr,
860  mapStr,
861  image->cal,
862  image->tsys);
863 
864  xgr_drawText(0.05, ROW1, buf, MAGENTA, font0);
865 
866  sprintf(buf, "FREQ= %.2f SYN= %10.8f VEL= %7.1f DV= %6.2f FR= %4.0f SB= %d",
867  image->freq,
868  image->synfreq / 1000.0,
869  image->vel,
870  image->dv,
871  image->freqres * 1000.0,
872  image->sb );
873  xgr_drawText(0.05, ROW2, buf, MAGENTA, font0);
874 
875  sprintf(buf, "Rms %8.3fK",image->rms);
876  xgr_drawText(0.80, ROW3, buf, MAGENTA, font0);
877 
878  return(0);
879 }
880 
881 
882 
883 int display_image(xb, xe, yb, ye, im)
884 float xb, xe, yb, ye;
885 struct DS_IMAGE_INFO *im;
886 {
887  float *xdata;
888  int i, noint;
889  float scale;
890 // char temp[80];
891  float *data;
892 
893  if(debug)
894  {
895  log_msg("display_image();");
896  }
897 
898  data = &im->ydata[0];
899 
900  noint = (int)im->noint;
901 
902  zerodata = 0;
903  if(!lockScale)
904  {
905  if( determine_min_max(data, noint, im->bscan))
906  {
907  zerodata = 1;
908  }
909  }
910 
911  scale = ye -yb;
912 // sprintf(temp, " %7.2f %8.8s", im->scan, im->backend);
913 // xgr_drawText(xb, 0.905*scale + yb, temp, RED, font0);
914  xgr_drawBox(xb, 0.05*scale + yb, xe, 0.90*scale + yb, GRAY50);
915 
916  /* Initialize the x-axis data points */
917  if( (xdata = (float *)malloc((unsigned)(noint*sizeof(float)))) == NULL)
918  {
919  log_perror("malloc(xdata)");
920  return(-1);
921  }
922 
923 #ifdef TOMMIE
924  /* Set the x-axis data points */
925  startRes = (float)im->refpt*im->freqres;
926 
927  if( im->sb == 2.0) /* LSB */
928  {
929  for(i=0;i<noint;i++)
930  {
931  xdata[i] = startRes + ((float)i*im->freqres);
932  }
933  }
934  else
935  {
936  for(i=0;i<noint;i++) /* USB */
937  {
938  xdata[i] = -startRes - ((float)i*im->freqres);
939  }
940  }
941 #else
942  for(i=0;i<noint;i++)
943  {
944  xdata[i] = (float)i;
945  }
946 #endif
947 
948  globalStart = xdata[0];
949  globalStop = xdata[noint-1];
950 
951  xgr_drawBin(xdata, data, noint, GREEN);
952 
953  if(zerodata)
954  {
955  xgr_drawText(xb, 0.8*scale + yb, "Data is Zero", RED, font0);
956  }
957 
958  free((char *)xdata);
959 
960  return(1);
961 }
962 
963 
964 int doSpecPlot(im)
965 struct DS_IMAGE_INFO *im;
966 {
967  int i;
968  float xmin, xmax, ymin, ymax, yavg, xl, yt, xr, yb;
969  extern float globalYMin, globalYMax;
970  extern int drawGrid;
971 
972  if(debug)
973  {
974  log_msg("doSpecPlot():");
975  }
976 
977  xgr_mapUnmapWindow("Spectral Plot Window", 1);
978 
980 
981  xgr_clearScreen();
982 
983  im->freqres = 1.0;
984 
985  drawGrid = 1;
986  display_image(0.05, 0.98, 0.01, 0.92, im);
987  drawGrid = 0;
988 
989  if(im->doBaseline)
990  {
991  xmin = globalStart;
992  xmax = globalStop;
993  ymin = globalYMin;
994  ymax = globalYMax;
995  yavg = (ymax - ymin) / 15.0;
996 
997  if(debug)
998  {
999  log_msg("Baselines: %d %d %d %d %d %d %d %d",
1000  im->baselines[0],
1001  im->baselines[1],
1002  im->baselines[2],
1003  im->baselines[3],
1004  im->baselines[4],
1005  im->baselines[5],
1006  im->baselines[6],
1007  im->baselines[7]);
1008 
1009  }
1010  for(i=0;i<8;i+=2)
1011  {
1012  if(im->baselines[i] > 0 && im->baselines[i+1] > 0 )
1013  {
1014  xl = (float)im->baselines[i];
1015  xr = (float)im->baselines[i+1];
1016  yt = -yavg;
1017  yb = yavg;
1018 
1019  if(debug)
1020  {
1021  log_msg("Put Rectangles(): %f %f %f %f %f %f %f %f %f %f",
1022  startRes, im->freqres, xmin, xmax, ymin, ymax, xl, yt, xr, yb);
1023  }
1024 
1025  xgr_drawRectangle( xmin, xmax, ymin, ymax, xl, yt, xr, yb, BLUE, 0);
1026  }
1027  }
1028  }
1029 
1030  if(im->int_beg >= 0 && im->int_end >= im->int_beg && im->int_end < im->noint-2)
1031  {
1032  xmin = globalStart;
1033  xmax = globalStop;
1034  ymin = globalYMin;
1035  ymax = globalYMax;
1036  yavg = (ymax - ymin) / 15.0;
1037 
1038  xl = (float)im->int_beg;
1039  xr = (float)im->int_end;
1040  yt = -yavg;
1041  yb = datamax;
1042 
1043  xgr_drawRectangle( xmin, xmax, ymin, ymax, xl, yt, xr, yb, YELLOW, 0);
1044  }
1045 
1046  putHeader(im);
1047 
1048  xgr_pixmapToWindow("Spectral Plot Window");
1049 
1051 
1052  return(0);
1053 }
1054 
1055 
1056 
1057 /* Create individual window */
1058 
1059 struct WINDOW *createWindow(s, title, cw, ch, xpos, ypos, bg, usPixmap, which)
1060 struct XGR_ *s;
1061 char *title;
1062 int cw, ch, xpos, ypos, bg, usPixmap, which;
1063 {
1064  unsigned long value_mask;
1065  XSetWindowAttributes attr;
1066  XSizeHints size_hints;
1067  struct WINDOW *w;
1068  XWMHints wm_hints;
1069  XTextProperty *wi, *ic;
1070 
1071  if((w = (struct WINDOW *)calloc(1, sizeof(struct WINDOW ))) == NULL)
1072  {
1073  log_msg("error in calloc for main Plot window");
1074  exit(1);
1075  }
1076 
1077  insque(w, s->windows.prev);
1078 
1079  strcpy(w->frameTitle, title);
1080  w->canw = cw;
1081  w->canh = ch;
1082  w->background = bg;
1083  w->first = 1;
1084  w->win = XCreateSimpleWindow(s->dpy, RootWindow(s->dpy,s->scr_num),
1085  xpos, ypos, (unsigned int)w->canw,
1086  (unsigned int)w->canh,
1087  1, s->colors[WHITE], /* fg */
1088  s->colors[BLACK]); /* bg */
1089  w->usPixmap = usPixmap;
1090 
1091  if(w->usPixmap)
1092  {
1093  if(!(w->pixmap = XCreatePixmap(s->dpy, w->win, (unsigned int)w->canw, (unsigned int)w->canh, s->depth)))
1094  {
1095  log_msg("%s: Error in create of off screen pixmap\n", prgName);
1096  exit(1);
1097  }
1098  }
1099 
1100  if(which == XGR_SPEC_WIN)
1101  {
1102  XSelectInput(s->dpy,w->win, frame_mask | ButtonPressMask | Button1MotionMask);
1103  }
1104 
1105  size_hints.flags = PPosition | PSize | PMinSize/* | PAspect*/;
1106  size_hints.min_width = cw;
1107  size_hints.min_height = ch;
1108  size_hints.x = xpos;
1109  size_hints.y = ypos;
1110 
1111  w->gc = XCreateGC(s->dpy, RootWindow(s->dpy, s->scr_num), (unsigned long)0, (XGCValues *)NULL);
1112 
1113  w->invalid = 1;
1114 
1115  w->icon = XCreateBitmapFromData(s->dpy, w->win, dataserv_bmp_bits,
1116  dataserv_bmp_width,
1117  dataserv_bmp_height);
1118 
1119  XSetStandardProperties(s->dpy, w->win,
1120  w->frameTitle, (char *)NULL, w->icon,
1121  (char **)NULL, 0, &size_hints);
1122  wi = NULL;
1123  ic = NULL;
1124 
1125  wm_hints.initial_state = NormalState;
1126  wm_hints.input = True;
1127  wm_hints.icon_pixmap = 0;
1128  wm_hints.flags = StateHint | InputHint | WindowGroupHint;
1129  wm_hints.window_group = w->win;
1130 
1131  XSetWMProperties(s->dpy, w->win, wi, ic, NULL, 0, &size_hints, &wm_hints, NULL);
1132 
1133 
1134  if(DoesBackingStore(XDefaultScreenOfDisplay(s->dpy)))
1135  {
1136  if(debug)
1137  {
1138  log_msg("createWindow(): Setting Backing Store for Plot Window");
1139  }
1140 
1141  value_mask = CWBackingStore;
1142  attr.backing_store = WhenMapped;
1143  XChangeWindowAttributes(s->dpy, w->win, value_mask, &attr);
1144  }
1145 
1146  XMapWindow(s->dpy, w->win);
1147  w->mapped = 1;
1148 
1149  XSetWindowBackground(s->dpy, w->win, s->colors[w->background]);
1150  XSetBackground(s->dpy, w->gc, s->colors[w->background]);
1151  XClearWindow(s->dpy, w->win);
1152 
1153  s->cur = w;
1154 
1155  return(w);
1156 }
1157 
1158 
1159 
1160 int createWindows(s, title, cw, ch, xpos, ypos, bg, usPixmap)
1161 struct XGR_ *s;
1162 char *title;
1163 int cw, ch, xpos, ypos, bg, usPixmap;
1164 {
1165  int x, y, w, h;
1166  struct WINDOW *win;
1167 
1168  log_msg("DisplayInfo for %s - %s major %d minor %d release %d",
1169  DisplayString(s->dpy), ServerVendor(s->dpy), ProtocolVersion(s->dpy),
1170  ProtocolRevision(s->dpy), VendorRelease(s->dpy));
1171 
1172  s->xfd = XConnectionNumber(s->dpy);
1173  s->scr_num = DefaultScreen(s->dpy);
1174  s->numFonts = XGR_MAX_FONTS;
1175  s->fontNames = findFixedFonts(s->dpy, &s->numFonts);
1176  s->windows.prev = s->windows.next = &s->windows;
1177  s->depth = XDefaultDepthOfScreen(XDefaultScreenOfDisplay(s->dpy));
1178  s->userXimage = NULL;
1179 
1180  x = xpos;
1181  y = ypos;
1182  w = cw;
1183  h = ch;
1184 
1185  /* create Spectral Plotting window */
1186  win = createWindow(s, "Spectral Plot Window", w, h, x, y, bg, usPixmap, XGR_SPEC_WIN);
1190  s->specwin = win;
1191 
1192  xgr_graphInit(s);
1193 
1194  return(0);
1195 }
1196 
1197 
1198 static int block_for_event(xfd, n)
1199 int *xfd;
1200 int n;
1201 {
1202  int len, i;
1203  static int sel = 1;
1204 
1205  sel = sock_sel(inMsg, &len, xfd, n, 10, 0);
1206 
1207  if( sel == -1 )
1208  { /* timeout */
1209  return(sel);
1210  }
1211 
1212  for(i=0;i<n;i++)
1213  {
1214  if(sel == xfd[i])
1215  {
1216  return(sel);
1217  }
1218  }
1219 
1220  if(sock_callback)
1221  {
1222  (*sock_callback)(inMsg, len);
1223  }
1224 
1225  return(sel);
1226 }
1227 
1228 
1229 
1231 {
1232  struct XGR_HEAD *p, *p2;
1233  struct XGR_ *s, *f;
1234  int count, n, xfd;
1235  int xfds[256];
1236 
1237  while (1)
1238  {
1239  count=0;
1240 
1241  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
1242  {
1243  s = (struct XGR_ *)p;
1244 
1245  if(XPending(s->dpy))
1246  {
1247  processEvent(s);
1248  count++;
1249  }
1250  }
1251 
1252  if(!count)
1253  {
1254  n=0;
1255 
1256  for(p2=xgr_head.next;p2!=&xgr_head;p2=p2->next)
1257  {
1258  f = (struct XGR_ *)p2;
1259  xfds[n] = f->xfd;
1260  n++;
1261  }
1262 
1263  xfd = block_for_event(xfds, n);
1264 
1265  for(p2=xgr_head.next;p2!=&xgr_head;p2=p2->next)
1266  {
1267  f = (struct XGR_ *)p2;
1268 
1269  if(xfd == f->xfd)
1270  {
1271  if(XPending(f->dpy) == 0)
1272  {
1273  if(f->dpy == server->dpy) /* is it the main one */
1274  exit(0);
1275 
1276  log_msg("Removeing %s in destoryFunc", DisplayString(f->dpy));
1277  remque(f);
1278  xgr_freeWindows(f);
1279 
1280  break;
1281  }
1282  }
1283  }
1284  }
1285  }
1286 
1287  return(0);
1288 }
1289 
1290 
1292 int (*call)();
1293 {
1294  sock_callback = call;
1295 
1296  return(0);
1297 }
1298 
1299 
1300 int main(argc, argv)
1301 int argc;
1302 char *argv[];
1303 {
1304  int cw, ch, bg;
1305  int xpos, ypos;
1306  char *cp;
1307 
1309 
1310  setpgid( (pid_t)0, (pid_t)0); /* divorce myself from parents */
1311 
1312  atexit((void *)exitProc);
1313 
1314  signal(SIGINT, (__sighandler_t)signalHandler);
1315  signal(SIGTERM, (__sighandler_t)signalHandler);
1316 
1317  strcpy(prgName, "DATASERV");
1318 
1319  cp = getenv("LPSESSION");
1320 
1321  if(cp)
1322  {
1323  sprintf(tfile, "LOGDIR=/tmp/%s", cp);
1324  putenv(tfile);
1325  }
1326 
1327  smart_log_open("specplot", 3);
1329 
1330  cp = getenv("DISPLAY");
1331  if(cp)
1332  sprintf(localHost,"%s",cp);
1333 
1335 
1336  if((server=(struct XGR_ *)calloc(1,sizeof(struct XGR_)))==NULL)
1337  {
1338  log_msg("error in calloc for main server");
1339  return(1);
1340  }
1341 
1342  insque(server, xgr_head.prev);
1343 
1344  xpos = 0;
1345  ypos = 910;
1346  cw = 720;
1347  ch = 480;
1348 
1349  strcpy(server->serverName, localHost);
1350 
1351  if((server->dpy = XOpenDisplay(localHost)) == (Display *)NULL)
1352  {
1353  log_msg("Unable to open display %s", localHost);
1354  return(0);
1355  }
1356 
1357  sock_bind("LINUXPOPS_SPECPLOT");
1358  dataserv = sock_connect("LINUXPOPS_DATASERV");
1359  helper = sock_connect("LINUXPOPS_HELPER");
1360 
1361  set_sock_callback( (int (*)(void))readMail );
1362 
1363  sock_bufct(sizeof(struct DS_IMAGE_INFO)+256);
1364 
1365  strcpy(title, "Dataserv");
1366  strcpy(mainFrameTitle, "Dataserv");
1367 
1368  bg = BLACK;
1369 
1370  createWindows(server, title, cw, ch, xpos, ypos, bg, globalUsPixmap);
1371 
1372  XSetErrorHandler(myErrorHandler);
1373  XSetIOErrorHandler((XIOErrorHandler)myIOErrorHandler);
1374 
1375  main_loop();
1376 
1377  return(0);
1378 }
int save_config
Definition: mailparse.c:45
struct SOCK * dataserv
Definition: linuxpops.c:75
struct WINDOW_HEAD * prev
Definition: xgr.h:44
int main(void)
Definition: gsl_try_2.c:176
struct SOCK * last_msg(void)
#define FONT_SIZE_SMALL
Definition: dataFonts.h:6
int plotyb
Definition: xgr.h:63
int doSpecWinRepaint(void)
Definition: specplot.c:211
int first
Definition: xgr.h:66
#define LOG_TO_LOGGER
Definition: loglib.h:3
#define YELLOW
Definition: colors.h:7
int xgr_drawBin(float *xdata, float *ydata, int n, int color)
Definition: xgr.c:1455
int printKeySymHelp(void)
Definition: otf.c:2891
int xgr_drawBox(double x, double y, double x2, double y2, int color)
char * strcmprs(char *str)
int checkKeyPress(XEvent *event)
Definition: otf.c:3293
char tfile[256]
Definition: specplot.c:34
int deNewLineIt(char *buf)
int lockScale
Definition: xgr.c:31
Pixmap icon
Definition: xgr.h:55
int parseMail(char *buf)
Definition: mailparse.c:245
#define MAX_KEYSYMS
Definition: specplot.c:84
int myErrorHandler(Display *display, XErrorEvent *myerr)
Definition: dataserv.c:333
char serverName[80]
Definition: xgr.h:78
int scan
int log_perror(char *msg)
char localHost[80]
Definition: dataserv.c:52
int xgr_drawText(double x, double y, char *msg, int clr, int f)
#define RED
Definition: colors.h:5
int determine_min_max(float *ydata, int dl, double scan)
int plotye
Definition: xgr.h:63
#define ROW1
Definition: specplot.c:8
struct WINDOW_HEAD windows
Definition: xgr.h:49
int plotxe
Definition: xgr.h:63
#define GRAY50
Definition: colors.h:7
int log_eventdEnable(int enable)
struct XGR_HEAD * next
Definition: xgr.h:36
struct XGR_HEAD * prev
Definition: xgr.h:37
char * help
Definition: otf.c:2841
#define BLUE
Definition: colors.h:8
char * getLogDate(int offset)
int xgr_freeWindows(struct XGR_ *s)
Definition: xgr.c:348
int mapped
Definition: xgr.h:67
#define WHITE
Definition: colors.h:11
int xfd
Definition: xgr.h:80
int zerodata
Definition: specdata.c:54
struct LP_IMAGE_INFO last_image
Definition: xgraphic.c:95
#define remque(e)
Definition: xgr.c:60
int display_image(double xb, double xe, double yb, double ye, struct DS_IMAGE_INFO *im)
int doSpecPlotWinEvent(XEvent *event, unsigned int mask)
Definition: specplot.c:404
#define insque(e, p)
Definition: xgr.c:51
char deadServer[80]
Definition: dataserv.c:52
long frame_mask
Definition: dataserv.c:117
#define XGR_SET_PIXMAP
Definition: xgr.h:24
#define ROW2
Definition: specplot.c:9
struct MAIL_PARSE parse_table[]
Definition: mailparse.c:56
char inMsg[16384]
Definition: dataserv.c:29
#define XGR_MAX_FONTS
Definition: xgr.h:33
int debug
Definition: mailparse.c:29
int usPixmap
Definition: xgr.h:53
Display * dpy
Definition: xgr.h:79
char * strlwr(char *str)
float globalStop
Definition: specplot.c:22
int(* resize_proc)()
Definition: xgr.h:69
int(* repaint_proc)()
Definition: xgr.h:68
int mon
Definition: convol.c:102
struct OTF_STRUCT * myotf
Definition: specplot.c:43
int sexagesimal(double dang, char *str, int prec)
char * months[12]
Definition: beam.c:85
int sock_bufct(int bufct)
int log_msg(const char *fmt,...)
XImage * createXimage(Display *display, int w, int h, int depth)
Definition: otf.c:4520
int depth
Definition: xgr.h:82
struct SOCK * helper
Definition: linuxpops.c:75
int do_help(char *buf)
Definition: mailparse.c:419
Definition: xgr.h:35
Definition: sock.h:30
int drawGrid
Definition: xgr.c:29
int plotxb
Definition: xgr.h:63
double datamin
Definition: dataserv.c:44
int smart_log_open(char *name, int offset)
int sock_send(struct SOCK *s, char *message)
int(* sock_callback)()
Definition: dataserv.c:28
#define DATASPREAD
Definition: specplot.c:11
int putChanTemp(int c, double t)
float globalYMax
Definition: xgr.c:27
#define ROW3
Definition: specplot.c:10
int globalUsPixmap
Definition: dataserv.c:120
float globalStart
Definition: specdata.c:37
struct STURCT_KEYSYMS keysyms[]
Definition: otf.c:2844
int exitProc(int status)
Definition: dataserv.c:371
KeySym sym
Definition: otf.c:2838
#define ROW0
Definition: specplot.c:7
Definition: xgr.h:48
char * msg
Definition: mailparse.c:43
Definition: xgr.h:75
int xgr_findWindow(Display *dpy, Window win, struct WINDOW **w)
Definition: xgr.c:602
#define XGR_SPEC_WIN
Definition: xgr.h:21
int(* fctn)()
Definition: mailparse.c:51
char * key
Definition: otf.c:2840
#define DD_MM_SS
Definition: sex.h:15
int count
Definition: mailparse.c:46
int xgr_graphInit(struct XGR_ *s)
Definition: xgr.c:71
char title[256]
Definition: specplot.c:34
int xgr_reSizeProc(Window window, int width, int height)
Definition: xgr.c:698
int sock_sel(char *message, int *l, int *p, int n, int tim, int rd_in)
char mainFrameTitle[80]
Definition: dataserv.c:52
int xgr_drawTextClear(double x, double y, char *msg, int clr, int f)
int xgr_eventProc(XEvent *event, Window window, unsigned int mask)
Definition: xgr.c:762
int main_loop(void)
Definition: dataserv.c:847
void * ptr
Definition: mailparse.c:49
Window win
Definition: xgr.h:52
float globalYMin
Definition: xgr.c:27
char * sock_name(struct SOCK *handle)
double datamax
Definition: dataserv.c:44
int xgr_setFont(struct XGR_ *s, int f)
Definition: xgr.c:2294
int xfd
Definition: linuxpops.c:83
char frameTitle[80]
Definition: xgr.h:50
int type
Definition: mailparse.c:47
int set_sock_callback(int(*call)(void))
Pixmap pixmap
Definition: xgr.h:54
float xdata[MAX_ATM_ELEMENTS]
Definition: atm.c:90
#define DDD_MM_SS_S100
Definition: sex.h:18
float scanNum
Definition: dataserv.c:46
struct XGR_HEAD xgr_head
Definition: xgr.c:36
int putHeader(struct DS_IMAGE_INFO *image)
Definition: specplot.c:819
int background
Definition: xgr.h:60
char * format
Definition: mailparse.c:48
GC gc
Definition: xgr.h:56
int readMail(char *buf, int len)
Definition: mailparse.c:223
#define BLACK
Definition: colors.h:4
struct BOUND * sock_bind(char *mbname)
int xgr_pixmapToWindow(char *name)
Definition: xgr.c:530
char prgName[80]
Definition: dataserv.c:52
int myIOErrorHandler(Display *display, XErrorEvent *myerr)
Definition: dataserv.c:314
struct SOCK * sock_connect(char *mbname)
int canw
Definition: xgr.h:57
int setCactusEnvironment(void)
#define XGR_SET_WIN
Definition: xgr.h:25
char ** findFixedFonts(Display *dpy, int *num)
Definition: xgr.c:2351
int(* event_proc)()
Definition: xgr.h:70
int invalid
Definition: xgr.h:65
char * vxstrtok(char *string, char *last_token, char *delim)
Definition: mailparse.c:655
int doSpecPlot(struct DS_IMAGE_INFO *im)
Definition: specplot.c:964
float ydata[MAX_ATM_ELEMENTS]
Definition: atm.c:91
struct WINDOW * createWindow(struct XGR_ *s, char *title, int cw, int ch, int xpos, int ypos, int bg, int usPixmap, int which)
Definition: dataserv.c:415
char * help
Definition: mailparse.c:52
int xgr_mapUnmapWindow(char *name, int map)
Definition: xgr.c:568
void signalHandler(void)
Definition: dataserv.c:351
int xgr_drawRectangle(double xmin, double xmax, double ymin, double ymax, double xl, double yt, double xr, double yb, int color, int bold)
int do_quit(void)
Definition: mailparse.c:384
int doSpecWinReSize(void)
Definition: specplot.c:227
int to_helper(char *buf)
Definition: dataserv.c:125
int xgr_rePaintProc(Window window)
Definition: xgr.c:794
#define MAGENTA
Definition: colors.h:9
float ydata[MAX_DATA_CHANNELS]
Definition: ds_image_info.h:39
float startRes
Definition: specplot.c:22
int to_dataserv(char *buf)
Definition: otf.c:82
int createWindows(struct XGR_ *s, char *title, int cw, int ch, int xpos, int ypos, int bg, int usPixmap)
Definition: dataserv.c:512
int canh
Definition: xgr.h:57
struct XGR_ * server
Definition: dataserv.c:112
int xgr_clearScreen(void)
Definition: xgr.c:921
#define GREEN
Definition: colors.h:6
int processEvent(struct XGR_ *s)
Definition: dataserv.c:908
int xgr_setCurWindow(int win, int which)
Definition: xgr.c:483