Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
xgraphic.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5 #include <fcntl.h>
6 #include <math.h>
7 #include <signal.h>
8 #include <time.h>
9 #include <termios.h>
10 #include <unistd.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <sys/ioctl.h>
14 
15 #include "observing_par.h"
16 #include "cactus.h"
17 #include "sex.h"
18 #include "global.h"
19 #include "gaussian.h"
20 #include "image.h"
21 #include "flux.h"
22 #include "accum.h"
23 #include "focus.h"
24 #include "object.h"
25 #include "lp_fft.h"
26 #include "strings_and_things.h"
27 #include "histogram.h"
28 #include "tsys.h"
29 #include "scan_sum.h"
30 #include "loglib.h"
31 
32 #define DEFINE_COLORS_STRINGS
33 #include "colors.h"
34 
35 #include "caclib_proto.h"
36 #include "linuxlib_proto.h"
37 #include "proto.h"
38 
39 #define TRUE 1
40 #define FALSE 0
41 
42 #define LAST_IMAGE_INFO 1
43 #define LAST_FLUX_INFO 2
44 #define LAST_ACCUM_RESULTS 3
45 #define LAST_FLUX_HISTORY 4
46 #define LAST_CONTINUUM_PLAIN 5
47 #define LAST_CONTINUUM_SPTIP 6
48 #define LAST_OBJECT_HISTORY 7
49 #define LAST_FFT_INFO 8
50 #define LAST_HISTO_INFO 9
51 #define LAST_TSYS_INFO 10
52 #define LAST_SSS_INFO 11
53 #define LAST_FOCUS_HISTORY 12
54 
55 #define PLOT 1
56 #define PRINT 2
57 
58 #define SINGLE 1
59 #define MULTI 2
60 
61 #define SAVE_DEM_FILE 1
62 
63 #define NEW_MAKE 1
64 
65 extern int computeXaxis(struct LP_IMAGE_INFO *image, int logit);
66 
67 char *firstArg = "H0"; /* Need to line ../condar/image.o */
68 
69 char *kp_sideband[] = { "H-LSB", "H-USB", "V-LSB", "V-USB" };
70 char *mg_sideband[] = { "H-LSB", "H-USB", "V-LSB", "V-USB" };
71 char *sideband[] = { "LSB", "USB", "LSB", "USB" };
72 
73 char *prompt = "Xgraphics >>"; /* Required for linking */
74 char *papersize = "10, 7.5";
75 char fsize[256], psize[256];
76 char *mouse_str = "print \"MOUSE: \", MOUSE_X, \" \", MOUSE_X2, \" \", MOUSE_Y, \" \", MOUSE_Y2";
77 char *map_ang_str = "print \"MAP_ANGLE: \", GPVAL_VIEW_ROT_X, \" \", GPVAL_VIEW_ROT_Z";
78 char *get_range_str = "print \"PLOT_RANGE: \", GPVAL_X_MIN, \" \", GPVAL_X_MAX, \" \", GPVAL_Y_MIN, \" \", GPVAL_Y_MAX";
79 
80 char session[80];
81 
82 char *focus_axis_str[] = { "AX", "NS", "EW" };
83 
84 struct SOCK *master;
87 int displayW = 1920;
88 int displayH = 1080;
89 int startx = 1920-800;
90 
92 
93 FILE *errPrint_fp = NULL;
94 
109 
110 #define MAX_BUF_SIZE (sizeof(last_image)+256)
111 
112 char *plotStyleStrs[] = { "histeps",
113  "lines",
114  "points",
115  "linespoints"
116 };
117 
118 FILE *gpout, *gpin;
119 
120  /* The following are Required for linking to ../lib/liblinux.a*/
125 
126 static float sinEl[] = {2.6, 2.3, 2.0, 1.7, 1.4, 1.1, 1.4, 1.7, 2.0, 2.3, 2.6};
127 
128 char osbStr[32];
129 
130 /* Redefine the bind keys so if I type in the plot window,
131  it doesn't do stupid things */
132 char *gnuplot_inits[] = {
133  "bind m \"x = 1\"",
134  "bind a \"x = 1\"",
135  "bind g \"x = 1\"",
136  "bind h \"x = 1\"",
137  "bind l \"x = 1\"",
138  "bind L \"x = 1\"",
139  "bind 1 \"x = 1\"",
140  "bind 2 \"x = 1\"",
141  "bind 3 \"x = 1\"",
142  "bind 4 \"x = 1\"",
143  "bind 5 \"x = 1\"",
144  "bind 6 \"x = 1\"",
145  "bind 7 \"x = 1\"",
146  NULL
147 };
148 #define MAX_GNUPLOT_INITS 13
149 
150 
151 int setColor(c)
152 int c;
153 {
154  return(0);
155 }
156 
157 /*
158 
159  Code stolen from: gpReadMouseTest.c
160 
161  Test piped communication and mouse readback with gnuplot.
162  This code is published under the GNU Public License.
163 
164  This example demonstrates how to wait for a mouse press and get the
165  mouse button number and mouse position, from a graph in gnuplot.
166 
167 */
168 
169 char gpfifo[256];
170 
172 char *term;
173 {
174  int i;
175  char pbuf[256], sysbuf[256];
176  char *string, line[256], *cp;
177  FILE *fp;
178 
179 /* Create a FIFO we later use for communication gnuplot => our program. */
180  if(mkfifo(gpfifo, 0600))
181  {
182  if(errno != EEXIST)
183  {
185  unlink(gpfifo);
186 
187  return(1);
188  }
189  }
190 
191  cp = getenv("LINUXPOPS_GNUPLOT");
192  if(cp)
193  {
194  sprintf(pbuf, "%s -title GNUPLOT_%s", cp, session);
195  }
196  else
197  {
198  sprintf(pbuf, "gnuplot -title GNUPLOT_%s", session);
199  }
200 
201  if((gpout = popen(pbuf, "w")) == NULL)
202  {
203  log_perror(pbuf);
204 
205  exit(1);
206  }
207 
208  log_msg("# Connected to gnuplot on FIFO: %s", gpfifo);
209 
210 /* Init mouse and redirect all gnuplot printings to our FIFO */
211  fprintf(gpout, "set mouse; set print \"%s\"\n", gpfifo);
212  fflush(gpout);
213 
214  fprintf(gpout, "set terminal %s enhanced font \"%s\"\n", term, fsize);
215  fflush(gpout);
216 
217  /* Redifine gnuplot bindings */
218  for(i=0;i<MAX_GNUPLOT_INITS;i++)
219  {
220  fprintf(gpout, "%s\n", gnuplot_inits[i]);
221  fflush(gpout);
222 
223  usleep(100000);
224  }
225 
226 /* Open the FIFO (where gnuplot is writing to) for reading. */
227  if((gpin = fopen(gpfifo,"r")) == NULL)
228  {
230  pclose(gpout);
231 
232  return(1);
233  }
234 
235  /* Now go find the PID of the underlying gnuplot process */
236  sprintf(sysbuf,
237  "/bin/ps auxww | /bin/grep -i 'GNUPLOT_%s' | /bin/grep 'gnuplot ' | /bin/grep -v grep | /bin/awk '{print $2}'",
238  session);
239 
240  if((fp = popen(sysbuf, "r")) == NULL)
241  {
242  log_perror(sysbuf);
243  pclose(gpin);
244  pclose(gpout);
245 
246  exit(1);
247  }
248 
249  while((string = fgets(line, sizeof(line), fp)) != NULL)
250  {
251  if(strlen(line) > 1)
252  {
253  gnuplot_pid = atoi(line);
254  break;
255  }
256  }
257 
258  pclose(fp);
259 
260  log_msg("< Got Gnuplot PID %d", gnuplot_pid);
261 
262  log_msg("# FIFO open for reading.");
263 
264  return(0);
265 }
266 
267 
269 {
270  if(gpin)
271  {
272  fclose(gpin);
273  }
274 
275  writeGnuplot("exit", 0);
276 
277  sleep(1);
278 
279  if(gpout)
280  {
281  pclose(gpout);
282  }
283 
284  unlink(gpfifo);
285 
286  return(0);
287 }
288 
290 char *buf;
291 int delay;
292 {
293  log_msg("> Sending to gnuplot: %s", buf);
294 
295  fprintf(gpout, "%s\n", buf);
296  fflush(gpout);
297 
298  if(delay > 0)
299  {
300  log_msg("Sleeping for %.3f seconds", (double)delay / 1.0e6);
301 
302  usleep(delay);
303  }
304 
305  return(0);
306 }
307 
308 
309 int readGnuplot(buf)
310 char *buf;
311 {
312  int len;
313  char inBuf[1024], *cp;
314  static int cnt = 0;
315 
316  cp = fgets(inBuf, sizeof(inBuf), gpin);
317 
318  if(cp == NULL)
319  {
320  log_msg("Nothing returned from fscanf()");
321  cnt++;
322 
323  if(cnt > 100)
324  {
325  log_msg("Runaway detected; Exiting");
326  sock_send(master, "xgraphic_quitting");
327 
328  exit(1);
329  }
330 
331  return(1);
332  }
333  else
334  {
335  len = strlen(inBuf);
336 
337  if(len > 2)
338  {
339  inBuf[len-1] = '\0';
340  }
341 
342  log_msg("< Got from gnuplot: %s", inBuf);
343 
344  strcpy(buf, inBuf);
345 
346  cnt = 0;
347  }
348 
349  return(0);
350 }
351 
352 
353 int isBadChan(image, bad)
354 struct LP_IMAGE_INFO *image;
355 int bad;
356 {
357  int i;
358 
359  for(i=0;i<MAX_BAD_CHANS;i++)
360  {
361  if(image->badChans[i] == bad)
362  {
363  return(1);
364  }
365  }
366 
367  return(0);
368 }
369 
370 char *makeDate(d)
371 double d;
372 {
373  double year, mon, day;
374  double f;
375  static char tbuf[256];
376 
377  /* Example date: 2016.1130 */
378 
379 // log_msg("Date: %f", d);
380 
381  year = floor(d);
382 // log_msg("Date: %f", year);
383 
384  f = d - year; /* f = 0000.1130 */
385 // log_msg("Date: %f", f);
386 
387  f *= 100.0; /* f = 11.30 */
388 // log_msg("Date: %f", f);
389 
390  mon = floor(f);
391 // log_msg("Date: %f", mon);
392 
393  f = f - floor(f); /* f = 0.30 */
394 // log_msg("Date: %f", f);
395 
396  f *= 100.0; /* f = 30.00 */
397 // log_msg("Date: %f", f);
398 
399  day = f;
400 // log_msg("Date: %f", day);
401 
402  sprintf(tbuf, "%02.0f-%02.0f-%4.0f", mon, day, year);
403 
404 // log_msg("Date: %s", tbuf);
405 
406  return(tbuf);
407 }
408 
409 
410 char *makeFrStr(freqres)
411 double freqres;
412 {
413  static char tbuf[256];
414  double fr;
415 
416  fr = fabs(freqres * 1e3);
417 
418  if(fr < 100.0)
419  {
420  sprintf(tbuf, "FR=%4.2f", fr);
421  }
422  else
423  {
424  sprintf(tbuf, "FR=%4.0f", fr);
425  }
426 
427  return(tbuf);
428 }
429 
430 
431 int makeLineHeader(image, buf)
432 struct LP_IMAGE_INFO *image;
433 char *buf;
434 {
435 // int l1, l2, l3;
436  char tbuf[256], raStr[80], decStr[80], timeStr[80], scanStr[80], dateStr[256];
437  struct HEADER *h;
438 
439  h = &image->head;
440 
441  sexagesimal(h->epocra / 15.0, raStr, DD_MM_SS);
442  sexagesimal(h->epocdec, decStr, DD_MM_SS);
443  sexagesimal(h->inttime / 3600.0, timeStr, DD_MM_SS);
444 
445  if(image->ainfo.bscan != 0.0 && image->ainfo.escan != 0.0)
446  {
447  sprintf(scanStr, "(%3d) Scans: %7.2f-%7.2f",
448  image->ainfo.scanct, image->ainfo.bscan, image->ainfo.escan);
449  }
450  else
451  {
452  sprintf(scanStr, "%7.2f ", h->scan);
453  }
454 
455  strcpy(dateStr, makeDate(h->utdate));
456 
457  sprintf(tbuf, "%16.16s %s INT=%s DATE: %s\\n", h->object, scanStr, timeStr, dateStr);
458 
459 // l1 = strlen(tbuf);
460 
461  strcpy(buf, tbuf);
462 
463  sprintf(tbuf, "%8.8s %s %s CAL= %6.1f TS=%6.1f\\n",
464  h->coordcd, raStr, decStr, h->tcal, h->stsys);
465 // l2 = strlen(tbuf);
466 
467  strcat(buf, tbuf);
468 
469  sprintf(tbuf, "FREQ= %9.2f SYN= %8.6f VEL= %8.1f DV= %5.2f %s SB=%d",
470  h->restfreq, h->synfreq/1000.0, h->velocity, h->deltax, makeFrStr(h->freqres), (int)h->sideband);
471 // l3 = strlen(tbuf);
472 
473  strcat(buf, tbuf);
474 
475 // log_msg("# Header Lenght: %d, %d, %d", l1, l2, l3);
476 
477  return(0);
478 }
479 
480 
481 int makeFFTHeader(fft, buf)
482 struct FFT_INFO *fft;
483 char *buf;
484 {
485  char tbuf[256], raStr[80], decStr[80], timeStr[80], scanStr[80], dateStr[256];
486  struct HEADER *h;
487 
488  h = &fft->head;
489 
490  sexagesimal(h->xsource / 15.0, raStr, DD_MM_SS);
491  sexagesimal(h->ysource, decStr, DD_MM_SS);
492  sexagesimal(h->inttime / 3600.0, timeStr, DD_MM_SS);
493 
494  sprintf(scanStr, "%7.2f ", h->scan);
495 
496  strcpy(dateStr, makeDate(h->utdate));
497 
498  sprintf(tbuf, "%12.12s %s INT=%s DATE: %s\\n", h->object, scanStr, timeStr, dateStr);
499 
500 // log_msg("# Header Line-1 len: %d", strlen(tbuf));
501 
502  strcpy(buf, tbuf);
503 
504  sprintf(tbuf, "%8.8s %s %s CAL= %6.1f TS= %5.0f\\n",
505  h->coordcd, raStr, decStr, h->tcal, h->stsys);
506 
507 // log_msg("# Header Line-2 len: %d", strlen(tbuf));
508 
509  strcat(buf, tbuf);
510 
511 
512  sprintf(tbuf, "FREQ= %9.2f SYN= %8.6f VEL= %8.1f DV= %5.2f %s SB=%d",
513  h->restfreq, h->synfreq/1000.0, h->velocity, h->deltax, makeFrStr(h->freqres), (int)h->sideband);
514 
515 // log_msg("# Header Line-3 len: %d", strlen(tbuf));
516 
517  strcat(buf, tbuf);
518 
519  return(0);
520 }
521 
522 
523 int makeSSSHeader(ss, buf)
524 struct SCAN_SUM_SEND *ss;
525 char *buf;
526 {
527  char tbuf[256], raStr[80], decStr[80], timeStr[80], scanStr[80], dateStr[256];
528  struct HEADER *h;
529 
530  h = &ss->head;
531 
532  sexagesimal(h->xsource / 15.0, raStr, DD_MM_SS);
533  sexagesimal(h->ysource, decStr, DD_MM_SS);
534  sexagesimal(h->inttime / 3600.0, timeStr, DD_MM_SS);
535 
536  sprintf(scanStr, "%7.2f ", h->scan);
537 
538  strcpy(dateStr, makeDate(h->utdate));
539 
540  sprintf(tbuf, "%12.12s %s INT=%s DATE: %s\\n", h->object, scanStr, timeStr, dateStr);
541 
542 // log_msg("# Header Line-1 len: %d", strlen(tbuf));
543 
544  strcpy(buf, tbuf);
545 
546  sprintf(tbuf, "%8.8s %s %s CAL= %6.1f TS= %5.0f\\n",
547  h->coordcd, raStr, decStr, h->tcal, h->stsys);
548 
549 // log_msg("# Header Line-2 len: %d", strlen(tbuf));
550 
551  strcat(buf, tbuf);
552 
553  sprintf(tbuf, "FREQ= %9.2f SYN= %8.6f VEL= %8.1f DV= %5.2f %s SB=%d",
554  h->restfreq, h->synfreq/1000.0, h->velocity, h->deltax, makeFrStr(h->freqres), (int)h->sideband);
555 
556 // log_msg("# Header Line-3 len: %d", strlen(tbuf));
557 
558  strcat(buf, tbuf);
559 
560  return(0);
561 }
562 
563 
564 int makeHistoHeader(histo, buf)
565 struct HISTO_INFO *histo;
566 char *buf;
567 {
568  char tbuf[256], raStr[80], decStr[80], timeStr[80], scanStr[80], dateStr[256];
569  struct HEADER *h;
570 
571  h = &histo->head;
572 
573  sexagesimal(h->xsource / 15.0, raStr, DD_MM_SS);
574  sexagesimal(h->ysource, decStr, DD_MM_SS);
575  sexagesimal(h->inttime / 3600.0, timeStr, DD_MM_SS);
576 
577  sprintf(scanStr, "%7.2f ", h->scan);
578 
579  strcpy(dateStr, makeDate(h->utdate));
580 
581  sprintf(tbuf, "%12.12s %s INT=%s DATE: %s\\n", h->object, scanStr, timeStr, dateStr);
582 
583 // log_msg("# Header Line-1 len: %d", strlen(tbuf));
584 
585  strcpy(buf, tbuf);
586 
587  sprintf(tbuf, "%8.8s %s %s CAL= %6.1f TS= %5.0f\\n",
588  h->coordcd, raStr, decStr, h->tcal, h->stsys);
589 
590 // log_msg("# Header Line-2 len: %d", strlen(tbuf));
591 
592  strcat(buf, tbuf);
593 
594  sprintf(tbuf, "FREQ= %9.2f SYN= %8.6f VEL= %8.1f DV= %5.2f %s SB=%d",
595  h->restfreq, h->synfreq/1000.0, h->velocity, h->deltax, makeFrStr(h->freqres), (int)h->sideband);
596 
597 // log_msg("# Header Line-3 len: %d", strlen(tbuf));
598 
599  strcat(buf, tbuf);
600 
601  return(0);
602 }
603 
604 int makeContHeader(h, a, buf)
605 struct HEADER *h;
606 struct ACCUM_RESULTS_SEND *a;
607 char *buf;
608 {
609  char tbuf[256], raStr[80], decStr[80], timeStr[80], scanStr[80], dateStr[256];
610 
611  if(a)
612  {
614  }
615  else
616  {
617  setPaperSize(0.0, 0.0, psize, fsize);
618  }
619 
620  sexagesimal(h->xsource / 15.0, raStr, DD_MM_SS);
621  sexagesimal(h->ysource, decStr, DD_MM_SS);
622  sexagesimal(h->inttime / 3600.0, timeStr, DD_MM_SS);
623 
624  if(a && (a->bscan != 0 && a->escan != 0))
625  {
626  sprintf(scanStr, "(%3d) Scans: %7.2f-%7.2f", a->scanct, a->bscan, a->escan);
627  }
628  else
629  {
630  sprintf(scanStr, "%7.2f ", h->scan);
631  }
632 
633  strcpy(dateStr, makeDate(h->utdate));
634 
635  sprintf(tbuf, "%12.12s %s INT=%s DATE: %s\\n", h->object, scanStr, timeStr, dateStr);
636 
637 // log_msg("# Header Line-1 len: %d", strlen(tbuf));
638  strcpy(buf, tbuf);
639 
640  sprintf(tbuf, "%8.8s %s %s CAL= %6.1f TS= %5.0f\\n",
641  h->coordcd, raStr, decStr, h->tcal, h->stsys);
642 // log_msg("# Header Line-2 len: %d", strlen(tbuf));
643  strcat(buf, tbuf);
644 
645  sprintf(tbuf, "FREQ= %9.2f SYN= %10.8f VEL= %8.1f SB=%d",
646  h->obsfreq, h->synfreq/1000.0, h->velocity, (int)h->sideband);
647 // log_msg("# Header Line-3 len: %d", strlen(tbuf));
648  strcat(buf, tbuf);
649 
650  return(0);
651 }
652 
653  /* Draw the plot */
654 int displayFFT(fft, how)
655 struct FFT_INFO *fft;
656 int how;
657 {
658  int i;
659  FILE *fp;
660  char datName[256], demName[256],
661  sname[256], headBuf[512], gpBuf[256];
662 
663  /* Write out datafile first */
664  sprintf(datName, "/tmp/%s/scan.dat", session);
665 
666  if((fp = fopen(datName, "w")) == NULL)
667  {
668  log_msg("Unable to open %s for writting", datName);
669 
670  return(0);
671  }
672 
673  /* Write Results */
674  for(i=0;i<fft->num;i++)
675  {
676  fprintf(fp, "%e %e\n", fft->xdata[i], fabs(fft->ydata[i]));
677  }
678 
679  fclose(fp);
680 
681  /* Now Write out gnuplot command file */
682  sprintf(demName, "/tmp/%s/scan.dem", session);
683 
684  if((fp = fopen(demName, "w")) == NULL)
685  {
686  log_msg("Unable to open %s for writting", demName);
687 
688  return(0);
689  }
690 
691  strncpy(sname, fft->head.object, 16);
692  sname[16] = '\0';
693 
694  makeFFTHeader(fft, headBuf);
695 
696  fprintf(fp, "reset\n");
697  fprintf(fp, "set size 1.0, 1.0\n");
698 
699  fprintf(fp, "set title \"%s\" font \"%s\" noenhanced\n", headBuf, fsize);
700 
701  fprintf(fp, "set xlabel \"Inverse Frequency (MHz^{-1})\" tc rgb \"red\"\n");
702  fprintf(fp, "set ylabel \" \" tc rgb \"red\"\n");
703 
704  if(fft->xset)
705  {
706  fprintf(fp, "set xrange [%e:%e]\n", fft->xb, fft->xe);
707  }
708 
709  fprintf(fp, "set grid\n");
710 
711  fprintf(fp, "set key off\n");
712 
713  fprintf(fp, "set terminal x11 enhanced %d font \"%s\" position %d,%d\n", fft->plotwin, fsize, startx, fft->plotwin*10);
714 
715  fprintf(fp, "plot '%s' with histeps lc rgb \"red\" \n", datName);
716 
717  fclose(fp);
718 
719  sprintf(gpBuf, "load \"/tmp/%s/scan.dem\"", session);
720  writeGnuplot(gpBuf, 0);
721 
722  bcopy((char *)fft, (char *)&last_fft, sizeof(last_fft));
723 
724  return(0);
725 }
726 
727 
728  /* Draw the plot */
729 int displayHisto(histo, how)
730 struct HISTO_INFO *histo;
731 int how;
732 {
733  int i;
734  FILE *fp;
735  char datName[256], demName[256], gname[256],
736  sname[256], headBuf[512], gpBuf[256];
737 
738  /* Write out datafile first */
739  sprintf(datName, "/tmp/%s/scan.dat", session);
740 
741  if((fp = fopen(datName, "w")) == NULL)
742  {
743  log_msg("Unable to open %s for writting", datName);
744 
745  return(0);
746  }
747 
748  /* Write Results */
749  for(i=0;i<histo->num;i++)
750  {
751  fprintf(fp, "%e %e\n", histo->xdata[i], histo->ydata[i]);
752  }
753 
754  fclose(fp);
755 
756  if(histo->gset)
757  {
758  /* Write out gaussian data */
759  sprintf(gname, "/tmp/%s/gauss.dat", session);
760 
761  if((fp = fopen(gname, "w")) == NULL)
762  {
763  log_msg("Unable to open %s for writting", gname);
764 
765  return(0);
766  }
767 
768  /* Write Results */
769  for(i=0;i<histo->num;i++)
770  {
771  fprintf(fp, "%e %e\n", histo->xdata[i], histo->gdata[i]);
772  }
773 
774  fclose(fp);
775  }
776 
777  /* Now Write out gnuplot command file */
778  sprintf(demName, "/tmp/%s/scan.dem", session);
779 
780  if((fp = fopen(demName, "w")) == NULL)
781  {
782  log_msg("Unable to open %s for writting", demName);
783 
784  return(0);
785  }
786 
787  strncpy(sname, histo->head.object, 16);
788  sname[16] = '\0';
789 
790  makeHistoHeader(histo, headBuf);
791 
792  fprintf(fp, "reset\n");
793  fprintf(fp, "set size 1.0, 1.0\n");
794 
795  fprintf(fp, "set title \"%s\" font \"%s\" noenhanced\n", headBuf, fsize);
796 
797  fprintf(fp, "set xlabel \"Intensity\" tc rgb \"red\"\n");
798  fprintf(fp, "set ylabel \" Quantity\" tc rgb \"red\"\n");
799 
800  fprintf(fp, "set grid\n");
801 
802  fprintf(fp, "set key off\n");
803 
804  fprintf(fp, "set terminal x11 enhanced %d font \"%s\" position %d,%d\n", histo->plotwin, fsize, startx, histo->plotwin*10);
805 
806  fprintf(fp, "plot '%s' with histeps lc rgb \"red\" ", datName);
807 
808  if(histo->gset)
809  {
810  fprintf(fp, ", '%s' with lines lc rgb \"dark-magenta\"", gname);
811  }
812 
813  fprintf(fp, "\n");
814 
815  fclose(fp);
816 
817  sprintf(gpBuf, "load \"/tmp/%s/scan.dem\"", session);
818  writeGnuplot(gpBuf, 0);
819 
820  bcopy((char *)histo, (char *)&last_histo, sizeof(last_histo));
821 
822  return(0);
823 }
824 
825 
826 int logImageInfo(image)
827 struct LP_IMAGE_INFO *image;
828 {
829  int i;
830  char bstr[4096], tbuf[256];
831 
832  log_msg("# ");
833  log_msg("# struct LP_IMAGE_INFO image");
834 
835  log_msg("# Magic = %s", image->magic);
836  log_msg("# Name = %s", image->name);
837  log_msg("# Mode = %d", image->mode);
838  log_msg("# Peak = %d", image->peakChan);
839  log_msg("# Plotwin = %d", image->plotwin);
840  log_msg("# NArray = %d", image->narray);
841  log_msg("# nSize = %d", image->nsize);
842  log_msg("# Datamin = %f", image->datamin);
843  log_msg("# Datamax = %f", image->datamax);
844 
845  log_msg("# struct ACCUM_INFO ainfo");
846 
847  log_msg("# ----> ScanCt = %d", image->ainfo.scanct);
848  log_msg("# ----> Bscan = %.2f", image->ainfo.bscan);
849  log_msg("# ----> Escan = %.2f", image->ainfo.escan);
850 
851  log_msg("# struct BASELINE_INFO binfo");
852 
853  strcpy(bstr, "Baselines = ");
854 
855  for(i=0;i<MAX_BASELINES;i++)
856  {
857  if(image->binfo.baselines[i][0] > 0)
858  {
859  sprintf(tbuf, "%d ", image->binfo.baselines[i][0]);
860  strcat(bstr, tbuf);
861  }
862 
863  if(image->binfo.baselines[i][1] > 0)
864  {
865  sprintf(tbuf, "%d ", image->binfo.baselines[i][1]);
866  strcat(bstr, tbuf);
867  }
868  }
869 
870  log_msg("# ----> DoBaseline = %d", image->binfo.doBaseLine);
871  log_msg("# ----> %s", bstr);
872  log_msg("# ----> a = %f", image->binfo.a);
873  log_msg("# ----> b = %f", image->binfo.b);
874  log_msg("# ----> rms = %f", image->binfo.rms);
875 
876  log_msg("# struct PLOT_INFO pinfo");
877 
878  log_msg("# ----> Markers = %d", image->pinfo.markers);
879  log_msg("# ----> Plotstyle = %d", image->pinfo.plotStyle);
880  log_msg("# ----> X1Mode = %d", image->pinfo.x1mode);
881  log_msg("# ----> X2Mode = %d", image->pinfo.x2mode);
882  log_msg("# ----> Gridmode = %d", image->pinfo.gridMode);
883  log_msg("# ----> Zline = %d", image->pinfo.zline);
884  log_msg("# ----> Badchshow = %d", image->pinfo.badchshow);
885  log_msg("# ----> Bmark = %d", image->pinfo.bmark);
886  log_msg("# ----> Bshow = %d", image->pinfo.bshow);
887  log_msg("# ----> Mshow = %d", image->pinfo.mshow);
888  log_msg("# ----> Bdrop = %d", image->pinfo.bdrop);
889  log_msg("# ----> Edrop = %d", image->pinfo.edrop);
890  log_msg("# ----> DoBadChan = %d", image->pinfo.dobadch);
891  log_msg("# ----> Yscale = %d", image->pinfo.yscale);
892  log_msg("# ----> Plot_noint = %d", image->pinfo.plot_noint);
893  log_msg("# ----> Bplot = %d", image->pinfo.bplot);
894  log_msg("# ----> YPlotMode = %d", image->pinfo.yplotmode);
895 
896  log_msg("# ----> PlotW = %d", image->pinfo.paperw);
897  log_msg("# ----> PlotH = %d", image->pinfo.paperh);
898 
899  log_msg("# ----> Yupper = %f", image->pinfo.yupper);
900  log_msg("# ----> Ylower = %f", image->pinfo.ylower);
901  log_msg("# ----> PlotMin = %f", image->pinfo.plotmin);
902  log_msg("# ----> PlotMax = %f", image->pinfo.plotmax);
903 
904  log_msg("# struct GAUSSIAN ginfo");
905 
906  log_msg("# ----> NFits = %d", image->ginfo.nfits);
907 
908  for(i=0;i<image->ginfo.nfits;i++)
909  {
910  log_msg("# ----> [%d] Peak = %f", i, image->ginfo.fits[i].peak);
911 
912  switch(image->ginfo.fits[i].xmode)
913  {
914  case XMODE_VEL:
915  log_msg("# ----> [%d] Peak Vel = %f", i, image->ginfo.fits[i].center);
916  break;
917 
918  case XMODE_CHAN:
919  log_msg("# ----> [%d] Peak Chan = %f", i, image->ginfo.fits[i].center);
920  break;
921 
922  case XMODE_FREQ:
923  log_msg("# ----> [%d] Peak Freq = %f", i, image->ginfo.fits[i].center);
924  break;
925  }
926 
927  log_msg("# ----> [%d] Peak HP = %f", i, image->ginfo.fits[i].hp);
928  log_msg("# ----> [%d] Sum Gauss = %f", i, image->ginfo.fits[i].sumK);
929 
930  }
931 
932  log_msg("# ");
933 
934  return(0);
935 }
936 
937 
938 int makeOSB(h)
939 struct HEADER *h;
940 {
941  if(fabs(h->openpar[0] - 54321.12345) < 0.001)
942  {
943  strcpy(osbStr, "(OSB)");
944  }
945  else
946  {
947  strcpy(osbStr, " ");
948  }
949 
950  return(0);
951 }
952 
953 
954 
955 int placeGauss(image, fp, print)
956 struct LP_IMAGE_INFO *image;
957 FILE *fp;
958 int print;
959 {
960  int i;
961  char lbuf[256], lcr[256], *font;
962  struct IMAGE_GAUSS *p;
963 
964  if(image->satActive)
965  {
966  p = &sat.gauss;
967 
968  if(!p->used)
969  {
970  return(0);
971  }
972 
973  font = "5x8";
974 
975  for(i=0;i<MAX_IMAGE_GAUSS_RESULTS;i++)
976  {
977  if(p->results[i].used)
978  {
979  sprintf(lbuf, "%s", p->results[i].string);
980  strcpy(lcr, "left");
981 
982  fprintf(fp, "set label \"%s\" at %.6f, %.6f %s tc rgb \"%s\" font \"%s\"\n",
983  lbuf,
984  p->results[i].x,
985  p->results[i].y,
986  lcr,
987  colors[p->color], font);
988 
989  }
990  }
991  }
992 
993 
994  return(0);
995 }
996 
997 
998 
999 int placeLabels(image, fp, print)
1000 struct LP_IMAGE_INFO *image;
1001 FILE *fp;
1002 int print;
1003 {
1004  int i, hlabel = 0;
1005  float y, diff;
1006  char lbuf[256], lcr[256], *font;
1007  struct IMAGE_LABELS *p;
1008 
1009  if(image->satActive)
1010  {
1011  p = &sat.labels[0];
1012 
1013  for(i=0;i<MAX_IMAGE_LABELS;i++, p++)
1014  {
1015  if(p->used)
1016  {
1017  hlabel = 0;
1018 
1019  if(strstr(p->label, "Helvet"))
1020  {
1021  font = " ";
1022  }
1023  else
1024  {
1025  font = "font \"Times-Roman,10\"";
1026  }
1027 
1028  if(p->direct == LABEL_LEFT)
1029  {
1030  sprintf(lbuf, "%s {/Symbol \256}", p->label); /* --> */
1031  strcpy(lcr, "right");
1032  }
1033  else
1034  if(p->direct == LABEL_RIGHT)
1035  {
1036  sprintf(lbuf, "{/Symbol \254} %s", p->label); /* <-- */
1037  strcpy(lcr, "left");
1038  }
1039  else
1040  if(p->direct == LABEL_DOWN)
1041  {
1042  sprintf(lbuf, "{/Symbol \254} %s", p->label); /* <-- */
1043  strcpy(lcr, "rotate by 90");
1044  }
1045  else
1046  {
1047  sprintf(lbuf, "{/Symbol \254}");
1048  strcpy(lcr, "rotate by 90");
1049  hlabel = 1;
1050  }
1051 
1052  /* Overwrite if no head */
1053  if(p->nohead == TRUE)
1054  {
1055  sprintf(lbuf, "%s", p->label);
1056  strcpy(lcr, "left");
1057  hlabel = 0;
1058  }
1059 
1060  fprintf(fp, "set label \"%s\" at %.6f, %.6f %s tc rgb \"%s\" %s\n",
1061  lbuf,
1062  p->x,
1063  p->y,
1064  lcr,
1065  colors[p->color], font);
1066 
1067  if(hlabel)
1068  {
1069 
1070  if(image->pinfo.yscale == Y_AUTO_SCALE) /* Use datamax - datamin */
1071  {
1072  diff = image->datamax - image->datamin;
1073  }
1074  else /* Use yupper - ulower */
1075  {
1076  diff = image->pinfo.yupper - image->pinfo.ylower;
1077  }
1078 
1079  y = p->y + diff * 0.04;
1080 
1081  log_msg("Placing label %s", p->label);
1082 
1083  if(strstr(p->label, "\\n")) /* Check for double high label */
1084  {
1085  log_msg("BUMPING LABEL");
1086 
1087  y += diff * 0.04; /* Raise it some more */
1088  }
1089 
1090  strcpy(lcr, "center");
1091  fprintf(fp, "set label \"%s\" at %.6f, %.6f %s tc rgb \"%s\" %s\n",
1092  p->label,
1093  p->x,
1094  y,
1095  lcr,
1096  colors[p->color], font);
1097  }
1098  }
1099  }
1100  }
1101 
1102  return(0);
1103 }
1104 
1105 
1106 int placeTBlock(image, fp, print)
1107 struct LP_IMAGE_INFO *image;
1108 FILE *fp;
1109 int print;
1110 {
1111  int i;
1112 // float y, diff;
1113  char lbuf[256], lcr[256], *font;
1114  struct TITLE_BLOCK *t;
1115  struct IMAGE_LABELS *p;
1116 
1117  t = &sat.tblock;
1118  p = &t->labels[0];
1119 
1120  if(image->satActive && t->used)
1121  {
1122  for(i=0;i<MAX_TBLOCK_LABELS;i++, p++)
1123  {
1124  if(p->used)
1125  {
1126  font = "Times-Roman,10";
1127 
1128  sprintf(lbuf, "%s", p->label);
1129  strcpy(lcr, "left");
1130 
1131  fprintf(fp, "set label \"%s\" at %.6f, %.6f %s tc rgb \"%s\" font \"%s\"\n",
1132  lbuf,
1133  p->x,
1134  p->y,
1135  lcr,
1136  colors[p->color], font);
1137 
1138  }
1139  }
1140  }
1141 
1142  return(0);
1143 }
1144 
1145 
1146 /* Mark any bad channels */
1147 int placeBadChans(image, fp)
1148 struct LP_IMAGE_INFO *image;
1149 FILE *fp;
1150 {
1151  int i;
1152  float delta;
1153 
1154  if(image->pinfo.badchshow)
1155  {
1156  delta = image->datamax - image->datamin;
1157  delta *= 0.05;
1158 
1159  for(i=1;i<(image->head.noint-1);i++)
1160  {
1161  if(isBadChan(image, i))
1162  {
1163  fprintf(fp, "set arrow from %.3f, %.3f to %.3f, %.3f front nohead lw 0.1 lc rgb \"green\"\n",
1164  image->x1data[i], image->yplot1[i] - delta,
1165  image->x1data[i], image->yplot1[i] + delta);
1166  }
1167  }
1168  log_msg("# Turning On BadChan Markers");
1169  }
1170 
1171  return(0);
1172 }
1173 
1174 
1176 struct LP_IMAGE_INFO *image;
1177 FILE *fp;
1178 {
1179  int i;
1180 
1181  if(image->pinfo.mshow && image->pinfo.markers)
1182  {
1183  for(i=image->pinfo.bdrop;i<(image->head.noint-image->pinfo.edrop);i++)
1184  {
1185  if(i > 0 && !(i%image->pinfo.markers))
1186  {
1187  fprintf(fp, "set arrow from %.3f, %.3f to %.3f, %.3f nohead lc rgb \"green\"\n",
1188  image->x1data[i], image->pinfo.plotmin,
1189  image->x1data[i], image->pinfo.plotmax);
1190  }
1191  }
1192  log_msg("# Turning On Markers");
1193  }
1194 
1195  return(0);
1196 }
1197 
1198 
1199 
1200 int placeMarkers(image, fp)
1201 struct LP_IMAGE_INFO *image;
1202 FILE *fp;
1203 {
1204  int i;
1205 
1206  if(image->satActive)
1207  {
1208  for(i=0;i<MAX_IMAGE_MARKERS;i++)
1209  {
1210  if(sat.markers[i].used)
1211  {
1212  fprintf(fp, "set arrow from %.6f, %.6f to %.6f, %.6f front nohead lw 0.3 lc rgb \"%s\"\n",
1213  sat.markers[i].x, sat.markers[i].y,
1214  sat.markers[i].x, sat.markers[i].y2,
1215  colors[sat.markers[i].color]);
1216  }
1217  }
1218  }
1219 
1220  return(0);
1221 }
1222 
1223 
1224 int placeHlines(image, fp)
1225 struct LP_IMAGE_INFO *image;
1226 FILE *fp;
1227 {
1228  int i, n;
1229 
1230  n = image->head.noint - 1;
1231  if(image->satActive)
1232  {
1233  for(i=0;i<MAX_IMAGE_HLINES;i++)
1234  {
1235  if(sat.hlines[i].used)
1236  {
1237  fprintf(fp, "set arrow from %.6f, %.6f to %.6f, %.6f front nohead lw 0.1 lc rgb \"%s\"\n",
1238  image->x1data[0], sat.hlines[i].value,
1239  image->x1data[n], sat.hlines[i].value,
1240  colors[sat.hlines[i].color]);
1241  }
1242  }
1243  }
1244 
1245  return(0);
1246 }
1247 
1248 
1249 int placeForks(image, fp, how)
1250 struct LP_IMAGE_INFO *image;
1251 FILE *fp;
1252 int how;
1253 {
1254  int i, j;
1255  float x, y, midpoint;
1256  char lbuf[256], lcr[80], *font;
1257 
1258  if(image->satActive)
1259  {
1260  for(i=0;i<MAX_IMAGE_FORKS;i++)
1261  {
1262  if(sat.forks[i].used)
1263  {
1264  /* Draw Tines */
1265  for(j=0;j<sat.forks[i].ntines;j++)
1266  {
1267  fprintf(fp, "set arrow from %.6f, %.6f to %.6f, %.6f front nohead lw 0.2 lc rgb \"%s\"\n",
1268  sat.forks[i].tines[j].x, sat.forks[i].tines[j].y,
1269  sat.forks[i].tines[j].x, sat.forks[i].crossT,
1270  colors[sat.forks[i].color]);
1271  }
1272 
1273  /* Draw Cross-Bar */
1274  fprintf(fp, "set arrow from %.6f, %.6f to %.6f, %.6f front nohead lw 0.2 lc rgb \"%s\"\n",
1275  sat.forks[i].tines[0].x, sat.forks[i].crossT,
1276  sat.forks[i].tines[sat.forks[i].ntines-1].x, sat.forks[i].crossT,
1277  colors[sat.forks[i].color]);
1278 
1279  /* Draw Fork Handle */
1280  midpoint = (sat.forks[i].tines[0].x + sat.forks[i].tines[sat.forks[i].ntines-1].x) / 2.0;
1281 
1282  fprintf(fp, "set arrow from %.6f, %.6f to %.6f, %.6f front nohead lw 0.2 lc rgb \"%s\"\n",
1283  midpoint, sat.forks[i].crossT,
1284  midpoint, sat.forks[i].topT,
1285  colors[sat.forks[i].color]);
1286 
1287  font = "Times-Roman,10";
1288 
1289  /* Draw Label */
1290  sprintf(lbuf, "%s", sat.forks[i].label);
1291  strcpy(lcr, "center");
1292 
1293 // len = strlen(lbuf);
1294  x = midpoint; /* Goes with 'center' above */
1295 
1296  /* Need more cleaver calc here */
1297  y = sat.forks[i].topT + (sat.forks[i].topT - sat.forks[i].crossT) * 0.5;
1298 
1299  fprintf(fp, "set label \"%s\" at %.6f, %.6f %s tc rgb \"%s\" font \"%s\"\n",
1300  lbuf,
1301  x,
1302  y,
1303  lcr,
1304  colors[sat.forks[i].color],
1305  font);
1306 
1307  }
1308  }
1309  }
1310 
1311  return(0);
1312 }
1313 
1314 
1315 int placeDate(image, fp)
1316 struct LP_IMAGE_INFO *image;
1317 FILE *fp;
1318 {
1319  char lcr[80];
1320 
1321  if(image->satActive)
1322  {
1323  if(sat.date.used)
1324  {
1325  strcpy(lcr, "left");
1326 
1327  log_msg("Placing Date, %s @ %f %f", sat.date.date, sat.date.x, sat.date.y);
1328 
1329  fprintf(fp, "set label \"%s\" at %.6f, %.6f %s tc rgb \"%s\" font \"fixed\"\n",
1330  sat.date.date,
1331  sat.date.x,
1332  sat.date.y,
1333  lcr,
1334  colors[sat.date.color]);
1335  }
1336  }
1337 
1338  return(0);
1339 }
1340 
1341 
1342 int getSize(s)
1343 int s;
1344 {
1345  int size = 12;
1346 
1347  if(s == 1)
1348  {
1349  size -= 8;
1350  }
1351  else
1352  if(s == 2)
1353  {
1354  size -= 6;
1355  }
1356  else
1357  if(s == 3)
1358  {
1359  size -= 4;
1360  }
1361  else
1362  if(s == 4)
1363  {
1364  size -= 2;
1365  }
1366  else
1367  if(s == 5)
1368  {
1369  ;
1370  }
1371  else
1372  if(s == 6)
1373  {
1374  size += 2;
1375  }
1376  else
1377  if(s == 7)
1378  {
1379  size += 4;
1380  }
1381  else
1382  if(s == 8)
1383  {
1384  size += 6;
1385  }
1386  else
1387  if(s == 9)
1388  {
1389  size += 8;
1390  }
1391 
1392  return(size);
1393 }
1394 
1395 
1396 
1397 int placePstamps(image, fp)
1398 struct LP_IMAGE_INFO *image;
1399 FILE *fp;
1400 {
1401  int i, k=50;
1402  char tbuf[256];
1403  struct STAMP *p;
1404 
1405  if(sat.pstamp.nstamps)
1406  {
1407  p = &sat.pstamp.stamps[0];
1408  for(i=0;i<MAX_PSTAMPS;i++,p++)
1409  {
1410  if(p->used)
1411  {
1412  fprintf(fp, "set object %d rect from %.6f,%.6f to %.6f,%.6f back fc rgb \"gray90\" fs empty\n", k+i,
1413  p->stampULx, p->stampULy,
1414  p->stampLRx, p->stampLRy);
1415 
1416  log_msg("# Drawing Postage Stamp: %d", i);
1417 
1418  fprintf(fp, "set label \"%s\" at %f, %f center tc rgb \"%s\"\n",
1419  p->label,
1420  (p->stampULx + p->stampLRx) / 2.0,
1421  p->stampULy + (p->stampULy - p->stampLRy) / 15.0,
1422  colors[p->color]);
1423 
1424  sprintf(tbuf, "%5.3fK", p->ymax);
1425 
1426  fprintf(fp, "set label \"%s\" at %f, %f left tc rgb \"%s\"\n", tbuf, p->stampLRx, p->stampULy, colors[p->color]);
1427  }
1428  }
1429  }
1430 
1431  return(0);
1432 }
1433 
1434 
1435 int placeBmark(image, fp)
1436 struct LP_IMAGE_INFO *image;
1437 FILE *fp;
1438 {
1439  int i, k;
1440  double diff, y1, y2;
1441 
1442  if(image->pinfo.bmark)
1443  {
1444  diff = (image->pinfo.plotmax - image->pinfo.plotmin) / 7.0;
1445 
1446  if(image->pinfo.bmark > 0) /* +/- about zero */
1447  {
1448  y1 = +diff * 0.2;
1449  y2 = -diff * 0.2;
1450  }
1451  else /* Place near bottom of plot */
1452  {
1453 
1454  y1 = image->pinfo.plotmin + diff * 0.2;
1455  y2 = image->pinfo.plotmin;
1456  }
1457 
1458  log_msg("Plot_interval = %f", diff);
1459  log_msg("Y1 = %f", y1);
1460  log_msg("Y2 = %f", y2);
1461 
1462  for(i=0,k=1;i<MAX_BASELINES;i++,k++)
1463  {
1464  if(image->binfo.baselines[i][0] == 0 || image->binfo.baselines[i][1] == 0)
1465  {
1466  continue;
1467  }
1468 
1469  fprintf(fp, "set object %d rect from %.6f,%.6f to %.6f,%.6f back fc rgb \"gray90\" fs empty\n", k,
1470  image->x1data[image->binfo.baselines[i][0]], y1,
1471  image->x1data[image->binfo.baselines[i][1]], y2);
1472  }
1473 
1474  log_msg("# Turning On Basline Markers");
1475  }
1476 
1477  return(0);
1478 }
1479 
1480 
1481 /*
1482  default char *papersize = "10, 7.5";
1483  */
1485 double w, h;
1486 char *psize, *fsize;
1487 {
1488  log_msg("setPaperSize(): PlotW = %f, PlotH = %f", w, h);
1489 
1490  if(w > 0.0 && h > 0.0)
1491  {
1492  sprintf(psize, "%.1f, %.1f", w, h);
1493 
1494  if(w > 24)
1495  {
1496  sprintf(fsize, "Courier,20");
1497  }
1498  else
1499  if(w > 18)
1500  {
1501  sprintf(fsize, "Courier,18");
1502  }
1503  else
1504  if(w > 14)
1505  {
1506  sprintf(fsize, "Courier,14");
1507  }
1508  else
1509  {
1510  sprintf(fsize, "Courier,12");
1511  }
1512 
1513  log_msg("setPaperSize(): Papersize: %s, Font: %s", psize, fsize);
1514 
1515  return(1);
1516  }
1517  else
1518  {
1519  strcpy(psize, papersize);
1520  strcpy(fsize, "9x15");
1521  }
1522 
1523  log_msg("setPaperSize(): Papersize: %s, Font: %s", psize, fsize);
1524 
1525  return(0);
1526 }
1527 
1528 
1529 int makeGfile(image, gname, fp)
1530 struct LP_IMAGE_INFO *image;
1531 char *gname;
1532 FILE *fp;
1533 {
1534  int i, k;
1535  double xd, a[4], dyda[4], y;
1536 
1537  sprintf(gname, "/tmp/%s/gline.dat", session);
1538 
1539  if((fp = fopen(gname, "w")) == NULL)
1540  {
1541  log_msg("Unable to open %s for writting", gname);
1542 
1543  return(1);
1544  }
1545 
1546  bzero((char *)&image->gplot[0], sizeof(float) * MAX_CHANS); /* Clear the gplot array */
1547 
1548  log_msg("# Creating G-Line-Line File");
1549 
1550  for(k=0;k<image->ginfo.nfits;k++)
1551  {
1552  a[0] = 0.0;
1553  a[1] = image->ginfo.fits[k].peak;
1554  a[2] = image->ginfo.fits[k].center;
1555  a[3] = image->ginfo.fits[k].hp;
1556 
1557  for(i=0;i<image->head.noint;i++)
1558  {
1559  xd = (double)image->x1data[i];
1560 
1561  fgauss(xd, &a[0], &y, &dyda[0]);
1562 
1563  image->gplot[i] += y;
1564  }
1565  }
1566 
1567  for(i=0;i<image->head.noint;i++)
1568  {
1569  fprintf(fp, "%e %e\n", image->x1data[i], image->gplot[i]);
1570  }
1571 
1572  fclose(fp);
1573 
1574  return(0);
1575 }
1576 
1577 
1578 int makeBfile(image, bshape, fp)
1579 struct LP_IMAGE_INFO *image;
1580 char *bshape;
1581 FILE *fp;
1582 {
1583  int i;
1584 
1585  sprintf(bshape, "/tmp/%s/bsplot.dat", session);
1586 
1587  if((fp = fopen(bshape, "w")) == NULL)
1588  {
1589  log_msg("Unable to open %s for writting", bshape);
1590 
1591  return(1);
1592  }
1593 
1594  log_msg("# Creating Baseline-Shape File");
1595 
1596  for(i=0;i<image->head.noint;i++)
1597  {
1598  fprintf(fp, "%e %e\n", image->x1data[i], image->bplot[i]);
1599  }
1600 
1601  fclose(fp);
1602 
1603  return(0);
1604 }
1605 
1606 
1607 int makeBshow(image, bname, fp)
1608 struct LP_IMAGE_INFO *image;
1609 char *bname;
1610 FILE *fp;
1611 {
1612  int i;
1613 
1614  sprintf(bname, "/tmp/%s/bline.dat", session);
1615 
1616  if((fp = fopen(bname, "w")) == NULL)
1617  {
1618  log_msg("Unable to open %s for writting", bname);
1619 
1620  return(0);
1621  }
1622 
1623  log_msg("# Creating Baseline-Line File");
1624 
1625  for(i=0;i<image->head.noint;i++)
1626  {
1627  fprintf(fp, "%e %e\n",
1628  image->x1data[i],
1629  (float)i * image->binfo.a + image->binfo.b);
1630  }
1631 
1632  fclose(fp);
1633 
1634  return(0);
1635 }
1636 
1637 
1638 int makeZline(image, zname, fp)
1639 struct LP_IMAGE_INFO *image;
1640 char *zname;
1641 FILE *fp;
1642 {
1643  int i;
1644 
1645  sprintf(zname, "/tmp/%s/zline.dat", session);
1646 
1647  if((fp = fopen(zname, "w")) == NULL)
1648  {
1649  log_msg("Unable to open %s for writting", zname);
1650 
1651  return(0);
1652  }
1653 
1654  log_msg("# Creating Z-Line File");
1655 
1656  for(i=0;i<image->head.noint;i++)
1657  {
1658  fprintf(fp, "%e 0.0\n", image->x1data[i]);
1659  }
1660 
1661  fclose(fp);
1662 
1663  return(0);
1664 }
1665 
1666 
1667 
1668 int makeHeaderAndLabels(image, fp, mode, how)
1669 struct LP_IMAGE_INFO *image;
1670 FILE *fp;
1671 int mode, how;
1672 {
1673  char sname[256], headBuf[1024];
1674 
1675  strncpy(sname, image->head.object, 16);
1676  sname[16] = '\0';
1677 
1678  makeLineHeader(image, headBuf);
1679 
1680  fprintf(fp, "reset\n");
1681  fprintf(fp, "set size 1.0, 1.0\n");
1682 
1683  setPaperSize(image->pinfo.paperw, image->pinfo.paperh, psize, fsize);
1684 
1685  if(mode == SINGLE)
1686  {
1687  fprintf(fp, "set title \"%s\" font \"%s\" noenhanced\n", headBuf, fsize);
1688  }
1689  else /* MULTI */
1690  {
1691  fprintf(fp, "set terminal x11 enhanced %d font \"%s\" position %d,%d\n", image->plotwin, psize, startx, image->plotwin*10);
1692 
1693  fprintf(fp, "set multiplot title \"%s\" layout 1,2 \n", headBuf);
1694  }
1695 
1696  if(image->xaxisotfoff == 1)
1697  {
1698  fprintf(fp, "set xlabel \"R.A. Offset (arcsec)\" tc rgb \"red\"\n");
1699  }
1700  else
1701  if(image->xaxisotfoff == 2)
1702  {
1703  fprintf(fp, "set xlabel \"Dec Offset (arcsec)\" tc rgb \"red\"\n");
1704  }
1705  else
1706  if(image->pinfo.x1mode == XMODE_FREQ)
1707  {
1708  fprintf(fp, "set xlabel \"%sFreq Offset (MHz)\" tc rgb \"red\"\n", osbStr);
1709  }
1710  else
1711  if(image->pinfo.x1mode == XMODE_VEL)
1712  {
1713  fprintf(fp, "set xlabel \"%sVelocity (%8.8s)\" tc rgb \"red\"\n", osbStr, image->head.veldef);
1714  }
1715  else
1716  if(image->pinfo.x1mode == XMODE_CHAN)
1717  {
1718  fprintf(fp, "set xlabel \"%sChannel Number\" tc rgb \"red\"\n", osbStr);
1719  }
1720 
1721  if(image->xaxisotfoff == 1)
1722  {
1723  fprintf(fp, "set x2label \"R.A. Offset (arcsec)\" tc rgb \"red\"\n");
1724  }
1725  else
1726  if(image->xaxisotfoff == 2)
1727  {
1728  fprintf(fp, "set x2label \"Dec Offset (arcsec)\" tc rgb \"red\"\n");
1729  }
1730  else
1731  if(image->pinfo.x2mode == XMODE_FREQ)
1732  {
1733  fprintf(fp, "set x2label \"%sFreq Offset (MHz)\" tc rgb \"red\"\n", osbStr);
1734  }
1735  else
1736  if(image->pinfo.x2mode == XMODE_VEL)
1737  {
1738  fprintf(fp, "set x2label \"%sVelocity (%8.8s)\" tc rgb \"red\"\n", osbStr, image->head.veldef);
1739  }
1740  else
1741  if(image->pinfo.x2mode == XMODE_CHAN)
1742  {
1743  fprintf(fp, "set x2label \"%sChannel Number\" tc rgb \"red\"\n", osbStr);
1744  }
1745 
1746  if(image->pinfo.yplotmode == LOG_PLOT)
1747  {
1748  if(!image->issmt && image->head.utdate < 2013.07) /* After new 12M telescope and removal of T / etafss */
1749  {
1750  fprintf(fp, "set ylabel \"log({/Symbol T}_{R} (K))\" tc rgb \"red\"\n");
1751  }
1752  else
1753  {
1754  fprintf(fp, "set ylabel \"log({/Symbol T}_{/Symbol A}* (K))\" tc rgb \"red\"\n");
1755  }
1756  }
1757  else
1758  {
1759  if(strlen(image->title))
1760  {
1761  fprintf(fp, "set ylabel \"%s\" tc rgb \"red\"\n", image->title);
1762  }
1763  else
1764  if(!image->issmt && image->head.utdate < 2013.07) /* After new 12M telescope and removal of T / etafss */
1765  {
1766  fprintf(fp, "set ylabel \"{/Symbol T}_{R} (K)\" tc rgb \"red\"\n");
1767  }
1768  else
1769  {
1770  fprintf(fp, "set ylabel \"{/Symbol T}_{/Symbol A}* (K)\" tc rgb \"red\"\n");
1771  }
1772  }
1773 
1774  if(image->pinfo.gridMode == GRID_MODE_NONE)
1775  {
1776  fprintf(fp, "unset grid\n");
1777  }
1778  else
1779  if(image->pinfo.gridMode == GRID_MODE_X_ONLY)
1780  {
1781  fprintf(fp, "set grid noytics xtics\n");
1782  }
1783  else
1784  if(image->pinfo.gridMode == GRID_MODE_Y_ONLY)
1785  {
1786  fprintf(fp, "set grid ytics noxtics\n");
1787  }
1788  else
1789  {
1790  fprintf(fp, "set grid\n");
1791  }
1792 
1793  fprintf(fp, "set key off\n");
1794  fprintf(fp, "set xrange [%e:%e]\n",
1795  image->x1data[image->pinfo.bdrop],
1796  image->x1data[(int)image->head.noint-1-image->pinfo.edrop]);
1797 
1798  fprintf(fp, "set x2tics out\n");
1799  fprintf(fp, "set x2range [%e:%e]\n",
1800  image->x2data[image->pinfo.bdrop],
1801  image->x2data[(int)image->head.noint-1-image->pinfo.edrop]);
1802 
1803  fprintf(fp, "set yrange [%e:%e]\n", image->pinfo.plotmin, image->pinfo.plotmax);
1804 
1805  sendPlotRange( image->x1data[image->pinfo.bdrop],
1806  image->x1data[(int)image->head.noint-1-image->pinfo.edrop],
1807  image->pinfo.plotmin,
1808  image->pinfo.plotmax);
1809 
1810  return(0);
1811 }
1812 
1813 
1814 
1815  /* Draw the plot */
1816 int linePlot_1(image, how)
1817 struct LP_IMAGE_INFO *image;
1818 int how;
1819 {
1820  int i, j, k;
1821  FILE *fp;
1822  double x, xscale, xmax, xmin, xstart;
1823  double y, yscale, ymax, ymin, yoffset;
1824  char datName[256], demName[256], bname[256], zname[256], gname[256], gpBuf[256], bshape[256];
1825  char psname[256];
1826  struct STAMP *p;
1827 
1828  makeOSB(&image->head);
1829 
1830  /* Go fill in x-axis values */
1831  computeXaxis(image, 1);
1832 
1833  /* Write out datafile first */
1834  sprintf(datName, "/tmp/%s/scan.dat", session);
1835 
1836  if((fp = fopen(datName, "w")) == NULL)
1837  {
1838  log_msg("Unable to open %s for writting", datName);
1839 
1840  return(1);
1841  }
1842 
1843  /* Write Results */
1844  for(i=0;i<image->head.noint;i++)
1845  {
1846  fprintf(fp, "%e %e\n", image->x1data[i], image->yplot1[i]);
1847  }
1848 
1849  fclose(fp);
1850 
1851  if(sat.pstamp.nstamps)
1852  {
1853  p = &sat.pstamp.stamps[0];
1854 
1855  for(j=0;j<MAX_PSTAMPS;j++, p++)
1856  {
1857  if(p->used)
1858  {
1859  sprintf(psname, "/tmp/%s/pstamp-%d.dat", session, j);
1860 
1861  if((fp = fopen(psname, "w")) == NULL)
1862  {
1863  log_msg("Unable to open %s for writting", psname);
1864 
1865  return(1);
1866  }
1867 
1868  xmax = -999999.9;
1869  xmin = 999999.9;
1870  ymax = -999999.9;
1871  ymin = 999999.9;
1872 
1873  /* find max value for this segment */
1874  for(i=0;i<image->head.noint;i++)
1875  {
1876  /* Only consider Values inside the stamp */
1877  if((image->x1data[i] >= p->linexmin && image->x1data[i] <= p->linexmax) ||
1878  (image->x1data[i] <= p->linexmin && image->x1data[i] >= p->linexmax))
1879  {
1880  if(image->x1data[i] > xmax)
1881  {
1882  xmax = image->x1data[i];
1883  }
1884 
1885  if(image->x1data[i] < xmin)
1886  {
1887  xmin = image->x1data[i];
1888  }
1889 
1890  if(image->yplot1[i] > ymax)
1891  {
1892  ymax = image->yplot1[i];
1893  }
1894 
1895  if(image->yplot1[i] < ymin)
1896  {
1897  ymin = image->yplot1[i];
1898  }
1899 
1900  }
1901  }
1902 
1903  if(p->linexmin < p->linexmax) /* Increaing xaxis */
1904  {
1905  xscale = (p->stampULx-p->stampLRx) / (xmax-xmin);
1906  xstart = p->stampLRx;
1907  }
1908  else
1909  {
1910  xscale = (p->stampULx-p->stampLRx) / (xmin-xmax);
1911  xstart = p->stampULx;
1912  }
1913 
1914  xscale *= 0.75;
1915 
1916  log_msg("(%2d): xmin = %9.3f, xmax = %9.3f, xstart = %9.3f, stampUx = %9.3f, stampLx = %9.3f, xscale = %9.3f", j,
1917  xmin, xmax, xstart, p->stampULx, p->stampLRx, xscale);
1918 
1919  yscale = (p->stampULy-p->stampLRy) / (ymax-ymin);
1920  yscale *= 0.98;
1921 
1922  if(ymin < 0.0)
1923  {
1924  yoffset = fabs(ymin);
1925  }
1926  else
1927  {
1928  yoffset = -ymin;
1929  }
1930 
1931  yoffset *= yscale;
1932 
1933  log_msg("(%2d): ymin = %9.3f, ymax = %9.3f, yoffst = %9.3f, stampUy = %9.3f, stampLy = %9.3f, yscale = %9.3f", j,
1934  ymin, ymax, yoffset, p->stampULy, p->stampLRy, yscale);
1935 
1936  p->ymax = ymax;
1937 
1938  /* Write Results */
1939  k = 0;
1940  for(i=0;i<image->head.noint;i++)
1941  {
1942  if(p->linexmin < p->linexmax) /* Increaing xaxis */
1943  {
1944  if(image->x1data[i] >= p->linexmin && image->x1data[i] <= p->linexmax)
1945  {
1946  x = xstart - (double)k * image->head.deltax * xscale;
1947 
1948  y = yoffset + p->stampLRy + (image->yplot1[i] * yscale);
1949 
1950  k++;
1951 
1952  fprintf(fp, "%e %e\n", x, y);
1953  }
1954  }
1955  else
1956  {
1957  if(image->x1data[i] >= p->linexmax && image->x1data[i] <= p->linexmin)
1958  {
1959  x = xstart + (double)k * image->head.deltax * xscale;
1960 
1961  y = yoffset + p->stampLRy + (image->yplot1[i] * yscale);
1962 
1963  k++;
1964 
1965  fprintf(fp, "%e %e\n", x, y);
1966  }
1967  }
1968  }
1969 
1970  fclose(fp);
1971  }
1972  }
1973  }
1974 
1975  /* compute min and max for ploting */
1976  find_ticks(image);
1977 
1978  if(image->pinfo.zline)
1979  {
1980  if(makeZline(image, zname, fp))
1981  {
1982  return(1);
1983  }
1984  }
1985 
1986  if(image->pinfo.bshow)
1987  {
1988  if(makeBshow(image, bname, fp))
1989  {
1990  return(1);
1991  }
1992  }
1993 
1994  if(image->pinfo.bplot)
1995  {
1996  if(makeBfile(image, bshape, fp))
1997  {
1998  return(1);
1999  }
2000  }
2001 
2002  if(image->ginfo.nfits)
2003  {
2004  if(makeGfile(image, gname, fp))
2005  {
2006  return(1);
2007  }
2008  }
2009 
2010  /* Now Write out gnuplot command file */
2011  sprintf(demName, "/tmp/%s/scan.dem", session);
2012 
2013  if((fp = fopen(demName, "w")) == NULL)
2014  {
2015  log_msg("Unable to open %s for writting", demName);
2016 
2017  return(1);
2018  }
2019 
2020  makeHeaderAndLabels(image, fp, SINGLE, how);
2021 
2022  placeBmark(image, fp);
2023  placeChanMarkers(image, fp);
2024  placeBadChans(image, fp);
2025  placeLabels(image, fp, how);
2026  placeTBlock(image, fp, how);
2027  placeGauss(image, fp, how);
2028  placeMarkers(image, fp);
2029  placeHlines(image, fp);
2030  placeForks(image, fp, how);
2031  placeDate(image, fp);
2032  placePstamps(image, fp);
2033 
2034  setPaperSize(image->pinfo.paperw, image->pinfo.paperh, psize, fsize);
2035 
2036  fprintf(fp, "set terminal x11 enhanced %d font \"%s\" position %d,%d\n", image->plotwin, fsize, startx, image->plotwin*10);
2037 
2038  fprintf(fp, "plot '%s' with %s lc rgb \"red\"", datName, plotStyleStrs[image->pinfo.plotStyle]);
2039 
2040  if(image->pinfo.bshow)
2041  {
2042  fprintf(fp, ", '%s' with lines lc rgb \"blue\"", bname);
2043  }
2044 
2045  if(image->pinfo.bplot)
2046  {
2047  fprintf(fp, ", '%s' with lines lc rgb \"magenta\"", bshape);
2048  }
2049 
2050  if(image->pinfo.zline)
2051  {
2052  fprintf(fp, ", '%s' with lines lc rgb \"blue\"", zname);
2053  }
2054 
2055  if(image->ginfo.nfits)
2056  {
2057  fprintf(fp, ", '%s' with lines lc rgb \"dark-magenta\"", gname);
2058  }
2059 
2060 
2061  if(sat.pstamp.nstamps)
2062  {
2063  p = &sat.pstamp.stamps[0];
2064 
2065  for(j=0;j<MAX_PSTAMPS;j++, p++)
2066  {
2067  if(p->used)
2068  {
2069  fprintf(fp, ", '/tmp/%s/pstamp-%d.dat' with lines lc rgb \"red\"", session, j);
2070  }
2071  }
2072  }
2073 
2074  fprintf(fp, "\n"); /* Close it out */
2075 
2076  fclose(fp);
2077 
2078  sprintf(gpBuf, "load \"/tmp/%s/scan.dem\"", session);
2079  writeGnuplot(gpBuf, image->xdelay);
2080 
2081 #ifdef SAVE_DEM_FILE
2082  /* Now save the .dem file for diagnostics */
2083 
2084  if(1)
2085  {
2086  int pid;
2087  char sysbuf[256];
2088 
2089  pid = rand();
2090  pid = pid%32767;
2091 
2092  sprintf(sysbuf, "cp /tmp/%s/scan.dem /tmp/%s/scan-%d.dem", session, session, pid);
2093 
2094  system(sysbuf);
2095  }
2096 #endif
2097 
2098  bcopy((char *)image, (char *)&last_image, sizeof(last_image));
2099 
2100  logImageInfo(image);
2101 
2102  return(0);
2103 } /* linePlot_1 */
2104 
2105 
2106 
2107  /* Draw a parallel plot */
2108 int linePlot_2(image, how)
2109 struct LP_IMAGE_INFO *image;
2110 int how;
2111 {
2112  int i;
2113  FILE *fp;
2114  char datName1[256], datName2[256], demName[256], bname[256], zname[256], gpBuf[256];
2115 
2116  makeOSB(&image->head);
2117 
2118  /* Go fill in x-axis values */
2119  computeXaxis(image, 1);
2120 
2121  /* Write out First datafile first */
2122  sprintf(datName1, "/tmp/%s/scan1.dat", session);
2123 
2124  if((fp = fopen(datName1, "w")) == NULL)
2125  {
2126  log_msg("Unable to open %s for writting", datName1);
2127 
2128  return(0);
2129  }
2130 
2131  log_msg("Writing Data file #1: %s", datName1);
2132 
2133  /* Write Results */
2134  for(i=0;i<image->head.noint;i++)
2135  {
2136  fprintf(fp, "%e %e\n", image->x1data[i], image->yplot1[i]);
2137  }
2138 
2139  fclose(fp);
2140 
2141  /* Write out Second datafile first */
2142  sprintf(datName2, "/tmp/%s/scan2.dat", session);
2143 
2144  if((fp = fopen(datName2, "w")) == NULL)
2145  {
2146  log_msg("Unable to open %s for writting", datName2);
2147 
2148  return(0);
2149  }
2150 
2151  log_msg("Writing Data file #2: %s", datName2);
2152 
2153  /* Write Results */
2154  for(i=0;i<image->head.noint;i++)
2155  {
2156  fprintf(fp, "%e %e\n", image->x1data[i], image->yplot2[i]);
2157  }
2158 
2159  fclose(fp);
2160 
2161 
2162  /* compute min and max for ploting */
2163  find_ticks(image);
2164 
2165  if(image->pinfo.zline)
2166  {
2167  if(makeZline(image, zname, fp))
2168  {
2169  return(1);
2170  }
2171  }
2172 
2173  if(image->pinfo.bshow)
2174  {
2175  if(makeBshow(image, bname, fp))
2176  {
2177  return(1);
2178  }
2179  }
2180 
2181  /* Now Write out gnuplot command file */
2182  sprintf(demName, "/tmp/%s/scan.dem", session);
2183 
2184  if((fp = fopen(demName, "w")) == NULL)
2185  {
2186  log_msg("Unable to open %s for writting", demName);
2187 
2188  return(0);
2189  }
2190 
2191  makeHeaderAndLabels(image, fp, MULTI, how);
2192 
2193  placeBmark(image, fp);
2194  placeChanMarkers(image, fp);
2195  placeBadChans(image, fp);
2196  placeLabels(image, fp, how);
2197  placeTBlock(image, fp, how);
2198  placeGauss(image, fp, how);
2199  placeMarkers(image, fp);
2200  placeHlines(image, fp);
2201  placeForks(image, fp, how);
2202  placeDate(image, fp);
2203 
2204  fprintf(fp, "plot '%s' with %s lc rgb \"red\"", datName1, plotStyleStrs[image->pinfo.plotStyle]);
2205 
2206  if(image->pinfo.bshow)
2207  {
2208  fprintf(fp, ", '%s' with lines lc rgb \"blue\"", bname);
2209  }
2210 
2211  if(image->pinfo.zline)
2212  {
2213  fprintf(fp, ", '%s' with lines lc rgb \"blue\"", zname);
2214  }
2215 
2216  fprintf(fp, "\n");
2217 
2218  fprintf(fp, "plot '%s' with %s lc rgb \"red\"", datName2, plotStyleStrs[image->pinfo.plotStyle]);
2219 
2220  if(image->pinfo.bshow)
2221  {
2222  fprintf(fp, ", '%s' with lines lc rgb \"blue\"", bname);
2223  }
2224 
2225  if(image->pinfo.zline)
2226  {
2227  fprintf(fp, ", '%s' with lines lc rgb \"blue\"", zname);
2228  }
2229 
2230  fprintf(fp, "\n");
2231 
2232  fprintf(fp, "unset multiplot\n");
2233 
2234  fclose(fp);
2235 
2236  sprintf(gpBuf, "load \"/tmp/%s/scan.dem\"", session);
2237 
2238  writeGnuplot(gpBuf, image->xdelay);
2239 
2240  bcopy((char *)image, (char *)&last_image, sizeof(last_image));
2241 
2242  logImageInfo(image);
2243 
2244  return(0);
2245 } /* linePlot_2 */
2246 
2247 
2248 
2249  /* Draw a quad plot */
2250 int linePlot_4(image, how)
2251 struct LP_IMAGE_INFO *image;
2252 int how;
2253 {
2254  int i, j;
2255  char datName1[256], datName2[256], *cp, datName3[256], datName4[256],
2256  demName[256], sname[256], headBuf[512], gpBuf[256], zname[256];
2257  float *f;
2258  FILE *fp;
2259 
2260  makeOSB(&image->head);
2261 
2262  /* Write out the datafiles */
2263  for(j=0;j<4;j++)
2264  {
2265  switch(j)
2266  {
2267  case 0: cp = datName1; f = image->yplot1; break;
2268  case 1: cp = datName2; f = image->yplot2; break;
2269  case 2: cp = datName3; f = image->yplot3; break;
2270  case 3: cp = datName4; f = image->yplot4; break;
2271  }
2272 
2273  sprintf(cp, "/tmp/%s/scan%d.dat", session, j+1);
2274 
2275  if((fp = fopen(cp, "w")) == NULL)
2276  {
2277  log_msg("Unable to open %s for writting", cp);
2278 
2279  return(0);
2280  }
2281 
2282  log_msg("Writing Data file #%d: %s", j+1, cp);
2283 
2284  /* Go fill in x-axis values using the proper values */
2285  image->head.scan = image->mhp[j].scan;
2286  image->head.restfreq = image->mhp[j].restfreq;
2287  image->head.stsys = image->mhp[j].stsys;
2288  image->head.tcal = image->mhp[j].tcal;
2289  image->head.freqres = image->mhp[j].freqres;
2290  image->head.sideband = image->mhp[j].sideband;
2291  image->head.refpt = image->mhp[j].refpt;
2292  image->head.refpt_vel = image->mhp[j].refpt_vel;
2293  image->head.deltax = image->mhp[j].deltax;
2294 
2295  computeXaxis(image, 1);
2296 
2297  for(i=0;i<image->head.noint;i++,f++)
2298  {
2299  fprintf(fp, "%e %e\n", image->x1data[i], *f);
2300  }
2301 
2302  fclose(fp);
2303  }
2304 
2305  /* Write Results */
2306 
2307  /* compute min and max for ploting */
2308  find_ticks(image);
2309 
2310  if(image->pinfo.zline)
2311  {
2312  if(makeZline(image, zname, fp))
2313  {
2314  return(1);
2315  }
2316  }
2317 
2318  /* Now Write out gnuplot command file */
2319  sprintf(demName, "/tmp/%s/scan.dem", session);
2320 
2321  if((fp = fopen(demName, "w")) == NULL)
2322  {
2323  log_msg("Unable to open %s for writting", demName);
2324 
2325  return(0);
2326  }
2327 
2328  strncpy(sname, image->head.object, 16);
2329  sname[16] = '\0';
2330 
2331  /* Put everything back */
2332  image->head.scan = image->mhp[0].scan;
2333  image->head.restfreq = image->mhp[0].restfreq;
2334  image->head.stsys = image->mhp[0].stsys;
2335  image->head.tcal = image->mhp[0].tcal;
2336  image->head.freqres = image->mhp[0].freqres;
2337  image->head.sideband = image->mhp[0].sideband;
2338  image->head.refpt = image->mhp[0].refpt;
2339  image->head.refpt_vel = image->mhp[0].refpt_vel;
2340  image->head.deltax = image->mhp[0].deltax;
2341 
2342  makeLineHeader(image, headBuf);
2343 
2344  fprintf(fp, "reset\n");
2345  fprintf(fp, "set size 1.0, 1.0\n");
2346 
2347  fprintf(fp, "set terminal x11 enhanced %d font \"%s\" position %d,%d\n", image->plotwin, fsize, startx, image->plotwin*10);
2348 
2349  fprintf(fp, "set multiplot title \"%s\" layout 2,2\n", headBuf);
2350 // fprintf(fp, "set multiplot title \"%s\" noenhanced layout 2,2\n", headBuf);
2351 // fprintf(fp, "set title \"%s\" font \"%s\"\n", headBuf, fsize);
2352 
2353  if(image->pinfo.x1mode == XMODE_FREQ)
2354  {
2355  fprintf(fp, "set xlabel \"%sFreq Offset (MHz)\" tc rgb \"red\"\n", osbStr);
2356  }
2357  else
2358  if(image->pinfo.x1mode == XMODE_VEL)
2359  {
2360  fprintf(fp, "set xlabel \"%sVelocity (%8.8s)\" tc rgb \"red\"\n", osbStr, image->head.veldef);
2361  }
2362  else
2363  if(image->pinfo.x1mode == XMODE_CHAN)
2364  {
2365  fprintf(fp, "set xlabel \"%sChannel Number\" tc rgb \"red\"\n", osbStr);
2366  }
2367 
2368  if(image->pinfo.x2mode == XMODE_FREQ)
2369  {
2370  fprintf(fp, "set x2label \"%sFreq Offset (MHz)\" tc rgb \"red\"\n", osbStr);
2371  }
2372  else
2373  if(image->pinfo.x2mode == XMODE_VEL)
2374  {
2375  fprintf(fp, "set x2label \"%sVelocity (%8.8s)\" tc rgb \"red\"\n", osbStr, image->head.veldef);
2376  }
2377  else
2378  if(image->pinfo.x2mode == XMODE_CHAN)
2379  {
2380  fprintf(fp, "set x2label \"%sChannel Number\" tc rgb \"red\"\n", osbStr);
2381  }
2382 
2383  if(image->pinfo.yplotmode == LOG_PLOT)
2384  {
2385  fprintf(fp, "set ylabel \"log(Temp (K))\" tc rgb \"red\"\n");
2386  }
2387  else
2388  {
2389  fprintf(fp, "set ylabel \"Temp (K)\" tc rgb \"red\"\n");
2390  }
2391 
2392  if(image->pinfo.gridMode == GRID_MODE_NONE)
2393  {
2394  fprintf(fp, "unset grid\n");
2395  }
2396  else
2397  if(image->pinfo.gridMode == GRID_MODE_X_ONLY)
2398  {
2399  fprintf(fp, "set grid noytics xtics\n");
2400  }
2401  else
2402  if(image->pinfo.gridMode == GRID_MODE_Y_ONLY)
2403  {
2404  fprintf(fp, "set grid ytics noxtics\n");
2405  }
2406  else
2407  {
2408  fprintf(fp, "set grid\n");
2409  }
2410 
2411  fprintf(fp, "set key off\n");
2412  fprintf(fp, "set x2tics out\n");
2413  fprintf(fp, "set yrange [%e:%e]\n", image->pinfo.plotmin, image->pinfo.plotmax);
2414 
2415  sendPlotRange( image->x1data[image->pinfo.bdrop],
2416  image->x1data[(int)image->head.noint-1-image->pinfo.edrop],
2417  image->pinfo.plotmin,
2418  image->pinfo.plotmax);
2419 
2420  placeBmark(image, fp);
2421 
2422  for(j=0;j<4;j++)
2423  {
2424  switch(j)
2425  {
2426  case 0: cp = datName1; break;
2427  case 1: cp = datName2; break;
2428  case 2: cp = datName3; break;
2429  case 3: cp = datName4; break;
2430  }
2431 
2432  /* Go fill in x-axis values using the proper values */
2433  image->head.scan = image->mhp[j].scan;
2434  image->head.restfreq = image->mhp[j].restfreq;
2435  image->head.stsys = image->mhp[j].stsys;
2436  image->head.tcal = image->mhp[j].tcal;
2437  image->head.freqres = image->mhp[j].freqres;
2438  image->head.sideband = image->mhp[j].sideband;
2439  image->head.refpt = image->mhp[j].refpt;
2440  image->head.refpt_vel = image->mhp[j].refpt_vel;
2441  image->head.deltax = image->mhp[j].deltax;
2442 
2443  computeXaxis(image, 1);
2444 
2445  fprintf(fp, "set xrange [%e:%e]\n",
2446  image->x1data[image->pinfo.bdrop],
2447  image->x1data[(int)image->head.noint-1-image->pinfo.edrop]);
2448 
2449  fprintf(fp, "set x2range [%e:%e]\n",
2450  image->x2data[image->pinfo.bdrop],
2451  image->x2data[(int)image->head.noint-1-image->pinfo.edrop]);
2452 
2453  fprintf(fp, "plot '%s' with %s lc rgb \"red\"", cp, plotStyleStrs[image->pinfo.plotStyle]);
2454 
2455  if(image->pinfo.zline)
2456  {
2457  fprintf(fp, ", '%s' with lines lc rgb \"blue\"", zname);
2458  }
2459 
2460  fprintf(fp, "\n");
2461  }
2462 
2463  fprintf(fp, "unset multiplot\n");
2464 
2465  fclose(fp);
2466 
2467  sprintf(gpBuf, "load \"/tmp/%s/scan.dem\"", session);
2468  writeGnuplot(gpBuf, image->xdelay);
2469 
2470  bcopy((char *)image, (char *)&last_image, sizeof(last_image));
2471 
2472  logImageInfo(image);
2473 
2474  return(0);
2475 } /* linePlot_4 */
2476 
2477 
2478  /* Draw a Cross Correlation plot */
2479 int plotXcor(image, how)
2480 struct LP_IMAGE_INFO *image;
2481 int how;
2482 {
2483  int i, j, dlen;
2484  FILE *fp;
2485  char datName1[256], datName2[256], *cp,
2486  datName3[256], datName4[256],
2487  demName[256], sname[256], headBuf[512], gpBuf[256];
2488  float *f;
2489 
2490  dlen = image->nsize / sizeof(float);
2491 
2492  /* Write out the datafiles */
2493  for(j=0;j<4;j++)
2494  {
2495  switch(j)
2496  {
2497  case 0: cp = datName1; f = image->yplot1; break;
2498  case 1: cp = datName2; f = image->yplot2; break;
2499  case 2: cp = datName3; f = image->yplot3; break;
2500  case 3: cp = datName4; f = image->yplot4; break;
2501  }
2502 
2503  sprintf(cp, "/tmp/%s/scan%d.dat", session, j+1);
2504 
2505  if((fp = fopen(cp, "w")) == NULL)
2506  {
2507  log_msg("Unable to open %s for writting", cp);
2508 
2509  return(0);
2510  }
2511 
2512  log_msg("Writing Data file #%d: %s; len = %d", j+1, cp, dlen);
2513 
2514  /* Write Results; NOTE Xaxis is in the bplot array */
2515  for(i=0;i<dlen;i++,f++)
2516  {
2517  if(image->bplot[i] != 0.0)
2518  {
2519  fprintf(fp, "%e %e\n", image->bplot[i], *f);
2520  }
2521  }
2522 
2523  fclose(fp);
2524  }
2525 
2526  /* compute min and max for ploting */
2527  find_ticks(image);
2528 
2529  /* Now Write out gnuplot command file */
2530  sprintf(demName, "/tmp/%s/scan.dem", session);
2531 
2532  if((fp = fopen(demName, "w")) == NULL)
2533  {
2534  log_msg("Unable to open %s for writting", demName);
2535 
2536  return(0);
2537  }
2538 
2539  strncpy(sname, image->head.object, 16);
2540  sname[16] = '\0';
2541 
2542  makeLineHeader(image, headBuf);
2543 
2544  fprintf(fp, "reset\n");
2545  fprintf(fp, "set size 1.0, 1.0\n");
2546 
2547  fprintf(fp, "set terminal x11 enhanced %d font \"%s\" position %d,%d\n", image->plotwin, fsize, startx, image->plotwin*10);
2548 
2549  fprintf(fp, "set title \"%s\"font \"%s\" noenhanced\n", headBuf, fsize);
2550 
2551  fprintf(fp, "set xlabel \"IF #1 (Kelvins)\" tc rgb \"red\"\n");
2552  fprintf(fp, "set ylabel \"IF #2 (Kelvins)\" tc rgb \"red\"\n");
2553 
2554  fprintf(fp, "set key off\n");
2555 
2556  for(j=0;j<4;j++)
2557  {
2558  switch(j)
2559  {
2560  case 0:
2561  fprintf(fp, "plot '%s' with %s lc rgb \"red\", ", datName1, "lp");
2562  break;
2563  case 1:
2564  fprintf(fp, "'%s' with %s lc rgb \"red\", ", datName2, "lines");
2565  break;
2566  case 2:
2567  fprintf(fp, "'%s' with %s lc rgb \"red\", ", datName3, "lines");
2568  break;
2569  case 3:
2570  fprintf(fp, "'%s' with %s lc rgb \"red\"\n", datName4, "lines");
2571  break;
2572  }
2573  }
2574 
2575  fclose(fp);
2576 
2577  sprintf(gpBuf, "load \"/tmp/%s/scan.dem\"", session);
2578  writeGnuplot(gpBuf, image->xdelay);
2579 
2580  bcopy((char *)image, (char *)&last_image, sizeof(last_image));
2581 
2582  logImageInfo(image);
2583 
2584  return(0);
2585 }
2586 
2587 
2588 int find_ticks(image)
2589 struct LP_IMAGE_INFO *image;
2590 {
2591  double min, max, tickint, diff;
2592  double log10();
2593  int i, ticks;
2594  int order;
2595  float *f;
2596 
2597  f = image->yplot1;
2598 
2599  max = -1.0e127; /* there are probably standard macros, but this works */
2600  min = 9.99e127;
2601 
2602  for(i=image->pinfo.bdrop;i<image->head.noint-image->pinfo.edrop;i++) /* compute min and max */
2603  {
2604  if(f[i] > max)
2605  {
2606  max = f[i];
2607  image->peakChan = i;
2608  }
2609  if(f[i] < min)
2610  {
2611  min = f[i];
2612  }
2613  }
2614 
2615  image->datamin = min;
2616  image->datamax = max;
2617 
2618  log_msg("# Max = %f, Min = %f", image->datamax, image->datamin);
2619 
2620  diff = max-min;
2621  if(diff > 0.0)
2622  {
2623  order = (int)rint(log10(diff))-1;
2624  }
2625  else
2626  {
2627  image->pinfo.plotmax = max;
2628  image->pinfo.plotmin = min;
2629 
2630  if(image->pinfo.yscale == Y_FIXED_SCALE)
2631  {
2632  image->pinfo.plotmin = image->pinfo.ylower;
2633  image->pinfo.plotmax = image->pinfo.yupper;
2634  }
2635 
2636  plot_interval = (image->pinfo.plotmax - image->pinfo.plotmin) / 8.0;
2637 
2638  return(1);
2639  }
2640 
2641  tickint = pow(10.0, (double)order);
2642  ticks = (int)rint(diff/tickint);
2643 
2644  log_msg("# Tickint = %f, ticks = %d", tickint, ticks);
2645 
2646  if( ticks >= 10 )
2647  {
2648  if( ticks >= 20 )
2649  {
2650  ticks /= 5;
2651  tickint *= 5.0;
2652  }
2653  else
2654  {
2655  ticks /= 2;
2656  tickint *= 2.0;
2657  }
2658  }
2659  else
2660  if( ticks < 3 )
2661  {
2662  ticks *= 5;
2663  tickint /= 5.0;
2664  }
2665 
2666  log_msg("# Tickint = %f, ticks = %d", tickint, ticks);
2667 
2668  image->pinfo.plotmax = ((int)floor((max + tickint) / tickint)) * tickint;
2669  image->pinfo.plotmin = image->pinfo.plotmax - (ticks +2) * tickint;
2670 
2671  plot_interval = tickint;
2672 
2673  log_msg("# Max = %f, Min = %f", image->pinfo.plotmax, image->pinfo.plotmin);
2674 
2675  if(image->pinfo.yscale == Y_FIXED_SCALE)
2676  {
2677  image->pinfo.plotmin = image->pinfo.ylower;
2678  image->pinfo.plotmax = image->pinfo.yupper;
2679  }
2680 
2681  return(ticks);
2682 }
2683 
2684 
2685 int fluxPlot(flux, how)
2686 struct FLUX_INFO *flux;
2687 int how;
2688 {
2689  int i;
2690  char datName[256], demName[256], gpBuf[256];
2691  FILE *fp;
2692 
2693  /* Write out datafile first */
2694  sprintf(datName, "/tmp/%s/scan.dat", session);
2695 
2696  if((fp = fopen(datName, "w")) == NULL)
2697  {
2698  log_msg("Unable to open %s for writting", datName);
2699 
2700  return(0);
2701  }
2702 
2703  for(i=0;i<flux->num;i++)
2704  {
2705  if(flux->values[i].freq > 0.0)
2706  {
2707  fprintf(fp, "%e %e\n", flux->values[i].freq, flux->values[i].tb);
2708  }
2709  }
2710 
2711  fclose(fp);
2712 
2713 
2714  /* Now Write out gnuplot command file */
2715  sprintf(demName, "/tmp/%s/scan.dem", session);
2716 
2717  if((fp = fopen(demName, "w")) == NULL)
2718  {
2719  log_msg("Unable to open %s for writting", demName);
2720 
2721  return(0);
2722  }
2723 
2724  fprintf(fp, "reset\n");
2725  fprintf(fp, "set size 1.0, 1.0\n");
2726  fprintf(fp, "set title \"%s Brightness Temperature\"\n", flux->name);
2727  fprintf(fp, "set xlabel \"Freq (GHz)\"\n");
2728  fprintf(fp, "set ylabel \"Brightness Temperature (K)\"\n");
2729 
2730  if(flux->manFreq)
2731  {
2732  fprintf(fp, "set xrange [%e:%e]\n", flux->bfreq, flux->efreq);
2733  }
2734  else
2735  {
2736  fprintf(fp, "set xrange [65:840]\n");
2737  }
2738 
2739  fprintf(fp, "set grid\n");
2740 
2741  fprintf(fp, "set terminal x11 enhanced %d font \"%s\" position %d,%d\n", flux->plotwin, fsize, startx, flux->plotwin*10);
2742 
2743  fprintf(fp, "plot \'%s' with lines\n", datName);
2744 
2745  fclose(fp);
2746 
2747  sprintf(gpBuf, "load \"/tmp/%s/scan.dem\"", session);
2748  writeGnuplot(gpBuf, 0);
2749 
2750  return(0);
2751 }
2752 
2753 
2754 int accumPlot(a, how)
2755 struct ACCUM_RESULTS_SEND *a;
2756 int how;
2757 {
2758  int i, j, k, l, n, first=1, wh, bfound=0;
2759  char datName[256], demName[256], xlabel[256],
2760  ylabel[256], gpBuf[256], sbname[80], headBuf[512], coeffStr[256], tbuf[256];
2761  float x, y, *f, yy, center;
2762  float xmin=9999.0, xmax = -99999, ymin = 99999.0, ymax = -99999.0, ydiff;
2763  FILE *fp;
2764 
2765  /* Write out datafile first */
2766 
2767  for(j=0;j<MAX_IFS;j++)
2768  {
2769  if(a->ar[j].num)
2770  {
2771  if(a->issmt)
2772  {
2773  strcpy(sbname, mg_sideband[j]);
2774  }
2775  else
2776  {
2777  strcpy(sbname, kp_sideband[j]);
2778  }
2779 
2780  sprintf(datName, "/tmp/%s/%s.dat", session, sbname);
2781 
2782  if((fp = fopen(datName, "w")) == NULL)
2783  {
2784  log_msg("Unable to open %s for writting", datName);
2785 
2786  return(0);
2787  }
2788 
2789  for(i=0;i<a->ar[j].num;i++)
2790  {
2791  x = 0.0;
2792  y = 0.0;
2793 
2794  switch(a->plot_select1)
2795  {
2796  case ACCUM_PLOT_X_EL:
2797  x = a->ar[j].results[i].el;
2798  sprintf(xlabel, "El (Degrees)");
2799  break;
2800 
2801  case ACCUM_PLOT_X_UT:
2802  x = a->ar[j].results[i].ut;
2803  sprintf(xlabel, "Time (UT)");
2804  break;
2805 
2806  case ACCUM_PLOT_X_SCAN:
2807  x = a->ar[j].results[i].scan;
2808  sprintf(xlabel, "Scan Number");
2809  break;
2810 
2811  default:
2812  x = (double)i;
2813  sprintf(xlabel, "Sample Number");
2814  break;
2815  }
2816 
2817  if(x < xmin)
2818  {
2819  xmin = x;
2820  }
2821 
2822  if(x > xmax)
2823  {
2824  xmax = x;
2825  }
2826 
2827 
2828  switch(a->plot_select2)
2829  {
2830  case ACCUM_PLOT_Y_SIG:
2831  y = a->ar[j].results[i].sig;
2832  sprintf(ylabel, "Signal Temperature (K)");
2833  break;
2834 
2835  case ACCUM_PLOT_Y_SKY:
2836  y = a->ar[j].results[i].sky;
2837  sprintf(ylabel, "Sky Temperature (K)");
2838  break;
2839 
2840  case ACCUM_PLOT_Y_SMROR:
2841  y = a->ar[j].results[i].smror;
2842  sprintf(ylabel, "Ratio: (Sig - Sky) / Sky");
2843  break;
2844 
2845  case ACCUM_PLOT_Y_TSYS:
2846  y = a->ar[j].results[i].tsys;
2847  sprintf(ylabel, "System Temperature (K)");
2848  break;
2849 
2850  case ACCUM_PLOT_Y_TASTAR:
2851  y = a->ar[j].results[i].tastar;
2852  sprintf(ylabel, "Temperature (Ta*) (K)");
2853  break;
2854 
2855  case ACCUM_PLOT_Y_TR:
2856  y = a->ar[j].results[i].tr;
2857  sprintf(ylabel, "Temperature (Tr) (K)");
2858  break;
2859 
2860  case ACCUM_PLOT_Y_JANSKY:
2861  y = a->ar[j].results[i].janskys;
2862  sprintf(ylabel, "Janskys");
2863  break;
2864 
2865  case ACCUM_PLOT_Y_NORMAL:
2866  y = a->ar[j].results[i].normalized;
2867  sprintf(ylabel, "Normalized");
2868  break;
2869 
2870  default:
2871  y = a->ar[j].results[i].janskys;
2872  sprintf(ylabel, "Janskys");
2873  break;
2874  }
2875 
2876  if(y < ymin)
2877  {
2878  ymin = y;
2879  }
2880 
2881  if(y > ymax)
2882  {
2883  ymax = y;
2884  }
2885 
2886  fprintf(fp, "%e %e\n", x, y);
2887  }
2888 
2889  fclose(fp);
2890  }
2891  }
2892 
2893  if(a->plotExpected)
2894  {
2895  for(j=2;j<4;j++) /* Only plot last two */
2896  {
2897  sprintf(datName, "/tmp/%s/expected-%s.dat", session, sideband[j]);
2898 
2899  if((fp = fopen(datName, "w")) == NULL)
2900  {
2901  log_msg("Unable to open %s for writting", datName);
2902 
2903  return(0);
2904  }
2905 
2906  n = a->ar[j].num;
2907 
2908  for(i=0;i<n;i++)
2909  {
2910  switch(a->plot_select1)
2911  {
2912  case ACCUM_PLOT_X_EL:
2913  x = a->ar[j].results[i].el;
2914  break;
2915 
2916  case ACCUM_PLOT_X_UT:
2917  x = a->ar[j].results[i].ut;
2918  break;
2919 
2920  case ACCUM_PLOT_X_SCAN:
2921  x = a->ar[j].results[i].scan;
2922  break;
2923 
2924  default:
2925  x = (double)i;
2926  break;
2927  }
2928 
2929  switch(a->plot_select2)
2930  {
2931  case ACCUM_PLOT_Y_SIG:
2932  y = 0.0;
2933  break;
2934 
2935  case ACCUM_PLOT_Y_SKY:
2936  y = 0.0;
2937  break;
2938 
2939  case ACCUM_PLOT_Y_SMROR:
2940  y = 0.0;
2941  break;
2942 
2943  case ACCUM_PLOT_Y_TSYS:
2944  y = 0.0;
2945  break;
2946 
2947  case ACCUM_PLOT_Y_TASTAR:
2948  y = a->expectedTaStar[j];
2949  break;
2950 
2951  case ACCUM_PLOT_Y_TR:
2952  y = a->expectedTr[j];
2953  break;
2954 
2955  case ACCUM_PLOT_Y_JANSKY:
2956  y = a->expectedJanskys[j];
2957  break;
2958 
2959  case ACCUM_PLOT_Y_NORMAL:
2960  y = 1.0;
2961  break;
2962 
2963  default:
2964  y = a->expectedTaStar[j];
2965  break;
2966  }
2967 
2968  fprintf(fp, "%e %e\n", x, y);
2969  }
2970 
2971  fclose(fp);
2972  }
2973  }
2974 
2975  if(a->bplot) /* Are there fitted curves to plot */
2976  {
2977  for(j=0;j<MAX_IFS;j++)
2978  {
2979  n = a->ar[j].num;
2980 
2981  if(n)
2982  {
2983  if(a->issmt)
2984  {
2985  sprintf(datName, "/tmp/%s/bplot-%s.dat", session, mg_sideband[j]);
2986  }
2987  else
2988  {
2989  sprintf(datName, "/tmp/%s/bplot-%s.dat", session, kp_sideband[j]);
2990  }
2991 
2992  if((fp = fopen(datName, "w")) == NULL)
2993  {
2994  log_msg("Unable to open %s for writting", datName);
2995 
2996  return(0);
2997  }
2998 
2999 
3000  f = &a->fitcurve[j][0];
3001 
3002  for(i=0;i<n;i++,f++)
3003  {
3004  switch(a->plot_select1)
3005  {
3006  case ACCUM_PLOT_X_EL:
3007  x = a->ar[j].results[i].el;
3008  break;
3009 
3010  case ACCUM_PLOT_X_UT:
3011  x = a->ar[j].results[i].ut;
3012  break;
3013 
3014  case ACCUM_PLOT_X_SCAN:
3015  x = a->ar[j].results[i].scan;
3016  break;
3017 
3018  default:
3019  x = (double)i;
3020  break;
3021  }
3022 
3023  y = *f;
3024 
3025  fprintf(fp, "%e %e\n", x, y);
3026  }
3027 
3028  fclose(fp);
3029 
3030  bfound++;
3031  }
3032  }
3033  }
3034 
3035  /* Now Write out gnuplot command file */
3036  sprintf(demName, "/tmp/%s/scan.dem", session);
3037 
3038  if((fp = fopen(demName, "w")) == NULL)
3039  {
3040  log_msg("Unable to open %s for writting", demName);
3041 
3042  return(0);
3043  }
3044 
3045  log_msg("Valid = 0x%x", a->valid);
3046 
3047  wh = -1;
3048  if(a->valid)
3049  {
3050  for(k=0;k<MAX_IFS;k++)
3051  {
3052  if(a->valid & 1<<k)
3053  {
3054  wh = k;
3055  break;
3056  }
3057  }
3058 
3059  if(wh == -1)
3060  {
3061  log_msg("No Valid Headers");
3062  return(0);
3063  }
3064 
3065  makeContHeader(&a->head[wh], a, headBuf);
3066  }
3067  else
3068  {
3069  log_msg("No Valid Headers");
3070  return(0);
3071  }
3072 
3073 
3074  fprintf(fp, "reset\n");
3075  fprintf(fp, "set size 1.0, 1.0\n");
3076 
3077  fprintf(fp, "set title \"%s\" font \"%s\" noenhanced\n", headBuf, fsize);
3078 
3079  fprintf(fp, "set xlabel \"%s\"\n", xlabel);
3080  fprintf(fp, "set ylabel \"%s\"\n", ylabel);
3081  fprintf(fp, "set pointsize 2\n");
3082  fprintf(fp, "set grid\n");
3083 
3084  /* Place labels */
3085  if(a->ncoeff)
3086  {
3087  ydiff = (ymax - ymin) / 10.0;
3088  center = (xmax - xmin);
3089  yy = ymin + ydiff*5.0;
3090  l = 0;
3091 
3092  for(j=0;j<MAX_IFS;j++)
3093  {
3094  if(a->ar[j].num) /* Valid data here ? */
3095  {
3096  if(a->issmt)
3097  {
3098  sprintf(coeffStr, "Coeff for %s ", mg_sideband[j]);
3099  }
3100  else
3101  {
3102  sprintf(coeffStr, "Coeff for %s ", kp_sideband[j]);
3103  }
3104 
3105  for(k=0;k<a->ncoeff+1;k++)
3106  {
3107  sprintf(tbuf, "a%d=%.3e ", k, a->coeff[j][k]);
3108  strcat(coeffStr, tbuf);
3109  }
3110 
3111  log_msg("accumPlot(): %s", coeffStr);
3112 
3113  fprintf(fp, "set label %d \"%s\" at %f, %f tc lt %d font \"fixed\"\n", j+11, coeffStr, center * 0.60, yy, 3+l);
3114 
3115  yy -= ydiff;
3116 
3117  l++;
3118 
3119  }
3120  }
3121  }
3122 
3123  fprintf(fp, "set terminal x11 enhanced %d font \"%s\" position %d,%d\n", a->plotwin, fsize, startx, a->plotwin*10);
3124 
3125  fprintf(fp, "plot ");
3126 
3127  if(a->plotExpected)
3128  {
3129  for(j=2;j<MAX_IFS;j++)
3130  {
3131  if(!first)
3132  {
3133  fprintf(fp, ", ");
3134  }
3135 
3136  sprintf(datName, "/tmp/%s/expected-%s.dat", session, sideband[j]);
3137 
3138  fprintf(fp, "\'%s' with lp", datName);
3139 
3140  first = 0;
3141  }
3142  }
3143 
3144  for(j=0;j<MAX_IFS;j++)
3145  {
3146  if(a->ar[j].num)
3147  {
3148  if(!first)
3149  {
3150  fprintf(fp, ", ");
3151  }
3152 
3153  if(a->issmt)
3154  {
3155  strcpy(sbname, mg_sideband[j]);
3156  }
3157  else
3158  {
3159  strcpy(sbname, kp_sideband[j]);
3160  }
3161 
3162  sprintf(datName, "/tmp/%s/%s.dat", session, sbname);
3163 
3164  fprintf(fp, "\'%s' with lp", datName);
3165 
3166  first = 0;
3167  }
3168  }
3169 
3170  if(a->bplot && bfound)
3171  {
3172  for(j=0;j<MAX_IFS;j++)
3173  {
3174  if(a->ar[j].num)
3175  {
3176  if(!first)
3177  {
3178  fprintf(fp, ", ");
3179  }
3180 
3181  if(a->issmt)
3182  {
3183  strcpy(sbname, mg_sideband[j]);
3184  }
3185  else
3186  {
3187  strcpy(sbname, kp_sideband[j]);
3188  }
3189 
3190  sprintf(datName, "/tmp/%s/bplot-%s.dat", session, sbname);
3191 
3192  fprintf(fp, "\'%s' with lines", datName);
3193 
3194  first = 0;
3195  }
3196  }
3197  }
3198 
3199  fprintf(fp, "\n");
3200 
3201  fclose(fp);
3202 
3203  sprintf(gpBuf, "load \"/tmp/%s/scan.dem\"", session);
3204  writeGnuplot(gpBuf, 0);
3205 
3206  return(0);
3207 }
3208 
3209 
3210 
3211 int contPlot(cp, how)
3212 struct CONTINUUM_PLAIN *cp;
3213 int how;
3214 {
3215  int i;
3216  char datName[256], demName[256], gpBuf[256], headBuf[512],
3217  gname[256], zname[256];
3218  FILE *fp;
3219  double max = -99999999.0, yy = 0.0;
3220 
3221  log_msg("Inside contPlot(): %d Data Points", cp->dlen);
3222 
3223  /* Write out datafile first */
3224  sprintf(datName, "/tmp/%s/scan.dat", session);
3225 
3226  if((fp = fopen(datName, "w")) == NULL)
3227  {
3228  log_msg("Unable to open %s for writting", datName);
3229  return(1);
3230  }
3231 
3232  for(i=0;i<cp->dlen;i++)
3233  {
3234  fprintf(fp, "%e %e\n", cp->xdata[i], cp->ydata[i]);
3235  }
3236 
3237  log_msg("Got %d datapoints & %d Gaussian points", cp->dlen, cp->ngauss);
3238 
3239  fclose(fp);
3240 
3241  if(cp->zline)
3242  {
3243  /* Write out datafile first */
3244  sprintf(zname, "/tmp/%s/zline.dat", session);
3245 
3246  if((fp = fopen(zname, "w")) == NULL)
3247  {
3248  log_msg("Unable to open %s for writting", zname);
3249  return(1);
3250  }
3251 
3252  for(i=0;i<cp->dlen;i++)
3253  {
3254  fprintf(fp, "%e %e\n", cp->xdata[i], 0.0);
3255  }
3256 
3257  fclose(fp);
3258  }
3259 
3260  if(cp->ngauss) /* Write out gaussian data */
3261  {
3262  log_msg("Inside contPlot(): %d Gaussian Data Points", cp->ngauss);
3263 
3264  sprintf(gname, "/tmp/%s/gauss.dat", session);
3265 
3266  if((fp = fopen(gname, "w")) == NULL)
3267  {
3268  st_fail("Unable to open %s for writting", gname);
3269 
3270  return(0);
3271  }
3272 
3273  for(i=0;i<cp->ngauss;i++)
3274  {
3275  fprintf(fp, "%e %e\n", cp->xdata[i], cp->gdata[i]);
3276 
3277  if(cp->gdata[i] > max)
3278  {
3279  max = cp->gdata[i];
3280  }
3281  }
3282 
3283  fclose(fp);
3284  }
3285 
3286  /* Now Write out gnuplot command file */
3287  sprintf(demName, "/tmp/%s/scan.dem", session);
3288 
3289  if((fp = fopen(demName, "w")) == NULL)
3290  {
3291  log_msg("Unable to open %s for writting", demName);
3292 
3293  return(1);
3294  }
3295 
3296  makeContHeader(&cp->head, NULL, headBuf);
3297 
3298  fprintf(fp, "reset\n");
3299  fprintf(fp, "set size 1.0, 1.0\n");
3300 
3301  fprintf(fp, "set title \"%s\" font \"%s\" noenhanced\n", headBuf, fsize);
3302 
3303  fprintf(fp, "set xlabel \"%s\"\n", cp->xlabel);
3304  fprintf(fp, "set ylabel \"%s\"\n", cp->ylabel);
3305 
3306  if(cp->gridMode == GRID_MODE_NONE)
3307  {
3308  fprintf(fp, "unset grid\n");
3309  }
3310  else
3311  if(cp->gridMode == GRID_MODE_X_ONLY)
3312  {
3313  fprintf(fp, "set grid noytics xtics\n");
3314  }
3315  else
3316  if(cp->gridMode == GRID_MODE_Y_ONLY)
3317  {
3318  fprintf(fp, "set grid ytics noxtics\n");
3319  }
3320  else
3321  {
3322  fprintf(fp, "set grid\n");
3323  }
3324 
3325  fprintf(fp, "set key off\n");
3326 
3327  fprintf(fp, "set xrange [%e:%e]\n", cp->xdata[0], cp->xdata[cp->dlen-1]);
3328 
3329  if(cp->autoscale == Y_FIXED_SCALE)
3330  {
3331  fprintf(fp, "set yrange [%e:%e]\n", cp->yplotmin, cp->yplotmax);
3332  }
3333 
3334  fprintf(fp, "set terminal x11 enhanced %d font \"%s\" position %d,%d\n", cp->plotwin, fsize, startx, cp->plotwin*10);
3335 
3336  if(cp->ngauss && cp->yaxis_scale != LOG_PLOT) /* Labels are useless for LOG_PLOT */
3337  {
3338  yy = 0.97;
3339  for(i=0;i<MAX_GLABELS;i++)
3340  {
3341  if(strlen(cp->glabels[i]) > 2)
3342  {
3343  fprintf(fp, "set label %d \"%s\" at %f, %f tc rgb \"blue\" font \"fixed\"\n", i+11, cp->glabels[i], cp->xdata[1], max * yy);
3344 
3345  yy -= 0.05;
3346  }
3347  }
3348  }
3349 
3350  if(cp->yaxis_scale == LOG_PLOT)
3351  {
3352  fprintf(fp, "plot '%s' with lp lc rgb \"red\"", datName);
3353  }
3354  else
3355  {
3356  fprintf(fp, "plot '%s' with %s lc rgb \"red\"", datName, plotStyleStrs[cp->plotStyle]);
3357  }
3358 
3359  if(cp->ngauss)
3360  {
3361  fprintf(fp, ", '%s' with lines lc rgb \"blue\"", gname);
3362  }
3363 
3364  if(cp->zline)
3365  {
3366  fprintf(fp, ", '%s' with lines lc rgb \"blue\"", zname);
3367  }
3368 
3369  fprintf(fp, "\n");
3370 
3371  fclose(fp);
3372 
3373  sprintf(gpBuf, "load \"/tmp/%s/scan.dem\"", session);
3374  writeGnuplot(gpBuf, 0);
3375 
3376  return(0);
3377 }
3378 
3379 
3380 int plotFluxHistory(f, how)
3381 struct FLUX_HISTORY *f;
3382 int how;
3383 {
3384  int i;
3385  FILE *fp;
3386  char datName[256], demName[256], gpBuf[256];
3387 
3388  log_msg("Plotting ALMA Calibrator %s", f->name);
3389 
3390  /* Write out datafile first */
3391  sprintf(datName, "/tmp/%s/scan.dat", session);
3392 
3393  if((fp = fopen(datName, "w")) == NULL)
3394  {
3395  st_fail("Unable to open %s for writting", datName);
3396 
3397  return(0);
3398  }
3399 
3400  for(i=0;i<f->num;i++)
3401  {
3402  fprintf(fp, "%s %e\n", f->history[i].date, f->history[i].flux);
3403  }
3404 
3405  fclose(fp);
3406 
3407  /* Now Write out gnuplot command file */
3408  sprintf(demName, "/tmp/%s/scan.dem", session);
3409 
3410  if((fp = fopen(demName, "w")) == NULL)
3411  {
3412  st_fail("Unable to open %s for writting", demName);
3413 
3414  return(0);
3415  }
3416 
3417  fprintf(fp, "reset\n");
3418  fprintf(fp, "set size 1.0, 1.0\n");
3419 
3420  fprintf(fp, "set title \"%s Flux Density History\"\n", f->name);
3421  fprintf(fp, "set xlabel \"Date\"\n");
3422  fprintf(fp, "set xdata time\n");
3423  fprintf(fp, "set timefmt \"%%Y/%%m/%%d\"\n");
3424  fprintf(fp, "set ylabel \"Flux Density (Jk)\"\n");
3425  fprintf(fp, "set grid\n");
3426  fprintf(fp, "set pointsize 2\n");
3427  fprintf(fp, "set key off\n");
3428 
3429  fprintf(fp, "set terminal x11 enhanced %d font \"%s\" position %d,%d\n", f->plotwin, fsize, startx, f->plotwin*10);
3430 
3431  fprintf(fp, "plot \'%s' using 1:2 with lp\n", datName);
3432 
3433  fclose(fp);
3434 
3435  log_msg("Plotting ALMA Calibrator %s", f->name);
3436  log_msg("Plotting %d ALMA calibrator measurements", f->num);
3437  log_msg("Plotting data: %s", f->datestr);
3438 
3439  sprintf(gpBuf, "load \"/tmp/%s/scan.dem\"", session);
3440  writeGnuplot(gpBuf, 0);
3441 
3442  return(0);
3443 }
3444 
3445 
3446 int plotFocusHistory(f, how)
3447 struct FOCUS_HISTORY_SEND *f;
3448 int how;
3449 {
3450  int i, j, l;
3451  FILE *fp;
3452  char datName[256], bplotName[256], demName[256], gpBuf[256];
3453  double xx, yy, err, ymin=999999.9, ymax=-999999.9, ydiff;
3454 
3455  log_msg("plotFocusHistory(): Plotting Focus History");
3456 
3457  /* Write out datafile first */
3458  sprintf(datName, "/tmp/%s/focus-results.dat", session);
3459 
3460  if((fp = fopen(datName, "w")) == NULL)
3461  {
3462  st_fail("plotFocusHistory(): Unable to open %s for writting", datName);
3463 
3464  return(0);
3465  }
3466 
3467  for(i=0;i<f->nfocs;i++)
3468  {
3469  yy = f->focuses[i].fit;
3470  err = f->focuses[i].cnterr;
3471 
3472  if(f->sort_order == FOCUS_SORTED_TAMB)
3473  {
3474  xx = f->focuses[i].tamb;
3475  }
3476  else
3477  {
3478  xx = f->focuses[i].el;
3479  }
3480 
3481  switch(f->scale)
3482  {
3483  case FOCUS_SCALE_ADD:
3484  yy += f->focuses[i].scaling;
3485  break;
3486 
3487  case FOCUS_SCALE_SUB:
3488  yy -= f->focuses[i].scaling;
3489  break;
3490 
3491  case FOCUS_SCALE_MULTI:
3492  yy *= f->focuses[i].scaling;
3493  err *= f->focuses[i].scaling;
3494  break;
3495 
3496  case FOCUS_SCALE_DIVIDE:
3497  yy /= f->focuses[i].scaling;
3498  err /= f->focuses[i].scaling;
3499  break;
3500 
3501  case FOCUS_SCALE_NONE: /* Do nothing */
3502  break;
3503  }
3504 
3505  fprintf(fp, "%e %e %e\n", xx, yy, err);
3506 
3507  if(yy < ymin)
3508  {
3509  ymin = yy;
3510  }
3511 
3512  if(yy > ymax)
3513  {
3514  ymax = yy;
3515  }
3516  }
3517 
3518  fclose(fp);
3519 
3520  if(f->bfit)
3521  {
3522  sprintf(bplotName, "/tmp/%s/focus-fit.dat", session);
3523 
3524  if((fp = fopen(bplotName, "w")) == NULL)
3525  {
3526  st_fail("plotFocusHistory(): Unable to open %s for writting", bplotName);
3527 
3528  return(0);
3529  }
3530 
3531  for(i=0;i<f->nfocs;i++)
3532  {
3533  yy = f->bplot[i];
3534 
3535  if(f->sort_order == FOCUS_SORTED_TAMB)
3536  {
3537  xx = f->focuses[i].tamb;
3538  }
3539  else
3540  {
3541  xx = f->focuses[i].el;
3542  }
3543 
3544  switch(f->scale)
3545  {
3546  case FOCUS_SCALE_ADD:
3547  yy += f->focuses[i].scaling;
3548  break;
3549 
3550  case FOCUS_SCALE_SUB:
3551  yy -= f->focuses[i].scaling;
3552  break;
3553 
3554  case FOCUS_SCALE_MULTI:
3555  yy *= f->focuses[i].scaling;
3556  break;
3557 
3558  case FOCUS_SCALE_DIVIDE:
3559  yy /= f->focuses[i].scaling;
3560  break;
3561 
3562  case FOCUS_SCALE_NONE: /* Do nothing */
3563  break;
3564  }
3565 
3566  fprintf(fp, "%e %e\n", xx, yy);
3567  }
3568 
3569  fclose(fp);
3570  }
3571 
3572  /* Now Write out gnuplot command file */
3573  sprintf(demName, "/tmp/%s/focus.dem", session);
3574 
3575  if((fp = fopen(demName, "w")) == NULL)
3576  {
3577  st_fail("plotFocusHistory(): Unable to open %s for writting", demName);
3578 
3579  return(0);
3580  }
3581 
3582  fprintf(fp, "reset\n");
3583  fprintf(fp, "set size 1.0, 1.0\n");
3584 
3585  fprintf(fp, "set title \"%s Focus History\"\n", focus_axis_str[f->axis]);
3586 
3587  if(f->sort_order == FOCUS_SORTED_TAMB)
3588  {
3589  fprintf(fp, "set xlabel \"Tamb\"\n");
3590  }
3591  else
3592  {
3593  fprintf(fp, "set xlabel \"El\"\n");
3594  }
3595 
3596 // fprintf(fp, "set xrange [0:90]\n");
3597 
3598  fprintf(fp, "set ylabel \"Focus Fit (mm)\"\n");
3599  fprintf(fp, "set grid\n");
3600 
3601  /* Place labels, if any */
3602  ydiff = ( ymax - ymin) / 20.0;
3603 
3604  if(f->xlabel != 0.0)
3605  {
3606  xx = f->xlabel;
3607  }
3608  else
3609  {
3610  xx = 25.0;
3611  }
3612 
3613  if(f->ylabel != 0.0)
3614  {
3615  yy = f->ylabel;
3616  }
3617  else
3618  {
3619  yy = ymax;
3620  }
3621 
3622  l = 0;
3623 
3624  for(j=0;j<MAX_FOCUS_LABELS;j++)
3625  {
3626  if(strlen(f->blabels[j]) > 2)
3627  {
3628  /* These most likely is for focus curves so assume the plot os 0 - 90 degrees */
3629  fprintf(fp, "set label %d \"%s\" at %f, %f tc lt %d font \"6x10\"\n", j+11, f->blabels[j], xx, yy, 3/*+l*/);
3630 
3631  yy -= ydiff;
3632 
3633  l++;
3634  }
3635  }
3636 
3637 // fprintf(fp, "set key off\n");
3638 
3639  fprintf(fp, "set terminal x11 enhanced %d font \"%s\" position %d,%d\n", f->plotwin, fsize, startx, f->plotwin*10);
3640 
3641  if(f->lines)
3642  {
3643  fprintf(fp, "plot \'%s' with yerrorlines", datName);
3644  }
3645  else
3646  {
3647  fprintf(fp, "plot \'%s' with yerror", datName);
3648  }
3649 
3650  if(f->bfit)
3651  {
3652  fprintf(fp, ", \'%s' with lines", bplotName);
3653  }
3654 
3655  fprintf(fp, "\n"); /* Close it out */
3656 
3657  fclose(fp);
3658 
3659  log_msg("Plotting Focus History");
3660  log_msg("Plotting %d Focus measurements", f->nfocs);
3661 
3662  if(f->bfit)
3663  {
3664  log_msg("And, Plotting %d bplot values", f->nfocs);
3665  }
3666 
3667  sprintf(gpBuf, "load \"%s\"", demName);
3668  writeGnuplot(gpBuf, 0);
3669 
3670  return(0);
3671 }
3672 
3673 
3674 int contSptipPlot(cs, how)
3675 struct CONTINUUM_SPTIP *cs;
3676 int how;
3677 {
3678  int chan, i, k;
3679  float *f;
3680  float sinel[11], delta_airmass, upper_airmass, lower_airmass, gfit0;
3681  char fitName[2][256], datName[2][256], demName[256], gpBuf[256], sname[80];
3682  char headBuf[512], *ftype;
3683  FILE *fp;
3684 
3685  log_msg("Inside contSptipPlot()");
3686 
3687  /* does the header contain the stop and start airmasses ??? */
3688  /* if so, use them */
3689  if(cs->head1.sptip_start > 0.0 && cs->head1.sptip_stop > 0.0)
3690  {
3691  lower_airmass = 1.0 / sin(cs->head1.sptip_start * DEG_TO_RAD);
3692  upper_airmass = 1.0 / sin(cs->head1.sptip_stop * DEG_TO_RAD);
3693 
3694  delta_airmass = (upper_airmass - lower_airmass) / 5.0;
3695 
3696  sinel[0] = sinel[10] = lower_airmass;
3697  sinel[1] = sinel[ 9] = lower_airmass + delta_airmass * 1.0;
3698  sinel[2] = sinel[ 8] = lower_airmass + delta_airmass * 2.0;
3699  sinel[3] = sinel[ 7] = lower_airmass + delta_airmass * 3.0;
3700  sinel[4] = sinel[ 6] = lower_airmass + delta_airmass * 4.0;
3701  sinel[5] = upper_airmass;
3702 
3703  }
3704  else /* if not, it's an old sptip and use the default */
3705  {
3706  for(k=0;k<11;k++)
3707  {
3708  sinel[k] = sinEl[k];
3709  }
3710  }
3711 
3712  for(chan=0;chan<2;chan++)
3713  {
3714  /* Write out datafile first */
3715  sprintf(datName[chan], "/tmp/%s/scan%d.dat", session, chan);
3716 
3717  if((fp = fopen(datName[chan], "w")) == NULL)
3718  {
3719  log_msg("Unable to open %s for writting", datName[chan]);
3720 
3721  return(0);
3722  }
3723 
3724  if(chan == 0)
3725  {
3726  f = &cs->ydata1[0];
3727  }
3728  else
3729  {
3730  f = &cs->ydata2[0];
3731  }
3732 
3733  for(i=0;i<cs->dlen;i++,f++)
3734  {
3735  fprintf(fp, "%2d %e\n", i+1, *f);
3736  }
3737 
3738  fclose(fp);
3739 
3740  log_msg("Wrote Channel %d datafile %s", chan+1, datName[chan]);
3741 
3742  /* Write out fit file second */
3743  sprintf(fitName[chan], "/tmp/%s/tipfit%d.dat", session, chan);
3744 
3745  if((fp = fopen(fitName[chan], "w")) == NULL)
3746  {
3747  log_msg("Unable to open %s for writting", fitName[chan]);
3748 
3749  return(0);
3750  }
3751 
3752  for(i=0;i<cs->dlen;i++)
3753  {
3754  gfit0 = cs->results[chan].a + ( -cs->results[chan].b * sinel[i]);
3755  fprintf(fp, "%2d %e\n", i+1, gfit0);
3756  }
3757 
3758  fclose(fp);
3759 
3760  log_msg("Wrote Channel %d fitfile %s", chan+1, fitName[chan]);
3761 
3762  /* Now Write out gnuplot command file */
3763  sprintf(demName, "/tmp/%s/scan.dem", session);
3764 
3765  if(chan == 0)
3766  {
3767  ftype = "w";
3768  }
3769  else
3770  {
3771  ftype = "a";
3772  }
3773 
3774  if((fp = fopen(demName, ftype)) == NULL)
3775  {
3776  log_msg("Unable to open %s for writting", demName);
3777 
3778  return(0);
3779  }
3780 
3781  strncpy(sname, cs->head1.object, 16);
3782  sname[16] = '\0';
3783 
3784 // TOM
3785 
3786  if(chan == 0)
3787  {
3788  makeContHeader(&cs->head1, NULL, headBuf);
3789 
3790  fprintf(fp, "reset\n");
3791  fprintf(fp, "set size 1.0, 1.0\n");
3792  fprintf(fp, "set title \"%s\" font \"%s\" noenhanced\n", headBuf, fsize);
3793 
3794  fprintf(fp, "set terminal x11 enhanced %d font \"%s\" position %d,%d\n", cs->plotwin, fsize, startx, cs->plotwin*10);
3795 
3796  fprintf(fp, "set size 1.0, 1.0\n");
3797  fprintf(fp, "set origin 0.0, 0.0\n");
3798  fprintf(fp, "set grid\n");
3799  fprintf(fp, "unset key\n");
3800  fprintf(fp, "set multiplot\n");
3801  fprintf(fp, "set xlabel \"Sample Number\"\n");
3802  fprintf(fp, "set ylabel \"Intensity\"\n");
3803  fprintf(fp, "set xrange [1:11]\n");
3804  fprintf(fp, "set size 1.0, 0.5\n");
3805  fprintf(fp, "set origin 0.0,0.5\n");
3806 
3807  fprintf(fp, "set label 11 \"Tau0 %.3f\" at 5.5, %.3f tc rgb \"red\" font \"fixed\"\n",
3808  cs->results[chan].tau0, cs->ydata1[2]);
3809  fprintf(fp, "set label 12 \"Siga +/- %.3f\" at 5.5, %.3f tc rgb \"red\" font \"fixed\"\n",
3810  cs->results[chan].sigmaA, cs->ydata1[1]);
3811  fprintf(fp, "set label 13 \"Sigb +/- %.3f\" at 5.5, %.3f tc rgb \"red\" font \"fixed\"\n",
3812  cs->results[chan].sigmaB, cs->ydata1[0]);
3813  }
3814  else
3815  {
3816  makeContHeader(&cs->head2, NULL, headBuf);
3817 
3818  fprintf(fp, "set title \"%s\" font \"%s\" noenhanced\n", headBuf, fsize);
3819  fprintf(fp, "set origin 0.0,0.0\n");
3820 
3821  fprintf(fp, "set label 11 \"Tau0 %.3f\" at 5.5, %.3f tc rgb \"red\" font \"fixed\"\n",
3822  cs->results[chan].tau0, cs->ydata2[2]);
3823  fprintf(fp, "set label 12 \"Siga +/- %.3f\" at 5.5, %.3f tc rgb \"red\" font \"fixed\"\n",
3824  cs->results[chan].sigmaA, cs->ydata2[1]);
3825  fprintf(fp, "set label 13 \"Sigb +/- %.3f\" at 5.5, %.3f tc rgb \"red\" font \"fixed\"\n",
3826  cs->results[chan].sigmaB, cs->ydata2[0]);
3827  }
3828 
3829 
3830 
3831  fprintf(fp, "plot \'%s' with histeps, \'%s' with lines\n", datName[chan], fitName[chan]);
3832 
3833  if(chan == 1)
3834  {
3835  fprintf(fp, "unset multiplot\n");
3836  }
3837 
3838  log_msg("Wrote %s in %s mode", demName, ftype);
3839 
3840  fclose(fp);
3841  }
3842 
3843  sprintf(gpBuf, "load \"/tmp/%s/scan.dem\"", session);
3844  writeGnuplot(gpBuf, 0);
3845 
3846  return(0);
3847 }
3848 
3849 
3850 int displayObjHistory(obj, how)
3851 struct OBJECT *obj;
3852 int how;
3853 {
3854  int i, j, k, l, used[MAX_IFS], first=1, ymode, xmode, lines;
3855  float x1, y1, s1, n1, xx, yy;
3856  float xmin=9999.0, xmax = -99999, ymin = 99999.0, ymax = -99999.0, ydiff;
3857  float dataymin = 99999.0, dataymax = -99999.0, dataydiff;
3858  double effSigma;
3859  char datName[256], demName[256], gpBuf[256];
3860  char coeffStr[256], tbuf[256];
3861  FILE *fp;
3862 
3863  log_msg("Plotting Continuum Source %s", obj->source);
3864  log_msg("Object %s has %d Measurements", obj->source, obj->numMeas);
3865 
3866  setPaperSize(obj->paperw, obj->paperh, psize, fsize); /* Borrow the last_image for now */
3867 
3868  xmode = obj->xmode;
3869  ymode = obj->ymode;
3870  lines = obj->lines;
3871 
3872  /* Write out datafile first */
3873  for(j=0;j<MAX_IFS;j++)
3874  {
3875  if(obj->measurements[0].results[j].measuredFlux > 0.0)
3876  {
3877  used[j] = 1;
3878  sprintf(datName, "/tmp/%s/flux-%s.dat", session, mg_sideband[j]);
3879 
3880  if((fp = fopen(datName, "w")) == NULL)
3881  {
3882  st_fail("Unable to open %s for writting", datName);
3883 
3884  return(0);
3885  }
3886 
3887  n1 = obj->normalize[j];
3888 
3889  for(i=0;i<obj->numMeas;i++)
3890  {
3891  if(ymode == MODE_EFF)
3892  {
3893  effSigma = obj->measurements[i].results[j].measuredTmbSigma /
3894  obj->measurements[i].results[j].measuredTmb;
3895 
3896  effSigma *= obj->measurements[i].results[j].beam_eff;
3897 
3898  if(xmode == MODE_NUM)
3899  {
3900  x1 = (float)(i+1);
3901  }
3902  else
3903  {
3904  x1 = obj->measurements[i].averageEl;
3905  }
3906 
3907  y1 = obj->measurements[i].results[j].beam_eff;
3908  s1 = effSigma;
3909 
3910  if(n1 != 0.0) /* Has it been normalized */
3911  {
3912  y1 *= n1;
3913  s1 *= n1;
3914  }
3915 
3916  if(y1 > dataymax)
3917  {
3918  dataymax = y1;
3919  }
3920 
3921  if(y1 < dataymin)
3922  {
3923  dataymin = y1;
3924  }
3925 
3926  fprintf(fp, "%e %e %e\n", x1, y1, s1);
3927  }
3928  else
3929  if(ymode == MODE_APP)
3930  {
3931  effSigma = obj->measurements[i].results[j].measuredFluxSigma /
3932  obj->measurements[i].results[j].measuredFlux;
3933 
3934  effSigma *= obj->measurements[i].results[j].app_eff;
3935 
3936  if(xmode == MODE_NUM)
3937  {
3938  x1 = (float)(i+1);
3939  }
3940  else
3941  {
3942  x1 = obj->measurements[i].averageEl;
3943  }
3944 
3945  y1 = obj->measurements[i].results[j].app_eff;
3946  s1 = effSigma;
3947 
3948  if(n1 != 0.0) /* Has it been normalized */
3949  {
3950  y1 *= n1;
3951  s1 *= n1;
3952  }
3953 
3954  if(y1 > dataymax)
3955  {
3956  dataymax = y1;
3957  }
3958 
3959  if(y1 < dataymin)
3960  {
3961  dataymin = y1;
3962  }
3963 
3964  fprintf(fp, "%e %e %e\n", x1, y1, s1);
3965  }
3966  else
3967  if(ymode == MODE_JANSKYS)
3968  {
3969  if(xmode == MODE_NUM)
3970  {
3971  x1 = (float)(i+1);
3972  }
3973  else
3974  {
3975  x1 = obj->measurements[i].averageEl;
3976  }
3977 
3978  y1 = obj->measurements[i].results[j].measuredFlux;
3979  s1 = obj->measurements[i].results[j].measuredFluxSigma;
3980 
3981  if(n1 != 0.0) /* Has it been normalized */
3982  {
3983  y1 *= n1;
3984  s1 *= n1;
3985  }
3986 
3987  if(y1 > dataymax)
3988  {
3989  dataymax = y1;
3990  }
3991 
3992  if(y1 < dataymin)
3993  {
3994  dataymin = y1;
3995  }
3996 
3997  fprintf(fp, "%e %e %e\n", x1, y1, s1);
3998  }
3999  else
4000  if(ymode == MODE_TMB)
4001  {
4002 
4003  if(xmode == MODE_NUM)
4004  {
4005  x1 = (float)(i+1);
4006  }
4007  else
4008  {
4009  x1 = obj->measurements[i].averageEl;
4010  }
4011 
4012  y1 = obj->measurements[i].results[j].measuredTmb;
4013  s1 = obj->measurements[i].results[j].measuredTmbSigma;
4014 
4015  if(n1 != 0.0) /* Has it been normalized */
4016  {
4017  y1 *= n1;
4018  s1 *= n1;
4019  }
4020 
4021  if(y1 > dataymax)
4022  {
4023  dataymax = y1;
4024  }
4025 
4026  if(y1 < dataymin)
4027  {
4028  dataymin = y1;
4029  }
4030 
4031  fprintf(fp, "%e %e %e\n", x1, y1, s1);
4032  }
4033  }
4034 
4035  fclose(fp);
4036  }
4037  else
4038  {
4039  used[j] = 0;
4040  }
4041  }
4042 
4043  /* Are there baselines curves to plot ?? */
4044  if(obj->bplot)
4045  {
4046  for(j=0;j<MAX_IFS;j++)
4047  {
4048  if(used[j])
4049  {
4050  sprintf(datName, "/tmp/%s/bplot-%s.dat", session, mg_sideband[j]);
4051 
4052  if((fp = fopen(datName, "w")) == NULL)
4053  {
4054  st_fail("Unable to open %s for writting", datName);
4055 
4056  return(0);
4057  }
4058 
4059  n1 = obj->normalize[j];
4060 
4061  if(obj->fit_scaled) /* linuxpops has already scaled the fit curves */
4062  {
4063  n1 = 0.0;
4064  }
4065 
4066  for(i=0;i<obj->numMeas;i++)
4067  {
4068  if(xmode == MODE_NUM)
4069  {
4070  x1 = (float)(i+1);
4071  }
4072  else
4073  {
4074  x1 = obj->measurements[i].averageEl;
4075  }
4076 
4077  if(x1 < xmin)
4078  {
4079  xmin = y1;
4080  }
4081 
4082  if(x1 > xmax)
4083  {
4084  xmax = x1;
4085  }
4086 
4087 
4088  y1 = obj->fitcurves[j][i];
4089 
4090  if(n1 != 0.0)
4091  {
4092  y1 *= n1;
4093  }
4094 
4095  if(y1 < ymin)
4096  {
4097  ymin = y1;
4098  }
4099 
4100  if(y1 > ymax)
4101  {
4102  ymax = y1;
4103  }
4104 
4105  fprintf(fp, "%e %e\n", x1, y1);
4106  }
4107 
4108  fclose(fp);
4109  }
4110  }
4111  }
4112 
4113  /* Now Write out gnuplot command file */
4114  sprintf(demName, "/tmp/%s/scan.dem", session);
4115 
4116  if((fp = fopen(demName, "w")) == NULL)
4117  {
4118  st_fail("Unable to open %s for writting", demName);
4119 
4120  return(0);
4121  }
4122 
4123  fprintf(fp, "reset\n");
4124  fprintf(fp, "set size 1.0, 1.0\n");
4125 
4126  if(obj->fit_scaled) /* This is normalized data */
4127  {
4128  fprintf(fp, "set title \"%s Beam Efficiency History\"\n", obj->source);
4129  fprintf(fp, "set ylabel \"Normalized\"\n");
4130  }
4131  else
4132  if(ymode == MODE_EFF)
4133  {
4134  fprintf(fp, "set title \"%s Beam Efficiency History\"\n", obj->source);
4135  fprintf(fp, "set ylabel \"Beam Efficiency\"\n");
4136  }
4137  else
4138  if(ymode == MODE_APP)
4139  {
4140  fprintf(fp, "set title \"%s Apperature Efficiency History\"\n", obj->source);
4141  fprintf(fp, "set ylabel \"Apperture Efficiency\"\n");
4142  }
4143  else
4144  if(ymode == MODE_JANSKYS)
4145  {
4146  fprintf(fp, "set title \"%s Flux Density History\"\n", obj->source);
4147  fprintf(fp, "set ylabel \"Flux Density (Jk)\"\n");
4148  }
4149  else
4150  if(ymode == MODE_TMB)
4151  {
4152  fprintf(fp, "set title \"%s Main Beam Temperature History\"\n", obj->source);
4153  fprintf(fp, "set ylabel \"Tmb (K)\"\n");
4154  }
4155 
4156  if(xmode == MODE_NUM)
4157  {
4158  fprintf(fp, "set xlabel \"Measurement\"\n");
4159  fprintf(fp, "set xrange [0:%d]\n", obj->numMeas+1);
4160  }
4161  else
4162  {
4163  fprintf(fp, "set xlabel \"Elevation\"\n");
4164 
4165  if(obj->xmin || obj->xmax)
4166  {
4167  fprintf(fp, "set xrange [%.2f:%.2f]\n", obj->xmin, obj->xmax);
4168  }
4169  else
4170  {
4171  fprintf(fp, "set xrange [%.2f:%.2f]\n", 0.0, 90.0);
4172  }
4173  }
4174 
4175  /* Place labels */
4176  if(obj->ncoeff)
4177  {
4178  dataydiff = (dataymax - dataymin) / 10.0;
4179  ydiff = ( ymax - ymin) / 10.0;
4180 
4181  if(dataydiff > ydiff)
4182  {
4183  ydiff = dataydiff;
4184  }
4185 
4186  if(obj->xlabel != 0.0)
4187  {
4188  xx = obj->xlabel;
4189  }
4190  else
4191  {
4192  xx = 20.0;
4193  }
4194 
4195  if(obj->ylabel != 0.0)
4196  {
4197  yy = obj->ylabel;
4198  }
4199  else
4200  {
4201  yy = ymin;
4202  }
4203 
4204  l = 0;
4205 
4206  for(j=0;j<MAX_IFS;j++)
4207  {
4208  if(used[j]) /* Valid data here ? */
4209  {
4210  sprintf(coeffStr, "Coeff for %s ", mg_sideband[j]);
4211 
4212  for(k=0;k<obj->ncoeff+1;k++)
4213  {
4214  sprintf(tbuf, "a%d=%.3e ", k, obj->coeff[j][k]);
4215  strcat(coeffStr, tbuf);
4216  }
4217 
4218  log_msg("accumPlot(): %s", coeffStr);
4219 
4220  /* These most likely is for el gain curves so assume the plot os 0 - 90 degrees */
4221  fprintf(fp, "set label %d \"%s\" at %f, %f tc lt %d font \"6x10\"\n", j+11, coeffStr, xx, yy, 3+l);
4222 
4223  yy -= ydiff;
4224 
4225  l++;
4226 
4227  }
4228  }
4229  }
4230 
4231  fprintf(fp, "set grid\n");
4232  fprintf(fp, "set pointsize 2\n");
4233 
4234  fprintf(fp, "set terminal x11 enhanced %d font \"%s\" position %d,%d\n", obj->plotwin, fsize, startx, obj->plotwin*10);
4235 
4236  first = 1;
4237  for(j=0;j<MAX_IFS;j++)
4238  {
4239  if(used[j])
4240  {
4241  sprintf(datName, "/tmp/%s/flux-%s.dat", session, mg_sideband[j]);
4242 
4243  if(first)
4244  {
4245  if(lines == MODE_LINES)
4246  {
4247  fprintf(fp, "plot \'%s' with yerrorlines", datName);
4248  }
4249  else
4250  {
4251  fprintf(fp, "plot \'%s' with yerror", datName);
4252  }
4253 
4254  first = 0;
4255  }
4256  else
4257  {
4258  if(lines == MODE_LINES)
4259  {
4260  fprintf(fp, ", \'%s' with yerrorlines", datName);
4261  }
4262  else
4263  {
4264  fprintf(fp, ", \'%s' with yerror", datName);
4265  }
4266  }
4267  }
4268  }
4269 
4270  if(obj->bplot)
4271  {
4272  for(j=0;j<MAX_IFS;j++)
4273  {
4274  if(used[j])
4275  {
4276  fprintf(fp, ", '/tmp/%s/bplot-%s.dat' with lines", session, mg_sideband[j]);
4277  }
4278  }
4279  }
4280 
4281  fprintf(fp, "\n"); /* Finish the line */
4282 
4283  fclose(fp);
4284 
4285  sprintf(gpBuf, "load \"/tmp/%s/scan.dem\"", session);
4286  writeGnuplot(gpBuf, 0);
4287 
4288  return(0);
4289 }
4290 
4291 
4292 int displayTsys(tsys, how)
4293 struct TSYS_SEND *tsys;
4294 int how;
4295 {
4296  int i, indx, el;
4297  FILE *fp;
4298  char fname[256], demName[256], gpBuf[256], title[256];
4299 
4300  /* Write out datafile first */
4301 
4302  for(i=0;i<tsys->num;i++)
4303  {
4304  if(!tsys->freqs[i].used)
4305  {
4306  continue;
4307  }
4308 
4309  sprintf(fname, "/tmp/%s/tsys-%03d.dat", session, tsys->freqs[i].freq);
4310 
4311  if((fp = fopen(fname, "w")) == NULL)
4312  {
4313  log_msg("Unable to open %s for writting", fname);
4314 
4315  return(1);
4316  }
4317 
4318  /* Write Results */
4319  for(el=0;el<90;el++)
4320  {
4321  if(tsys->freqs[i].elev[el] > 0)
4322  {
4323  fprintf(fp, "%d %d\n", el, tsys->freqs[i].elev[el]);
4324  }
4325  }
4326 
4327  fclose(fp);
4328  }
4329 
4330  /* Now Write out gnuplot command file */
4331  sprintf(demName, "/tmp/%s/tsys.dem", session);
4332 
4333  if((fp = fopen(demName, "w")) == NULL)
4334  {
4335  log_msg("Unable to open %s for writting", demName);
4336 
4337  return(1);
4338  }
4339 
4340  fprintf(fp, "reset\n");
4341  fprintf(fp, "set size 1.0, 1.0\n");
4342  fprintf(fp, "set title \"Receiver Tsys\"\n");
4343  fprintf(fp, "set grid\n");
4344  fprintf(fp, "set xlabel \"Elevation\" tc rgb \"red\"\n");
4345  fprintf(fp, "set ylabel \"Tsys\" tc rgb \"red\"\n");
4346 
4347  setPaperSize(last_image.pinfo.paperw, last_image.pinfo.paperh, psize, fsize); /* Borrow the last_image for now */
4348 
4349  indx = 0;
4350  for(i=0;i<tsys->num;i++)
4351  {
4352  if(!tsys->freqs[i].used)
4353  {
4354  continue;
4355  }
4356 
4357  sprintf(fname, "/tmp/%s/tsys-%03d.dat", session, tsys->freqs[i].freq);
4358  sprintf(title, "%03d GHz", tsys->freqs[i].freq);
4359 
4360  if(indx == 0)
4361  {
4362  fprintf(fp, "plot '%s' with lines lc rgb \"red\" title \"%s\"", fname, title);
4363  }
4364  else
4365  {
4366  fprintf(fp, ", '%s' with lines lc rgb \"red\" title \"%s\"", fname, title);
4367  }
4368 
4369  indx++;
4370  }
4371 
4372  log_msg("Plotted %d freqs", indx);
4373 
4374  fprintf(fp, "\n"); /* Close it out */
4375 
4376  fclose(fp);
4377 
4378  sprintf(gpBuf, "load \"/tmp/%s/tsys.dem\"", session);
4379  writeGnuplot(gpBuf, tsys->xdelay);
4380 
4381  return(0);
4382 }
4383 
4384 
4386 struct SCAN_SUM_SEND *ss;
4387 int how;
4388 {
4389  int i, j, indx;
4390  double x, y;
4391  FILE *fp;
4392  char fname[256], demName[256], gpBuf[256], headBuf[1024];
4393  char xbuf[256], ybuf[256];
4394 
4395  log_msg("SSS: scans: %d", ss->nscans);
4396  log_msg("SSS: X-Axis: %d", ss->xaxis);
4397  log_msg("SSS: Y-Axis: %d", ss->yaxis);
4398  log_msg("SSS: Plotwin: %d", ss->plotwin);
4399  log_msg("SSS: XDelay: %d", ss->xdelay);
4400 
4401  /* Write out datafile first */
4402  for(i=0;i<MAX_IFS;i++)
4403  {
4404  if(ss->scans[0].scan[i] < 1.0)
4405  {
4406  continue;
4407  }
4408 
4409  sprintf(fname, "/tmp/%s/sss-%d.dat", session, i);
4410 
4411  if((fp = fopen(fname, "w")) == NULL)
4412  {
4413  log_msg("Unable to open %s for writting", fname);
4414 
4415  return(1);
4416  }
4417 
4418  /* Write Results */
4419  for(j=0;j<ss->nscans;j++)
4420  {
4421  switch(ss->xaxis)
4422  {
4423  case SCAN_SUM_X_UT: x = ss->scans[j].ut[i]; break;
4424  case SCAN_SUM_X_LST: x = ss->scans[j].lst[i]; break;
4425  case SCAN_SUM_X_AZ: x = ss->scans[j].az[i]; break;
4426  case SCAN_SUM_X_EL: x = ss->scans[j].el[i]; break;
4427  case SCAN_SUM_X_NUM: x = (double)j; break;
4428  default: x = ss->scans[j].scan[i]; break;
4429  }
4430 
4431  switch(ss->yaxis)
4432  {
4433  case SCAN_SUM_Y_RMS: y = ss->scans[j].rms[i]*1000.0; break;
4434  case SCAN_SUM_Y_TSYS: y = ss->scans[j].tsys[i]; break;
4435  case SCAN_SUM_Y_TCAL: y = ss->scans[j].tcal[i]; break;
4436  default: y = ss->scans[j].peak[i]; break;
4437  }
4438 
4439  fprintf(fp, "%e %e\n", x, y);
4440  }
4441 
4442  fclose(fp);
4443 
4444  log_msg("Wrote %d elements to %s", j, fname);
4445  }
4446 
4447 
4448  /* Now Write out gnuplot command file */
4449  sprintf(demName, "/tmp/%s/sss.dem", session);
4450 
4451  if((fp = fopen(demName, "w")) == NULL)
4452  {
4453  log_msg("Unable to open %s for writting", demName);
4454 
4455  return(1);
4456  }
4457 
4458  fprintf(fp, "reset\n");
4459  fprintf(fp, "set size 1.0, 1.0\n");
4460 
4461  makeSSSHeader(ss, headBuf);
4462 
4463  fprintf(fp, "set title \"%s\"\n", headBuf);
4464  fprintf(fp, "set grid\n");
4465 
4466  switch(ss->xaxis)
4467  {
4468  case SCAN_SUM_X_UT: strcpy(xbuf, "UT"); break;
4469  case SCAN_SUM_X_LST: strcpy(xbuf, "LST"); break;
4470  case SCAN_SUM_X_AZ: strcpy(xbuf, "AZ"); break;
4471  case SCAN_SUM_X_EL: strcpy(xbuf, "EL"); break;
4472  case SCAN_SUM_X_NUM: strcpy(xbuf, "Num"); break;
4473  default: strcpy(xbuf, "Scan"); break;
4474  }
4475 
4476  switch(ss->yaxis)
4477  {
4478  case SCAN_SUM_Y_RMS: strcpy(ybuf, "rms"); break;
4479  case SCAN_SUM_Y_TSYS: strcpy(ybuf, "Tsys"); break;
4480  case SCAN_SUM_Y_TCAL: strcpy(ybuf, "Tcal"); break;
4481  default: strcpy(ybuf, "(K)"); break;
4482  }
4483 
4484  fprintf(fp, "set xlabel \"%s\" tc rgb \"red\"\n", xbuf);
4485  fprintf(fp, "set ylabel \"%s\" tc rgb \"red\"\n", ybuf);
4486 
4487  if(ss->yscale)
4488  {
4489  fprintf(fp, "set yrange [%e:%e]\n", ss->ylower, ss->yupper);
4490  }
4491 
4492  setPaperSize(last_image.pinfo.paperw, last_image.pinfo.paperh, psize, fsize); /* Borrow the last_image for now */
4493 
4494  fprintf(fp, "set terminal x11 enhanced %d font \"%s\" position %d,%d\n", ss->plotwin, fsize, startx, ss->plotwin*10);
4495 
4496  indx = 0;
4497  for(i=0;i<MAX_IFS;i++)
4498  {
4499  if(ss->scans[0].scan[i] < 1.0)
4500  {
4501  continue;
4502  }
4503 
4504  sprintf(fname, "/tmp/%s/sss-%d.dat", session, i);
4505 
4506  if(indx == 0)
4507  {
4508  fprintf(fp, "plot '%s' with lp lc rgb \"red\" ", fname);
4509  }
4510  else
4511  {
4512  fprintf(fp, ", '%s' with lp lc rgb \"red\" ", fname);
4513  }
4514 
4515  indx++;
4516  }
4517 
4518  fprintf(fp, "\n"); /* Close it out */
4519 
4520  fclose(fp);
4521 
4522  sprintf(gpBuf, "load \"/tmp/%s/sss.dem\"", session);
4523  writeGnuplot(gpBuf, ss->xdelay);
4524 
4525  return(0);
4526 }
4527 
4528 
4530 {
4531  int gfd;
4532  char tbuf[256];
4533 
4534  sprintf(tbuf, "x11 size 800,600 position %d,0", startx);
4535 
4536  if(gnuplot_init(tbuf))
4537  {
4538  log_msg("Failed to open connection to gnuplot");
4539  exit(1);
4540  }
4541 
4542  gfd = fileno(gpin);
4543 
4544  log_msg("# Gnuplot gfd = %d", gfd);
4545 
4546  return(gfd);
4547 }
4548 
4549 
4550 int sendPlotRange(xmin, xmax, ymin, ymax)
4551 double xmin, xmax, ymin, ymax;
4552 {
4553  bzero((char *)&xsend, sizeof(xsend));
4554 
4555  strcpy(xsend.magic, "XGRAPHICS");
4556 
4557  xsend.plot_used = 1;
4558  xsend.xplotmin = xmin;
4559  xsend.xplotmax = xmax;
4560  xsend.yplotmin = ymin;
4561  xsend.yplotmax = ymax;
4562 
4563  sock_write(master, (char *)&xsend, sizeof(xsend));
4564 
4565  return(0);
4566 }
4567 
4568 
4569 int sendMousePosition(x, y, x2, y2)
4570 double x, y, x2, y2;
4571 {
4572  bzero((char *)&xsend, sizeof(xsend));
4573 
4574  strcpy(xsend.magic, "XGRAPHICS");
4575  xsend.mouse_used = 1;
4576 
4577  xsend.last_mouse_x = x;
4578  xsend.last_mouse_y = y;
4579  xsend.last_mouse_x2 = x2;
4580  xsend.last_mouse_y2 = x2;
4581 
4582  log_msg("sendMousePosition(): Sending structure");
4583 
4584  sock_write(master, (char *)&xsend, sizeof(xsend));
4585 
4586  return(0);
4587 }
4588 
4589 
4590 int sendMapAngle(ang1, ang2)
4591 double ang1, ang2;
4592 {
4593  bzero((char *)&xsend, sizeof(xsend));
4594 
4595  strcpy(xsend.magic, "XGRAPHICS");
4596 
4597  xsend.map_angle_used = 1;
4598  xsend.map_angle_1 = ang1;
4599  xsend.map_angle_2 = ang2;
4600 
4601  sock_write(master, (char *)&xsend, sizeof(xsend));
4602 
4603  return(0);
4604 }
4605 
4606 
4607 /*
4608 MOUSE: 94.4722850678733 -143.047007918552 0.0230744018354638 0.0230744018354638
4609  */
4610 
4612 char *buf;
4613 {
4614  int n;
4615  double x, y, x2, y2;
4616  double ang1, ang2;
4617  double xmin, xmax, ymin, ymax;
4618 
4619  log_msg("parseGnuplot(1): Got %s", buf);
4620 
4621  if(buf && strstr(buf, "MOUSE"))
4622  {
4623  if(!strncmp(buf, "MOUSE: MOUSE: ", 14))
4624  {
4625  n = sscanf(buf, "MOUSE: MOUSE: %lf %lf %lf %lf", &x, &x2, &y, &y2);
4626  }
4627  else
4628  {
4629  n = sscanf(buf, "MOUSE: %lf %lf %lf %lf", &x, &x2, &y, &y2);
4630  }
4631 
4632  if(n == 4)
4633  {
4634  log_msg("parseGnuplot(2): Got %d args", n);
4635  sendMousePosition(x, y, x2, y2);
4636  }
4637  else
4638  {
4639  log_msg("parseGnuplot(2): Wrong number of args: %d", n);
4640  log_msg("parseGnuplot(2): Got %s", buf);
4641  }
4642  }
4643  else
4644  if(buf && strstr(buf, "MAP_ANGLE"))
4645  {
4646  n = sscanf(buf, "MAP_ANGLE: %lf %lf", &ang1, &ang2);
4647 
4648  if(n == 2)
4649  {
4650  log_msg("parseGnuplot(3): Got %d Args", n);
4651  sendMapAngle(ang1, ang2);
4652  }
4653  }
4654  else
4655  if(buf && strstr(buf, "PLOT_RANGE"))
4656  {
4657  n = sscanf(buf, "PLOT_RANGE: %lf %lf %lf %lf", &xmin, &xmax, &ymin, &ymax);
4658 
4659  if(n == 4)
4660  {
4661  log_msg("parseGnuplot(4): Got %d Args", n);
4662  sendPlotRange(xmin, xmax, ymin, ymax);
4663  }
4664  }
4665 
4666  return(0);
4667 }
4668 
4669 
4670 /* Make a postscript output file of previously plotted data */
4671 int make()
4672 {
4673  char cmdStr[256], plotfname[256];
4674 
4675  sprintf(cmdStr, "set terminal postscript font \"%s\" color solid enhanced landscape size %s", fsize, psize);
4676  writeGnuplot(cmdStr, 100000);
4677 
4678 
4679  sprintf(plotfname, "/tmp/%s/ccal_plot.ps", session);
4680  sprintf(cmdStr, "set out \"%s\"", plotfname);
4681  writeGnuplot(cmdStr, 100000);
4682 
4683  sprintf(cmdStr, "replot");
4684  writeGnuplot(cmdStr, 100000);
4685 
4686  sprintf(cmdStr, "set terminal x11 enhanced");
4687  writeGnuplot(cmdStr, 100000);
4688 
4689  sprintf(cmdStr, "replot");
4690  writeGnuplot(cmdStr, 100000);
4691 
4692  return(0);
4693 }
4694 
4695 
4696 int main(argc, argv)
4697 int argc;
4698 char *argv[];
4699 {
4700  int lastCmdCancel = 0;
4701  int gfd, sel, len;
4702  int n, xw, xy;
4703  int expectedSize = -1, nexpected = 0, curExpected=0, bplotExpected = 0;
4704  char message[MAX_BUF_SIZE], gpBuf[512], logdir[256], *cp, sysbuf[256];
4705 
4707 
4708  if(argc > 1)
4709  {
4710  n = sscanf(argv[1], "%dx%d", &xw, &xy);
4711 
4712  if(n == 2)
4713  {
4714  displayW = xw;
4715  displayH = xy;
4716  }
4717  }
4718 
4719  cp = getenv("LPSESSION");
4720 
4721  if(cp)
4722  {
4723  strcpy(session, cp);
4724  }
4725  else
4726  {
4727  strcpy(session, "12345");
4728  }
4729 
4730  sprintf(gpfifo, "/tmp/%s/gpio", session);
4731  sprintf(logdir, "LOGDIR=/tmp/%s/", session);
4732 
4733  putenv(logdir);
4734 
4735  smart_log_open("xgraphic", 3);
4736 
4737  sock_bind("LINUXPOPS_XGRAPHIC");
4738 
4740 
4741  master = sock_connect("LINUXPOPS_MASTER");
4742 
4744 
4745  log_msg("Using Display Width: %d, Height: %d", displayW, displayH);
4746 
4747  startx = displayW - 800;
4748 
4749  strcpy(fsize, "9x15");
4750  strcpy(psize, papersize);
4751 
4752  gfd = startGnuPlot();
4753 
4754 // Look for background
4755 // xrdb -query | grep gnuplot.background
4756 
4757  while(1)
4758  {
4759  sel = sock_sel(message, &len, &gfd, 1, 60, 0);
4760 
4761  log_msg("< Select Returned: %d", sel);
4762 
4763  if(sel == -1)
4764  {
4765  log_msg("# Awake");
4766  }
4767  else
4768  if(sel == gfd)
4769  {
4770  readGnuplot(gpBuf);
4771  if(!lastCmdCancel)
4772  {
4773  parseGnuplot(gpBuf);
4774  }
4775  }
4776  else
4777  if(sel > 0)
4778  {
4779  log_msg("-");
4780  log_msg("< Got %d bytes on fd = %d", len, sel);
4781  lastCmdCancel = 0;
4782 
4783  if(len == expectedSize)
4784  {
4785  log_msg("Len %d matches Expected %d", len, expectedSize);
4786 
4787  if(curExpected != nexpected)
4788  {
4789  switch(curExpected)
4790  {
4791  case 0:
4792  bcopy(message, (char *)&last_image.yplot1, last_image.nsize);
4793  curExpected++;
4794  break;
4795 
4796  case 1:
4797  bcopy(message, (char *)&last_image.yplot2, last_image.nsize);
4798  curExpected++;
4799  break;
4800 
4801  case 2:
4802  bcopy(message, (char *)&last_image.yplot3, last_image.nsize);
4803  curExpected++;
4804  break;
4805 
4806  case 3:
4807  bcopy(message, (char *)&last_image.yplot4, last_image.nsize);
4808  curExpected++;
4809  break;
4810  }
4811  /* Are we still waiting for more?? */
4812  if(curExpected != nexpected)
4813  {
4814  continue;
4815  }
4816  }
4817  else
4818  if(bplotExpected)
4819  {
4820  bcopy(message, (char *)&last_image.bplot, last_image.nsize);
4821  log_msg("Received my Baseline Plot Array");
4822 
4823  bplotExpected = 0;
4824  }
4825 
4826  if(curExpected == nexpected && !bplotExpected)
4827  {
4828  switch(last_image.mode)
4829  {
4830  case MODE_SPEC:
4831  case MODE_OTF:
4832  if(last_image.narray == 1)
4833  {
4835  }
4836  else
4837  if(last_image.narray == 2)
4838  {
4840  }
4841  else
4842  if(last_image.narray == 4)
4843  {
4845  }
4846 
4847  break;
4848 
4849  case MODE_CONT:
4850  log_msg("CONT mode not implemented yet");
4851  break;
4852 
4853  case MODE_XCOR:
4854  log_msg("XCOR: Plotting");
4855  plotXcor(&last_image, PLOT);
4856  break;
4857  }
4858 
4860 
4861  expectedSize = -1;
4862  nexpected = 0;
4863  curExpected = 0;
4864  }
4865  }
4866  else
4867  if(len == SHORT_IMAGE_SIZE)
4868  {
4869  if(!strncmp(message, "LP_IMAGE_INFO", 13))
4870  {
4871  log_msg("< Got SHORT_IMAGE_INFO struct");
4872 
4873  bzero((char *)&last_image, sizeof(last_image));
4874  bcopy(message, (char *)&last_image, SHORT_IMAGE_SIZE);
4875 
4876  /* Remember how many arrays and how big, to follow */
4877  nexpected = last_image.narray;
4878  expectedSize = last_image.nsize;
4879  bplotExpected = last_image.pinfo.bplot;
4880 
4881  log_msg("Expecting %d Arrays of %d size", nexpected, expectedSize);
4882 
4883  if(bplotExpected)
4884  {
4885  log_msg("Also Expecting a Baseline Plot Array");
4886  }
4887  else
4888  {
4889  log_msg("NOT Expecting a Baseline Plot Array");
4890  }
4891 
4892  log_msg("SAT Struct Active = %d", last_image.satActive);
4893  }
4894 
4895  continue;
4896  }
4897  else
4898  if(len == sizeof(struct FLUX_INFO))
4899  {
4900  if(!strncmp(message, "FLUX_INFO", 9))
4901  {
4902  log_msg("< Got FLUX_INFO struct");
4903 
4904  bcopy(message, (char *)&last_flux, sizeof(last_flux));
4905 
4906  fluxPlot(&last_flux, PLOT);
4907 
4909  }
4910 
4911  continue;
4912  }
4913  else
4914  if(len == sizeof(struct ACCUM_RESULTS_SEND))
4915  {
4916  if(!strncmp(message, "ACCUM_INFO", 9))
4917  {
4918  log_msg("< Got ACCUM_RESULTS_SEND struct: %d", len);
4919 
4920  bcopy(message, (char *)&ars, sizeof(ars));
4921 
4922  accumPlot(&ars, PLOT);
4923 
4925  }
4926 
4927  continue;
4928  }
4929  else
4930  if(len == sizeof(struct CONTINUUM_PLAIN))
4931  {
4932  if(!strncmp(message, "CONTINUUM_PLAIN", 15))
4933  {
4934  log_msg("< Got CONTINUUM_PLAIN struct: %d", len);
4935 
4936  bcopy(message, (char *)&last_plain_send, sizeof(last_plain_send));
4937 
4939 
4941  }
4942 
4943  continue;
4944  }
4945  else
4946  if(len == sizeof(struct CONTINUUM_SPTIP))
4947  {
4948  if(!strncmp(message, "CONTINUUM_SPTIP", 15))
4949  {
4950  log_msg("< Got CONTINUUM_SPTIP struct: %d", len);
4951 
4952  bcopy(message, (char *)&last_sptip_send, sizeof(last_sptip_send));
4953 
4955 
4957  }
4958 
4959  continue;
4960  }
4961  else
4962  if(len == sizeof(struct FLUX_HISTORY))
4963  {
4964  if(!strncmp(message, "FLUX_HISTORY", 9))
4965  {
4966  log_msg("< Got FLUX_HISTORY struct: %d", len);
4967 
4968  bcopy(message, (char *)&fh, sizeof(fh));
4969 
4970  plotFluxHistory(&fh, PLOT);
4971 
4973  }
4974 
4975  continue;
4976  }
4977  else
4978  if(len == sizeof(struct FOCUS_HISTORY_SEND))
4979  {
4980  if(!strncmp(message, "FOCUS_SEND", 10))
4981  {
4982  log_msg("< Got FOCUS_HISTORY_SEND struct: %d", len);
4983 
4984  bcopy(message, (char *)&focus_send, sizeof(focus_send));
4985 
4987 
4989  }
4990 
4991  continue;
4992  }
4993  else
4994  if(len == sizeof(struct OBJECT))
4995  {
4996  if(!strncmp(message, "OBJECT_MAGIC", 12))
4997  {
4998  log_msg("< Got OBJECT_MAGIC struct: %d", len);
4999 
5000  bcopy(message, (char *)&last_obj, sizeof(last_obj));
5001 
5003 
5005  }
5006  else
5007  {
5008  log_msg("ObjectDisplay(): message is not OBJECT_MAGIC");
5009  }
5010 
5011  continue;
5012  }
5013  else
5014  if(len == sizeof(struct FFT_INFO))
5015  {
5016  if(!strncmp(message, "FFT_INFO", 8))
5017  {
5018  log_msg("< Got FFT_INFO struct: %d", len);
5019 
5020  bcopy(message, (char *)&last_fft, sizeof(last_fft));
5021 
5023 
5025  }
5026  else
5027  {
5028  log_msg("main(): message is not FFT_INFO");
5029  }
5030 
5031  continue;
5032  }
5033  else
5034  if(len == sizeof(struct HISTO_INFO))
5035  {
5036  if(!strncmp(message, "HISTOGRAM", 9))
5037  {
5038  log_msg("< Got HISTO_INFO struct: %d", len);
5039 
5040  bcopy(message, (char *)&last_histo, sizeof(last_histo));
5041 
5043 
5045  }
5046  else
5047  {
5048  log_msg("main(): message is not HISTO_INFO");
5049  }
5050 
5051  continue;
5052  }
5053  else
5054  if(len == sizeof(struct STRINGS_AND_THINGS))
5055  {
5056  if(!strncmp(message, "STRINGS", 7))
5057  {
5058  log_msg("< Got STRINGS_AND_THINGS struct: %d", len);
5059 
5060  bcopy(message, (char *)&sat, sizeof(sat));
5061 
5062  }
5063  else
5064  {
5065  log_msg("main(): message is not STRINGS_AND_THINGS");
5066  }
5067 
5068  continue;
5069  }
5070  else
5071  if(len == sizeof(struct TSYS_SEND))
5072  {
5073  if(!strncmp(message, "TSYS_SEND", 9))
5074  {
5075  log_msg("< Got TSYS_SEND struct: %d", len);
5076 
5077  bcopy(message, (char *)&last_tsys, sizeof(last_tsys));
5078 
5080 
5082  }
5083  else
5084  {
5085  log_msg("main(): message is not TSYS_SEND");
5086  }
5087 
5088  continue;
5089  }
5090  else
5091  if(len == sizeof(struct SCAN_SUM_SEND))
5092  {
5093  if(!strncmp(message, "SCAN_SUM_SEND", 13))
5094  {
5095  log_msg("< Got SCAN_SUM_SEND struct: %d", len);
5096 
5097  bcopy(message, (char *)&sss, sizeof(sss));
5098 
5099  displayScanSum(&sss, PLOT);
5100 
5102  }
5103  else
5104  {
5105  log_msg("main(): message is not SCAN_SUM_SEND; %s", message);
5106  }
5107 
5108  continue;
5109  }
5110 
5111  /* Check for commands */
5112  if(!strncmp(message, "exit", 4))
5113  {
5114  log_msg("< Got command to exit()");
5115 
5116  log_msg("lp_exit"); /* Trigger the logger to exit too */
5117 
5118  closeGnuplot();
5119 
5120  exit(0);
5121  }
5122  else
5123  if(!strncmp(message, "ccur", 4))
5124  {
5125  log_msg("< Got 'ccur'");
5126  writeGnuplot("pause mouse button1", 0);
5127  writeGnuplot(mouse_str, 0);
5128  }
5129  else
5130  if(!strncmp(message, "tcur", 4))
5131  {
5132  log_msg("< Got 'tcur'");
5133  writeGnuplot("pause mouse button1", 0);
5134  writeGnuplot(mouse_str, 0);
5135  }
5136  else
5137  if(!strncmp(message, "cancel", 4))
5138  {
5139  log_msg("< Got 'cancel'");
5140  log_msg("> Sending SIGINT to gnuplot");
5141  sprintf(sysbuf, "/bin/kill -INT %d", gnuplot_pid);
5142  log_msg(sysbuf);
5143  system(sysbuf);
5144  lastCmdCancel = 1;
5145  }
5146  else
5147  if(!strncmp(message, "restart", 7))
5148  {
5149  log_msg("< Got 'restart'");
5150  log_msg("> Sending SIGHUP to gnuplot");
5151 
5152  closeGnuplot();
5153 
5154  gfd = startGnuPlot();
5155  }
5156  else
5157  if(!strncmp(message, "page", 4))
5158  {
5159  log_msg("< Got 'page'");
5160  writeGnuplot("clear", 0);
5161  }
5162  else
5163  if(!strncmp(message, "show_view", 9))
5164  {
5165  log_msg("< Got 'show_view'");
5167  }
5168  else
5169  if(!strncmp(message, "get_range", 9))
5170  {
5171  log_msg("< Got 'get_range'");
5173  }
5174  else
5175  if(!strncmp(message, "make", 4))
5176  {
5177  log_msg("< Got 'make'");
5178  make();
5179  }
5180  else
5181  if(!strncmp(message, "refresh", 7))
5182  {
5183  log_msg("< Got 'refresh'");
5184  switch(lastPlot)
5185  {
5186  case LAST_IMAGE_INFO:
5187  if(last_image.mode == MODE_XCOR)
5188  {
5189  plotXcor(&last_image, PLOT);
5190  }
5191  else
5192  if(last_image.narray == 1)
5193  {
5195  }
5196  else
5197  if(last_image.narray == 2)
5198  {
5200  }
5201  else
5202  if(last_image.narray == 4)
5203  {
5205  }
5206 
5207  break;
5208 
5209  case LAST_FLUX_INFO: fluxPlot(&last_flux, PLOT); break;
5210  case LAST_ACCUM_RESULTS: accumPlot(&ars, PLOT); break;
5211  case LAST_FLUX_HISTORY: plotFluxHistory(&fh, PLOT); break;
5214  case LAST_FFT_INFO: displayFFT(&last_fft, PLOT); break;
5215  case LAST_HISTO_INFO: displayHisto(&last_histo, PLOT); break;
5216  case LAST_TSYS_INFO: displayTsys(&last_tsys, PLOT); break;
5217  case LAST_SSS_INFO: displayScanSum(&sss, PLOT); break;
5219  }
5220  }
5221  else
5222  if(!strncmp(message, "load", 4))
5223  {
5224  log_msg("< Got 'load'");
5225  sprintf(gpBuf, "load \"/tmp/%s/scan.dem\"", session);
5226  writeGnuplot(gpBuf, 0);
5227  }
5228  else
5229  if(!strncmp(message, "xgraphic", 8))
5230  {
5231  log_msg("< Got '%s'", message);
5232  sprintf(gpBuf, "%s", message+8);
5233  writeGnuplot(gpBuf, 0);
5234  }
5235  }
5236  else
5237  {
5238  log_msg("* sock_sel() returned %d", sel);
5239  }
5240  }
5241 
5242  return(0);
5243 }
5244 
5245 
5246 #ifdef TOMMIE
5247  All gnuplot available variables:
5248 
5249  pi = 3.14159265358979
5250  NaN = NaN
5251  GNUTERM = "wxt"
5252  GPVAL_TERM = "x11"
5253  GPVAL_TERMOPTIONS = "1 nopersist enhanced size 815,850 position -100,100 "
5254  GPVAL_OUTPUT = ""
5255  GPVAL_VERSION = 4.4
5256  GPVAL_PATCHLEVEL = "0"
5257  GPVAL_COMPILE_OPTIONS = "-READLINE +LIBREADLINE +HISTORY -BACKWARDS_COMPATIBILITY +BINARY_DATA \n+GD_PNG +GD_JPEG +GD_TTF +GD_GIF +ANIMATION \n-NOCWDRC +X11 +X11_POLYGON +MULTIBYTE +X11_EXTERNAL +USE_MOUSE +HIDDEN3D_QUADTREE \n+DATASTRINGS +HISTOGRAMS +OBJECTS +STRINGVARS +MACROS +IMAGE \n"
5258  GPVAL_MULTIPLOT = 0
5259  GPVAL_PLOT = 0
5260  GPVAL_SPLOT = 1
5261  GPVAL_TERMINALS = " canvas cgm corel dpu414 dumb dxf eepic emf emtex epslatex epson_180dpi epson_60dpi epson_lx800 fig gif gpic hp2623A hp2648 hp500c hpdj hpgl hpljii hppj imagen jpeg latex mf mif mp nec_cp6 okidata pbm pcl5 pdfcairo png pngcairo postscript pslatex pstex pstricks qms regis starc svg tandy_60dpi tek40xx tek410x texdraw tgif tkcanvas tpic unknown vttek wxt x11 xlib xterm "
5262  GPVAL_pi = 3.14159265358979
5263  GPVAL_NaN = NaN
5264  GPVAL_ERRNO = 0
5265  GPVAL_ERRMSG = ""
5266  GPVAL_PWD = "/home/helix/tfolkers/cactus/linuxpops/linuxpops"
5267  GPVAL_LAST_PLOT = "splot \"/tmp/LP-9430/beam_map.dat\" every 1::0::1024 with lines"
5268  GPVAL_TERM_WINDOWID = 10485898
5269  GPVAL_X_MIN = -307.5
5270  GPVAL_X_MAX = 307.5
5271  GPVAL_X_REVERSE = 0
5272  GPVAL_X_LOG = 0.0
5273  GPVAL_DATA_X_MIN = -300.0
5274  GPVAL_DATA_X_MAX = 300.0
5275  GPVAL_Y_MIN = -307.5
5276  GPVAL_Y_MAX = 307.5
5277  GPVAL_Y_REVERSE = 0
5278  GPVAL_Y_LOG = 0.0
5279  GPVAL_DATA_Y_MIN = -307.5
5280  GPVAL_DATA_Y_MAX = 292.5
5281  GPVAL_X2_MIN = -10.0
5282  GPVAL_X2_MAX = 10.0
5283  GPVAL_X2_REVERSE = 0
5284  GPVAL_X2_LOG = 0.0
5285  GPVAL_DATA_X2_MIN = 0.0
5286  GPVAL_DATA_X2_MAX = 0.0
5287  GPVAL_Y2_MIN = -10.0
5288  GPVAL_Y2_MAX = 10.0
5289  GPVAL_Y2_REVERSE = 0
5290  GPVAL_Y2_LOG = 0.0
5291  GPVAL_DATA_Y2_MIN = 0.0
5292  GPVAL_DATA_Y2_MAX = 0.0
5293  GPVAL_Z_MIN = -68.76
5294  GPVAL_Z_MAX = 0.51
5295  GPVAL_Z_REVERSE = 0
5296  GPVAL_Z_LOG = 0.0
5297  GPVAL_DATA_Z_MIN = -68.25509
5298  GPVAL_DATA_Z_MAX = 0.010893
5299  GPVAL_CB_MIN = -68.76
5300  GPVAL_CB_MAX = 0.51
5301  GPVAL_CB_REVERSE = 0
5302  GPVAL_CB_LOG = 0.0
5303  GPVAL_T_MIN = -10.0
5304  GPVAL_T_MAX = 10.0
5305  GPVAL_T_REVERSE = 0
5306  GPVAL_T_LOG = 0.0
5307  GPVAL_DATA_CB_MIN = -68.25509
5308  GPVAL_DATA_CB_MAX = 0.010893
5309  GPVAL_U_MIN = -5.0
5310  GPVAL_U_MAX = 5.0
5311  GPVAL_U_REVERSE = 0
5312  GPVAL_U_LOG = 1.0
5313  GPVAL_V_MIN = -5.0
5314  GPVAL_V_MAX = 5.0
5315  GPVAL_V_REVERSE = 0
5316  GPVAL_V_LOG = 1.0
5317  GPVAL_TERM_XMIN = 87
5318  GPVAL_TERM_XMAX = 4009
5319  GPVAL_TERM_YMIN = 156
5320  GPVAL_TERM_YMAX = 3940
5321  GPVAL_VIEW_MAP = 0
5322  GPVAL_VIEW_ROT_X = 65.0
5323  GPVAL_VIEW_ROT_Z = 41.0
5324  GPVAL_VIEW_SCALE = 1.0
5325  GPVAL_VIEW_ZSCALE = 1.0
5326 #endif
double last_mouse_x
Definition: global.h:49
float yplot1[MAX_CHANS]
Definition: image.h:110
struct SCAN_SUM_SEND ss
Definition: scansum.c:61
struct STRINGS_AND_THINGS sat
int plot_used
Definition: global.h:39
int xx()
Definition: linuxpops.c:605
#define MAX_BAD_CHANS
Definition: defines.h:43
double scan
Definition: header.h:35
int main(void)
Definition: gsl_try_2.c:176
char label[MAX_LABEL_LENGTH]
char * mg_sideband[]
Definition: strings.c:78
#define LOG_PLOT
Definition: defines.h:111
#define LOG_TO_LOGGER
Definition: loglib.h:3
#define MULTI
Definition: xgraphic.c:59
double stampULy
int placeHlines(struct LP_IMAGE_INFO *image, FILE *fp)
Definition: xgraphic.c:1224
int linePlot_1(struct LP_IMAGE_INFO *image, int how)
Definition: xgraphic.c:1816
#define ACCUM_PLOT_X_EL
Definition: accum.h:10
int sendMapAngle(double ang1, double ang2)
Definition: xgraphic.c:4590
int sock_write(struct SOCK *s, char *message, int l)
char * prompt
Definition: makemem.c:101
#define MODE_OTF
Definition: defines.h:88
char * sideband[]
Definition: xgraphic.c:71
int first
Definition: dbase.c:106
int sendMousePosition(double x, double y, double x2, double y2)
Definition: xgraphic.c:4569
struct SCAN_SUM_SEND sss
Definition: xgraphic.c:106
#define GRID_MODE_X_ONLY
Definition: defines.h:115
float paperh
Definition: accum.h:70
int displayHisto(struct HISTO_INFO *histo, int how)
Definition: xgraphic.c:729
double last_mouse_y2
Definition: global.h:52
#define SCAN_SUM_Y_RMS
Definition: scan_sum.h:14
int setPaperSize(double w, double h, char *psize, char *fsize)
Definition: xgraphic.c:1484
double utdate
Definition: header.h:61
#define MODE_XCOR
Definition: defines.h:92
struct STAMP stamps[MAX_PSTAMPS]
char * kp_sideband[]
Definition: strings.c:72
#define MODE_TMB
Definition: object.h:23
int placeLabels(struct LP_IMAGE_INFO *image, FILE *fp, int print)
Definition: xgraphic.c:999
#define MODE_LINES
Definition: object.h:20
float paperw
Definition: image.h:40
#define MODE_EFF
Definition: object.h:24
#define FOCUS_SCALE_MULTI
Definition: focus.h:15
double xplotmin
Definition: global.h:46
int contSptipPlot(struct CONTINUUM_SPTIP *cs, int how)
Definition: xgraphic.c:3674
double yplotmin
Definition: global.h:44
#define LAST_FOCUS_HISTORY
Definition: xgraphic.c:53
int startGnuPlot(void)
Definition: xgraphic.c:4529
#define SCAN_SUM_Y_TSYS
Definition: scan_sum.h:15
int log_perror(char *msg)
int nsize
Definition: image.h:80
#define MAX_CHANS
Definition: defines.h:38
int getSize(int s)
Definition: xgraphic.c:1342
int displayTsys(struct TSYS_SEND *tsys, int how)
Definition: xgraphic.c:4292
int displayFFT(struct FFT_INFO *fft, int how)
Definition: xgraphic.c:654
int logImageInfo(struct LP_IMAGE_INFO *image)
Definition: xgraphic.c:826
struct termios term
Definition: linuxpops.c:68
#define MAX_TBLOCK_LABELS
#define MODE_CONT
Definition: defines.h:86
int displayScanSum(struct SCAN_SUM_SEND *ss, int how)
Definition: xgraphic.c:4385
#define LAST_CONTINUUM_PLAIN
Definition: xgraphic.c:46
char * focus_axis_str[]
Definition: xgraphic.c:82
FILE * fp
Definition: linuxpops.c:70
#define max(a, b)
Definition: cactus.h:115
Definition: header.h:13
int log_eventdEnable(int enable)
double stampULx
double xsource
Definition: header.h:74
double ysource
Definition: header.h:75
char coordcd[8]
Definition: header.h:87
#define MAX_BUF_SIZE
Definition: xgraphic.c:110
struct SOCK * master
Definition: xgraphic.c:84
double plot_interval
Definition: xgraphic.c:91
double tcal
Definition: header.h:202
void fgauss()
int placeDate(struct LP_IMAGE_INFO *image, FILE *fp)
Definition: xgraphic.c:1315
#define SCAN_SUM_X_LST
Definition: scan_sum.h:8
double stampLRx
#define MAX_IMAGE_HLINES
#define min(a, b)
Definition: cactus.h:114
int plotFocusHistory(struct FOCUS_HISTORY_SEND *f, int how)
Definition: xgraphic.c:3446
int plotXcor(struct LP_IMAGE_INFO *image, int how)
Definition: xgraphic.c:2479
FILE * gpout
Definition: xgraphic.c:118
#define ACCUM_PLOT_Y_TSYS
Definition: accum.h:19
Definition: object.h:70
#define SCAN_SUM_X_NUM
Definition: scan_sum.h:11
struct LP_IMAGE_INFO last_image
Definition: xgraphic.c:95
struct IMAGE_LABELS labels[MAX_TBLOCK_LABELS]
int stquiet
Definition: env.c:90
int plotFluxHistory(struct FLUX_HISTORY *f, int how)
Definition: xgraphic.c:3380
int lastPlot
Definition: xgraphic.c:86
#define LAST_FLUX_HISTORY
Definition: xgraphic.c:45
char * makeFrStr(double freqres)
Definition: xgraphic.c:410
#define GRID_MODE_NONE
Definition: defines.h:114
FILE * gpin
Definition: xgraphic.c:118
#define MODE_NUM
Definition: object.h:16
int make()
Definition: xgraphic.c:4671
struct PLOT_INFO pinfo
Definition: image.h:102
#define ACCUM_PLOT_Y_SMROR
Definition: accum.h:18
#define MODE_APP
Definition: object.h:25
struct IMAGE_LABELS labels[MAX_IMAGE_LABELS]
#define SHORT_IMAGE_SIZE
Definition: image.h:122
#define FOCUS_SCALE_SUB
Definition: focus.h:14
double sideband
Definition: header.h:143
int makeFFTHeader(struct FFT_INFO *fft, char *buf)
Definition: xgraphic.c:481
int displayObjHistory(struct OBJECT *obj, int how)
Definition: xgraphic.c:3850
double synfreq
Definition: header.h:132
int gnuplot_init(char *term)
Definition: xgraphic.c:171
char * dateStr
Definition: build.c:4
#define MAX_BASELINES
Definition: defines.h:42
int find_ticks(struct LP_IMAGE_INFO *image)
Definition: xgraphic.c:2588
struct FOCUS_HISTORY_SEND focus_send
Definition: focus.c:60
float paperh
Definition: image.h:41
struct FLUX_HISTORY fh
Definition: xgraphic.c:98
int makeOSB(struct HEADER *h)
Definition: xgraphic.c:938
#define ACCUM_PLOT_Y_SKY
Definition: accum.h:17
struct HISTO_INFO last_histo
Definition: histogram.c:63
int makeHistoHeader(struct HISTO_INFO *histo, char *buf)
Definition: xgraphic.c:564
int recursiveLevel
Definition: makemem.c:93
#define MAX_IMAGE_FORKS
char fsize[256]
Definition: xgraphic.c:75
int mon
Definition: convol.c:102
#define LAST_HISTO_INFO
Definition: xgraphic.c:50
int sexagesimal(double dang, char *str, int prec)
#define XMODE_CHAN
Definition: defines.h:97
int sock_bufct(int bufct)
double last_mouse_y
Definition: global.h:50
float yplot2[MAX_CHANS]
Definition: image.h:111
int placeMarkers(struct LP_IMAGE_INFO *image, FILE *fp)
Definition: xgraphic.c:1200
int log_msg(const char *fmt,...)
struct OBJECT last_obj
Definition: xgraphic.c:101
#define LAST_CONTINUUM_SPTIP
Definition: xgraphic.c:47
Definition: sock.h:30
int placeBmark(struct LP_IMAGE_INFO *image, FILE *fp)
Definition: xgraphic.c:1435
#define LAST_IMAGE_INFO
Definition: xgraphic.c:42
#define MODE_JANSKYS
Definition: object.h:22
int smart_log_open(char *name, int offset)
char osbStr[32]
Definition: xgraphic.c:128
int gnuplot_pid
Definition: xgraphic.c:85
char * map_ang_str
Definition: xgraphic.c:77
struct FORK_TINE tines[MAX_FORK_TINES]
int sock_send(struct SOCK *s, char *message)
int displayW
Definition: xgraphic.c:87
#define ACCUM_PLOT_Y_SIG
Definition: accum.h:16
#define SCAN_SUM_X_EL
Definition: scan_sum.h:10
struct IMAGE_HLINE hlines[MAX_IMAGE_HLINES]
struct IMAGE_FORKS forks[MAX_IMAGE_FORKS]
int satActive
Definition: image.h:81
#define MAX_FOCUS_LABELS
Definition: focus.h:5
#define DEG_TO_RAD
Definition: cactus.h:48
int makeGfile(struct LP_IMAGE_INFO *image, char *gname, FILE *fp)
Definition: xgraphic.c:1529
char * papersize
Definition: strings.c:63
#define ACCUM_PLOT_Y_TR
Definition: accum.h:21
struct IMAGE_MARKERS markers[MAX_IMAGE_MARKERS]
struct FLUX_INFO last_flux
Definition: xgraphic.c:97
#define LAST_FFT_INFO
Definition: xgraphic.c:49
int placeChanMarkers(struct LP_IMAGE_INFO *image, FILE *fp)
Definition: xgraphic.c:1175
#define SCAN_SUM_X_UT
Definition: scan_sum.h:7
#define SINGLE
Definition: xgraphic.c:58
double stampLRy
#define LAST_SSS_INFO
Definition: xgraphic.c:52
void st_fail()
int readGnuplot(char *buf)
Definition: xgraphic.c:309
#define MAX_IMAGE_GAUSS_RESULTS
#define LABEL_RIGHT
Definition: flux.h:13
int placePstamps(struct LP_IMAGE_INFO *image, FILE *fp)
Definition: xgraphic.c:1397
char label[MAX_LABEL_LENGTH]
int writeGnuplot(char *buf, int delay)
Definition: xgraphic.c:289
int mode
Definition: image.h:76
double velocity
Definition: header.h:118
char * colors[]
char label[MAX_LABEL_LENGTH]
struct CONTINUUM_SPTIP last_sptip_send
Definition: xgraphic.c:100
#define DD_MM_SS
Definition: sex.h:15
int makeLineHeader(struct LP_IMAGE_INFO *image, char *buf)
Definition: xgraphic.c:431
int makeBshow(struct LP_IMAGE_INFO *image, char *bname, FILE *fp)
Definition: xgraphic.c:1607
double map_angle_2
Definition: global.h:55
#define ACCUM_PLOT_X_SCAN
Definition: accum.h:12
#define MAX_IMAGE_MARKERS
float paperw
Definition: accum.h:69
char title[256]
Definition: specplot.c:34
char magic[16]
Definition: global.h:37
int sock_sel(char *message, int *l, int *p, int n, int tim, int rd_in)
int makeZline(struct LP_IMAGE_INFO *image, char *zname, FILE *fp)
Definition: xgraphic.c:1638
#define Y_FIXED_SCALE
Definition: defines.h:107
double stsys
Definition: header.h:203
#define FOCUS_SORTED_TAMB
Definition: focus.h:10
int bplot
Definition: image.h:35
int placeGauss(struct LP_IMAGE_INFO *image, FILE *fp, int print)
Definition: xgraphic.c:955
int placeBadChans(struct LP_IMAGE_INFO *image, FILE *fp)
Definition: xgraphic.c:1147
double epocra
Definition: header.h:78
Definition: tsys.h:48
char session[80]
Definition: strings.c:67
#define ACCUM_PLOT_Y_TASTAR
Definition: accum.h:20
char * plotStyleStrs[]
Definition: strings.c:97
#define XMODE_FREQ
Definition: defines.h:95
#define MODE_SPEC
Definition: defines.h:87
int displayH
Definition: xgraphic.c:88
int makeHeaderAndLabels(struct LP_IMAGE_INFO *image, FILE *fp, int mode, int how)
Definition: xgraphic.c:1668
int setColor(int c)
Definition: parse.c:2644
struct IMAGE_PSTAMPS pstamp
int startx
Definition: xgraphic.c:89
#define LAST_TSYS_INFO
Definition: xgraphic.c:51
char gpfifo[256]
Definition: xgraphic.c:169
struct IMAGE_DATE_STRING date
#define SCAN_SUM_Y_TCAL
Definition: scan_sum.h:16
#define MAX_GNUPLOT_INITS
Definition: xgraphic.c:148
#define LAST_ACCUM_RESULTS
Definition: xgraphic.c:44
#define FOCUS_SCALE_NONE
Definition: focus.h:12
int placeForks(struct LP_IMAGE_INFO *image, FILE *fp, int how)
Definition: xgraphic.c:1249
#define LAST_FLUX_INFO
Definition: xgraphic.c:43
struct ACCUM_RESULTS_SEND ars
Definition: xgraphic.c:96
#define MAX_PSTAMPS
int makeContHeader(struct HEADER *h, struct ACCUM_RESULTS_SEND *a, char *buf)
Definition: xgraphic.c:604
int makeBfile(struct LP_IMAGE_INFO *image, char *bshape, FILE *fp)
Definition: xgraphic.c:1578
struct FFT_INFO last_fft
Definition: fft.c:80
double deltax
Definition: header.h:209
int closeGnuplot(void)
Definition: xgraphic.c:268
int computeXaxis(struct LP_IMAGE_INFO *image, int logit)
Definition: xaxis.c:70
char * mouse_str
Definition: xgraphic.c:76
struct CONTINUUM_PLAIN last_plain_send
Definition: xgraphic.c:99
struct IMAGE_GAUSS gauss
double map_angle_1
Definition: global.h:54
#define FOCUS_SCALE_DIVIDE
Definition: focus.h:16
struct XGRAPHIC_SEND xsend
Definition: linuxpops.c:73
struct GAUSS_INFO_RESULTS results[MAX_IMAGE_GAUSS_RESULTS]
int isBadChan(int bad)
Definition: badchan.c:377
#define FOCUS_SCALE_ADD
Definition: focus.h:13
int placeTBlock(struct LP_IMAGE_INFO *image, FILE *fp, int print)
Definition: xgraphic.c:1106
double linexmin
#define ACCUM_PLOT_Y_NORMAL
Definition: accum.h:23
double inttime
Definition: header.h:210
char * firstArg
Definition: makemem.c:104
struct BOUND * sock_bind(char *mbname)
double last_mouse_x2
Definition: global.h:51
char * makeDate(double d)
Definition: xgraphic.c:370
#define MAX_GLABELS
Definition: accum.h:28
struct SOCK * sock_connect(char *mbname)
int narray
Definition: image.h:79
int linePlot_2(struct LP_IMAGE_INFO *image, int how)
Definition: xgraphic.c:2108
char * get_range_str
Definition: xgraphic.c:78
#define LABEL_DOWN
#define SCAN_SUM_X_AZ
Definition: scan_sum.h:9
#define TRUE
Definition: xgraphic.c:39
int makeSSSHeader(struct SCAN_SUM_SEND *ss, char *buf)
Definition: xgraphic.c:523
int fluxPlot(struct FLUX_INFO *flux, int how)
Definition: xgraphic.c:2685
char * gnuplot_inits[]
Definition: xgraphic.c:132
#define Y_AUTO_SCALE
Definition: defines.h:106
int lp_logging
Definition: linuxpops.c:88
double xplotmax
Definition: global.h:47
int setCactusEnvironment(void)
float bplot[MAX_CHANS]
Definition: image.h:116
#define PLOT
Definition: xgraphic.c:55
int accumPlot(struct ACCUM_RESULTS_SEND *a, int how)
Definition: xgraphic.c:2754
double yplotmax
Definition: global.h:45
#define LABEL_LEFT
#define MAX_IMAGE_LABELS
int linePlot_4(struct LP_IMAGE_INFO *image, int how)
Definition: xgraphic.c:2250
int contPlot(struct CONTINUUM_PLAIN *cp, int how)
Definition: xgraphic.c:3211
int sendPlotRange(double xmin, double xmax, double ymin, double ymax)
Definition: xgraphic.c:4550
int mouse_used
Definition: global.h:40
char object[16]
Definition: header.h:40
double restfreq
Definition: header.h:198
int delay(double dc)
#define XMODE_VEL
Definition: defines.h:96
double linexmax
int map_angle_used
Definition: global.h:41
double pi
Definition: env.c:74
#define MAX_IFS
Definition: accum.h:5
int parseGnuplot(char *buf)
Definition: xgraphic.c:4611
double freqres
Definition: header.h:199
#define LAST_OBJECT_HISTORY
Definition: xgraphic.c:48
#define GRID_MODE_Y_ONLY
Definition: defines.h:116
double epocdec
Definition: header.h:79
struct TSYS_SEND last_tsys
Definition: xgraphic.c:105
struct TITLE_BLOCK tblock
Definition: lp_fft.h:7
#define ACCUM_PLOT_X_UT
Definition: accum.h:11
#define ACCUM_PLOT_Y_JANSKY
Definition: accum.h:22
FILE * errPrint_fp
Definition: linuxpops.c:70
char psize[256]
Definition: xgraphic.c:75
float yplot3[MAX_CHANS]
Definition: image.h:112
int verboseLevel
Definition: linuxpops.c:80
float yplot4[MAX_CHANS]
Definition: image.h:113