Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
spec5.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 
62  double scan;
63  double az;
64  double el;
65 
66  double gpeaks[5];
67  double gsums[5];
68 
69  int used;
70  int good_fit;
71 };
72 
74 
75 char *spec5Strings[] = { "North ",
76  "South ",
77  "Center",
78  "East ",
79  "West "
80 };
81 
82 
84 {
85  int i, j, k;
86  double azAvg, elAvg;
87  struct SPEC_5_RESULTS *p;
88 
89  st_report(" ");
90  st_report("Spec 5 Results");
91  st_report(" ");
92  st_report(" Scan Az El GPeak GSum Fit ");
93 
94  azAvg = elAvg = 0.0;
95  k = j = 0;
96 
97  p = &spec5_results[0];
98 
99  for(i=0;i<4;i++,p++)
100  {
101  st_report("%8.2f %7.2f %7.2f %7.2f %7.2f %d", p->scan, p->az, p->el, p->gpeaks[2], p->gsums[2], p->good_fit);
102 
103  if(p->az != 0.0)
104  {
105  azAvg += p->az;
106  j++;
107  }
108 
109  if(p->el != 0.0)
110  {
111  elAvg += p->el;
112  k++;
113  }
114  }
115 
116  if(j)
117  {
118  azAvg /= (double)j;
119  }
120 
121  if(k)
122  {
123  elAvg /= (double)k;
124  }
125 
126  if(j && k);
127  {
128  st_report("Average %7.2f %7.2f", azAvg, elAvg);
129  }
130 
131  return(0);
132 }
133 
134 
135 
137 {
138  int i, indx, x1mode, x2mode;
139  double scan, tscan;
140  double bw;
141  double x1, x2, x3; /* X coordinates */
142  float a, b, c; /* curve constants */
143  char tbuf[256];
144  struct SPEC_5_RESULTS *p;
145 
146  if(isSet(PF_C_FLAG))
147  {
148  st_report("doSpecFive(): Clearing out Pointing Results Array");
149 
150  bzero((char *)&spec5_results[0], sizeof(spec5_results));
151 
152  return(0);
153  }
154 
155  if(isSet(PF_L_FLAG))
156  {
158  return(0);
159  }
160 
161  if(args->ntokens < 2)
162  {
163  return(1);
164  }
165 
166  scan = atof(args->secondArg);
167 
168  if(scan <= 0.0)
169  {
170  return(1);
171  }
172 
173  indx = getFeed(scan);
174 
175  if(indx > 4) /* Shift IF 5-8 down to 1-4 */
176  {
177  indx -= 4;
178  }
179 
180  if(indx < 1 || indx > 4)
181  {
182  st_fail("Scan # %.2f produced a bogus index of: %f: Must be 1 - 4", scan, indx);
183  return(1);
184  }
185 
186  indx--;
187 
188  p = &spec5_results[indx];
189 
190  p->scan = scan;
191 
192  /* Save axis modes */
193  x1mode = env->x1mode;
194  x2mode = env->x2mode;
195 
196  env->x1mode = XMODE_FREQ; /* Place FREQ on bottom axis so Gaussian fits are in Freq */
197  env->x2mode = XMODE_VEL;
198 
199  /* Load all 5 sccans into H1-H5, remove baseline; fit a gaussian; record Peak */
200 
201  for(i=0;i<5;i++)
202  {
203  tscan = scan + ((double)i - 4.0 + 2.0);
204  st_report("Fetching %s Scan: %.2f in H%d", spec5Strings[i], tscan, i+1);
205 
206  sprintf(tbuf, "h%d", i+1);
207  parseCmd(tbuf);
208 
209  sprintf(tbuf, "get %.2f", tscan);
210  parseCmd(tbuf);
211 
212  st_report("Scan %.2f: openpar[8]: %.1f", tscan, h0->head.openpar[8]);
213 
214  if(i<4)
215  {
216  if(fabs(h0->head.openpar[8]-9998.5) > 0.5)
217  {
218  st_fail("Scan %.2f is not part of a Spec 5", tscan);
219 
220  env->x1mode = x1mode;
221  env->x2mode = x2mode;
222 
223  return(1);
224  }
225  }
226  else
227  {
228  if(fabs(h0->head.openpar[8]-9999.5) > 0.5)
229  {
230  st_fail("Scan %.2f is not the last of a Spec 5", tscan);
231 
232  env->x1mode = x1mode;
233  env->x2mode = x2mode;
234 
235  return(1);
236  }
237  }
238 
239  sprintf(tbuf, "show");
240  parseCmd(tbuf);
241  usleep(100000);
242 
243  sprintf(tbuf, "baseline");
244  parseCmd(tbuf);
245  usleep(100000);
246 
247  sprintf(tbuf, "gauss /a");
248  parseCmd(tbuf);
249  usleep(100000);
250 
251  p->gpeaks[i] = env->gaussPeak;
252  p->gsums[i] = env->gaussSum;
253  }
254 
255  sprintf(tbuf, "h3"); /* Point back to center scan */
256  parseCmd(tbuf);
257 
258  sprintf(tbuf, "xx");
259  parseCmd(tbuf);
260 
261  st_print("\n");
262  st_print(" Az Offset: %7.2f, El Offset: %7.2f\n", h0->head.uxpnt, h0->head.uypnt);
263  st_print("\n");
264 
265  st_print(" %s\n", spec5Strings[0]);
266  st_print(" %7.2f\n", p->gpeaks[0]);
267  st_print(" %7.2f\n", p->gsums[0]);
268  st_print(" \n");
269  st_print(" \n");
270  st_print(" \n");
271  st_print(" \n");
272  st_print(" %s %s %s\n", spec5Strings[3], spec5Strings[2], spec5Strings[4]);
273  st_print(" %7.2f %7.2f %7.2f\n", p->gpeaks[3], p->gpeaks[2], p->gpeaks[4]);
274  st_print(" %7.2f %7.2f %7.2f\n", p->gsums[3], p->gsums[2], p->gsums[4]);
275  st_print(" \n");
276  st_print(" \n");
277  st_print(" \n");
278  st_print(" %s\n", spec5Strings[1]);
279  st_print(" %7.2f\n", p->gpeaks[1]);
280  st_print(" %7.2f\n", p->gsums[1]);
281  st_print(" \n");
282 
283  x1 = -h0->head.bfwhm;
284  x2 = 0.0;
285  x3 = h0->head.bfwhm;
286 
287  /* Steal the continuum gaussian fit routine, as it was written for this */
288 
289  /* Determine the Gaussian curve that fits the Az data */
290  if( cont_gauss(p->gsums[3], p->gsums[2], p->gsums[4], x1, x2, x3, &a, &b, &c) )
291  {
292  if( (1.0 / b) > 0.0)
293  {
294  bw = sqrt( 1.0 / b) * 1.664;
295  }
296 
297  st_print("AZ: Peak = %7.2f, b = %f, Off: = %5.2f, BW = %7.2f, Corrected: %7.2f\n", a, b, c, bw, h0->head.uxpnt-c);
298  p->az = h0->head.uxpnt-c;
299 
300  p->good_fit++;
301  }
302  else
303  {
304  st_print("AZ: Fit Failed\n");
305  }
306 
307  /* Determine the Gaussian curve that fits the EL data */
308  if( cont_gauss(p->gsums[1], p->gsums[2], p->gsums[0], x1, x2, x3, &a, &b, &c) )
309  {
310  if( (1.0 / b) > 0.0)
311  {
312  bw = sqrt( 1.0 / b) * 1.664;
313  }
314 
315  st_print("EL: Peak = %7.2f, b = %f, Off: = %5.2f, BW = %7.2f, Corrected: %7.2f\n", a, b, c, bw, h0->head.uypnt-c);
316  p->el = h0->head.uypnt-c;
317 
318  p->good_fit++;
319  }
320  else
321  {
322  st_print("EL: Fit Failed\n");
323  }
324 
326 
327  env->x1mode = x1mode;
328  env->x2mode = x2mode;
329 
330  return(0);
331 }
struct LP_IMAGE_INFO * h0
Definition: image.c:74
char * spec5Strings[]
Definition: spec5.c:75
int getFeed()
struct PARSE_STACK * args
Definition: parse.h:196
int x1mode
Definition: env.h:145
int good_fit
Definition: spec5.c:70
int scan
double bfwhm
Definition: header.h:114
int cont_gauss(float y1, float y2, float y3, double x1, double x2, double x3, float *a, float *b, float *c)
Definition: gauss.c:766
int doSpecFive(void)
Definition: spec5.c:136
double gpeaks[5]
Definition: spec5.c:66
double openpar[10]
Definition: header.h:155
double uypnt
Definition: header.h:51
struct ENVIRONMENT * env
Definition: linuxpops.c:71
int isSet(int flag)
Definition: parse.c:646
double scan
Definition: spec5.c:62
struct HEADER head
Definition: image.h:104
struct SPEC_5_RESULTS spec5_results[4]
Definition: spec5.c:73
void st_fail()
double gaussPeak
Definition: env.h:199
int listPointingResults(void)
Definition: spec5.c:83
double el
Definition: spec5.c:64
#define XMODE_FREQ
Definition: defines.h:95
void st_report()
double gsums[5]
Definition: spec5.c:67
double uxpnt
Definition: header.h:50
double gaussSum
Definition: env.h:202
int used
Definition: spec5.c:69
char * secondArg
Definition: parse.h:181
void st_print()
int ntokens
Definition: parse.h:173
double az
Definition: spec5.c:63
int parseCmd(char *buf)
Definition: parse.c:2090
#define XMODE_VEL
Definition: defines.h:96
int x2mode
Definition: env.h:146