Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
optical.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 
63 float *ydata;
64 int dl;
65 float scan;
66 {
67  int i;
68 
69  if(ydata == NULL)
70  {
71  return(1);
72  }
73 
74  env->peakChan = 0;
75  /* redetermine min and max */
76  env->datamax = -9999999999.9;
77  env->datamin = 9999999999.0;
78 
79  for(i=0;i<dl;i++)
80  {
81  if(ydata[i] > env->datamax)
82  {
83  env->datamax = ydata[i];
84  env->peakChan = i;
85  }
86 
87  if(ydata[i] < env->datamin)
88  {
89  env->datamin = ydata[i];
90  }
91  }
92 
93  if(fabs(env->datamax - env->datamin) < DATASPREAD)
94  {
95  st_print("Scan #%7.2f is all %.4f\n", scan, env->datamin);
96 
97  env->datamin -= 1.0;
98  env->datamax += 1.0;
99 
100  return(1);
101  }
102 
103  st_report("DataMin %f, dataMax %f", env->datamin, env->datamax);
104 
105  return(0);
106 }
107 
108 
109 
111 float *data;
112 struct HEADER *h;
113 int plot;
114 {
115  float ydata[MAX_CONT_SAMPLES], *yp;
116  int i, dlen, oldzline;
117 
118  dlen = (int)h->noint;
119 
120  zero_check("Phases", dlen, data);
121 
122  if(dlen > MAX_CONT_SAMPLES)
123  {
124  st_fail("Too many Continuum Samples: %d", dlen);
125  return(1);
126  }
127 
128  yp = &ydata[0];
129 
130  oldzline = env->zline; /* Save for later */
131 
132  if(isSet(PF_S_FLAG)) /* switched ? */
133  {
134  if(env->issmt)
135  {
136  smt_bin_and_cal_data( yp, dlen, SWITCHED, data, h);
137  }
138  else
139  {
140  kp_bin_and_cal_data( yp, dlen, SWITCHED, data, h);
141  }
142 
143  dlen /= h->nophase;
144  }
145  else
146  {
147  env->zline = 0;
148 
149  for(i=0;i<dlen;i++)
150  {
151  ydata[i] = data[i];
152  }
153  }
154 
155  if(cont_determine_min_max(ydata, dlen, h->scan))
156  {
157  env->zline = oldzline;
158 
159  return(0);
160  }
161 
162  if(isSet(PF_S_FLAG))
163  {
164  clearFillContStruct(h, dlen, "Sample Number", "Intensity");
165  }
166  else
167  {
168  clearFillContStruct(h, dlen, "Sample Number", "Counts");
169  }
170 
171  for(i=0;i<dlen;i++)
172  {
173  cont_plain_send.xdata[i] = (float)(i) + 1.0;
174  cont_plain_send.ydata[i] = ydata[i];
175  }
176 
177  if(xgraphic)
178  {
180  }
181 
182  env->zline = oldzline;
183 
185 
186  return(0);
187 }
188 
189 
191 struct LP_IMAGE_INFO *image;
192 {
193  int row, col, count=0;
194  char fname[256];
195  double x, y, z, x1, x2, y1, y2;
196  FILE *fp;
197 
198  sprintf(fname, "/tmp/%s/opt-3d-plot.dem", session);
199 
200  if( (fp = fopen(fname, "w") ) <= (FILE *)0)
201  {
202  st_fail("display_3d_optical(): Unable to open '%s'", fname);
203  return(1);
204  }
205 
206  fprintf(fp, "reset\n");
207  fprintf(fp, "set title \"%16.16s\"\n", image->head.object);
208 
209  fprintf(fp, "set xlabel \"Az Offset\"\n");
210  fprintf(fp, "set ylabel \"El. Offset\"\n");
211  fprintf(fp, "set zlabel \"Intensity\"\n");
212 
213  fprintf(fp, "#\n");
214  fprintf(fp, "set border 4095\n");
215  fprintf(fp, "set hidden3d\n");
216  fprintf(fp, "#\n");
217 
218  x1 = -(image->head.noxpts / 2.0) * 1.5; /* replace with plate_scale */
219  x2 = (image->head.noxpts / 2.0) * 1.5; /* replace with plate_scale */
220  y1 = -(image->head.noypts / 2.0) * 1.5; /* replace with plate_scale */
221  y2 = (image->head.noypts / 2.0) * 1.5; /* replace with plate_scale */
222 
223  fprintf(fp, "set xrange [%f:%f]\n", x1, x2);
224  fprintf(fp, "set yrange [%f:%f]\n", y1, y2);
225  fprintf(fp, "set cbrange [%f:%f]\n", env->datamin, env->datamax);
226  fprintf(fp, "#\n");
227 
228  fprintf(fp, "set samples %d*%d\n", (int)image->head.noxpts, (int)image->head.noypts);
229  fprintf(fp, "set isosamples 60\n");
230  fprintf(fp, "set ticslevel 0.1\n");
231  fprintf(fp, "set pm3d\n");
232  fprintf(fp, "set palette color\n");
233  fprintf(fp, "set palette model RGB\n");
234  fprintf(fp, "set palette defined ( 0 \"blue\", 1 \"green\", 2 \"yellow\", 3 \"red\" )\n");
235  fprintf(fp, "set palette gamma 1.0\n");
236  fprintf(fp, "#\n");
237 
238  fprintf(fp, "set view 60.0, 30.0, 1.0, 1.0\n");
239  fprintf(fp, "set terminal x11 background rgb \"black\" enhanced 1 size 1200, 850 position 800, 500\n");
240  fprintf(fp, "set contour both\n");
241  fprintf(fp, "set cntrparam levels incr %.2f,%.2f,%.2f\n", env->datamin, env->datamax / 11.0, env->datamax);
242  fprintf(fp, "splot \"/tmp/%s/opt-3d-plot.dat\" every 1::0::1024 with lines\n", session);
243 
244  fclose(fp);
245 
246  /* Write the data */
247  sprintf(fname, "/tmp/%s/opt-3d-plot.dat", session);
248 
249  if( (fp = fopen(fname, "w") ) <= (FILE *)0)
250  {
251  log_msg("display_3d_optical(): Unable to open '%s'", fname);
252  return(1);
253  }
254 
255  count = 0;
256  for(row=0;row<(int)image->head.noypts;row++) /* Search all cells for valid data */
257  {
258  for(col=0;col<(int)image->head.noxpts;col++)
259  {
260  x = (-image->head.noxpts / 2.0 * 1.5) + (double)col * 1.5; /* Replace with plate_scale */
261  y = (-image->head.noypts / 2.0 * 1.5) + (double)row * 1.5; /* Replace with plate_scale */
262  z = image->yplot1[count];
263 
264  fprintf(fp, "%8.2f %8.2f %8.2f\n", x, y, z);
265 
266  count++;
267  }
268 
269  fprintf(fp, " \n");
270  }
271 
272  fclose(fp);
273 
274  st_report("display_3d_optical(); Wrote %d cells to %s", count, fname);
275 
276  sprintf(fname, "xgraphic load \"/tmp/%s/opt-3d-plot.dem\"", session);
277 
278  sock_send(xgraphic, fname);
279 
280  return(0);
281 }
282 
283 
284 
285 
286 int cont_display_optical(image, plot)
287 struct LP_IMAGE_INFO *image;
288 int plot;
289 {
290  float *yp;
291  int i, dlen;
292 
293  dlen = image->head.noint;
294 
295  clearFillContStruct(&image->head, dlen, "Sample Number", "Intensity");
296 
297  yp = &image->yplot1[0];
298  for(i=0;i<dlen;i++,yp++)
299  {
300  cont_plain_send.xdata[i] = (float)(i) + 1.0;
301  cont_plain_send.ydata[i] = *yp;
302  }
303 
304  if(xgraphic)
305  {
307  }
308 
309  if(isSet(PF_3_FLAG))
310  {
311  optical_determine_min_max(image->yplot1, dlen, image->head.scan);
312 
313  display_3d_optical(image);
314  }
315 
317 
318  return(0);
319 }
320 
321 
322 
323 /* Display a table of switched values */
325 float *data;
326 struct HEADER *h;
327 {
328  float *yp;
329  int i, dlen;
330 
331  yp = data;
332  dlen = h->noint;
333 
334  for(i=0;i<dlen;i++,yp++)
335  {
336  if(!(i%10))
337  {
338  printf("\n%4d: ", i);
339  }
340 
341  printf("%10.6f ", *yp);
342  }
343 
344  printf("\n");
345 
346  return(0);
347 }
struct SOCK * xgraphic
Definition: linuxpops.c:75
double scan
Definition: header.h:35
int clearFillContStruct(struct HEADER *h, int dlen, char *xl, char *yl)
Definition: cont.c:1726
int optical_determine_min_max(float *ydata, int dl, float scan)
Definition: optical.c:62
double noint
Definition: header.h:211
int scan
double nophase
Definition: header.h:66
int display_optical_table(float *data, struct HEADER *h)
Definition: optical.c:324
FILE * fp
Definition: linuxpops.c:70
#define SWITCHED
Definition: defines.h:21
Definition: header.h:13
int optical_show_phases(float *data, struct HEADER *h, int plot)
Definition: optical.c:110
float xdata[MAX_CONT_SAMPLES]
Definition: accum.h:117
int issmt
Definition: env.h:63
float ydata[MAX_CONT_SAMPLES]
Definition: accum.h:118
int zero_check(char *who, int dl, float *data)
Definition: cont.c:2498
double datamin
Definition: env.h:181
int peakChan
Definition: env.h:126
int cont_display_optical(struct LP_IMAGE_INFO *image, int plot)
Definition: optical.c:286
int cont_determine_min_max(float *ydata, int dl, float scan)
Definition: cont.c:1206
struct ENVIRONMENT * env
Definition: linuxpops.c:71
int log_msg(const char *fmt,...)
int isSet(int flag)
Definition: parse.c:646
struct HEADER head
Definition: image.h:104
int sock_send(struct SOCK *s, char *message)
double datamax
Definition: env.h:180
void st_fail()
int kp_bin_and_cal_data(float *ydata, int dl, int avg, float *data, struct HEADER *h)
Definition: cont.c:1252
int smt_bin_and_cal_data(float *ydata, int dl, int avg, float *data, struct HEADER *h)
Definition: cont.c:1630
int sendCont(int mode)
Definition: cont.c:1827
double count[3]
Definition: header.h:173
#define DATASPREAD
Definition: defines.h:23
char session[80]
Definition: strings.c:67
struct CONTINUUM_PLAIN cont_plain_send
Definition: cont.c:63
void st_report()
#define SEQUENCE
Definition: observing_par.h:43
#define SEND_PLAIN
Definition: defines.h:134
int validate(int which)
Definition: linuxpops.c:164
void st_print()
#define MAX_CONT_SAMPLES
Definition: accum.h:26
float ydata[MAX_ATM_ELEMENTS]
Definition: atm.c:91
int zline
Definition: env.h:151
int display_3d_optical(struct LP_IMAGE_INFO *image)
Definition: optical.c:190