Debian Codegraph @

libsrc/st/sck.c

raw
1 /*===========================================================================
2 Copyright (C) 1995-2009 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 Massachusetss Ave, Cambridge,
17 MA 02139, USA.
18
19 Corresponding 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 SCK +++++++++++++++++++++++
29 .LANGUAGE C
30 .IDENTIFICATION Module SCK
31 .AUTHOR K. Banse ESO - Garching
32 .KEYWORDS standard interfaces, keyword data base
33 .ENVIRONMENT VMS and UNIX
34 .COMMENTS
35 holds SCKGETC, SCKRDx routines
36
37 .VERSION [2.00] 871124: new version
38
39 090630 last modif
40 -----------------------------------------------------------------------------*/
41
42 #include <fileexts.h>
43
44
45
46 /*
47
48 */
49
50 int SCKGETC(key,felem,maxvals,actvals,values)
51
52 /*++++++++++++++++++++++++++++++++++++++++++++++++++
53 .PURPOSE
54 get data from character keyword and terminate with null (no trailing blanks)
55 buffer 'values' must have at least 'maxvals+1' size, to be able to hold
56 most 'maxvals' chars + null (end-char.)
57 .ALGORITHM
58 use SCKRDC
59 .RETURNS
60 return status ( 0 = ok )
61 --------------------------------------------------*/
62
63 char *key; /* IN : name of keyword */
64 int felem; /* IN : first data item to be read */
65 int maxvals; /* IN : max. no. of elements to get */
66 int *actvals; /* OUT: actual no. of elements returned */
67 char *values; /* OUT: buffer for data values */
68
69 {
70 int nulo, munit;
71 int status, invals, kindx;
72 register int nr;
73
74 register char mychar;
75
76
77
78 status = SCKRDC(key,1,felem,maxvals,&invals,values,&munit,&nulo);
79
80
81 /* now get rid of trailing blanks/nulls */
82
83 kindx = invals - 1; /* point to last buffer element */
84
85 mychar = values[kindx];
86 if ((mychar != ' ') && (mychar != '\0'))
87 {
88 /* this might cause trouble ...
89 if (invals == maxvals)
90 {
91 char txt[80];
92
93 sprintf(txt,"key = %s, maxvals = %d",key,maxvals);
94 SCTPUT(txt);
95 SCTPUT("must overwrite output buffer...");
96 }
97 */
98
99 *actvals = invals;
100 values[invals] = '\0'; /* add(!) Null terminator */
101 return status;
102 }
103
104 for (nr=(kindx-1); nr>=0; nr--)
105 { /* try to truncate */
106 mychar = values[nr];
107 if ((mychar != ' ') && (mychar != '\0'))
108 {
109 *actvals = nr + 1;
110 values[nr+1] = '\0'; /* add null terminator */
111 return status;
112 }
113 }
114
115 values[0] = '\0';
116 *actvals = 0; /* indicate also in actvals */
117 return status;
118 }
119
120 /*
121
122 */
123
124 int SCKRDC(key,noelm,felem,maxvals,actvals,values,unit,null)
125
126 /*++++++++++++++++++++++++++++++++++++++++++++++++++
127 .PURPOSE
128 read data from character keyword
129 .ALGORITHM
130 straight forward
131 .RETURNS
132 return status ( 0 = ok )
133 --------------------------------------------------*/
134
135 char *key /* IN : name of keyword */;
136 int noelm /* IN : for char. arrays, CHAR*noelm */;
137 int felem /* IN : first data item to be read */;
138 int maxvals /* IN : no. of elements to get */;
139 int *actvals /* OUT: actual no. of elements returned */;
140 char *values /* OUT: buffer for data values */;
141 int *unit /* OUT: unit-pointer */;
142 int *null /* OUT: no. of null values in keyword */;
143
144 {
145 int kk, kunit, status, offset;
146 /* int nulflag; */
147 int bytelem, noelem, nn, kentry, noval;
148 register int nr;
149
150 struct KEY_STRUCT *keypntr;
151
152 char k_typ[4];
153 register char *cpntr, *valptr;
154
155
156
157 /* find entry in keyword control table */
158
159 kentry = MID_FNDKEY(key,k_typ,&bytelem,&noelem,&kunit);
160 if (kentry < 0)
161 {
162 status = ERR_KEYBAD;
163 goto end_of_it;
164 }
165 else if (k_typ[0] != 'C')
166 {
167 status = ERR_KEYTYP;
168 goto end_of_it;
169 }
170
171
172 /* get info about keyword */
173
174 keypntr = KEYALL.KEYNAMES + kentry;
175
176 noval = keypntr->NOELEM * keypntr->BYTELEM; /* real size of keyword */
177 offset = (felem - 1) * noelm; /* requested offset */
178 kk = noval - offset; /* size available */
179 kk /= noelm; /* no. of elements/values available */
180
181
182 /* check parameters */
183
184 if ( (felem <= 0) || (noelm < 1) || (kk < 1) || (maxvals <= 0) )
185 {
186 status = ERR_OUTLIM;
187 goto end_of_it;
188 }
189
190
191 offset += keypntr->OFFSET; /* get location in KEY_CWORDS */
192 if (maxvals < kk) kk = maxvals; /* minimize ... */
193 nn = kk * noelm; /* total no. of bytes to copy */
194
195
196 /* copy data + check for null values at same time */
197
198 cpntr = KCWORDS + offset;
199 valptr = values; /* copy pointer */
200
201 /* nulflag = *null; this feature is currently not used !!!
202
203 if (nulflag > -1)
204 {
205 for (nr=0; nr<nn; nr++)
206 {
207 if (*cpntr == NUL_CVAL) (*null) ++;
208 *valptr++ = *cpntr++;
209 }
210 }
211 else
212 {
213 for (nr=0; nr<nn; nr++) *valptr++ = *cpntr++;
214 }
215 */
216
217
218 for (nr=0; nr<nn; nr++) *valptr++ = *cpntr++;
219
220 *null = 0;
221 *unit = kunit;
222 *actvals = kk;
223
224 return ERR_NORMAL;
225
226 /* here for errors */
227 end_of_it:
228 MID_E1(5,key,status,1);
229 return status;
230 }
231
232 /*
233
234 */
235
236 int SCKRDD(key,felem,maxvals,actvals,values,unit,null)
237
238 /*++++++++++++++++++++++++++++++++++++++++++++++++++
239 .PURPOSE
240 read data from double keyword
241 .ALGORITHM
242 straight forward
243 .RETURNS
244 return status ( 0 = ok )
245 --------------------------------------------------*/
246
247 char *key /* IN : name of keyword */;
248 int felem /* IN : first data item to be read */;
249 int maxvals /* IN : no. of elements to get */;
250 int *actvals /* OUT: actual no. of elements returned */;
251 double *values /* OUT: buffer for data values */;
252 int *unit /* OUT: unit-pointer */;
253 int *null /* OUT: no. of null values in keyword */;
254
255 {
256 int kunit, status, offset;
257 int bytelem, noelem, kentry, noval;
258 register int nr;
259
260 struct KEY_STRUCT *keypntr;
261
262 char k_typ[4];
263
264 double *dpntr, *valptr;
265
266
267
268 /* find entry in keyword control table */
269
270 kentry = MID_FNDKEY(key,k_typ,&bytelem,&noelem,&kunit);
271 if (kentry < 0)
272 {
273 status = ERR_KEYBAD;
274 goto end_of_it;
275 }
276 else if (k_typ[0] != 'D')
277 {
278 status = ERR_KEYTYP;
279 goto end_of_it;
280 }
281
282
283 /* keyname o.k. - check first element + no. of values */
284
285 if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) )
286 {
287 status = ERR_OUTLIM;
288 goto end_of_it;
289 }
290
291
292 /* get "real" length + offset before 1. value in data block */
293
294 keypntr = KEYALL.KEYNAMES + kentry;
295 nr = felem - 1;
296
297 offset = keypntr->OFFSET + nr;
298 noval = keypntr->NOELEM - nr;
299 if (noval < maxvals) maxvals = noval; /* minimize... */
300 *unit = kunit;
301 *actvals = maxvals;
302
303
304 /* fill input array */
305
306 *null = 0;
307 dpntr = KDWORDS + offset;
308 valptr = values; /* copy pointer */
309
310 /* nulflag = *null; this feature is currently not used !!!
311 if (nulflag > -1)
312 {
313 for (nr=0; nr<maxvals; nr++)
314 {
315 if (*dpntr == NUL_DVAL) (*null) ++;
316 *valptr++ = *dpntr++;
317 }
318 }
319
320 else
321 {
322 for (nr=0; nr<maxvals; nr++) *valptr++ = *dpntr++;
323 }
324 */
325
326 for (nr=0; nr<maxvals; nr++) *valptr++ = *dpntr++;
327
328
329 return ERR_NORMAL;
330
331 /* here for errors */
332 end_of_it:
333 MID_E1(5,key,status,1);
334 return status;
335 }
336
337 /*
338
339 */
340
341 int SCKRDI(key,felem,maxvals,actvals,values,unit,null)
342
343 /*++++++++++++++++++++++++++++++++++++++++++++++++++
344 .PURPOSE
345 read data from integer keyword
346 .ALGORITHM
347 straight forward
348 .RETURNS
349 return status ( 0 = ok )
350 --------------------------------------------------*/
351
352 char *key /* IN : name of keyword */;
353 int felem /* IN : first data item to be read */;
354 int maxvals /* IN : no. of elements to get */;
355 int *actvals /* OUT: actual no. of elements returned */;
356 int *values /* OUT: buffer for data values */;
357 int *unit /* OUT: unit-pointer */;
358 int *null /* OUT: no. of null values in keyword */;
359
360 {
361 int kunit, status, offset;
362 int bytelem, noelem, kentry, noval;
363 register int nr, *ipntr, *valptr;
364
365 struct KEY_STRUCT *keypntr;
366
367 char k_typ[4];
368
369
370
371 /* find entry in keyword control table */
372
373 kentry = MID_FNDKEY(key,k_typ,&bytelem,&noelem,&kunit);
374 if (kentry < 0)
375 {
376 status = ERR_KEYBAD;
377 goto end_of_it;
378 }
379 else if (k_typ[0] != 'I')
380 {
381 status = ERR_KEYTYP;
382 goto end_of_it;
383 }
384
385
386 /* keyname o.k. - check first element + no. of values */
387
388 if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) )
389 {
390 status = ERR_OUTLIM;
391 goto end_of_it;
392 }
393
394
395 /* get "real" length + offset before 1. value in data block */
396
397 keypntr = KEYALL.KEYNAMES + kentry;
398 nr = felem - 1;
399
400 offset = keypntr->OFFSET + nr;
401 noval = keypntr->NOELEM - nr;
402 if (noval < maxvals) maxvals = noval; /* minimize... */
403 *unit = kunit;
404 *actvals = maxvals;
405
406
407 /* fill input array */
408
409 *null = 0;
410 ipntr = KIWORDS + offset;
411 valptr = values; /* copy pointer */
412
413 /* nulflag = *null; this feature is currently not used !!!
414 if (nulflag > -1)
415 {
416 for (nr=0; nr<maxvals; nr++)
417 {
418 if (*ipntr == NUL_IVAL) (*null) ++;
419 *valptr++ = *ipntr++;
420 }
421 }
422 else
423 {
424 for (nr=0; nr<maxvals; nr++) *valptr++ = *ipntr++;
425 }
426 */
427
428 for (nr=0; nr<maxvals; nr++) *valptr++ = *ipntr++;
429
430
431 return ERR_NORMAL;
432
433 /* here for errors */
434 end_of_it:
435 MID_E1(5,key,status,1);
436 return status;
437 }
438 /*
439
440 */
441
442 int SCKRDR(key,felem,maxvals,actvals,values,unit,null)
443
444 /*++++++++++++++++++++++++++++++++++++++++++++++++++
445 .PURPOSE
446 read data from character keyword
447 .ALGORITHM
448 use lower level routines MID_RDKEYR
449 .RETURNS
450 return status ( 0 = ok )
451 --------------------------------------------------*/
452
453 char *key /* IN : name of keyword */;
454 int felem /* IN : first data item to be read */;
455 int maxvals /* IN : no. of elements to get */;
456 int *actvals /* OUT: actual no. of elements returned */;
457 float *values /* OUT: buffer for data values */;
458 int *unit /* OUT: unit-pointer */;
459 int *null /* OUT: no. of null values in keyword */;
460
461 {
462 int kunit, status, offset;
463 int bytelem, noelem, kentry, noval;
464 register int nr;
465
466 struct KEY_STRUCT *keypntr;
467
468 char k_typ[4];
469
470 register float *rpntr, *valptr;
471
472
473
474 /* find entry in keyword control table */
475
476 kentry = MID_FNDKEY(key,k_typ,&bytelem,&noelem,&kunit);
477 if (kentry < 0)
478 {
479 status = ERR_KEYBAD;
480 goto end_of_it;
481 }
482 else if (k_typ[0] != 'R')
483 {
484 status = ERR_KEYTYP;
485 goto end_of_it;
486 }
487
488
489 /* keyname o.k. - check first element + no. of values */
490
491 if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) )
492 {
493 status = ERR_OUTLIM;
494 goto end_of_it;
495 }
496
497
498 /* get "real" length + offset before 1. value in data block */
499
500 keypntr = KEYALL.KEYNAMES + kentry;
501 nr = felem - 1;
502
503 offset = keypntr->OFFSET + nr;
504 noval = keypntr->NOELEM - nr;
505 if (noval < maxvals) maxvals = noval; /* minimize... */
506 *unit = kunit;
507 *actvals = maxvals;
508
509
510 /* fill input array */
511
512 *null = 0;
513 rpntr = KRWORDS + offset;
514 valptr = values; /* copy pointer */
515
516 /* nulflag = *null; this feature is currently not used !!!
517 if (nulflag > -1)
518 {
519 for (nr=0; nr<maxvals; nr++)
520 {
521 if (*rpntr == NUL_RVAL) (*null) ++;
522 *valptr++ = *rpntr++;
523 }
524 }
525 else
526 {
527 for (nr=0; nr<maxvals; nr++) *valptr++ = *rpntr++;
528 }
529 */
530
531 for (nr=0; nr<maxvals; nr++) *valptr++ = *rpntr++;
532
533
534 return ERR_NORMAL;
535
536 /* here for errors */
537 end_of_it:
538 MID_E1(5,key,status,1);
539 return status;
540 }
541 /*
542
543 */
544
545 int SCKRDS(key,felem,maxvals,actvals,values,unit,null)
546 /*++++++++++++++++++++++++++++++++++++++++++++++++++
547 .PURPOSE
548 read data from size_t keyword
549 .ALGORITHM
550 .RETURNS
551 return status ( 0 = ok )
552 --------------------------------------------------*/
553
554 char *key /* IN : name of keyword */;
555 int felem /* IN : first data item to be read */;
556 int maxvals /* IN : no. of elements to get */;
557 int *actvals /* OUT: actual no. of elements returned */;
558 size_t *values /* OUT: buffer for data values */;
559 int *unit /* OUT: unit-pointer */;
560 int *null /* OUT: no. of null values in keyword */;
561
562 {
563 int kunit, status, offset;
564 int bytelem, noelem, kentry, noval;
565 register int nr;
566
567 struct KEY_STRUCT *keypntr;
568
569 char k_typ[4];
570
571 register size_t *spntr, *valptr;
572
573
574
575 /* find entry in keyword control table */
576
577 kentry = MID_FNDKEY(key,k_typ,&bytelem,&noelem,&kunit);
578 if (kentry < 0)
579 {
580 status = ERR_KEYBAD;
581 goto end_of_it;
582 }
583 else if (k_typ[0] != 'S')
584 {
585 status = ERR_KEYTYP;
586 goto end_of_it;
587 }
588
589
590 /* keyname o.k. - check first element + no. of values */
591
592 if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) )
593 {
594 status = ERR_OUTLIM;
595 goto end_of_it;
596 }
597
598
599 /* get "real" length + offset before 1. value in data block */
600
601 keypntr = KEYALL.KEYNAMES + kentry;
602 nr = felem - 1;
603
604 offset = keypntr->OFFSET + nr;
605 noval = keypntr->NOELEM - nr;
606 if (noval < maxvals) maxvals = noval; /* minimize... */
607 *unit = kunit;
608 *actvals = maxvals;
609
610
611 /* fill input array */
612
613 *null = 0;
614 spntr = KSWORDS + offset;
615 valptr = values; /* copy pointer */
616
617 /* nulflag = *null; this feature is currently not used !!!
618 if (nulflag > -1)
619 {
620 for (nr=0; nr<maxvals; nr++)
621 {
622 if (*spntr == NUL_IVAL) (*null) ++;
623 *valptr++ = *spntr++;
624 }
625 }
626 else
627 {
628 for (nr=0; nr<maxvals; nr++) *valptr++ = *spntr++;
629 }
630 */
631
632 for (nr=0; nr<maxvals; nr++) *valptr++ = *spntr++;
633
634
635 return ERR_NORMAL;
636
637 /* here for errors */
638 end_of_it:
639 MID_E1(5,key,status,1);
640 return status;
641 }
642