Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
io.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 int noenv = 1;
62 
63 int runFile()
64 {
65  noenv = 0;
66 
67  if(readFile())
68  {
69  noenv = 1;
70  return(1);
71  }
72  else
73  {
74  noenv = 1;
75  return(0);
76  }
77 }
78 
79 
80 /*
81 zenity --list --column="Freq" --column="Qty" --multiple --text="Select a Freq" \
82  "230.538" 25 "220.500" 20 "115.270" 35
83  */
84 
85 
86 int doZenity(cmd, rst)
87 char *cmd, *rst;
88 {
89  FILE *fp;
90  char *string, line[4096];
91  static char cmdBuf[8*4096];
92 
93  sprintf(cmdBuf, "/usr/bin/zenity %s 2> /dev/null", cmd);
94 
95  if( (fp = popen(cmdBuf, "r") ) <= (FILE *)0 )
96  {
97  st_fail("doZenity(): Unable to open %s", cmdBuf);
98 
99  return(1);
100  }
101 
102  bzero(line, sizeof(line));
103 
104  while((string = fgets(line, sizeof(line), fp)) != NULL)
105  {
106  deNewLineIt(line);
107  strcmprs(line);
108  strcpy(rst, line);
109  }
110 
111  pclose(fp);
112 
113  return(0);
114 }
115 
116 
117 #define MAX_LOAD_LEVELS 10
118 
119 int incLevel(l)
120 int l;
121 {
122  l++;
123 
124  if(l >= MAX_LOAD_LEVELS)
125  {
126  l = MAX_LOAD_LEVELS-1;
127  }
128 
129  return(l);
130 }
131 
132 
133 
134 int decLevel(l)
135 int l;
136 {
137  l--;
138 
139  if(l <= 0)
140  {
141  l = 0;
142  }
143 
144  return(l);
145 }
146 
147 
148 /* this routine needs to be made re-enterant */
149 int readFile()
150 {
151  int ret;
152  int n[MAX_LOAD_LEVELS] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
153  double start[MAX_LOAD_LEVELS], end[MAX_LOAD_LEVELS];
154  FILE *fp[MAX_LOAD_LEVELS];
155  char *string, line[256], fname[MAX_LOAD_LEVELS][256];
156  static int lastline[MAX_LOAD_LEVELS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
157  static int level = 0;
158 
159  if(strlen(args->secondArg) < 2)
160  {
161  st_warn("Missing arg for readFile()");
162  return(1);
163  }
164 
165  level = incLevel(level);
166 
167  strcpy(fname[level], args->secondArg);
168 
169  st_report("readFile(): Opening up %s in run level %d", fname[level], level);
170 
171  if((fp[level] = fopen(fname[level], "r") ) <= (FILE *)0)
172  {
173  st_fail("readFile(): Unable to open file %s", fname[level]);
174  level = decLevel(level);
175 
176  return(1);
177  }
178 
179  if(notSet(PF_C_FLAG)) /* continuation flag */
180  {
181  lastline[level] = 0;
182  }
183 
184  start[level] = getmJulDate(0);
185 
186  clearInterrupt();
187 
188  while((string = fgets(line, sizeof(line), fp[level])) != NULL)
189  {
190  n[level]++;
191 
192  if(n[level] < (lastline[level]-1)) /* Alway backup one line in the file */
193  {
194  continue;
195  }
196 
197  lastline[level] = n[level];
198 
199  if(strlen(line) < 2)
200  {
201  continue;
202  }
203 
204  if(line[0] == '#')
205  {
206  continue;
207  }
208 
209  if(isSet(PF_C_FLAG)) /* Check that the first line in contiune is not a delay */
210  {
211  if(strstr(line, "helperwait"))
212  {
213  setFlag(PF_C_FLAG, 0); /* Clear it */
214 
215  continue;
216  }
217  }
218 
219  deNewLineIt(line); /* Clean it up */
220 
222  {
223  st_report("Parsing: %s", line);
224  }
225 
226  if(!strcmp(line, "break"))
227  {
228  st_report("readFile(1): Closing %s in run level %d", fname[level], level);
229  fclose(fp[level]);
230 
231  end[level] = getmJulDate(0);
232 
233  st_report("Total Load Time in Secs: %.2f", (end[level]-start[level]) * 86400.0);
234 
235  level = decLevel(level);
236 
237  return(0);
238  }
239 
240  if(isInterrupt()) /* Check for Control C */
241  {
242  st_report("readFile(2): Closing %s in run level %d", fname[level], level);
243  fclose(fp[level]);
244 
245  end[level] = getmJulDate(0);
246 
247  st_report("Total Load Time in Secs: %.2f", (end[level]-start[level]) * 86400.0);
248 
249  level = decLevel(level);
250 
251  return(0);
252  }
253 
254  ret = parseCmd(line);
255 
256  if(ret)
257  {
258  st_fail("Error in batch file: %s; aborting", fname[level]);
259 
260  st_report("readFile(3): Closing %s in run level %d", fname[level], level);
261  fclose(fp[level]);
262 
263  end[level] = getmJulDate(0);
264 
265  st_report("Total Load Time in Secs: %.2f", (end[level]-start[level]) * 86400.0);
266 
267  level = decLevel(level);
268 
269  return(1);
270  }
271  }
272 
273  st_report("readFile(4): Closing %s in run level %d", fname[level], level);
274  fclose(fp[level]);
275 
276  end[level] = getmJulDate(0);
277 
278  st_report("Total Load Time in Secs: %.2f", (end[level]-start[level]) * 86400.0);
279 
280  level = decLevel(level);
281 
282 
283  return( reloadFile() );
284 }
285 
286 
288 {
289  char sysbuf[256], *cp;
290  FILE *fp;
291  int ret;
292 
293  if(access(lockFileName, F_OK)) /* File doesn't exist; create it */
294  {
295  st_report("Creating LOCKFILE: %s", lockFileName);
296 
297  if((fp = fopen(lockFileName, "w") ) <= (FILE *)0)
298  {
299  st_fail("checkLockFile(): Unable to open lockfile %s", lockFileName);
300  return(0);
301  }
302 
303  fprintf(fp, "Observer Initials %s\n", obs_inits);
304  fprintf(fp, "Session: %s\n", session);
305  fprintf(fp, "Host: %s\n", hostname);
306  fprintf(fp, "Date: %s\n", getcTime(0));
307 
308  cp = getenv("REMOTEHOST");
309 
310  if(cp)
311  {
312  fprintf(fp, "RemoteHost %s\n", cp);
313  }
314 
315  fclose(fp);
316 
317  return(1);
318  }
319 
320  st_report("LOCKFILE %s Already Exists", lockFileName);
321 
322  st_print(" \n");
323  sprintf(sysbuf, "cat %s", lockFileName);
324  system(sysbuf);
325 
326  while(1)
327  {
328  do
329  {
330  ret = getNumericResponse("\nTo Exit the program, type: 0\nTo remove the leftover lockfile, type: 1\nTo ignore the lockfile, type: 2\n");
331  }
332  while(ret < 0);
333 
334  if(ret == 0)
335  {
336  return(0);
337  }
338  else
339  if(ret == 1)
340  {
341  removeLockFile();
342  checkLockFile();
343  return(1);
344  }
345  else
346  if(ret == 2)
347  {
348  st_print("\nIgnoring LOCKFILE: Proceed at your own risk\n\n");
350  return(1);
351  }
352  else
353  {
354  st_print("Unknown Response\n");
355  }
356  }
357 
358  return(0);
359 }
360 
361 
363 {
364  char sysbuf[256];
365 
366  if(strlen(lockFileName))
367  {
368  st_report("Removing LOCKFILE: %s", lockFileName);
369  sprintf(sysbuf, "rm -f %s", lockFileName);
370 
371  if(verboseLevel == 2)
372  {
373  st_report("Executing Command: %s", sysbuf);
374  }
375 
376  system(sysbuf);
377  }
378 
379  return(0);
380 }
381 
382 
383 
385 {
386  st_warn("watchFile() Not implemented yet");
387 
388  return(0);
389 }
390 
391 
393 {
394  subArgs(2, env->filename);
395  args->ntokens = 2;
396 
397  return( loadFile() );
398 }
399 
400 
401 /* Did the data file change size; i.e. online file */
403 {
404  FILE *fp;
405  struct stat filestat;
406 
407  if( (fp = fopen(env->filename, "r") ) <= (FILE *)0 )
408  {
409  st_fail("fileChanged(): Unable to open %s", env->filename);
410  return(1);
411  }
412 
413  fstat(fileno(fp), &filestat);
414 
415  fclose(fp);
416 
417  /* Is the 'force' flag set or file larger */
418  if(isSet(PF_F_FLAG) || (filestat.st_size != lastFileSize))
419  {
420  st_report("Reloading Data File %s", env->filename);
421  strcpy(args->tok[1], env->filename);
422  args->ntokens = 2;
423 
424  if(loadFile())
425  {
426  return(1);
427  }
428 
429  lastFileSize = filestat.st_size;
430  }
431  else
432  {
433  st_report("Data File %s, Unchanged", env->filename);
434  }
435 
436  return(0);
437 }
438 
439 
440 int loadFile()
441 {
442  int ret;
443  char results[256], input[256], tmp[256];
444 
445  bzero(results, sizeof(results));
446  strcpy(tmp, env->filename);
447 
448  if(args->ntokens < 2)
449  {
450  sprintf(input, "--file-selection --title='Select a Datafile' --file-filter='*.save *.sav *.SAV *.KEEP *.keep sdd* *.sdd' --filename='%s/'", dirname(tmp));
451  doZenity(input, results);
452 
453  st_report("doZenity() returned: '%s'", results);
454  strcmprs(results);
455  st_report("doZenity() After strcmprs: '%s'", results);
456 
457  if(strlen(results) < 4)
458  {
459  strcpy(results, env->filename);
460  }
461 
462  subArgs(2, results);
463  }
464 
465  strcpy(env->filename, args->secondArg);
466 
467  env->numofscans = 0;
468 
469  st_report("Loading File %s", env->filename);
470 
471  ret = findSize(env);
472 
473  if(ret < 0)
474  {
475  return(1);
476  }
477 
479 
480  st_report("Found %d Scans; %d Sources", env->numofscans, numOfSources);
481 
482  sendFilenames();
483 
484  return(0);
485 }
486 
487 
489 {
490  char results[256], input[256], tmp[256];
491 
492  bzero(results, sizeof(results));
493  strcpy(tmp, env->gfilename);
494 
495  if(args->ntokens < 2)
496  {
497  sprintf(input, "--file-selection --title='Select a Gainsfile' --file-filter='gsdd* *.gsdd' --filename='%s/'", dirname(tmp));
498  doZenity(input, results);
499 
500  strcmprs(results);
501 
502  if(strlen(results) < 4)
503  {
504  strcpy(results, env->gfilename);
505  }
506 
507  subArgs(2, results);
508  }
509 
510  strcpy(env->gfilename, args->secondArg);
511 
512  sendFilenames();
513 
514  return(0);
515 }
516 
517 
519 {
520  char results[256], input[256], tmp[512];
521 
522  bzero(results, sizeof(results));
523  strcpy(tmp, env->userfile);
524 
525  if(args->ntokens < 2)
526  {
527  sprintf(input, "--file-selection --title='Select a Userfile' --filename='%s/'", dirname(tmp));
528  doZenity(input, results);
529 
530  strcmprs(results);
531 
532  if(strlen(results) < 4)
533  {
534  strcpy(results, env->userfile);
535  }
536 
537  subArgs(2, results);
538  }
539 
540  strcpy(env->userfile, args->secondArg);
541 
542  if(strlen(env->userfile))
543  {
544  if(isSet(PF_E_FLAG))
545  {
546  sprintf(tmp, "rm -f %s", env->userfile);
547  system(tmp);
548  }
549 
550  if(isSet(PF_C_FLAG))
551  {
552  st_report("Creating User-File: %s", env->userfile);
553 
555  }
556  else
557  {
558  st_report("Skipping Creation of User-File: %s", env->userfile);
559  }
560  }
561  else
562  {
563  st_fail("Missing name for userfile");
564  }
565 
566  return(0);
567 }
568 
569 
571 {
572  char results[256], input[256], tmp[512];
573  int dont_erase = 0;
574 
575  bzero(results, sizeof(results));
576  strcpy(tmp, env->savefile);
577 
578  if(args->ntokens < 2)
579  {
580  sprintf(input, "--file-selection --title='Select a Savefile' --filename='%s/'", dirname(tmp));
581  doZenity(input, results);
582 
583  strcmprs(results);
584 
585  if(strlen(results) < 4)
586  {
587  strcpy(results, env->savefile);
588  }
589 
590  subArgs(2, results);
591 
592  dont_erase = 1; /* Existing file; don't erase */
593  }
594 
595  strcpy(env->savefile, args->secondArg);
596 
597  if(strlen(env->savefile))
598  {
599  if( !dont_erase && isSet(PF_E_FLAG))
600  {
601  if(getYesNoQuit("\nDelete savefile: %s [y/N]", env->savefile) == 1)
602  {
603  sprintf(tmp, "rm -f %s", env->savefile);
604 
605  st_print("%s\n", tmp);
606  system(tmp);
607  }
608  else
609  {
610  st_fail("Deletion of savefile: %s, aborted", env->savefile);
611  return(1);
612  }
613  }
614 
615  if( !dont_erase && isSet(PF_C_FLAG))
616  {
617  if(getYesNoQuit("\nCreate savefile: %s [y/N]", env->savefile) == 1)
618  {
619  st_report("Creating Save-File: %s", env->savefile);
620 
622  }
623  else
624  {
625  st_fail("Creation of savefile: %s, aborted", env->savefile);
626  return(1);
627  }
628  }
629  else
630  {
631  st_report("Opening Save-File: %s", env->savefile);
632  }
633  }
634  else
635  {
636  st_fail("Missing name for savefile");
637  return(1);
638  }
639 
640  return(0);
641 }
642 
643 
645 {
646  if(!strncmp(h0->head.obsmode, "CONTSEQ ", 8))
647  {
649  }
650  else
651  if(!strncmp(h0->head.obsmode, "CONTMAP ", 8))
652  {
654  }
655  else
656  if(!strncmp(h0->head.obsmode, "CONTFIVE", 8))
657  {
658  validate(QK5);
659  }
660  else
661  if(!strncmp(h0->head.obsmode, "CONTQK5 ", 8))
662  {
663  validate(QK5);
664  }
665  else
666  if(!strncmp(h0->head.obsmode, "CONTFOC ", 8))
667  {
669  }
670  else
671  if(!strncmp(h0->head.obsmode, "CONTNSFC", 8))
672  {
674  }
675  else
676  if(!strncmp(h0->head.obsmode, "CONTEWFC", 8))
677  {
679  }
680  else
681  if(!strncmp(h0->head.obsmode, "LINEPCAL", 8))
682  {
683  validate(PS_CAL);
684  }
685  else
686  if(!strncmp(h0->head.obsmode, "LINEBSP ", 8))
687  {
688  validate(BSP);
689  }
690  else
691  if(!strncmp(h0->head.obsmode, "LINEPS ", 8))
692  {
693  validate(PS);
694  }
695  else
696  if(!strncmp(h0->head.obsmode, "LINEFS ", 8))
697  {
698  validate(FS);
699  }
700 
701  return(0);
702 }
703 
704 
705 
707 {
708  char *cp;
709  unsigned int l;
710  int uninget(char *fname, int nsave, struct HEADER *head, float *data);
711 
712  if(strlen(env->savefile))
713  {
714  cp = env->savefile;
715  }
716  else
717  {
718  st_fail("savefile must be set first");
719  return(1);
720  }
721 
722  st_report("Fetching Nsave %d into %s", env->nsave, h0->name);
723 
724  if(env->nsave > 0)
725  {
726  uninget(cp, env->nsave, &h0->head, h0->yplot1);
727  }
728  else
729  {
730  return(1);
731  }
732 
733  env->curScan = h0->head.scan;
734  env->mapangle = h0->head.scanang;
735 
736  /* now check for abnormal float in data array */
737  l = (unsigned)h0->head.datalen / sizeof(float);
738 
739  lp_checkBounds(h0->yplot1, l, 1);
740 
741  h0->ainfo.scanct = h0->head.nostac;
742  h0->ainfo.bscan = h0->head.fscan;
743  h0->ainfo.escan = h0->head.lscan;
744 
745  setValidate();
746 
747  return(0);
748 }
749 
750 
751 int getNSave()
752 {
753  char *cp;
754  unsigned int l;
755  int uninget(char *fname, int nsave, struct HEADER *head, float *data);
756 
757  if(strlen(env->filename))
758  {
759  cp = env->filename;
760  }
761  else
762  {
763  st_fail("filename must be set first");
764  return(1);
765  }
766 
767  st_report("Fetching Nsave %d into %s", env->nsave, h0->name);
768 
769  if(env->nsave > 0)
770  {
771  uninget(cp, env->nsave, &h0->head, h0->yplot1);
772  }
773  else
774  {
775  return(1);
776  }
777 
778  env->curScan = h0->head.scan;
779  env->mapangle = h0->head.scanang;
780 
781  /* now check for abnormal float in data array */
782  l = (unsigned)h0->head.datalen / sizeof(float);
783 
784  lp_checkBounds(h0->yplot1, l, 1);
785 
786  h0->ainfo.scanct = h0->head.nostac;
787  h0->ainfo.bscan = h0->head.fscan;
788  h0->ainfo.escan = h0->head.lscan;
789 
790  setValidate();
791 
792  return(0);
793 }
794 
795 
797 {
798  freeX();
799  freeY();
800 
801  getScan(1);
802 
803  if(isSet(PF_R_FLAG))
804  {
805  removeBadChans();
806  }
807 
808  return(0);
809 }
810 
811 
812 int getScan(verbose)
813 int verbose;
814 {
815  double fscan, ret;
816 
817  if(strlen(args->secondArg) == 0)
818  {
819  st_warn("Missing Scan# for get");
820  return(1);
821  }
822 
823  hzero(h0); /* Clear out the H0 image array */
824 
825  last_valid = 0;
826  env->dobaseline = 0;
827 
828  if(!strcmp(args->secondArg, "stackscan"))
829  {
830  fscan = env->stackscan;
831  }
832  else
833  {
834  fscan = atof(args->secondArg);
835  }
836 
837  if(verbose)
838  {
839  st_report("Fetching Scan %.2f into %s", fscan, h0->name);
840  }
841 
842  ret = read_scan(fscan, env->filename, h0->yplot1, &h0->head, env->autobad);
843 
844  if(verbose)
845  {
846  st_report("read_scan(): Returned: %.2f", ret);
847  }
848 
849  env->curScan = fscan;
850  env->mapangle = h0->head.scanang;
851 
852  if(ret > 0.0)
853  {
854  setValidate();
855 
856  return(0);
857  }
858 
859  return(1);
860 }
861 
862 
863 int ggetScan(buf)
864 char *buf;
865 {
866  double fscan, ret;
867 
868  if(strlen(args->secondArg) == 0)
869  {
870  st_warn("Missing Scan# for get");
871  return(1);
872  }
873 
874  if(strlen(env->gfilename) == 0)
875  {
876  st_warn("No Gains File Specified");
877  return(1);
878  }
879 
880  hzero(h0); /* Clear out the H0 image array */
881 
882  last_valid = 0;
883  env->dobaseline = 0;
884 
885  fscan = atof(args->secondArg);
886 
887  if(buf)
888  {
889  st_report("Fetching %s Array %.2f into %s", buf, fscan, h0->name);
890  }
891  else
892  {
893  st_report("Fetching Gain Scan %.2f into %s", fscan, h0->name);
894  }
895 
896  ret = read_scan(fscan, env->gfilename, h0->yplot1, &h0->head, 0);
897  env->curScan = fscan;
898 
899  st_report("ggetScan() returned %f", ret);
900 
901  if(ret > 0.0)
902  {
903  setValidate();
904 
905  return(0);
906  }
907 
908  return(1);
909 }
910 
911 
912 
913 int doFver()
914 {
915  int newver;
916  char tbuf[256], fbuf[512];
917 
918  if(strlen(args->secondArg) == 0)
919  {
920  findVersions(DATA_FILE, "");
921 
922  if(doingOTF)
923  {
924  gsetFile();
925  }
926 
927  return(0);
928  }
929 
930  newver = atoi(args->secondArg);
931 
932  strcpy(tbuf, env->filename);
933 
934  tbuf[strlen(tbuf)-3] = '\0'; /* Truncate the versin number */
935 
936  sprintf(fbuf, "%s%03d", tbuf, newver);
937 
938  st_report("New file version: %s", fbuf);
939 
940  strcpy(env->filename, fbuf);
941 
942 // sendFilenames();
943 
944  if(doingOTF)
945  {
946  gsetFile();
947  }
948 
949  return( reloadFile() );
950 }
951 
952 
953 int doGver()
954 {
955  int newver;
956  char tbuf[256], fbuf[512];
957 
958  if(strlen(args->secondArg) == 0)
959  {
961  return(1);
962  }
963 
964  if(strlen(env->gfilename) < 4)
965  {
966  st_fail("Gains Filename NOT set");
967 
968  return(1);
969  }
970 
971  newver = atoi(args->secondArg);
972 
973  strcpy(tbuf, env->gfilename);
974 
975  tbuf[strlen(tbuf)-3] = '\0'; /* Truncate the versin number */
976 
977  sprintf(fbuf, "%s%03d", tbuf, newver);
978 
979  st_print("New Gains file version: %s\n", fbuf);
980 
981  strcpy(env->gfilename, fbuf);
982 
983  return(0);
984 }
985 
986 
990 int gsetFile()
991 {
992  char dir[256], base[256], tbuf[1024], tmp[256];
993 
994  strcpy(tmp, env->filename);
995  strcpy(dir, dirname(tmp));
996 
997  strcpy(tmp, env->filename);
998  strcpy(base, basename(tmp));
999 
1000  sprintf(tbuf, "%s/g%s", dir, base);
1001 
1002  st_report("Dir: %s", dir);
1003  st_report("Base: %s", base);
1004 
1005  st_report("New Gains file name: %s", tbuf);
1006 
1007  strcpy(env->gfilename, tbuf);
1008 
1009  sendFilenames();
1010 
1011  return(0);
1012 }
1013 
1014 
1015 int getTerminalSize(cols, rows)
1016 int *cols, *rows;
1017 {
1018  struct winsize w;
1019 
1020  ioctl(0, TIOCGWINSZ, &w);
1021 
1022  *cols = w.ws_col;
1023  *rows = w.ws_row;
1024 
1025  return(0);
1026 }
1027 
1028 
1030 {
1031  char sysBuf[256];
1032 
1033  st_report("Data file: %s", env->filename);
1034  st_report("Gains file: %s", env->gfilename);
1035  st_report("Log file: %s", logfilename);
1036  st_report("Lock file: %s", lockFileName);
1037 
1038  sprintf(sysBuf, "ls -l /tmp/%s/*", session);
1039 
1040  system(sysBuf);
1041 
1042  return(0);
1043 }
1044 
1045 
1047 {
1048  findVersions(DATA_FILE, "seq");
1049 
1050  return(0);
1051 }
1052 
1053 
1054 int findVersions(which, seq)
1055 int which;
1056 char *seq;
1057 {
1058  FILE *fp;
1059  char *string, line[256];
1060  static char cmdBuf[4*4096];
1061 
1062  sprintf(cmdBuf, "findVersions %s %s", env->filename, seq);
1063 
1064  if( (fp = popen(cmdBuf, "r") ) <= (FILE *)0 )
1065  {
1066  st_fail("findVersions(): Unable to open %s", cmdBuf);
1067 
1068  return(1);
1069  }
1070 
1071  bzero(line, sizeof(line));
1072 
1073  while((string = fgets(line, sizeof(line), fp)) != NULL)
1074  {
1075  deNewLineIt(line);
1076 
1077  strcmprs(line);
1078 
1079  if(!strncmp(line, "LOADING", 7))
1080  {
1081  printf(".");
1082  fflush(stdout);
1083  }
1084  else
1085  if(!strncmp(line, "DONE", 4))
1086  {
1087  printf("\n");
1088  fflush(stdout);
1089  }
1090  else
1091  if(strstr(line, "sdd"))
1092  {
1093  st_report("findVersions() returned: '%s'", line);
1094 
1095  if(which == DATA_FILE)
1096  {
1097  strcpy(env->filename, line);
1098  }
1099  else
1100  if(which == GAINS_FILE)
1101  {
1102  strcpy(env->gfilename, line);
1103  }
1104 
1105  if(reloadFile())
1106  {
1107  return(1);
1108  }
1109  }
1110  else
1111  {
1112  printf("findVersions(): %s\n", line);
1113  }
1114  }
1115 
1116  pclose(fp);
1117 
1118  return(0);
1119 }
1120 
1121 
1123 {
1124  findVersions(DATA_FILE, "");
1125 
1126  if(doingOTF)
1127  {
1128  gsetFile();
1129  }
1130 
1131  return(0);
1132 }
1133 
1134 
1136 {
1137  int uninsave(char *fname, int nsave, int overwrite, struct HEADER *head, float *data);
1138 
1139  if(env->nsave > 0)
1140  {
1141  if(strlen(env->savefile))
1142  {
1143  st_report("Saving Image to nsave=%d, in %s", env->nsave, env->savefile);
1144 
1145  if(h0->head.noint > 0)
1146  {
1147  h0->head.align3[0] = env->nsave; /* Save nsave in header */
1148 
1149  uninsave(env->savefile, env->nsave, env->overwrite, &h0->head, (float *)&h0->yplot1[0]);
1150  }
1151  else
1152  {
1153  st_fail("Image Holder: %s, appears to be empty", h0->name);
1154  }
1155  }
1156  else
1157  {
1158  st_fail("savefile must be set first");
1159  }
1160  }
1161  else
1162  {
1163  st_fail("nsave must be > 0");
1164  }
1165 
1166  return(0);
1167 }
1168 
1169 
1170 /* Ingest, Convert and possibly Export old version of SDD files */
1171 int doSDD()
1172 {
1173  char sysBuf[512];
1174 
1175  st_report("Entering doSDD()");
1176 
1177  if(args->ntokens < 3)
1178  {
1179  printH_FlagHelp("sdd");
1180  }
1181 
1182  if(isSet(PF_C_FLAG))
1183  {
1184  sprintf(sysBuf, "convert2intel %s %s", args->secondArg, args->thirdArg);
1185 
1186  system(sysBuf);
1187 
1188  if(isSet(PF_L_FLAG)) /* Use this new file? */
1189  {
1190  sprintf(sysBuf, "file %s", args->thirdArg);
1191 
1192  parseCmd(sysBuf);
1193  }
1194 
1195  return(0);
1196  }
1197 
1198  return(0);
1199 }
1200 
1201 /* Ingest, Convert and possibly Export old version of GILDAS Class files */
1202 int doClass()
1203 {
1204  char sysBuf[512], cfile[256], cname[128];
1205 
1206  st_report("Entering doClass(%d)", args->ntokens);
1207 
1208  if(isSet(PF_C_FLAG))
1209  {
1210  sprintf(sysBuf, "class2sdd %s %s", args->secondArg, args->thirdArg);
1211 
1212  system(sysBuf);
1213 
1214  if(isSet(PF_L_FLAG)) /* Use this new file? */
1215  {
1216  sprintf(sysBuf, "file %s", args->thirdArg);
1217 
1218  parseCmd(sysBuf);
1219  }
1220 
1221  return(0);
1222  }
1223  else
1224  if(isSet(PF_S_FLAG)) /* Save the H0 to a file */
1225  {
1226  if(strlen(args->secondArg))
1227  {
1228  strcpy(cfile, args->secondArg);
1229 
1230  if(isSet(PF_I_FLAG))
1231  {
1232  sprintf(sysBuf, "rm -i %s", cfile);
1233  system(sysBuf);
1234  }
1235 
1236  if(class_init(cfile))
1237  {
1238  strncpy(cname, h0->head.backend, 8);
1239  cname[8] = '\0';
1240 
1241  class_write(cfile, &h0->head, &h0->yplot1[0], cname, 1);
1242 
1243  return(0);
1244  }
1245  }
1246  else
1247  {
1248  st_fail("doClass(): No filename passed");
1249  printH_FlagHelp("class");
1250 
1251  return(1);
1252  }
1253  }
1254  else
1255  {
1256  printH_FlagHelp("class");
1257  }
1258 
1259  return(0);
1260 }
1261 
1262 
1263 /* Ingest, Convert and possibly Export old version of PDFL files */
1264 int doPDFL()
1265 {
1266  st_report("Entering doPDFL()");
1267 
1268  return(0);
1269 }
1270 
1271 
1272 
1274 {
1275  char *cp;
1276  int unilistsave_(char *fname);
1277 
1278  if(strlen(env->savefile))
1279  {
1280  cp = env->savefile;
1281  }
1282  else
1283  {
1284  st_fail("savefile must be set first");
1285  return(1);
1286  }
1287 
1288  st_report("Fetching Nsave %d into %s", env->nsave, h0->name);
1289 
1290  unilistsave_(cp);
1291 
1292  return(0);
1293 }
1294 
1295 
1297 {
1298  char *cp, sysBuf[512], gsysBuf[512];
1299 
1300  if(args->ntokens < 2)
1301  {
1303 
1304  return(1);
1305  }
1306 
1307  cp = getenv("HOST");
1308 
1309  if(cp)
1310  {
1311  if(strstr(cp, "modelo") || strstr(cp, "smtoast") || strstr(cp, "unipops"))
1312  {
1313  st_report("Update not available Mountain computer: %s", cp);
1314  return(1);
1315  }
1316  }
1317  else
1318  {
1319  st_report("Update not available from Mountain computers");
1320  return(1);
1321  }
1322 
1323  st_report("Proceeding on host: %s", cp);
1324 
1325  if(!strcmp(args->secondArg, "12m"))
1326  {
1327  sprintf( sysBuf, "scp modelo:%s %s", env->filename, env->filename);
1328 
1329  if(isSet(PF_G_FLAG))
1330  {
1331  sprintf(gsysBuf, "scp modelo:%s %s", env->gfilename, env->gfilename);
1332  }
1333  }
1334  else
1335  if(!strcmp(args->secondArg, "smt"))
1336  {
1337  sprintf(sysBuf, "scp smtoast:%s %s", env->filename, env->filename);
1338 
1339  if(isSet(PF_G_FLAG))
1340  {
1341  sprintf(gsysBuf, "scp smtoast:%s %s", env->gfilename, env->gfilename);
1342  }
1343  }
1344  else
1345  {
1347 
1348  return(1);
1349  }
1350 
1351  if(isSet(PF_F_FLAG))
1352  {
1353  st_report("system(%s);", sysBuf);
1354 
1355  system(sysBuf);
1356 
1357  if(isSet(PF_G_FLAG))
1358  {
1359  st_report("system(%s);", gsysBuf);
1360 
1361  system(gsysBuf);
1362  }
1363  }
1364  else
1365  {
1366  st_report("system(%s);", sysBuf);
1367 
1368  if(isSet(PF_G_FLAG))
1369  {
1370  st_report("system(%s);", gsysBuf);
1371  }
1372  }
1373 
1374  return(0);
1375 }
1376 
int showFiles()
Definition: io.c:1029
float yplot1[MAX_CHANS]
Definition: image.h:110
struct LP_IMAGE_INFO * h0
Definition: image.c:74
int gsetFile()
Definition: io.c:990
int removeLockFile()
Definition: io.c:362
int loadFile()
Definition: io.c:440
double scan
Definition: header.h:35
int hzero(struct LP_IMAGE_INFO *image)
Definition: image.c:616
double curScan
Definition: env.h:178
#define BSP
Definition: observing_par.h:30
int noenv
Definition: io.c:61
int ggetScan(char *buf)
Definition: io.c:863
#define NS_FOCALIZE
Definition: observing_par.h:47
int lastFileSize
Definition: sdd.c:23
char * strcmprs(char *str)
double stackscan
Definition: env.h:268
struct RESULTS results[MAX_BKNDS][MAX_BKNDS]
Definition: beam.c:81
struct PARSE_STACK * args
Definition: parse.h:196
int listSaves()
Definition: io.c:1273
char userfile[256]
Definition: env.h:14
int deNewLineIt(char *buf)
double noint
Definition: header.h:211
double datalen
Definition: header.h:34
int findSequences()
Definition: io.c:1046
int setValidate()
Definition: io.c:644
double scanang
Definition: header.h:100
int lp_checkBounds()
int sendFilenames()
Definition: otf.c:259
float escan
Definition: image.h:53
int recallNSave()
Definition: io.c:706
int read_scan()
char name[32]
Definition: image.h:73
#define GAINS_FILE
Definition: defines.h:141
FILE * fp
Definition: linuxpops.c:70
Definition: header.h:13
int isInterrupt()
Definition: interrupt.c:152
int doGver()
Definition: io.c:953
int printH_FlagHelp(char *cmd)
Definition: help.c:430
char gfilename[256]
Definition: env.h:10
double nostac
Definition: header.h:223
#define PS_CAL
Definition: observing_par.h:40
int findVers()
Definition: io.c:1122
int setFlag(int flag, int state)
Definition: parse.c:685
float bscan
Definition: image.h:52
int last_valid
Definition: linuxpops.c:78
int numOfSources
Definition: sdd.c:24
double align3[4]
Definition: header.h:230
int getScan(int verbose)
Definition: io.c:812
char tok[MAX_TOKENS][MAX_TOKENS]
Definition: parse.h:176
int doPDFL()
Definition: io.c:1264
int autobad
Definition: env.h:24
int class_write()
int clearInterrupt()
Definition: interrupt.c:144
int notSet(int flag)
Definition: parse.c:669
char hostname[256]
Definition: strings.c:67
int getYesNoQuit()
struct ENVIRONMENT * env
Definition: linuxpops.c:71
int removeBadChans()
Definition: line.c:1382
int dobaseline
Definition: env.h:48
#define FS
Definition: observing_par.h:29
char * thirdArg
Definition: parse.h:182
#define DATA_FILE
Definition: defines.h:140
int isSet(int flag)
Definition: parse.c:646
int doZenity(char *cmd, char *rst)
Definition: io.c:86
struct HEADER head
Definition: image.h:104
int lp_new_sdd()
int doUpdate()
Definition: io.c:1296
#define EW_FOCALIZE
Definition: observing_par.h:53
int reloadFile()
Definition: io.c:392
int findSize()
#define FOCALIZE
Definition: observing_par.h:46
void st_warn()
#define PS
Definition: observing_par.h:27
char obsmode[8]
Definition: header.h:41
char backend[8]
Definition: header.h:43
void st_fail()
double getmJulDate(int offset)
#define MAX_LOAD_LEVELS
Definition: io.c:117
int freeX()
Definition: paxis.c:476
char savefile[256]
Definition: env.h:13
int setUFileName()
Definition: io.c:518
int strcmp()
int overwrite
Definition: env.h:124
int setSFileName()
Definition: io.c:570
struct ACCUM_INFO ainfo
Definition: image.h:100
int setGFileName()
Definition: io.c:488
int getNumericResponse()
int getNSave()
Definition: io.c:751
int class_init()
int doFver()
Definition: io.c:913
char * getcTime(int offset)
char session[80]
Definition: strings.c:67
int findScans()
int doSDD()
Definition: io.c:1171
void st_report()
char logfilename[256]
Definition: strings.c:67
#define QK5
Definition: observing_par.h:66
char lockFileName[256]
Definition: makemem.c:97
int runFile()
Definition: io.c:63
char obs_inits[256]
Definition: makemem.c:97
int incLevel(int l)
Definition: io.c:119
int getTerminalSize(int *cols, int *rows)
Definition: io.c:1015
int saveNSave()
Definition: io.c:1135
int numofscans
Definition: env.h:85
int nsave
Definition: env.h:83
int doNotRemoveLockFile
Definition: linuxpops.c:81
#define SEQUENCE
Definition: observing_par.h:43
void subArgs(int wt, const char *fmt,...)
Definition: parse.c:430
int scanct
Definition: image.h:51
double fscan
Definition: header.h:224
int readFile()
Definition: io.c:149
int validate(int which)
Definition: linuxpops.c:164
char * secondArg
Definition: parse.h:181
void st_print()
int ntokens
Definition: parse.h:173
int watchFile()
Definition: io.c:384
int decLevel(int l)
Definition: io.c:134
int mapangle
Definition: env.h:70
char * firstArg
Definition: parse.h:180
int parseCmd(char *buf)
Definition: parse.c:2090
#define CONT_MAP
Definition: observing_par.h:45
int p_getScan()
Definition: io.c:796
int fileChanged()
Definition: io.c:402
int checkLockFile()
Definition: io.c:287
double lscan
Definition: header.h:225
char filename[256]
Definition: env.h:9
int doingOTF
Definition: otf.c:64
#define VERBOSE_PARSE
Definition: makemem.c:90
int findVersions(int which, char *seq)
Definition: io.c:1054
int freeY()
Definition: paxis.c:488
int doClass()
Definition: io.c:1202
int verboseLevel
Definition: linuxpops.c:80