1
/*===========================================================================
2
Copyright (C) 1995-2010 European Southern Observatory (ESO)
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.
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.
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,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
28
/*+++++++++++++++++++++ Module MIDKEYA +++++++++++++++++++++++++++++++++++++++
30
.IDENTIFICATION Module MIDKEYA
31
.AUTHOR Klaus Banse ESO - Garching
32
.KEYWORDS Midas keyword utility routines.
33
.ENVIRONMENT VMS and UNIX
35
holds IPROMPT, RPROMPT, CPROMPT, DPROMPT
38
.VERSION [3.00] 920129: split off original midkey.c
41
------------------------------------------------------------------------*/
53
int MID_CPROMPT(p_string,noval,carray,nullo)
55
/*++++++++++++++++++++++++++++++++++++++++++++++++++
57
display a prompt string on the terminal + read the user input
59
use MID_TPRO to display prompt string + get user input as character string
60
convert this string to relevant data via CGN_CNVT
62
status: I*4 return status
63
--------------------------------------------------*/
65
char *p_string /* IN : prompt string (null terminated) */;
66
int *noval /* IO : length of expected input */;
67
char *carray /* OUT: input data for type = 3 */;
68
int *nullo /* OUT: no. of null values in input */;
74
char work[96], prombuf[96];
77
save_val = *noval; /* save noval */
78
*noval = 0; /* init to 0 ... */
80
/* store prompt string in logfile */
82
(void) MID_LOG('G',p_string,(int)strlen(p_string));
85
/* cut off trailing blanks of prompt + read a line from the terminal */
87
CGN_CUTOFF(p_string,prombuf);
88
MID_TPRO(prombuf,work,80);
90
count = (int) strlen(work); /* test, if something came in */
91
if (count <= 0) return ERR_NODATA;
94
/* do not pass more values than required */
96
(void) MID_LOG('G',work,count);
97
if (save_val <= count)
100
memset((void *)carray,32,(size_t)save_val); /* fill first with blanks */
104
for (nr=0; nr<count; nr++)
106
*carray++ = work[nr];
107
if (work[nr] == NUL_CVAL) (*nullo) ++;
116
int MID_DPROMPT(p_string,noval,array,nullo)
118
/*++++++++++++++++++++++++++++++++++++++++++++++++++
120
display a prompt string on the terminal + read the user input
122
use MID_TPRO to display prompt string + get user input as character string
123
convert this string to relevant data via CGN_CNVT
125
status: I*4 return status
126
--------------------------------------------------*/
128
char *p_string /* IN : prompt string (null terminated) */;
129
int *noval /* IO : length of expected input */;
130
double *array /* OUT: input data */;
131
int *nullo /* OUT: no. of null values in input */;
134
int save_val, status, mm, iar;
139
char work[96], prombuf[96];
143
save_val = *noval; /* save noval */
144
*noval = 0; /* init to 0 ... */
146
/* store prompt string in logfile */
148
(void) MID_LOG('G',p_string,(int)strlen(p_string));
151
/* cut off trailing blanks of prompt + read a line from the terminal */
153
CGN_CUTOFF(p_string,prombuf);
154
MID_TPRO(prombuf,work,80);
156
mm = (int) strlen(work); /* test, if something came in */
157
if (mm <= 0) return ERR_NODATA;
159
(void) MID_LOG('G',work,mm);
160
mm = CGN_CNVT(work,4,save_val,&iar,&rar,array);
163
status = ERR_INPINV; /* conversion error... */
171
for (nr=0; nr<mm; nr++) /* look for null values */
173
if (array[nr] == NUL_DVAL) (*nullo) ++;
177
if (status != ERR_NORMAL)
178
MID_ERROR("MIDAS","MID_DPROMPT",status,0);
186
int MID_IPROMPT(p_string,noval,array,nullo)
188
/*++++++++++++++++++++++++++++++++++++++++++++++++++
190
display a prompt string on the terminal + read the user input
192
use MID_TPRO to display prompt string + get user input as character string
193
convert this string to relevant data via CGN_CNVT
195
status: I*4 return status
196
--------------------------------------------------*/
198
char *p_string /* IN : prompt string (null terminated) */;
199
int *noval /* IO : length of expected input */;
200
int *array /* OUT: input data */;
201
int *nullo /* OUT: no. of null values in input */;
204
int save_val, status, mm;
210
char work[96], prombuf[96];
213
save_val = *noval; /* save noval */
214
*noval = 0; /* init to 0 ... */
216
/* store prompt string in logfile */
218
(void) MID_LOG('G',p_string,(int)strlen(p_string));
221
/* cut off trailing blanks of prompt + read a line from the terminal */
223
CGN_CUTOFF(p_string,prombuf);
224
MID_TPRO(prombuf,work,80);
226
mm = (int) strlen(work); /* test, if something came in */
227
if (mm <= 0) return ERR_NODATA;
229
(void) MID_LOG('G',work,mm);
230
mm = CGN_CNVT(work,1,save_val,array,&rar,&dar);
233
status = ERR_INPINV; /* conversion error... */
241
for (nr=0; nr<mm; nr++) /* look for null values */
243
if (array[nr] == NUL_IVAL) (*nullo) ++;
247
if (status != ERR_NORMAL)
248
MID_ERROR("MIDAS","MID_IPROMPT",status,0);
256
int MID_RPROMPT(p_string,noval,array,nullo)
258
/*++++++++++++++++++++++++++++++++++++++++++++++++++
260
display a prompt string on the terminal + read the user input
262
use MID_TPRO to display prompt string + get user input as character string
263
convert this string to relevant data via CGN_CNVT
265
status: I*4 return status
266
--------------------------------------------------*/
268
char *p_string /* IN : prompt string (null terminated) */;
269
int *noval /* IO : length of expected input */;
270
float *array /* OUT: input data */;
271
int *nullo /* OUT: no. of null values in input */;
274
int save_val, status, mm, iar;
277
char work[96], prombuf[96];
282
save_val = *noval; /* save noval */
283
*noval = 0; /* init to 0 ... */
285
/* store prompt string in logfile */
287
(void) MID_LOG('G',p_string,(int)strlen(p_string));
290
/* cut off trailing blanks of prompt + read a line from the terminal */
292
CGN_CUTOFF(p_string,prombuf);
293
MID_TPRO(prombuf,work,80);
295
mm = (int) strlen(work); /* test, if something came in */
296
if (mm <= 0) return ERR_NODATA;
298
(void) MID_LOG('G',work,mm);
299
mm = CGN_CNVT(work,2,save_val,&iar,array,&dar);
302
status = ERR_INPINV; /* conversion error... */
310
for (nr=0; nr<mm; nr++) /* look for null values */
312
if (array[nr] == NUL_DVAL) (*nullo) ++;
316
if (status != ERR_NORMAL)
317
MID_ERROR("MIDAS","MID_RPROMPT",status,0);
325
int MID_KEYFILE(progname)
327
/*++++++++++++++++++++++++++++++++++++++++++++++++++
329
read keyword values from ASCII file progname.key
332
status: int return status
333
--------------------------------------------------*/
335
char *progname; /* IN : name of calling program */
338
int slen, cl, nc, nb, fid, m, n;
339
int *ibuf, unit, start, first, noelem, sbytelem, bytelem;
347
char *cbuf, cc[4], buff[128];
348
char keyname[32], type[16], k_type[4], substr[24];
355
(void) strncpy(buff,progname,120);
356
buff[120] = '\0'; /* so we have an end... */
357
m = CGN_INDEXC(buff,' ');
359
(void) strcat(buff,".KEY");
361
(void) strcpy(&buff[m],".KEY");
364
fid = osaopen(buff,READ);
365
if (fid < 0) return (ERR_FRMNAC);
367
work_str = malloc((size_t)200);
369
dbuf = (double *)work_str;
370
ibuf = (int *)work_str;
371
rbuf = (float *)work_str;
372
cbuf = (char *)work_str;
375
memset((void *)buff,32,(size_t)80); /* clear read buffer */
376
slen = osaread(fid,buff,80);
380
goto file_end; /* EOF reached */
384
if (slen == 0) goto read_loop;
387
printf("record read: %s\n",buff);
390
/* we've got some stuff */
392
for (nr=0; nr<slen; nr++)
394
if ((buff[nr] != ' ') && (buff[nr] != '\t')) goto text_a;
396
goto read_loop; /* skip empty lines */
399
CGN_strcpy(buff,&buff[nr]);
400
if (buff[0] == '!') goto read_loop; /* skip comments */
402
cl = CGN_INDEXC(buff,' ');
405
printf("invalid syntax - line %d skipped...\n",nc);
412
slen = CGN_INDEXC(buff,'/');
413
(void) strncpy(keyname,buff,(size_t)slen);
414
keyname[slen] = '\0';
416
slen = CGN_EXTRSS(buff,cl,'/',&start,type,15);
418
MID_TYPCHK(type,cc,&bytelem);
421
printf("bad keytype - line %d skipped...\n",nc);
425
slen = CGN_EXTRSS(buff,cl,'/',&start,substr,20);
428
printf("bad start element - line %d skipped...\n",nc);
432
n = CGN_CNVT(substr,1,1,&first,&rwa,&dwa);
435
printf("bad start element - line %d skipped...\n",nc);
439
slen = CGN_EXTRSS(buff,cl,'/',&start,substr,20);
440
n = CGN_CNVT(substr,1,1,&noelem,&rwa,&dwa);
443
printf("bad noelem - line %d skipped...\n",nc);
447
n = MID_FNDKEY(keyname,k_type,&sbytelem,&nb,&unit);
450
if ( (type[0] != k_type[0]) || (bytelem != sbytelem) )
452
printf("wrong keytype - line %d skipped...\n",nc);
458
slen = noelem + first - 1;
459
m = MID_DEFKEY(keyname,' ',type,slen,&unit);
460
if (stat != ERR_NORMAL)
462
printf("problem creating keyword - line %d skipped...\n",nc);
469
else if (type[0] == 'R')
471
else if (type[0] == 'C')
476
CGN_strcpy(buff,&buff[cl+1]);
477
slen = (int) strlen(buff);
478
for (nr=0; nr<slen; nr++)
480
if ((buff[nr] != ' ') && (buff[nr] != '\t')) goto text_b;
482
printf("missing data - line %d skipped...\n",nc);
486
if (nr > 0) CGN_strcpy(buff,&buff[nr]);
489
printf("data: %s\nnb = %d, first = %d, noelem = %d\n",buff,nb,first,noelem);
494
m = CGN_CNVT(buff,nb,noelem,ibuf,rbuf,dbuf);
495
if (m > noelem) m = noelem;
498
stat = SCKWRI(keyname,ibuf,first,m,&unit);
500
stat = SCKWRR(keyname,rbuf,first,m,&unit);
502
stat = SCKWRD(keyname,dbuf,first,m,&unit);
507
m = noelem * bytelem; /* total size */
510
printf("data overflow (> 200) - line %d skipped...\n",nc);
514
slen = (int) strlen(buff) - 1;
515
if ( (buff[0] == '"') && (slen > 1) && (buff[slen] == '"') )
528
for (nr=slen; nr<m; nr++) cbuf[nr] = ' '; /* pad with blanks */
531
stat = SCKWRC(keyname,bytelem,cbuf,first,noelem,&unit);
533
if (stat != ERR_NORMAL)
534
printf("problem filling keyword - line %d skipped...\n",nc);
548
int MID_SPROMPT(p_string,noval,array,nullo)
550
/*++++++++++++++++++++++++++++++++++++++++++++++++++
552
display a prompt string on the terminal + read the user input
554
use MID_TPRO to display prompt string + get user input as character string
555
convert this string to relevant data via CGN_xCNVT
558
--------------------------------------------------*/
560
char *p_string /* IN : prompt string (null terminated) */;
561
int *noval /* IO : length of expected input */;
562
size_t *array /* OUT: input data */;
563
int *nullo /* OUT: no. of null values in input */;
566
int save_val, status, mm, iar;
572
char work[96], prombuf[96];
579
save_val = *noval; /* save noval */
580
*noval = 0; /* init to 0 ... */
582
/* store prompt string in logfile */
584
(void) MID_LOG('G',p_string,(int)strlen(p_string));
587
/* cut off trailing blanks of prompt + read a line from the terminal */
589
CGN_CUTOFF(p_string,prombuf);
590
MID_TPRO(prombuf,work,80);
592
mm = (int) strlen(work); /* test, if something came in */
593
if (mm <= 0) return ERR_NODATA;
595
(void) MID_LOG('G',work,mm);
596
mm = CGN_xCNVT(work,5,save_val,&iar,&rar,&dar,array);
599
status = ERR_INPINV; /* conversion error... */
607
snul = (size_t)NUL_DVAL;
608
for (nr=0; nr<mm; nr++) /* look for null values */
610
if (array[nr] == snul) (*nullo) ++;
614
if (status != ERR_NORMAL)
615
MID_ERROR("MIDAS","MID_DPROMPT",status,0);