Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ffb.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 char ffb_lines[80][80];
64 
65 
67 
68 static char ffb_tok[40][40];
69 
70 static int ffb_get_tok(edit)
71 char *edit;
72 {
73  int c = 0;
74  char *token;
75 
76  bzero((char *)&ffb_tok, sizeof(ffb_tok));
77 
78  token = strtok(edit, " :\n");
79  while(token != (char *)NULL)
80  {
81  sprintf(ffb_tok[c++], "%s", token);
82  token = strtok((char *)NULL, " :\n");
83  }
84 
85  return(c);
86 }
87 
88 
89 int printFFBChan(c, p, header)
90 int c, header;
91 struct FFB_CHANNELS *p;
92 {
93  struct FFB_CHANNELS *pp;
94 
95  if(!p)
96  {
97  pp = &ffb_chans[c];
98  }
99  else
100  {
101  pp = p;
102  }
103 
104  if(header)
105  {
106  st_print("Chan# Chan# Crate# Board# CON2 CON3 CON4\n");
107  }
108 
109 
110  st_print("%4d %4d %d %2d %8.8s %8.8s %8.8s\n",
111  c, pp->chan, pp->crate, pp->board, pp->con2, pp->con3, pp->con4);
112 
113  return(0);
114 }
115 
116 
118 {
119  int i, first = 1;
120  struct FFB_CHANNELS *p;
121 
122  p = &ffb_chans[0];
123 
124  for(i=0;i<MAX_FFB_CHANS;i++,p++)
125  {
126  if(!strlen(p->con2) || !strlen(p->con3) || !strlen(p->con4))
127  {
128  printFFBChan(i, p, first);
129  first = 0;
130  }
131  }
132 
133  return(0);
134 }
135 
136 
137 int ffb_load()
138 {
139  int i, j, n, bchan, echan, indx=0;
140  char fname[256], line[512], *string, *cp;;
141  FILE *fp;
142 
143  sprintf(fname, "%s/share/ffb_numbering.dat", pkg_home);
144 
145  if((fp = fopen(fname, "r") ) <= (FILE *)0)
146  {
147  st_fail("Unable to open file %s", fname);
148  return(0);
149  }
150 
151  bzero((char *)&ffb_chans[0], sizeof(ffb_chans));
152 
153  while((string = fgets(line, sizeof(line), fp)) != NULL)
154  {
155  if(line[0] == '#')
156  {
157 // fprintf(stderr, "ffb_load(): Skipping Comment\n");
158  continue;
159  }
160 
161  strcpy(ffb_lines[indx], line);
162  indx++;
163 
164  n = ffb_get_tok(line);
165 
166  if(!n)
167  {
168 // fprintf(stderr, "ffb_load(): Skipping Enpty Line\n");
169  continue;
170  }
171 
172  if(!strcmp(ffb_tok[0], "CON2"))
173  {
174  if(n != 7)
175  {
176 // fprintf(stderr, "ffb_load(): NTok != 7; %d Skipping Enpty Line\n", n);
177  continue;
178  }
179 /*
180  0 1 2 3 4 5 6
181 CON2: 1-128 513-640 1025-1152 1537-1664 2049-2176 L-yellow
182  */
183 
184  for(j=1;j<6;j++)
185  {
186  bchan = atoi(ffb_tok[j]) -1;
187  cp = strstr(ffb_tok[j], "-");
188  echan = atoi(cp+1);
189 
190 // fprintf(stderr, "ffb_load(): Loading CON2 Chans: %4d to %4d: %s\n", bchan, echan, ffb_tok[6]);
191  for(i=bchan;i<echan;i++)
192  {
193  strcpy(ffb_chans[i].con2, ffb_tok[6]);
194  }
195  }
196 
197  }
198  else
199  if(!strcmp(ffb_tok[0], "CON3"))
200  {
201  if(n != 7)
202  {
203  fprintf(stderr, "ffb_load(): NTok != 7; %d Skipping Enpty Line\n", n);
204  continue;
205  }
206 /*
207  0 1 2 3 4 5 6
208 CON3: 1-64 513-576 1025-1088 1537-1600 2049-2112 L-orange
209  */
210 
211  for(j=1;j<6;j++)
212  {
213  bchan = atoi(ffb_tok[j]) -1;
214  cp = strstr(ffb_tok[j], "-");
215  echan = atoi(cp+1);
216 
217 // fprintf(stderr, "ffb_load(): Loading CON3 Chans: %4d to %4d: %s\n", bchan, echan, ffb_tok[6]);
218  for(i=bchan;i<echan;i++)
219  {
220  strcpy(ffb_chans[i].con3, ffb_tok[6]);
221  }
222  }
223  }
224  else
225  if(!strcmp(ffb_tok[0], "CHAN"))
226  {
227  if(n != 8)
228  {
229 // fprintf(stderr, "ffb_load(): NTok != 8; %d Skipping Enpty Line\n", n);
230  continue;
231  }
232 
233 /*
234  0 1 2 3 4 5 6 7
235 CHAN: 1-16 513-528 1025-1040 1537-1552 2049-2064 L-brown 0
236  */
237 
238  for(j=1;j<6;j++)
239  {
240  bchan = atoi(ffb_tok[j]) -1;
241  cp = strstr(ffb_tok[j], "-");
242  echan = atoi(cp+1);
243 
244 // fprintf(stderr, "ffb_load(): Loading CHAN Chans: %4d to %4d: CON4: %s, Board: %d\n",
245 // bchan, echan, ffb_tok[6], atoi(ffb_tok[7]));
246  for(i=bchan;i<echan;i++)
247  {
248  ffb_chans[i].chan = i;
249  ffb_chans[i].crate = j-1;
250  ffb_chans[i].board = atoi(ffb_tok[7]);
251 
252  strcpy(ffb_chans[i].con4, ffb_tok[6]);
253  }
254  }
255  }
256  else
257  {
258  fprintf(stderr, "ffb_load(): Skipping Keyword: %s\n", ffb_tok[0]);
259  continue;
260  }
261  }
262 
263  fclose(fp);
264 
265  max_ffb_lines = indx;
266 
267  st_report("FFB_Load(): Loaded %d lines", indx);
268 
269  verifyFFBChans();
270 
271  return(0);
272 }
273 
274 
276 int chan, first;
277 {
278  setColor(RED);
279 
280  if(h0->head.noint == 1024 && chan < 1024) /* It's possible this is one of 2 halves; 1 mHz */
281  {
282  printFFBChan(chan+1024, NULL, first);
283  }
284 
285  if(h0->head.noint == 512 && chan < 512) /* It's possible this is one of 4 quads; 1 mHz */
286  {
287  printFFBChan(chan+512, NULL, first);
288  printFFBChan(chan+1024, NULL, first);
289  printFFBChan(chan+1536, NULL, first);
290  }
291 
292  if(h0->head.noint == 256 && chan < 256) /* It's possible this is one of 2 halves; 250 kHz */
293  {
294  printFFBChan(chan+256, NULL, first);
295  }
296 
297  if(h0->head.noint == 128 && chan < 128) /* It's possible this is one of 4 quads; 250 kHz */
298  {
299  printFFBChan(chan+128, NULL, first);
300  printFFBChan(chan+256, NULL, first);
301  printFFBChan(chan+384, NULL, first);
302  }
303 
304  setColor(BLACK);
305 
306  return(0);
307 }
308 
309 
310 int doFFB()
311 {
312  int i, c, first=1, chan;
313  char hint[256];
314 
315  if(!env->issmt)
316  {
317  st_report("Not SMT data");
318  return(0);
319  }
320 
321  if(args->ntokens > 1)
322  {
323  c = atoi(args->secondArg);
324 
325  if(c >= 0 && c < MAX_FFB_CHANS)
326  {
327  printFFBChan(c, NULL, 1);
328  }
329  else
330  {
331  st_fail("FFB(): Channel %d, out of range: 0 - %d", MAX_FFB_CHANS);
332  return(1);
333  }
334 
335  return(0);
336  }
337 
338  if(isSet(PF_A_FLAG))
339  {
340  for(i=0;i<MAX_FFB_CHANS;i++)
341  {
342  if(!(i%32))
343  {
344  first = 1;
345  }
346 
347  printFFBChan(i, NULL, first);
348 
349  first = 0;
350  }
351 
352  return(0);
353  }
354 
355  if(isSet(PF_B_FLAG))
356  {
357  for(i=0;i<MAX_BAD_CHANS;i++)
358  {
359  c = env->badchans[i];
360 
361  if(c >= 0)
362  {
363  printFFBChan(c, NULL, first);
364  first = 0;
365 
366  printExtraChans(c, first);
367  }
368  }
369 
370  return(0);
371  }
372 
373  if(isSet(PF_T_FLAG))
374  {
375  st_print("\n");
376 
377  for(i=0;i<max_ffb_lines;i++)
378  {
379  st_print("%s", ffb_lines[i]);
380 
381  if(i == 3 || i == 11)
382  {
383  st_print("\n");
384  }
385  }
386 
387  st_print("\n");
388 
389  return(0);
390  }
391 
392  if(isSet(PF_R_FLAG))
393  {
394  ffb_load();
395 
396  return(0);
397  }
398 
399  /* Ask for a channels */
400 
401  sprintf(hint, "Click Left Mouse Button to pick Channel");
402 
403  if(!_doCCur(hint))
404  {
405  chan = (int)round(env->ccur);
406 
407  printFFBChan(chan, NULL, first);
408  first = 0;
409 
410  printExtraChans(chan, first);
411  }
412 
413  return(0);
414 }
415 
struct LP_IMAGE_INFO * h0
Definition: image.c:74
#define MAX_BAD_CHANS
Definition: defines.h:43
char pkg_home[256]
Definition: makemem.c:97
int first
Definition: dbase.c:106
struct PARSE_STACK * args
Definition: parse.h:196
int verifyFFBChans()
Definition: ffb.c:117
double noint
Definition: header.h:211
Definition: parse.h:8
#define RED
Definition: colors.h:5
double ccur
Definition: env.h:176
FILE * fp
Definition: linuxpops.c:70
char ffb_lines[80][80]
Definition: ffb.c:62
int issmt
Definition: env.h:63
int printExtraChans(int chan, int first)
Definition: ffb.c:275
struct ENVIRONMENT * env
Definition: linuxpops.c:71
int _doCCur(char *msg)
Definition: linuxpops.c:2411
int isSet(int flag)
Definition: parse.c:646
struct HEADER head
Definition: image.h:104
int printFFBChan(int c, struct FFB_CHANNELS *p, int header)
Definition: ffb.c:89
#define MAX_FFB_CHANS
Definition: ffb.h:4
void st_fail()
int strcmp()
int badchans[MAX_BAD_CHANS]
Definition: env.h:29
int ffb_load()
Definition: ffb.c:137
int max_ffb_lines
Definition: ffb.c:63
int doFFB()
Definition: ffb.c:310
int setColor(int c)
Definition: parse.c:2644
void st_report()
Definition: parse.h:9
struct FFB_CHANNELS ffb_chans[MAX_FFB_CHANS]
Definition: ffb.c:66
char con3[16]
Definition: ffb.h:12
int board
Definition: ffb.h:9
#define BLACK
Definition: colors.h:4
char con2[16]
Definition: ffb.h:11
char * secondArg
Definition: parse.h:181
void st_print()
int ntokens
Definition: parse.h:173
int crate
Definition: ffb.h:8
int chan
Definition: ffb.h:7
char con4[16]
Definition: ffb.h:13