Debian Codegraph @

libsrc/st/scs.c

raw
1 /*===========================================================================
2 Copyright (C) 1995-2012 European Southern Observatory (ESO)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with this program; if not, write to the Free
16 Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26 ===========================================================================*/
27
28 /*+++++++++++++++++++++++++++++ SC interface module SCS +++++++++++++++++++++
29 .LANGUAGE C
30 .IDENTIFICATION Module SCS
31 .AUTHOR K. Banse ESO - Garching 870721
32 .KEYWORDS standard interfaces.
33 .ENVIRONMENT theoretically environment independant.
34 .COMMENTS all SC_interfaces related to System + parameter:
35 SCSPRO, SCSEPI, SCPSET
36
37 .VERSION
38 120423 last modif - really!!
39
40 -----------------------------------------------------------------------------*/
41
42
43 #include <stdlib.h>
44
45 #include <osyparms.h>
46 #include <fileexts.h>
47 #include <stlibvars.h>
48 #include <osparms.h>
49 #include <osterm.h>
50
51 static int NoInt = 1, CntrlC = 0, only = 0, NoStop = 0;
52
53
54 /*
55
56 */
57
58
59 /* ARGSUSED */
60 void interc(s)
61 int s;
62
63 {
64 if (NoInt == 1)
65 CntrlC = 1; /* just set the CntrlC flag */
66 else
67 MID_ABORT(999,100); /* exit from the application */
68 }
69
70 /*
71
72 */
73
74 int myINIT(from)
75 int from; /* = 0, from monitor
76 = 1, from application */
77
78 {
79 register int nr;
80
81
82 YDSC_PNTR = &YDSCDIR_ENTRY;
83
84 MID_INITER(); /* init error business */
85
86
87 /* create + clear FCT structure */
88
89 (void) MID_FCTIN(-1); /* indicate 1. time */
90
91 /* FCT_PARM[0,1] holds values for F_XD_PARM
92 [0] = initial no. of descriptors
93 [1] = initial total space needed for descriptors in bytes
94 defaulted to 100 initial descriptors and 6000 bytes descr. space
95 => total 3 LDBs (1 for directory + 2 for descrs)
96
97 [2] = delete flag for extracted subframes, 1- delete, 0 - not
98
99 [3] = FITS header flag
100 0- use all FITS keywords, 1- ignore ESO hierarchical keywords */
101
102 FCT.PARM[0] = 100;
103 FCT.PARM[1] = 6000;
104 FCT.PARM[2] = 1;
105 FCT.PARM[3] = 0; /* reset */
106
107
108 for (nr=0; nr<CAT_MAXNO; nr++) /* clear CATALOG structure */
109 CATAL[nr].NAME[0] = ' ';
110
111 MID_TINIT(); /* some stuff for terminal I/O */
112
113 return 0;
114 }
115 /*
116
117 */
118
119 int SCSPRO(prog)
120
121 /*++++++++++++++++++++++++++++++++++++++++++++++++++
122 .PURPOSE
123 read keywords data base, initialize File Control Table and open logfile
124 .ALGORITHM
125 straight forward
126 .RETURNS
127 return status ( 0 = o.k )
128 --------------------------------------------------*/
129
130 char *prog; /* IN : name of calling program
131 if `name' is starting with a minus sign (-),
132 this program is running outside the Midas
133 environment;
134 if `name' = "-no-stop-", SCSEPI() will not
135 terminate the process but just return the
136 last status */
137
138 {
139 int i, status;
140 int tcols, tlines;
141
142 char cbuf[8], *outside;
143
144
145 #if vms
146 #else
147 osscatch(SIGINT,interc);
148 osscatch(SIGUSR1,SIG_IGN); /* ignore signal USER1 + USER2 */
149 osscatch(SIGUSR2,SIG_IGN);
150 #endif
151
152 if (only == 0)
153 only = 1;
154 else
155 {
156 (void) printf("SCSPRO should only be called once - this call ignored ...\n");
157 return ERR_NORMAL;
158 }
159
160
161 i = myINIT(1); /* returned value ignored for now */
162
163
164
165 /* check, if this is an "outside" call */
166 /* ----------------------------------- */
167
168
169 cbuf[1] = '\0';
170
171
172 if (unlikely(*prog == '-'))
173 {
174 if (strcmp(prog,"-no-stop-") == 0) NoStop = 1;
175
176 cbuf[0] = '*'; /* default to use new FORGRdrs.KEY */
177 if ((outside = getenv("MIDASDRS")))
178 {
179 if (*outside == 'y') /* if yes, reuse existing */
180 { /* FORGRdrs.KEY, if possible */
181 cbuf[1] = '*';
182 cbuf[2] = '\0';
183 }
184 }
185 }
186 else if ((outside = getenv("MIDAS_OUTSIDE")))
187 { /* yes, MIDAS_OUTSIDE env.var. is defined */
188 cbuf[0] = cbuf[1] = '*'; /* reuse existing FORGRdrs.KEY */
189 cbuf[2] = '\0';
190 }
191 else
192 {
193 cbuf[0] = ' ';
194 goto inside_job;
195 }
196
197
198 status = MID_MOVKEY("IA",cbuf); /* use new/old FORGRdrs.KEY */
199 if (status != ERR_NORMAL) /* not o.k. - get out of here ... */
200 {
201 if (NoStop == 1)
202 return status;
203 else
204 ospexit(1);
205 }
206
207 MID_TTINFO(&tcols,&tlines); /* get initial terminal size */
208 KIWORDS[OFF_LOG+9] = tcols; /* save in log(10,11) */
209 KIWORDS[OFF_LOG+10] = tlines;
210
211 DATA_PATH[0] = '^';
212 DATA_PATH[320] = '\0';
213
214 #if vms /* enable interrupt routine for CTRL/C */
215 #else
216 if (CntrlC == 1)
217 MID_ABORT(999,100); /* exit from the application */
218 #endif
219
220 if (NoStop != 1) status = MID_KEYFILE(prog);
221 return status;
222
223
224 /* inside Midas session */
225 /* use FORGR{DAZUNIT(1:2)}.KEY as keyword file */
226
227 inside_job:
228 status = MID_MOVKEY("IA",cbuf); /* get current keywords in */
229
230 if (status != ERR_NORMAL) /* if not o.k. - get out of here ... */
231 {
232 (void) printf("Problems getting keywords in for program %s\n",prog);
233 ospexit(1);
234 }
235
236
237 /* get data path names from keyword DATA_PATH */
238
239 (void) memcpy(DATA_PATH,&KCWORDS[OFF_DPATH],320);
240 DATA_PATH[320] = '\0';
241
242
243 /* open logfile */
244
245 KIWORDS[OFF_LOG] = KIWORDS[OFF_LOG+7]; /* reset log flag */
246 status = MID_LOG('I',&KCWORDS[OFF_SESS+10],2); /* point to DAZUNIT */
247 if (KIWORDS[OFF_LOG] == 2)
248 { /* if key LOG(1) = 2, init CPU timer */
249 float time;
250 time = 0.0;
251 status = OSY_TIMER('I',&time);
252 if (status != ERR_NORMAL) MID_E1(1,"SCSPRO",status,1);
253 }
254
255
256 /* enable interrupt routine for CTRL/C to exit */
257
258 #if vms
259 #else
260 if (CntrlC == 1)
261 MID_ABORT(999,100); /* exit from the application */
262 else
263 NoInt = 0;
264 #endif
265
266 /* check keyword AUX_MODE(10), if we should use
267 old, VERS_010 or new descriptor format */
268
269 if (KIWORDS[OFF_MONPAR+11] > 0)
270 { /* from key MONITPAR(12,13) */
271 FCT.PARM[0] = KIWORDS[OFF_MONPAR+11]; /* get initial no. of descr.s */
272 FCT.PARM[1] = KIWORDS[OFF_MONPAR+12]; /* and initial descr_data bytes */
273 }
274
275 if (KIWORDS[OFF_AUX+15] == 1) /* ESO-DESC_ignore_flag set? */
276 {
277 i = 1; /* Yes. Ignore ESO.xyz keywords */
278 (void) SCPSET(F_FITS_PARM,&i); /* in FITS headers */
279 }
280
281
282 return status;
283 }
284 /*
285
286 */
287
288 int SCSEPI()
289
290 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
291 .PURPOSE
292 write keywords back + clean up everything
293 .ALGORITHM
294 if everything goes o.k. and we are running inside Midas, we also exit
295 .RETURNS
296 return status only if something went wrong or we are outside Midas!!
297 -------------------------------------------------------------*/
298
299 {
300 int mm, status, fp;
301 register int i;
302
303 char cbuf[8];
304
305 struct FCT_STRUCT *fctpntr;
306
307
308
309
310 only = 0; /* reset one_time flag */
311
312
313 /* if key LOG(1) = 2 we get the CPU time + log it */
314
315 if (KIWORDS[OFF_LOG] == 2)
316 {
317 float time, r;
318 char record[80];
319
320 status = OSY_TIMER('G',&time);
321 if (status != ERR_NORMAL) MID_E1(2,"SCFCLO",status,1);
322
323 KIWORDS[OFF_AUX+1] = (int) time;
324 r = time * 0.01 ; /* obtain seconds */
325 i = OFF_APPLIC + 2;
326 mm = snprintf(record,(size_t)80,"%.50s: CPU time = %g seconds\n",
327 &KCWORDS[i],r); /* obtain program name */
328 (void) MID_LOG('G',record,mm);
329 }
330
331 fp = KIWORDS[OFF_OUTFLG+2];
332 if (fp > 0)
333 {
334 if (fp < 999) osaclose(fp); /* fp = 999 means "Nullo" output */
335 KIWORDS[OFF_OUTFLG+2] = -2;
336 }
337
338
339 /* close all files still open + add to current catalog */
340
341 fctpntr = FCT.ENTRIES;
342 for (i=0; i<FCT.MAXENT; i++)
343 {
344 if (fctpntr->NAME[0] != ' ')
345 {
346 if (fctpntr->ACCESS == 'X') /* virtual memory only */
347 fctpntr->NAME[0] = ' ';
348 else
349 {
350 if (fctpntr->CATALOG[0] == 'T')
351 status = TCTCLO(i);
352 else
353 status = SCFCLO(i);
354 }
355 }
356 fctpntr ++;
357 }
358
359
360 KCWORDS[OFF_APPLIC] = 't'; /* indicate that normal termination */
361 KIWORDS[OFF_PRSTAT] = 0;
362
363 NoInt = 1; /* disable exiting in CntrlC interrupt handler */
364
365
366 /* close logfile + write keywords back */
367
368 KIWORDS[OFF_LOG+8] = 0; /* clear print flag */
369 (void) MID_LOG('O',cbuf,2); /* length of cbuf not used */
370 cbuf[0] = ' ';
371 status = MID_MOVKEY("O",cbuf);
372
373 if (NoStop == 0)
374 {
375 if (status != ERR_NORMAL) MID_E1(2,"...",status,1);
376 ospexit(0); /* always stop the process */
377 }
378
379 return status; /* if we get here, just return last status */
380 }
381
382 /*
383
384 */
385
386 int SCPSET(para,pval)
387
388 /*++++++++++++++++++++++++++++++++++++++++++++++++++
389 .PURPOSE
390 set values for a parameter
391 .ALGORITHM
392 para is the parameter no. and pval[] the array of values for that parameter
393 .RETURNS
394 return status ( 0 = o.k )
395 --------------------------------------------------*/
396
397 int para; /* IN: parameter no. given as a symbol */
398 int *pval; /* IN: array with values (may be just one) */
399
400 {
401 int i;
402
403
404 switch (para)
405 {
406 case F_XD_PARM: /* specify no. of descrs + initial space */
407 if (*pval<1) /* pval[0] - no. of inital descriptors */
408 return ERR_INPINV;
409 i = *(pval+1);
410 if (i<1) /* pval[1] - initial descr. space in bytes */
411 return ERR_INPINV;
412
413 FCT.PARM[0] = *pval;
414 FCT.PARM[1] = i;
415 return ERR_NORMAL;
416
417
418 case F_DEL_PARM: /* delete (or not) extracted frames */
419 i = *pval;
420 if (i != 1) i = 0;
421 FCT.PARM[2] = i; /* 1 = YES - delete, 0 = NO */
422 return ERR_NORMAL;
423
424
425 case F_FITS_PARM: /* handling of FITS headers */
426 FCT.PARM[3] = *pval;
427 if (KIWORDS[OFF_AUX+13] == 1)
428 FCT.PARM[3] = 0; /* FITS files are updated! */
429 /*
430 printf
431 ("FCT.PARM = %d, %d, %d, %d\n",FCT.PARM[0],FCT.PARM[1],FCT.PARM[2],FCT.PARM[3]);
432 */
433 return ERR_NORMAL;
434
435
436 default:
437 return ERR_INPINV;
438 }
439
440 }
441