Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
otf.c
Go to the documentation of this file.
1 #define DEFINE_OTF_STRUCT
2 #include "ds_extern.h"
3 #include "ds_proto.h"
4 
5 static int font0 = FONT_SIZE_SMALL;
6 static int font1 = FONT_SIZE_NORMAL;
7 
8 struct HEADER lastHead;
10 extern struct DS_IMAGE_INFO *last_image;
11 
12 extern float scanNum, datamax, datamin, globalStart;
13 extern int scan, noXTick, noYTick, noPlot, doColor,
16 
17 extern char source[], filename[], gfilename[], mainFrameTitle[], oldBuf[];
18 extern struct XGR_HEAD xgr_head;
19 
20 extern struct RGB colormap[];
21 
24 int chanSelOTF = 0;
25 int ephemObj = 0;
26 int lastGraph = 0;
27 int ok2grid = 0;
28 int dontsend = 0;
29 int zeroCellCount = 0;
31 
33 double *workArrayChans = NULL;
34 
37 
39 
40 struct OTF_GRID *gridHead = NULL;
41 struct OTF_GRID *gridLast = NULL;
42 
43 struct SPECDATA sd;
44 
45 int writeSingleChan = TRUE; /* for azimuth(deg) + total power output */
46 
47 int otfInit()
48 {
49  do_etimeClear();
50 
51  log_msg("otfInit(): Enter");
52 
53  otf.initialized = 0;
54  otf.bins = 10;
55  otf.plots = 5;
56  otf.singleChan = 126;
57  otf.arrayNum = OTFRA;
58  otf.singleOtfBin = 8;
59  otf.reqSpecIndx = -1;
60  otf.gridBaseLine = 1;
61  otf.noPlot = 0;
62  otf.newShade = 1;
63  otf.requestCol = 5;
64  otf.requestRow = 5;
65  otf.cols = 32;
66  otf.rows = 32;
67  otf.noint = 1024;
68  otf.int_chans[0] = 508;
69  otf.int_chans[1] = 516;
70  otf.lockScale = 0;
71  otf.valueMaxChanged = 0;
72  otf.intenChanged = 0;
75  otf.noColorBar = 0;
76  otf.manMapRa = 0.0;
77  otf.manMapDec = 0.0;
78  otf.manNyquistRa = 11.1761475;
79  otf.manNyquistDec = 8.05853271;
80  otf.manMapWidth = 0.60;
81  otf.manMapHeight = 0.60;
82  otf.windowSizeSet = 0;
83  otf.chanCompress = 1;
84  otf.scaleFactor = 1.0;
85  otf.gamma = 1.0;
87  otf.IFNumber = 0.01;
88  otf.chanSelOTF = 0;
89  otf.nyquistRa = 22.35;
90  otf.nyquistDec = 22.35;
91  otf.valueMax = 10.0;
92  otf.map_scans_head = NULL;
93  otf.gridArray = NULL;
94  otf.gridArrayChans = NULL;
99  otf.freqres = -1.0;
100  otf.restfreq = -1.0;
101  otf.velocity = -1.0;
102  otf.xsource = -1.0;
103  otf.ysource = -100.0;
104  otf.peakStr[0] = '\0';
105  otf.ximage = NULL;
107  otf.cutoff = 0;
108  otf.regionshowbold = 0;
109  otf.baselines[0] = 1;
110  otf.baselines[1] = 30;
111  otf.baselines[2] = -1;
112  otf.baselines[3] = -1;
113  otf.baselines[4] = -1;
114  otf.baselines[5] = -1;
115  otf.baselines[6] = 224;
116  otf.baselines[7] = 254;
117 
119 
120  log_msg("otfInit(): Done");
121 
122  return(0);
123 }
124 
125 
127 {
128  struct OTF_GRID *g;
129  struct OTF_GRID *o;
130 
131  log_msg("freeOtfMemory(): Enter");
132 
133  if(otf.gridArray)
134  {
135  for(g=gridHead;g;g=o)
136  {
137  if(g->chans)
138  {
139  free((char *)g->chans);
140  }
141 
142  o = g->next;
143  free((char *)g);
144  }
145 
146  free((char *)otf.gridArray);
147  otf.gridArray = NULL;
148  }
149 
150  gridHead = NULL;
151  gridLast = NULL;
152 
153  if(workArrayChans)
154  {
155  free((char *)workArrayChans);
156  workArrayChans = NULL;
157  }
158 
159  remMapScans();
160 
161  log_msg("freeOtfMemory(): Done");
162 
163  return(0);
164 }
165 
166 
167 int otfGridInit(cols, rows, noint)
168 int cols, rows, noint;
169 {
170  int col, row;
171  int n, k;
172 
173  log_msg("otfGridInit(): Initializing %dx%dx%d Chs", cols, rows, noint);
174 
175  otf.reqSpecIndx = -1;
176 
177  freeOtfMemory();
178 
179  ephemObj = 0;
180 
181  n = cols * rows;
182  if((otf.gridArray=(struct OTF_GRID **)malloc((unsigned)(n * sizeof(struct OTF_GRID *)))) == NULL)
183  {
184  log_msg("otfGridInit(): Error in malloc(%d)", n * sizeof(struct OTF_GRID));
185 
186  return(1);
187  }
188 
189  bzero((char *)otf.gridArray, n*sizeof(struct OTF_GRID *));
190 
191  otf.cols = cols;
192  otf.rows = rows;
193  otf.numCellsTotal = cols * rows;
194  otf.noint = noint;
195 
197  if((workArrayChans=(double *)malloc((unsigned)(n * sizeof(double)))) == NULL)
198  {
199  log_msg("otfGridInit(): Error in malloc(%d)", n * sizeof(double));
200 
201  workArrayChans = NULL;
202 
203  return(1);
204  }
205 
206  otf.sizeofWorkArray = n * sizeof(double);
207 
208  bzero((char *)workArrayChans, otf.sizeofWorkArray);
209 
210  k = 0;
211  for(col=0;col<WORK_ARRAY_X;col++)
212  {
213  for(row=0;row<WORK_ARRAY_Y;row++,k++)
214  {
216  }
217  }
218 
219  otf.regionshowbold = 0;
220  otf.initialized = 1;
221  otf.windowSizeSet = 0;
222 
223  log_msg("otfGridInit(): Done");
224 
225  return(0);
226 }
227 
228 
229 struct HEADER *do_addHeader(ver, scan, head)
230 int ver;
231 float scan;
232 struct HEADER *head;
233 {
234  struct HEADER *h;
235  static int old_ver = 0;
236  static double old_scan = 0.0;
237  static struct HEADER *old_head = NULL;
238 
239 #ifdef DO_DSTIME
241 #endif
242 
243  /* If it's the same ver and scan as the last call, return last head */
244  if(old_ver == ver && fabs(old_scan-scan) < 0.01)
245  {
246 #ifdef DO_DSTIME
248 #endif
249  return(old_head);
250  }
251 
252  if((h = checkScanHeader(ver, scan)))
253  {
254  old_ver = ver;
255  old_scan = scan;
256  old_head = h;
257 
258 #ifdef DO_DSTIME
260 #endif
261  return(h);
262  }
263  else
264  {
265  if((h = addScanHeader(ver, scan, head)))
266  {
267  old_ver = ver;
268  old_scan = scan;
269  old_head = h;
270 
271 #ifdef DO_DSTIME
273 #endif
274  return(h);
275  }
276  else
277  {
278  log_msg("do_addHeader(): Error adding scan %.2f, in ver %d", scan, ver);
279  }
280  }
281 
282 #ifdef DO_DSTIME
284 #endif
285 
286  return((struct HEADER *)NULL);
287 }
288 
289 
290 struct HEADER *checkScanHeader(v, s)
291 int v;
292 float s;
293 {
294 #ifdef DO_DSTIME
296 #endif
297 
298  struct SCAN_HEADERS *m;
299  float ss;
300 
301  if(otf_scan_headers == NULL)
302  {
303 #ifdef DO_DSTIME
305 #endif
306  return((struct HEADER *)NULL);
307  }
308 
309  /* users can pass a scan number like 1234.0, which will ignore all
310  scans with that prefix */
311  ss = (float)(int)s;
312 
313  for(m=otf_scan_headers;m->next; m=m->next)
314  {
315  if(m)
316  {
317  if((m->scan == s || m->scan == ss) && m->ver == v)
318  {
319 #ifdef DO_DSTIME
321 #endif
322  return(&m->head);
323  }
324  }
325  }
326 
327  /* Check the last one, if valid */
328  if(m)
329  {
330  if((m->scan == s || m->scan == ss) && m->ver == v)
331  {
332 #ifdef DO_DSTIME
334 #endif
335  return(&m->head);
336  }
337  }
338 
339 #ifdef DO_DSTIME
341 #endif
342 
343  return((struct HEADER *)NULL);
344 }
345 
346 
347 struct HEADER *addScanHeader(v, s, head)
348 int v;
349 float s;
350 struct HEADER *head;
351 {
352  struct SCAN_HEADERS *m;
353 
354 #ifdef DO_DSTIME
356 #endif
357 
358  /* Create a fresh list */
359  if(otf_scan_headers == NULL)
360  {
361  if((otf_scan_headers=(struct SCAN_HEADERS *)malloc((unsigned)(sizeof(struct SCAN_HEADERS))))==NULL)
362  {
363  log_msg("Error in addIgnoreScans malloc(%d)", sizeof(struct SCAN_HEADERS));
364 
365 #ifdef DO_DSTIME
367 #endif
368 
369  return((struct HEADER *)NULL);
370  }
371 
372  otf_scan_headers->ver = v;
373  otf_scan_headers->scan = s;
374 
375  bcopy((char *)head, (char *)&otf_scan_headers->head, sizeof(struct HEADER));
376 
377  otf_scan_headers->next = NULL;
378 
379 #ifdef DO_DSTIME
381 #endif
382 
383  return(&otf_scan_headers->head);
384  }
385 
386  /* Find next available slot */
387  for(m=otf_scan_headers;m->next; m=m->next)
388  {
389  ;
390  }
391 
392  /* Append new scan */
393  if((m->next=(struct SCAN_HEADERS *)malloc((unsigned)(sizeof(struct SCAN_HEADERS))))==NULL)
394  {
395  log_msg("Error in addIgnoreScans malloc(%d)", sizeof(struct SCAN_HEADERS));
396 
397 #ifdef DO_DSTIME
399 #endif
400 
401  return((struct HEADER *)NULL);
402  }
403 
404  m->next->ver = v;
405  m->next->scan = s;
406 
407  bcopy((char *)head, (char *)&m->next->head, sizeof(struct HEADER));
408 
409  m->next->next = NULL;
410 
411 #ifdef DO_DSTIME
413 #endif
414 
415  return(&m->next->head);
416 }
417 
418 
420 {
421  struct SCAN_HEADERS *p;
422  struct SCAN_HEADERS *q;
423 
424 #ifdef DO_DSTIME
426 #endif
427 
428  for(p=otf_scan_headers; p; p=q)
429  {
430  q = p->next;
431 
432  if(p)
433  {
434  free((char *)p);
435  }
436  }
437 
438  otf_scan_headers = NULL;
439 
440 #ifdef DO_DSTIME
442 #endif
443 
444  return(0);
445 }
446 /* TOMMIE */
447 
449 char *buf;
450 {
451  int n, v;
452  float f;
453 
454 #ifdef DO_DSTIME
456 #endif
457 
458  if(buf)
459  {
460  n = sscanf(buf, "%d %f", &v, &f);
461 
462  if(n == 2)
463  {
464  if((f > 0.0 && f < 49999.9) && (v > 0 && v < 999))
465  {
466  if(!checkIgnoreScans(v, f))
467  {
468  if(!addIgnoreScans(v, f))
469  {
470  log_msg("Scan %.2f, in version %d ignored", f, v);
471  }
472  else
473  {
474  log_msg("Scan %.2f, in version %d, could NOT be ignored", f, v);
475  }
476  }
477  else
478  {
479  log_msg("Scan %.2f already ignored in version %d", f, v);
480  }
481  }
482  else
483  {
484  log_msg("Scan %f or version: %d, out of range", f, v);
485 #ifdef DO_DSTIME
487 #endif
488  return(1);
489  }
490  }
491  else
492  {
493  log_msg("do_ignoreScan(): Missing args for ignore: %d", n);
494 #ifdef DO_DSTIME
496 #endif
497  return(1);
498  }
499  }
500 
501 #ifdef DO_DSTIME
503 #endif
504 
505  return(0);
506 }
507 
508 
510 int v;
511 float s;
512 {
513  struct MAP_SCANS *m;
514  float ss;
515 
516 #ifdef DO_DSTIME
518 #endif
519 
520  if(ignore_scans_head == NULL)
521  {
522 #ifdef DO_DSTIME
524 #endif
525  return(0);
526  }
527 
528  /* users can pass a scan number like 1234.0, which will ifnore all
529  scans with that prefix */
530  ss = (float)(int)s;
531 
532  for(m=ignore_scans_head;m->next; m=m->next)
533  {
534  if(m)
535  {
536  if((m->scan == s || m->scan == ss) && m->ver == v)
537  {
538 #ifdef DO_DSTIME
540 #endif
541  return(1);
542  }
543  }
544  }
545 
546  if(m)
547  {
548  if((m->scan == s || m->scan == ss) && m->ver == v)
549  {
550 #ifdef DO_DSTIME
552 #endif
553  return(1);
554  }
555  }
556 
557 #ifdef DO_DSTIME
559 #endif
560 
561  return(0);
562 }
563 
564 
565 int addIgnoreScans(v, s)
566 int v;
567 float s;
568 {
569  struct MAP_SCANS *m;
570 
571 #ifdef DO_DSTIME
573 #endif
574 
575  /* Create a fresh list */
576  if(ignore_scans_head == NULL)
577  {
578  if((ignore_scans_head=(struct MAP_SCANS *)malloc((unsigned)(sizeof(struct MAP_SCANS))))==NULL)
579  {
580  log_msg("Error in addIgnoreScans malloc(%d)", sizeof(struct MAP_SCANS));
581 
582 #ifdef DO_DSTIME
584 #endif
585 
586  return(1);
587  }
588 
589  ignore_scans_head->ver = v;
590  ignore_scans_head->scan = s;
591  ignore_scans_head->next = NULL;
592 
593 #ifdef DO_DSTIME
595 #endif
596 
597  return(0);
598  }
599 
600  /* Find next available slot */
601  for(m=ignore_scans_head;m->next; m=m->next)
602  {
603  ;
604  }
605 
606  /* Append new scan */
607  if((m->next=(struct MAP_SCANS *)malloc((unsigned)(sizeof(struct MAP_SCANS))))==NULL)
608  {
609  log_msg("Error in addIgnoreScans malloc(%d)", sizeof(struct MAP_SCANS));
610 
611 #ifdef DO_DSTIME
613 #endif
614 
615  return(1);
616  }
617 
618  m->next->ver = v;
619  m->next->scan = s;
620  m->next->next = NULL;
621 
622 #ifdef DO_DSTIME
624 #endif
625 
626  return(0);
627 }
628 
629 
631 {
632  struct MAP_SCANS *p;
633  struct MAP_SCANS *q;
634 
635 #ifdef DO_DSTIME
637 #endif
638 
639  for(p=ignore_scans_head; p; p=q)
640  {
641  q = p->next;
642 
643  if(p)
644  {
645  free((char *)p);
646  }
647  }
648 
649  ignore_scans_head = NULL;
650 
651 #ifdef DO_DSTIME
653 #endif
654 
655  return(0);
656 }
657 
658 
660 FILE *fp;
661 {
662  struct MAP_SCANS *m;
663  int i=0;
664 
665 #ifdef DO_DSTIME
667 #endif
668 
669  if(ignore_scans_head == NULL)
670  {
671 #ifdef DO_DSTIME
673 #endif
674  return(0);
675  }
676 
677  for(m=ignore_scans_head;m->next; m=m->next, i++)
678  {
679  if(m)
680  {
681  fprintf(fp, "ignore %d %7.2f\n", m->ver, m->scan);
682  }
683  }
684 
685  if(m)
686  {
687  fprintf(fp, "ignore %d %7.2f\n", m->ver, m->scan);
688  }
689 
690 #ifdef DO_DSTIME
692 #endif
693 
694  return(0);
695 }
696 
697 
698 
700 {
701  struct MAP_SCANS *m;
702  int i=0;
703 
704 #ifdef DO_DSTIME
706 #endif
707 
708  if(ignore_scans_head == NULL)
709  {
710  log_msg("None Ignored");
711 
712 #ifdef DO_DSTIME
714 #endif
715 
716  return(0);
717  }
718 
719  for(m=ignore_scans_head;m->next; m=m->next, i++)
720  {
721  if(m)
722  {
723  log_msg("Ignoring scan %3d = %7.2f, in Version: %d", i, m->scan, m->ver);
724  }
725  }
726 
727  if(m)
728  {
729  log_msg("Ignoring scan %3d = %7.2f, in Version: %d", i, m->scan, m->ver);
730  }
731 
732 #ifdef DO_DSTIME
734 #endif
735 
736  return(0);
737 }
738 
739 
740 
742 {
743 #ifdef DO_DSTIME
745 #endif
746 
747  remIgnoreScans();
748 
749 #ifdef DO_DSTIME
751 #endif
752 
753  return(0);
754 }
755 
756 
757 int checkMapScans(v, s)
758 int v;
759 float s;
760 {
761  struct MAP_SCANS *m;
762 
763 #ifdef DO_DSTIME
765 #endif
766 
767  if(otf.map_scans_head == NULL)
768  {
769 #ifdef DO_DSTIME
771 #endif
772  return(0);
773  }
774 
775  for(m=otf.map_scans_head;m->next; m=m->next)
776  {
777  if(m)
778  {
779  if(m->scan == s && m->ver == v)
780  {
781 #ifdef DO_DSTIME
783 #endif
784  return(1);
785  }
786  }
787  }
788 
789  if(m)
790  {
791  if(m->scan == s && m->ver == v)
792  {
793 #ifdef DO_DSTIME
795 #endif
796  return(1);
797  }
798  }
799 
800 #ifdef DO_DSTIME
802 #endif
803 
804  return(0);
805 }
806 
807 
808 int addMapScans(v, s)
809 int v;
810 float s;
811 {
812  struct MAP_SCANS *m;
813 
814 #ifdef DO_DSTIME
816 #endif
817 
818  if(otf.map_scans_head == NULL)
819  {
820  if((otf.map_scans_head=(struct MAP_SCANS *)malloc((unsigned)(sizeof(struct MAP_SCANS))))==NULL)
821  {
822  log_msg("Error of addMapScans addMapScans(malloc(%d))", sizeof(struct MAP_SCANS));
823 
824 #ifdef DO_DSTIME
826 #endif
827 
828  return(1);
829  }
830 
831  otf.map_scans_head->ver = v;
832  otf.map_scans_head->scan = s;
833  otf.map_scans_head->next = NULL;
834 
835 #ifdef DO_DSTIME
837 #endif
838 
839  return(0);
840  }
841 
842  for(m=otf.map_scans_head;m->next; m=m->next)
843  {
844  ;
845  }
846 
847  if((m->next=(struct MAP_SCANS *)malloc((unsigned)(sizeof(struct MAP_SCANS))))==NULL)
848  {
849  log_msg("Error of addMapScans addMapScans(malloc(%d))", sizeof(struct MAP_SCANS));
850 
851 #ifdef DO_DSTIME
853 #endif
854 
855  return(1);
856  }
857 
858  m->next->ver = v;
859  m->next->scan = s;
860  m->next->next = NULL;
861 
862 #ifdef DO_DSTIME
864 #endif
865 
866  return(0);
867 }
868 
869 
870 
872 {
873  struct MAP_SCANS *p;
874  struct MAP_SCANS *q;
875 
876 #ifdef DO_DSTIME
878 #endif
879 
880  for(p=otf.map_scans_head; p; p=q)
881  {
882  q = p->next;
883 
884  if(p)
885  {
886  free((char *)p);
887  }
888  }
889 
890  otf.map_scans_head = NULL;
891 
892 #ifdef DO_DSTIME
894 #endif
895 
896  return(0);
897 }
898 
899 
901 {
902  struct MAP_SCANS *m;
903  int i=0;
904 
905 #ifdef DO_DSTIME
907 #endif
908 
909  if(otf.map_scans_head == NULL)
910  {
911  log_msg("No Scans Loaded");
912 
913 #ifdef DO_DSTIME
915 #endif
916 
917  return(0);
918  }
919 
920  for(m=otf.map_scans_head;m->next; m=m->next, i++)
921  {
922  if(m)
923  {
924  log_msg("scan %3d = %7.2f, in version: %d", i, m->scan, m->ver);
925  }
926  }
927 
928  if(m)
929  {
930  log_msg("scan %3d = %7.2f, in version: %d", i, m->scan, m->ver);
931  }
932 
933 #ifdef DO_DSTIME
935 #endif
936 
937  return(0);
938 }
939 
940 
941 
943 float datalen, noint;
944 {
945  int dl;
946 
947 #ifdef DO_DSTIME
949 #endif
950 
951  dl = (int)datalen / ( sizeof(float) * ( (int)noint +5));
952 
953 #ifdef DO_DSTIME
955 #endif
956 
957  return(dl);
958 }
959 
960 
961 
963 struct SPECDATA *sd;
964 {
965  char sysBuf[256];
966  static time_t oldTime=0;
967  time_t t;
968 
969  t = time(NULL);
970 
971  if(abs(t-oldTime) > 5)
972  {
973  fprintf(stdout, "Starting specdata viewer\n");
974  fflush(stdout);
975 
976  log_msg("sock_write() returned Error; starting specdata viewer");
977 
978  sprintf(sysBuf, "specdata &");
979 
980  system(sysBuf);
981 
982 // usleep(250000);
983 
984  /* resend */
985 // ret = sock_write(specdata, (char *)sd, sizeof(*sd));
986 
987 // if(!ret)
988 // {
989 // fprintf(stdout, "sock_write() Still returning Error; Check Instalation\n");
990 // fflush(stdout);
991 
992 // log_msg("sock_write() Still returning Error; Check Installation");
993 
994 // }
995 
996  oldTime = t;
997  }
998 
999  return(0);
1000 }
1001 
1002 
1003 
1004 /* --------------- entry point of otf ------------------ */
1005 
1007 float *data, *offdata, *gainsdata;
1008 struct HEADER *head;
1009 {
1010  int ret;
1011  extern int sockWriteNoBitch; /* in ../cactus/lib/socknoxvlib.c */
1012 
1013 #ifdef DO_DSTIME
1015 #endif
1016 
1017  bcopy((char *)head, (char *)&lastHead, sizeof(struct HEADER));
1018 
1019  otf.head = &lastHead;
1020  otf.ondata = data;
1021  otf.offdata = offdata;
1024 
1026  {
1027  ok2grid = 0;
1028  otf.noint = (int)otf.head->noint;
1029  log_msg("DATASERV: Can not grid %.0f chans", otf.head->noint);
1030  }
1031  else
1032  {
1033  ok2grid = 1;
1034 
1035  if(!fillOtfGrid())
1036  {
1037  paintOtfGrid();
1038  }
1039  }
1040 
1041  bzero((char *)&sd, sizeof(sd));
1042 
1043  strcpy(sd.datafile, filename);
1044  strcpy(sd.gainsfile, gfilename);
1045 
1046  sd.scanno = (int)head->scan;
1047  sd.feed = (int)round((otf.IFNumber*100.0));
1050  sd.debugSpectra = 0;
1051  sd.doTPprocess = 1;
1052  sd.arrayNum = 2;
1053 
1054  sockWriteNoBitch = 1; /* In case it hasn't started yet, turn off sock_write(): libary bitching */
1055  ret = sock_write(specdata, (char *)&sd, sizeof(sd));
1056  sockWriteNoBitch = 0;
1057 
1058  if(!ret) /* Process specplot, not running or died; start it */
1059  {
1060 
1061  resendSpecData(&sd);
1062  }
1063 
1064 #ifdef DO_DSTIME
1066 #endif
1067 
1068  return(0);
1069 }
1070 
1071 
1072 
1074 {
1075 #ifdef DO_DSTIME
1077 #endif
1078 
1079  otf.newShade = 1;
1081 
1082  otf.valueMaxChanged = 1;
1083  otf.intenChanged = 1;
1084 
1085  if(otf.head == NULL)
1086  {
1087 #ifdef DO_DSTIME
1089 #endif
1090  return(1);
1091  }
1092 
1093  paintOtfGrid();
1095 
1096 #ifdef DO_DSTIME
1098 #endif
1099 
1100  return(0);
1101 }
1102 
1103 
1105 {
1106 #ifdef DO_DSTIME
1108 #endif
1109 
1110  if(debug)
1111  {
1112  log_msg("doOtfGridRePaint()");
1113  }
1114 
1115  otf.newShade = 1;
1116 
1117  if(otf.lastAction == INTERP)
1118  {
1119  if(debug)
1120  {
1121  log_msg("doOtfGridRePaint(): lastAction = INTERP");
1122  }
1123 
1124  otfInterp();
1125  }
1126  else
1127  if(otf.lastAction == NORMAL_MAP)
1128  {
1129  if(debug)
1130  {
1131  log_msg("doOtfGridRePaint(): lastAction = NORMAL_MAP");
1132  }
1133 
1134  paintOtfGrid();
1135  }
1136  else
1137  if(otf.lastAction == CHANNEL_MAP)
1138  {
1139  if(debug)
1140  {
1141  log_msg("doOtfGridRePaint(): lastAction = CHANNEL_MAP");
1142  }
1143 
1144  do_otfChannelMap(NULL);
1145  }
1146 
1147  if(lastGraph == OTF_GRAPH)
1148  {
1149  if(debug)
1150  {
1151  log_msg("doOtfGridRePaint(): LastGraph = OTF_GRAPH");
1152  }
1153 
1154  if(otf.lastAction == INTERP)
1155  {
1156  paintOtfGrid();
1157  otfInterp();
1158  }
1159  else
1160  if(otf.lastAction == NORMAL_MAP)
1161  {
1162  paintOtfGrid();
1163  }
1164  else
1165  if(otf.lastAction == CHANNEL_MAP)
1166  {
1167  do_otfChannelMap(NULL);
1168  }
1169  }
1170  else
1171  {
1172  if(debug)
1173  {
1174  log_msg("doOtfGridRePaint(): LastGraph = Unknown");
1175  }
1176  }
1177 
1178 #ifdef DO_DSTIME
1180 #endif
1181 
1182  return(0);
1183 }
1184 
1185 
1187 {
1188 #ifdef DO_DSTIME
1190 #endif
1191 
1192  if(debug)
1193  {
1194  log_msg("doOtfGridReSize()");
1195  }
1196 
1197  otf.newShade = 1;
1198 
1199 #ifdef DO_DSTIME
1201 #endif
1202 
1203  return(0);
1204 }
1205 
1206 
1207 
1209 {
1210  int i, bc, noint;
1211  struct OTF_GRID *g;
1212 
1213 #ifdef DO_DSTIME
1215 #endif
1216 
1217  if(!otf.gridArray || !otf.head)
1218  {
1219  log_msg("do_otfRmBadChan(): OTF Array or header is empty");
1220 #ifdef DO_DSTIME
1222 #endif
1223  return(1);
1224  }
1225 
1226  noint = otf.noint;
1227 
1228  for(i=0;i<MAX_BAD_CHAN;i++)
1229  {
1230  if((bc = badChanArray[i]))
1231  {
1232  bc--;
1233 
1234  if(bc > noint || bc < 0) /* if I have still screwed up, contiune */
1235  {
1236  continue;
1237  }
1238 
1239  log_msg("do_otfRmBadChan(): Removing Channel %4d from Map", bc);
1240 
1241  for(g=gridHead;g;g=g->next)
1242  {
1243  if(g->set == 1) /* Only work on valid celles */
1244  {
1245  if(bc == 0)
1246  {
1247  g->chans[bc] = g->chans[bc+1];
1248  }
1249  else
1250  if(bc == noint)
1251  {
1252  g->chans[bc] = g->chans[bc-1];
1253  }
1254  else
1255  {
1256  g->chans[bc] = (g->chans[bc-1] + g->chans[bc+1]) / 2.0;
1257  }
1258 
1259  g->bdirty = 1;
1260  g->ddirty = 1;
1261 
1262  otf.bdirty = 1;
1263  otf.ddirty = 1;
1264  }
1265  }
1266  }
1267  }
1268 
1269  otf.valueMaxChanged = 1;
1270  otf.intenChanged = 1;
1271  otf.newShade = 1;
1272 
1273  log_msg("do_otfRmBadChan(): Recomputing Baselines");
1274 
1276 
1277  paintOtfGrid();
1279 
1280  log_msg("do_otfRmBadChan(): Done");
1281 
1282 #ifdef DO_DSTIME
1284 #endif
1285 
1286  return(0);
1287 }
1288 
1289 
1290  /* Zero out any data points larger that 'max' */
1291 int spikeCheck(buf)
1292 char *buf;
1293 {
1294  int i, noint, nspec, nspike;
1295  float max, val;
1296  struct OTF_GRID *g;
1297 
1298 #ifdef DO_DSTIME
1300 #endif
1301 
1302  if(!otf.gridArray || !otf.head)
1303  {
1304  log_msg("spikeCheck(): OTF Array or header is empty");
1305 #ifdef DO_DSTIME
1307 #endif
1308  return(1);
1309  }
1310 
1311  if(buf)
1312  {
1313  max = atof(buf);
1314  }
1315  else
1316  {
1317  log_msg("Missing arg for despike");
1318 
1319 #ifdef DO_DSTIME
1321 #endif
1322 
1323  return(1);
1324  }
1325 
1326  if(max > 0.0)
1327  {
1328  noint = otf.noint;
1329 
1330  nspec = 0;
1331  for(g=gridHead;g;g=g->next)
1332  {
1333  if(g->set == 1) /* Only work on valid cells */
1334  {
1335  nspike = 0;
1336  for(i=0;i<noint;i++)
1337  {
1338  if(otf.gridBaseLine)
1339  {
1340  val = g->chans[i] - ((float)i * g->a + g->b);
1341  }
1342  else
1343  {
1344  val = g->chans[i];
1345  }
1346 
1347  if(fabs(val) > max)
1348  {
1349  g->chans[i] = 0.0;
1350 
1351  nspike++;
1352  }
1353  }
1354 
1355  if(nspike)
1356  {
1357  log_msg("Removed %d spikes in scan %.2f - %.2f", nspike, g->bscan, g->escan);
1358 
1359  nspec++;
1360  }
1361  }
1362  }
1363 
1365  forceDrawGrid();
1366 
1367  log_msg("Corrected %d spectra", nspec);
1368  }
1369 
1370 #ifdef DO_DSTIME
1372 #endif
1373 
1374  return(0);
1375 }
1376 
1377 int computeInten(bc, ec)
1378 int bc, ec;
1379 {
1380  int j, k, count=0, tcount=0;
1381  double accum, intInten, intInten2;
1382  struct OTF_GRID *g;
1383 
1384 #ifdef DO_DSTIME
1386 #endif
1387 
1388  if(!otf.gridArray || !otf.head)
1389  {
1390  log_msg("COMPUTEINTEN: OTF Array or header is empty");
1391 #ifdef DO_DSTIME
1393 #endif
1394  return(1);
1395  }
1396 
1397  if(bc < 0 || bc > otf.noint-1 || ec > otf.noint-1)
1398  {
1399  log_msg("COMPUTEINTEN: bc, %d; or ec, %d; greater then nochan, %d", bc, ec, otf.noint);
1400 #ifdef DO_DSTIME
1402 #endif
1403  return(1);
1404  }
1405 
1406  log_msg("computeInten(): Started");
1407 
1408  /* now compute area under curve for selected chans */
1409  for(g=gridHead;g;g=g->next)
1410  {
1411  if(g->set == 1)
1412  {
1413  tcount++;
1414 
1415  if(g->ddirty) /* Only work on valid celles */
1416  {
1417  if(otf.whichPlot != PLOT_TSYS && otf.whichPlot != PLOT_RMS) /* Don't waste time */
1418  {
1419  k = 0;
1420  accum = 0.0;
1421  j = bc;
1422 
1423  do
1424  {
1425  if(otf.gridBaseLine)
1426  {
1427  accum += g->chans[j] - ((float)j * g->a + g->b);
1428  }
1429  else
1430  {
1431  accum += g->chans[j];
1432  }
1433 
1434  k++;
1435  } while(j++<ec);
1436  }
1437 
1438  g->kms = (float)(accum * fabs(otf.head->deltax));
1439  intInten = (float)(accum / (double)k) * otf.scaleFactor;
1440 
1441  /* Apply Gamma correction if cell > 0.0 */
1442  if(intInten > 0.0)
1443  {
1444  intInten2 = (double)MAX_GRAY_SCALE * pow((intInten / (double)MAX_GRAY_SCALE), otf.gamma);
1445 
1446  if(isnan(intInten2))
1447  {
1448  log_msg("Col %d, Row %d: intInten = %f using Gamma of %f", g->col, g->row, intInten, otf.gamma);
1449  g->intInten = intInten;
1450  }
1451  else
1452  {
1453  g->intInten = intInten2;
1454  }
1455  }
1456  else
1457  {
1458  g->intInten = intInten;
1459  }
1460 
1461  g->ddirty = 0;
1462  count++;
1463  }
1464 
1465  /* Assign & Apply scaling factor */
1466 
1467  switch(otf.whichPlot)
1468  {
1469  case PLOT_INT_INTENSITY:
1470  g->plotVal1 = g->intInten;
1471  g->plotVal2 = g->kms;
1472 
1473  break;
1474 
1475  case PLOT_RMS:
1476  g->plotVal1 = g->rms;
1477  g->plotVal2 = g->rms;
1478 
1479  break;
1480 
1481  case PLOT_TSYS:
1482  g->plotVal1 = g->tsys;
1483  g->plotVal2 = g->tsys;
1484 
1485  break;
1486 
1487  case PLOT_TIME:
1488  g->plotVal1 = g->time;
1489  g->plotVal2 = g->time;
1490 
1491  break;
1492  }
1493 
1494  if(isnan(g->plotVal1))
1495  {
1496  g->plotVal1 = 0.0;
1497  }
1498  }
1499  }
1500 
1501  log_msg("computeInten(): Computed %d out of %d populated cells", count, tcount);
1502 
1503 #ifdef DO_DSTIME
1505 #endif
1506 
1507  return(0);
1508 }
1509 
1510 
1512 {
1513  struct OTF_GRID *g;
1514 
1515 #ifdef DO_DSTIME
1517 #endif
1518 
1519  if(!otf.gridArray)
1520  {
1521  log_msg("COMPUTEMINMAX: OTF Array is empty");
1522 #ifdef DO_DSTIME
1524 #endif
1525 
1526  return(1);
1527  }
1528 
1529  if(!otf.valueMaxChanged)
1530  {
1531 #ifdef DO_DSTIME
1533 #endif
1534  return(0);
1535  }
1536 
1537  if(otf.lockScale)
1538  {
1539 #ifdef DO_DSTIME
1541 #endif
1542  return(0);
1543  }
1544 
1545  if(debug)
1546  {
1547  log_msg("COMPUTEMINMAX: Recomputing OTF Cell Min & Max Values");
1548  }
1549 
1550  otf.valueMin = 999999999.0;
1551  otf.valueMax = -999999999.0;
1552 
1553  otf.numCellsUsed = 0;
1554  zeroCellCount = 0;
1555  artificialCells = 0;
1556 
1557  for(g=gridHead;g;g=g->next)
1558  {
1559  if(g->set == 1) /* Only work on valid celles */
1560  {
1561  if(g->col == 0 && g->row == 0) /* How many cells think there are 0, 0 */
1562  {
1563  zeroCellCount++;
1564  }
1565 
1566  if(g->artificial)
1567  {
1568  artificialCells++;
1569  }
1570 
1571  if(g->plotVal1 > otf.valueMax)
1572  {
1573  otf.valueMax = g->plotVal1;
1574 
1575  otf.valueMaxX = g->col;
1576  otf.valueMaxY = g->row;
1577  }
1578 
1579  if(g->plotVal1 < otf.valueMin)
1580  {
1581  otf.valueMin = g->plotVal1;
1582 
1583  otf.valueMinX = g->col;
1584  otf.valueMinY = g->row;
1585  }
1586 
1587  otf.numCellsUsed++;
1588  }
1589  }
1590 
1591  otf.valueMaxChanged = 0;
1592 
1593 #ifdef DO_DSTIME
1595 #endif
1596 
1597  return(0);
1598 }
1599 
1600 
1601 
1603 {
1604  struct OTF_GRID *g;
1605  float d;
1606 
1607 #ifdef DO_DSTIME
1609 #endif
1610 
1611  if(!otf.gridArray)
1612  {
1613  log_msg("COMPUTESHADE: OTF Array is empty");
1614 #ifdef DO_DSTIME
1616 #endif
1617  return(1);
1618  }
1619 
1620  if(!otf.newShade)
1621  {
1622 #ifdef DO_DSTIME
1624 #endif
1625  return(0);
1626  }
1627 
1628  if(debug)
1629  {
1630  log_msg("COMPUTESHADE: Recomputing OTF Cell Color Shades");
1631  }
1632 
1633  d = (float)max_gray_scale / otf.valueMax * otf.scaleFactor;
1634 
1635  for(g=gridHead;g;g=g->next)
1636  {
1637  if(g->set == 1) /* Only work on valid celles */
1638  {
1639  if(otf.valueMax == 0.0)
1640  {
1641  g->shade = 1;
1642  }
1643  else
1644  {
1645  g->shade = (int)((g->plotVal1) * d);
1646  }
1647 
1648  if(g->shade > max_gray_scale-1)
1649  {
1650  g->shade = max_gray_scale-1;
1651  }
1652 
1653  if(g->shade < 1)
1654  {
1655  g->shade = 1;
1656  }
1657 
1658  if(g->plotVal1 == otf.valueMax)
1659  {
1660  if(otf.whichPlot == PLOT_TSYS)
1661  {
1662  sprintf(otf.peakStr, " Tsys %8.4f", g->plotVal1);
1663  }
1664  else
1665  if(otf.whichPlot == PLOT_RMS)
1666  {
1667  sprintf(otf.peakStr, " rms %8.4f", g->plotVal1);
1668  }
1669  else
1670  if(otf.whichPlot == PLOT_TIME)
1671  {
1672  sprintf(otf.peakStr, " time %8.4f", g->plotVal1);
1673  }
1674  else
1675  {
1676  sprintf(otf.peakStr, "Intensity %8.4f", g->plotVal1);
1677  }
1678  }
1679  }
1680  }
1681 
1682 #ifdef DO_DSTIME
1684 #endif
1685 
1686  return(0);
1687 }
1688 
1689 
1690 
1692 float *data;
1693 {
1694  int i;
1695 
1696 #ifdef DO_DSTIME
1698 #endif
1699 
1700  for(i=0;i<otf.numSpectra;i++)
1701  {
1702  data[i] *= 3600.0;
1703  }
1704 
1705 #ifdef DO_DSTIME
1707 #endif
1708 
1709  return(0);
1710 }
1711 
1712 
1713 
1714 
1716 float *data;
1717 {
1718  float xmin, xscale;
1719  int i;
1720 
1721 #ifdef DO_DSTIME
1723 #endif
1724 
1725  xscale = otf.head->inttime * otf.head->deltaxr / 3600.0;
1726  xmin = xscale / -2.0;
1727  xscale = xscale / (float)otf.numSpectra;
1728 
1729  if(data[0] > 0)
1730  {
1731  for(i=0;i<otf.numSpectra;i++)
1732  {
1733  data[i] += (xmin + (xscale * (float)i));
1734  data[i] *= 3600.0;
1735  }
1736  }
1737  else
1738  {
1739  for(i=0;i<otf.numSpectra;i++)
1740  {
1741  data[i] -= (xmin + (xscale * (float)i));
1742  data[i] *= 3600.0;
1743  }
1744  }
1745 
1746 #ifdef DO_DSTIME
1748 #endif
1749 
1750  return(0);
1751 }
1752 
1753 
1754 
1756 {
1757  int color, size;
1758  float deltax, deltay, xstart, ystart, bsize;
1759 
1760 #ifdef DO_DSTIME
1762 #endif
1763 
1764  if(otf.beamRa == 0.0)
1765  {
1766  otf.beamRa = otf.manMapRa;
1768  }
1769 
1770  if(otf.placeBeamSize == 1) /* Radio beam size in arc-seconds */
1771  {
1772  bsize = otf.head->bfwhm;
1773 
1774  color = WHITE;
1775  size = 1;
1776  }
1777  else
1778  if(otf.placeBeamSize == 2) /* display the Moon's size in arc-seconds */
1779  {
1780  bsize = 32.0 * 60.0;
1781 
1782  color = MAGENTA;
1783  size = 2;
1784  }
1785  else
1786  {
1787  return(0);
1788  }
1789 
1790  deltax = bsize / 3600.0 / 15.0;
1791  deltay = bsize / 3600.0;
1792 
1793  xstart = otf.beamRa / 15.0 + deltax;
1794  ystart = otf.beamDec + deltay;
1795 
1796  log_msg("placeBeamSize(): xstart = %f, ystart = %f, deltax = %f, deltay = %f", xstart, ystart, deltax, deltay);
1797 
1800  xstart, ystart,
1801  xstart+deltax*2.0, ystart-deltay*2.0,
1802  color, size);
1803 
1804 #ifdef DO_DSTIME
1806 #endif
1807 
1808  return(0);
1809 }
1810 
1811 
1813 {
1814  int ret;
1815 
1816  do_etimeClear();
1817 
1818 #ifdef DO_DSTIME
1820 #endif
1821 
1822  if((ret = otfGridInit(otf.cols, otf.rows, otf.noint)))
1823  {
1824  if(debug)
1825  {
1826  log_msg("initGrid(): otfGridInit() returned %d", ret);
1827  }
1828 
1829 #ifdef DO_DSTIME
1831 #endif
1832 
1833  return(1);
1834  }
1835 
1836 #ifdef DO_DSTIME
1838 #endif
1839 
1840  return(0);
1841 }
1842 
1843 
1845 {
1846  static int first=1;
1847  float xl, xr, yt, yb;
1848  float xmin, xmax, ymin, ymax, kmin, kmax;
1849  int row, col;
1850  float deltax, deltay;
1851  float xscale, yscale;
1852  struct OTF_GRID *f;
1853  char tbuf[256];
1854 
1856  {
1857  if(debug)
1858  {
1859  log_msg("paintOtfGrid(): ignoreAllRepaints set: Ignoring ForceDrawGrid");
1860  }
1861 
1862  return(0);
1863  }
1864 
1865 #ifdef DO_DSTIME
1867 #endif
1868 
1869  log_msg("paintOtfGrid(): Enter");
1870 
1871  if(first)
1872  {
1873  log_msg("paintOtfGrid(): Resizing Gridder Window");
1874 
1875  first = 0;
1876  }
1877 
1878  if(debug)
1879  {
1880  log_msg(" ");
1881  log_msg("paintOtfGrid()");
1882  }
1883 
1884  if(!otf.head)
1885  {
1886  if(debug)
1887  {
1888  log_msg("paintOtfGrid(): No otf.head; returning");
1889  }
1890 
1891 #ifdef DO_DSTIME
1893 #endif
1894 
1895  return(1);
1896  }
1897 
1898  if(debug)
1899  {
1900  log_msg("paintOtfGrid(): otf.initialized = %d; ok2grid = %d", otf.initialized, ok2grid);
1901  }
1902 
1903  if(!otf.initialized)
1904  {
1905  initGrid();
1906  }
1907 
1908  lastGraph = OTF_GRAPH;
1909 
1910  if(otf.noPlot)
1911  {
1912  log_msg("paintOtfGrid(): Done");
1913 #ifdef DO_DSTIME
1915 #endif
1916  return(0);
1917  }
1918 
1919  if(!thisIsaRefresh)
1920  {
1921  setInValid(1);
1922  }
1923 
1925 
1926  if(otf.head->obsmode && !strncmp(otf.head->obsmode, "LINEOTF ", 8))
1927  {
1928  xgr_mapUnmapWindow("OTF Gridder", 1);
1929  }
1930 
1931  if(otf.newShade)
1932  {
1933  xgr_clearScreen();
1934  }
1935 
1936  xscale = otf.nyquistRa / 3600.0 * otf.cols;
1937  xmin = xscale / -2.0 - otf.nyquistRa / 7200.0;
1938  xmax = xscale / 2.0 - otf.nyquistRa / 7200.0;
1939  xmin = xmin / (15.0 * cos(otf.ysource * CTR));
1940  xmax = xmax / (15.0 * cos(otf.ysource * CTR));
1941 
1942  yscale = (otf.nyquistDec * otf.rows) / 3600.0;
1943  ymin = yscale / -2.0;
1944  ymax = yscale / 2.0;
1945 
1946  globalXmin = xmin + otf.xsource / 15.0;
1947  globalXmax = xmax + otf.xsource / 15.0;
1948  globalYmin = ymin + otf.ysource;
1949  globalYmax = ymax + otf.ysource;
1950 
1951  otf.plotxb = OTFPLOTXB;
1952  otf.plotxe = OTFPLOTXE;
1953  otf.plotyb = OTFPLOTYB;
1954  otf.plotye = OTFPLOTYE;
1955 
1956  deltax = (xmax - xmin) / (float)otf.cols;
1957  deltay = (ymax - ymin) / (float)otf.rows;
1958 
1960 
1962 
1963  computeMinMax();
1964  computeShade();
1965 
1966  kmin = 999999999.0;
1967  kmax = -999999999.0;
1968 
1969  if(debug)
1970  {
1971  log_msg("PAINTGRID: Regenerating OTF Plot");
1972  }
1973 
1974  if(otf.gridArray)
1975  {
1976  for(row=0;row<otf.rows;row++)
1977  {
1978  for(col=0;col<otf.cols;col++)
1979  {
1980  f = fetchMapCell(row, col);
1981 
1982  if(!f)
1983  {
1984  continue;
1985  }
1986 
1987  if(f->set == -1) /* Used but ignored */
1988  {
1989  continue;
1990  }
1991 
1992  xl = xmin+(float)col * deltax;
1993  xr = xmin+(float)(col+1) * deltax;
1994  yt = ymin+(float)row * deltay;
1995  yb = ymin+(float)(row+1) * deltay;
1996 
1997  if(otf.newShade || f->shade != f->oldshade)
1998  {
1999  if(f->shade > (otf.cutoff * max_gray_scale / 100))
2000  {
2001  xgr_drawFillBox( xmin, xmax, ymin, ymax, xl, yt, xr, yb, f->shade * -1);
2002  }
2003  else
2004  {
2005  xgr_drawFillBox( xmin, xmax, ymin, ymax, xl, yt, xr, yb, -1); /* make it the lowet shade */
2006  }
2007 
2008  f->oldshade = f->shade;
2009  }
2010 
2011  if(f->plotVal2 > kmax)
2012  {
2013  kmax = f->plotVal2;
2014  }
2015 
2016  if(f->plotVal2 < kmin)
2017  {
2018  kmin = f->plotVal2;
2019  }
2020  }
2021  }
2022 
2023  otf.newShade = 0;
2025 
2026  putOtfGrid();
2027 
2028  xgr_drawTextClear(0.01, 0.010, otf.peakStr, YELLOW, font0);
2029 
2030  drawColorBar();
2031 
2032  xgr_drawGrid(kmin/otf.scaleFactor, kmax/otf.scaleFactor, ymin, ymax,
2033  max_gray_scale, 1, 6, 1, -1, 1,
2035 
2036  if(otf.whichPlot == PLOT_TSYS)
2037  {
2038  xgr_drawTextClear(0.5, 0.010, " Tsys", YELLOW, font0);
2039  }
2040  else
2041  if(otf.whichPlot == PLOT_RMS)
2042  {
2043  xgr_drawTextClear(0.5, 0.010, " rms ", YELLOW, font0);
2044  }
2045  else
2046  if(otf.whichPlot == PLOT_TIME)
2047  {
2048  xgr_drawTextClear(0.5, 0.010, " time", YELLOW, font0);
2049  }
2050  else
2051  {
2052  xgr_drawTextClear(0.5, 0.010, " K * km/s", YELLOW, font0);
2053  }
2054 
2055  sprintf(tbuf, "Scale: %6.2f", otf.scaleFactor);
2056  xgr_drawTextClear(0.3, 0.010, tbuf, YELLOW, font0);
2057 
2058  sprintf(tbuf, "Gamma: %6.2f", otf.gamma);
2059  xgr_drawTextClear(0.75, 0.010, tbuf, YELLOW, font0);
2060 
2062 
2063  placeBeamSize();
2064  }
2065 
2066  if(otf.regionshow)
2067  {
2068  drawRegions();
2069  }
2070 
2071  xgr_pixmapToWindow("OTF Gridder");
2072 
2073  if(otf.valueMax < 0.0)
2074  {
2075  otf.valueMax = 10.0;
2076  }
2077 
2079 
2080  if(debug)
2081  {
2082  log_msg(" ");
2083  }
2084 
2085  log_msg("paintOtfGrid(): Done");
2086 
2087 #ifdef DO_DSTIME
2089 #endif
2090 
2091  return(0);
2092 }
2093 
2094 
2096 {
2097  if(!otf.cols || !otf.rows)
2098  return(0);
2099 
2101  otf.cols, otf.rows, 4, 4, 1, 3, GRAY50, YELLOW, XGR_PLOT_SEX);
2102 
2103  return(0);
2104 }
2105 
2106 
2107 
2109 {
2110  float xl, xr, yt, yb;
2111  float deltax, deltay;
2112  int i;
2113  float xmin, xmax, ymin, ymax;
2114 
2115  if(otf.noColorBar)
2116  {
2117  otf.noColorBar = 0;
2118  return(0);
2119  }
2120  xmin = globalXmin;
2121  xmax = globalXmax;
2122  ymin = globalYmin;
2123  ymax = globalYmax;
2124  deltax = (xmax - xmin) / (float)(max_gray_scale-1.0);
2125  deltay = (ymax - ymin) / (float)1;
2127  for(i=0;i<max_gray_scale;i++)
2128  {
2129  xl = xmin+(float)i*deltax;
2130  xr = xmin+(float)(i+1)*deltax;
2131  yt = ymin;
2132  yb = ymin +1.0*deltay;
2133 
2134  if( (i+1) > (otf.cutoff * max_gray_scale / 100))
2135  {
2136  xgr_drawFillBox( xmin, xmax, ymin, ymax, xl, yt, xr, yb,(i+1)*-1);
2137  }
2138  else
2139  {
2140  xgr_drawFillBox( xmin, xmax, ymin, ymax, xl, yt, xr, yb, BLACK);
2141  }
2142  }
2143 
2144  return(0);
2145 }
2146 
2147 
2148 
2150 {
2151  int noint;
2152 
2153  if(!otf.head)
2154  {
2155  return(1);
2156  }
2157 
2158  otf.xsource = otf.manMapRa;
2162 
2164  {
2165  log_msg("Scan %.2f, version: %d, already in grid", otf.head->scan, version);
2166 
2167  return(1);
2168  }
2169 
2170  if(fabs(otf.restfreq - otf.head->restfreq) > 0.5 && otf.restfreq != -1.0)
2171  {
2172  log_msg("Rest Freq %.2f: NOT the same as grid %.2f", otf.head->restfreq, otf.restfreq);
2173 
2174  return(1);
2175  }
2176 
2177  if(fabs(otf.velocity - otf.head->velocity) > 0.5 && otf.velocity != -1.0)
2178  {
2179 // log_msg("Velocity %.2f: NOT the same as grid %.2f", otf.head->velocity, otf.velocity);
2180 
2181  if(!otf.allowVelShift)
2182  {
2183  return(1);
2184  }
2185  }
2186 
2187  if(fabs(otf.freqres - otf.head->freqres) > 0.001 && otf.freqres != -1.0 )
2188  {
2189  log_msg("Resolution %.2f: NOT the same as grid %.2f", otf.head->freqres, otf.freqres);
2190 
2191  return(1);
2192  }
2193 
2194  noint = (int)otf.head->noint;
2195 
2196  if(noint != otf.noint) /* this fixed a very hidious bug */
2197  {
2198  log_msg("Number of Channels %d, Not the same as grid %d", noint, otf.noint);
2199 
2200  return(1);
2201  }
2202 
2203  otf.valueMaxChanged = 1;
2204  otf.row = (int)(otf.head->ycell0 - 1.0);
2205 
2207 
2209 
2210  otf.valueMaxChanged = 1;
2211  otf.intenChanged = 1;
2212  otf.newShade = 1;
2213 
2214  return(0);
2215 }
2216 
2217 
2219 {
2220  int i, j, first = 1, rej;
2221  int workCent_x = -1, workCent_y = -1;
2222  int colIndx, rowIndx;
2223  int cell_x, cell_y;
2224  float *raData, *decData;
2225  float ra, dec;
2226  struct GRID_ACCUM *p;
2227  double *w;
2228  float *o;
2229  double deltaRa = 0.0, deltaDec = 0.0, cosDec;
2230 
2231  zeroWorkArray();
2232 
2233  raData = &otf.ondata[otf.noint * otf.numSpectra + otf.numSpectra*1];
2234  decData = &otf.ondata[otf.noint * otf.numSpectra + otf.numSpectra*2];
2235 
2236  rej = 0;
2237 
2238  if(!ephemObj)
2239  {
2240  deltaRa = otf.xsource - otf.head->xsource;
2241  deltaDec = otf.ysource - otf.head->ysource;
2242  }
2243 
2244  if(debug)
2245  {
2246  log_msg("ACCUMULATOR: Loading Scan %7.2f", otf.head->scan);
2247  }
2248 
2249  cosDec = cos(otf.head->ysource * CTR);
2250 
2251  for(i=0;i<otf.numSpectra;i++)
2252  {
2253  ra = (*raData++ / cosDec - deltaRa) * 3600.0;
2254  dec = (*decData++ - deltaDec) * 3600.0;
2255 
2256  colIndx = (int)rint(((float)otf.cols-1.0) - ((ra / otf.nyquistRa) + (float)otf.cols / 2.0));
2257  rowIndx = (int)rint( ((dec / otf.nyquistDec) + ((float)otf.rows + 1.0) / 2.0) -1.0);
2258 
2259 // colIndx = (otf.cols-1) - ((int)(ra / otf.nyquistRa) + otf.cols / 2);
2260 // rowIndx = (int)rint(((dec / otf.nyquistDec) + ((float)otf.rows+1.0) / 2.0) -1.0);
2261 
2262 // log_msg("ACCUMULATOR(): ra = %f, colIndx = %3d, Dec = %f, rowIndx = %3d", ra, colIndx, dec, rowIndx);
2263 
2264  if(colIndx<0 || colIndx>otf.cols-1 || rowIndx<0 || rowIndx>otf.rows-1)
2265  {
2266  rej++;
2267 
2268  continue;
2269  }
2270 
2271  if(first)
2272  {
2273  workCent_x = colIndx;
2274  workCent_y = rowIndx;
2275  first = 0;
2276  }
2277 
2278  cell_x = workCent_x - colIndx;
2279  cell_y = workCent_y - rowIndx;
2280 
2281  if(cell_x < WORK_ARRAY_X_M || cell_x > WORK_ARRAY_X_P || cell_y < WORK_ARRAY_Y_M || cell_y > WORK_ARRAY_Y_P)
2282  {
2283  normalizeAndCal();
2284 
2286 
2287  zeroWorkArray();
2288 
2289  workCent_x = colIndx;
2290  workCent_y = rowIndx;
2291  cell_x = 0;
2292  cell_y = 0;
2293  }
2294 
2295  p = &workArray[cell_x + WORK_ARRAY_X_CENT] [cell_y + WORK_ARRAY_Y_CENT];
2296  w = &p->chans[0];
2297  o = &otf.ondata[i*otf.noint];
2298 
2299  p->n++;
2300  p->col = colIndx;
2301  p->row = rowIndx;
2302 
2303  for(j=0;j<otf.noint;j++, w++, o++)
2304  {
2305  *w += (double)*o;
2306  }
2307  }
2308 
2309  if(rej)
2310  {
2311  if(rej == otf.numSpectra)
2312  {
2313  log_msg("ACCUMULATOR: Scan: %.2f: All %d Spectra Out of Bounds", otf.head->scan, rej);
2314  return(0);
2315  }
2316 
2317  log_msg("ACCUMULATOR: Scan: %.2f: %d Spectra Out of Bounds", otf.head->scan, rej);
2318  }
2319 
2320  normalizeAndCal();
2322 
2323  return(0);
2324 }
2325 
2326 
2327 
2329 {
2330  int col, row;
2331  struct GRID_ACCUM *p;
2332 
2333  for(col=0;col<WORK_ARRAY_X;col++)
2334  {
2335  for(row=0;row<WORK_ARRAY_Y;row++)
2336  {
2337  p = &workArray[col][row];
2338  p->n = 0;
2339  p->col = 0;
2340  p->row = 0;
2341  p->wt = 0.0;
2342  }
2343  }
2344 
2345  bzero((char *)workArrayChans, otf.sizeofWorkArray);
2346 
2347  return(0);
2348 }
2349 
2350 
2351 
2353 {
2354  int col, row, k;
2355  struct GRID_ACCUM *p;
2356  double *w;
2357  float *o, *g;
2358 
2359  for(col=0;col<WORK_ARRAY_X;col++)
2360  {
2361  for(row=0;row<WORK_ARRAY_Y;row++)
2362  {
2363  p = &workArray[col][row];
2364 
2365  if(!p->n) /* no data in this cell */
2366  {
2367  continue;
2368  }
2369 
2370  w = &p->chans[0];
2371  o = &otf.offdata[0];
2372  g = &otf.gainsdata[0];
2373 
2374  for(k=0;k<otf.noint;k++, w++, o++, g++)
2375  {
2376  *w = (((*w / (double)p->n) - (double)*o) / (double)*o) * (double)*g;
2377  }
2378 
2379  p->wt = (double)p->n * 0.1 / ((double)otf.head->stsys * (double)otf.head->stsys);
2380  }
2381  }
2382 
2383  return(0);
2384 }
2385 
2386 
2387 int insertVersion(g, ver)
2388 struct OTF_GRID *g;
2389 int ver;
2390 {
2391  int i;
2392 
2393  for(i=0;i<8;i++) /* Check if it's already in here */
2394  {
2395  if(g->version[i] == ver)
2396  {
2397  return(0); /* yes, return */
2398  }
2399  }
2400 
2401  for(i=0;i<8;i++) /* No, so add it */
2402  {
2403  if(g->version[i] == 0) /* Find an empty slot */
2404  {
2405  g->version[i] = ver;
2406 
2407  return(0);
2408  }
2409  }
2410 
2411  return(1);
2412 }
2413 
2414 
2415 
2417 double *in;
2418 int n, shift;
2419 {
2420  int i, k, s;
2421  double avg;
2422  static double out[MAX_DATA_CHANNELS];
2423 
2424  if(!shift) /* Nothing to do */
2425  {
2426  return(0);
2427  }
2428 
2429  bzero((char *)&out[0], sizeof(out));
2430 
2431  avg = 0.0;
2432  s = abs(shift);
2433  if(shift > 0)
2434  {
2435 // log_msg("shiftOtfChans(): Shifting %d channels to the Right", s);
2436 
2437  k = s;
2438  for(i=0;i<(n-s);i++,k++) /* shift and copy */
2439  {
2440  out[k] = in[i];
2441  }
2442 
2443  /* find a suitable average */
2444  for(i=0;i<5;i++)
2445  {
2446  avg += in[i];
2447  }
2448  avg /= 5.0;
2449 
2450 // log_msg("shiftOtfChans(): filling %d Beginning channels with %f", s, avg);
2451 
2452  for(i=0;i<s;i++) /* Fill in first shift channels with average */
2453  {
2454  out[i] = avg;
2455  }
2456  }
2457  else
2458  {
2459 // log_msg("shiftOtfChans(): Shifting %d channels to the Left", s);
2460 
2461  k = 0;
2462  for(i=s;i<n;i++,k++) /* shift and copy */
2463  {
2464  out[k] = in[i];
2465  }
2466 
2467  /* find a suitable average */
2468  for(i=(n-5);i<n;i++)
2469  {
2470  avg += in[i];
2471  }
2472  avg /= 5.0;
2473 
2474 // log_msg("shiftOtfChans(): filling %d Ending channels with %f", s, avg);
2475 
2476  for(i=(n-s);i<n;i++,k++)
2477  {
2478  out[k] = avg; /* k still holds the index */
2479  }
2480  }
2481 
2482  /* put it back */
2483 
2484  for(i=0;i<n;i++)
2485  {
2486  in[i] = out[i];
2487  }
2488 
2489  return(0);
2490 }
2491 
2492 
2493 
2494 /* Accumilate the x x Y work array into the greater OTF map.
2495  If there is a velocity offset, here is where we fix that.
2496  */
2498 {
2499  int n, row, col, k, shift = 0;
2500  struct GRID_ACCUM *p;
2501  struct OTF_GRID *f;
2502  float *w;
2503  double *o;
2504 
2505  if(!otf.gridArray)
2506  {
2507  log_msg("ACCUM: OTF Array is empty");
2508 
2509  return(1);
2510  }
2511 
2512 // log_msg("accumWorkIntoGrid(): Enter: %.2f", otf.head->scan);
2513 
2514  shift = rint((otf.head->velocity - (double)otf.velocity) / otf.head->deltax);
2515 
2516  if(shift)
2517  {
2518  log_msg("accumWorkIntoGrid(): Need to shift %d channels, for %f %f", shift, otf.velocity, otf.head->velocity);
2519  }
2520 
2521  n = otf.noint;
2522 
2523  for(col=0;col<WORK_ARRAY_Y;col++)
2524  {
2525  for(row=0;row<WORK_ARRAY_X;row++)
2526  {
2527  p = &workArray[col][row];
2528 
2529  if(!p->n) /* no data in this cell */
2530  {
2531  continue;
2532  }
2533 
2534  f = fetchMapCell(p->row, p->col);
2535 
2536  if(!f) /* malloc space for grid array info on a as needed basis */
2537  {
2538 // if((f = (struct OTF_GRID *)malloc((sizeof(struct OTF_GRID)))) == NULL)
2539  if((f = (struct OTF_GRID *)calloc((sizeof(struct OTF_GRID)), 1)) == NULL)
2540  {
2541  log_msg("Err accumWorkIntoGrid(malloc(%d))", sizeof(struct OTF_GRID));
2542  return(1);
2543  }
2544 
2545 // bzero((char *)f, sizeof(struct OTF_GRID));
2546 
2548 
2549  setMapCell(p->row, p->col, f);
2550 
2551  if(gridLast)
2552  {
2553  gridLast = gridLast->next = f;
2554  }
2555  else
2556  {
2557  gridHead = gridLast = f;
2558  }
2559 
2560  }
2561 
2562  if(!f->chans) /* malloc space for channels on a as needed basis */
2563  {
2564  if((f->chans=(float *)malloc((unsigned)(n*sizeof(float))))==NULL)
2565  {
2566  log_msg("Error in accumWorkIntoGrid(malloc(%d))", n*sizeof(float));
2567  return(1);
2568  }
2569  bzero((char *)f->chans, n * sizeof( float) );
2570  }
2571 
2572  w = f->chans;
2573  o = p->chans;
2574 
2575  if(shift) /* shift before averaging in */
2576  {
2577  shiftOtfChans(o, n, shift);
2578  }
2579 
2580  for(k=0;k<n;k++, o++, w++)
2581  {
2582  *w = ((double)*w * f->wt + *o * p->wt) / (f->wt + p->wt);
2583  }
2584 
2585  f->wt += p->wt;
2586  f->intInten = 0.0;
2587  f->set = 1;
2588  f->time += (float)p->n * 0.1;
2589  f->scanct += 1.0;
2590 
2591  f->tsys = sqrt(1.0 / (f->wt / f->time));
2592 
2593  if(f->bscan == 0.0)
2594  {
2595  f->bscan = otf.head->scan;
2596  }
2597 
2598  f->escan = otf.head->scan;
2599  f->col = p->col;
2600  f->row = p->row;
2601 
2602  insertVersion(f, version);
2603 
2604  strncpy(f->source, otf.head->object, 16);
2605  f->source[15] = '\0';
2606 
2607  f->bdirty = 1;
2608  f->ddirty = 1;
2609 
2610  otf.bdirty = 1;
2611  otf.ddirty = 1;
2612 
2613  computeBaseLine(f, 0, 0, 0, 0, 0, 0);
2614  }
2615  }
2616 
2617  return(1);
2618 }
2619 
2620 
2622 {
2623  struct OTF_GRID *g;
2624 
2625  log_msg("markDataDirty()");
2626 
2627  for(g=gridHead;g;g=g->next)
2628  {
2629  if(g->set == 1) /* Only work on valid cells */
2630  {
2631  g->ddirty = 1;
2632  }
2633  }
2634 
2635  otf.ddirty = 1;
2636 
2637  return(0);
2638 }
2639 
2640 
2642 {
2643  struct OTF_GRID *g;
2644 
2645  log_msg("markBaseDirty()");
2646 
2647  for(g=gridHead;g;g=g->next)
2648  {
2649  if(g->set == 1) /* Only work on valid cells */
2650  {
2651  g->bdirty = 1;
2652  }
2653  }
2654 
2655  otf.bdirty = 1;
2656 
2657  return(0);
2658 }
2659 
2660 
2661 
2663 {
2664  struct OTF_GRID *g;
2665 
2666  if(!otf.gridArray)
2667  {
2668  log_msg("BASELINE: OTF Array is empty");
2669 
2670  return(1);
2671  }
2672 
2673  if(debug)
2674  {
2675  log_msg("BASELINE: Recomputing OTF Cell Baselines");
2676  }
2677 
2678  for(g=gridHead;g;g=g->next)
2679  {
2680  if(g->set == 1) /* Only work on valid celles */
2681  {
2682  computeBaseLine(g, 0, 0, 0, 0, 0, 0);
2683  }
2684  }
2685 
2686  return(1);
2687 }
2688 
2689 
2690 int computeBaseLine(g, data, a, b, Rms, noint, mode)
2691 struct OTF_GRID *g;
2692 float *data, *a, *b, *Rms;
2693 int noint, mode;
2694 {
2695  int i, j, l, k, noInt;
2696  float x[MAX_DATA_CHANNELS],
2697  sig[MAX_DATA_CHANNELS],
2698  lsqArray[MAX_DATA_CHANNELS];
2699  float a1, b1, siga1, sigb1, chi2_1, q1;
2700  float *p, rms;
2701  double avg = 0.0;
2702 
2703  if(mode == 0)
2704  {
2705  if(!g->set)
2706  {
2707  return(0);
2708  }
2709 
2710  if(!otf.gridBaseLine)
2711  {
2712  return(0);
2713  }
2714 
2715  p = g->chans;
2716  noInt = otf.noint;
2717  }
2718  else
2719  {
2720  p = data;
2721  noInt = noint;
2722  }
2723 
2724  k=0;
2725 
2726  for(l=0;l<8;l+=2)
2727  {
2728  if(otf.baselines[l] == -1 || otf.baselines[l+1] == -1)
2729  {
2730  continue;
2731  }
2732 
2733  if(otf.baselines[l] > noInt || otf.baselines[l+1] > noInt)
2734  {
2735  continue;
2736  }
2737 
2738  for(j=otf.baselines[l];j<otf.baselines[l+1];j++)
2739  {
2740  sig[k] = 0.0;
2741  x[k] = (float)j;
2742  lsqArray[k++] = p[j];
2743  }
2744  }
2745 
2746  for(i=0;i<k;i++)
2747  {
2748  avg += lsqArray[i];
2749  }
2750  avg /= (double)k;
2751 
2752  if(k>=4)
2753  {
2754  lsqfit(x,lsqArray, 0, k, sig, 0, &b1, &a1, &sigb1, &siga1, &chi2_1, &q1);
2755 
2756  computeRms(lsqArray, k, &rms);
2757 
2758  if(mode == 0)
2759  {
2760  g->a = a1;
2761  g->b = b1;
2762  g->rms = rms;
2763  }
2764  else
2765  {
2766  *a = a1;
2767  *b = b1;
2768  *Rms = rms;
2769  }
2770  }
2771  else
2772  {
2773  if(mode == 0)
2774  {
2775  g->a = 0.0;
2776  g->b = 0.0;
2777  g->rms = 100.0;
2778  }
2779  else
2780  {
2781  *a = 0.0;
2782  *b = 0.0;
2783  *Rms = 100.0;
2784  }
2785  }
2786 
2787  g->bdirty = 0; /* Mark as clean */
2788 
2789  return(0);
2790 }
2791 
2792 
2793 int computeRms(y, n, rms)
2794 float *y, *rms;
2795 int n;
2796 {
2797  int i;
2798  double mean, sums;
2799 
2800  if(!n)
2801  {
2802  return(1);
2803  }
2804 
2805  mean = 0.0;
2806 
2807  for(i=0;i<n;i++)
2808  {
2809  mean += y[i];
2810  }
2811 
2812  mean /= (float)n;
2813 
2814  sums = 0.0;
2815 
2816  for(i=0;i<n;i++)
2817  {
2818  sums += ((y[i] - mean) * (y[i] - mean));
2819  }
2820 
2821  sums /= (float)n;
2822 
2823  if(sums > 0.0)
2824  {
2825  *rms = sqrt(sums);
2826  }
2827  else
2828  {
2829  *rms = 100.0;
2830  }
2831 
2832  return(0);
2833 }
2834 
2835 
2836 
2838  KeySym sym;
2839  int win;
2840  char *key;
2841  char *help;
2842 };
2843 
2845  { XK_1, 0, "1", "Set Lower Level Cutoff to 10 percent" },
2846  { XK_2, 0, "2", "Set Lower Level Cutoff to 20 percent" },
2847  { XK_3, 0, "3", "Set Lower Level Cutoff to 30 percent" },
2848  { XK_4, 0, "4", "Set Lower Level Cutoff to 40 percent" },
2849  { XK_5, 0, "5", "Set Lower Level Cutoff to 50 percent" },
2850  { XK_6, 0, "6", "Set Lower Level Cutoff to 60 percent" },
2851  { XK_7, 0, "7", "Set Lower Level Cutoff to 70 percent" },
2852  { XK_8, 0, "8", "Set Lower Level Cutoff to 80 percent" },
2853  { XK_9, 0, "9", "Set Lower Level Cutoff to 90 percent" },
2854  { XK_0, 0, "0", "Set Lower Level Cutoff to Full Range" },
2855  { XK_b, 0, "b", "Place a 'beam-size' marker on screen" },
2856  { XK_B, 0, "B", "Toggle the Removal of Baselines" },
2857  { XK_d, 0, "d", "Toggle up through Colors of Regions" },
2858  { XK_D, 0, "D", "Toggle Down through Colors of Regions" },
2859  { XK_f, 0, "f", "Set Color Scheme to Flame (Repeat to Toggle Through all)" },
2860  { XK_g, 0, "g", "Set Color Scheme to Grayscale" },
2861  { XK_i, 0, "i", "Show Map in Interp Mode" },
2862  { XK_l, 0, "l", "Toggle Region Labels" },
2863  { XK_m, 0, "m", "Show Channel Map Mosaic" },
2864  { XK_o, 0, "o", "Reset Map to Original Values" },
2865  { XK_p, 0, "p", "Set Color Scheme to Pseudo" },
2866  { XK_p, 0, "<control> + p", "Screen Capture OTF Plot" },
2867  { XK_r, 0, "r", "Revert Map to Regular Mode" },
2868  { XK_R, 0, "R", "Show a Map of RMS Values" },
2869  { XK_r, 0, "<control> r", "Toggle Region Outlines" },
2870  { XK_t, 0, "t", "Show a Map of Tsys Values" },
2871  { XK_T, 0, "T", "Show a Map of Integrated Time Values" },
2872  { XK_Up, 0, "Up-Arrow", "Move Lower Threshold Up 1%" },
2873  { XK_Down, 0, "Down-Arrow", "Move Lower Threshold Down 1%" },
2874  { XK_Up, 0, "<Control> Up-Arrow", "Increase Gamma Effect 5%" },
2875  { XK_Down, 0, "<Control> Down-Arrow", "Decrease Gamma Effect 5%" },
2876  { XK_Up, 0, "<shift> Up-Arrow", "Increase Scale 5%" },
2877  { XK_Down, 0, "<shift> Down-Arrow", "Decrease Scale 5%" },
2878 
2879  { XK_Up, 1, "Up-Arrow", "Move Integration Region Up" },
2880  { XK_Down, 1, "Down-Arrow", "Move Integration Region Down" },
2881  { XK_Up, 1, "<Control> Up-Arrow", "Move Upper Integration Channel Up" },
2882  { XK_Down, 1, "<Control> Down-Arrow", "Move Upper Integration Channel Down" },
2883  { XK_Up, 1, "<shift> Up-Arrow", "Move Lower Integration Channel Up" },
2884  { XK_Down, 1, "<shift> Down-Arrow", "Move Lower Integration Channel Down" },
2885  { XK_p, 1, "<control> + p", "Screen Capture Spectrum Plot" }
2886 };
2887 
2888 #define MAX_KEYSYMS (sizeof(keysyms) / sizeof(struct STURCT_KEYSYMS))
2889 
2890 
2892 {
2893  int i;
2894  char tbuf[256];
2895  struct STURCT_KEYSYMS *k;
2896 
2897  sprintf(tbuf, "Press the Following Keys in Either the OTF or Spectral Plot Windows\n");
2898 
2899  printf("\n%s\n", tbuf);
2900  if(sockmode)
2901  {
2902  log_msg(" ");
2903  log_msg(tbuf);
2904  log_msg(" ");
2905  }
2906 
2907  k = &keysyms[0];
2908  for(i=0;i<MAX_KEYSYMS;i++,k++)
2909  {
2910  if(k->win == 0)
2911  {
2912  sprintf(tbuf, "Press %s key for %s", k->key, k->help);
2913  printf("%s\n", tbuf);
2914 
2915  if(sockmode)
2916  {
2917  log_msg(tbuf);
2918  }
2919  }
2920  }
2921 
2922  sprintf(tbuf, "Press the Following Keys Spectral Plot Windows\n");
2923 
2924  printf("\n%s\n", tbuf);
2925  if(sockmode)
2926  {
2927  log_msg(" ");
2928  log_msg(tbuf);
2929  log_msg(" ");
2930  }
2931 
2932  k = &keysyms[0];
2933  for(i=0;i<MAX_KEYSYMS;i++,k++)
2934  {
2935  if(k->win == 1)
2936  {
2937  sprintf(tbuf, "Press %s key for %s", k->key, k->help);
2938  printf("%s\n", tbuf);
2939 
2940  if(sockmode)
2941  {
2942  log_msg(tbuf);
2943  }
2944  }
2945  }
2946 
2947  return(0);
2948 }
2949 
2950 
2951 
2952 /* Keyboard input to OTF graid map window */
2954 XEvent *e;
2955 {
2956  KeySym keysym;
2957  XComposeStatus compose;
2958  char buffer[1], tbuf[256], cbuf[256];
2959  char fname[256], sysBuf[256];
2960  int bufsize=1, change = 0;
2961  static int color = 0;
2962  static int old_cutoff = -1;
2963 
2964  XLookupString((XKeyEvent *)e, buffer, bufsize, &keysym, &compose);
2965 
2966  switch(keysym)
2967  {
2968  case XK_1: otf.cutoff = 10; change = 2; break;
2969  case XK_2: otf.cutoff = 20; change = 2; break;
2970  case XK_3: otf.cutoff = 30; change = 2; break;
2971  case XK_4: otf.cutoff = 40; change = 2; break;
2972  case XK_5: otf.cutoff = 50; change = 2; break;
2973  case XK_6: otf.cutoff = 60; change = 2; break;
2974  case XK_7: otf.cutoff = 70; change = 2; break;
2975  case XK_8: otf.cutoff = 80; change = 2; break;
2976  case XK_9: otf.cutoff = 90; change = 2; break;
2977  case XK_0: otf.cutoff = 0; change = 2; break;
2978  case XK_Up:
2979  if(e->xkey.state & ControlMask)
2980  {
2981  otf.gamma /= 1.05;
2982  change = 4;
2983  }
2984  else
2985  if(e->xkey.state & ShiftMask)
2986  {
2987  otf.scaleFactor *= 1.05;
2988  change = 4;
2989  }
2990  else
2991  {
2992  otf.cutoff++;
2993 
2994  if(otf.cutoff > 99)
2995  {
2996  otf.cutoff = 99;
2997  }
2998 
2999  change = 2;
3000  }
3001  break;
3002 
3003  case XK_Down:
3004  if(e->xkey.state & ControlMask)
3005  {
3006  otf.gamma *= 1.05;
3007  change = 4;
3008  }
3009  else
3010  if(e->xkey.state & ShiftMask)
3011  {
3012  otf.scaleFactor /= 1.05;
3013  change = 4;
3014  }
3015  else
3016  {
3017  otf.cutoff--;
3018 
3019  if(otf.cutoff < 0)
3020  {
3021  otf.cutoff = 0;
3022  }
3023 
3024  change = 2;
3025  }
3026 
3027  break;
3028 
3029  case XK_b:
3030  if(otf.placeBeamSize == 0)
3031  {
3032  otf.placeBeamSize = 1;
3033  }
3034  else
3035  if(otf.placeBeamSize == 1)
3036  {
3037  otf.placeBeamSize = 2;
3038  }
3039  else
3040  if(otf.placeBeamSize == 2)
3041  {
3042  otf.placeBeamSize = 0;
3043  }
3044 
3045  sprintf(tbuf, "otf_show_beam_size = %d /q", otf.placeBeamSize);
3046  to_helper(tbuf);
3047 
3048  change = 1;
3049 
3050  break;
3051 
3052  case XK_B:
3053  if(otf.gridBaseLine)
3054  {
3055  otf.gridBaseLine = 0;
3056  }
3057  else
3058  {
3059  otf.gridBaseLine = 1;
3060  }
3061 
3062  sprintf(tbuf, "otf_baselines = %d /q", otf.gridBaseLine);
3063  to_helper(tbuf);
3064 
3065  change = 1;
3066 
3067  break;
3068 
3069  case XK_g: sprintf(cbuf, "gray /q"); color = 0; change = 3; break;
3070 
3071  case XK_o: change = 5; break;
3072 
3073  case XK_p:
3074  if(e->xkey.state & ControlMask) /* Grab screen */
3075  {
3076  sprintf(fname, "OTF-Plot-%s.png", getLogDate(0));
3077 
3078  sprintf(sysBuf, "import -w 0x%x %s", (unsigned int)server->otfwin->win, fname);
3079 
3080  log_msg("%s", sysBuf);
3081 
3082  system(sysBuf);
3083 
3084  printf("Created file: %s\n", fname);
3085  }
3086  else
3087  {
3088  sprintf(cbuf, "pseudo");
3089  color = 1;
3090  change = 3;
3091  }
3092 
3093  break;
3094 
3095  case XK_f:
3096 
3097  if(color < 2)
3098  {
3099  color = 1;
3100  }
3101 
3102  color++;
3103 
3104  if(color > 7)
3105  {
3106  color = 2;
3107  }
3108 
3109  sprintf(cbuf, "flame%d", color-1);
3110  change = 3;
3111 
3112  break;
3113 
3114  case XK_i:
3115 // markDataDirty();
3116  do_otfInterp();
3117  return(0);
3118 
3119  case XK_l:
3120 // markDataDirty();
3122  return(0);
3123 
3124  case XK_m:
3125 // markDataDirty();
3126  do_otfChannelMap(NULL);
3127  return(0);
3128 
3129  case XK_d:
3130 // markDataDirty();
3131  do_toggleRegionBold(1);
3132  return(0);
3133 
3134  case XK_D:
3135 // markDataDirty();
3136  do_toggleRegionBold(-1);
3137  return(0);
3138 
3139  case XK_r:
3140  if(e->xkey.state & ControlMask)
3141  {
3142  do_toggleRegion();
3143  }
3144  else
3145  {
3146 // markDataDirty();
3147  do_otfRegular();
3148  }
3149 
3150  return(0);
3151 
3152  case XK_R:
3153 // markDataDirty();
3154  do_otfRms(" ");
3155  return(0);
3156 
3157  case XK_t:
3158 // markDataDirty();
3159  do_otfTsys(" ");
3160  return(0);
3161 
3162  case XK_T:
3163 // markDataDirty();
3164  do_otfTime(" ");
3165  return(0);
3166 
3167  case XK_P:
3168 
3169  break;
3170 
3171  case XK_Shift_L:
3172  case XK_Shift_R:
3173  case XK_Control_L:
3174  case XK_Control_R:
3175  case XK_Caps_Lock:
3176  case XK_Shift_Lock:
3177  case XK_Meta_L:
3178  case XK_Meta_R:
3179  case XK_Alt_L:
3180  case XK_Alt_R:
3181  case XK_Super_L:
3182  case XK_Super_R:
3183  case XK_Hyper_L:
3184  case XK_Hyper_R:
3185  case XK_Return:
3186  case XK_BackSpace:
3187  case XK_Tab:
3188  case XK_End:
3189  case XK_Home:
3190  case XK_Delete:
3191  case XK_Escape:
3192 
3193  break;
3194 
3195  default: log_msg("Un-handled key stroke: 0x%x", keysym); break;
3196  }
3197 
3198  switch(change)
3199  {
3200  case 1:
3201  break;
3202 
3203  case 2:
3204 
3205  if(otf.cutoff == old_cutoff) /* Prevent constant repaints */
3206  {
3207  return(0);
3208  }
3209 
3210  sprintf(tbuf, "otf_cutoff = %d /q", otf.cutoff);
3211  to_helper(tbuf);
3212 
3213  old_cutoff = otf.cutoff;
3214 
3215  break;
3216 
3217  case 3:
3218 
3219  sprintf(tbuf, "otf_color = %d /q", color);
3220  to_helper(tbuf);
3221 
3222  dontsend = 1;
3223  do_otfColorChoice(cbuf);
3224  dontsend = 0;
3225 
3226  return(0);
3227 
3228  case 4:
3229  sprintf(tbuf, "otf_gamma = %f /q", otf.gamma);
3230  to_helper(tbuf);
3231 
3232  sprintf(tbuf, "otf_grid_scale = %f /q", otf.scaleFactor);
3233  to_helper(tbuf);
3234 
3235  break;
3236 
3237  case 5: /* Reset everything */
3238  do_otfRegular();
3239 
3240  otf.placeBeamSize = 1;
3241  sprintf(tbuf, "otf_show_beam_size = %d /q", otf.placeBeamSize);
3242  to_helper(tbuf);
3243 
3244  otf.gridBaseLine = 1;
3245  sprintf(tbuf, "otf_baselines = %d /q", otf.gridBaseLine);
3246  to_helper(tbuf);
3247 
3248  otf.cutoff = 0;
3249  sprintf(tbuf, "otf_cutoff = %d /q", otf.cutoff);
3250  to_helper(tbuf);
3251 
3252  old_cutoff = otf.cutoff;
3253 
3254  sprintf(tbuf, "otf_color = 0 /q");
3255  to_helper(tbuf);
3256 
3257  dontsend = 1;
3258  sprintf(cbuf, "pseudo /q");
3259  do_otfColorChoice(cbuf);
3260  dontsend = 0;
3261 
3262  otf.gamma = 1.0;
3263  sprintf(tbuf, "otf_gamma = %f /q", otf.gamma);
3264  to_helper(tbuf);
3265 
3266  otf.scaleFactor = 1.0;
3267  sprintf(tbuf, "otf_grid_scale = %f /q", otf.scaleFactor);
3268  to_helper(tbuf);
3269 
3270  break;
3271 
3272  default:
3273  return(0);
3274  }
3275 
3276  /* If you reach here, repaint plot */
3277 
3278  markDataDirty();
3279  markBaseDirty();
3280 
3281  otf.valueMaxChanged = 1;
3282  otf.intenChanged = 1;
3283  otf.newShade = 1;
3284 
3285  paintOtfGrid();
3287 
3288  return(0);
3289 }
3290 
3291 
3292 
3293 int checkKeyPress(event)
3294 XEvent *event;
3295 {
3296  KeySym keysym;
3297  XComposeStatus compose;
3298  char buffer[1], tbuf[256];
3299  char fname[256], sysBuf[256];
3300  int bufsize=1, change = 0;
3301  static int old_b = -1, old_e = -1;
3302 
3303  if(otf.head == NULL)
3304  {
3305  log_msg("No map to plot");
3306 
3307  return(1);
3308  }
3309 
3310  /* Seperate event handler for grid window */
3311  if(event->xbutton.window == server->otfwin->win)
3312  {
3313  dispatchOtfGridEvents(event);
3314  return(0);
3315  }
3316 
3317  XLookupString((XKeyEvent *)event, buffer, bufsize, &keysym, &compose);
3318 
3319  if(keysym == XK_p && event->xkey.state & ControlMask)
3320  {
3321  if(event->xkey.state & ControlMask) /* Print screen */
3322  {
3323  sprintf(fname, "SpectralPlot-%s.png", getLogDate(0));
3324 
3325  sprintf(sysBuf, "import -w 0x%x %s", (unsigned int)event->xany.window, fname);
3326 
3327  log_msg("%s", sysBuf);
3328 
3329  system(sysBuf);
3330 
3331  printf("Created file: %s\n", fname);
3332  }
3333  }
3334  else
3335  if(keysym == XK_Up && event->xkey.state & ControlMask) /* Raise the upper channel only */
3336  {
3337  otf.int_chans[1]++;
3338 
3339  if(otf.int_chans[1] > otf.noint-1) /* Don't exceed number of chans */
3340  {
3341  otf.int_chans[1] = otf.noint -1;
3342  }
3343 
3344  change = 1;
3345  }
3346  else
3347  if(keysym == XK_Down && event->xkey.state & ControlMask) /* Lower the upper channel only */
3348  {
3349  otf.int_chans[1]--;
3350 
3351  if(otf.int_chans[1] < otf.int_chans[0]) /* Don't go below lower chan */
3352  {
3353  otf.int_chans[1] = otf.int_chans[0];
3354  }
3355 
3356  change = 1;
3357  }
3358  else
3359  if(keysym == XK_Up && event->xkey.state & ShiftMask) /* Raise the lower channel only */
3360  {
3361  otf.int_chans[0]++;
3362 
3363  if(otf.int_chans[0] > otf.int_chans[1]) /* Don't exceed upper chan */
3364  {
3365  otf.int_chans[0] = otf.int_chans[1];
3366  }
3367 
3368  change = 1;
3369  }
3370  else
3371  if(keysym == XK_Down && event->xkey.state & ShiftMask) /* Lower the lower channel only */
3372  {
3373  otf.int_chans[0]--;
3374 
3375  if(otf.int_chans[0] < 0) /* Don't go below 0 */
3376  {
3377  otf.int_chans[0] = 0;
3378  }
3379 
3380  change = 1;
3381  }
3382  else
3383  if(keysym == XK_Up)
3384  {
3385  otf.int_chans[0]++;
3386  otf.int_chans[1]++;
3387 
3388  if(otf.int_chans[1] > otf.noint-1)
3389  {
3390  otf.int_chans[1] = otf.noint -1;
3391  }
3392 
3393  if(otf.int_chans[0] > otf.int_chans[1])
3394  {
3395  otf.int_chans[0] = otf.int_chans[1];
3396  }
3397 
3398  change = 1;
3399  }
3400  else
3401  if(keysym == XK_Down)
3402  {
3403  otf.int_chans[0]--;
3404  otf.int_chans[1]--;
3405 
3406  if(otf.int_chans[0] < 0)
3407  {
3408  otf.int_chans[0] = 0;
3409  }
3410 
3411  if(otf.int_chans[1] < otf.int_chans[0])
3412  {
3413  otf.int_chans[1] = otf.int_chans[0] +1;
3414  }
3415 
3416  change = 1;
3417  }
3418  else
3419  if(keysym == XK_P)
3420  {
3421  log_msg("Shift P pressed");
3422  }
3423 
3424  if(change)
3425  {
3426  sprintf(tbuf, "otf_bint_chan = %d /q", otf.int_chans[0]);
3427  to_helper(tbuf);
3428  sprintf(tbuf, "otf_eint_chan = %d /q", otf.int_chans[1]);
3429  to_helper(tbuf);
3430 
3431  if(otf.int_chans[0] == old_b && otf.int_chans[1] == old_e) /* The same chans? */
3432  {
3433  return(0);
3434  }
3435 
3436  old_b = otf.int_chans[0];
3437  old_e = otf.int_chans[1];
3438 
3439  markDataDirty();
3440 
3441  otf.valueMaxChanged = 1;
3442  otf.intenChanged = 1;
3443  otf.newShade = 1;
3444 
3445  paintOtfGrid();
3447  }
3448 
3449  return(0);
3450 }
3451 
3452 
3454 char *buf;
3455 {
3456  int n, ret, col, row;
3457 
3458  n = sscanf(buf, "%d %d", &col, &row);
3459 
3460  if(n == 2)
3461  {
3462  ret = getRequestedCell(row, col);
3463 
3464  if(ret)
3465  {
3466  return(1);
3467  }
3468  }
3469 
3470  if(sockmode)
3471  {
3472  log_msg("Sending Copy of 'Spectral Plot Window to Linuxpops/Helper'.");
3473 
3474  sock_write(helper, (char *)&ds_image_info, sizeof(ds_image_info));
3475  }
3476 
3477  return(0);
3478 }
3479 
3480 
3481 
3482 int getRequestedCell(row, col)
3483 int row, col;
3484 {
3485  int indx;
3486  struct OTF_GRID *f;
3487 
3488  if((row < 0 || row > otf.rows) && (col < 0 || col > otf.cols))
3489  {
3490  log_msg("Requested row: %d, or cols: %d, out of bounds: %d, %d", row, col, otf.rows, otf.cols);
3491  return(1);
3492  }
3493 
3494  indx = col+row*otf.cols;
3495 
3496  f = fetchMapCell(row, col);;
3497 
3498  if(!f)
3499  {
3500  if(debug)
3501  {
3502  log_msg("No data for Cell: %d, %d", col, row);
3503  }
3504 
3505  return(1);
3506  }
3507 
3508  if(f->plotVal1)
3509  {
3510  if(otf.whichPlot == PLOT_TSYS)
3511  {
3512  sprintf(otf.peakStr, "Cell: %dx%d, Tsys %8.4f", col, row, f->plotVal1);
3513  }
3514  else
3515  if(otf.whichPlot == PLOT_RMS)
3516  {
3517  sprintf(otf.peakStr, "Cell: %dx%d, rms %8.4f", col, row, f->plotVal1);
3518  }
3519  else
3520  if(otf.whichPlot == PLOT_TIME)
3521  {
3522  sprintf(otf.peakStr, "Cell: %dx%d, time %8.4f", col, row, f->plotVal1);
3523  }
3524  else
3525  {
3526  sprintf(otf.peakStr, "Cell: %dx%d, Intensity %8.4f", col, row, f->plotVal1);
3527  }
3528 
3529  otf.requestCol = col;
3530  otf.requestRow = row;
3531  otf.reqSpecIndx = indx;
3532 
3534 
3536 
3537  xgr_drawTextClear(0.01, 0.010, otf.peakStr, YELLOW, font0);
3538 
3539  return(0);
3540  }
3541  else
3542  {
3543 // if(debug)
3544  {
3545  log_msg("getRequestedCell(): No Intensity for cell: %d: %e", indx, f->plotVal1);
3546  }
3547  }
3548 
3549  return(1);
3550 }
3551 
3552 
3553 int otfGridDisplaySpec(event, mask)
3554 XEvent *event;
3555 unsigned int mask;
3556 {
3557  struct WINDOW *w;
3558  int col, row, indx, but;
3559  float x,y;
3560  double ra, dec, raOff, decOff;
3561  char tbuf[256];
3562  struct OTF_GRID *f;
3563 
3564  if(debug)
3565  {
3566  log_msg("otfGridDisplaySpec()");
3567  }
3568 
3569  if(!otf.gridArray)
3570  {
3571  log_msg("DISPLAYSPEC: OTF Array is empty");
3572  return(1);
3573  }
3574 
3575  but = event->xbutton.button;
3576 
3577  switch(event->type)
3578  {
3579  case MotionNotify:
3580  if(but == 2 || but == 3 || but == 4 || but == 5)
3581  {
3582  log_msg("Button Motion on Button: %d", but);
3583  }
3584  case ButtonPressMask:
3585  if(but == 2 || but == 3 || but == 4 || but == 5)
3586  {
3587  log_msg("Button Press on Button: %d", but);
3588  return(1);
3589  }
3590  break;
3591 
3592  case KeyPress:
3593  checkKeyPress(event);
3594  return(1);
3595  break;
3596 
3597  default:
3598  return(1);
3599  break;
3600  }
3601 
3602  if( xgr_findWindow(event->xbutton.display, event->xbutton.window, &w))
3603  {
3604  log_msg("xgr_findWindow() returned Non Zero");
3605  return(1);
3606  }
3607 
3608  x = ((float)w->plotxe - (float)w->plotxb) / (float)otf.cols;
3609  x = ((float)event->xbutton.x - (float)w->plotxb) / x - 0.5;
3610  col = (int)rint(x);
3611 
3612  y = ((float)w->plotye - (float)w->plotyb) / (float)otf.rows;
3613  y = ((float)w->plotye - (float)event->xbutton.y) / y - 0.5;
3614  row = (int)rint(y);
3615 
3616  /* Allow out of bounds clicking for placing beam marker */
3617  if(!otf.armBeamLocation && (col < 0 || col >= otf.cols || row < 0 || row >= otf.rows))
3618  {
3619  if(debug)
3620  {
3621  log_msg("Req Col or Row, out of bounds: %d %d", col, row);
3622  }
3623 
3624  return(1);
3625  }
3626 
3627  indx = col+row*otf.cols;
3628  f = fetchMapCell(row, col);
3629 
3630  if(otf.armBeamLocation) /* User setting BeamSize location */
3631  {
3632  log_msg("Got new beam location of Col: %d, Row: %d", col, row);
3633  otf.armBeamLocation = 0;
3634 
3635  /* Col & row seems to be off a bit; add a few here */
3636 
3637  row += 2;
3638 
3639  ra = otf.xsource / 15.0;
3640  dec = otf.ysource;
3641 
3642  raOff = otf.nyquistRa * ((float)col - (float)(otf.cols / 2.0));
3643  decOff = otf.nyquistDec * ((float)row - (float)(otf.rows / 2.0));
3644 
3645  raOff /= 3600.0;
3646  raOff *= 1.0 - (12.0 / 1000.0); /* Adjust a smidge */
3647 
3648  raOff /= (15.0 * cos(otf.head->ysource * CTR));
3649  ra -= raOff;
3650  dec += decOff / 3600.0;
3651 
3652  otf.beamRa = ra * 15.0;
3653  otf.beamDec = dec;
3654 
3655  /* send new ra & dec back to lp */
3656  sprintf(tbuf, "otf_beam_ra = %f /q", otf.beamRa / 15.0);
3657  to_helper(tbuf);
3658  sprintf(tbuf, "otf_beam_dec = %f /q", otf.beamDec);
3659  to_helper(tbuf);
3660 
3661  if(otf.placeBeamSize == 0)
3662  {
3663  otf.placeBeamSize = 1;
3664  }
3665 
3666  forceDrawGrid();
3667 
3668  return(0);
3669  }
3670 
3671  if(!f)
3672  {
3673  if(debug)
3674  {
3675  log_msg("No data for Cell: %d, %d", col, row);
3676  }
3677 
3678  return(1);
3679  }
3680 
3681  if(f->set == -1)
3682  {
3683  if(debug)
3684  {
3685  log_msg("Cell: %d, %d, ignored", col, row);
3686  }
3687 
3688  return(1);
3689  }
3690 
3691  if(f->plotVal1)
3692  {
3693  if(otf.whichPlot == PLOT_TSYS)
3694  {
3695  sprintf(otf.peakStr, "Cell: %dx%d, Tsys %8.4f", col, row, f->plotVal1);
3696  }
3697  else
3698  if(otf.whichPlot == PLOT_RMS)
3699  {
3700  sprintf(otf.peakStr, "Cell: %dx%d, rms %8.4f", col, row, f->plotVal1);
3701  }
3702  else
3703  if(otf.whichPlot == PLOT_TIME)
3704  {
3705  sprintf(otf.peakStr, "Cell: %dx%d, time %8.4f", col, row, f->plotVal1);
3706  }
3707  else
3708  {
3709  sprintf(otf.peakStr, "Cell: %dx%d, Intensity %8.4f", col, row, f->plotVal1);
3710  }
3711 
3712  otf.requestCol = col;
3713  otf.requestRow = row;
3714  otf.reqSpecIndx = indx;
3715 
3717 
3719 
3720  xgr_drawTextClear(0.01, 0.010, otf.peakStr, YELLOW, font0);
3721 
3722  return(0);
3723  }
3724  else
3725  {
3726  // if(debug)
3727  {
3728  log_msg("otfGridDisplaySpec(): No Intensity for cell: %d: %e", indx, f->plotVal1);
3729  }
3730  }
3731 
3732  return(1);
3733 }
3734 
3735 
3736 
3738 {
3739  struct OTF_GRID **g;
3740  struct OTF_GRID *f;
3741 
3742  if(otf.reqSpecIndx < 0)
3743  {
3744  return(1);
3745  }
3746 
3747  if(!otf.gridArray)
3748  {
3749  log_msg("DISPLAYREQ: OTF Array is empty");
3750  return(1);
3751  }
3752 
3753  g = &otf.gridArray[otf.reqSpecIndx];
3754  f = (struct OTF_GRID *)*g;
3755 
3756  if(f && f->set == 1)
3757  {
3759  }
3760 
3761  return(0);
3762 }
3763 
3764 
3765 
3767 struct OTF_GRID *s;
3768 {
3769  int j, noint, ret;
3770  double ra, dec, raOff, decOff;
3771  char sysBuf[256];
3772  extern int sockWriteNoBitch; /* in ../cactus/lib/socknoxvlib.c */
3773 
3774  if(!otf.gridArray)
3775  {
3776  log_msg("DISPLAYGRIDSPEC: OTF Array is empty");
3777  return(1);
3778  }
3779 
3780  noint = otf.noint;
3781 
3782  ra = otf.xsource / 15.0;
3783  dec = otf.ysource;
3784  raOff = otf.nyquistRa * ((float)otf.requestCol - (float)(otf.cols / 2.0));
3785  decOff = otf.nyquistDec * ((float)otf.requestRow - (float)(otf.rows / 2.0));
3786  raOff /= 3600.0;
3787  raOff /= (15.0 * cos(otf.head->ysource * CTR));
3788  ra -= raOff;
3789  dec += decOff / 3600.0;
3790 
3791  strcpy(ds_image_info.magic, "DS_IMAGE_INFO");
3792 
3793  strncpy(ds_image_info.source, s->source, 16);
3794  ds_image_info.source[15] = '\0';
3795 
3796  strncpy(ds_image_info.coordcd, otf.head->coordcd, 8);
3797  ds_image_info.coordcd[7] = '\0';
3798 
3799  if(s->head)
3800  {
3801  bcopy((char *)s->head, (char *)&ds_image_info.head, sizeof(struct HEADER));
3802  }
3803  else
3804  {
3805  bcopy((char *)&lastHead, (char *)&ds_image_info.head, sizeof(struct HEADER));
3806  }
3807 
3808  ds_image_info.ra = ra;
3809  ds_image_info.dec = dec;
3810  ds_image_info.rms = s->rms;
3811  ds_image_info.a = s->a;
3812  ds_image_info.b = s->b;
3815  ds_image_info.bscan = s->bscan;
3816  ds_image_info.escan = s->escan;
3817  ds_image_info.noint = noint;
3826  ds_image_info.sb = (int)otf.head->sideband;
3830  ds_image_info.wt = s->wt;
3831  ds_image_info.time = s->time;
3832  ds_image_info.scanct = (int)s->scanct;
3833  ds_image_info.tsys = s->tsys;
3834 
3835  ds_image_info.head.inttime = s->time; /* Overwrite Header */
3836 
3837  if(otf.gridBaseLine)
3838  {
3839  for(j=0;j<noint;j++)
3840  {
3841  ds_image_info.ydata[j] = s->chans[j] - ((float)j * s->a + s->b);
3842  }
3843  }
3844  else
3845  {
3846  for(j=0;j<noint;j++)
3847  {
3848  ds_image_info.ydata[j] = s->chans[j];
3849  }
3850  }
3851 
3853  bcopy((char *)otf.baselines, (char *)ds_image_info.baselines, sizeof(ds_image_info.baselines));
3854 
3855  sockWriteNoBitch = 1;
3856 
3857  ret = sock_write(specplot, (char *)&ds_image_info, sizeof(ds_image_info));
3858 
3859  sockWriteNoBitch = 0;
3860 
3861  if(!ret) /* Spec Plot is not running; start it */
3862  {
3863  fprintf(stdout, "Starting specplot viewer\n");
3864  fflush(stdout);
3865 
3866  log_msg("sock_write() returned Error; starting specplot viewer");
3867 
3868  sprintf(sysBuf, "specplot &");
3869 
3870  system(sysBuf);
3871 
3872  usleep(250000);
3873 
3874  /* resend */
3875  ret = sock_write(specplot, (char *)&ds_image_info, sizeof(ds_image_info));
3876 
3877  if(!ret)
3878  {
3879  fprintf(stdout, "sock_write() Still returning Error; Check Instalation\n");
3880  fflush(stdout);
3881 
3882  log_msg("sock_write() Still returning Error; Check Installation");
3883  }
3884  }
3885 
3886  return(1);
3887 }
3888 
3889 
3890 
3892 int *b;
3893 {
3894  if(b)
3895  {
3896  bcopy((char *)otf.baselines, (char *)b, sizeof(ds_image_info.baselines));
3897  }
3898 
3899  return(otf.gridBaseLine);
3900 }
3901 
3902 
3903 
3905 char *buf;
3906 {
3907  int i, b, e, n, ob, oe, record=0, interp=0;
3908  char dir[20], *cp, tmp[256];
3909  char sysBuf[256], fname[256], src[256];
3910  double d;
3911 
3912  strcpy(tmp, buf);
3913 
3914  if(strstr(buf, "record"))
3915  {
3916  record = 1;
3917  }
3918 
3919  if(strstr(buf, "interp"))
3920  {
3921  interp = 1;
3922  }
3923 
3924  cp = strtok(tmp," \n\t");
3925  if(cp)
3926  {
3927  b = atoi(cp);
3928  }
3929  else
3930  {
3931  log_msg("Bad begin chan specifier in do_otfVelRun");
3932  return(1);
3933  }
3934 
3935  cp = strtok((char *)NULL," \n\t");
3936  if(cp)
3937  {
3938  e = atoi(cp);
3939  }
3940  else
3941  {
3942  log_msg("Bad ending chan specifier in do_otfVelRun");
3943  return(1);
3944  }
3945 
3946  cp = strtok((char *)NULL," \n\t");
3947  if(cp)
3948  {
3949  n = atoi(cp);
3950  }
3951  else
3952  {
3953  log_msg("Bad channel spacing chan specifier in do_otfVelRun");
3954  return(1);
3955  }
3956 
3957  cp = strtok((char *)NULL," \n\t");
3958  if(cp)
3959  {
3960  strcpy(dir,cp);
3961  }
3962  else
3963  {
3964  log_msg("Bad direction specifier in do_otfVelRun");
3965  return(1);
3966  }
3967 
3968  cp = strtok((char *)NULL," \n\t");
3969  if(cp)
3970  {
3971  d = atof(cp);
3972  }
3973  else
3974  {
3975  d = 0.0;
3976  }
3977 
3978  if(otf.head == NULL)
3979  {
3980  return(1);
3981  }
3982 
3983  otf.valueMaxChanged = 1;
3984  otf.lockScale = 1;
3985  ob = otf.int_chans[0];
3986  oe = otf.int_chans[1];
3987 
3988  if(!strncmp(dir, "forw", 4))
3989  {
3990  for(i=b;i<=e;i++)
3991  {
3992  if(i+(n-1)>otf.noint)
3993  {
3994  continue;
3995  }
3996 
3997 
3998  otf.int_chans[0] = i;
3999  otf.int_chans[1] = i+(n-1);
4000  otf.intenChanged = 1;
4001  otf.newShade = 1;
4002 
4003  markDataDirty();
4004 
4005  paintOtfGrid();
4007 
4008  if(record)
4009  {
4010  if(interp)
4011  {
4012  do_otfInterp();
4013 
4014  XFlush(server->dpy);
4015 
4016  usleep(100000);
4017  }
4018 
4019  strncpy(src, otf.head->object, 16);
4020  src[16] = '\0';
4021  strcmprs(src);
4022 
4023  sprintf(fname, "%s-%.3f-%03d.png", src, otf.head->restfreq / 1000.0, i);
4024 
4025  sprintf(sysBuf, "import -w 0x%x %s", (unsigned int)server->otfwin->win, fname);
4026 
4027  log_msg("%s", sysBuf);
4028 
4029  system(sysBuf);
4030  }
4031 
4032  if(ds_delay(d))
4033  {
4034  break;
4035  }
4036  }
4037  }
4038 
4039  otf.valueMaxChanged = 1;
4040  otf.intenChanged = 1;
4041  otf.newShade = 1;
4042  otf.lockScale = 0;
4043  otf.int_chans[0] = ob;
4044  otf.int_chans[1] = oe;
4045 
4046  xgr_clearScreen();
4047 
4048  markDataDirty();
4049 
4050  paintOtfGrid();
4051 
4053 
4054  return(0);
4055 }
4056 
4057 
4058 
4060 {
4061  int row, col;
4062  struct OTF_GRID *f;
4063 
4064  if(!otf.gridArray)
4065  {
4066  log_msg("GRIDDUMP: OTF Array is empty");
4067  return(1);
4068  }
4069 
4070  if(otf.head == NULL)
4071  {
4072  return(1);
4073  }
4074 
4075  for(row=0;row<otf.rows;row++)
4076  {
4077  for(col=0;col<otf.cols;col++)
4078  {
4079  f = fetchMapCell(row, col);
4080 
4081  if(f && f->set == 1)
4082  {
4083  printf("%f ", f->plotVal1);
4084  }
4085  else
4086  {
4087  printf("%f ", 0.0);
4088  }
4089  }
4090 
4091  printf("\n");
4092  }
4093 
4094  return(0);
4095 }
4096 
4097 
4098 
4099 
4101 char *buf;
4102 {
4103  int i, b, e, repaint = 1;
4104  char *cp, tb[80];
4105  float d;
4106  char tmp[256];
4107  extern int stopFlag;
4108  int oldBaseline;
4109 
4110  log_msg("do_otfGridLoad(): Enter");
4111 
4112 #ifdef DO_DSTIME
4114 #endif
4115 
4116  strcpy(tmp, buf);
4117 
4118  /* Grab beginning scan number */
4119  cp = strtok(tmp,"\n\t ");
4120 
4121  if(cp)
4122  {
4123  b = atoi(cp);
4124  }
4125  else
4126  {
4127  log_msg("do_otfGridLoad(), no begin scan specified");
4128 
4129 #ifdef DO_DSTIME
4131 #endif
4132 
4133  return(1);
4134  }
4135  /* Grab ending scan number */
4136  cp = strtok((char *)NULL,"\n\t ");
4137 
4138  if(cp)
4139  {
4140  e = atoi(cp);
4141  }
4142  else
4143  {
4144  log_msg("do_otfGridLoad(), no end scan specified");
4145 
4146 #ifdef DO_DSTIME
4148 #endif
4149 
4150  return(1);
4151  }
4152  /* Grab delay; if any */
4153  cp = strtok((char *)NULL,"\n\t ");
4154 
4155  if(cp)
4156  {
4157  d = atof(cp);
4158  }
4159  else
4160  {
4161  d = 0.0;
4162  }
4163 
4164  if(d < 0.0) /* It a sign to not repaint i.e. fast load */
4165  {
4166  repaint = 0;
4167  d = 0.0;
4168  }
4169 
4170  if(otf.loadChoice != LOAD_PREVIEW)
4171  {
4172  otf.noPlot = 1;
4173  }
4174 
4175  otf.newShade = 1;
4176 
4177  oldBaseline = otf.gridBaseLine; /* don't baseline while loading */
4178  otf.gridBaseLine = 0;
4179 
4180  otf.ignoreAllRepaints = 1;
4181 
4182  for(i=b;i<=e;i++)
4183  {
4184  sprintf(tb,"%d",i);
4185 
4186  if(otf.loadChoice == LOAD_STEP)
4187  {
4188  if(!(i % 10) || i == b || i == e)
4189  {
4190  otf.newShade = 1;
4191  otf.noPlot = 0;
4192  }
4193  else
4194  {
4195  otf.noPlot = 1;
4196  }
4197  }
4198 
4199  fbScanDone = 1;
4200  aosScanDone = 3;
4201 
4202  do_scanDone(tb);
4203 
4204  if(ds_delay(d))
4205  {
4206  log_msg("do_otfGridLoad(): Breaking out of load");
4207 
4208  stopFlag = 1;
4209 
4210  if(repaint)
4211  {
4212  forceDrawGrid();
4213  }
4214 
4215  break;
4216  }
4217  else
4218  {
4220  }
4221  }
4222 
4223  otf.ignoreAllRepaints = 0;
4224 
4225  log_msg("do_otfGridLoad(): Done loading scans");
4226 
4227  otf.noPlot = 0;
4228 
4229  otf.gridBaseLine = oldBaseline; /* now compute the baselines */
4230 
4231  if(otf.gridBaseLine)
4232  {
4233  if(repaint)
4234  {
4236  }
4237  }
4238 
4239  if(repaint)
4240  {
4241  forceDrawGrid();
4242  }
4243 
4244  if(sockmode)
4245  {
4246  to_helper("done");
4247  }
4248 
4249 #ifdef DO_DSTIME
4251 #endif
4252 
4253  return(0);
4254 }
4255 
4256 
4258 {
4259  do_etimeClear();
4260 
4261  otf.initialized = 0;
4262  otf.head = 0;
4263  otf.reqSpecIndx = -1;
4264 
4266 
4267  xgr_clearScreen();
4268 
4269  xgr_pixmapToWindow("OTF Gridder");
4270 
4271  xgr_setWindowSize("OTF Gridder", 879, 779);
4272  usleep(10000);
4273  xgr_setWindowSize("OTF Gridder", 860, 780);
4274 
4275  initGrid();
4276 
4277  return(0);
4278 }
4279 
4280 
4281 
4283 {
4284  struct XGR_HEAD *p;
4285  struct XGR_ *s;
4286  struct WINDOW_HEAD *p2;
4287  struct WINDOW *s2;
4288  int w, h;
4289 
4290 // log_msg("otfInterp(): Entered");
4291 
4292  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
4293  {
4294  s = (struct XGR_ *)p;
4295 
4296  for(p2=s->windows.next;p2!=&s->windows;p2=p2->next)
4297  {
4298  s2 = (struct WINDOW *)p2;
4299 
4300  if(!strcmp(s2->frameTitle, "OTF Gridder"))
4301  {
4302  if(otf.ximage)
4303  {
4304  XDestroyImage(otf.ximage);
4305  otf.ximage = NULL;
4306  }
4307 
4308  w = s2->plotxe-s2->plotxb;
4309 
4310  if(w%2)
4311  {
4312  w--;
4313  }
4314 
4315  h = s2->plotye-s2->plotyb;
4316 
4317  otf.ximage = createXimage(s->dpy, w, h, s->depth);
4318 
4319  if(otf.ximage)
4320  {
4321  s2->pixmapX = s2->plotxb;
4322  s2->pixmapY = s2->plotyb;
4323 
4324 // log_msg("otfInterp(): x = %d, y = %d, w = %d, h = %d", s2->pixmapX, s2->pixmapY, w, h);
4325 
4326  interpAndPlot(s);
4327  }
4328  }
4329  }
4330  }
4331 
4332  if(otf.ximage)
4333  {
4334  XDestroyImage(otf.ximage);
4335  }
4336 
4337  otf.ximage = NULL;
4338  otf.lastAction = INTERP;
4339 
4340  return(0);
4341 }
4342 
4343 
4344 
4346 struct XGR_ *s;
4347 {
4348  int i, row, col, k, x, y;
4349  int in, out;
4350  float *inarray=NULL, *outarray=NULL;
4351  unsigned char uc;
4352  float d;
4353  struct OTF_GRID *f;
4354 
4355  if(!otf.gridArray)
4356  {
4357  log_msg("INTERP: OTF Array is empty");
4358  return(1);
4359  }
4360 
4361  if(!otf.ximage)
4362  {
4363  log_msg("No otf.ximage");
4364  return(1);
4365  }
4366 
4367  if(!otf.doingMosaic)
4368  {
4370 
4371  xgr_mapUnmapWindow("OTF Gridder", 1);
4372 
4373  drawColorBar();
4374 
4376  }
4377 
4378  in = otf.cols * otf.rows;
4379  out = otf.ximage->width * otf.ximage->height;
4380 
4381  if( (inarray = (float *)malloc((unsigned)(in * sizeof(float)))) == NULL)
4382  {
4383  log_msg("Unable to malloc(%d) inarray in interpAndPlot()", in * sizeof(float));
4384 
4385  return(1);
4386  }
4387 
4388  if( (outarray = (float *)malloc((unsigned)(out * sizeof(float)))) == NULL)
4389  {
4390  log_msg("Unable to malloc(%d) outarray in interpAndPlot()", in * sizeof(float));
4391 
4392  free((char *)inarray);
4393 
4394  return(1);
4395  }
4396 
4397  bzero((char *)inarray, in * sizeof(float));
4398  bzero((char *)outarray, out * sizeof(float));
4399 
4400  k = 0;
4401  for(row=otf.rows-1;row>=0;row--)
4402  {
4403  for(col=0;col<otf.cols;col++)
4404  {
4405  f = fetchMapCell(row, col);
4406 
4407  if(f && f->set == 1)
4408  {
4409  inarray[k++] = (float)f->shade;
4410  }
4411  else
4412  {
4413  inarray[k++] = 0.0;
4414  }
4415  }
4416  }
4417 
4418  interp(inarray, otf.cols, otf.rows, outarray, otf.ximage->width, otf.ximage->height);
4419 
4420  if(s->depth == 8)
4421  {
4422  for(i=0;i<out;i++)
4423  {
4424  d = (float)outarray[i];
4425 
4426  if(d < 1.0)
4427  {
4428  uc = 1;
4429  }
4430  else
4431  if(d > (float)(max_gray_scale-1))
4432  {
4433  uc = max_gray_scale-1;
4434  }
4435  else
4436  {
4437  uc = (unsigned char)outarray[i];
4438  }
4439 
4440  if(uc > (otf.cutoff * max_gray_scale / 100))
4441  {
4442  otf.ximage->data[i] = (unsigned char)s->grayScale[(int)uc];
4443  }
4444  else
4445  {
4446  otf.ximage->data[i] = (unsigned char)s->colors[BLACK];
4447  }
4448  }
4449  }
4450  else
4451  {
4452  i = 0;
4453 
4454  for(y=0;y<otf.ximage->height;y++)
4455  {
4456  for(x=0;x<otf.ximage->width;x++,i++)
4457  {
4458  d = (float)outarray[i];
4459 
4460  if(d < 1.0)
4461  {
4462  uc = 1;
4463  }
4464  else
4465  if(d > (float)(max_gray_scale-1))
4466  {
4467  uc = max_gray_scale-1;
4468  }
4469  else
4470  {
4471  uc = (unsigned char)outarray[i];
4472  }
4473 
4474  if(uc > (otf.cutoff * max_gray_scale / 100))
4475  {
4476  XPutPixel(otf.ximage, x, y, s->grayScale[(int)uc]);
4477  }
4478  else
4479  {
4480  XPutPixel(otf.ximage, x, y, s->colors[BLACK]);
4481  }
4482  }
4483  }
4484  }
4485 
4486  XPutImage(s->dpy, s->cur->act, s->cur->gc, otf.ximage, 0, 0,
4487  s->cur->pixmapX, s->cur->pixmapY,
4488  (unsigned int)otf.ximage->width,
4489  (unsigned int)otf.ximage->height);
4490 
4491  if(!otf.doingMosaic)
4492  {
4493  putOtfGrid();
4494 
4495  placeBeamSize();
4496 
4497  if(otf.regionshow)
4498  {
4499  drawRegions();
4500  }
4501 
4502  xgr_pixmapToWindow("OTF Gridder");
4503  }
4504 
4505  if(inarray)
4506  {
4507  free((char *)inarray);
4508  }
4509 
4510  if(outarray)
4511  {
4512  free((char *)outarray);
4513  }
4514 
4515  return(0);
4516 }
4517 
4518 
4519  /* Create an X11 image given a desired width, height and depth. */
4520 XImage *createXimage(display, w, h, depth)
4521 Display *display;
4522 int w, h, depth;
4523 {
4524  Visual *visual;
4525  XImage *xi;
4526  unsigned ui;
4527 
4528  visual = DefaultVisual(display, DefaultScreen(display));
4529 
4530  if(depth == 1)
4531  {
4532  return((XImage *)NULL);
4533  }
4534 
4535  xi = XCreateImage(display, visual, (unsigned int)depth, ZPixmap,0,
4536  (char *)NULL, (unsigned int)w, (unsigned int)h, 16, 0);
4537  if(xi == NULL)
4538  {
4539  log_msg("XCreateImage failed");
4540  return((XImage *)NULL);
4541  }
4542 
4543  ui = (unsigned)(xi->height*xi->bytes_per_line*sizeof(char));
4544  if((xi->data=(char *)malloc(ui))==NULL)
4545  {
4546  log_msg("Unable to malloc(%d) ximage in createXimage()", ui);
4547  XDestroyImage(xi);
4548  return((XImage *)NULL);
4549  }
4550 
4551  bzero((char *)xi->data, xi->height * xi->bytes_per_line * sizeof(char));
4552 
4553  return(xi);
4554 }
4555 
4556 
4557 
4559 char *buf;
4560 {
4561  int i, j, bc, ec, indx, halfway, first=1;
4562  char *cp, tmp[256], vbuf[80];
4563  float scale, xb, xe, yb, ye, vbc, vec, refpt, deltax12, vel;
4564  static int cc=256, nx=5, ny=5, nc=1;
4565 
4566  if(buf)
4567  {
4568  strcpy(tmp, buf);
4569  }
4570  else
4571  {
4572  sprintf(tmp, "%d %d %d %d", cc, nx, ny, nc);
4573  }
4574 
4575  cp = strtok(tmp," \n\t");
4576  if(cp)
4577  {
4578  cc = atoi(cp);
4579  }
4580  else
4581  {
4582  log_msg("Bad Center channel in do_otfChannelMap()");
4583  return(1);
4584  }
4585 
4586  cp = strtok(NULL," \n\t");
4587  if(cp)
4588  {
4589  nx = atoi(cp);
4590  }
4591  else
4592  {
4593  log_msg("Bad num of col specifier in do_otfChannelMap()");
4594  return(1);
4595  }
4596 
4597  cp = strtok((char *)NULL," \n\t");
4598  if(cp)
4599  {
4600  ny = atoi(cp);
4601  }
4602  else
4603  {
4604  log_msg("Bad num of row specifier in do_otfChannelMap()");
4605  return(1);
4606  }
4607 
4608  cp = strtok((char *)NULL," \n\t");
4609  if(cp)
4610  {
4611  nc = atoi(cp);
4612  }
4613  else
4614  {
4615  log_msg("Bad num of channels specifier in do_otfChannelMap()");
4616  return(1);
4617  }
4618 
4619  if(otf.head == NULL)
4620  {
4621  return(1);
4622  }
4623 
4624  xgr_setCurWindow(XGR_OTF_WIN, XGR_SET_WIN); /* Us the none pixmap window */
4625 
4626  setInValid(1);
4627 
4628  xgr_clearScreen();
4629 
4630  refpt = otf.head->refpt-0.5;
4631  deltax12 = otf.head->deltax;
4632  vel = otf.head->refpt_vel;
4633  halfway = (nx*ny*nc) / 2;
4634  indx = cc - halfway;
4635  otf.doingMosaic = 1;
4636  xgr_hardFont = -1;
4637 
4638  for(i=(ny-1);i>=0;i--)
4639  {
4640  for(j=0;j<nx;j++)
4641  {
4642  setInValid(1);
4643 
4644  xb = (float)j / (float)nx;
4645  xe = (float)(j+1) / (float)nx;
4646  yb = (float)i / (float)ny;
4647  ye = (float)(i+1) / (float)ny;
4648 
4649  scale = ye-yb;
4650  xgr_drawBox(xb+0.005, 0.05*scale +yb, xe, 0.998*scale +yb, GRAY75);
4651 
4652  bc = indx;
4653  ec = indx+(nc-1);
4654  indx += nc;
4655 
4656  otf.intenChanged = 1;
4657 
4658  markDataDirty(); /* Force a recalculation of intensities */
4659 
4660  computeInten(bc, ec);
4661 
4662  otf.newShade = 1;
4663 
4664  computeShade();
4665 
4666  otf.noColorBar = 1;
4667 
4668  otf.newShade = 1;
4669 
4670  otfInterp();
4671 
4672  if(otf.head->sideband == 3.0)
4673  {
4674  vbc = vel - (((float)bc - refpt) * deltax12) + deltax12 / 2.0;
4675  vec = vel - (((float)ec - refpt) * deltax12) - deltax12 / 2.0;
4676  }
4677  else
4678  {
4679  vbc = vel - (((float)bc - refpt) * -deltax12) - deltax12 / 2.0;
4680  vec = vel - (((float)ec - refpt) * -deltax12) + deltax12 / 2.0;
4681  }
4682 
4683  if( (vec < vel && vbc > vel) || (vbc < vel && vec > vel))
4684  {
4685  sprintf(vbuf, "%.1f, %.1f %.1f km/s", vbc, vec, vel);
4686  xgr_drawPosText(0.01, 0.98, vbuf, GREEN, font1);
4687  }
4688  else
4689  {
4690  sprintf(vbuf, "%.1f, %.1f km/s", vbc, vec);
4691  xgr_drawPosText(0.01, 0.98, vbuf, WHITE, font1);
4692  }
4693 
4694  if(first)
4695  {
4696  xgr_drawPosText(0.01, 0.08, source, GREEN, font1);
4697  first = 0;
4698  }
4699  }
4700  }
4701 
4702  xgr_hardFont = 0;
4703 
4705 
4706  otf.doingMosaic = 0;
4707 
4708  setInValid(0);
4709 
4710  sprintf(oldBuf, "otfchannelmap %d %d %d", nx, ny, nc);
4711 
4712  otf.intenChanged = 1;
4713 
4714  markDataDirty(); /* Force a recalculation of intensities */
4715 
4717 
4718  otf.newShade = 1;
4719 
4720  computeShade();
4721 
4723 
4724  return(0);
4725 }
4726 
4727 
4728 
4730 {
4731  return(otf.chanSelOTF);
4732 }
4733 
4734 
4735 
4736 double v1a[8], v2a[8];
4737 
4739 int max;
4740 {
4741  int i;
4742  double frac;
4743 
4744  if(max < 0 || max > 8)
4745  {
4746  return(1);
4747  }
4748 
4749  bzero((char *)&v1a, sizeof(v1a));
4750  bzero((char *)&v2a, sizeof(v2a));
4751 
4752  frac = 1.0 / (double)max;
4753 
4754  for(i=0;i<(max+1);i++)
4755  {
4756  v1a[i] = 1.0 - (frac * (double)i);
4757  v2a[i] = frac * (double)i;
4758  }
4759 
4760  log_msg("V1A: %d: %f %f %f %f %f %f %f %f", max,
4761  v1a[0], v1a[1], v1a[2], v1a[3], v1a[4], v1a[5], v1a[6], v1a[7]);
4762 
4763  log_msg("V2A: %d: %f %f %f %f %f %f %f %f", max,
4764  v2a[0], v2a[1], v2a[2], v2a[3], v2a[4], v2a[5], v2a[6], v2a[7]);
4765 
4766 
4767  return(0);
4768 }
4769 
4770 
4771 double findInterp(v1, v2, indx, max)
4772 double v1, v2;
4773 int indx, max;
4774 {
4775  if(indx == 0) /* no use going any further */
4776  {
4777  return(v1);
4778  }
4779 
4780  if(indx > max)
4781  {
4782  return(v1);
4783  }
4784 
4785  return(v1 * v1a[indx] + v2 * v2a[indx]);
4786 }
4787 
4788 
4789 
4790 
4792 char *buf;
4793 {
4794  int row, col, k;
4795  struct OTF_GRID p1, *p1p, *p2p;
4796  float chans[MAX_DATA_CHANNELS];
4797  float *p1c, *p2c;
4798 
4799  if(!otf.gridArray)
4800  {
4801  log_msg("do_otfSpectralSum(): OTF Array is empty");
4802 
4803  return(1);
4804  }
4805 
4806  bzero((char *)&p1, sizeof(p1));
4807  bzero((char *)&chans, sizeof(chans));
4808 
4809  p1p = &p1;
4810  p1p->chans = &chans[0];
4811 
4812  for(row=0;row<otf.rows;row++) /* Search all cells for valid data */
4813  {
4814  for(col=0;col<otf.cols;col++)
4815  {
4816  p2p = fetchMapCell(row, col);;
4817 
4818  if(!p2p) /* No data here */
4819  {
4820  continue;
4821  }
4822 
4823  if(p2p->set == -1) /* data ignored */
4824  {
4825  continue;
4826  }
4827 
4828  p1c = p1p->chans;
4829  p2c = p2p->chans;
4830 
4831  for(k=0;k<otf.noint;k++, p1c++, p2c++)
4832  {
4833  *p1c = (*p1c * p1p->wt + *p2c * p2p->wt) / (p1p->wt + p2p->wt);
4834  }
4835 
4836  p1p->wt += p2p->wt;
4837 
4838  p1p->time = p1p->time + p2p->time;
4839  p1p->tsys = sqrt(1.0 / (p1p->wt / p1p->time));
4840  }
4841  }
4842 
4843  p1p->set = 1;
4844 
4845  computeBaseLine(p1p, 0, 0, 0, 0, 0, 0);
4846 
4847  strcpy(ds_image_info.magic, "DS_IMAGE_INFO");
4848 
4849  strncpy(ds_image_info.source, lastHead.object, 16);
4850  ds_image_info.source[15] = '\0';
4851 
4852  strncpy(ds_image_info.coordcd, otf.head->coordcd, 8);
4853  ds_image_info.coordcd[7] = '\0';
4854 
4855  bcopy((char *)&lastHead, (char *)&ds_image_info.head, sizeof(struct HEADER));
4856 
4859  ds_image_info.rms = p1p->rms;
4860  ds_image_info.a = p1p->a;
4861  ds_image_info.b = p1p->b;
4864  ds_image_info.bscan = 0;
4865  ds_image_info.escan = 0;
4875  ds_image_info.sb = (int)otf.head->sideband;
4879  ds_image_info.wt = p1p->wt;
4880  ds_image_info.time = p1p->time;
4881  ds_image_info.scanct = 1;
4882  ds_image_info.tsys = p1p->tsys;
4883 
4884  ds_image_info.head.inttime = p1p->time; /* Overwrite Header */
4885 
4886  if(otf.gridBaseLine)
4887  {
4888  for(k=0;k<otf.noint;k++)
4889  {
4890  ds_image_info.ydata[k] = p1p->chans[k] - ((float)k * p1p->a + p1p->b);
4891  }
4892  }
4893  else
4894  {
4895  for(k=0;k<otf.noint;k++)
4896  {
4897  ds_image_info.ydata[k] = p1p->chans[k];
4898  }
4899  }
4900 
4902 
4903  bcopy((char *)otf.baselines, (char *)ds_image_info.baselines, sizeof(ds_image_info.baselines));
4904 
4905  if(sockmode)
4906  {
4907  log_msg("Sending Copy of 'Spectral Plot Window to Linuxpops/Helper'.");
4908 
4909  sock_write(helper, (char *)&ds_image_info, sizeof(ds_image_info));
4910  }
4911 
4913 
4914  return(0);
4915 }
4916 
4917 
4918 
4919 /* Produce a 3d cube of data to be used in CloudCompare */
4920 /* Args:
4921 
4922  bc: beginning channel/velocity number
4923  ec: Ending channel/velocity number
4924  interp: Number of artificial channels to interp between true channels
4925  vrange: Scale factor to multiple vel-range to get it to smooth better
4926  in 3d cube.
4927  lowerThreashold: only display cells with temp above this % of maxT.
4928  */
4929 
4930 
4932 char *buf;
4933 {
4934  int row, col, l, m, bc, ec, interp, count=0, wroteOne = 0;
4935  char *cp, tmpStr[256], fname[256];
4936  double x, y, z, vrange, lowerThres, zfactor = 1.0;
4937  double tmp, vel, refpt, deltax12;
4938  double accum1, vel1, intInten, velratio, velrange;
4939  double accum2, vel2, urms = 10.0, raSize, decSize;
4940  FILE *fp;
4941  struct OTF_GRID *f;
4942 
4943  if(!otf.gridArray)
4944  {
4945  log_msg("do_otf3d(): OTF Array is empty");
4946 
4947  return(1);
4948  }
4949 
4950  strcpy(tmpStr, buf);
4951 
4952  cp = strtok(tmpStr," \n\t");
4953  if(cp)
4954  {
4955  bc = atoi(cp);
4956  }
4957  else
4958  {
4959  log_msg("do_otf3d(): Bad begin chan specifier in do_otf3d");
4960 
4961  return(1);
4962  }
4963 
4964  cp = strtok((char *)NULL," \n\t");
4965  if(cp)
4966  {
4967  ec = atoi(cp);
4968  }
4969  else
4970  {
4971  log_msg("do_otf3d(): Bad ending chan specifier in do_otf3d");
4972 
4973  return(1);
4974  }
4975 
4976  cp = strtok((char *)NULL," \n\t");
4977  if(cp)
4978  {
4979  interp = atoi(cp);
4980  }
4981  else
4982  {
4983  log_msg("do_otf3d(): Bad interp spacing in do_otf3d");
4984 
4985  return(1);
4986  }
4987 
4988  cp = strtok((char *)NULL," \n\t");
4989  if(cp)
4990  {
4991  vrange = atof(cp);
4992  }
4993  else
4994  {
4995  log_msg("do_otf3d(): Bad vel_range specifier in do_otf3d");
4996 
4997  return(1);
4998  }
4999 
5000  cp = strtok((char *)NULL," \n\t");
5001  if(cp)
5002  {
5003  lowerThres = atof(cp) * otf.valueMax;
5004  }
5005  else
5006  {
5007  log_msg("do_otf3d(): Bad Lower Threshold specifier in do_otf3d");
5008 
5009  return(1);
5010  }
5011 
5012  cp = strtok((char *)NULL," \n\t");
5013  if(cp)
5014  {
5015  urms = atof(cp);
5016  }
5017  else
5018  {
5019  log_msg("do_otf3d(): Bad Upper rms specifier in do_otf3d");
5020 
5021  return(1);
5022  }
5023 
5024  cp = strtok((char *)NULL," \n\t");
5025  if(cp)
5026  {
5027  zfactor = atof(cp);
5028  }
5029  else
5030  {
5031  log_msg("do_otf3d(): Bad Z-Axis Factor specifier in do_otf3d");
5032 
5033  return(1);
5034  }
5035 
5036  if(fabs(zfactor) < 0.1) /* Come on Man! */
5037  {
5038  zfactor = 1.0;
5039  }
5040 
5041  if(lowerThres == 0.0 && otf.numCellsUsed > 500000)
5042  {
5043  log_msg("do_otf3d(): Bad Lower Threshold specifier with too many active celles: %d do_otf3d", otf.numCellsUsed);
5044 
5045  return(1);
5046  }
5047 
5048  if(ec-bc < 0 || ec>otf.noint || bc < 1 || vrange == 0.0 || interp < 1 || interp > 8)
5049  {
5050  log_msg("do_otf3d(): Bad parameters: %d [0 - <ec], %d [>bc - <noint-1], vrange: %.3f, %d [1 - 8]",
5051  bc, ec, vrange, interp);
5052 
5053  return(1);
5054  }
5055 
5056  /* I use reduces because I can cross-mount it on my Mac without regard to permissions */
5057  strcpy(fname, "/home/reduced/otf-3d.pts");
5058 
5059  if( (fp = fopen(fname, "w") ) <= (FILE *)0)
5060  {
5061  log_msg("do_otf3d(): Unable to open %s", fname);
5062 
5063  return(1);
5064  }
5065 
5066  createInterpTable(interp); /* Go create/update interp tables */
5067 
5068  refpt = otf.head->refpt - 0.5;
5069  deltax12 = otf.head->deltax;
5070  vel = otf.head->refpt_vel;
5071 
5072  if(otf.head->sideband == 3.0)
5073  {
5074  vel1 = vel - (((double)bc - refpt) * deltax12) + deltax12 / 2.0;
5075  vel2 = vel - (((double)ec - refpt) * deltax12) - deltax12 / 2.0;
5076  }
5077  else
5078  {
5079  vel1 = vel - (((double)bc - refpt) * -deltax12) - deltax12 / 2.0;
5080  vel2 = vel - (((double)ec - refpt) * -deltax12) + deltax12 / 2.0;
5081  }
5082 
5083  if(vel2 < vel1) /* Swap them */
5084  {
5085  tmp = vel1;
5086  vel1 = vel2;
5087  vel2 = tmp;
5088  }
5089 
5090  velrange = vel2 - vel1;
5091  velratio = velrange * vrange;
5092 
5093  raSize = otf.nyquistRa * (double)otf.cols;
5094  decSize = otf.nyquistDec * (double)otf.rows;
5095 
5096  log_msg("raSeize = %f, decSeize = %f", raSize, decSize);
5097  log_msg("velrange = %f, velration = %f, zfactor = %f", velrange, velratio, zfactor);
5098 
5099  /* "5929.00 3297.00 1436.76 2.98" */
5100  fprintf(fp, " X Y Z Intensity Tsys rms\n");
5101 
5102  for(row=0;row<otf.rows;row++) /* Search all cells for valid data */
5103  {
5104  for(col=0;col<otf.cols;col++)
5105  {
5106  if(ds_delay(0.0)) /* Check if user requested to stop */
5107  {
5108  fclose(fp);
5109 
5110  log_msg(" ");
5111  log_msg("Wrote %d cells to %s", count, fname);
5112  log_msg(" ");
5113 
5114  /* Force a redraw */
5115  otf.valueMaxChanged = 1;
5116  otf.intenChanged = 1;
5117  otf.newShade = 1;
5118  otf.lockScale = 0;
5119 
5120  xgr_clearScreen();
5121 
5122  paintOtfGrid();
5123 
5125 
5126  return(0);
5127  }
5128 
5129  f = fetchMapCell(row, col);
5130 
5131  if(!f) /* No data here */
5132  {
5133  continue;
5134  }
5135 
5136  if(f->set == -1) /* data ignored */
5137  {
5138  continue;
5139  }
5140 
5141  x = otf.nyquistRa * ((double)col - (double)(otf.cols) * 0.5);
5142  y = otf.nyquistDec * ((double)row - (double)(otf.rows) * 0.5);
5143 
5144  for(l=bc;l<ec;l++)
5145  {
5146  if(otf.gridBaseLine)
5147  {
5148  accum1 = f->chans[l] - ((double)l * f->a + f->b);
5149  accum2 = f->chans[l+1] - ((double)(l+1) * f->a + f->b);
5150  }
5151  else
5152  {
5153  accum1 = f->chans[l];
5154  accum2 = f->chans[l+1];
5155  }
5156 
5157  if(accum1 < lowerThres && accum2 < lowerThres) /* No use going any further */
5158  {
5159  continue;
5160  }
5161 
5162  if(otf.head->sideband == 3.0)
5163  {
5164  vel1 = vel - (((double)l - refpt) * deltax12) + deltax12 / 2.0;
5165  vel2 = vel - (((double)(l+1) - refpt) * deltax12) + deltax12 / 2.0;
5166  }
5167  else
5168  {
5169  vel1 = vel - (((double)l - refpt) * -deltax12) - deltax12 / 2.0;
5170  vel2 = vel - (((double)(l+1) - refpt) * -deltax12) - deltax12 / 2.0;
5171  }
5172 
5173  for(m=0;m<interp;m++)
5174  {
5175  z = findInterp(vel1, vel2, m, interp) * velratio;
5176  intInten = findInterp(accum1, accum2, m, interp);
5177 
5178  if(intInten > lowerThres && f->rms < urms)
5179  {
5180  fprintf(fp, "%.4f %.4f %.4f %.4f %.4f %.4f\n", x, y, z * zfactor, intInten, f->tsys, f->rms);
5181  wroteOne++;
5182  count++;
5183  }
5184  }
5185  }
5186 
5187  }
5188 
5189  if(wroteOne)
5190  {
5191  fflush(fp);
5192  log_msg("Wrote out Row: %d", row);
5193 
5194  wroteOne = 0;
5195  }
5196  }
5197 
5198  fclose(fp);
5199 
5200  log_msg(" ");
5201  log_msg("Wrote %d cells to %s", count, fname);
5202  log_msg(" ");
5203 
5204  /* Force a redraw */
5205  otf.valueMaxChanged = 1;
5206  otf.intenChanged = 1;
5207  otf.newShade = 1;
5208  otf.lockScale = 0;
5209 
5210  xgr_clearScreen();
5211 
5212  paintOtfGrid();
5213 
5215 
5216  return(0);
5217 }
5218 
5219 
5221 char *buf;
5222 {
5223  int row, col, count=0, interp = 0;
5224  char *cp, fname[256], session[256];
5225  double x, y, z;
5226  FILE *fp;
5227  struct OTF_GRID *f;
5228 
5229  if(!otf.gridArray)
5230  {
5231  log_msg("do_otf3dplot(): OTF Array is empty");
5232 
5233  return(1);
5234  }
5235 
5236  cp = strtok(buf, "\t\n ");
5237 
5238  if(!cp)
5239  {
5240  log_msg("do_otf3dplot(): Missing 'session' argument");
5241 
5242  return(1);
5243  }
5244 
5245  strcpy(session, cp);
5246 
5247  cp = strtok(NULL, "\t\n ");
5248 
5249  if(cp)
5250  {
5251  interp = atoi(cp);
5252 
5253  log_msg("do_otf3dplot(): Got Interp val: %d", interp);
5254  }
5255 
5256  strupr(session);
5257 
5258  sprintf(fname, "/tmp/%s/otf-3d-plot.dem", session);
5259 
5260  if( (fp = fopen(fname, "w") ) <= (FILE *)0)
5261  {
5262  log_msg("do_otf3dplot(): Unable to open '%s'", fname);
5263  return(1);
5264  }
5265 
5266  fprintf(fp, "reset\n");
5267  fprintf(fp, "set title \"OTF Map\"\n");
5268 
5269  fprintf(fp, "set xlabel \"R.A. Offset\"\n");
5270  fprintf(fp, "set ylabel \"Dec. Offset\"\n");
5271  fprintf(fp, "set zlabel \"Intensity\"\n");
5272 
5273  fprintf(fp, "#\n");
5274  fprintf(fp, "set border 4095\n");
5275  fprintf(fp, "set hidden3d\n");
5276  fprintf(fp, "#\n");
5277 
5278  // fprintf(fp, "set zrange [%f:%f]\n", otf.valueMin, otf.valueMax);
5279  fprintf(fp, "set zrange [%f:%f]\n", 0.0, 10.0);
5280  fprintf(fp, "set cbrange [%f:%f]\n", otf.valueMin, otf.valueMax);
5281  fprintf(fp, "#\n");
5282 
5283  fprintf(fp, "set samples %d*%d\n", otf.cols, otf.rows);
5284  fprintf(fp, "set isosamples 60\n");
5285 
5286  fprintf(fp, "set ticslevel 0.1\n");
5287 
5288  if(interp)
5289  {
5290 // fprintf(fp, "set pm3d at bs interpolate %d,%d\n", interp, interp);
5291  fprintf(fp, "set pm3d interpolate %d,%d\n", interp, interp);
5292  }
5293  else
5294  {
5295 // fprintf(fp, "set pm3d at bs\n");
5296  fprintf(fp, "set pm3d\n");
5297  }
5298 
5299  fprintf(fp, "set palette color\n");
5300  fprintf(fp, "set palette model RGB\n");
5301  fprintf(fp, "set palette defined ( 0 \"blue\", 1 \"green\", 2 \"yellow\", 3 \"red\" )\n");
5302  fprintf(fp, "set palette gamma 1.0\n");
5303  fprintf(fp, "#\n");
5304 
5305  fprintf(fp, "set view 60.0, 30.0, 1.0, 1.0\n");
5306 
5307  fprintf(fp, "set terminal x11 background rgb \"black\" enhanced 1 size 1200, 850 position 800, 500\n");
5308 
5309  fprintf(fp, "set contour both\n");
5310 
5311  fprintf(fp, "set cntrparam levels incr %.2f,%.2f,%.2f\n", otf.valueMin, fabs(otf.valueMax-otf.valueMin) / 11.0, otf.valueMax);
5312 
5313 
5314  fprintf(fp, "splot \"/tmp/%s/otf-3d-plot.dat\" every 1::0::1024 with lines\n", session);
5315 
5316  fclose(fp);
5317 
5318  /* Write the data */
5319  sprintf(fname, "/tmp/%s/otf-3d-plot.dat", session);
5320 
5321  if( (fp = fopen(fname, "w") ) <= (FILE *)0)
5322  {
5323  log_msg("do_otf3dplot(): Unable to open '%s'", fname);
5324  return(1);
5325  }
5326 
5327  for(row=0;row<otf.rows;row++) /* Search all cells for valid data */
5328  {
5329  for(col=0;col<otf.cols;col++)
5330  {
5331  f = fetchMapCell(row, col);
5332 
5333  if(f && f->set > 0)
5334  {
5335  x = otf.nyquistRa * ((float)col - (float)(otf.cols) * 0.5);
5336  y = otf.nyquistDec * ((float)row - (float)(otf.rows) * 0.5);
5337 
5338  /* If No data here; gnuplot doesn like missing data so write zeros instead */
5339  if(f && f->set == 1)
5340  {
5341  z = f->plotVal1;
5342  }
5343  else
5344  {
5345  z = 0.0;
5346  }
5347 
5348  fprintf(fp, "%.2f %.2f %.2f\n", x, y, z);
5349 
5350  count++;
5351  }
5352  }
5353 
5354  fprintf(fp, " \n");
5355  }
5356 
5357 
5358  fclose(fp);
5359 
5360  log_msg("do_otf3dplot(); Wrote %d cells to %s", count, fname);
5361 
5362  sprintf(fname, "xgraphic load \"/tmp/%s/otf-3d-plot.dem\"", session);
5363 
5364  to_xgraphic(fname);
5365 
5366  return(0);
5367 }
5368 
5369 
5370 /*
5371  shade = 254,
5372  oldshade = 254,
5373  set = 1,
5374  col = 517,
5375  row = 373,
5376  scanct = 3,
5377  intInten = 13.5080051,
5378  kms = 13.5080051,
5379  rms = 13.5080051,
5380  chans = 0x18aac90,
5381  a = -0.0395153947,
5382  b = -6.85798168,
5383  bscan = 50.0400009,
5384  escan = 267.040009,
5385  time = 1.29999995,
5386  tsys = 212.764191,
5387  wt = 2.87174771e-05,
5388  source = "CO21_CygX_097 ", '\000' <repeats 16 times>,
5389  head = 0x18a5038,
5390  next = 0x18ab4a0
5391 */
5392 
5393 /* Zero out any cell whos rms is greater than passwd arg */
5394 int do_otfRmRMS(buf)
5395 char *buf;
5396 {
5397  int row, col, k, count=0;
5398  char *cp, fname[256];
5399  double rmsLimit;
5400  FILE *fp;
5401  struct OTF_GRID *f;
5402 
5403  if(!otf.gridArray)
5404  {
5405  log_msg("do_otf3dplot(): OTF Array is empty");
5406 
5407  return(1);
5408  }
5409 
5410  cp = strtok(buf, "\t\n ");
5411 
5412  if(!cp)
5413  {
5414  log_msg("do_otfRmRMS(): Missing 'rms limit' argument");
5415 
5416  return(1);
5417  }
5418 
5419  rmsLimit = atof(cp);
5420 
5421  if(rmsLimit < 0.1)
5422  {
5423  log_msg("do_otfRmRMS(): 'rmslimit' argument %f, unresonable");
5424 
5425  return(1);
5426  }
5427 
5428  /* open file to write bad info */
5429  sprintf(fname, "bad_rms_cells.txt");
5430 
5431  if( (fp = fopen(fname, "w") ) <= (FILE *)0)
5432  {
5433  log_msg("do_otfRmRMS(): Unable to open '%s'", fname);
5434  return(1);
5435  }
5436 
5437  for(row=0;row<otf.rows;row++) /* Search all cells for valid data */
5438  {
5439  for(col=0;col<otf.cols;col++)
5440  {
5441  f = fetchMapCell(row, col);
5442 
5443  if(!f) /* If No data here */
5444  {
5445  continue;
5446  }
5447 
5448  if(f->rms > rmsLimit)
5449  {
5450  fprintf(fp, "row: %4d, col: %4d, rms: %8.4f, bscan: %8.2f, escan %8.2f ", row, col, f->rms, f->bscan, f->escan);
5451 
5452  for(k=0;k<8;k++)
5453  {
5454  if(f->version[k])
5455  {
5456  fprintf(fp, "%3d ", f->version[k]);
5457 
5458  }
5459  }
5460 
5461  fprintf(fp, "\n");
5462 
5463  f->set = -1; /* Mark as no longer used; but allocated */
5464  f->shade = 0;
5465  f->oldshade = 0;
5466  f->col = 0;
5467  f->row = 0;
5468  f->scanct = 0;
5469  f->intInten = 0.0;
5470  f->kms = 0.0;
5471  f->rms = 0.0;
5472  f->a = 0.0;
5473  f->b = 0.0;
5474  f->bscan = 0.0;
5475  f->escan = 0.0;
5476  f->time = 0.0;
5477  f->tsys = 0.0;
5478  f->wt = 0.0;
5479  f->source[0] = '\0';
5480 
5481  count++;
5482  }
5483  }
5484  }
5485 
5486  fclose(fp);
5487 
5488  log_msg("do_otfRmRMS(); Wrote %d cells to %s", count, fname);
5489 
5490  forceDrawGrid();
5491 
5492  return(0);
5493 }
5494 
5495 
5496 /* Zero out passed cell @ col and row*/
5497 int do_zapCell(buf)
5498 char *buf;
5499 {
5500  int row, col;
5501  char *cp;
5502  struct OTF_GRID *f;
5503 
5504  if(!otf.gridArray)
5505  {
5506  log_msg("do_otf3dplot(): OTF Array is empty");
5507 
5508  return(1);
5509  }
5510 
5511  cp = strtok(buf, "\t\n ");
5512 
5513  if(!cp)
5514  {
5515  log_msg("do_zapCell(): Missing 'Col' argument");
5516 
5517  return(1);
5518  }
5519  col = atoi(cp);
5520 
5521  cp = strtok(NULL, "\t\n ");
5522 
5523  if(!cp)
5524  {
5525  log_msg("do_zapCell(): Missing 'Row' argument");
5526 
5527  return(1);
5528  }
5529  row = atoi(cp);
5530 
5531  if(col < 0 || col > otf.cols-1 || row < 0 || row > otf.rows-1)
5532  {
5533  log_msg("do_zapCell(): Col or Row out of limits: [0 - %d] [0 - %d]", otf.cols, otf.rows);
5534 
5535  return(1);
5536  }
5537 
5538  f = fetchMapCell(row, col);
5539 
5540  if(!f) /* If No data here */
5541  {
5542  log_msg("No data in cell: %d x %d", col, row);
5543  return(1);
5544  }
5545 
5546  f->set = -1; /* Mark as no longer used; but allocated */
5547  f->shade = 0;
5548  f->oldshade = 0;
5549  f->col = 0;
5550  f->row = 0;
5551  f->scanct = 0;
5552  f->intInten = 0.0;
5553  f->kms = 0.0;
5554  f->rms = 0.0;
5555  f->a = 0.0;
5556  f->b = 0.0;
5557  f->bscan = 0.0;
5558  f->escan = 0.0;
5559  f->time = 0.0;
5560  f->tsys = 0.0;
5561  f->wt = 0.0;
5562  f->source[0] = '\0';
5563 
5564  log_msg("do_zapCell(); Cleared Cell: Col: %d x Row: %d", col, row);
5565 
5566  forceDrawGrid();
5567 
5568  return(0);
5569 }
5570 
5571 
5572 
5573 #define FIRST_FFB 1
5574 #define SECOND_FFB 2
5575 #define THIRD_FFB 3
5576 #define FOURTH_FFB 4
5577 #define FIFTH_FFB 5
5578 #define SIXTH_FFB 6
5579 #define SEVENTH_FFB 7
5580 #define EIGHTH_FFB 8
5581 
5582 
5583 
5585 int row, col;
5586 {
5587  if((row < otf.rows) && (col < otf.cols))
5588  {
5589  return((struct OTF_GRID *)otf.gridArray[(row*otf.cols) + col]);
5590  }
5591 
5592  return((struct OTF_GRID *)NULL);
5593 }
5594 
5595 
5596 
5598 int row, col;
5599 struct OTF_GRID *f;
5600 {
5601  if(row <otf.rows && col < otf.cols)
5602  {
5603  otf.gridArray[(row*otf.cols) + col] = f;
5604 
5605  return(0);
5606  }
5607 
5608  return(1);
5609 }
5610 
5611 
5612 #define MAX_GAP 5
5613 
5615 int row, col;
5616 struct OTF_GRID **p2;
5617 {
5618  int r;
5619  struct OTF_GRID *f;
5620 
5621  for(r=1;r<MAX_GAP;r++)
5622  {
5623  f = fetchMapCell(row+r, col);
5624 
5625  if(f && f->set == 1)
5626  {
5627  *p2 = f;
5628 
5629  return(r);
5630  }
5631  }
5632 
5633  return(0);
5634 }
5635 
5636 
5637 
5638 /* Gaps are usually caused by ignored rows; interpolate top to bottom */
5639 /* An attempt to fill in the large gaps in a map; limited to MAX_GAP (5) holes */
5641 char *buf;
5642 {
5643  int i, row, col, n, count = 0;
5644  double p1_avg, p2_avg;
5645  struct OTF_GRID *f;
5646  struct OTF_GRID *p1, *p2;
5647 
5648  for(col=2;col<otf.cols-2;col++) /* Stay away from edges */
5649  {
5650  p1 = (struct OTF_GRID *)NULL;
5651 
5652  for(row=2;row<otf.rows-2;row++) /* ditto top & bottom */
5653  {
5654  f = fetchMapCell(row, col);
5655 
5656  if(f && f->set == 1) /* There is already valid data here */
5657  {
5658  p1 = f; /* Remember it as last valid cell */
5659 
5660  continue;
5661  }
5662 
5663  if(!p1) /* We have to have hit at least one valid cell in each col first */
5664  {
5665  continue;
5666  }
5667 
5668  /* this cell empty; find the next valid one; if any */
5669 
5670  n = findNextCell(row, col, &p2);
5671 
5672  if(n > 0)
5673  {
5674  log_msg("Col: %4d, Row: %4d missing, found next valid cell: %d %d, Gap: %d", col, row, p2->col, p2->row, n);
5675 
5676  /* Fill in missing cells using a weigthed interpolation between p1 & p2 */
5677 
5678  createInterpTable(n+1);
5679 
5680  /* fix this one first */
5681  p1_avg = 0.5 + v1a[1];
5682  p2_avg = 0.5 + v2a[1];
5683  log_msg("Averages: %f %f", p1_avg, p2_avg);
5684  weightedAvergeCells(f, p1, p1_avg, p2, p2_avg, 0, row, col, &count); /* give each their weight */
5685 
5686  /* fix all others */
5687  for(i=1;i<n;i++)
5688  {
5689  f = fetchMapCell(row+i, col); /* fetch next empty cell */
5690 
5691  p1_avg = 0.5 + v1a[1+i];
5692  p2_avg = 0.5 + v2a[1+i];
5693  log_msg("Averages: %f %f", p1_avg, p2_avg);
5694 
5695  weightedAvergeCells(f, p1, p1_avg, p2, p2_avg, 0, row, col, &count); /* give each their weight */
5696  }
5697 
5698  p1 = (struct OTF_GRID *)NULL;
5699  p2 = (struct OTF_GRID *)NULL;
5700 
5701  row += n; /* go ahead and jump to next row */
5702  }
5703  else /* We have traveled more that MAX_GAP and haven't found anything; forget p1 */
5704  {
5705  p1 = (struct OTF_GRID *)NULL;
5706  }
5707 
5708  /* search for next valid cell vertically */
5709  }
5710  }
5711 
5712  forceDrawGrid();
5713 
5714  log_msg("do_fullInterpFill(): Repaired %d cells", count);
5715 
5716  if(count)
5717  {
5718  do_fullInterpFill(buf); /* Do it again until count == 0 */
5719  }
5720 
5721  return(0);
5722 }
5723 
5724 
5725 
5726 /* Given 2 valid cells, average them together using
5727  their integrated weights and the passed weights;
5728  place results in the OTF_CELL pointed to by 'f'
5729 
5730  Malloc channels and the OTF_CELL itself if need be
5731  */
5732 int weightedAvergeCells(f, p1, p1_avg, p2, p2_avg, try, row, col, count)
5733 struct OTF_GRID *f, *p1, *p2;
5734 double p1_avg, p2_avg;
5735 int try, row, col, *count;
5736 {
5737  int chan;
5738  float *gc, *p1c, *p2c;
5739 
5740  if( p1->set == 1 && p2->set == 1) /* Both are good cells */
5741  {
5742  if(p1->wt && p2->wt) /* Both have data to average */
5743  {
5744  if(!f) /* did we already fix this on previous 'try' loop? */
5745  {
5746  /* malloc space for grid array */
5747  if((f = (struct OTF_GRID *)malloc(sizeof(struct OTF_GRID))) == NULL)
5748  {
5749  log_msg("Err FixBadCells(malloc(%d))", sizeof(struct OTF_GRID));
5750  return(1);
5751  }
5752 
5753  bzero((char *)f, sizeof(struct OTF_GRID));
5754 
5755  setMapCell(row, col, f);
5756 
5757  gridLast = gridLast->next = f; /* Add to master linked list */
5758  /* malloc space for channels */
5759  if((f->chans = (float *)malloc(otf.noint * sizeof(float))) == NULL)
5760  {
5761  log_msg("Err in FixBadCells(malloc(%d))", otf.noint * sizeof(float));
5762  return(1);
5763  }
5764  }
5765 
5766  bzero((char *)f->chans, otf.noint * sizeof( float) );
5767 
5768  *count = *count +1;
5769 
5770  gc = f->chans; /* Average in the first cell */
5771  p1c = p1->chans;
5772 
5773  for(chan=0;chan<otf.noint;chan++, p1c++, gc++)
5774  {
5775  *gc = (*gc * f->wt + (*p1c * p1->wt * p1_avg)) / (f->wt + (p1->wt * p1_avg));
5776  }
5777 
5778  f->wt += (p1->wt * p1_avg);
5779 
5780  gc = f->chans; /* Average in the second cell */
5781  p2c = p2->chans;
5782 
5783  for(chan=0;chan<otf.noint;chan++, p2c++, gc++)
5784  {
5785  *gc = (*gc * f->wt + (*p2c * p2->wt * p2_avg)) / (f->wt + (p2->wt * p2_avg));
5786  }
5787 
5788  f->wt += (p2->wt * p2_avg);
5789 
5790  f->intInten = 0.0;
5791  f->set = 1;
5792  f->scanct = p1->scanct + p2->scanct;
5793  f->time = (p1->time * p1_avg) + (p2->time * p2_avg);
5794 
5795  f->tsys = sqrt(1.0 / (f->wt / f->time));
5796 
5797  if(debug)
5798  {
5799  log_msg("%d: Setting Col: %3d, Row: %3d Tsys to: %7.1f, from %.1f %.1f", try, col, row, f->tsys, p1->tsys, p2->tsys);
5800  }
5801 
5802  f->bscan = p2->bscan;
5803  f->escan = p2->escan;
5804 
5805  f->artificial = 1;
5806  f->row = row;
5807  f->col = col;
5808 
5809  f->bdirty = 1; /* Mark baselines dirty */
5810  f->ddirty = 1; /* Mark data dirty */
5811 
5812  otf.bdirty = 1;
5813  otf.ddirty = 1;
5814 
5815  strcpy(f->source, p1->source);
5816 
5817  computeBaseLine(f, 0, 0, 0, 0, 0, 0);
5818  }
5819  else
5820  {
5821  log_msg("do_otfFixBadCells(): p1->wt or p2->wt == 0; %f %f; skipping", p1->wt, p2->wt);
5822  }
5823  }
5824  else
5825  {
5826  log_msg("do_otfFixBadCells(): p1->set or p2->set == 0; %d %d; skipping", p1->set, p2->set);
5827  }
5828 
5829  return(0);
5830 }
5831 
5832 
5833 /* Create an artificial cell based on the two ajacent cells,
5834  either to the (left and right) or (above and below)
5835  */
5837 char *buf;
5838 {
5839  int row, col, try, count = 0;
5840  struct OTF_GRID *p1, *p2;
5841  struct OTF_GRID *f;
5842 
5843  if(!otf.gridArray)
5844  {
5845  log_msg("FIXBADCELLS: OTF Array is empty");
5846  return(1);
5847  }
5848 
5849  if(strstr(buf, "interp"))
5850  {
5851  do_fullInterpFill(buf);
5852 
5853  return(0);
5854  }
5855 
5856  for(row=1;row<otf.rows-1;row++)
5857  {
5858  for(col=1;col<otf.cols-1;col++)
5859  {
5860  f = fetchMapCell(row, col);
5861 
5862  if(f && f->set == 1) /* There is already valid data here */
5863  {
5864  continue;
5865  }
5866 
5867  /* OK, this cell is empty; is there data to the left & right; or above or below ?? */
5868 
5869  for(try=0;try<2;try++) /* Try side by side; then above and below */
5870  {
5871  if(try == 0)
5872  {
5873  p1 = fetchMapCell(row, col-1);
5874  p2 = fetchMapCell(row, col+1);
5875  }
5876  else
5877  {
5878  p1 = fetchMapCell(row-1, col);
5879  p2 = fetchMapCell(row+1, col);
5880  }
5881 
5882  /* Is there two valid cells worth of data ??? */
5883  if(p1 && p2)
5884  {
5885  weightedAvergeCells(f, p1, 1.0, p2, 1.0, try, row, col, &count); /* give each equal weight */
5886  }
5887  }
5888  }
5889  }
5890 
5891  forceDrawGrid();
5892 
5893  log_msg("OTFFIXBADCELLS: Repaired %d cells", count);
5894 
5895  if(count)
5896  {
5897  do_otfFixBadCells(buf); /* Do it again until count == 0 */
5898  }
5899 
5900  return(0);
5901 }
5902 
5903 
5905 char *buf;
5906 {
5907  int row, col;
5908  struct OTF_GRID *f;
5909 
5910  if(!otf.gridArray)
5911  {
5912  log_msg("do_otfListCells(): OTF Array is empty");
5913 
5914  return(1);
5915  }
5916 
5917  for(row=1;row<otf.rows-1;row++)
5918  {
5919  for(col=1;col<otf.cols-1;col++)
5920  {
5921  f = fetchMapCell(row, col);
5922 
5923  if(f) /* There's data here */
5924  {
5925  log_msg("Col: %4d, Row: %4d, ScanCt: %.1f, Tsys: %.1f, Wt: %.2e", col, row, f->scanct, f->tsys, f->wt);
5926  }
5927  }
5928  }
5929 
5930  return(0);
5931 }
5932 
5933 
5934 
5936 {
5938  {
5939  log_msg("forceDrawGrid(): ignoreAllRepaints set");
5940 
5941  return(0);
5942  }
5943 
5944  log_msg("forceDrawGrid(): Enter");
5945 
5946  otf.intenChanged = 1;
5947 
5949 
5950  otf.valueMaxChanged = 1;
5951 
5952  computeMinMax();
5953 
5954  otf.newShade = 1;
5955 
5956  computeShade();
5957 
5958  paintOtfGrid();
5959 
5960  return(0);
5961 }
5962 
5963 
5964 int do_otfSlice(buf)
5965 char *buf;
5966 {
5967  int j, row, col, first = 1, ret, scanct=0, dir;
5968  double raOff, decOff, bscan= 999999.9, escan = -999999.9;
5969  char *cp, fname[256], source[256];
5970  struct OTF_GRID *f;
5971  FILE *fp = NULL;
5972 
5973  if(!otf.gridArray)
5974  {
5975  log_msg("do_otfListCells(): OTF Array is empty");
5976 
5977  return(1);
5978  }
5979 
5980  j = 0;
5981  if((cp = strstr(buf, "row")))
5982  {
5983  dir = 1;
5984 
5985  row = atoi(cp+4);
5986 
5987  for(col=1;col<otf.cols-1;col++)
5988  {
5989  f = fetchMapCell(row, col);
5990 
5991  if(f && f->set > 0) /* There's data here */
5992  {
5993  raOff = otf.nyquistRa * ((double)col - (double)(otf.cols / 2.0));
5994  raOff /= 3600.0;
5995  raOff /= (15.0 * cos(otf.head->ysource * CTR));
5996  raOff *= 3600.0; /* Convert to seconds of time */
5997  raOff *= 15.0; /* Convert to arc Seconds */
5998 
5999  if(first)
6000  {
6001  ret = getRequestedCell(row, col); /* Do this, because it will populate the image_info struct */
6002 
6003  if(!ret)
6004  {
6005  log_msg("Got the row header");
6006  }
6007  else
6008  {
6009  log_msg("Could NOT get the row header");
6010  }
6011 
6012  strcpy(source, f->source);
6013  strcmprs(source);
6014  sprintf(fname, "%s-Row-%d.otfdata", source, row);
6015 
6016  if((fp = fopen(fname, "w")) <= (FILE *)NULL)
6017  {
6018  log_msg("Unable to open: %s", fname);
6019  return(1);
6020  }
6021 
6022  first = 0;
6023  }
6024 
6025  fprintf(fp, "%e %e\n", raOff, f->intInten);
6026 
6027  ds_image_info.ydata[j] = f->intInten;
6028 
6029  /* Check for bscan, escan and scanct extents */
6030  if(f->bscan > 0 && f->bscan < bscan)
6031  {
6032  bscan = f->bscan;
6033  }
6034  if(f->escan > 0 && f->escan > escan)
6035  {
6036  escan = f->escan;
6037  }
6038  if(f->scanct > scanct)
6039  {
6040  scanct = f->scanct;
6041  }
6042 
6043  j++;
6044  }
6045  }
6046  }
6047  else
6048  if((cp = strstr(buf, "col")))
6049  {
6050  dir = 2;
6051 
6052  col = atoi(cp+4);
6053 
6054  for(row=1;row<otf.rows-1;row++)
6055  {
6056  f = fetchMapCell(row, col);
6057 
6058  if(f && f->set > 0) /* There's data here */
6059  {
6060  decOff = otf.nyquistDec * ((double)row - (double)(otf.rows / 2.0));
6061 
6062  if(first)
6063  {
6064  ret = getRequestedCell(row, col); /* Do this, because it will populate the image_info struct */
6065 
6066  if(!ret)
6067  {
6068  log_msg("Got the row header");
6069  }
6070  else
6071  {
6072  log_msg("Could NOT get the row header");
6073  }
6074 
6075  strcpy(source, f->source);
6076  strcmprs(source);
6077  sprintf(fname, "%s-Col-%d.otfdata", source, col);
6078 
6079  if((fp = fopen(fname, "w")) <= (FILE *)NULL)
6080  {
6081  log_msg("Unable to open: %s", fname);
6082  return(1);
6083  }
6084 
6085  first = 0;
6086  }
6087 
6088  fprintf(fp, "%e %e\n", decOff, f->intInten);
6089 
6090  ds_image_info.ydata[j] = f->intInten;
6091 
6092  /* Check for bscan, escan and scanct extents */
6093  if(f->bscan > 0 && f->bscan < bscan)
6094  {
6095  bscan = f->bscan;
6096  }
6097  if(f->escan > 0 && f->escan > escan)
6098  {
6099  escan = f->escan;
6100  }
6101  if(f->scanct > scanct)
6102  {
6103  scanct = f->scanct;
6104  }
6105 
6106  j++;
6107  }
6108  }
6109  }
6110  else
6111  {
6112  log_msg("Wrong Args to otfslice");
6113  return(1);
6114  }
6115 
6116  if(fp)
6117  {
6118 
6119  ds_image_info.head.noint = (double)j;
6120  ds_image_info.head.refpt = (double)j / 2.0;
6121 
6122  if(dir == 1)
6123  {
6124  ds_image_info.head.deltax = otf.nyquistRa / cos(otf.manMapDec * M_PI / 180.0); /* Increase by cos(dec) */
6125  }
6126  else
6127  {
6129  }
6130 
6131  ds_image_info.head.velocity = 0.0;
6136  ds_image_info.noint = j;
6137  ds_image_info.refpt = (double)j / 2.0;
6138 
6139  log_msg("Sending Copy of 'Spectral Plot Window to Linuxpops/Helper'.");
6140 
6141  sock_write(helper, (char *)&ds_image_info, sizeof(ds_image_info));
6142 
6143  log_msg("Created File: %s", fname);
6144 
6145  fclose(fp);
6146  }
6147 
6148  return(0);
6149 }
6150 
6151 
6153 {
6154  int tScans = 0;
6155  char raStr[256], decStr[256];
6156  struct MAP_SCANS *m;
6157  extern int log_dup2stdout;
6158 
6159  if(otf.map_scans_head != NULL)
6160  {
6161  for(m=otf.map_scans_head;m->next; m=m->next)
6162  {
6163  if(m)
6164  {
6165  tScans++;
6166  }
6167  }
6168 
6169  markDataDirty(); /* Force a recalculation of intensities */
6170 
6172 
6173  computeMinMax();
6174  }
6175  else
6176  {
6177  log_msg("No Scans Loaded");
6178 
6179 // otf.valueMax = 0.0;
6180 // otf.valueMaxX = 0;
6181 // otf.valueMaxY = 0;
6182 
6183 // otf.valueMin = 0.0;
6184 // otf.valueMinX = 0;
6185 // otf.valueMinY = 0;
6186 
6187 // otf.manMapRa = 0.0;
6188 // otf.manMapDec = 0.0;
6189 
6190 // otf.restfreq = 0.0;
6191 
6192 // otf.cols = 0;
6193 // otf.rows = 0;
6194  }
6195 
6196  sexagesimal(otf.manMapRa/15.0, raStr, DD_MM_SS);
6197  sexagesimal(otf.manMapDec, decStr, DD_MM_SS);
6198 
6199  log_dup2stdout = 1;
6200 
6201  log_msg("OTF: Map Info:");
6202 
6203  log_msg("OTF: Map Coordinates: RA: %s; Dec: %s", raStr, decStr);
6204  log_msg("OTF: Map Cell Size: RA: %.2f Sec; Dec: %.2f Sec", otf.manNyquistRa, otf.manNyquistDec);
6205  log_msg("OTF: Map Cols: %4d; Rows: %4d", otf.cols, otf.rows);
6206  log_msg("OTF: Map Rest Freq: %.6f", otf.restfreq / 1000.0);
6207  log_msg("OTF: Backend Resolution: %.3f MHz; noint: %d", fabs(otf.freqres), otf.noint);
6208 
6209  log_msg("OTF: Number of Occupied Cells: %d out of %d", otf.numCellsUsed, otf.numCellsTotal);
6210  log_msg("OTF: Number of Bogus 0, 0 cells: %d", zeroCellCount);
6211  log_msg("OTF: Number of Artificial cells: %d", artificialCells);
6212  log_msg("OTF: Total Number of OTF Map Scans: %d", tScans);
6213  log_msg("OTF: Map Max Value: %10.6f @ Col: %d, Row: %d", otf.valueMax, otf.valueMaxX, otf.valueMaxY);
6214  log_msg("OTF: Map Min Value: %10.6f @ Col: %d, Row: %d", otf.valueMin, otf.valueMinX, otf.valueMinY);
6215 
6216  log_msg("OTF: Map Scale Factor: %.2f; Gamma Correction: %.2f", otf.scaleFactor, otf.gamma);
6217 
6218  log_msg("OTF: initialized = %d", otf.initialized);
6219  log_msg("OTF: ignoreAllRepaints = %d", otf.ignoreAllRepaints);
6220  log_msg("OTF: cutoff = %d", otf.cutoff);
6221  log_msg("OTF: fixBadChan = %d", otf.fixBadChan);
6222  log_msg("OTF: bins = %d", otf.bins);
6223  log_msg("OTF: plots = %d", otf.plots);
6224  log_msg("OTF: singleChan = %d", otf.singleChan);
6225  log_msg("OTF: arrayNum = %d", otf.arrayNum);
6226  log_msg("OTF: singleOtfBin = %d", otf.singleOtfBin);
6227  log_msg("OTF: debugSpectra = %d", otf.debugSpectra);
6228  log_msg("OTF: reqSpecIndx = %d", otf.reqSpecIndx);
6229  log_msg("OTF: noPlot = %d", otf.noPlot);
6230  log_msg("OTF: newShade = %d", otf.newShade);
6231  log_msg("OTF: requestCol = %d", otf.requestCol);
6232  log_msg("OTF: requestRow = %d", otf.requestRow);
6233  log_msg("OTF: col = %d", otf.col);
6234  log_msg("OTF: row = %d", otf.row);
6235  log_msg("OTF: cols = %d", otf.cols);
6236  log_msg("OTF: rows = %d", otf.rows);
6237  log_msg("OTF: numCellsTotal = %d", otf.numCellsTotal);
6238  log_msg("OTF: numCellsUsed = %d", otf.numCellsUsed);
6239  log_msg("OTF: noint = %d", otf.noint);
6240  log_msg("OTF: numSpectra = %d", otf.numSpectra);
6241  log_msg("OTF: int_chans[2] = %d - %d", otf.int_chans[0], otf.int_chans[1]);
6242  log_msg("OTF: lockScale = %d", otf.lockScale);
6243  log_msg("OTF: valueMaxChanged = %d", otf.valueMaxChanged);
6244  log_msg("OTF: intenChanged = %d", otf.intenChanged);
6245  log_msg("OTF: loadChoice = %d", otf.loadChoice);
6246  log_msg("OTF: lastAction = %d", otf.lastAction);
6247  log_msg("OTF: noColorBar = %d", otf.noColorBar);
6248  log_msg("OTF: colorChoice = %d", otf.colorChoice);
6249  log_msg("OTF: chanSelOTF = %d", otf.chanSelOTF);
6250  log_msg("OTF: gridBaseLine = %d", otf.gridBaseLine);
6251  log_msg("OTF: windowSizeSet = %d", otf.windowSizeSet);
6252  log_msg("OTF: placeBeamSize = %d", otf.placeBeamSize);
6253  log_msg("OTF: regionshow = %d", otf.regionshow);
6254  log_msg("OTF: regionshowbold = %d", otf.regionshowbold);
6255  log_msg("OTF: allowVelShift = %d", otf.allowVelShift);
6256  log_msg("OTF: whichPlot = %d", otf.whichPlot);
6257  log_msg("OTF: sizeofWorkArray = %d", otf.sizeofWorkArray);
6258  log_msg("OTF: baselines[8] = %d %d %d %d %d %d %d %d",
6259  otf.baselines[0], otf.baselines[1],
6260  otf.baselines[2], otf.baselines[3],
6261  otf.baselines[4], otf.baselines[5],
6262  otf.baselines[6], otf.baselines[7]);
6263 
6264  log_msg("OTF: scaleFactor = %f", otf.scaleFactor);
6265  log_msg("OTF: gamma = %f", otf.gamma);
6266  log_msg("OTF: IFNumber = %f", otf.IFNumber);
6267  log_msg("OTF: nyquistRa = %f", otf.nyquistRa);
6268  log_msg("OTF: nyquistDec = %f", otf.nyquistDec);
6269  log_msg("OTF: valueMin = %f", otf.valueMin);
6270  log_msg("OTF: valueMax = %f", otf.valueMax);
6271  log_msg("OTF: plotxb = %f", otf.plotxb);
6272  log_msg("OTF: plotyb = %f", otf.plotyb);
6273  log_msg("OTF: plotxe = %f", otf.plotxe);
6274  log_msg("OTF: plotye = %f", otf.plotye);
6275  log_msg("OTF: manMapRa = %f", otf.manMapRa);
6276  log_msg("OTF: manMapDec = %f", otf.manMapDec);
6277  log_msg("OTF: manMapWidth = %f", otf.manMapWidth);
6278  log_msg("OTF: manMapHeight = %f", otf.manMapHeight);
6279  log_msg("OTF: manNyquistRa = %f", otf.manNyquistRa);
6280  log_msg("OTF: manNyquistDec = %f", otf.manNyquistDec);
6281  log_msg("OTF: chanCompress = %f", otf.chanCompress);
6282  log_msg("OTF: freqres = %f", otf.freqres);
6283  log_msg("OTF: restfreq = %f", otf.restfreq);
6284  log_msg("OTF: velocity = %f", otf.velocity);
6285  log_msg("OTF: xsource = %f", otf.xsource);
6286  log_msg("OTF: ysource = %f", otf.ysource);
6287  log_msg("OTF: beamRa = %f", otf.beamRa);
6288  log_msg("OTF: beamDec = %f", otf.beamDec);
6289 
6290  log_msg("OTF: ");
6291 
6292  log_dup2stdout = 0;
6293 
6294  return(0);
6295 }
6296 
6297 
6298 
6300 struct XGR_ *s;
6301 {
6302  int i, row, col, k;
6303  int in, out, cols, rows;
6304  float *inarray=NULL, *outarray=NULL;
6305  char fname[256];
6306  FILE *fp;
6307  struct OTF_GRID *f;
6308 
6309  if(!otf.gridArray)
6310  {
6311  log_msg("interpAndWrite(): OTF Array is empty");
6312  return(1);
6313  }
6314 
6315  sprintf(fname, "/tmp/dataserv-grid.%d.dat", getpid());
6316 
6317  if((fp = fopen(fname, "w")) == NULL)
6318  {
6319  log_msg("interpAndWrite(): Unable to open %s", fname);
6320  return(1);
6321  }
6322 
6323  in = otf.cols * otf.rows;
6324  cols = otf.cols * 2;
6325  rows = otf.rows * 2;
6326 
6327  out = cols * rows;
6328 
6329  if( (inarray = (float *)malloc((unsigned)(in * sizeof(float)))) == NULL)
6330  {
6331  log_msg("interpAndWrite(): Unable to malloc(%d) inarray", in * sizeof(float));
6332 
6333  return(1);
6334  }
6335 
6336  if( (outarray = (float *)malloc((unsigned)(out * sizeof(float)))) == NULL)
6337  {
6338  log_msg("interpAndWrite(): Unable to malloc(%d) outarray", in * sizeof(float));
6339 
6340  free((char *)inarray);
6341 
6342  return(1);
6343  }
6344 
6345  bzero((char *)inarray, in * sizeof(float));
6346  bzero((char *)outarray, out * sizeof(float));
6347 
6348  k = 0;
6349  for(row=otf.rows-1;row>=0;row--)
6350  {
6351  for(col=0;col<otf.cols;col++)
6352  {
6353  f = fetchMapCell(row, col);
6354 
6355  if(f)
6356  {
6357  inarray[k++] = (float)f->shade;
6358  }
6359  else
6360  {
6361  inarray[k++] = 0.0;
6362  }
6363  }
6364  }
6365 
6366  interp(inarray, otf.cols, otf.rows, outarray, cols, rows);
6367 
6368  i = 0;
6369  for(row=0;row<rows;row++)
6370  {
6371  for(col=0;col<cols;col++,i++)
6372  {
6373  fprintf(fp, "%d %d %f\n", row, col, (float)outarray[i]);
6374  }
6375 
6376  fprintf(fp, "\n");
6377  }
6378 
6379  fclose(fp);
6380 
6381  if(inarray)
6382  {
6383  free((char *)inarray);
6384  }
6385 
6386  if(outarray)
6387  {
6388  free((char *)outarray);
6389  }
6390 
6391  return(0);
6392 }
6393 
6394 
6395 
6396 static float sqrarg;
6397 
6398 #define SQR(a) (sqrarg=(a),sqrarg*sqrarg)
6399 
6400 int lsqfit(x, y, bdata, ndata, sig, mwt, a, b, siga, sigb, chi2, q)
6401 float x[],y[],sig[],*a,*b,*siga,*sigb,*chi2,*q;
6402 int bdata,ndata,mwt;
6403 {
6404  int i;
6405  float wt, t, sxoss, sx = 0.0, sy = 0.0, st2 = 0.0, ss, sigdat;
6406 
6408 
6409  *b=0.0;
6410 
6411  if(mwt)
6412  {
6413  ss=0.0;
6414 
6415  for(i=bdata;i<ndata;i++)
6416  {
6417  wt = 1.0 / SQR(sig[i]);
6418  ss += wt;
6419  sx += x[i] * wt;
6420  sy += y[i] * wt;
6421  }
6422  }
6423  else
6424  {
6425  for(i=bdata;i<ndata;i++)
6426  {
6427  sx += x[i];
6428  sy += y[i];
6429  }
6430 
6431  ss=ndata-bdata;
6432  }
6433 
6434  sxoss = sx / ss;
6435 
6436  if(mwt)
6437  {
6438  for(i=bdata;i<ndata;i++)
6439  {
6440  t = (x[i] - sxoss) / sig[i];
6441  st2 += t * t;
6442  *b += t * y[i] / sig[i];
6443  }
6444  }
6445  else
6446  {
6447  for(i=bdata;i<ndata;i++)
6448  {
6449  t = x[i] - sxoss;
6450  st2 += t * t;
6451  *b += t * y[i];
6452  }
6453  }
6454 
6455  *b /= st2;
6456  *a = (sy - sx * (*b)) / ss;
6457  *siga = sqrt((1.0 + sx * sx / (ss * st2)) / ss);
6458  *sigb = sqrt(1.0 / st2);
6459  *chi2 = 0.0;
6460 
6461  if(mwt == 0)
6462  {
6463  for(i=bdata;i<ndata;i++)
6464  {
6465  *chi2 += SQR(y[i] - (*a) - (*b) * x[i]);
6466  }
6467 
6468  *q = 1.0;
6469  sigdat = sqrt((*chi2) / (ndata - bdata - 2));
6470  *siga *= sigdat;
6471  *sigb *= sigdat;
6472  }
6473 
6475 
6476  return(0);
6477 }
6478 
6479 #undef SQR
float valueMax
Definition: otf.h:217
int scanno
Definition: otf.h:64
float plotxe
Definition: otf.h:223
int regionshow
Definition: otf.h:188
double * workArrayChans
Definition: otf.c:33
struct WINDOW_HEAD windows
Definition: xgr.h:94
struct SCAN_SUM_SEND ss
Definition: scansum.c:61
struct HEADER head
Definition: ds_image_info.h:37
int do_otfRegular(void)
Definition: otf.c:1073
int singleChan
Definition: otf.h:158
double scan
Definition: header.h:35
float beamRa
Definition: otf.h:239
float scaleFactor
Definition: otf.h:211
float xsource
Definition: otf.h:237
#define FONT_SIZE_SMALL
Definition: dataFonts.h:6
int plotyb
Definition: xgr.h:63
int freeOtfMemory(void)
Definition: otf.c:126
int xgr_drawGrid(double f1b, double f1e, double f2b, double f2e, int n1, int n2, int dx, int dy, int tick, int label, int clr1, int clr2, int format)
float plotVal1
Definition: otf.h:117
int spikeCheck(char *buf)
Definition: otf.c:1291
#define YELLOW
Definition: colors.h:7
int debugSpectra
Definition: otf.h:161
int noYTick
Definition: xgr.c:19
int do_printIgnoreScans(void)
Definition: otf.c:699
int printKeySymHelp(void)
Definition: otf.c:2891
int xgr_drawPosText(double x, double y, char *msg, int clr, int f)
#define MAX_DATA_CHANNELS
Definition: linuxpops.c:61
int sock_write(struct SOCK *s, char *message, int l)
#define LSQFIT
Definition: etime_funcs.h:123
int xgr_drawBox(double x, double y, double x2, double y2, int color)
char * strcmprs(char *str)
int do_toggleRegion(void)
int checkKeyPress(XEvent *event)
Definition: otf.c:3293
int armBeamLocation
Definition: otf.h:192
int first
Definition: dbase.c:106
float otfIFNumber
Definition: otf.c:23
float beamDec
Definition: otf.h:240
int interp(double *array, int nx, int ny, double *parray, int npx, int npy)
Definition: interp.c:102
double v2a[8]
Definition: findinterp.c:11
#define WORK_ARRAY_X
Definition: otf.h:26
double noint
Definition: header.h:211
int shiftOtfChans(double *in, int n, int shift)
Definition: otf.c:2416
double datalen
Definition: header.h:34
float manMapDec
Definition: otf.h:228
double utdate
Definition: header.h:61
int sockmode
Definition: dataserv.c:37
int artificialCells
Definition: otf.c:30
struct OTF_GRID * gridLast
Definition: otf.c:41
float wt
Definition: otf.h:130
float manNyquistRa
Definition: otf.h:231
int scan
int datalen
Definition: dataserv.c:33
Definition: otf.h:98
int do_fullInterpFill(char *buf)
Definition: otf.c:5640
#define WORK_ARRAY_Y
Definition: otf.h:31
int colorChoice
Definition: otf.h:181
double sqrarg
Definition: gridmap.c:65
char source[SRCLEN+1]
Definition: dataserv.c:52
struct OTF_GRID * gridHead
Definition: otf.c:40
int cutoff
Definition: otf.h:153
int chanSelOTF
Definition: otf.h:183
float a
Definition: otf.h:123
int artificial
Definition: otf.h:111
#define CTR
Definition: defines.h:26
int do_etime(int func, int action)
Definition: etime.c:268
int ephemObj
Definition: otf.c:25
int plotye
Definition: xgr.h:63
float * gridArrayChans
Definition: otf.h:225
struct HEADER * head
Definition: otf.h:246
int do_otfTsys(char *buf)
Definition: mailparse.c:1516
int aosScanDone
Definition: mailparse.c:33
int do_otfRmRMS(char *buf)
Definition: otf.c:5394
#define GRAY75
Definition: colors.h:8
double bfwhm
Definition: header.h:114
char filename[256]
Definition: dataserv.c:49
#define COMPUTEINTEN
Definition: etime_funcs.h:34
float scan
Definition: gridmap.c:94
int plotxe
Definition: xgr.h:63
int accumDataIntoWork(void)
Definition: otf.c:2218
struct DS_IMAGE_INFO ds_image_info
Definition: linuxpops.c:64
FILE * fp
Definition: linuxpops.c:70
#define max(a, b)
Definition: cactus.h:115
#define GRAY50
Definition: colors.h:7
int getChanOTF(void)
Definition: otf.c:4729
Definition: header.h:13
int debugSpectra
Definition: otf.h:71
float b
Definition: otf.h:124
int do_otfColorChoice(char *buf)
Definition: mailparse.c:1249
#define DO_OTFREGULAR
Definition: etime_funcs.h:29
#define OTFPLOTYB
Definition: otf.h:21
double xsource
Definition: header.h:74
double ysource
Definition: header.h:75
struct XGR_HEAD * next
Definition: xgr.h:36
char coordcd[8]
Definition: header.h:87
char * help
Definition: otf.c:2841
int numSpectra
Definition: otf.h:172
#define PLACEBEAMSIZE
Definition: etime_funcs.h:39
int createInterpTable(int max)
Definition: otf.c:4738
float * offdata
Definition: specdata.c:87
double tcal
Definition: header.h:202
int placeBeamSize
Definition: otf.h:187
#define NORMAL_MAP
Definition: otf.h:11
char * getLogDate(int offset)
int do_otfTime(char *buf)
Definition: mailparse.c:1559
int row
Definition: otf.h:110
#define SUBTRACTPREDICTEDRA
Definition: etime_funcs.h:38
#define DO_IGNORESCAN
Definition: etime_funcs.h:11
int drawColorBar(void)
Definition: otf.c:2108
char gainsfile[256]
Definition: otf.h:62
#define WHITE
Definition: colors.h:11
#define DO_OTFRMBADCHAN
Definition: etime_funcs.h:32
int lastGraph
Definition: otf.c:26
int version
Definition: dataserv.c:41
struct LP_IMAGE_INFO last_image
Definition: xgraphic.c:95
float intInten
Definition: otf.h:119
int computeShade(void)
Definition: otf.c:1602
int shift(void)
Definition: shift.c:65
int valueMaxX
Definition: otf.h:196
int computeBaseLine(struct LP_IMAGE_INFO *image)
Definition: baseline.c:200
int otfGridDisplaySpec(XEvent *event, unsigned int mask)
Definition: otf.c:3553
int zeroCellCount
Definition: otf.c:29
int newShade
Definition: otf.h:164
#define OTFPLOTYE
Definition: otf.h:22
int sockWriteNoBitch
struct MAP_SCANS * next
Definition: otf.h:102
#define DO_ADDHEADER
Definition: etime_funcs.h:7
struct MAP_SCANS * ignore_scans_head
Definition: otf.c:35
int noint
Definition: otf.h:171
int lastAction
Definition: otf.h:179
float plotxb
Definition: otf.h:221
int markDataDirty(void)
Definition: otf.c:2621
char * strupr(char *str)
float tsys
Definition: otf.h:129
struct WINDOW * otfwin
Definition: xgr.h:98
#define FONT_SIZE_NORMAL
Definition: dataFonts.h:7
#define XGR_SET_PIXMAP
Definition: xgr.h:24
#define PLOT_RMS
Definition: otf.h:52
float plotye
Definition: otf.h:224
#define DSTIME_START
Definition: etime.h:6
double sideband
Definition: header.h:143
int doTPprocess
Definition: otf.h:76
struct GRID_ACCUM workArray[WORK_ARRAY_X][WORK_ARRAY_Y]
Definition: otf.c:32
float globalXmax
Definition: otf.c:22
struct SCAN_HEADERS * otf_scan_headers
Definition: otf.c:36
double synfreq
Definition: header.h:132
int computeRms(float *y, int n, float *rms)
Definition: line.c:82
struct OTF_GRID * next
Definition: otf.h:136
int debug
Definition: mailparse.c:29
char oldBuf[16384]
Definition: dataserv.c:52
int doOtfGridRePaint(void)
Definition: otf.c:1104
struct OTF_GRID * fetchMapCell(int row, int col)
Definition: otf.c:5584
int fbScanDone
Definition: mailparse.c:32
int int_chans[2]
Definition: otf.h:173
int displayOtfGridSpectra(struct OTF_GRID *s)
Definition: otf.c:3766
struct HEADER lastHead
Definition: otf.c:8
int placeBeamSize(void)
Definition: otf.c:1755
int whichPlot
Definition: otf.h:202
Display * dpy
Definition: xgr.h:79
#define DOOTFGRIDREPAINT
Definition: etime_funcs.h:30
int baselines[8]
Definition: otf.h:207
int ddirty
Definition: otf.h:205
char magic[16]
Definition: ds_image_info.h:2
int sexagesimal(double dang, char *str, int prec)
int noXTick
Definition: xgr.c:18
int do_toggleRegionLabels(void)
int interpAndPlot(struct XGR_ *s)
Definition: otf.c:4345
int allowVelShift
Definition: otf.h:191
float nyquistRa
Definition: otf.h:214
struct HEADER * checkScanHeader(int v, float s)
Definition: gridmap.c:131
float chanCompress
Definition: otf.h:233
#define INITGRID
Definition: etime_funcs.h:40
int getNumSpectra(double datalen, double noint)
int markBaseDirty(void)
Definition: otf.c:2641
int log_msg(const char *fmt,...)
float rms
Definition: otf.h:121
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 dispatchOtfGridEvents(XEvent *e)
Definition: otf.c:2953
char datafile[256]
Definition: otf.h:61
struct SOCK * specdata
Definition: dataserv.c:31
#define DO_PRINTIGNORESCANS
Definition: etime_funcs.h:16
Definition: xgr.h:35
char gfilename[256]
Definition: dataserv.c:50
int do_otfSlice(char *buf)
Definition: otf.c:5964
#define WORK_ARRAY_X_P
Definition: otf.h:29
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)
float manMapWidth
Definition: otf.h:229
int xgr_drawFillBox(double xmin, double xmax, double ymin, double ymax, double xl, double yt, double xr, double yb, int color)
#define OTFRA
Definition: otf.h:6
int accumWorkIntoGrid(void)
Definition: otf.c:2497
int regionshowbold
Definition: otf.h:189
int oldshade
Definition: otf.h:107
int doColor
Definition: xgr.c:13
int plotxb
Definition: xgr.h:63
int do_otf3dplot(char *buf)
Definition: otf.c:5220
float * gainsdata
Definition: specdata.c:89
int setInValid(int w)
Definition: xgr.c:2333
int do_otfRmBadChan(void)
Definition: otf.c:1208
#define DO_CLEARIGNORE
Definition: etime_funcs.h:17
double datamin
Definition: dataserv.c:44
int checkMapScans(int v, double s)
int setMapCell(int row, int col, struct OTF_GRID *f)
Definition: otf.c:5597
Definition: otf.h:105
float * ondata
Definition: otf.h:218
int do_toggleRegionBold(int dir)
float nyquistDec
Definition: otf.h:215
int zeroWorkArray(void)
Definition: otf.c:2328
int numCellsUsed
Definition: otf.h:200
double refpt_vel
Definition: header.h:175
int ok2grid
Definition: otf.c:27
#define CHECKSCANHEADER
Definition: etime_funcs.h:8
#define REMMAPSCANS
Definition: etime_funcs.h:20
int getRequestedCell(int row, int col)
Definition: otf.c:3482
int valueMaxChanged
Definition: otf.h:176
#define XGR_OTF_WIN
Definition: xgr.h:20
int arrayNum
Definition: otf.h:77
#define SQR(a)
Definition: otf.c:6398
int ddirty
Definition: otf.h:113
int pixmapY
Definition: xgr.h:61
int forceDrawGrid(void)
Definition: otf.c:5935
int do_otfListCells(char *buf)
Definition: otf.c:5904
float globalYmax
Definition: otf.c:22
#define DO_OTF
Definition: etime_funcs.h:28
int xgr_setWindowSize(char *name, double x, double y)
int chanSelOTF
Definition: otf.c:24
float manMapHeight
Definition: otf.h:230
int ver
Definition: otf.h:99
int lockScale
Definition: otf.h:174
#define DO_OTFGRIDLOAD
Definition: etime_funcs.h:65
int valueMinY
Definition: otf.h:195
float manNyquistDec
Definition: otf.h:232
float globalStart
Definition: specdata.c:37
int baselines[8]
Definition: ds_image_info.h:13
char obsmode[8]
Definition: header.h:41
int valueMaxY
Definition: otf.h:197
struct STURCT_KEYSYMS keysyms[]
Definition: otf.c:2844
int gridBaseLine
Definition: otf.h:184
int drawRegions(void)
#define MAX_BAD_CHAN
Definition: defines.h:29
int checkIgnoreScans(int v, double s)
int singleOtfBin
Definition: otf.h:74
float * gainsdata
Definition: otf.h:220
int otfInit(int init)
Definition: otf.c:423
Definition: otf.h:58
#define XGR_PLOT_SEX
Definition: xgr.h:31
#define CHECKIGNORESCANS
Definition: etime_funcs.h:12
KeySym sym
Definition: otf.c:2838
int addIgnoreScans(int v, double s)
int dontsend
Definition: otf.c:28
int initGrid(void)
Definition: otf.c:1812
Definition: xgr.h:48
int strcmp()
float * chans
Definition: otf.h:122
Definition: xgr.h:75
int xgr_findWindow(Display *dpy, Window win, struct WINDOW **w)
Definition: xgr.c:602
int row
Definition: otf.h:142
double velocity
Definition: header.h:118
#define CHECKMAPSCANS
Definition: etime_funcs.h:18
int doOtfGridReSize(void)
Definition: otf.c:1186
#define LOAD_STEP
Definition: otf.h:16
int valueMinX
Definition: otf.h:194
float velocity
Definition: otf.h:236
char * key
Definition: otf.c:2840
int normalizeAndCal(void)
Definition: otf.c:2352
int bdirty
Definition: otf.h:204
int subtractPredictedRA(float *data)
Definition: otf.c:1715
#define DD_MM_SS
Definition: sex.h:15
#define COMPUTESHADE
Definition: etime_funcs.h:36
struct HEADER head
Definition: gridmap.c:96
#define LOAD_PREVIEW
Definition: otf.h:15
double wt
Definition: otf.h:146
int shade
Definition: otf.h:106
int fillOtfGrid(void)
Definition: otf.c:2149
int loadChoice
Definition: otf.h:178
int do_otfSpectralSum(char *buf)
Definition: otf.c:4791
int do_clearIgnore(void)
Definition: otf.c:741
char mainFrameTitle[80]
Definition: dataserv.c:52
float gamma
Definition: otf.h:212
double * chans
Definition: otf.h:145
int do_scanDone(char *buf)
Definition: mailparse.c:306
long sizeofWorkArray
Definition: otf.h:209
float globalXmin
Definition: otf.c:22
double stsys
Definition: header.h:203
int xgr_drawTextClear(double x, double y, char *msg, int clr, int f)
#define WORK_ARRAY_X_CENT
Definition: otf.h:27
int opticalFileNeedDisplay
Definition: colors.h:45
int do_otfGridDump(void)
Definition: otf.c:4059
char session[80]
Definition: strings.c:67
char source[16]
Definition: ds_image_info.h:3
int arrayNum
Definition: otf.h:159
float * offdata
Definition: otf.h:219
int interpAndWrite(struct XGR_ *s)
Definition: otf.c:6299
Window win
Definition: xgr.h:52
double findInterp(double v1, double v2, int indx, int max)
Definition: otf.c:4771
int getBaselines(int *b)
Definition: otf.c:3891
int row
Definition: otf.h:168
#define DSTIME_STOP
Definition: etime.h:7
int remIgnoreScans(void)
Definition: otf.c:630
int displayRequestedOtf(void)
Definition: otf.c:3737
int noPlot
Definition: xgr.c:20
int xgr_hardFont
Definition: xgr.c:21
double refpt
Definition: header.h:207
int badChanArray[MAX_BAD_CHAN]
Definition: otf.c:38
double datamax
Definition: dataserv.c:44
int numCellsTotal
Definition: otf.h:199
float ysource
Definition: otf.h:238
int paintOtfGrid(void)
Definition: otf.c:1844
char frameTitle[80]
Definition: xgr.h:50
int do_ignoreScan(char *buf)
Definition: otf.c:448
float globalYmin
Definition: otf.c:22
float IFNumber
Definition: otf.h:213
float bdata[MAX_ATM_ELEMENTS]
Definition: atm.c:94
int addMapScans(int v, double s)
int rows
Definition: otf.h:170
int n
Definition: otf.h:143
#define PLOT_TIME
Definition: otf.h:54
struct WINDOW_HEAD * next
Definition: xgr.h:43
int do_otfGridInit(void)
Definition: otf.c:4257
double deltax
Definition: header.h:209
#define MAX_GRAY_SCALE
Definition: colors.h:31
float manMapRa
Definition: otf.h:227
int thisIsaRefresh
Definition: dataserv.c:36
#define OTFPLOTXB
Definition: otf.h:19
int cols
Definition: otf.h:169
#define CHANNEL_MAP
Definition: otf.h:13
float scanNum
Definition: dataserv.c:46
struct XGR_HEAD xgr_head
Definition: xgr.c:36
char source[32]
Definition: otf.h:132
#define SPIKECHECK
Definition: etime_funcs.h:33
int do_saveIgnoreScans(FILE *fp)
Definition: otf.c:659
int doingMosaic
Definition: otf.h:182
#define WORK_ARRAY_Y_CENT
Definition: otf.h:32
int set
Definition: otf.h:108
int computeInten(int bc, int ec)
Definition: otf.c:1377
int do_otfRms(char *buf)
Definition: mailparse.c:1538
#define XGR_PLOT_DEGREES
Definition: xgr.h:30
double rms
Definition: beam.h:5
int do_printMapScans(void)
Definition: otf.c:900
int writeSingleChan
Definition: otf.c:45
int resendSpecData(struct SPECDATA *sd)
Definition: otf.c:962
int do_otfInterp(void)
Definition: mailparse.c:1234
#define OTFPLOTXE
Definition: otf.h:20
struct RGB colormap[]
Definition: xgr.c:69
int noColorBar
Definition: otf.h:180
int col
Definition: otf.h:109
int do_etimeClear(void)
Definition: etime.c:170
int do_otf3dcube(char *buf)
Definition: otf.c:4931
float plotVal2
Definition: otf.h:118
int initialized
Definition: otf.h:151
int singleChan
Definition: otf.h:73
int do_otf(float *data, struct HEADER *head, float *offdata, float *gainsdata)
Definition: otf.c:1006
int stopFlag
Definition: mailparse.c:30
double inttime
Definition: header.h:210
#define BLACK
Definition: colors.h:4
int fixBadChan
Definition: otf.h:155
int xgr_pixmapToWindow(char *name)
Definition: xgr.c:530
int intenChanged
Definition: otf.h:177
struct HEADER * addScanHeader(int v, float s, struct HEADER *head)
Definition: gridmap.c:171
#define DO_PRINTMAPSCANS
Definition: etime_funcs.h:21
#define REMSCANHEADERS
Definition: etime_funcs.h:10
int requestCol
Definition: otf.h:165
int pixmapX
Definition: xgr.h:61
double avg
Definition: beam.h:5
int requestRow
Definition: otf.h:166
char peakStr[80]
Definition: otf.h:242
int putOtfGrid(void)
Definition: otf.c:2095
double ycell0
Definition: header.h:109
double deltaxr
Definition: header.h:103
struct SOCK * specplot
Definition: dataserv.c:31
#define TRUE
Definition: xgraphic.c:39
int do_otfVelRun(char *buf)
Definition: otf.c:3904
int xgr_setBox(double x, double y, double dx, double dy)
#define ADDIGNORESCANS
Definition: etime_funcs.h:13
int max_gray_scale
Definition: xgr.c:66
struct OTF_STRUCT otf
Definition: specdata.c:100
int ignoreAllRepaints
Definition: otf.h:152
int insertVersion(struct OTF_GRID *g, int ver)
Definition: otf.c:2387
int xgr_drawCircle(double xmin, double xmax, double ymin, double ymax, double x, double y, double w, double h, int color, int size)
int col
Definition: otf.h:167
int do_otfFixBadCells(char *buf)
Definition: otf.c:5836
int otfGridInit(int cols, int rows, int noint)
Definition: otf.c:167
int feed
Definition: otf.h:65
#define XGR_SET_WIN
Definition: xgr.h:25
#define DO_SAVEIGNORESCANS
Definition: etime_funcs.h:15
int weightedAvergeCells(struct OTF_GRID *f, struct OTF_GRID *p1, double p1_avg, struct OTF_GRID *p2, double p2_avg, int try, int row, int col, int *count)
Definition: otf.c:5732
#define m(i)
float plotyb
Definition: otf.h:222
int to_xgraphic(char *buf)
Definition: dataserv.c:139
#define SCALEDATA
Definition: etime_funcs.h:37
struct HEADER * head
Definition: otf.h:134
int doSpecPlot(struct DS_IMAGE_INFO *im)
Definition: specplot.c:964
XImage * ximage
Definition: otf.h:247
struct HEADER * do_addHeader(int ver, float scan, struct HEADER *head)
Definition: gridmap.c:104
float bscan
Definition: otf.h:125
int bins
Definition: otf.h:156
float restfreq
Definition: otf.h:235
struct MAP_SCANS * map_scans_head
Definition: otf.h:244
#define GETNUMSPECTRA
Definition: etime_funcs.h:22
#define OTF_GRAPH
Definition: defines.h:11
int do_otfStatus(void)
Definition: otf.c:6152
struct OTF_GRID ** gridArray
Definition: otf.h:245
int scaleData(float *data)
Definition: otf.c:1691
float freqres
Definition: otf.h:234
#define ADDMAPSCANS
Definition: etime_funcs.h:19
int version[8]
Definition: otf.h:114
int otfInterp(void)
Definition: otf.c:4282
int remScanHeaders()
Definition: gridmap.c:224
int reqSpecIndx
Definition: otf.h:162
char object[16]
Definition: header.h:40
#define PLOT_INT_INTENSITY
Definition: otf.h:51
double restfreq
Definition: header.h:198
int findNextCell(int row, int col, struct OTF_GRID **p2)
Definition: otf.c:5614
int do_zapCell(char *buf)
Definition: otf.c:5497
float escan
Definition: otf.h:126
int ds_delay(double dc)
Definition: dataserv.c:1167
int xgr_mapUnmapWindow(char *name, int map)
Definition: xgr.c:568
#define MAX_KEYSYMS
Definition: otf.c:2888
double freqres
Definition: header.h:199
#define MAX_GAP
Definition: otf.c:5612
#define PAINTOTFGRID
Definition: etime_funcs.h:41
float time
Definition: otf.h:127
float scan
Definition: otf.h:100
#define COMPUTEMINMAX
Definition: etime_funcs.h:35
#define ADDSCANHEADER
Definition: etime_funcs.h:9
#define WORK_ARRAY_Y_P
Definition: otf.h:34
int do_otfGridLoad(char *buf)
Definition: otf.c:4100
#define DOOTFGRIDRESIZE
Definition: etime_funcs.h:31
int remMapScans(void)
Definition: otf.c:871
#define REMIGNORESCANS
Definition: etime_funcs.h:14
int col
Definition: otf.h:141
struct SPECDATA sd
Definition: otf.c:43
#define INTERP
Definition: otf.h:12
int to_helper(char *buf)
Definition: dataserv.c:125
float scanct
Definition: otf.h:116
float kms
Definition: otf.h:120
#define MAGENTA
Definition: colors.h:9
float ydata[MAX_DATA_CHANNELS]
Definition: ds_image_info.h:39
struct SCAN_HEADERS * next
Definition: gridmap.c:98
int xgr_checkForEvents(void)
Definition: xgr.c:2547
int singleOtfBin
Definition: otf.h:160
int windowSizeSet
Definition: otf.h:185
int computeMinMax(void)
Definition: otf.c:1511
int recomputeBaseLines(void)
Definition: otf.c:2662
char coordcd[8]
Definition: ds_image_info.h:4
int do_otfSendPlot(char *buf)
Definition: otf.c:3453
struct XGR_ * server
Definition: dataserv.c:112
int xgr_clearScreen(void)
Definition: xgr.c:921
#define PLOT_TSYS
Definition: otf.h:53
float valueMin
Definition: otf.h:216
int plots
Definition: otf.h:157
#define GREEN
Definition: colors.h:6
int noPlot
Definition: otf.h:163
int bdirty
Definition: otf.h:112
int do_otfChannelMap(char *buf)
Definition: otf.c:4558
double v1a[8]
Definition: findinterp.c:11
int xgr_setCurWindow(int win, int which)
Definition: xgr.c:483