Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
befd.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 
62 int deCommaBuf(buf)
63 char *buf;
64 {
65  char *cp;
66 
67  if(buf)
68  {
69  for(cp=buf;*cp;cp++)
70  {
71  if(*cp == ',')
72  {
73  *cp = ' ';
74  }
75  }
76  }
77 
78  return(0);
79 }
80 
81 
82 int fillScans(bscan, s, f, buf)
83 int bscan;
84 char *s;
85 double f;
86 char *buf;
87 {
88  int n = 0;
89  int i;
90  struct HEADER *p;
91  double freq, tsys, tcal;
92  char *sbname[] = { " ", "LSB", "USB", "DSB" };
93  char tbuf[256];
94 
95  p = &sa[0];
96  for(i=0;i<env->numofscans;i++,p++)
97  {
98  if(!strncmp(p->obsmode, "CONTSEQ ", 8))
99  {
100  if((int)p->scan < bscan)
101  {
102  continue;
103  }
104 
105  freq = restFreq(p) / 1000.0;
106 
107  if(f && fabs(f-freq) > 0.001)
108  {
109  continue;
110  }
111 
112  if(s)
113  {
114  if(strncmp(s, p->object, strlen(s)))
115  {
116  continue;
117  }
118  }
119 
120  if(manual_tcal > 0.0 && fabs(p->tcal-400.0) < 1.0)
121  {
122  tsys = p->stsys * manual_tcal / p->tcal;
123  tcal = manual_tcal;
124  }
125  else
126  {
127  tsys = p->stsys;
128  tcal = p->tcal;
129  }
130 
131  sprintf(tbuf, "' %10.10s' '%10.6f' '%10.4f' '%6.2f' '%7.2f' '%4.0f' '%4.0f' '%s' ",
132  p->object, freq, p->utdate, p->ut, p->scan, tsys, tcal, sbname[(int)p->sideband]);
133 
134  strcat(buf, tbuf);
135 
136  n++;
137 
138  if(strlen(buf) > (10*4000))
139  {
140  return(n);
141  }
142  }
143  }
144 
145  return(n);
146 }
147 
148 
149 /* Changes:
150  *
151  */
152 
153 int doBefd()
154 {
155  int n, ret, sbs;
156  char rst[4096];
157  static char cmd[12*4096], bigBuf[10*4096], src[256];
158 
159  if(args->ntokens > 1)
160  {
161  strcpy(src, args->secondArg);
162  }
163  else
164  {
166 
167  return(0);
168  }
169 
170  saveEnv();
171 
172  bzero(bigBuf, sizeof(bigBuf));
173  bzero(rst, sizeof(rst));
174 
175  st_report("doBefd(): Entered looking for source: %s", src);
176 
177  n = fillScans(0, src, 0.0, bigBuf);
178 
179  st_report("doBefd(): Filled First with %d scans", n);
180 
181  if(n || strlen(bigBuf))
182  {
183  sprintf(cmd, "--list --height=1080 --width=600 --column='Source' --column='Freq' --column='Date' --column='UT' --column='Scan' --column='Tsys' --column='Tsys' --column='SB' --print-column=5 --text='Select First Scan to Reduce' %s", bigBuf);
184 
185  if(isSet(PF_V_FLAG))
186  {
187  st_print("pickSourceFreq(): %s\n", cmd);
188  }
189 
190  st_report("Standby, Finding all Seq scans");
191 
192  ret = doZenity(cmd, rst);
193 
194  if(!ret && strlen(rst))
195  {
196  st_report("Setting Bscan to %s", rst);
197 
198  env->bscan = atof(rst);
199  }
200  else
201  {
202  restoreEnv();
203  return(1);
204  }
205 
206  bzero(bigBuf, sizeof(bigBuf));
207  bzero(rst, sizeof(rst));
208 
209  subArgs(2, "%.2f", env->bscan);
210 
211  getScan(1);
212 
213  n = fillScans((int)env->bscan, src, restFreq(&h0->head) / 1000.0, bigBuf);
214 
215  sprintf(cmd, "--list --height=600 --width=600 --column='Source' --column='Freq' --column='Date' --column='UT' --column='Scan' --column='Tsys' --column='Tsys' --column='SB' --print-column=5 --text='Select Last Scan to Reduce' %s", bigBuf);
216 
217  st_report("Standby, Finding Ending Seq scans");
218 
219  ret = doZenity(cmd, rst);
220 
221  if(!ret && strlen(rst))
222  {
223  st_report("Setting Escan to %s", rst);
224 
225  env->escan = atoi(rst);
226  }
227  else
228  {
229  restoreEnv();
230  return(1);
231  }
232 
233  bzero(rst, sizeof(rst));
234  sprintf(cmd, "--list --height=400 --width=500 --column='Index' --column='Sideband' --column='Notes' --print-column=1 --separator=',' --text='Select IFs to Use' \
235  '1' 'LSB' 'Scans xx.01 and xx.03' \
236  '2' 'USB' 'Scans xx.02 and xx.04' \
237  '3' 'Both' 'Scans xx.01, xx.02, xx.03 and xx.04' \
238  '4' '1-2 USB' 'Scans xx.01 and xx.02' \
239  '5' '1-2 LSB' 'Scans xx.01 and xx.02' \
240  ");
241 
242  if(isSet(PF_V_FLAG))
243  {
244  st_print("pickIF(): %s\n", cmd);
245  }
246 
247  st_report("Select, IF's to use");
248 
249  ret = doZenity(cmd, rst);
250 
251  if(!ret && strlen(rst))
252  {
253  st_report("Using Index %s", rst);
254  }
255  else
256  {
257  restoreEnv();
258  return(1);
259  }
260 
261  sbs = atoi(rst);
262 
263  if(sbs < 1 || sbs > 5)
264  {
265  st_fail("Unknown Response %s", rst);
266 
267  restoreEnv();
268 
269  return(1);
270  }
271 
272  if(sbs == 1)
273  {
274  sprintf(cmd, "--forms --title='Beam Efficiencies' --text='Enter Rejections.' --separator=',' --add-entry='H-LSB Rejection' --add-entry='V-LSB Rejection' ");
275  }
276  else
277  if(sbs == 2)
278  {
279  sprintf(cmd, "--forms --title='Beam Efficiencies' --text='Enter Rejections.' --separator=',' --add-entry='H-USB Rejection' --add-entry='V-USB Rejection'");
280  }
281  else
282  if(sbs == 3)
283  {
284  sprintf(cmd, "--forms --title='Beam Efficiencies' --text='Enter Rejections.' --separator=',' --add-entry='H-LSB Rejection' --add-entry='H-USB Rejection' --add-entry='V-LSB Rejection' --add-entry='V-USB Rejection'");
285  }
286  else
287  if(sbs == 4)
288  {
289  sprintf(cmd, "--forms --title='Beam Efficiencies' --text='Enter Rejections.' --separator=',' --add-entry='H-USB Rejection' --add-entry='V-USB Rejection' ");
290  }
291  else
292  if(sbs == 5)
293  {
294  sprintf(cmd, "--forms --title='Beam Efficiencies' --text='Enter Rejections.' --separator=',' --add-entry='H-LSB Rejection' --add-entry='V-LSB Rejection'");
295  }
296 
297  bzero(rst, sizeof(rst));
298 
299  st_report("Enter Rejections");
300 
301  ret = doZenity(cmd, rst);
302 
303  if(!ret && strlen(rst))
304  {
305  st_report("Setting Rejections to %s", rst);
306  }
307  else
308  {
309  restoreEnv();
310  return(1);
311  }
312 
313  deCommaBuf(rst);
314 
315  if(sbs == 1)
316  {
317  sprintf(cmd, "beffl %d %d %s", (int)env->bscan, (int)env->escan, rst);
318  }
319  else
320  if(sbs == 2)
321  {
322  sprintf(cmd, "beffu %d %d %s", (int)env->bscan, (int)env->escan, rst);
323  }
324  else
325  if(sbs == 3)
326  {
327  sprintf(cmd, "beff4r %d %d %s", (int)env->bscan, (int)env->escan, rst);
328  }
329  else
330  if(sbs == 4)
331  {
332  sprintf(cmd, "beff12 %d %d %s", (int)env->bscan, (int)env->escan, rst);
333  }
334  else
335  if(sbs == 5)
336  {
337  sprintf(cmd, "beff12 %d %d %s", (int)env->bscan, (int)env->escan, rst);
338  }
339 
340  restoreEnv(); /* I needed to wait until I had scan numbers out of the env before restoring */
341 
342  st_report(" ");
343  st_report("Executing: %s", cmd);
344  st_report(" ");
345 
346  parseCmd(cmd);
347 
348  return(0);
349  }
350 
351  restoreEnv();
352 
353  return(0);
354 }
struct LP_IMAGE_INFO * h0
Definition: image.c:74
double scan
Definition: header.h:35
int doBefd()
Definition: befd.c:153
struct PARSE_STACK * args
Definition: parse.h:196
double utdate
Definition: header.h:61
int deCommaBuf(char *buf)
Definition: befd.c:62
Definition: header.h:13
int printH_FlagHelp(char *cmd)
Definition: help.c:430
double tcal
Definition: header.h:202
struct HEADER * sa
Definition: linuxpops.c:72
int getScan(int verbose)
Definition: io.c:812
double sideband
Definition: header.h:143
double restFreq(struct HEADER *h)
Definition: linuxpops.c:2837
struct ENVIRONMENT * env
Definition: linuxpops.c:71
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
char obsmode[8]
Definition: header.h:41
int fillScans(int bscan, char *s, double f, char *buf)
Definition: befd.c:82
int saveEnv()
Definition: env.c:709
void st_fail()
int restoreEnv()
Definition: env.c:722
double stsys
Definition: header.h:203
void st_report()
int numofscans
Definition: env.h:85
double bscan
Definition: env.h:173
void subArgs(int wt, const char *fmt,...)
Definition: parse.c:430
double manual_tcal
Definition: env.c:86
char * secondArg
Definition: parse.h:181
void st_print()
int ntokens
Definition: parse.h:173
double escan
Definition: env.h:186
char object[16]
Definition: header.h:40
char * firstArg
Definition: parse.h:180
int parseCmd(char *buf)
Definition: parse.c:2090
double ut
Definition: header.h:62