Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
line.c
Go to the documentation of this file.
1 /*
2 Copyright 2021 Arizona Board of Regents on behalf of the University of Arizona.
3 
4 For commercial uses, to obtain a license to sell and or sublicense copies of
5 the Software please contact the University of Arizona at Tech Launch Arizona:
6 lewish@tla.arizona.edu.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction for non-commercial use educational and
11 research purposes, including without limitation the rights to use, copy,
12 modify, merge, publish, distribute, and to permit persons to whom the Software
13 is furnished to do so, subject to the following conditions:
14 
15 The entire above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 SOFTWARE.
25 
26 1. Additional Required Provisions
27 
28 1.1. Arbitration. The parties agree that if a dispute arises between them
29 concerning this Agreement, the parties may be required to submit the matter to
30 arbitration pursuant to Arizona law.
31 
32 1.2. Applicable Law and Venue. This Agreement shall be interpreted pursuant
33 to the laws of the State of Arizona. Any arbitration or litigation between the
34 Parties shall be conducted in Pima County, ARIZONA, and LICENSEE hereby
35 submits to venue and jurisdiction in Pima County, ARIZONA.
36 
37 1.3. Non-Discrimination. The Parties agree to be bound by state and federal
38 laws and regulations governing equal opportunity and non-discrimination and
39 immigration.
40 
41 1.4. Appropriation of Funds. The Parties recognize that performance by
42 ARIZONA may depend upon appropriation of funds by the State Legislature of
43 ARIZONA. If the Legislature fails to appropriate the necessary funds, or if
44 ARIZONA’S appropriation is reduced during the fiscal year, ARIZONA may cancel
45 this Agreement without further duty or obligation. ARIZONA will notify
46 LICENSEE as soon as reasonably possible after it knows of the loss of funds.
47 
48 1.5. Conflict of Interest. This Agreement is subject to the provisions of
49 A.R.S. 38-511 and other conflict of interest regulations. Within three years
50 of the EFFECTIVE DATE, ARIZONA may cancel this Agreement if any person
51 significantly involved in initiating, negotiating, drafting, securing, or
52 creating this Agreement for or on behalf of ARIZONA becomes an employee or
53 consultant in any capacity of LICENSEE with respect to the subject matter of
54 this Agreement.
55 
56  */
57 
58 
59 #include "extern.h"
60 
61 #include <gsl/gsl_statistics_double.h>
62 
63 /* Changes:
64  *
65  * Added nbox function: twf; March 01, 2016
66  *
67  */
68 
69 double workingTsys = 0.0;
70 double workingTcal = 0.0;
71 double workingTime = 0.0;
74 
75 char rmsResultsStr[256];
76 
77 #define USE_GSL 1
78 
82 int computeRms(y, n, rms)
83 float *y, *rms;
84 int n;
85 {
86  int i, verbose=0;
87 #ifdef USE_GSL
88 //#warning Using the GSL version of computeRMS()
89  double meangsl, rmsgsl, tss, gsv;
90  double d[MAX_CHANS];
91 #else
92  double mean, sums;
93 #endif
94 
95  if(isSet(PF_V_FLAG))
96  {
97  st_report("computeRms(): Verbose Set");
98  verbose = 1;
99  }
100 
101  clearRMS();
102 
103  if(n==0)
104  {
105  return(1);
106  }
107 
108 #ifdef USE_GSL
109 
110  for(i=0;i<n;i++)
111  {
112  d[i] = y[i];
113  }
114 
115  meangsl = gsl_stats_mean(d, 1, n);
116 
117  if(verbose)
118  {
119  st_print("GSL Mean = %12.6f mK\n", meangsl);
120  }
121 
122  tss = gsl_stats_tss_m(d, 1, n, meangsl);
123 
124  gsv = gsl_stats_variance_m(d, 1, n, meangsl);
125 
126  if(verbose)
127  {
128  st_print("GSL Variance = %12.6f mK\n", gsv * 1000.0);
129  st_print("GSL TSS = %12.6f mK\n", tss * 1000.0);
130  st_print("GSL sqrt(TTS) = %12.6f mK\n", sqrt(tss) * 1000.0);
131  }
132 
133  rmsgsl = gsl_stats_absdev_m(&d[0], 1, n, meangsl);
134  if(verbose)
135  {
136  st_print("GSL Abs Dev = %12.6f mK\n", rmsgsl * 1000.0);
137  }
138 
139  rmsgsl = gsl_stats_sd_m(d, 1, n, meangsl);
140 
141  if(verbose)
142  {
143  st_print("GSL rms = %12.6f mK\n", rmsgsl * 1000.0);
144  }
145 
146  if(verbose)
147  {
148  st_print("GSL Skew = %12.6f mK\n", gsl_stats_skew(d, 1, n) * 1000.0);
149  st_print("GSL Kurtosis = %12.6f mK\n", gsl_stats_kurtosis(d, 1, n) * 1000.0);
150  st_print("GSL AutoCorr = %12.6f mK\n", gsl_stats_lag1_autocorrelation(d, 1, n) * 1000.0);
151  }
152 
153  /* Use the gsl version */
154  *rms = rmsgsl;
155 
156 #else
157 
158  mean = 0.0;
159  for(i=0;i<n;i++)
160  {
161  mean += y[i];
162  }
163 
164  mean /= (float)n;
165 
166 // st_print("My Mean = %f\n", mean);
167 
168  sums = 0.0;
169  for(i=0;i<n;i++)
170  {
171  sums += ((y[i] - mean) * (y[i] - mean));
172  }
173 
174  sums /= (float)n;
175 
176  if(sums > 0.0)
177  {
178  *rms = sqrt(sums);
179  }
180  else
181  {
182  *rms = 100.0;
183  }
184 
185 // st_print("My rms = %f\n", *rms * 1000.0);
186 
187 #endif
188 
189  return(0);
190 }
191 
192 
193 
195 {
196 // st_print("Resetting Accumulators\n");
197 
198  bzero((char *)&accum_image, sizeof(struct LP_IMAGE_INFO));
199  strcpy(accum_image.name, "ACCUM");
200 
201  bzero((char *)&workingX, sizeof(workingX));
202  bzero((char *)&workingY, sizeof(workingY));
203 
204  workingTsys = 0.0;
205  workingTcal = 0.0;
206  workingTime = 0.0;
207 
208  return(0);
209 }
210 
211 
212 int line_accum(image)
213 struct LP_IMAGE_INFO *image;
214 {
215  int k;
216  float *i, iwt, *o, owt;
217  double raoff, decoff;
218  static double xoff, yoff, roff, doff, noint;
219 
220  if(env->accumreset)
221  {
223 
224  clearFBOffets();
225 
226  strcpy(accum_image.magic, "LP_IMAGE_INFO");
227 
228  bcopy((char *)&image->head, (char *)&accum_image.head, sizeof(accum_image.head));
229 
230  accum_image.ainfo.bscan = (float)image->head.scan;
231 
232  xoff = image->head.az_offset;
233  yoff = image->head.el_offset;
234 
235  roff = image->head.epocra - image->head.xsource;
236  doff = image->head.epocdec - image->head.ysource;
237 
238  noint = image->head.noint;
239 
240  env->avgEl = 0.0;
241  }
242 
243  if(image->head.noint != noint)
244  {
246  {
247  printf("line_accum(%.2f), Rejected: NOINT Differs: %.1f, %.1f\n",
248  image->head.scan, image->head.noint, noint);
249  }
250 
252 
253  return(1);
254  }
255 
256  /* Has user supplied an upper limit on acceptable tsys? */
257  if((env->tsyslimit > 0.0 && image->head.stsys > env->tsyslimit) || gsl_isnan(image->head.stsys))
258  {
260  {
261  printf("line_accum(%.2f), Rejected: TSYS %.1f > TSLimit: %.1f\n",
262  image->head.scan, image->head.stsys, env->tsyslimit);
263  }
264 
266 
267  return(1);
268  }
269 
270  if(!env->ignoremapoff && image->head.az_offset != xoff)
271  {
273  {
274  printf("line_accum(%.2f), Rejected: AZ_OFFSET Differs: %.1f, %.1f\n",
275  image->head.scan, image->head.az_offset*3600.0, xoff*3600.0);
276  }
277 
279 
280  return(1);
281  }
282 
283  if(!env->ignoremapoff && image->head.el_offset != yoff)
284  {
286  {
287  printf("line_accum(%.2f), Rejected: EL_OFFSET Differs: %.1f, %.1f\n",
288  image->head.scan, image->head.el_offset*3600.0, yoff*3600.0);
289  }
290 
292 
293  return(1);
294  }
295 
296  raoff = image->head.epocra - image->head.xsource;
297  decoff = image->head.epocdec - image->head.ysource;
298 
299  if(!env->ignoremapoff && raoff != roff)
300  {
302  {
303  printf("line_accum(%.2f), Rejected: RA_OFFSET Differs: %.1f, %.1f\n",
304  image->head.scan, raoff*3600.0, roff*3600.0);
305  }
306 
308 
309  return(1);
310  }
311 
312  if(!env->ignoremapoff && decoff != doff)
313  {
315  {
316  printf("line_accum(%.2f), Rejected: DEC_OFFSET Differs: %.1f, %.1f\n",
317  image->head.scan, decoff*3600.0, doff*3600.0);
318  }
319 
321 
322  return(1);
323  }
324 
325  if(lp_fcmp(accum_image.head.freqres, image->head.freqres, 0.01 ))
326  {
328  {
329  printf("line_accum(%.2f), Rejected: Acuum Freq Res %.3f vs. Scan Freq Res %.3f, differ\n",
330  image->head.scan, accum_image.head.freqres, image->head.freqres);
331  }
332 
334 
335  return(1);
336  }
337 
338  if(fabs(accum_image.head.epocra - image->head.epocra ) > 0.001 && !env->ignorepos)
339  {
341  {
342  printf("line_accum(%.2f), Rejected: Ra %.3f & %.3f, differ\n",
343  image->head.scan, accum_image.head.epocra, image->head.epocra);
344  }
345 
346  incrementRejRa();
347 
348 
349  return(1);
350  }
351 
352  if(fabs(accum_image.head.epocdec - image->head.epocdec) > 0.001 && !env->ignorepos)
353  {
355  {
356  printf("line_accum(%.2f), Rejected: Dec %.3f & %.3f, differ\n",
357  image->head.scan, accum_image.head.epocdec, image->head.epocdec);
358  }
359 
360  incrementRejDec();
361 
362  return(1);
363  }
364 
365  if((int)accum_image.head.sideband != (int)image->head.sideband )
366  {
368  {
369  printf("line_accum(%.2f), Rejected: Sb %d & %d, differ\n",
370  image->head.scan, (int)accum_image.head.sideband, (int)image->head.sideband);
371  }
372 
373  incrementRejSb();
374 
375  return(1);
376  }
377 
378  if(fabs(accum_image.head.restfreq / 1000.0 - image->head.restfreq / 1000.0) > env->dfreq )
379  {
381  {
382  printf("line_accum(%.2f), Rejected: Rest Freq %.5f & %.5f, differ\n", image->head.scan,
383  accum_image.head.restfreq / 1000.0,
384  image->head.restfreq / 1000.0);
385  }
386 
388 
389  return(1);
390  }
391 
392  if(env->dvel == 0.0) /* Check for uninitialize value */
393  {
394  env->dvel = 0.001;
395  }
396 
397  if(fabs(accum_image.head.refpt_vel - image->head.refpt_vel) > env->dvel && !env->ignorepos)
398  {
400  {
401  printf("line_accum(%.2f), Rejected: Vel %.3f & %.3f, differ\n",
402  image->head.scan, accum_image.head.refpt_vel, image->head.refpt_vel);
403  }
404 
405  incrementRejVel();
406 
407  return(1);
408  }
409 
410  /* Do a weighted average base on integration_time / tsys^2 */
411 
412  accum_image.ainfo.escan = (float)image->head.scan;
413 
414  workingTime += image->head.inttime;
415  workingTsys += (image->head.stsys * image->head.inttime);
416  workingTcal += (image->head.tcal * image->head.inttime);
417 
418  iwt = image->head.inttime / ( image->head.stsys * image->head.stsys );
419  owt = accum_image.ainfo.wt;
420 
421  i = image->yplot1;
422  o = workingY;
423 
424  for(k=0;k<accum_image.head.noint;k++, i++, o++)
425  {
426  *o = (*o * owt + *i * iwt) / (owt + iwt);
427  }
428 
429  accum_image.ainfo.wt += iwt;
430  accum_image.ainfo.escan = (float)image->head.scan;
432 
433  env->avgEl += image->head.el;
434 
435  printScan(&image->head, 0);
436 
437  env->accumreset = 0; /* Don't reset again until told to */
438 
439  return(0);
440 }
441 
442 
444 {
445  int i, j = 0, indx, cols, rows;
446  struct HEADER *p;
447  double ret;
448  char tmp[80], tbuf[256];
449 
451 
452  env->accumreset = 1; /* Reset accumalators */
453 
454  getTerminalSize(&cols, &rows);
455 
456  rows -= 2;
457 
458  resetRejections();
459 
460  freeX();
461  freeY();
462 
463  /* Clear the titleBlock which may contain out-dated info */
464  sprintf(tbuf, "titleblock /c");
465  parseCmd(tbuf);
466 
467 // if(env->markers == 0)
468 // {
469 // env->markers = 16;
470 // st_report("Setting Markers to Default: %d", env->markers);
471 // }
472 
473  st_report("Spectral Line Accum");
474 
475  if(env->autobad)
476  {
477  st_report("Flagged Bad Channels will be removed");
478  }
479 
480  if(!env->numofscans)
481  {
482  st_warn("No Valid Data Files Loaded");
483 
484  env->accumreset = 1;
485 
486  return(1);
487  }
488 
489  if(env->accumreset)
490  {
492  {
493  if(env->freq > 0.0)
494  {
495  st_report("Looking for scans using Freq = %.3f +/- %3.3f MHz", env->freq, env->dfreq*1000.0);
496  }
497  else
498  {
499  st_report("Looking for scans using ALL Freqs");
500  }
501 
502  if(env->check_date)
503  {
504  st_report("Looking for scans taken on %.4f", env->date);
505  }
506  else
507  {
508  st_report("Looking for scans taken on ALL dates");
509  }
510 
511  if(env->check_source)
512  {
513  st_report("Looking for scans on %s", env->source);
514  }
515  else
516  {
517  st_report("Looking for scans on ALL Sources");
518  }
519 
520  if(env->check_scans)
521  {
522  st_report("Looking for scans starting at: %.2f up to %.2f", env->bscan, env->escan);
523  }
524  else
525  {
526  st_report("Looking for Entire Range of scan numbers");
527  }
528 
529  switch(env->bkmatch)
530  {
531  case BKMATCH_FEED:
532  st_report("Looking for scans ending in %.2f", env->if_feed);
533  break;
534 
535  case BKMATCH_RESOLUTION:
536  st_report("Looking for scans with backend resolution: %.3f", env->bkres);
537  break;
538 
539  case BKMATCH_NAME:
540  st_report("Looking for scans with backend name: %s", env->backend);
541  break;
542 
543  case BKMATCH_NAMERES:
544  st_report("Looking for scans with backend name: %s & backend resolution: %.3f", env->backend, env->bkres);
545  break;
546  }
547  }
548 
549  env->dobaseline = 0;
550  }
551 
552  p = &sa[0];
553  indx = 0;
554 
555  for(i=0;i<env->numofscans;i++,p++)
556  {
558  {
559  printf("Passing Scan %.2f to meetsCritiria(): ", p->scan);
560  }
561 
562  /* Check the most obvious critiria */
563  if(!meetsCritiria(p, CHECK_ALL))
564  {
565  continue;
566  }
567 
568  /* Check for proper LINE* Mode */
569  if(strncmp(p->obsmode, "LINEBSP", 7) &&
570  strncmp(p->obsmode, "LINEPS", 6) &&
571  strncmp(p->obsmode, "LINEFS", 6) &&
572  strncmp(p->obsmode, "LINETPON", 8) &&
573  strncmp(p->obsmode, "LINEAPS", 7)) /* We only process BSP, APS & PS so far; treat FS the same */
574  {
576  continue; /* Not Spectral */
577  }
578 
579  if(p->openpar[5] == 5555.5) /* a BSP focal */
580  {
581  continue; /* Ignore */
582  }
583 
584  /* Is this scan ignored??? */
585  if(isScanIgnored(p->scan))
586  {
588  continue;
589  }
590 
591  if(!env->allow_five_pt && isSpecFivePoint(p))
592  {
594  continue;
595  }
596 
597  /* Made it this far; read it in */
598  ret = read_scan(p->scan, env->filename, h0->yplot1, &h0->head, env->autobad);
599  env->curScan = p->scan;
600 
601  if(ret > 0.0)
602  {
603  if(!(j%rows))
604  {
605  st_print("%s Res Xoff Yoff\n", listHeader);
606  j = 1;
607  }
608 
609  /* Go accum this scan */
610  if(!line_accum(h0))
611  {
612  indx++; /* Accum went well */
613  j++;
614  }
615  }
616  }
617 
618  if(indx == 0)
619  {
620  st_print("No Scans Found Matching Search Criteria\n");
621 
622  env->last_scan_count = 0;
623 
624  printRejections();
625 
626  return(1);
627  }
628 
629  env->avgEl /= (double)indx;
630 
631  /* Normalize the accum's */
632 
637 
639  bcopy((char *)&env->baselines, (char *)&accum_image.binfo.baselines, sizeof(accum_image.binfo.baselines));
640 
641  st_report(" ");
642 
643  st_print("%s Avg Tsys: %.1f for %d scans; ", prompt,
646 
648 
649  if(accum_image.head.inttime / 60.0 > 120)
650  {
651  st_print("%.2f Hours Int Time\n", accum_image.head.inttime / 3600.0);
652  }
653  else
654  {
655  st_print("%.2f Minutes Int Time\n", accum_image.head.inttime / 60.0);
656  }
657 
658  /* now copy the workingY into the image struct */
659 
660  for(i=0;i<accum_image.head.noint;i++)
661  {
662  accum_image.yplot1[i] = workingY[i];
663  }
664 
666 
667  strcpy(tmp, h0->name); /* Save the name first */
668  bcopy((char *)&accum_image, (char *)h0, sizeof(struct LP_IMAGE_INFO));
669  strcpy(h0->name, tmp); /* Restore the name */
670 
671  h0->narray = 1;
672  h0->nsize = h0->head.noint * sizeof(float);
673 
675  h0->head.fscan = h0->ainfo.bscan;
676  h0->head.lscan = h0->ainfo.escan;
677  h0->head.rms = env->rms;
678 
679  linePlot(h0);
680 
681  env->accumreset = 1;
682 
683  return(0);
684 }
685 
686 
687 
688 
695 struct LP_IMAGE_INFO *image;
696 {
697  int i;
698  float *f;
699  /* redetermine min and max */
700  image->datamax = -9999999999.9;
701  image->datamin = 9999999999.0;
702 
703  f = &image->yplot1[env->bdrop];
704  for(i=env->bdrop;i<image->head.noint-env->edrop;i++,f++)
705  {
706  if(*f > image->datamax)
707  {
708  image->datamax = *f;
709  image->peakChan = env->peakChan = i;
710  }
711 
712  if(*f < image->datamin)
713  {
714  image->datamin = *f;
715  }
716  }
717 
718  if(fabs(image->datamax - image->datamin) < DATASPREAD)
719  {
720  st_print("Scan #%7.2f is all %.4f\n", image->head.scan, image->datamin);
721 
722  image->datamin -= 1.0;
723  image->datamax += 1.0;
724 
725  return(1);
726  }
727 
728  env->datamin = image->datamin;
729  env->datamax = image->datamax;
730 
731  return(0);
732 }
733 
734 
735 int processSpectra(image)
736 struct LP_IMAGE_INFO *image;
737 {
738 
739  return(0);
740 }
741 
742 
743 int line_display_spectra(image, plot)
744 struct LP_IMAGE_INFO *image;
745 int plot;
746 {
747  if(env->procspec)
748  {
749  if(processSpectra(image))
750  {
751  return(1);
752  }
753  }
754 
755  line_removeBadChans(image, 1);
756 
757  image->narray = 1;
758 
759  if(isSet(PF_F_FLAG)) /* Spec focus contains several plots */
760  {
761  image->head.noint = image->head.datalen / sizeof(float);
762  }
763 
764  image->nsize = image->head.noint * sizeof(float);
765 
766  linePlot(image);
767 
768  return(0);
769 }
770 
771 
772 
774 struct LP_IMAGE_INFO *image;
775 {
776  int i;
777  float *f, *g;
778 
779  if(env->rm_fit_data && image->pinfo.bplot)
780  {
781  f = &image->yplot1[0];
782  g = &image->bplot[0];
783 
784  for(i=0;i<image->head.noint;i++,f++,g++)
785  {
786  *f = *f - *g;
787  }
788 
789  env->rm_fit_data = image->pinfo.bplot = 0;
790 
791  image->yplot1[0] = 0.0; /* Most times the 0'th entry cant be removed */
792  }
793 
794  return(0);
795 }
796 
797 
798  /* Draw the plot */
799 int linePlot(image)
800 struct LP_IMAGE_INFO *image;
801 {
802  if(image->head.noint == 0.0)
803  {
804  st_fail("Nothing in Array %s to Display", image->name);
805  return(0);
806  }
807 
808  st_report("Displaying Plot: %s", image->name);
809 
810  copyEnv2Image(image);
811 
812  /* Go fill in x-axis values */
813  computeXaxis(image, 0);
814 
815  line_determine_min_max(image);
816 
817 /* Check if we are running external viewer */
818  if(xgraphic)
819  {
820  sendImageStruct(image, env->mode);
821 
822  validate(BSP);
823 
824  return(0);
825  }
826  else
827  {
828  st_report("No connection to xgraphic to send plot");
829  }
830 
831  return(0);
832 }
833 
834 
836 {
837  float s;
838 
839  if(strlen(args->secondArg))
840  {
841  s = atof(args->secondArg);
842 
843  s = floor(s);
844 
845  subArgs(2, "%.2f", s+0.01);
846 
847  getScan(1);
848 
849  showScan();
850  }
851 
852  return(0);
853 }
854 
855 
857 {
858  float s;
859 
860  if(strlen(args->secondArg))
861  {
862  s = atof(args->secondArg);
863 
864  s = floor(s);
865 
866  if(env->issmt)
867  {
868  subArgs(2, "%.2f", s+0.02);
869  }
870  else
871  {
872  subArgs(2, "%.2f", s+0.03);
873  }
874 
875  getScan(1);
876 
877  showScan();
878  }
879 
880  return(0);
881 }
882 
883 
884 int setHWDC(image)
885 struct LP_IMAGE_INFO *image;
886 {
887 
888  if(!strncmp(image->head.backend, "ARO", 3))
889  {
890  env->hwdc = 1.0;
891  }
892  else
893  if(!strncmp(image->head.backend, "MAC", 3) || !strncmp(image->head.backend, "HS_", 3))
894  {
895  env->hwdc = 1.0;
896  }
897  else
898  if(!strncmp(image->head.backend, "FFB", 3))
899  {
900  env->hwdc = 1.0;
901  }
902  else
903  {
904  env->hwdc = 0.9;
905  }
906 
907  st_report("Auto Setting HWDC to: %.3f", env->hwdc);
908 
909  return(0);
910 
911 }
912 
913 
914 /* Unipops: 2.0*stsys/(abs(freqres)*1.0e6*inttime)^0.5
915  */
916 int printRMS()
917 {
918  int ret;
919  double sq;
920 
921  struct LP_IMAGE_INFO *image = h0;
922 
923  /* Go compute the baseline which computes
924  the rms of the baseline region */
925  ret = computeBaseLine(image);
926 
927  if(env->hwdc < 0.1)
928  {
929  setHWDC(image);
930  }
931 
932  sq = sqrt(fabs(image->head.freqres) * 1e6 * image->head.inttime * env->hwdc);
933 
934  if(sq > 0.0)
935  {
936  env->trms = image->head.stsys * 2.0 / sq;
937 
938  env->p2p = env->rms / sin(45.0 * CTR);
939  }
940  else
941  {
942  st_fail("sqrt(freqres * inttime * hwdc) = %f", sq);
943  env->trms = 99999.0;
944  }
945 
946  st_report("Using HWDC: %.3f", env->hwdc);
947 
948 
949  sprintf(rmsResultsStr, "%.2f / %.2f mK over %d chans; Factor: %f",
950  env->rms * 1000.0, env->trms * 1e3, ret,
951  env->rms / env->trms);
952 
953  st_report("Computed rms = %s", rmsResultsStr);
954 
955  if(isSet(PF_P_FLAG))
956  {
957  st_report("Computed P2P = %.2f mK", env->p2p * 1e3);
958  }
959 
961 
962  return(0);
963 }
964 
965 
966 int selfRej()
967 {
968  double ratio;
969 
970  if(strlen(args->secondArg))
971  {
972  ratio = atof(args->secondArg);
973 
974  if(env->rms / env->trms > ratio)
975  {
976  st_fail("Scan %.2f BAD", h0->head.scan);
977 
978  addIgnore(h0->head.scan);
979  }
980  }
981 
982  return(0);
983 }
984 
985 
986 int clearRMS()
987 {
988  env->rms = 0.0;
989  env->slope = 0.0;
990  env->intercept = 0.0;
991 
992  return(0);
993 }
994 
995 
996 
998 {
999  int i, bc, ec, eFlag = 0, first=1;
1000  struct LP_IMAGE_INFO *image = h0;
1001 
1002  eFlag = isSet(PF_EXP_FLAG);;
1003 
1004  bc = env->bdrop;
1005  ec = image->head.noint - env->edrop;
1006 
1007  if(image->head.noint > 0)
1008  {
1009  for(i=bc;i<ec;i++)
1010  {
1011  if(first || !(i%8))
1012  {
1013  first = 0;
1014  st_print("\n%5d: ", i);
1015  }
1016 
1017  if(eFlag)
1018  {
1019  st_print("%14.6e ", image->yplot1[i]);
1020  }
1021  else
1022  {
1023  st_print("%10.6f ", image->yplot1[i]);
1024  }
1025  }
1026 
1027  st_print("\n");
1028  }
1029  else
1030  {
1031  st_fail("No data loaded");
1032  }
1033 
1034  return(0);
1035 }
1036 
1037 
1038 int line_MinMax(image)
1039 struct LP_IMAGE_INFO *image;
1040 {
1041  int i;
1042  float *f, min, max;
1043 
1044  max = -1.0e127; /* there are probably standard macros, but this works */
1045  min = 9.99e127;
1046 
1047  f = &image->yplot1[0];
1048  for(i=0;i<image->head.noint;i++) /* compute min and max */
1049  {
1050  if(f[i] > max)
1051  {
1052  max = f[i];
1053  }
1054  else
1055  if(f[i] < min)
1056  {
1057  min = f[i];
1058  }
1059  }
1060 
1061  image->datamin = min;
1062  image->datamax = max;
1063 
1064  st_report("Max = %f, Min = %f", image->datamax, image->datamin);
1065 
1066  return(0);
1067 }
1068 
1069 
1070 
1072 {
1073  int n;
1074  double from, to, diff, freeD, wireD;
1075 
1076  n = getNumericResponse("Enter Number of Cycles to Measure: ");
1077 
1078  _doTCur("Click the Left Mouse Button on First Peak");
1079  from = env->fcur;
1080 
1081  _doTCur("Click the Left Mouse Button on Last Peak");
1082  to = env->fcur;
1083 
1084  diff = fabs(from - to);
1085 
1086  diff *= 1e6; /* Convert to Hz */
1087 
1088  diff /= (double)n; /* Reduce to one cycle */
1089 
1090  freeD = 1.0 / diff * SPEED_OF_LIGHT;
1091  wireD = 1.0 / diff * SPEED_OF_LIGHT_COAX;
1092 
1093  freeD /= 2.0;
1094  wireD /= 2.0;
1095 
1096  st_report("Spacing: %7.3f MHz", diff / 1e6);
1097  st_report("Free Space Distance: %7.3f Meters", freeD);
1098  st_report("Coaxial Wire Distance: %7.3f Meters", wireD);
1099 
1100  return(0);
1101 }
1102 
1103 
1105 {
1106  if(args->ntokens > 1)
1107  {
1109  }
1110  else
1111  {
1112  showAverage(NULL);
1113  }
1114 
1115  return(0);
1116 }
1117 
1118 int showAverage(buf)
1119 char *buf;
1120 {
1121  int i, n, j=0;
1122  double avg = 0.0, ptmb = 0.0, rejs[4];
1123  struct LP_IMAGE_INFO *image = h0;
1124 
1125  for(i=0;i<4;i++)
1126  {
1127  rejs[i] = 1.0 / (1.0 + pow(10.0, -1.0 * env->rejections[i] / 10.0));
1128  }
1129 
1130  if(isPlanet(env->source))
1131  {
1132  st_report("Source is Planet");
1133 
1134  getPlanet();
1135 
1136  if(!strcasecmp(env->source, "Mercury"))
1137  {
1138  ptmb = env->mercury_tmb;
1139  }
1140  else
1141  if(!strcasecmp(env->source, "Venus"))
1142  {
1143  ptmb = env->venus_tmb;
1144  }
1145  else
1146  if(!strcasecmp(env->source, "Mars"))
1147  {
1148  ptmb = env->mars_tmb;
1149  }
1150  else
1151  if(!strcasecmp(env->source, "Jupiter"))
1152  {
1153  ptmb = env->jupiter_tmb;
1154  }
1155  else
1156  if(!strcasecmp(env->source, "Saturn"))
1157  {
1158  ptmb = env->saturn_tmb;
1159  }
1160  else
1161  if(!strcasecmp(env->source, "Uranus"))
1162  {
1163  ptmb = env->uranus_tmb;
1164  }
1165  else
1166  if(!strcasecmp(env->source, "Neptune"))
1167  {
1168  ptmb = env->neptune_tmb;
1169  }
1170  }
1171 
1172  if(env->mode == MODE_SPEC || env->mode == MODE_OTF) /* Examining Calibrate works the same */
1173  {
1174  if(isSet(PF_B_FLAG)) /* Use only baseline regions */
1175  {
1176  if(isSet(PF_S_FLAG))
1177  {
1178  j = computeEachBaseLine(h0);
1179  avg = env->rst;
1180  }
1181  else
1182  {
1183  setFlag(PF_N_FLAG, 1);
1184 
1185  j = computeBaseLine(h0);
1186 
1187  setFlag(PF_N_FLAG, 0);
1188 
1189  avg = env->rst;
1190  }
1191  }
1192 
1193  if(j == 0) /* Because computeBaseLine() can return 0 if no baselines defined */
1194  {
1195  n = image->head.noint;
1196 
1197  for(i=env->bdrop;i<(n-env->edrop);i++)
1198  {
1199  avg += image->yplot1[i];
1200  j++;
1201  }
1202 
1203  avg /= (double)j;
1204  }
1205 
1206  if(buf)
1207  {
1208  st_report("Average of %s, using %d channels: %.6fK", buf, j, avg);
1209  }
1210  else
1211  {
1212  st_report("Average Bandpass Temperature, using %d channels: %.6fK", j, avg);
1213  }
1214 
1215  env->bp_avg = avg;
1216 
1217  if(ptmb > 0.0) /* It's a planet? */
1218  {
1219  st_report("Using Rejections Coeff: %f %f %f %f", rejs[0], rejs[1], rejs[2], rejs[3]);
1220 
1221  st_report("Tmb of %s: %.2fK", env->source, ptmb);
1222 
1223  env->beam_eff = env->bp_avg / ptmb * 100.0 * rejs[0];
1224 
1225  st_report("Beam Eff for %s: %.2f%%", env->source, env->beam_eff);
1226  }
1227  }
1228  else
1229  if(env->mode == MODE_CONT)
1230  {
1231  if(ptmb > 0.0)
1232  {
1233  st_print(" Channel: 1 2 3 4\n");
1234 
1235  st_print(" Average Tr: %9.4f %9.4f %9.4f %9.4f\n",
1236  local_ars.avgTr[0],
1237  local_ars.avgTr[1],
1238  local_ars.avgTr[2],
1239  local_ars.avgTr[3]);
1240 
1241  st_print(" Planet Temp: %9.4f %9.4f %9.4f %9.4f\n",
1242  ptmb, ptmb, ptmb, ptmb);
1243 
1244  st_print("Main Beam Eff: %9.2f %9.2f %9.2f %9.2f\n",
1245  local_ars.avgTr[0] / ptmb * 100.0 * rejs[0],
1246  local_ars.avgTr[1] / ptmb * 100.0 * rejs[1],
1247  local_ars.avgTr[2] / ptmb * 100.0 * rejs[2],
1248  local_ars.avgTr[3] / ptmb * 100.0 * rejs[3]);
1249 
1250  st_print(" Rejections: %9d %9d %9d %9d\n",
1251  (int)env->rejections[0],
1252  (int)env->rejections[1],
1253  (int)env->rejections[2],
1254  (int)env->rejections[3]);
1255 
1256  }
1257  }
1258 
1259  return(0);
1260 }
1261 
1262 
1263 
1264 int doPshow()
1265 {
1266  int nsize;
1267  double s, min=999999.9, max=-999999.9, min1, min2, max1, max2;
1268  double diff = 0.01;
1269 
1270  if(strlen(args->secondArg))
1271  {
1272  doPageCmd();
1273 
1274  clearAllImages();
1275 
1276  s = atof(args->secondArg);
1277 
1278  subArgs(2, "%.2f", s);
1279  _h0(); /* Point to H0 */
1280 
1281  if(getScan(1))
1282  {
1283  return(1);
1284  }
1285 
1286  line_removeBadChans(h0, 1);
1287 
1288  if(isSet(PF_B_FLAG))
1289  {
1290  st_report("Removing Baselines");
1291 
1292  env->dobaseline = 1;
1293 
1295  }
1296 
1297  if(isSet(PF_I_FLAG))
1298  {
1299  doSpecInvert();
1300  }
1301 
1302  line_MinMax(h0);
1303 
1304  min1 = h0->datamin;
1305  max1 = h0->datamax;
1306  if(min1 < min)
1307  {
1308  min = min1;
1309  }
1310  if(max1 > max)
1311  {
1312  max = max1;
1313  }
1314 
1315  if(!strncmp(h0->head.backend, "FB_2", 4))
1316  {
1317  diff = 0.02; /* Filters in series inciments by 0.02 */
1318  }
1319 
1320  subArgs(2, "%.2f", s + diff);
1321  _h1(); /* Point to H1 */
1322 
1323  if(getScan(1))
1324  {
1325  return(1);
1326  }
1327 
1328  line_removeBadChans(h0, 1);
1329 
1330  if(isSet(PF_B_FLAG))
1331  {
1332  st_report("Removing Baselines");
1333 
1334  env->dobaseline = 1;
1335 
1337  }
1338 
1339  if(isSet(PF_I_FLAG))
1340  {
1341  doSpecInvert();
1342  }
1343 
1344  line_MinMax(h0);
1345 
1346  min2 = h0->datamin;
1347  max2 = h0->datamax;
1348  if(min2 < min)
1349  {
1350  min = min2;
1351  }
1352  if(max2 > max)
1353  {
1354  max = max2;
1355  }
1356 
1357  nsize = h0->head.noint * sizeof(float);
1358 
1359  env->ylower = min;
1360  env->yupper = max;
1362  H0.nsize = nsize;
1363  H0.narray = 2; /* Let xgraphic know there are 2 arrays */
1364 
1365  bcopy((char *)&H1.yplot1, (char *)&H0.yplot2, nsize); /* Copy H1 array to H0's yplot2 */
1366 
1367  _h0(); /* Point back to H0 */
1368 
1369  linePlot(h0); /* Plot it */
1370  }
1371  else
1372  {
1373  st_fail("Missing arg to pshow");
1374  return(1);
1375  }
1376 
1377  return(0);
1378 }
1379 
1380 
1381 
1383 {
1384  if(env->mode == MODE_SPEC)
1385  {
1386  line_removeBadChans(h0, 1);
1387  }
1388 
1389  return(0);
1390 }
1391 
1392 
1396 int doQshow()
1397 {
1398  int i, nsize;
1399  double s, minT=999999.9, maxT=-999999.9, min[4], max[4];
1400  double frac[] = { 0.00, 0.01, 0.02, 0.03 };
1401 
1402  if(strlen(args->secondArg))
1403  {
1404  doPageCmd();
1405 
1406  clearAllImages();
1407 
1408  s = atof(args->secondArg);
1409 
1410 /* First */
1411  for(i=0;i<4;i++)
1412  {
1413  switch(i)
1414  {
1415  case 0: _h0(); /* Point to H0 */ break;
1416  case 1: _h1(); /* Point to H1 */ break;
1417  case 2: _h2(); /* Point to H2 */ break;
1418  case 3: _h3(); /* Point to H3 */ break;
1419  }
1420 
1421  subArgs(2, "%.2f", s + frac[i]);
1422 
1423  if(getScan(1))
1424  {
1425  return(1);
1426  }
1427 
1428  line_removeBadChans(h0, 1);
1429 
1430  if(isSet(PF_B_FLAG))
1431  {
1432  st_report("Removing Baselines");
1433 
1434  env->dobaseline = 1;
1435 
1437  }
1438 
1439  if(isSet(PF_I_FLAG))
1440  {
1441  doSpecInvert();
1442  }
1443 
1444  line_MinMax(h0);
1445 
1446  min[i] = h0->datamin;
1447  max[i] = h0->datamax;
1448  if(min[i] < minT)
1449  {
1450  minT = min[i];
1451  }
1452  if(max[i] > maxT)
1453  {
1454  maxT = max[i];
1455  }
1456 
1457  strncpy(H0.mhp[i].backend, h0->head.backend, 8);
1458  H0.mhp[i].backend[8] = '\0';
1459 
1460  H0.mhp[i].scan = h0->head.scan;
1461  H0.mhp[i].restfreq = h0->head.restfreq;
1462  H0.mhp[i].stsys = h0->head.stsys;
1463  H0.mhp[i].tcal = h0->head.tcal;
1464  H0.mhp[i].freqres = h0->head.freqres;
1465  H0.mhp[i].sideband = h0->head.sideband;
1466  H0.mhp[i].refpt = h0->head.refpt;
1467  H0.mhp[i].refpt_vel = h0->head.refpt_vel;
1468  H0.mhp[i].deltax = h0->head.deltax;
1469  }
1470 
1471  _h0(); /* Point back to H0 */
1472 
1473  nsize = h0->head.noint * sizeof(float);
1474 
1475  env->ylower = minT;
1476  env->yupper = maxT;
1478  H0.nsize = nsize;
1479  H0.narray = 4; /* Let xgraphic know there are 2 arrays */
1480 
1481  bcopy((char *)&H1.yplot1, (char *)&H0.yplot2, nsize); /* Copy H1 array to H0's yplot2 */
1482  bcopy((char *)&H2.yplot1, (char *)&H0.yplot3, nsize); /* Copy H2 array to H0's yplot3 */
1483  bcopy((char *)&H3.yplot1, (char *)&H0.yplot4, nsize); /* Copy H3 array to H0's yplot4 */
1484 
1485  linePlot(h0); /* Plot it */
1486  }
1487  else
1488  {
1489  st_fail("Missing arg to pshow");
1490 
1491  return(1);
1492  }
1493 
1494  return(0);
1495 }
1496 
1497 
1498 int do_psc()
1499 {
1500  int i, save_bkmatch, save_ckfeed, req[2];
1501  int nsize, first=1, rb = 0;
1502  double minT=999999.9, maxT=-999999.9, min[4], max[4];
1503 
1504  /* Check if user wants baselines removed */
1505  if(isSet(PF_B_FLAG))
1506  {
1507  rb = 1;
1508  st_report("Removing Baselines from Plots");
1509  }
1510 
1511  /* save environment */
1512  save_bkmatch = env->bkmatch;
1513  save_ckfeed = env->check_feed;
1514 
1516  env->check_feed = 1;
1517 
1518  if(!strncmp(args->currentCmd, "psc12", 5))
1519  {
1520  req[0] = 1;
1521  req[1] = 2;
1522  }
1523  else
1524  if(!strncmp(args->currentCmd, "psc34", 5))
1525  {
1526  req[0] = 3;
1527  req[1] = 4;
1528  }
1529  else
1530  if(!strncmp(args->currentCmd, "psc13", 5))
1531  {
1532  req[0] = 1;
1533  req[1] = 3;
1534  }
1535  else
1536  if(!strncmp(args->currentCmd, "psc24", 5))
1537  {
1538  req[0] = 2;
1539  req[1] = 4;
1540  }
1541  else
1542  {
1543  req[0] = 0;
1544  req[1] = 0;
1545  }
1546 
1547  _h1(); /* Point to H1 */
1548  for(i=0;i<4;i++)
1549  {
1550  switch(i)
1551  {
1552  case 0:
1553  if(i+1 == req[0] || i+1 == req[1])
1554  {
1555  showC1();
1556 
1557  if(rb)
1558  {
1559  doBaseline();
1560  }
1561 
1562  line_MinMax(h0);
1563 
1564  min[i] = h0->datamin;
1565  max[i] = h0->datamax;
1566  if(min[i] < minT)
1567  {
1568  minT = min[i];
1569  }
1570  if(max[i] > maxT)
1571  {
1572  maxT = max[i];
1573  }
1574 
1575  nsize = h0->head.noint * sizeof(float);
1576 
1577  if(first)
1578  {
1579  _copyImage(h0, &H0);
1580 
1581  _h2(); /* Point to H2 */
1582 
1583  first = 0;
1584  }
1585  else
1586  {
1587  bcopy((char *)&h0->yplot1, (char *)&H0.yplot2, nsize); /* Copy H1 array to H0's yplot2 */
1588  }
1589  }
1590  break;
1591 
1592  case 1:
1593  if(i+1 == req[0] || i+1 == req[1])
1594  {
1595  showC2();
1596 
1597  if(rb)
1598  {
1599  doBaseline();
1600  }
1601 
1602  line_MinMax(h0);
1603 
1604  min[i] = h0->datamin;
1605  max[i] = h0->datamax;
1606  if(min[i] < minT)
1607  {
1608  minT = min[i];
1609  }
1610  if(max[i] > maxT)
1611  {
1612  maxT = max[i];
1613  }
1614 
1615  nsize = h0->head.noint * sizeof(float);
1616 
1617  if(first)
1618  {
1619  _copyImage(h0, &H0);
1620 
1621  _h2(); /* Point to H2 */
1622 
1623  first = 0;
1624  }
1625  else
1626  {
1627  bcopy((char *)&h0->yplot1, (char *)&H0.yplot2, nsize); /* Copy H1 array to H0's yplot2 */
1628  }
1629  }
1630  break;
1631 
1632  case 2:
1633  if(i+1 == req[0] || i+1 == req[1])
1634  {
1635  showC3();
1636 
1637  if(rb)
1638  {
1639  doBaseline();
1640  }
1641 
1642  line_MinMax(h0);
1643 
1644  min[i] = h0->datamin;
1645  max[i] = h0->datamax;
1646  if(min[i] < minT)
1647  {
1648  minT = min[i];
1649  }
1650  if(max[i] > maxT)
1651  {
1652  maxT = max[i];
1653  }
1654 
1655  nsize = h0->head.noint * sizeof(float);
1656 
1657  if(first)
1658  {
1659  _copyImage(h0, &H0);
1660 
1661  _h2(); /* Point to H2 */
1662 
1663  first = 0;
1664  }
1665  else
1666  {
1667  bcopy((char *)&h0->yplot1, (char *)&H0.yplot2, nsize); /* Copy H1 array to H0's yplot2 */
1668  }
1669  }
1670  break;
1671 
1672  case 3:
1673  if(i+1 == req[0] || i+1 == req[1])
1674  {
1675  showC4();
1676 
1677  if(rb)
1678  {
1679  doBaseline();
1680  }
1681 
1682  line_MinMax(h0);
1683 
1684  min[i] = h0->datamin;
1685  max[i] = h0->datamax;
1686  if(min[i] < minT)
1687  {
1688  minT = min[i];
1689  }
1690  if(max[i] > maxT)
1691  {
1692  maxT = max[i];
1693  }
1694 
1695  nsize = h0->head.noint * sizeof(float);
1696 
1697  if(first)
1698  {
1699  _copyImage(h0, &H0);
1700 
1701  _h2(); /* Point to H2 */
1702 
1703  first = 0;
1704  }
1705  else
1706  {
1707  bcopy((char *)&h0->yplot1, (char *)&H0.yplot2, nsize); /* Copy H1 array to H0's yplot2 */
1708  }
1709  }
1710  break;
1711  }
1712  }
1713 
1714  env->ylower = minT;
1715  env->yupper = maxT;
1717  H0.nsize = nsize;
1718  H0.narray = 2; /* Let xgraphic know there are 2 arrays */
1719 
1720  _h0(); /* Point back to H0 */
1721 
1722  h0->ainfo.escan = H2.ainfo.escan; /* Tag the last scan */
1723 
1724  linePlot(h0); /* Plot it */
1725 
1726  /* restore environment */
1727  env->bkmatch = save_bkmatch;
1728  env->check_feed = save_ckfeed;
1729 
1730  return(0);
1731 }
1732 
1733 
1734 int doBzero()
1735 {
1736  int i, n;
1737 
1738  if(strlen(args->secondArg))
1739  {
1740  n = atoi(args->secondArg);
1741 
1742  if(n > 0 && n < h0->head.noint)
1743  {
1744  st_report("Zeroing out %d channels at beginning of data", n);
1745 
1746  for(i=0;i<n;i++)
1747  {
1748  h0->yplot1[i] = 0.0;
1749  }
1750  }
1751  else
1752  if(n < 0 && abs(n) < h0->head.noint)
1753  {
1754  n = abs(n);
1755 
1756  st_report("Zeroing out %d channels at end of data", n);
1757 
1758  for(i=h0->head.noint-n;i<h0->head.noint;i++)
1759  {
1760  h0->yplot1[i] = 0.0;
1761  }
1762  }
1763 
1764  }
1765 
1766  return(0);
1767 }
1768 
1769 
1770 /* Invert the spectra in h0;
1771  Copied from unipops/source/conline/line/au2.F
1772  */
1774 {
1775  int i, noint;
1776  float *s, *d, hold[MAX_CHANS];
1777 
1778  noint = h0->head.noint;
1779 
1780  st_report("Inverting %d Spectal Data", noint);
1781 
1782  /* Save the data */
1783  bcopy((char *)&h0->yplot1[0], (char *)&hold[0], sizeof(float)*noint);
1784 
1785  /* Invert the data */
1786  s = &hold[noint-1];
1787  d = &h0->yplot1[0];
1788  for(i=0;i<noint;i++,d++,s--)
1789  {
1790  *d = *s;
1791  }
1792 
1793  /* fix header variables */
1794 
1795  h0->head.deltax *= -1.0;
1796  h0->head.refpt = h0->head.noint - h0->head.refpt + h0->head.spn;
1797  h0->head.freqres *= -1.0;
1798 
1799  return(0);
1800 }
1801 
1802 /* OSB -- Other Side Band
1803 
1804  Copied from unipops/source/conline/line/au8.F
1805 
1806  */
1807 
1808 int doOSB()
1809 {
1810  struct HEADER *h;
1811  double fshift;
1812 
1813  h = &h0->head;
1814 
1815  /* flip sign of c12fr, and c12dx */
1816  h->freqres *= -1.0;
1817  h->deltax *= -1.0;
1818 
1819  /* recalculate the frequencies, first the shift */
1820  if(h->sideband == 0.0 || h->sideband == 2.0) /* USB -> LSB */
1821  {
1822  fshift = -2.0 * h->firstif;
1823  }
1824  else /* LSB -> USB */
1825  {
1826  fshift = 2.0 * h->firstif;
1827  }
1828 
1829  if(h->obsfreq != 0.0)
1830  {
1831  h->restfreq = h->restfreq * (1.0 + fshift / h->obsfreq);
1832  }
1833  else
1834  {
1835  h->restfreq = h->restfreq + fshift;
1836  }
1837 
1838  /* then the center freq, which is just a straight shift */
1839  h->obsfreq = h->obsfreq + fshift;
1840 
1841  /* reset the sideband value */
1842  if(h->sideband == 0.0)
1843  {
1844  h->sideband = 1.0;
1845  }
1846  else
1847  if(h->sideband == 1.0)
1848  {
1849  h->sideband = 0.0;
1850  }
1851  else
1852  if(h->sideband == 2.0)
1853  {
1854  h->sideband = 3.0;
1855  }
1856  else
1857  {
1858  h->sideband = 2.0;
1859  }
1860 
1861  /* and set/unset a flag in class 10 */
1862  /* I don't care to do this as; well don't see any need to */
1863  /* OK, talked me into it; set a flag in openpar[0] */
1864 
1865  if(h->openpar[0] == 54321.12345)
1866  {
1867  h->openpar[0] = 0.0;
1868  }
1869  else
1870  {
1871  h->openpar[0] = 54321.12345;
1872  }
1873 
1874  return(0);
1875 }
1876 
1877 #define SIN_PAT 1
1878 #define COS_PAT 2
1879 #define TAN_PAT 3
1880 #define SQR_PAT 4
1881 
1883 {
1884  int i, n, pat = SIN_PAT;
1885  float *f;
1886  double freq, fr, f2, f1, nchans, delta;
1887 
1888  if(args->ntokens < 2)
1889  {
1890  st_fail("Missing args for fillpattern: Usage: fillpattern freq");
1891 
1892  return(1);
1893  }
1894 
1895  if(isSet(PF_S_FLAG))
1896  {
1897  pat = SIN_PAT;
1898  }
1899 
1900  if(isSet(PF_T_FLAG))
1901  {
1902  pat = TAN_PAT;
1903  }
1904 
1905  if(isSet(PF_C_FLAG))
1906  {
1907  pat = COS_PAT;
1908  }
1909 
1910  if(isSet(PF_Q_FLAG))
1911  {
1912  pat = SQR_PAT;
1913  }
1914 
1915  freq = atof(args->secondArg);
1916  fr = fabs(h0->head.freqres);
1917  n = h0->head.noint;
1918  nchans = freq / fr;
1919  f1 = nchans / 360.0;
1920  delta = 1.0 / f1;
1921 
1922  st_report("freq = %.2f, fr = %.2f, nchans = %.2f, f1 = %.2f, delta = %.2f",
1923  freq, fr, nchans, f1, delta);
1924 
1925  f = &h0->yplot1[0];
1926  f2 = 0.0;
1927  for(i=0;i<n;i++,f++)
1928  {
1929  switch(pat)
1930  {
1931  case SIN_PAT: *f = (float)sin(f2 * DEG_TO_RAD); break;
1932  case COS_PAT: *f = (float)cos(f2 * DEG_TO_RAD); break;
1933  case SQR_PAT:
1934  *f = (float)sin(f2 * DEG_TO_RAD);
1935  if(*f < -0.0)
1936  {
1937  *f = -1.0;
1938  }
1939  if(*f > 0.0)
1940  {
1941  *f = 1.0;
1942  }
1943  break;
1944 
1945  case TAN_PAT:
1946  *f = (float)tan(f2 * DEG_TO_RAD);
1947  if(*f < -10.0)
1948  {
1949  *f = -10.0;
1950  }
1951  if(*f > 10.0)
1952  {
1953  *f = 10.0;
1954  }
1955  break;
1956  }
1957 
1958  f2 += delta;
1959 
1960  if(f2 >= 360.0)
1961  {
1962  f2 = 0.0;
1963  }
1964  }
1965 
1966  return(0);
1967 }
1968 
1969 
1970 /* Set y-azis to 10 * log10(y/peak) */
1972 {
1973  int i, n;
1974  float *p, max=-1e12;
1975 
1976  n = h0->head.noint;
1977 
1978  st_report("Converting %d floats to log-plot", n);
1979 
1980 
1981  p = &h0->yplot1[0];
1982  for(i=0;i<n;i++,p++)
1983  {
1984  if(*p > max)
1985  {
1986  max = *p;
1987  }
1988  }
1989 
1990  p = &h0->yplot1[0];
1991  for(i=0;i<n;i++,p++)
1992  {
1993  *p = 10.0 * log10(*p / max);
1994  }
1995 
1997 
1998  return(0);
1999 }
2000 
2001 
2002 
2004 struct LP_IMAGE_INFO *h;
2005 {
2006  int i, dlen;
2007  char fname[256];
2008  FILE *fp;
2009 
2010  if(args->ntokens < 2)
2011  {
2013 
2014  return(0);
2015  }
2016 
2017  dlen = (int)h->head.noint;
2018 
2019  sprintf(fname, "%s", args->secondArg);
2020 
2021  if((fp = fopen(fname, "w")) == NULL)
2022  {
2023  st_fail("Unable to open %s for writting", fname);
2024 
2025  return(0);
2026  }
2027 
2028  st_report("Saving %d records to: %s", dlen, fname);
2029 
2030  fprintf(fp, "# Scan Number %8.2f\n", h->head.scan);
2031  fprintf(fp, "# Bscan Number %8.2f\n", h->ainfo.bscan);
2032  fprintf(fp, "# Escan Number %8.2f\n", h->ainfo.escan);
2033  fprintf(fp, "# Scan Count %8d\n", h->ainfo.scanct);
2034  fprintf(fp, "# \n");
2035 
2036  for(i=0;i<dlen;i++)
2037  {
2038  fprintf(fp, "%5d %12.6f\n", i, h->yplot1[i]);
2039  }
2040 
2041  fclose(fp);
2042 
2043  return(0);
2044 }
2045 
2046 
2048 {
2049  system("rm -f report.log");
2050 
2051  return(0);
2052 }
2053 
2054 
2055 int writeReport(buf)
2056 char *buf;
2057 {
2058  FILE *fp;
2059  char *fname = "report.log";
2060 
2061  if((fp = fopen(fname, "a")) == NULL)
2062  {
2063  st_fail("Unable to open %s for writting", fname);
2064 
2065  return(0);
2066  }
2067 
2068  fprintf(fp, "%s\n", buf);
2069 
2070  fclose(fp);
2071 
2072  return(0);
2073 }
2074 
2075 
2076 /* Print various scan varibles */
2078 {
2079  int tmp;
2080  char outBuf[256], tbuf[512], src[256];
2081 
2082  if(args->ntokens > 1)
2083  {
2084  if(!strncmp(args->secondArg, "delete", strlen(args->secondArg)))
2085  {
2086  deleteReport();
2087 
2088  return(0);
2089  }
2090  }
2091 
2092  strcpy(outBuf, "REPORT: ");
2093 
2094  if(isSet(PF_O_FLAG))
2095  {
2096  sprintf(src, "%16.16s ", h0->head.object);
2097  strcmprs(src);
2098 
2099  sprintf(tbuf, "Source: %s ", src);
2100  strcat(outBuf, tbuf);
2101  }
2102 
2103  if(isSet(PF_S_FLAG))
2104  {
2105  sprintf(tbuf, "Scan: %.2f ", h0->head.scan);
2106  strcat(outBuf, tbuf);
2107  }
2108 
2109  if(isSet(PF_D_FLAG))
2110  {
2111  sprintf(tbuf, "Date: %.4f ", h0->head.utdate);
2112  strcat(outBuf, tbuf);
2113  }
2114 
2115  if(isSet(PF_U_FLAG))
2116  {
2117  sprintf(tbuf, "UT: %.2f ", h0->head.ut);
2118  strcat(outBuf, tbuf);
2119  }
2120 
2121  if(isSet(PF_L_FLAG))
2122  {
2123  sprintf(tbuf, "LST: %.2f ", h0->head.lst);
2124  strcat(outBuf, tbuf);
2125  }
2126 
2127  if(isSet(PF_A_FLAG))
2128  {
2129  sprintf(tbuf, "Az: %.1f ", h0->head.az);
2130  strcat(outBuf, tbuf);
2131  }
2132 
2133  if(isSet(PF_E_FLAG)) /* El flag */
2134  {
2135  sprintf(tbuf, "El: %.1f ", h0->head.el);
2136  strcat(outBuf, tbuf);
2137  }
2138 
2139  if(isSet(PF_I_FLAG))
2140  {
2141  sprintf(tbuf, "Time: %.0f ", h0->head.inttime);
2142  strcat(outBuf, tbuf);
2143  }
2144 
2145  if(isSet(PF_P_FLAG))
2146  {
2147  sprintf(tbuf, "Pk: %.2f ", env->datamax);
2148  strcat(outBuf, tbuf);
2149  }
2150 
2151  if(isSet(PF_R_FLAG))
2152  {
2153  strcpy(tbuf, "rms"); /* Go compute rms */
2154 
2155  tmp = stquiet;
2156  stquiet = 1;
2157 
2158  parseCmd(tbuf);
2159 
2160  stquiet = tmp;
2161 
2162  sprintf(tbuf, "rms: %.2f mK ", env->rms * 1000.0);
2163  strcat(outBuf, tbuf);
2164  }
2165 
2166  if(isSet(PF_T_FLAG))
2167  {
2168  sprintf(tbuf, "Tsys: %.1f ", h0->head.stsys);
2169  strcat(outBuf, tbuf);
2170  }
2171 
2172  if(isSet(PF_W_FLAG))
2173  {
2174  writeReport(outBuf);
2175  }
2176  else
2177  {
2178  strcat(outBuf, "\n");
2179  st_print(outBuf);
2180  }
2181 
2182  return(0);
2183 }
2184 
2185 
2187 struct HEADER *h;
2188 {
2189  if(h->openpar[8] == 9998.50 || h->openpar[8] == 9999.50)
2190  {
2191  return(1);
2192  }
2193 
2194  return(0);
2195 }
2196 
2197 
2199 {
2200  int i;
2201 
2202  if(args->ntokens > 1)
2203  {
2204  if(strlen(args->secondArg))
2205  {
2206  env->cal_scale = atof(args->secondArg);
2207 
2208  st_report("Scaling Data by %.3f", env->cal_scale);
2209 
2210  h0->head.tcal /= env->cal_scale;
2211  h0->head.stsys /= env->cal_scale;
2212 
2213  for(i=0;i<h0->head.noint;i++)
2214  {
2215  h0->yplot1[i] /= env->cal_scale;
2216  }
2217 
2218  xx();
2219  }
2220  else
2221  {
2223  }
2224  }
2225 
2226  return(0);
2227 }
2228 
2229 
2230 int doZero()
2231 {
2232  int bd, ed, i, n;
2233  double avg;
2234  struct LP_IMAGE_INFO *image = h0;
2235 
2236  _doCCur("Click Left Mouse Button on Left Edge of Desired Region");
2237 
2238  bd = (int)round(env->ccur);
2239 
2240  if(bd < 1)
2241  {
2242  bd = 1;
2243  }
2244 
2245  _doCCur("Click Left Mouse Button on Right Edge of Desired Region");
2246 
2247  ed = (int)round(env->ccur);
2248 
2249  n = image->head.noint;
2250 
2251  if(ed >= n)
2252  {
2253  ed = n -1;
2254  }
2255 
2256  if(isSet(PF_Z_FLAG)) /* Force them to zero ?? */
2257  {
2258  avg = 0.0;
2259  }
2260  else /* Default is to average the end points */
2261  {
2262  avg = (image->yplot1[bd] + image->yplot1[ed]) / 2.0;
2263  }
2264 
2265  st_report("Setting Channels %d - %d to %.4f", bd, ed, avg);
2266 
2267  for(i=bd;i<ed;i++)
2268  {
2269  image->yplot1[i] = avg;
2270  }
2271 
2272  return(0);
2273 }
2274 
2275 
2276 int doTrec()
2277 {
2278  int i, n, ret;
2279  char tbuf[256];
2280  double bscan, havg, savg, cavg;
2281  double yfac, syfac, avyfac, trec;
2282  double xval, yval;
2283 
2284  if(args->ntokens > 1)
2285  {
2286  if(strlen(args->secondArg))
2287  {
2288  bscan = atof(args->secondArg);
2289 
2290  st_report("T-Receiver: %.2f", bscan);
2291 
2292  /* Get hot load */
2293  _h1();
2294  bscan += 0.20;
2295  subArgs(2, "%.2f", bscan);
2296  ret = ggetScan("Vane");
2297 
2298  if(ret)
2299  {
2300  st_fail("doTrec(): Hot-Load Scan %.2f not found", bscan);
2301 
2302  return(1);
2303  }
2304 
2305  showAverage("Vane");
2306  havg = env->bp_avg;
2307 
2308  /* Get sky load */
2309  _h2();
2310  bscan += 0.20;
2311  subArgs(2, "%.2f", bscan);
2312  ret = ggetScan("Sky");
2313 
2314 
2315  if(ret)
2316  {
2317  st_fail("doTrec(): Sky Scan %.2f not found", bscan);
2318 
2319  return(1);
2320  }
2321 
2322  showAverage("Sky");
2323  savg = env->bp_avg;
2324 
2325  syfac = havg / savg;
2326 
2327  st_report("Sky Yfac = %.2f", syfac);
2328 
2329  /* Get cold load */
2330  _h3();
2331  bscan += 0.20;
2332  subArgs(2, "%.2f", bscan);
2333  ret = ggetScan("Cold");
2334 
2335  if(ret)
2336  {
2337  st_fail("doTrec(): Cold-Load Scan %.2f not found", bscan);
2338 
2339  return(1);
2340  }
2341 
2342  showAverage("Cold");
2343  cavg = env->bp_avg;
2344 
2345  avyfac = havg / cavg;
2346  trec = (273.0+H1.head.tchop-avyfac*H1.head.tcold) / (avyfac - 1.0);
2347 
2348  st_report("Yfac = %.2f, Trec = %.2f", avyfac, trec);
2349 
2350  _h0();
2351 
2352  hzero(&H0);
2353 
2354  /* Copy the header */
2355  bcopy((char *)&H1.head, (char *)&H0.head, sizeof(H0.head));
2356 
2357  n = H1.head.noint;
2358 
2359  for(i=env->bdrop;i<(n-env->edrop);i++)
2360  {
2361  if(H3.yplot1[i] > 0.0)
2362  {
2363  yfac = H1.yplot1[i] / H3.yplot1[i];
2364  }
2365  else
2366  {
2367  yfac = H1.yplot1[i] / cavg;
2368  }
2369 
2370  H0.yplot1[i] = (273.0+H1.head.tchop-yfac*H1.head.tcold) / (yfac - 1.0);
2371  }
2372 
2373  H0.head.scan = atof(args->secondArg); /* Set the scan number back */
2374 
2375  showScan();
2376 
2377  getResponse(WAIT_FOR_PLOT); /* Wait for xgraphics to plot and respond */
2378 
2379  sprintf(tbuf, "hline /Cmg /c 0 %f", trec);
2380  parseCmd(tbuf);
2381 
2382  strcpy(h0->title, "T-receiver");
2383 
2384  n = (int)(H1.head.noint * 0.10);
2385 
2386  xval = H0.x1data[n];
2387  yval = (env->yplotmax - env->yplotmin) * 0.90 + env->yplotmin;
2388 
2389  sprintf(tbuf, "label set 0 %f %f 5 0 T_{rec}: %.1f, Y_{fac}: %.2f /3", xval, yval, trec, avyfac);
2390  parseCmd(tbuf);
2391  }
2392  else
2393  {
2395  }
2396  }
2397 
2398  return(0);
2399 }
2400 
2401 
2403 {
2404  int ret;
2405  char tbuf[256];
2406  double bscan, havg, savg;
2407  double yfac;
2408 
2409  if(args->ntokens > 1)
2410  {
2411  if(strlen(args->secondArg))
2412  {
2413  bscan = atof(args->secondArg);
2414 
2415  st_report("doYFactor: %.2f", bscan);
2416 
2417  /* Get hot load */
2418  _h1();
2419  bscan += 0.20;
2420  subArgs(2, "%.2f", bscan);
2421  ret = ggetScan("Vane");
2422 
2423  if(ret)
2424  {
2425  st_fail("doYFactor(): Hot-Load Scan %.2f not found", bscan);
2426 
2427  return(1);
2428  }
2429 
2430  showAverage("Vane");
2431  havg = env->bp_avg;
2432 
2433  /* Get sky load */
2434  _h2();
2435  bscan += 0.20;
2436  subArgs(2, "%.2f", bscan);
2437  ret = ggetScan("Sky");
2438 
2439 
2440  if(ret)
2441  {
2442  st_fail("doYFactor(): Sky Scan %.2f not found", bscan);
2443 
2444  return(1);
2445  }
2446 
2447  showAverage("Sky");
2448  savg = env->bp_avg;
2449 
2450  yfac = havg / savg;
2451 
2452  st_report("Sky Yfac = %.2f", yfac);
2453 
2454  sprintf(tbuf, "image /y h1 h2");
2455  parseCmd(tbuf);
2456 
2457  _h0();
2458 
2459  strcpy(h0->title, "Y-Factors");
2460 
2461  showScan();
2462 
2463  getResponse(WAIT_FOR_PLOT); /* Wait for xgraphics to plot and respond */
2464 
2465  sprintf(tbuf, "hline /Cmg /c 0 %f", yfac);
2466  parseCmd(tbuf);
2467 
2468  }
2469  else
2470  {
2472  }
2473  }
2474 
2475  return(0);
2476 }
2477 
2478 
2479 /* Duplicate the Unipops 'nsac' command.
2480  *
2481  * Recall any number of nsaves; shift them if necessary; sum them;
2482  */
2483 int doNsac()
2484 {
2485  int i, n, ret, nsave, nscans=0;
2486  int argsPassed = 0;
2487  char tbuf[256];
2488  double freq, newfreq, fscan = 1e9, lscan = 0.0;
2489  char source[80], newsource[80];
2490 
2491  if(!strlen(env->savefile))
2492  {
2493  setColor(RED);
2494  st_report("Save file not set");
2495  setColor(BLACK);
2496 
2497  return(1);
2498  }
2499 
2500  saveEnv();
2501 
2502  argsPassed = args->ntokens - 1;
2503 
2504  if(!argsPassed)
2505  {
2506  n = getNumericResponse("Enter Number of 'nsaves' to average < 9: ");
2507  }
2508  else
2509  {
2510  n = atoi(args->tok[1]);
2511  }
2512 
2513  if(n == 0)
2514  {
2515  setColor(RED);
2516  st_report("nsac(): Cancelled");
2517  setColor(BLACK);
2518  restoreEnv();
2519 
2520  return(0);
2521  }
2522 
2523  if(n > 9)
2524  {
2525  setColor(RED);
2526  st_report("nsac(): Number of nsaves, %d, too large; 9 Max", n);
2527  setColor(BLACK);
2528  restoreEnv();
2529 
2530  return(1);
2531  }
2532 
2533 // st_report("ntokens = %d, n+2 = %d\n", args->ntokens, n+2);
2534 
2535  if(argsPassed && args->ntokens != n+2)
2536  {
2537  setColor(RED);
2538  st_report("nsac(): Wrong Number of arguments for command");
2539  setColor(BLACK);
2540  restoreEnv();
2541 
2542  return(1);
2543  }
2544 
2545  if(isSet(PF_C_FLAG))
2546  {
2547  clearAllImages();
2548  }
2549 
2550  /* Fetch all the nsaves first */
2551  for(i=0;i<n;i++)
2552  {
2553  if(!argsPassed)
2554  {
2555  nsave = getNumericResponse("Enter nsave: %d of %d: ", i+1, n);
2556  }
2557  else
2558  {
2559  nsave = atoi(args->tok[i+2]);
2560  }
2561 
2562  if(nsave == 0)
2563  {
2564  setColor(RED);
2565  st_report("nsac(): Cancelled");
2566  setColor(BLACK);
2567  restoreEnv();
2568 
2569  return(0);
2570  }
2571 
2572  env->nsave = nsave;
2573 
2574  sprintf(tbuf, "H%d", i+1);
2575  subArgs(2, tbuf);
2576  setHeader();
2577  /* The first one is the refereance */
2578  ret = recallNSave();
2579 
2580  if(ret)
2581  {
2582  setColor(RED);
2583  st_report("Error retreiving nasave %d", nsave);
2584  setColor(BLACK);
2585  restoreEnv();
2586 
2587  return(1);
2588  }
2589 
2590  sprintf(tbuf, "NSAVE_%d", nsave);
2591  subArgs(2, tbuf);
2592  strcpy(h0->title, tbuf);
2593 
2594  if(i == 0)
2595  {
2596  strncpy(source, h0->head.object, 16);
2597  source[16] = '\0';
2598  strcmprs(source);
2599 
2600  freq = h0->head.restfreq;
2601  }
2602  else
2603  {
2604  strncpy(newsource, h0->head.object, 16);
2605  newsource[16] = '\0';
2606  strcmprs(newsource);
2607 
2608  if(strncmp(source, newsource, 16))
2609  {
2610  setColor(RED);
2611  st_report("Sources are not the same: %s, %s", source, newsource);
2612  setColor(BLACK);
2613  restoreEnv();
2614 
2615  return(1);
2616  }
2617 
2618  newfreq = h0->head.restfreq;
2619  if(fabs(newfreq-freq) > 50.0) /* 50 MHz should cover all shifts */
2620  {
2621  setColor(RED);
2622  st_report("RestFreq's are not the same: %f, %f", newfreq, freq);
2623  setColor(BLACK);
2624  restoreEnv();
2625 
2626  return(1);
2627  }
2628 
2629  subArgs(2, "H1");
2630  ret = compAutoShift();
2631 
2632  if(ret)
2633  {
2634  setColor(RED);
2635  st_report("nsac(): Shift Failed");
2636  setColor(BLACK);
2637  restoreEnv();
2638 
2639  return(1);
2640  }
2641  }
2642 
2643  h0->ainfo.bscan = h0->head.fscan;
2644  h0->ainfo.escan = h0->head.lscan;
2645  h0->ainfo.scanct = h0->head.nostac;
2646 
2647  nscans += h0->head.nostac;
2648 
2649  if(h0->head.fscan < fscan)
2650  {
2651  fscan = h0->head.fscan;
2652  }
2653 
2654  if(h0->head.lscan > lscan)
2655  {
2656  lscan = h0->head.lscan;
2657  }
2658  }
2659 
2660  /* Now sum them all up */
2661 
2662  for(i=0;i<n;i++)
2663  {
2664  if(i == 0) /* Copy the first one into holder 0 */
2665  {
2666  subArgs(2, "H1");
2667  subArgs(3, "H0");
2668 
2669  copyImage();
2670  }
2671  else
2672  {
2673  sprintf(tbuf, "H%d", i+1);
2674  subArgs(2, "H0");
2675  subArgs(3, tbuf);
2676 
2677  doSum();
2678  }
2679  }
2680 
2681  subArgs(2, "H0");
2682  setHeader();
2683  strcpy(h0->title, "Sum");
2684 
2685  h0->ainfo.bscan = h0->head.fscan = fscan;
2686  h0->ainfo.escan = h0->head.lscan = lscan;
2687  h0->ainfo.scanct = h0->head.nostac = nscans;
2688 
2689  showScan();
2690 
2691  imageSummary();
2692 
2693  restoreEnv();
2694 
2695  return(0);
2696 }
2697 
2698 
2699 int doDedit()
2700 {
2701  int i, n, ret, which = 0;
2702  char fname[256], sysBuf[512], *string, line[256];
2703  float *f, ff;
2704  FILE *fp;
2705 
2706  if(isSet(PF_0_FLAG))
2707  {
2708  which = 0;
2709  }
2710  else
2711  if(isSet(PF_1_FLAG))
2712  {
2713  which = 1;
2714  }
2715  else
2716  if(isSet(PF_2_FLAG))
2717  {
2718  which = 2;
2719  }
2720  else
2721  if(isSet(PF_3_FLAG))
2722  {
2723  which = 3;
2724  }
2725 
2726  if(isSet(PF_S_FLAG)) /* Save */
2727  {
2728  sprintf(fname, "/tmp/%s/dedit.txt", session);
2729 
2730  st_report("Saving Data[%d] array to: %s", which, fname);
2731 
2732  if((fp = fopen(fname, "w")) == NULL)
2733  {
2734  st_fail("Unable to open %s for writting", fname);
2735 
2736  return(0);
2737  }
2738 
2739  n = h0->head.noint;
2740 
2741  switch(which)
2742  {
2743  case 0: f = &h0->yplot1[0]; break;
2744  case 1: f = &h0->yplot2[0]; break;
2745  case 2: f = &h0->yplot3[0]; break;
2746  case 3: f = &h0->yplot4[0]; break;
2747  }
2748 
2749  for(i=0;i<n;i++, f++)
2750  {
2751  fprintf(fp, "%5d %.10f\n", i, *f);
2752  }
2753 
2754  fclose(fp);
2755 
2756  return(0);
2757  }
2758 
2759  if(isSet(PF_E_FLAG)) /* Edit */
2760  {
2761  sprintf(fname, "/tmp/%s/dedit.txt", session);
2762 
2763  st_report("Editing %s", fname);
2764 
2765  sprintf(sysBuf, "/usr/bin/vim %s", fname);
2766 
2767  system(sysBuf);
2768 
2769  return(0);
2770  }
2771 
2772  if(isSet(PF_R_FLAG)) /* Read */
2773  {
2774  sprintf(fname, "/tmp/%s/dedit.txt", session);
2775 
2776  st_report("Reading into Data[%d], %s", which, fname);
2777 
2778  if((fp = fopen(fname, "r")) == NULL)
2779  {
2780  st_fail("Unable to open %s for reaading", fname);
2781 
2782  return(0);
2783  }
2784 
2785  n = h0->head.noint;
2786 
2787  while((string = fgets(line, sizeof(line), fp)) != NULL)
2788  {
2789  ret = sscanf(line, "%d %f", &i, &ff);
2790 
2791  if(ret == 2)
2792  {
2793  /* I can't assume the array is still in channel
2794  order, so use index */
2795  if(i>= 0 && i < n)
2796  {
2797  switch(which)
2798  {
2799  case 0: h0->yplot1[i] = ff; break;
2800  case 1: h0->yplot2[i] = ff; break;
2801  case 2: h0->yplot3[i] = ff; break;
2802  case 3: h0->yplot4[i] = ff; break;
2803  case 4: h0->bplot [i] = ff; break;
2804  case 5: h0->gplot [i] = ff; break;
2805  }
2806  }
2807  else
2808  {
2809  st_print("doDedit(): %d, greater then noint: %d", i, n);
2810  }
2811  }
2812  else
2813  {
2814  st_print("doDedit(): sacanf() returned %d, and not 2", ret);
2815  }
2816  }
2817 
2818  xx();
2819 
2820  fclose(fp);
2821 
2822  return(0);
2823  }
2824 
2825  if(isSet(PF_U_FLAG)) /* User action flag */
2826  {
2827  if(args->ntokens > 1)
2828  {
2829  sprintf(fname, "/tmp/%s/dedit.txt", session);
2830 
2831  sprintf(sysBuf, "%s %s", args->secondArg, fname);
2832 
2833  st_report("Executing: %s", fname);
2834 
2835  system(sysBuf);
2836 
2837  return(0);
2838  }
2839 
2840  return(0);
2841  }
2842 
2844 
2845  return(0);
2846 }
int rm_fit_data
Definition: env.h:133
struct SOCK * xgraphic
Definition: linuxpops.c:75
float yplot1[MAX_CHANS]
Definition: image.h:110
struct LP_IMAGE_INFO * h0
Definition: image.c:74
struct LP_IMAGE_INFO accum_image
Definition: image.c:61
int compAutoShift(void)
Definition: shift.c:168
int xx()
Definition: linuxpops.c:605
double tcold
Definition: header.h:171
double az
Definition: header.h:82
double scan
Definition: header.h:35
#define BKMATCH_RESOLUTION
Definition: defines.h:122
float wt
Definition: image.h:54
int hzero(struct LP_IMAGE_INFO *image)
Definition: image.c:616
double curScan
Definition: env.h:178
#define BSP
Definition: observing_par.h:30
double rms
Definition: env.h:262
int ggetScan(char *buf)
Definition: io.c:863
#define LOG_PLOT
Definition: defines.h:111
double dfreq
Definition: env.h:183
struct LP_IMAGE_INFO H1
Definition: image.c:64
int doDedit()
Definition: line.c:2699
char * strcmprs(char *str)
int _copyImage(struct LP_IMAGE_INFO *i1, struct LP_IMAGE_INFO *i2)
Definition: image.c:329
char * prompt
Definition: makemem.c:101
double yplotmax
Definition: env.h:286
int incrementBogusTsys(void)
Definition: reject.c:217
#define MODE_OTF
Definition: defines.h:88
int first
Definition: dbase.c:106
int _h0()
Definition: image.c:93
struct PARSE_STACK * args
Definition: parse.h:196
int edrop
Definition: env.h:52
int doQshow()
Definition: line.c:1396
double cal_scale
Definition: env.h:175
double noint
Definition: header.h:211
int selfRej()
Definition: line.c:966
double rejections[MAX_BEAMS]
Definition: env.h:261
#define SPEED_OF_LIGHT
Definition: defines.h:126
int computeEachBaseLine(struct LP_IMAGE_INFO *image)
Definition: baseline.c:102
double utdate
Definition: header.h:61
struct BOX_DATA bd
Definition: obsmodes.c:132
int cmdShowAverage()
Definition: line.c:1104
Definition: parse.h:8
int doTrec()
Definition: line.c:2276
double workingTime
Definition: line.c:71
struct LP_IMAGE_INFO H2
Definition: image.c:65
struct LP_IMAGE_INFO H0
Definition: image.c:63
int clearRMS()
Definition: line.c:986
double sideband
Definition: image.h:64
struct BASELINE_INFO binfo
Definition: image.h:101
int lp_fcmp(double first, double second, double delta)
Definition: linuxpops.c:2768
int line_doBaseLine(struct LP_IMAGE_INFO *image)
Definition: baseline.c:291
char source[SRCLEN+1]
Definition: dataserv.c:52
int nsize
Definition: image.h:80
#define MAX_CHANS
Definition: defines.h:38
float escan
Definition: image.h:53
int recallNSave()
Definition: io.c:706
int setHWDC(struct LP_IMAGE_INFO *image)
Definition: line.c:884
#define CTR
Definition: defines.h:26
#define RED
Definition: colors.h:5
int check_scans
Definition: env.h:43
int zero_bl_averages()
Definition: baseline.c:67
double ccur
Definition: env.h:176
int read_scan()
char name[32]
Definition: image.h:73
#define MODE_CONT
Definition: defines.h:86
int line_showTable()
Definition: line.c:997
FILE * fp
Definition: linuxpops.c:70
#define max(a, b)
Definition: cactus.h:115
Definition: header.h:13
int linePlot(struct LP_IMAGE_INFO *image)
Definition: line.c:799
int printH_FlagHelp(char *cmd)
Definition: help.c:430
double slope
Definition: env.h:266
double nostac
Definition: header.h:223
double tcal
Definition: header.h:202
int incrementRejSb(void)
Definition: reject.c:138
double jupiter_tmb
Definition: env.h:213
#define min(a, b)
Definition: cactus.h:114
char rmsResultsStr[256]
Definition: line.c:75
#define SPEED_OF_LIGHT_COAX
Definition: defines.h:127
double neptune_tmb
Definition: env.h:229
int allow_five_pt
Definition: env.h:22
float workingY[MAX_CHANS]
Definition: line.c:73
int stquiet
Definition: env.c:90
struct HEADER * sa
Definition: linuxpops.c:72
int setFlag(int flag, int state)
Definition: parse.c:685
int computeBaseLine(struct LP_IMAGE_INFO *image)
Definition: baseline.c:200
#define BKMATCH_NAME
Definition: defines.h:123
#define TAN_PAT
Definition: line.c:1879
int _h3()
Definition: image.c:126
int issmt
Definition: env.h:63
float bscan
Definition: image.h:52
float datamin
Definition: image.h:95
double openpar[10]
Definition: header.h:155
int showC4()
Definition: observe.c:408
int processSpectra(struct LP_IMAGE_INFO *image)
Definition: line.c:735
struct PLOT_INFO pinfo
Definition: image.h:102
double datamin
Definition: env.h:181
int doBaseLine
Definition: image.h:8
int line_save_data(struct LP_IMAGE_INFO *h)
Definition: line.c:2003
int nscans
Definition: beam.h:4
int getResponse(int which)
Definition: linuxpops.c:2287
int procspec
Definition: env.h:130
double venus_tmb
Definition: env.h:280
int getScan(int verbose)
Definition: io.c:812
int peakChan
Definition: env.h:126
double sideband
Definition: header.h:143
int incrementRejIgnored(void)
Definition: reject.c:169
char tok[MAX_TOKENS][MAX_TOKENS]
Definition: parse.h:176
int computeRms(float *y, int n, float *rms)
Definition: line.c:82
double date
Definition: env.h:182
int autobad
Definition: env.h:24
double mars_tmb
Definition: env.h:226
int do_S_Command()
Definition: line.c:856
int _h2()
Definition: image.c:115
int doPshow()
Definition: line.c:1264
int do_psc()
Definition: line.c:1498
double p2p
Definition: env.h:259
int line_display_spectra(struct LP_IMAGE_INFO *image, int plot)
Definition: line.c:743
double avgTr[MAX_IFS]
Definition: accum.h:76
int doOSB()
Definition: line.c:1808
int addIgnore(double scan)
Definition: ignore.c:61
int doSpecInvert()
Definition: line.c:1773
int last_scan_count
Definition: env.h:66
int yplotmode
Definition: image.h:38
double spn
Definition: header.h:212
int doYFactor()
Definition: line.c:2402
double refpt
Definition: image.h:65
double deltax
Definition: image.h:67
struct ENVIRONMENT * env
Definition: linuxpops.c:71
int _doCCur(char *msg)
Definition: linuxpops.c:2411
int removeBadChans()
Definition: line.c:1382
float yplot2[MAX_CHANS]
Definition: image.h:111
int dobaseline
Definition: env.h:48
int writeReport(char *buf)
Definition: line.c:2055
float x1data[MAX_CHANS]
Definition: image.h:117
int isPlanet(char *name)
Definition: planets.c:1527
int do_specCombClear()
Definition: line.c:194
char source[64]
Definition: env.h:11
#define BKMATCH_NAMERES
Definition: defines.h:124
double workingTcal
Definition: line.c:70
double mercury_tmb
Definition: env.h:227
int copyEnv2Image(struct LP_IMAGE_INFO *image)
Definition: image.c:784
int imageSummary()
Definition: image.c:538
int check_source
Definition: env.h:44
double hwdc
Definition: env.h:205
int isSet(int flag)
Definition: parse.c:646
struct HEADER head
Definition: image.h:104
double lst
Definition: header.h:63
double rms
Definition: header.h:229
double datamin
Definition: dataserv.c:44
int resetRejections(void)
Definition: reject.c:233
char * listHeader
Definition: strings.c:130
double refpt_vel
Definition: header.h:175
#define DEG_TO_RAD
Definition: cactus.h:48
double datamax
Definition: env.h:180
double indx
Definition: header.h:84
int doNsac()
Definition: line.c:2483
int line_MinMax(struct LP_IMAGE_INFO *image)
Definition: line.c:1038
int getPlanet()
Definition: planets.c:850
int ignorepos
Definition: env.h:61
int doMeasure()
Definition: line.c:1071
int incrementRejNoint(void)
Definition: reject.c:98
void st_warn()
int incrementRejDec(void)
Definition: reject.c:130
char obsmode[8]
Definition: header.h:41
int saveEnv()
Definition: env.c:709
int printRejections(void)
Definition: reject.c:257
double bkres
Definition: env.h:170
double obsfreq
Definition: header.h:197
int isSpecFivePoint(struct HEADER *h)
Definition: line.c:2186
char backend[8]
Definition: header.h:43
#define SQR_PAT
Definition: line.c:1880
void st_fail()
int freeX()
Definition: paxis.c:476
int restoreEnv()
Definition: env.c:722
int incrementRejOffsets(void)
Definition: reject.c:106
char savefile[256]
Definition: env.h:13
float datamax
Definition: image.h:98
int meetsCritiria(struct HEADER *p, int mask)
Definition: observe.c:90
double ylower
Definition: env.h:287
double trms
Definition: env.h:274
double firstif
Definition: header.h:136
double tcal
Definition: image.h:62
struct ACCUM_INFO ainfo
Definition: image.h:100
int line_accum(struct LP_IMAGE_INFO *image)
Definition: line.c:212
int line_setScale()
Definition: line.c:2198
int doPageCmd()
Definition: linuxpops.c:2611
int getNumericResponse()
int ignoremapoff
Definition: env.h:60
int check_feed
Definition: env.h:41
#define DATASPREAD
Definition: defines.h:23
#define Y_FIXED_SCALE
Definition: defines.h:107
double stsys
Definition: header.h:203
double saturn_tmb
Definition: env.h:265
int isScanIgnored(double scan)
Definition: ignore.c:181
#define COS_PAT
Definition: line.c:1878
int line_accumSelected()
Definition: line.c:443
double epocra
Definition: header.h:78
char session[80]
Definition: strings.c:67
int doSum(void)
Definition: sum.c:61
int mode
Definition: env.h:75
#define MODE_SPEC
Definition: defines.h:87
int yscale
Definition: env.h:149
int setColor(int c)
Definition: parse.c:2644
double restfreq
Definition: image.h:60
int printReport()
Definition: line.c:2077
float gplot[MAX_CHANS]
Definition: image.h:115
int accumreset
Definition: env.h:18
int incrementRejMode(void)
Definition: reject.c:162
double refpt
Definition: header.h:207
int copyImage()
Definition: image.c:275
char magic[32]
Definition: image.h:72
void st_report()
double el
Definition: header.h:83
int clearFBOffets()
Definition: fboffset.c:451
int printScan(struct HEADER *p, int nsave)
Definition: linuxpops.c:725
#define WAIT_FOR_PLOT
Definition: global.h:33
#define BKMATCH_FEED
Definition: defines.h:121
Definition: parse.h:9
int clearAllImages()
Definition: image.c:629
int showC3()
Definition: observe.c:368
int printRMS()
Definition: line.c:916
double deltax
Definition: header.h:209
double if_feed
Definition: env.h:208
int showScan()
Definition: observe.c:1205
int fillPattern()
Definition: line.c:1882
double rst
Definition: env.h:263
int computeXaxis(struct LP_IMAGE_INFO *image, int logit)
Definition: xaxis.c:70
double bp_avg
Definition: env.h:172
struct ACCUM_RESULTS_SEND local_ars
Definition: object.c:78
int getTerminalSize(int *cols, int *rows)
Definition: io.c:1015
int deleteReport()
Definition: line.c:2047
int numofscans
Definition: env.h:85
int showC1()
Definition: observe.c:287
double workingTsys
Definition: line.c:69
double rms
Definition: beam.h:5
double tchop
Definition: header.h:170
int nsave
Definition: env.h:83
int incrementRejFive(void)
Definition: reject.c:90
int bdrop
Definition: env.h:31
int doZero()
Definition: line.c:2230
double scan
Definition: image.h:59
int baselines[MAX_BASELINES][2]
Definition: image.h:9
double yupper
Definition: env.h:288
double bscan
Definition: env.h:173
double intercept
Definition: env.h:210
char currentCmd[256]
Definition: parse.h:191
char backend[16]
Definition: env.h:12
int line_removeBadChans(struct LP_IMAGE_INFO *image, int print)
Definition: badchan.c:521
double freq
Definition: env.h:197
struct MISC_HEADER_PARAMS mhp[MAX_PLOT_ARRAYS]
Definition: image.h:105
int bkmatch
Definition: env.h:32
void subArgs(int wt, const char *fmt,...)
Definition: parse.c:430
double inttime
Definition: header.h:210
#define BLACK
Definition: colors.h:4
int do_F_Command()
Definition: line.c:835
double uranus_tmb
Definition: env.h:277
int scanct
Definition: image.h:51
double freqres
Definition: image.h:63
double avg
Definition: beam.h:5
#define SIN_PAT
Definition: line.c:1877
#define CHECK_ALL
Definition: defines.h:64
struct LP_IMAGE_INFO H3
Definition: image.c:66
int narray
Definition: image.h:79
double yplotmin
Definition: env.h:285
double fscan
Definition: header.h:224
int showAverage(char *buf)
Definition: line.c:1118
int incrementRejRa(void)
Definition: reject.c:122
int validate(int which)
Definition: linuxpops.c:164
int sendImageStruct(struct LP_IMAGE_INFO *image, int mode)
Definition: image.c:820
char * secondArg
Definition: parse.h:181
int _doTCur(char *msg)
Definition: linuxpops.c:2580
float bplot[MAX_CHANS]
Definition: image.h:116
float workingX[MAX_CHANS]
Definition: line.c:72
void st_print()
char backend[8]
Definition: image.h:58
int baselines[MAX_BASELINES][2]
Definition: env.h:30
int showC2()
Definition: observe.c:327
int removeFittedData(struct LP_IMAGE_INFO *image)
Definition: line.c:773
int ntokens
Definition: parse.h:173
double escan
Definition: env.h:186
int check_date
Definition: env.h:40
#define VERBOSE_CRITIRIA
Definition: defines.h:68
double dvel
Definition: env.h:184
int line_determine_min_max(struct LP_IMAGE_INFO *image)
Definition: line.c:694
int incrementRejFreq(void)
Definition: reject.c:146
char title[256]
Definition: image.h:74
double stsys
Definition: image.h:61
double effint
Definition: header.h:218
char object[16]
Definition: header.h:40
char * firstArg
Definition: parse.h:180
double restfreq
Definition: header.h:198
int parseCmd(char *buf)
Definition: parse.c:2090
int incrementRejFreqres(void)
Definition: reject.c:114
double fcur
Definition: env.h:190
double freqres
Definition: header.h:199
int _h1()
Definition: image.c:104
int doBaseline()
Definition: baseline.c:77
double lscan
Definition: header.h:225
double ut
Definition: header.h:62
int setHeader()
Definition: image.c:203
double epocdec
Definition: header.h:79
char filename[256]
Definition: env.h:9
int lineConvert2LogPlot()
Definition: line.c:1971
double avgEl
Definition: env.h:167
double tsyslimit
Definition: env.h:275
int doBzero()
Definition: line.c:1734
double beam_eff
Definition: env.h:169
int freeY()
Definition: paxis.c:488
double refpt_vel
Definition: image.h:66
float yplot3[MAX_CHANS]
Definition: image.h:112
int verboseLevel
Definition: linuxpops.c:80
int incrementRejVel(void)
Definition: reject.c:154
float yplot4[MAX_CHANS]
Definition: image.h:113