Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
specdata.c
Go to the documentation of this file.
1 /*
2  * specdata.c: Program to display the called for scan; Unlike the original
3  * dataserv program which would display the just completed observation,
4  * and perform analysis on the data, this program just displays the
5  * data and doesn't do anything with it.
6  *
7  * Sleeps on a socket waiting for a SPECDATA structure containing the
8  * file names and scan number to display. Only display Spectral data.
9  */
10 
11 #include "ds_extern.h"
12 
13 #include "sd_proto.h"
14 
15 #ifdef GALACTIC
16 #undef GALACTIC
17 #endif
18 
19 #ifdef AZEL
20 #undef AZEL
21 #endif
22 
23 #ifdef USERDEF
24 #undef USERDEF
25 #endif
26 
27 #include "dataserv.bmp"
28 #include "datagrid.bmp"
29 
30 #define TRUE 1
31 #define FALSE 0
32 #define DATASPREAD 0.000001
33 
34 static int font0 = FONT_SIZE_SMALL;
35 static int font1 = FONT_SIZE_NORMAL;
36 
38 
39 int (*sock_callback)() = NULL;
40 char inMsg[16384];
41 
43 
44 int datalen = 0,
51  version = 1;
52 
53 int debug = 0;
54 int zerodata = 0;
55 
56 
57 float datamax,
58  datamin,
59  scanNum = -1.0;
60 
61 
62 #ifdef TOMMIE
63 char filename[256];
64 char gfilename[256];
66 #endif
67 
68 char initials[256], source[SRCLEN+1], oldBuf[16384], tempBuf[16384],
69  prgName[80], errBuf[512], manInitials[80], localHost[80],
70  deadServer[80], saveBuf[16384], manVersion[80], mainFrameTitle[80],
71  tailFileName[80], datadir[128], fixeddir[128], _3ddir[128];
72 
73 
74 
75 
76 int scansDone[100];
77 int scansDoneInx = 0;
78 int scanDone = 0;
79 
80 static int block_for_event();
81 
82 struct HEADER onhead;
83 struct HEADER offhead;
85 
86 float *ondata;
87 float *offdata;
88 
89 float *gainsdata;
90 
91 extern int _Xdebug;
92 
93 int fitFail = 0;
95 
96 extern int noPlot, noYTick, noXTick;
97 extern struct XGR_HEAD xgr_head;
98 struct XGR_ *server;
99 
101 
102 struct SPECDATA sd;
103 
104 int PID;
105 
106  /* DO NOT FORGET TO ADD A HANDLER FOR ANY EXTRA MASKS ADDED, processEvent() */
107 long frame_mask = KeyPressMask | ExposureMask | StructureNotifyMask;
108 
109 int istty;
111 
112 extern int insque(), remque();
113 
114 static char *spaces = " ";
115 
116 struct MAIL_PARSE {
117  char *msg;
118  int log;
119  int save_config;
120  int count;
121  int type;
122  char *format;
123  void *ptr;
124  int len;
125  int (*fctn)();
126  char *help;
127 };
128 
129 
131  /* Commands that change internal variables and are saved to dataserv.conf */
132 /* msg, log, save, cnt, type, fmt, *ptr, len, fctn(), *help */
133  { "help", 0, 0, 0, 0, NULL, NULL, 4, do_help, "Displays this list"},
134  { "quit", 0, 0, 0, 0, NULL, NULL, 4, do_quit, "Exit program"},
135 
136  { NULL, 0, 0, 0, 0, NULL, NULL, 0, (void *)0, NULL }
137 };
138 
139 
140 struct STURCT_KEYSYMS {
141  KeySym sym;
142  int win;
143  char *key;
144  char *help;
145 };
146 
148  { XK_q, 1, "q", "Quit Program" },
149  { XK_p, 1, "<control> + p", "Screen Capture Window" }
150 };
151 
152 #define MAX_KEYSYMS (sizeof(keysyms) / sizeof(struct STURCT_KEYSYMS))
153 
154 
155 
156 
157 int to_helper(buf)
158 char *buf;
159 {
160  if(buf)
161  {
162  log_msg("To HELPER: '%s'", buf);
163 
164  sock_send(helper, buf);
165  }
166 
167  return(0);
168 }
169 
170 
171 int to_xgraphic(buf)
172 char *buf;
173 {
174  if(buf)
175  {
176  log_msg("To XGRAPHIC: %s", buf);
177 
178  sock_send(xgraphic, buf);
179  }
180 
181  return(0);
182 }
183 
184 
186 {
187  int i;
188  char tbuf[256];
189  struct STURCT_KEYSYMS *k;
190 
191  sprintf(tbuf, "Press the Following Keys in Either the OTF or Spectral Plot Windows\n");
192 
193  printf("\n%s\n", tbuf);
194  log_msg(" ");
195  log_msg(tbuf);
196  log_msg(" ");
197 
198  k = &keysyms[0];
199  for(i=0;i<MAX_KEYSYMS;i++,k++)
200  {
201  if(k->win == 0)
202  {
203  sprintf(tbuf, "Press %s key for %s", k->key, k->help);
204  printf("%s\n", tbuf);
205 
206  log_msg(tbuf);
207  }
208  }
209 
210  sprintf(tbuf, "Press the Following Keys Spectral Plot Windows\n");
211 
212  printf("\n%s\n", tbuf);
213  log_msg(" ");
214  log_msg(tbuf);
215  log_msg(" ");
216 
217  k = &keysyms[0];
218  for(i=0;i<MAX_KEYSYMS;i++,k++)
219  {
220  if(k->win == 1)
221  {
222  sprintf(tbuf, "Press %s key for %s", k->key, k->help);
223  printf("%s\n", tbuf);
224 
225  log_msg(tbuf);
226  }
227  }
228 
229  return(0);
230 }
231 
232 
233 int do_help(buf)
234 char *buf;
235 {
236  struct MAIL_PARSE *p;
237  char tbuf[128];
238  char *cp;
239 
240  cp = strtok(buf, " \n\t");
241 
242  sprintf(tbuf, "Command Arguments\n");
243  printf("\n%s\n", tbuf);
244 
245  log_msg(tbuf);
246 
247  for(p=parse_table;p->msg;p++)
248  {
249  if(cp)
250  {
251  if(!strncmp(p->msg, cp, strlen(cp)))
252  {
253  sprintf(tbuf, "%s: %s", p->msg, spaces);
254  strcpy(tbuf+18, p->help);
255  printf("%s\n", tbuf);
256 
257  log_msg(tbuf);
258  }
259  }
260  else
261  {
262  sprintf(tbuf, "%s: %s", p->msg, spaces);
263  strcpy(tbuf+18, p->help);
264  printf("%s\n", tbuf);
265 
266  log_msg(tbuf);
267  }
268  }
269 
270  printKeySymHelp();
271 
272  return(0);
273 }
274 
275 
276 
277 int do_quit()
278 {
279  signalHandler();
280 
281  return(0);
282 }
283 
284 
285 char *vxstrtok(string, last_token, delim)
286 char *string, *last_token, *delim;
287 
288 /* char *vxstrtok(char *string, char *last_token, char *delim) --
289  * Like strtok, but can be used in VxWorks. The first call passes a non-NULL
290  * "string". A pointer to the first character in "string" not in "delim" is
291  * returned (or NULL if none). The next occurance of a character in "delim"
292  * past this first character is set to NUL and a second NUL is appended to
293  * "string". Subsequent calls must pass a NULL pointer "string" and the
294  * previous return value ("last_token"). In these calls, the NUL following
295  * last_token is replaced by the first character in "delim" and the scan
296  * continues until the next non-"delim" past this point is found or the
297  * end of the string is found (NULL returned). Again, if a non-"delim"
298  * character is found, the next "delim" character following it is replaced by
299  * a NUL.
300  */
301 
302 {
303  int n, i;
304  char *ptr, *ret;
305 
306  if(string) {
307  /* First call on a new string */
308  string[strlen(string)+1] = '\0'; /* Add a second NUL to the end */
309  ptr = string;
310  } else if(!last_token || !*last_token || !delim || !*delim)
311  return NULL;
312  else {
313  /* A subsequent call on the same string */
314  ptr = last_token + strlen(last_token); /* End of previous token */
315  *ptr++ = delim[0]; /* Put a delimiter back */
316  }
317  /* Scan for the next non-"delim" character */
318  for(n=strlen(delim); *ptr; ptr++) {
319  for(i=0; i < n && *ptr != delim[i]; i++)
320  continue;
321  if(i == n)
322  break; /* Found one */
323  }
324  if(!*ptr)
325  return NULL; /* End of string */
326 
327  ret = ptr++; /* Save beginning of token */
328 
329  /* Scan for next "delim" character */
330  for( ; *ptr; ptr++) {
331  for(i=0; i < n && *ptr != delim[i]; i++)
332  continue;
333  if(i != n)
334  break; /* Found one */
335  }
336  *ptr = '\0'; /* Mark the end */
337  return ret; /* Return the beginning */
338 }
339 
340 
341 
342 int readMail(buf, len)
343 char *buf;
344 int len;
345 {
346  char *cp;
347  static char cmdbuf[4096];
348 
349  if(len == sizeof(struct SPECDATA))
350  {
351  if(debug)
352  {
353  log_msg("Got SPECDATA struct");
354  }
355 
356  bcopy(buf, (char *)&sd, len);
357 
358  otf.IFNumber = (float)sd.feed / 100.0;
363 
364  show_display();
365 
366  return(0);
367  }
368 
369  if(debug)
370  {
371  log_msg("readMail(): Got %d bytes, %s", len, buf);
372  }
373 
374  if(buf || len < sizeof(cmdbuf))
375  {
376  cp = vxstrtok(buf, NULL, "\n");
377  while(cp)
378  {
379  strcpy(cmdbuf, cp);
380  parseMail(cmdbuf);
381  cp = vxstrtok(NULL, cp, "\n");
382  }
383  }
384 
385  return(0);
386 }
387 
388 
389 int parseMail(buf)
390 char *buf;
391 {
392  char *s;
393  struct MAIL_PARSE *p;
394 
395  deNewLineIt(buf);
396 
397  strlwr(buf);
398 
399  for(p=parse_table;p->msg;p++)
400  {
401  if(!strncmp(p->msg, buf, p->len))
402  {
403  if(p->log && strlen(buf) < 2048)
404  {
405  s = (char *)sock_name(last_msg());
406  if(s)
407  log_msg("%s: (%s) %s", prgName, sock_name(last_msg()), buf);
408  else
409  log_msg("%s: %s", prgName, buf);
410  }
411 
412  p->fctn(buf+p->len);
413 
414  return(0);
415  }
416  }
417 
418  log_msg("Command %s NOT found", buf);
419 
420  return(0);
421 }
422 
423 
424 int otfInit()
425 {
426  if(debug)
427  {
428  log_msg("otfInit(): Enter");
429  }
430 
431  otf.initialized = 0;
432  otf.bins = 10;
433  otf.plots = 5;
434  otf.singleChan = 126;
435  otf.arrayNum = OTFRA;
436  otf.singleOtfBin = 8;
437  otf.reqSpecIndx = -1;
438  otf.gridBaseLine = 1;
439  otf.noPlot = 0;
440  otf.newShade = 1;
441  otf.requestCol = 5;
442  otf.requestRow = 5;
443  otf.cols = 32;
444  otf.rows = 32;
445  otf.noint = 1024;
446  otf.int_chans[0] = 508;
447  otf.int_chans[1] = 516;
448  otf.lockScale = 0;
449  otf.valueMaxChanged = 0;
450  otf.intenChanged = 0;
453  otf.noColorBar = 0;
454  otf.manMapRa = 0.0;
455  otf.manMapDec = 0.0;
456  otf.manNyquistRa = 11.1761475;
457  otf.manNyquistDec = 8.05853271;
458  otf.manMapWidth = 0.60;
459  otf.manMapHeight = 0.60;
460  otf.windowSizeSet = 0;
461  otf.chanCompress = 1;
462  otf.scaleFactor = 1.0;
463  otf.gamma = 1.0;
465  otf.IFNumber = 0.01;
466  otf.chanSelOTF = 0;
467  otf.nyquistRa = 22.35;
468  otf.nyquistDec = 22.35;
469  otf.valueMax = 10.0;
470  otf.map_scans_head = NULL;
471  otf.gridArray = NULL;
472  otf.gridArrayChans = NULL;
473  otf.plotxb = OTFPLOTXB;
474  otf.plotyb = OTFPLOTYB;
475  otf.plotxe = OTFPLOTXE;
476  otf.plotye = OTFPLOTYE;
477  otf.freqres = -1.0;
478  otf.restfreq = -1.0;
479  otf.velocity = -1.0;
480  otf.xsource = -1.0;
481  otf.ysource = -100.0;
482  otf.peakStr[0] = '\0';
483  otf.ximage = NULL;
484 // otf.colorChoice = doColor;
485  otf.cutoff = 0;
486  otf.regionshowbold = 0;
487  otf.baselines[0] = 1;
488  otf.baselines[1] = 30;
489  otf.baselines[2] = -1;
490  otf.baselines[3] = -1;
491  otf.baselines[4] = -1;
492  otf.baselines[5] = -1;
493  otf.baselines[6] = 224;
494  otf.baselines[7] = 254;
495 
496 // otfIFNumber = otf.IFNumber;
497 
498  if(debug)
499  {
500  log_msg("otfInit(): Done");
501  }
502 
503  return(0);
504 }
505 
506 
507 
508 int main(argc,argv)
509 int argc;
510 char *argv[];
511 {
512  char *cp, tfile[256];
513  int cw, ch, bg;
514  int xpos, ypos;
515  char title[80];
516 
518 
519  manualInitials = 1;
520  strcpy(manInitials, "ssk");
521 
522  atexit((void *)exitProc);
523 
524  signal(SIGINT, (__sighandler_t)signalHandler);
525  signal(SIGTERM, (__sighandler_t)signalHandler);
526 
527  strcpy(prgName, "SPECDATA");
528 
529  cp = getenv("LPSESSION");
530 
531  if(cp)
532  {
533  sprintf(tfile, "LOGDIR=/tmp/%s", cp);
534 
535  putenv(tfile);
536  }
537  else
538  {
539  fprintf(stderr, "No SESSION defined\n");
540  exit(1);
541  }
542 
543  smart_log_open("specdata", 3);
544 
545 
546  setpgid( (pid_t)0, (pid_t)0); /* divorce myself from parents */
547 
548  PID = getpid();
549 
550  cp = getenv("TOPDIR");
551  if(cp)
552  sprintf(datadir,"%s",cp);
553  else
554  sprintf(datadir,"/home/data");
555 
556  cp = getenv("FIXDAT");
557  if(cp)
558  sprintf(fixeddir,"%s",cp);
559  else
560  sprintf(fixeddir,"/home/data4/fixed");
561 
562  cp = getenv("_3DDIR");
563  if(cp)
564  sprintf(_3ddir,"%s",cp);
565  else
566  sprintf(_3ddir,"/home/data1/3d");
567 
568  cp = getenv("DISPLAY");
569 
570  if(cp)
571  {
572  sprintf(localHost, "%s", cp);
573  }
574 
576 
577  if((server=(struct XGR_ *)calloc(1,sizeof(struct XGR_)))==NULL)
578  {
579  log_msg("error in calloc for main server");
580  return(1);
581  }
582 
583  insque(server, xgr_head.prev);
584 
585  cw = 650;
586  ch = 790;
587  xpos = 10;
588  ypos = 10;
589 
590  strcpy(server->serverName, localHost);
591 
592  if((server->dpy = XOpenDisplay(localHost)) == (Display *)NULL)
593  {
594  log_msg("Unable to open display %s", localHost);
595  return(0);
596  }
597 
598 
599  sock_bind("LINUXPOPS_SPECDATA");
600 // log_eventdEnable(1); /* enable loging to the event daemon */
601 
602  master = sock_connect("LINUXPOPS_MASTER");
603  helper = sock_connect("LINUXPOPS_HELPER");
604  xgraphic = sock_connect("LINUXPOPS_XGRAPHIC");
605  specplot = sock_connect("LINUXPOPS_SPECPLOT");
606 
607  set_sock_callback( (int (*)(void))readMail );
608 
609  strcpy(title,"Specdata");
610  strcpy(mainFrameTitle,"Specdata");
611 
612  otfInit();
613 
614  bg = BLACK;
615 
616  createWindows(server, title, cw, ch, xpos, ypos, bg, globalUsPixmap);
617 
618  XSetErrorHandler(myErrorHandler);
619  XSetIOErrorHandler((XIOErrorHandler)myIOErrorHandler);
620 
621  main_loop();
622 
623  return(0);
624 }
625 
626 
627 int myIOErrorHandler(display, myerr)
628 Display *display;
629 XErrorEvent *myerr;
630 {
631  if(display)
632  {
633  log_msg("Server %s caused IO Trap", DisplayString(display));
634  strcpy(deadServer, DisplayString(display));
635  }
636  else
637  {
638  log_msg("Server: Unknown Server caused IO Trap");
639  strcpy(deadServer, "Unknown Server");
640  }
641  exit(2);
642 }
643 
644 
645 
646 int myErrorHandler(display, myerr)
647 Display *display;
648 XErrorEvent *myerr;
649 {
650  if(display)
651  {
652  log_msg("Server %s caused Xlib Error", DisplayString(display));
653  strcpy(deadServer, DisplayString(display));
654  }
655  else
656  {
657  log_msg("Server: Unknown Server caused Xlib Error");
658  strcpy(deadServer, "Unknown Server");
659  }
660  return(0);
661 }
662 
663 
665 {
666  struct XGR_HEAD *p;
667  struct XGR_ *s;
668 
669  exit(1);
670 
671  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
672  {
673  s = (struct XGR_ *)p;
674  if(s->dpy)
675  {
676  log_msg("Signal: Shuting Down Server %s", DisplayString(s->dpy));
677  XFlush(s->dpy);
678  XCloseDisplay(s->dpy);
679  }
680  }
681 }
682 
683 
684 int exitProc(status)
685 int status;
686 {
687  log_msg("Exiting with status %d", status);
688 
689  /* kill the spec viewer */
690  sock_send(specplot, "quit");
691 
692  return(status);
693 }
694 
695 
696 
697 int dummieEventProc(event)
698 XEvent *event;
699 {
700  KeySym keysym;
701  XComposeStatus compose;
702  char buffer[1];
703  int bufsize=1;
704 
705  if(event->type == KeyPress)
706  {
707  XLookupString((XKeyEvent *)event, buffer, bufsize, &keysym, &compose);
708 
709  if(keysym == XK_p && event->xkey.state == ControlMask)
710  {
711  log_msg("Stand-by, Making Copy of SpecData Window.");
712 // do_diagHarCopyServ();
713  }
714  }
715 
716  return(0);
717 }
718 
719 
720 #define WINDOW_PLOT 1
721 #define WINDOW_OTF 2
722 
723 /* Create individual window */
724 
725 struct WINDOW *createWindow(s, title, cw, ch, xpos, ypos, bg, usPixmap, which)
726 struct XGR_ *s;
727 char *title;
728 int cw, ch, xpos, ypos, bg, usPixmap, which;
729 {
730  unsigned long value_mask;
731  XSetWindowAttributes attr;
732  XSizeHints size_hints;
733  struct WINDOW *w;
734  XWMHints wm_hints;
735  XTextProperty *wi, *ic;
736 
737  if((w = (struct WINDOW *)calloc(1, sizeof(struct WINDOW ))) == NULL)
738  {
739  log_msg("error in calloc for main Plot window");
740  exit(1);
741  }
742 
743  insque(w, s->windows.prev);
744 
745  strcpy(w->frameTitle, title);
746  w->canw = cw;
747  w->canh = ch;
748  w->background = bg;
749  w->first = 1;
750  w->win = XCreateSimpleWindow(s->dpy, RootWindow(s->dpy,s->scr_num),
751  xpos, ypos, (unsigned int)w->canw,
752  (unsigned int)w->canh,
753  1, s->colors[WHITE],
754  s->colors[BLACK]);
755  w->usPixmap = usPixmap;
756 
757  if(w->usPixmap)
758  {
759  if(!(w->pixmap = XCreatePixmap(s->dpy, w->win, (unsigned int)w->canw, (unsigned int)w->canh, s->depth)))
760  {
761  log_msg("%s: Error in create of off screen pixmap\n", prgName);
762  exit(1);
763  }
764  }
765 
766  if(which == XGR_MAIN_WIN)
767  {
768  XSelectInput(s->dpy, w->win, frame_mask );
769  }
770 
771  size_hints.flags = PPosition | PSize | PMinSize/* | PAspect*/;
772  size_hints.min_width = cw;
773  size_hints.min_height = ch;
774  size_hints.x = xpos;
775  size_hints.y = ypos;
776 
777  w->gc = XCreateGC(s->dpy, RootWindow(s->dpy, s->scr_num), (unsigned long)0, (XGCValues *)NULL);
778 
779  w->invalid = 1;
780 
781  if(which == XGR_MAIN_WIN)
782  {
783  w->icon = XCreateBitmapFromData(s->dpy, w->win, dataserv_bmp_bits,
784  dataserv_bmp_width,
785  dataserv_bmp_height);
786  }
787  else
788  {
789  w->icon = XCreateBitmapFromData(s->dpy, w->win, datagrid_bmp_bits,
790  datagrid_bmp_width,
791  datagrid_bmp_height);
792  }
793 
794  XSetStandardProperties(s->dpy, w->win,
795  w->frameTitle, (char *)NULL, w->icon,
796  (char **)NULL, 0, &size_hints);
797 
798  wi = NULL;
799  ic = NULL;
800 
801  wm_hints.initial_state = NormalState;
802  wm_hints.input = True;
803  wm_hints.icon_pixmap = 0;
804  wm_hints.flags = StateHint | InputHint | WindowGroupHint;
805  wm_hints.window_group = w->win;
806 
807  XSetWMProperties(s->dpy, w->win, wi, ic, NULL, 0, &size_hints, &wm_hints, NULL);
808 
809 
810  if(DoesBackingStore(XDefaultScreenOfDisplay(s->dpy)))
811  {
812  if(debug)
813  {
814  log_msg("createWindow(): Setting Backing Store for Plot Window");
815  }
816 
817  value_mask = CWBackingStore;
818  attr.backing_store = WhenMapped;
819  XChangeWindowAttributes(s->dpy, w->win, value_mask, &attr);
820  }
821 
822  XMapWindow(s->dpy, w->win);
823  w->mapped = 1;
824 
825  XSetWindowBackground(s->dpy, w->win, s->colors[w->background]);
826  XSetBackground(s->dpy, w->gc, s->colors[w->background]);
827  XClearWindow(s->dpy, w->win);
828 
829  s->cur = w;
830 
831  return(w);
832 }
833 
834 
835 int createWindows(s, title, cw, ch, xpos, ypos, bg, usPixmap)
836 struct XGR_ *s;
837 char *title;
838 int cw, ch, xpos, ypos, bg, usPixmap;
839 {
840  int x, y, w, h;
841  struct WINDOW *win;
842 
843  log_msg("DisplayInfo for %s - %s major %d minor %d release %d",
844  DisplayString(s->dpy), ServerVendor(s->dpy), ProtocolVersion(s->dpy),
845  ProtocolRevision(s->dpy), VendorRelease(s->dpy));
846 
847  s->xfd = XConnectionNumber(s->dpy);
848  s->scr_num = DefaultScreen(s->dpy);
849  s->numFonts = XGR_MAX_FONTS;
850  s->fontNames = findFixedFonts(s->dpy, &s->numFonts);
851  s->windows.prev = s->windows.next = &s->windows;
852  s->depth = XDefaultDepthOfScreen(XDefaultScreenOfDisplay(s->dpy));
853  s->userXimage = NULL;
854 
855  x = xpos;
856  y = ypos;
857  w = cw;
858  h = ch;
859  /* Create main plot window */
860  win = createWindow(s, title, w, h, x, y, bg, usPixmap, XGR_MAIN_WIN);
863  s->plotwin = win;
864 
865  xgr_graphInit(s);
866 
867  return(0);
868 }
869 
870 
871 
872 
873 int argmatch(s1, s2, atleast)
874 char *s1;
875 char *s2;
876 int atleast;
877 {
878  int l1 = strlen(s1);
879  int l2 = strlen(s2);
880 
881  if(l1 < atleast)
882  return 0;
883 
884  if(l1 > l2)
885  return 0;
886 
887  return(strncmp(s1, s2, l1) == 0);
888 }
889 
890 
891 int usage(progname)
892 char *progname;
893 {
894  fprintf(stderr, "\nUsage of '%s' command line arguments: \n", progname);
895  fprintf(stderr, "-ws x y Set Window size to x y\n");
896  fprintf(stderr, "-nopixmap Set dataserv in non-pixmap mapping mode\n");
897  fprintf(stderr, "-obs initials Set initials to display; defaults to current observer\n");
898  fprintf(stderr, "-ver n dir Set datafile ver to n, located on disk dir;\n");
899  fprintf(stderr, " defaults to current observers version\n");
900  fprintf(stderr, "-maxcolors [16|32|64|128] Set max colors of image display; default 64\n");
901  fprintf(stderr, "-color [GRAY|PSEUDO|FLAME] Set color mode of image display; default PSEUDO\n");
902  fprintf(stderr, "-usage This message\n");
903  exit(0);
904 }
905 
906 
908 {
909  if(strlen(sd.datafile))
910  {
911  showDisplay();
912  }
913 
914  return(0);
915 }
916 
917 
919 int scn;
920 {
921  int i;
922 
923  for(i=0;i<100;i++)
924  {
925  if(scn == scansDone[i])
926  {
927  scanDone = 1;
928  return(0);
929  }
930  }
931 
932  insertScan(scn);
933  scanDone = 0;
934 
935  return(1);
936 }
937 
938 
939 
940 int insertScan(scn)
941 int scn;
942 {
943  scansDoneInx++;
944  if(scansDoneInx > 99)
945  scansDoneInx = 0;
946 
947  scansDone[scansDoneInx] = scn;
948 
949  return(0);
950 }
951 
952 
953 
954 int to_monitor(buf)
955 char *buf;
956 {
957  log_msg("To Monitor: %s", buf);
958 
959  return(0);
960 }
961 
962 
963 int to_rambo(buf)
964 char *buf;
965 {
966  log_msg("To Rambo: %s", buf);
967 
968  return(0);
969 }
970 
971 int to_exec(buf)
972 char *buf;
973 {
974  log_msg("To Exec: %s", buf);
975 
976  return(0);
977 }
978 
980 char *buf;
981 {
982  if(buf)
983  useFixData = atoi(buf);
984  else
985  useFixData = 0;
986 
987  log_msg("Setting use of fixed data to %d", useFixData);
988 
989  return(0);
990 }
991 
992 
994 {
995  showDisplay();
996 
998 
999  return(0);
1000 }
1001 
1002 
1003 /* dummie function; we don't ignore scans here; alway return 0 */
1005 int v;
1006 float s;
1007 {
1008  return(0);
1009 }
1010 
1011 
1012 int loadFile(be, modeid)
1013 int *be, *modeid;
1014 {
1015  char *cp;
1016  int ret=0;
1017  float scan;
1018 
1019  if(strlen(sd.datafile) == 0)
1020  {
1021  log_msg("No structure sent yet");
1022 
1023  return(1);
1024  }
1025 
1026  if(debug)
1027  {
1028  log_msg("Scan = %d, feed = %d", sd.scanno, sd.feed);
1029  }
1030 
1031  scan = (float)sd.scanno + (float)sd.feed / 100.0;
1032 
1033  cp = sd.datafile;
1034 
1035  if(debug)
1036  {
1037  log_msg("Looking for scan %.2f in %s", scan, cp);
1038  }
1039 
1040  if(peekScan(scan, cp, be, modeid, &onhead))
1041  {
1042  log_msg("Scan %.2f, not found in %s", scan, cp);
1043  return(1);
1044  }
1045 
1046  if( (ret = read_scan( scan, cp, &ondata, &onhead)) != 0 )
1047  {
1048  return(ret);
1049  }
1050 
1051  if(*modeid == OTF)
1052  {
1053  scan = onhead.offscan;
1054 
1055  if(debug)
1056  {
1057  log_msg("Scan is OTF: Loading Off Scan %.2f", scan);
1058  }
1059 
1060  if( (ret = read_scan( scan, cp, &offdata, &offhead)) != 0 )
1061  {
1062  log_msg("Off Scan %.2f, not found in %s", scan, cp);
1063  return(ret);
1064  }
1065 
1066  cp = sd.gainsfile;
1067  scan = onhead.gains;
1068 
1069  if(debug)
1070  {
1071  log_msg("Loading Gains Scan %.2f", scan);
1072  }
1073 
1074  if( (ret = read_scan( scan, cp, &gainsdata, &gainshead)) != 0 )
1075  {
1076  log_msg("Gains Scan %.2f, not found in %s", scan, cp);
1077  return(ret);
1078  }
1079  }
1080 
1081  strncpy(source, onhead.object, SRCLEN);
1082  source[SRCLEN] = '\0';
1083 
1084  return(ret);
1085 }
1086 
1087 
1089 {
1090  int ret, be, modeid;
1091 
1092  /* Read scan here */
1093 
1094  ret = loadFile(&be, &modeid);
1095 
1096  if(ret)
1097  {
1098  return(1);
1099  }
1100 
1102 
1103  switch(modeid)
1104  {
1105  case TP_OFF:
1106  case TPM_OFF:
1108  break;
1109 
1110  case OTF:
1111  do_lineotf();
1112  break;
1113 
1114  default:
1115  do_linedefault();
1116  break;
1117  }
1118 
1119 
1121 
1123 
1124  return(0);
1125 }
1126 
1127 
1128 
1130 {
1131  struct XGR_HEAD *p, *p2;
1132  struct XGR_ *s, *f;
1133  int count, n, xfd;
1134  int xfds[256];
1135 
1136  while (1)
1137  {
1138  count=0;
1139 
1140  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
1141  {
1142  s = (struct XGR_ *)p;
1143 
1144  if(XPending(s->dpy))
1145  {
1146  processEvent(s);
1147  count++;
1148  }
1149  }
1150 
1151  if(!count)
1152  {
1153  n=0;
1154 
1155  for(p2=xgr_head.next;p2!=&xgr_head;p2=p2->next)
1156  {
1157  f = (struct XGR_ *)p2;
1158  xfds[n] = f->xfd;
1159  n++;
1160  }
1161 
1162  xfd = block_for_event(xfds, n);
1163 
1164  for(p2=xgr_head.next;p2!=&xgr_head;p2=p2->next)
1165  {
1166  f = (struct XGR_ *)p2;
1167 
1168  if(xfd == f->xfd)
1169  {
1170  if(XPending(f->dpy) == 0)
1171  {
1172  if(f->dpy == server->dpy) /* is it the main one */
1173  exit(0);
1174 
1175  log_msg("Removeing %s in destoryFunc", DisplayString(f->dpy));
1176  remque(f);
1177  xgr_freeWindows(f);
1178 
1179  break;
1180  }
1181  }
1182  }
1183  }
1184  }
1185 
1186  return(0);
1187 }
1188 
1189 
1191 struct XGR_ *s;
1192 {
1193  XEvent event;
1194 
1195  while(XPending(s->dpy))
1196  {
1197  XNextEvent(s->dpy, &event);
1198 
1199  switch( event.type )
1200  {
1201  case Expose:
1202  /* Filter down to the last Expose event */
1203  while (XCheckTypedWindowEvent(s->dpy, event.xany.window, Expose, &event))
1204  {
1205  ;
1206  }
1207 
1208  xgr_rePaintProc(event.xexpose.window);
1209 
1210  break;
1211 
1212  case ConfigureNotify:
1213 
1214  /* Filter down to the last ConfigureNotify event */
1215  while (XCheckTypedWindowEvent(s->dpy, event.xany.window, ConfigureNotify, &event))
1216  {
1217  ;
1218  }
1219 
1220  if(event.xconfigure.window && !event.xconfigure.send_event)
1221  {
1222  xgr_reSizeProc(event.xconfigure.window, event.xconfigure.width, event.xconfigure.height);
1223  }
1224 
1225  break;
1226 
1227  case ButtonPress:
1228  xgr_eventProc(&event, event.xbutton.window, ButtonPress);
1229  break;
1230 
1231  case MotionNotify:
1232  xgr_eventProc(&event, event.xbutton.window, MotionNotify);
1233  break;
1234 
1235  case KeyPress:
1236  xgr_eventProc(&event, event.xbutton.window, KeyPress);
1237  break;
1238 
1239  case UnmapNotify:
1240  break;
1241 
1242  case DestroyNotify:
1243  log_msg("Destroy");
1244 
1245  exit((int)3);
1246 
1247  break;
1248 
1249  default:
1250  break;
1251  }
1252  }
1253 
1254  return(0);
1255 }
1256 
1257 
1258 
1259 
1260 static int block_for_event(xfd, n)
1261 int *xfd;
1262 int n;
1263 {
1264  int len, i;
1265  static int sel = 1;
1266 
1267  sel = sock_sel(inMsg, &len, xfd, n, 10, 0);
1268 
1269  if( sel == -1 )
1270  { /* timeout */
1271  return(sel);
1272  }
1273 
1274  for(i=0;i<n;i++)
1275  {
1276  if(sel == xfd[i])
1277  {
1278  return(sel);
1279  }
1280  }
1281 
1282  if(sock_callback)
1283  {
1284  (*sock_callback)(inMsg, len);
1285  }
1286 
1287  return(sel);
1288 }
1289 
1290 
1292 int (*call)();
1293 {
1294  sock_callback = call;
1295 
1296  return(0);
1297 }
1298 
1299 
1300 
1302 int v;
1303 {
1304  struct XGR_HEAD *p;
1305  struct XGR_ *s;
1306 
1307  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
1308  {
1309  s = (struct XGR_ *)p;
1310 
1311  XSynchronize(s->dpy, v);
1312  }
1313 
1314  return(0);
1315 }
1316 
1317 
1318  /* Create an X11 image given a desired width, height and depth. */
1319 XImage *createXimage(display, w, h, depth)
1320 Display *display;
1321 int w, h, depth;
1322 {
1323  Visual *visual;
1324  XImage *xi;
1325  unsigned ui;
1326 
1327  visual = DefaultVisual(display, DefaultScreen(display));
1328 
1329  if(depth == 1)
1330  {
1331  return((XImage *)NULL);
1332  }
1333 
1334  xi = XCreateImage(display, visual, (unsigned int)depth, ZPixmap,0,
1335  (char *)NULL, (unsigned int)w, (unsigned int)h, 16, 0);
1336  if(xi == NULL)
1337  {
1338  log_msg("XCreateImage failed");
1339  return((XImage *)NULL);
1340  }
1341 
1342  ui = (unsigned)(xi->height*xi->bytes_per_line*sizeof(char));
1343  if((xi->data=(char *)malloc(ui))==NULL)
1344  {
1345  log_msg("Unable to malloc(%d) ximage in createXimage()", ui);
1346  XDestroyImage(xi);
1347  return((XImage *)NULL);
1348  }
1349 
1350  bzero((char *)xi->data, xi->height * xi->bytes_per_line * sizeof(char));
1351 
1352  return(xi);
1353 }
1354 
1355 
1357 float *ydata;
1358 int dl;
1359 float scan;
1360 {
1361  int i;
1362 
1363  if(ydata == NULL)
1364  return(1);
1365  /* redetermine min and max */
1366  datamax = -9999999999.9;
1367  datamin = 9999999999.0;
1368 
1369  for(i=0;i<dl;i++)
1370  {
1371  if(ydata[i] > datamax)
1372  datamax = ydata[i];
1373  if(ydata[i] < datamin)
1374  datamin = ydata[i];
1375  }
1376 
1377  if(fabs(datamax - datamin) < DATASPREAD)
1378  {
1379  log_msg("determine_min_max(): Scan #%7.2f is all %.4f", scan, datamin);
1380 
1381  datamin -= 1.0;
1382  datamax += 1.0;
1383 
1384  return(1);
1385  }
1386  return(0);
1387 }
1388 
1389 
1391 {
1392  if(debug)
1393  {
1394  log_msg("Freeing Data Pointers");
1395  }
1396 
1397  if(ondata)
1398  {
1399  free((char *)ondata);
1400  ondata = (float *)NULL;
1401  }
1402 
1403  if(offdata)
1404  {
1405  free((char *)offdata);
1406  offdata = (float *)NULL;
1407  }
1408 
1409  if(gainsdata)
1410  {
1411  free((char *)gainsdata);
1412  gainsdata = (float *)NULL;
1413  }
1414 
1415  return(0);
1416 }
1417 
1418 
1420 {
1421  int i;
1422  float f, *xArray, *yArray;
1423  float xb, xe, yb, ye;
1424  float scale;
1425  char temp[80];
1426 
1427  xb = 0.05; xe = 0.995;
1428  yb = 0.05; ye = 1.000;
1429 
1431  {
1432  log_msg("Requested spectra > numOfSpectra");
1433  return(1);
1434  }
1435  if((xArray = (float *)malloc((unsigned)(otf.noint*sizeof(float))))==NULL)
1436  {
1437  log_msg("Unable to malloc(%d) xArray in displaySingleOtfSpectra()", otf.noint*sizeof(float));
1438  return(1);
1439  }
1440  if((yArray = (float *)malloc((unsigned)(otf.noint*sizeof(float))))==NULL)
1441  {
1442  log_msg("Unable to malloc(%d) yArray in displaySingleOtfSpectra()", otf.noint*sizeof(float));
1443  free((char *)xArray);
1444  return(1);
1445  }
1446 
1447  if(sd.doTPprocess)
1448  {
1449  for(i=0;i<otf.noint;i++)
1450  {
1451  yArray[i] = ((ondata[i+sd.debugSpectra*otf.noint] - offdata[i])
1452  / offdata[i]) * gainsdata[i];
1453  }
1454  }
1455  else
1456  {
1457  for(i=0;i<otf.noint;i++)
1458  {
1459  yArray[i] = ondata[i+sd.debugSpectra*otf.noint];
1460  }
1461  }
1462 
1463  if( onhead.sideband == 3.0)
1464  {
1465  f = otf.noint * onhead.freqres / 2.0;
1466 
1467  for(i=0;i<otf.noint;i++)
1468  {
1469  xArray[i] = f - ((float)i * onhead.freqres);
1470  }
1471  }
1472  else
1473  {
1474  f = -otf.noint * onhead.freqres / 2.0;
1475 
1476  for(i=0;i<otf.noint;i++)
1477  {
1478  xArray[i] = f + ((float)i*onhead.freqres);
1479  }
1480  }
1481 
1482  scale = ye -yb;
1483  sprintf(temp, "Scan %7.2f: Spectra # %d", onhead.scan, sd.debugSpectra);
1484  xgr_drawText(xb, 0.905*scale + yb, temp, RED, font1);
1485  xgr_drawBox(xb, 0.05*scale + yb, xe, 0.90*scale + yb, GRAY50);
1486  globalStart = xArray[0];
1487  xgr_drawBin(xArray, yArray, otf.noint, GREEN);
1488 
1489  if(xArray)
1490  {
1491  free((char *)xArray);
1492  }
1493 
1494  if(yArray)
1495  {
1496  free((char *)yArray);
1497  }
1498 
1499  return(1);
1500 }
1501 
1502 
1503 
1504 
1506 float datalen, noint;
1507 {
1508  int dl;
1509 
1510  dl = (int)datalen / ( sizeof(float) * ( (int)noint +5));
1511 
1512  return(dl);
1513 }
1514 
1515 
1516 
1517 int displayArrayGraph(xb, xe, yb, ye)
1518 float xb, xe, yb, ye;
1519 {
1520  float *xdata, *ydata, *sig = 0;
1521  int i;
1522  float scale, dec_slope, ra_slope;
1523  float a1, b1, siga1, sigb1, chi2_1, q1 = 0;
1524  char temp[80];
1525 
1526  scale = ye -yb;
1527  /* Initialize the x-axis data points */
1528  if((xdata = (float *)malloc((unsigned)(otf.numSpectra*sizeof(float))))==NULL)
1529  {
1530  log_msg("Unable to malloc(%d) xdata in ArrayDisplay()", otf.numSpectra*sizeof(float));
1531  return(1);
1532  }
1533 
1534  for(i=0;i<otf.numSpectra;i++)
1535  xdata[i] = (float)i;
1536 
1537  if((ydata = (float *)malloc((unsigned)(otf.numSpectra*sizeof(float))))==NULL)
1538  {
1539  log_msg("Unable to malloc(%d) ydata in ArrayDisplay()", otf.numSpectra*sizeof(float));
1540  free((char *)xdata);
1541  return(1);
1542  }
1543 
1544  switch(sd.arrayNum)
1545  {
1546  case OTFAUTO:
1547  /* test which direction telescope is going */
1548  /* try ra dir first */
1549  bcopy((char *)&ondata[otf.noint * otf.numSpectra + otf.numSpectra*1],
1550  (char *)ydata, otf.numSpectra*sizeof(float));
1551 
1552  /* we are not using a weighted lsq so 'sig' doesn't need to be initialized */
1553  lsqfit(xdata,ydata, 0, i, sig, 0, &b1, &a1, &sigb1, &siga1, &chi2_1, &q1);
1554  ra_slope = a1;
1555 
1556 
1557  /* try dec next */
1558  bcopy((char *)&ondata[otf.noint * otf.numSpectra + otf.numSpectra*2],
1559  (char *)ydata, otf.numSpectra*sizeof(float));
1560 
1561  lsqfit(xdata,ydata, 0, i, sig, 0, &b1, &a1, &sigb1, &siga1, &chi2_1, &q1);
1562  dec_slope = a1;
1563 
1564  if((fabs(ra_slope) < fabs(dec_slope)))
1565  {
1566  bcopy((char *)&ondata[otf.noint *otf.numSpectra +otf.numSpectra*1],
1567  (char *)ydata, otf.numSpectra*sizeof(float));
1568  sprintf(temp, "R.A. Array");
1569  scaleData(ydata);
1570  }
1571  else
1572  {
1573  sprintf(temp, "Dec. Array");
1574  scaleData(ydata);
1575  }
1576 
1577  break;
1578  case OTFTIME:
1579  bcopy((char *)&ondata[otf.noint * otf.numSpectra], (char *)ydata, otf.numSpectra*sizeof(float));
1580  sprintf(temp, "Time Array");
1581  break;
1582  case OTFRA:
1583  bcopy((char *)&ondata[otf.noint * otf.numSpectra + otf.numSpectra*1], (char *)ydata, otf.numSpectra*sizeof(float));
1584  subtractPredictedRA(ydata);
1585  sprintf(temp, "R.A. Array");
1586  break;
1587  case OTFDEC:
1588  bcopy((char *)&ondata[otf.noint * otf.numSpectra + otf.numSpectra*2], (char *)ydata, otf.numSpectra*sizeof(float));
1589  scaleData(ydata);
1590  sprintf(temp, "Dec. Array");
1591  break;
1592  case OTFAZ:
1593  bcopy((char *)&ondata[otf.noint * otf.numSpectra + otf.numSpectra*3], (char *)ydata, otf.numSpectra*sizeof(float));
1594  sprintf(temp, "Az. Array");
1595  break;
1596  case OTFEL:
1597  bcopy((char *)&ondata[otf.noint * otf.numSpectra + otf.numSpectra*4], (char *)ydata, otf.numSpectra*sizeof(float));
1598  sprintf(temp, "El. Array");
1599  break;
1600  default:
1601  free((char *)xdata);
1602  free((char *)ydata);
1603  return(1);
1604  }
1605 
1606 /*
1607  if( determine_min_max(ydata, otf.numSpectra, onhead.scan))
1608  return(0);
1609  */
1611 
1612  xgr_drawBox(xb, 0.05*scale + yb, xe, 0.90*scale + yb, GRAY75);
1613  xgr_drawText(xb, 0.905*scale + yb, temp, RED, font0);
1614 
1615  globalStart = xdata[0];
1616  xgr_drawBin(xdata, ydata, otf.numSpectra, GREEN);
1617  free((char *)xdata);
1618  free((char *)ydata);
1619 
1620  return(1);
1621 }
1622 
1623 
1624 
1625 
1626 int displaySingleChan(xb, xe, yb, ye)
1627 float xb, xe, yb, ye;
1628 {
1629  int i, j, sc, no;
1630  float scale;
1631  char t[80];
1632  double dtemp;
1633  float *xdata, *ydata;
1634  float *x, *y, *w, *o, *g;
1635 
1636  scale = ye -yb;
1637  sc = sd.singleChan -1;
1638 
1639  if(sc < 0)
1640  {
1641  sc = 0;
1642  }
1643 
1644  if((xdata = (float *)malloc((unsigned)(otf.numSpectra*sizeof(float))))==NULL)
1645  {
1646  log_msg("Unable to malloc(%d) xdata in singleChan()", otf.numSpectra*sizeof(float));
1647  return(0);
1648  }
1649 
1650  if((ydata = (float *)malloc((unsigned)(otf.numSpectra*sizeof(float))))==NULL)
1651  {
1652  log_msg("Unable to malloc(%d) ydata in singleChan", otf.numSpectra*sizeof(float));
1653  free((char *)xdata);
1654 
1655  return(0);
1656  }
1657 
1658  x = xdata;
1659  y = ydata;
1660  w = &ondata[sc];
1661  o = &offdata[sc];
1662  g = &gainsdata[sc];
1663  no = otf.noint;
1664 
1665  for(i=0;i<otf.numSpectra; i++, x++, y++, w+=no)
1666  {
1667  *x = (float)i;
1668  *y = ((*w - *o) / *o) * *g;
1669  }
1670 
1671  if(sd.singleOtfBin)
1672  {
1673  for(i=0;i<otf.numSpectra-(sd.singleOtfBin-1);i+=sd.singleOtfBin)
1674  {
1675  dtemp = 0.0;
1676 
1677  for(j=0;j<sd.singleOtfBin;j++)
1678  {
1679  dtemp += ydata[i+j];
1680  }
1681 
1682  dtemp /= (float)sd.singleOtfBin;
1683 
1684  for(j=0;j<sd.singleOtfBin;j++)
1685  {
1686  ydata[i+j] = dtemp;
1687  }
1688  }
1689  }
1690 
1692  {
1693  free((char *)xdata);
1694  free((char *)ydata);
1695 
1696  return(0);
1697  }
1698 
1699  sprintf(t,"Chan # %d Binned to %d Chans", sd.singleChan, sd.singleOtfBin);
1700  xgr_drawText(xb, 0.905*scale + yb, t, RED, font0);
1701  xgr_drawBox(xb, 0.05*scale + yb, xe, 0.90*scale + yb, GRAY75);
1702 
1703  globalStart = xdata[0];
1704  xgr_drawBin(xdata, ydata, otf.numSpectra, GREEN);
1705 
1706  free((char *)xdata);
1707  free((char *)ydata);
1708 
1709  return(1);
1710 }
1711 
1712 
1713 
1714 int stuffOtf(plot, indxX, xArray, yArray)
1715 int plot, *indxX;
1716 float *xArray, *yArray;
1717 {
1718  int i, j, plotStart, indx;
1719  double *accum;
1720  float f;
1721 
1722  plotStart = plot * otf.numSpectra / (otf.plots-1);
1723  indx = *indxX;
1724 
1725  if(plot == 0)
1726  {
1727  ;
1728  }
1729  else
1730  if(plot == (otf.plots-1))
1731  {
1732  plotStart -= otf.bins;
1733  }
1734  else
1735  {
1736  plotStart -= (otf.bins / 2);
1737  }
1738 
1739  if( (accum = (double *)malloc((unsigned)(otf.noint*sizeof(double)))) == NULL)
1740  {
1741  log_msg("Unable to malloc(%d) accum in stuffOtf()", otf.noint*sizeof(double));
1742  return(-1);
1743  }
1744 
1745  for(i=0;i<otf.noint;i++)
1746  {
1747  accum[i] = 0.0;
1748 
1749  for(j=0;j<otf.bins;j++)
1750  {
1751  accum[i] += ondata[i+j*otf.noint+plotStart*otf.noint];
1752  }
1753 
1754  yArray[indx++] = ((accum[i] / (float)otf.bins - offdata[i]) / offdata[i]) * gainsdata[i];
1755  }
1756  /* Initialize the x-axis data points */
1757  indx = *indxX;
1758  if( onhead.sideband == 3.0)
1759  {
1760  f = otf.noint * onhead.freqres / 2.0;
1761 
1762  for(i=0;i<otf.noint;i++)
1763  {
1764  xArray[indx++] = f - ((float)i*onhead.freqres);
1765  }
1766  }
1767  else
1768  {
1769  f = -otf.noint * onhead.freqres / 2.0;
1770 
1771  for(i=0;i<otf.noint;i++)
1772  {
1773  xArray[indx++] = f + ((float)i*onhead.freqres);
1774  }
1775  }
1776 
1777  *indxX = indx;
1778  free((char *)accum);
1779 
1780  return(1);
1781 }
1782 
1783 
1784 
1785 int do_otf( head)
1786 struct HEADER *head;
1787 {
1788  int i;
1789  float xb=0.050, xe=0.995, yb=0.50, ye=1.0;
1790  float scale, delta, dxb[12], dxe[12];
1791  char temp[80];
1792  int arraySize, indx;
1793  float *xArray, *yArray;
1794 
1795  otf.numSpectra = getNumSpectra(head->datalen, head->noint);
1796  otf.noint = (int)head->noint;
1797 
1799  {
1800  log_msg("DATASERV: Can not grid %d chans", otf.noint);
1801  return(0);
1802  }
1803 
1805  xgr_clearScreen();
1806 
1807  if(sd.debugSpectra > 0)
1808  {
1810 
1811  return(0);
1812  }
1813 
1814  scale = ye -yb;
1815  delta = (xe - xb ) / (float)otf.plots;
1816  scale = ye - yb;
1817  sprintf(temp, "Scan %7.2f:", head->scan);
1818 
1819  xgr_drawText(xb, 0.905*scale + yb, temp, RED, font0);
1820 
1821  arraySize = otf.noint * otf.plots;
1822 
1823  if((xArray = (float *)malloc((unsigned)(arraySize*sizeof(float))))==NULL)
1824  {
1825  log_msg("Unable to malloc(%d) xdata in do_otf()", arraySize*sizeof(float));
1826 
1827  return(1);
1828  }
1829 
1830  if((yArray = (float *)malloc((unsigned)(arraySize*sizeof(float))))==NULL)
1831  {
1832  log_msg("Unable to malloc(%d) ydata in do_otf()", arraySize*sizeof(float));
1833  free((char *)xArray);
1834 
1835  return(1);
1836  }
1837 
1838 
1839  indx = 0;
1840  for(i=0;i<otf.plots;i++)
1841  {
1842  dxb[i] = xb + (float)i*delta;
1843 
1844  if(stuffOtf(i, &indx, xArray, yArray) < 0)
1845  {
1846  if(xArray)
1847  {
1848  free((char *)xArray);
1849  }
1850 
1851  if(yArray)
1852  {
1853  free((char *)yArray);
1854  }
1855 
1856  return(1);
1857  }
1858  }
1859 
1860  if( determine_min_max(yArray, arraySize, head->scan))
1861  {
1862  if(xArray)
1863  {
1864  free((char *)xArray);
1865  }
1866 
1867  if(yArray)
1868  {
1869  free((char *)yArray);
1870  }
1871 
1872  return(0);
1873  }
1874 
1875  xgr_drawBox(xb, 0.05*scale + yb, xe, 0.90*scale + yb, GRAY75);
1876 
1877  globalStart = xArray[0];
1878  noXTick = 1;
1879 
1880  xgr_drawBin(xArray, yArray, arraySize, GREEN);
1881 
1882  for(i=0;i<otf.plots;i++)
1883  {
1884  if(i<otf.plots-1)
1885  {
1886  dxe[i] = dxb[i+1];
1887  }
1888  else
1889  {
1890  dxe[i] = xe;
1891  }
1892 
1893  xgr_drawBox(dxb[i], 0.05*scale + yb, dxe[i], 0.90*scale + yb, GRAY75);
1894 
1895  noPlot=1;
1896  noYTick=1;
1897 
1898  xgr_drawBin(xArray + i*otf.noint, yArray + i*otf.noint, otf.noint, GREEN);
1899  }
1900 
1901  displaySingleChan(0.05, 0.495, 0.0, 0.5);
1902  displayArrayGraph(0.55, 0.995, 0.0, 0.5);
1903 
1904  if(xArray)
1905  {
1906  free((char *)xArray);
1907  }
1908 
1909  if(yArray)
1910  {
1911  free((char *)yArray);
1912  }
1913 
1915 
1916  return(0);
1917 }
1918 
1919 
1920 
1921 
1923 {
1924  if(debug)
1925  {
1926  log_msg("Doing Total Map Off Plot");
1927  }
1928 
1929  return(0);
1930 }
1931 
1932 
1934 {
1935  if(debug)
1936  {
1937  log_msg("Doing OTF Plot");
1938  }
1939 
1940  do_otf(&onhead);
1941 
1943 
1944  return(0);
1945 }
1946 
1947 
1949 {
1950  if(debug)
1951  {
1952  log_msg("Doing Default Spectral Plot");
1953  }
1954 
1955  return(0);
1956 }
1957 
1958 
1960 float *data;
1961 {
1962  float xmin, xscale;
1963  int i;
1964 
1965  xscale = onhead.inttime * onhead.deltaxr / 3600.0;
1966  xmin = xscale / -2.0;
1967  xscale = xscale / (float)otf.numSpectra;
1968 
1969  if(data[0] > 0)
1970  {
1971  for(i=0;i<otf.numSpectra;i++)
1972  {
1973  data[i] += (xmin + (xscale * (float)i));
1974  data[i] *= 3600.0;
1975  }
1976  }
1977  else
1978  {
1979  for(i=0;i<otf.numSpectra;i++)
1980  {
1981  data[i] -= (xmin + (xscale * (float)i));
1982  data[i] *= 3600.0;
1983  }
1984  }
1985 
1986  return(0);
1987 }
1988 
1989 
1990 
1992 float *data;
1993 {
1994  int i;
1995 
1996  for(i=0;i<otf.numSpectra;i++)
1997  {
1998  data[i] *= 3600.0;
1999  }
2000 
2001  return(0);
2002 }
2003 
2004 
2005 static float sqrarg;
2006 
2007 #define SQR(a) (sqrarg=(a),sqrarg*sqrarg)
2008 
2009 int lsqfit(x, y, bdata, ndata, sig, mwt, a, b, siga, sigb, chi2, q)
2010 float x[],y[],sig[],*a,*b,*siga,*sigb,*chi2,*q;
2011 int bdata,ndata,mwt;
2012 {
2013  int i;
2014  float wt, t, sxoss, sx = 0.0, sy = 0.0, st2 = 0.0, ss, sigdat;
2015 
2016  *b=0.0;
2017 
2018  if(mwt)
2019  {
2020  ss=0.0;
2021 
2022  for(i=bdata;i<ndata;i++)
2023  {
2024  wt = 1.0 / SQR(sig[i]);
2025  ss += wt;
2026  sx += x[i] * wt;
2027  sy += y[i] * wt;
2028  }
2029  }
2030  else
2031  {
2032  for(i=bdata;i<ndata;i++)
2033  {
2034  sx += x[i];
2035  sy += y[i];
2036  }
2037 
2038  ss=ndata-bdata;
2039  }
2040 
2041  sxoss = sx / ss;
2042 
2043  if(mwt)
2044  {
2045  for(i=bdata;i<ndata;i++)
2046  {
2047  t = (x[i] - sxoss) / sig[i];
2048  st2 += t * t;
2049  *b += t * y[i] / sig[i];
2050  }
2051  }
2052  else
2053  {
2054  for(i=bdata;i<ndata;i++)
2055  {
2056  t = x[i] - sxoss;
2057  st2 += t * t;
2058  *b += t * y[i];
2059  }
2060  }
2061 
2062  *b /= st2;
2063  *a = (sy - sx * (*b)) / ss;
2064  *siga = sqrt((1.0 + sx * sx / (ss * st2)) / ss);
2065  *sigb = sqrt(1.0 / st2);
2066  *chi2 = 0.0;
2067 
2068  if(mwt == 0)
2069  {
2070  for(i=bdata;i<ndata;i++)
2071  {
2072  *chi2 += SQR(y[i] - (*a) - (*b) * x[i]);
2073  }
2074 
2075  *q = 1.0;
2076  sigdat = sqrt((*chi2) / (ndata - bdata - 2));
2077  *siga *= sigdat;
2078  *sigb *= sigdat;
2079  }
2080 
2081  return(0);
2082 }
2083 
2084 #undef SQR
int save_config
Definition: mailparse.c:45
float valueMax
Definition: otf.h:217
struct SOCK * xgraphic
Definition: linuxpops.c:75
char tailFileName[80]
Definition: dataserv.c:52
int scanno
Definition: otf.h:64
float plotxe
Definition: otf.h:223
struct WINDOW_HEAD * prev
Definition: xgr.h:44
struct SCAN_SUM_SEND ss
Definition: scansum.c:61
int loadFile()
Definition: io.c:440
int to_rambo(char *buf)
Definition: dataserv.c:650
int singleChan
Definition: otf.h:158
double scan
Definition: header.h:35
#define SRCLEN
Definition: defines.h:9
int main(void)
Definition: gsl_try_2.c:176
struct SOCK * last_msg(void)
float scaleFactor
Definition: otf.h:211
float xsource
Definition: otf.h:237
#define FONT_SIZE_SMALL
Definition: dataFonts.h:6
int first
Definition: xgr.h:66
int initialsChanged
Definition: dataserv.c:38
char saveBuf[16384]
Definition: dataserv.c:52
int debugSpectra
Definition: otf.h:161
int noYTick
Definition: xgr.c:19
int xgr_drawBin(float *xdata, float *ydata, int n, int color)
Definition: xgr.c:1455
int PID
Definition: dataserv.c:114
int printKeySymHelp(void)
Definition: otf.c:2891
#define MAX_DATA_CHANNELS
Definition: linuxpops.c:61
int xgr_drawBox(double x, double y, double x2, double y2, int color)
char tfile[256]
Definition: specplot.c:34
int deNewLineIt(char *buf)
#define MAX_KEYSYMS
Definition: specdata.c:152
struct HEADER offhead
Definition: specdata.c:83
#define OTF
Definition: observing_par.h:63
float manMapDec
Definition: otf.h:228
Pixmap icon
Definition: xgr.h:55
int parseMail(char *buf)
Definition: mailparse.c:245
int myErrorHandler(Display *display, XErrorEvent *myerr)
Definition: dataserv.c:333
char serverName[80]
Definition: xgr.h:78
int to_monitor(char *buf)
Definition: dataserv.c:641
#define TPM_OFF
Definition: observing_par.h:38
float manNyquistRa
Definition: otf.h:231
int scan
int datalen
Definition: dataserv.c:33
struct HEADER gainshead
Definition: specdata.c:84
double sqrarg
Definition: gridmap.c:65
char localHost[80]
Definition: dataserv.c:52
char source[SRCLEN+1]
Definition: dataserv.c:52
int cutoff
Definition: otf.h:153
int chanSelOTF
Definition: otf.h:183
int xgr_drawText(double x, double y, char *msg, int clr, int f)
#define RED
Definition: colors.h:5
int freeDataPointers(void)
Definition: obsmodes.c:330
int determine_min_max(float *ydata, int dl, double scan)
#define XGR_MAIN_WIN
Definition: xgr.h:19
int do_lineotf(void)
Definition: obsmodes.c:163
#define DATASPREAD
Definition: specdata.c:32
float * gridArrayChans
Definition: otf.h:225
int read_scan()
struct WINDOW_HEAD windows
Definition: xgr.h:49
#define GRAY75
Definition: colors.h:8
char filename[256]
Definition: dataserv.c:49
int verifyScanDone(int scn)
Definition: dataserv.c:606
#define GRAY50
Definition: colors.h:7
double offscan
Definition: header.h:115
Definition: header.h:13
int debugSpectra
Definition: otf.h:71
#define OTFPLOTYB
Definition: otf.h:21
int manualInitials
Definition: dataserv.c:34
struct XGR_HEAD * next
Definition: xgr.h:36
struct XGR_HEAD * prev
Definition: xgr.h:37
char * help
Definition: otf.c:2841
int numSpectra
Definition: otf.h:172
struct SOCK * master
Definition: xgraphic.c:84
float * offdata
Definition: specdata.c:87
#define NORMAL_MAP
Definition: otf.h:11
char tempBuf[16384]
Definition: dataserv.c:52
int xgr_freeWindows(struct XGR_ *s)
Definition: xgr.c:348
char gainsfile[256]
Definition: otf.h:62
int mapped
Definition: xgr.h:67
#define WHITE
Definition: colors.h:11
int xfd
Definition: xgr.h:80
int zerodata
Definition: specdata.c:54
int version
Definition: dataserv.c:41
int to_exec(char *buf)
Definition: dataserv.c:658
#define remque(e)
Definition: xgr.c:60
int stuffOtf(int plot, int *indxX, float *xArray, float *yArray)
Definition: specdata.c:1714
#define insque(e, p)
Definition: xgr.c:51
char deadServer[80]
Definition: dataserv.c:52
int scanDone
Definition: dataserv.c:63
int newShade
Definition: otf.h:164
#define OTFPLOTYE
Definition: otf.h:22
long frame_mask
Definition: dataserv.c:117
int noint
Definition: otf.h:171
int mainFrameRepaint(void)
Definition: dataserv.c:594
int lastAction
Definition: otf.h:179
float plotxb
Definition: otf.h:221
#define SQR(a)
Definition: specdata.c:2007
int useFixData
Definition: dataserv.c:40
#define FONT_SIZE_NORMAL
Definition: dataFonts.h:7
#define XGR_SET_PIXMAP
Definition: xgr.h:24
float plotye
Definition: otf.h:224
double sideband
Definition: header.h:143
struct MAIL_PARSE parse_table[]
Definition: mailparse.c:56
int doTPprocess
Definition: otf.h:76
char inMsg[16384]
Definition: dataserv.c:29
#define XGR_MAX_FONTS
Definition: xgr.h:33
int debug
Definition: mailparse.c:29
char oldBuf[16384]
Definition: dataserv.c:52
double gains
Definition: header.h:145
int usPixmap
Definition: xgr.h:53
int int_chans[2]
Definition: otf.h:173
int whichPlot
Definition: otf.h:202
int scansDone[100]
Definition: dataserv.c:61
Display * dpy
Definition: xgr.h:79
char * strlwr(char *str)
int dummieEventProc(XEvent *event)
Definition: dataserv.c:388
int(* repaint_proc)()
Definition: xgr.h:68
int baselines[8]
Definition: otf.h:207
int noXTick
Definition: xgr.c:18
float nyquistRa
Definition: otf.h:214
float chanCompress
Definition: otf.h:233
int getNumSpectra(double datalen, double noint)
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
int found_scans[MAX_BACKENDS *MAX_PARTS]
Definition: dataserv.c:58
struct SOCK * helper
Definition: linuxpops.c:75
char datafile[256]
Definition: otf.h:61
int do_help(char *buf)
Definition: mailparse.c:419
char initials[256]
Definition: dataserv.c:52
Definition: xgr.h:35
char gfilename[256]
Definition: dataserv.c:50
int lsqfit(float x[], float y[], int bdata, int ndata, float sig[], int mwt, float *a, float *b, float *siga, float *sigb, float *chi2, float *q)
Definition: sock.h:30
int do_linedefault(void)
Definition: obsmodes.c:275
float manMapWidth
Definition: otf.h:229
int displaySingleOtfSpectra(void)
Definition: specdata.c:1419
#define OTFRA
Definition: otf.h:6
int regionshowbold
Definition: otf.h:189
float * gainsdata
Definition: specdata.c:89
double datamin
Definition: dataserv.c:44
int smart_log_open(char *name, int offset)
int do_linetotalmapoff(void)
Definition: obsmodes.c:154
#define OTFDEC
Definition: otf.h:7
int sock_send(struct SOCK *s, char *message)
float nyquistDec
Definition: otf.h:215
char datadir[128]
Definition: dataserv.c:52
int(* sock_callback)()
Definition: dataserv.c:28
char fixeddir[128]
Definition: dataserv.c:52
int valueMaxChanged
Definition: otf.h:176
int arrayNum
Definition: otf.h:77
struct HEADER onhead
Definition: specdata.c:82
int doNotSaveConfig
Definition: dataserv.c:105
float manMapHeight
Definition: otf.h:230
int lockScale
Definition: otf.h:174
float manNyquistDec
Definition: otf.h:232
int globalUsPixmap
Definition: dataserv.c:120
float globalStart
Definition: specdata.c:37
int manualVersion
Definition: dataserv.c:35
struct STURCT_KEYSYMS keysyms[]
Definition: otf.c:2844
int gridBaseLine
Definition: otf.h:184
#define OTFEL
Definition: otf.h:9
int checkIgnoreScans(int v, double s)
int singleOtfBin
Definition: otf.h:74
int otfInit(int init)
Definition: otf.c:423
Definition: otf.h:58
char errBuf[512]
Definition: dataserv.c:52
int exitProc(int status)
Definition: dataserv.c:371
KeySym sym
Definition: otf.c:2838
int scansDoneInx
Definition: dataserv.c:62
Definition: xgr.h:48
char * msg
Definition: mailparse.c:43
Definition: xgr.h:75
int printDataLines
Definition: dataserv.c:39
int displayArrayGraph(double xb, double xe, double yb, double ye)
float velocity
Definition: otf.h:236
int(* fctn)()
Definition: mailparse.c:51
char * key
Definition: otf.c:2840
#define OTFAUTO
Definition: otf.h:4
int subtractPredictedRA(float *data)
Definition: otf.c:1715
#define LOAD_PREVIEW
Definition: otf.h:15
int count
Definition: mailparse.c:46
int loadChoice
Definition: otf.h:178
char _3ddir[128]
Definition: dataserv.c:52
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
float gamma
Definition: otf.h:212
int xgr_eventProc(XEvent *event, Window window, unsigned int mask)
Definition: xgr.c:762
int displaySingleChan(double xb, double xe, double yb, double ye)
int main_loop(void)
Definition: dataserv.c:847
void * ptr
Definition: mailparse.c:49
int usage(char *name)
Definition: linuxpops.c:1473
int arrayNum
Definition: otf.h:159
int do_toggleFixData(char *buf)
Definition: dataserv.c:666
int fitFail
Definition: dataserv.c:104
Window win
Definition: xgr.h:52
char manVersion[80]
Definition: dataserv.c:52
char * sock_name(struct SOCK *handle)
int insertScan(int scn)
Definition: dataserv.c:627
int _Xdebug
int noPlot
Definition: xgr.c:20
int argmatch(char *s1, char *s2, int atleast)
Definition: dataserv.c:559
double datamax
Definition: dataserv.c:44
int synchronize(int v)
Definition: dataserv.c:1036
int xfd
Definition: linuxpops.c:83
float ysource
Definition: otf.h:238
char frameTitle[80]
Definition: xgr.h:50
int type
Definition: mailparse.c:47
#define MAX_PARTS
Definition: backends.h:15
#define MAX_BACKENDS
Definition: backends.h:14
int set_sock_callback(int(*call)(void))
float IFNumber
Definition: otf.h:213
float bdata[MAX_ATM_ELEMENTS]
Definition: atm.c:94
Pixmap pixmap
Definition: xgr.h:54
int rows
Definition: otf.h:170
float xdata[MAX_ATM_ELEMENTS]
Definition: atm.c:90
float manMapRa
Definition: otf.h:227
int thisIsaRefresh
Definition: dataserv.c:36
#define OTFPLOTXB
Definition: otf.h:19
int cols
Definition: otf.h:169
float scanNum
Definition: dataserv.c:46
struct XGR_HEAD xgr_head
Definition: xgr.c:36
int background
Definition: xgr.h:60
#define OTFPLOTXE
Definition: otf.h:20
char * format
Definition: mailparse.c:48
GC gc
Definition: xgr.h:56
int noColorBar
Definition: otf.h:180
int readMail(char *buf, int len)
Definition: mailparse.c:223
int initialized
Definition: otf.h:151
#define TP_OFF
Definition: observing_par.h:32
int singleChan
Definition: otf.h:73
int do_otf(float *data, struct HEADER *head, float *offdata, float *gainsdata)
Definition: otf.c:1006
int peekScan(double scan, char *filename, int *be, int *modeid, struct HEADER *head)
double inttime
Definition: header.h:210
#define BLACK
Definition: colors.h:4
struct BOUND * sock_bind(char *mbname)
int xgr_pixmapToWindow(char *name)
Definition: xgr.c:530
int intenChanged
Definition: otf.h:177
char prgName[80]
Definition: dataserv.c:52
int myIOErrorHandler(Display *display, XErrorEvent *myerr)
Definition: dataserv.c:314
int requestCol
Definition: otf.h:165
int requestRow
Definition: otf.h:166
char peakStr[80]
Definition: otf.h:242
struct SOCK * sock_connect(char *mbname)
int canw
Definition: xgr.h:57
double deltaxr
Definition: header.h:103
#define OTFTIME
Definition: otf.h:5
struct SOCK * specplot
Definition: dataserv.c:31
struct OTF_STRUCT otf
Definition: specdata.c:100
int setCactusEnvironment(void)
#define OTFAZ
Definition: otf.h:8
int feed
Definition: otf.h:65
char ** findFixedFonts(Display *dpy, int *num)
Definition: xgr.c:2351
int(* event_proc)()
Definition: xgr.h:70
int invalid
Definition: xgr.h:65
float plotyb
Definition: otf.h:222
char * vxstrtok(char *string, char *last_token, char *delim)
Definition: mailparse.c:655
int to_xgraphic(char *buf)
Definition: dataserv.c:139
float ydata[MAX_ATM_ELEMENTS]
Definition: atm.c:91
XImage * ximage
Definition: otf.h:247
int bins
Definition: otf.h:156
int showDisplay(void)
Definition: dataserv.c:690
float restfreq
Definition: otf.h:235
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
struct MAP_SCANS * map_scans_head
Definition: otf.h:244
struct OTF_GRID ** gridArray
Definition: otf.h:245
int scaleData(float *data)
Definition: otf.c:1691
float freqres
Definition: otf.h:234
char * help
Definition: mailparse.c:52
int reqSpecIndx
Definition: otf.h:162
char object[16]
Definition: header.h:40
#define PLOT_INT_INTENSITY
Definition: otf.h:51
int xgr_mapUnmapWindow(char *name, int map)
Definition: xgr.c:568
void signalHandler(void)
Definition: dataserv.c:351
double freqres
Definition: header.h:199
float * ondata
Definition: specdata.c:86
int do_quit(void)
Definition: mailparse.c:384
int show_display(void)
Definition: dataserv.c:680
struct SPECDATA sd
Definition: otf.c:43
int to_helper(char *buf)
Definition: dataserv.c:125
int xgr_rePaintProc(Window window)
Definition: xgr.c:794
int xgr_checkForEvents(void)
Definition: xgr.c:2547
int singleOtfBin
Definition: otf.h:160
int windowSizeSet
Definition: otf.h:185
int istty
Definition: dataserv.c:119
char manInitials[80]
Definition: dataserv.c:52
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
int plots
Definition: otf.h:157
#define GREEN
Definition: colors.h:6
int noPlot
Definition: otf.h:163
int processEvent(struct XGR_ *s)
Definition: dataserv.c:908
int xgr_setCurWindow(int win, int which)
Definition: xgr.c:483