Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
config.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 #define CWRITE 1
62 #define CAPPEND 2
63 
65 
67 {
68  FILE *fp;
69  char *string, line[256];
70 
71  if((fp = fopen(args->secondArg, "r") ) <= (FILE *)0)
72  {
73  st_fail("Unable to open config file %s", args->secondArg);
74  return(0);
75  }
76 
77  st_report("Reading Configuration File: %s", args->secondArg);
78 
79  while((string = fgets(line, sizeof(line), fp)) != NULL)
80  {
81  if(strlen(line) < 4)
82  {
83  continue;
84  }
85 
86  if(line[0] == '#')
87  {
88  continue;
89  }
90 
91  deNewLineIt(line); /* Clean it up */
92 
93  st_report("%s", line);
94 
95  my_add_history(line);
96 
97  parseCmd(line);
98  }
99 
100  fclose(fp);
101 
102  return(0);
103 }
104 
105 
107 FILE *fp;
108 {
109  int i, j, ngs;
110  struct GSKEY *pgs;
111  extern int getSizeOfGS();
112  extern struct GSKEY getset[];
113 
114  ngs = getSizeOfGS();
115 
116  pgs = &getset[0];
117  for(i=0;i<ngs;i++,pgs++)
118  {
119  switch(pgs->type)
120  {
121  case INTEGER:
122  if(pgs->size > 1)
123  {
124  ;
125  }
126  else
127  {
128  fprintf(fp, "let %s = %d\n", pgs->name, *pgs->iaddr);
129  }
130  break;
131 
132  case DOUBLE:
133  if(pgs->size > 1)
134  {
135  for(j=0;j<pgs->size;j++)
136  {
137  if(!strncmp(pgs->name, "ignoredscans", 12))
138  {
139  if(j == 0)
140  {
141  fprintf(fp, "ignore /c\n"); /* Force a clearing of the ignore array */
142  fprintf(fp, "stquiet=1 \n"); /* We don't want to see all this on reload */
143  }
144 
145  if(pgs->daddr[j] != 0.0 || j == 0)
146  {
147  fprintf(fp, "ignore %8.2f\n", pgs->daddr[j]);
148  }
149  }
150  }
151  }
152  else
153  {
154  fprintf(fp, "let %s = %20.20f\n", pgs->name, *pgs->daddr);
155  }
156  break;
157 
158  case CHARSTAR:
159  if(strlen(pgs->caddr) > 1)
160  {
161  fprintf(fp, "%s %s\n", pgs->name, pgs->caddr);
162  }
163  break;
164 
165  }
166  }
167 
168  if(env->mode == MODE_SPEC)
169  {
170  fprintf(fp, "nbaseset /c\n");
171 
172  for(i=0;i<MAX_BASELINES;i++)
173  {
174  if(env->baselines[i][0] || env->baselines[i][1])
175  {
176  fprintf(fp, "nbaseset %2d %4d %4d\n", i, env->baselines[i][0], env->baselines[i][1]);
177  }
178  }
179 
180  for(i=0;i<MAX_BAD_CHANS;i++)
181  {
182  if(env->badchans[i] > -1)
183  {
184  fprintf(fp, "badch %d /i\n", env->badchans[i]);
185  }
186  }
187 
188  }
189 
190  return(0);
191 }
192 
193 
194 
196 {
197  FILE *fp;
198  char *rmode;
199 
200  if(cwritemode == CWRITE)
201  {
202  rmode = "w";
203  }
204  else
205  if(cwritemode == CAPPEND)
206  {
207  rmode = "a";
208  }
209  else
210  {
211  st_fail("Unknown Configuration File Write Mode: %d", cwritemode);
212  return(1);
213  }
214 
215 
216  if(strlen(args->secondArg)< 2)
217  {
218  st_fail("Missing Args for writeConfig()");
219  return(1);
220  }
221 
222  if((fp = fopen(args->secondArg, rmode) ) <= (FILE *)0)
223  {
224  st_fail("Unable to open config file %s", args->secondArg);
225  return(0);
226  }
227 
228  fprintf(fp, "\n");
229  fprintf(fp, "switch %d\n", envNumber);
230 
231  writeParams(fp);
232 
233  fprintf(fp, "stquiet=0 \n");
234  fprintf(fp, "ignore \n");
235 
236  fprintf(fp, "\n");
237 
238  st_report("Wrote Environment[%d] Configuration to file %s", envNumber, args->secondArg);
239 
240  fclose(fp);
241 
242  return(0);
243 }
244 
245 
247 {
248  int i, save;
249 
250  if(strlen(args->secondArg)< 2)
251  {
252  st_fail("Missing Args for writeAllConfig()");
253  return(1);
254  }
255 
256  save = envNumber;
257 
258  for(i=0;i<MAX_ENV;i++)
259  {
260  if(i == 0)
261  {
262  cwritemode = CWRITE;
263  }
264  else
265  {
267  }
268 
269  if(strlen(CGM->envrs[i].title))
270  {
271  env = &CGM->envrs[i];
272  mapGS2Env();
273  envNumber = i;
274  writeConfig();
275  }
276  }
277 
278  envNumber = save;
279  env = &CGM->envrs[envNumber];
280  mapGS2Env();
281 
282  cwritemode = CWRITE;
283 
284  return(0);
285 }
286 
287 
289 {
290  char *cp;
291 
292  cp = getenv("LPSETUP");
293 
294  if(cp)
295  {
296  st_report("Loading Initfile: %s", cp);
297 
298  subArgs(2, cp);
299  readFile();
300  }
301 
302  return(0);
303 }
#define DOUBLE
Definition: defines.h:56
#define MAX_BAD_CHANS
Definition: defines.h:43
int getSizeOfGS()
int loadInitFile()
Definition: config.c:288
int * iaddr
Definition: gminit.h:9
struct PARSE_STACK * args
Definition: parse.h:196
char * caddr
Definition: gminit.h:10
int deNewLineIt(char *buf)
int mapGS2Env()
Definition: env.c:210
struct ENVIRONMENT envrs[MAX_ENV]
Definition: global.h:62
FILE * fp
Definition: linuxpops.c:70
char title[80]
Definition: env.h:8
int envNumber
Definition: env.c:71
int writeConfig()
Definition: config.c:195
int cwritemode
Definition: config.c:64
#define INTEGER
Definition: defines.h:54
#define MAX_BASELINES
Definition: defines.h:42
int size
Definition: gminit.h:8
struct ENVIRONMENT * env
Definition: linuxpops.c:71
int readConfig()
Definition: config.c:66
int writeParams(FILE *fp)
Definition: config.c:106
void st_fail()
#define CAPPEND
Definition: config.c:62
int badchans[MAX_BAD_CHANS]
Definition: env.h:29
double * daddr
Definition: gminit.h:11
int writeAllConfig()
Definition: config.c:246
struct GLOBAL_MEMORY * CGM
Definition: global.h:66
int mode
Definition: env.h:75
#define MODE_SPEC
Definition: defines.h:87
#define CHARSTAR
Definition: defines.h:57
void st_report()
int my_add_history(char *buf)
Definition: parse.c:109
void subArgs(int wt, const char *fmt,...)
Definition: parse.c:430
Definition: gminit.h:4
int readFile()
Definition: io.c:149
char * secondArg
Definition: parse.h:181
char * name
Definition: gminit.h:6
int baselines[MAX_BASELINES][2]
Definition: env.h:30
#define MAX_ENV
Definition: defines.h:35
int parseCmd(char *buf)
Definition: parse.c:2090
int type
Definition: gminit.h:7
#define CWRITE
Definition: config.c:61