Debian Codegraph @

libsrc/st/sckb.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 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 SCKB +++++++++++++++++++++++
29 .LANGUAGE C
30 .IDENTIFICATION Module SCKB
31 .AUTHOR K. Banse ESO - Garching
32 .KEYWORDS standard interfaces, keyword data base
33 .ENVIRONMENT VMS and UNIX
34 .COMMENTS
35 holds SCKWRx routines
36
37 .VERSION [1.00] 920213: pulled over from sck.c
38
39 090318 last modif
40 -----------------------------------------------------------------------------*/
41
42 #include <fileexts.h>
43
44
45
46 static char k_typ[4];
47
48 static int kunit, status;
49 static int bytelem, noelem, nn, kentry, lastval;
50
51 static struct KEY_STRUCT *keypntr;
52 /*
53
54 */
55
56 int SCKWRC(key,noelm,values,felem,maxvals,unit)
57 /*++++++++++++++++++++++++++++++++++++++++++++++++++
58 .PURPOSE
59 write data into character keyword
60 .ALGORITHM
61 .RETURNS
62 return status ( 0 = ok )
63 --------------------------------------------------*/
64
65 char *key /* IN : name of keyword */;
66 int noelm /* IN : for char. array, CHAR*noelm */;
67 char *values /* IN : buffer with data values */;
68 int felem /* IN : first data item to be written */;
69 int maxvals /* IN : no. of elements to write */;
70 int *unit /* IN : unit-pointer */;
71
72 {
73
74 int offset;
75 register int nr;
76
77 char *cdest;
78 register char cc;
79
80
81
82 /* find kentry in keyword control table */
83
84 kentry = MID_FNDKEY(key,k_typ,&bytelem,&noelem,&kunit);
85 if (unlikely(kentry < 0))
86 {
87 status = ERR_KEYBAD;
88 goto end_of_it;
89 }
90
91 if ( (k_typ[0] != 'C') || (bytelem != noelm) )
92 { /* type + bytes-per-element have to match */
93 status = ERR_KEYTYP;
94 goto end_of_it;
95 }
96
97 keypntr = KEYALL.KEYNAMES + kentry; /* point to keyword entry */
98 nn = felem - 1; /* offset in keyword array */
99 lastval = nn + maxvals; /* get last char. */
100
101
102 /* check first element + no. of values */
103
104 if ( (felem <= 0) || (lastval > noelem ) || (maxvals <=0) )
105 {
106 status = ERR_OUTLIM;
107 goto end_of_it;
108 }
109
110
111 offset = keypntr->OFFSET + (nn*bytelem); /* get offset in KCWORDS */
112 nn = maxvals * bytelem;
113
114 /* *****************************
115 kk = strlen(values);
116
117 if (kk >= nn)
118 strncpy(KCWORDS+offset,values,nn);
119 else
120 {
121 strcpy(KCWORDS+offset,values);
122 offset += kk;
123 for (nr=kk; nr<nn; nr++) KCWORDS[offset++] = ' ';
124 }
125 ********************************** */
126
127 cdest = KCWORDS + offset;
128 for (nr=0; nr<nn; nr++) /* fill KCWORDS */
129 {
130 cc = *values++;
131 *cdest++ = cc;
132 if (cc == '\0') /* check for Null */
133 {
134 register int mr;
135
136 for (mr=nr+1;mr<nn; mr++) *cdest++ = ' '; /* pad with blanks */
137 goto next_step;
138 }
139 }
140
141 next_step:
142 keypntr->UNIT = 0; /* not used yet */
143
144 return ERR_NORMAL;
145
146 /* here for errors */
147 end_of_it:
148 MID_E1(7,key,status,1);
149 return status;
150 }
151 /*
152
153 */
154
155 int SCKWRD(key,values,felem,maxvals,unit)
156 /*++++++++++++++++++++++++++++++++++++++++++++++++++
157 .PURPOSE
158 write data into character keyword
159 .ALGORITHM
160 .RETURNS
161 return status ( 0 = ok )
162 --------------------------------------------------*/
163
164 char *key /* IN : name of keyword */;
165 double *values /* IN : buffer with data values */;
166 int felem /* IN : first data item to be written */;
167 int maxvals /* IN : no. of elements to write */;
168 int *unit /* IN : unit-pointer */;
169
170 {
171
172 register int nr;
173
174 double *dpntr;
175
176
177 /* find kentry in keyword control table */
178
179 kentry = MID_FNDKEY(key,k_typ,&bytelem,&noelem,&kunit);
180 if (unlikely(kentry < 0))
181 {
182 status = ERR_KEYBAD;
183 goto end_of_it;
184 }
185
186 if (k_typ[0] != 'D') /* types have to match... */
187 {
188 status = ERR_KEYTYP;
189 goto end_of_it;
190 }
191
192
193 /* keyname o.k. - check first element + no. of values */
194
195 lastval = felem + maxvals - 1; /* last element to write */
196 if ( (felem <= 0) || (lastval > noelem) || (maxvals <=0) )
197 {
198 status = ERR_OUTLIM;
199 goto end_of_it;
200 }
201
202 keypntr = KEYALL.KEYNAMES + kentry; /* point to entry */
203
204
205 /* fill KDWORDS */
206
207 dpntr = KDWORDS + keypntr->OFFSET + felem - 1; /* get offset in KDWORDS */
208 for (nr=0; nr<maxvals; nr++)
209 *dpntr++ = *values++;
210
211 keypntr->UNIT = 0; /* not used yet */
212
213 return ERR_NORMAL;
214
215 /* here for errors */
216 end_of_it:
217 MID_E1(7,key,status,1);
218 return status;
219 }
220 /*
221
222 */
223
224 int SCKWRI(key,values,felem,maxvals,unit)
225 /*++++++++++++++++++++++++++++++++++++++++++++++++++
226 .PURPOSE
227 write data into character keyword
228 .ALGORITHM
229 .RETURNS
230 return status ( 0 = ok )
231 --------------------------------------------------*/
232
233 char *key /* IN : name of keyword */;
234 int *values /* IN : buffer with data values */;
235 int felem /* IN : first data item to be written */;
236 int maxvals /* IN : no. of elements to write */;
237 int *unit /* IN : unit-pointer */;
238
239 {
240
241 register int nr;
242
243 int *ipntr;
244
245
246 /* find kentry in keyword control table */
247
248 kentry = MID_FNDKEY(key,k_typ,&bytelem,&noelem,&kunit);
249 if (unlikely(kentry < 0))
250 {
251 status = ERR_KEYBAD;
252 goto end_of_it;
253 }
254
255 if (k_typ[0] != 'I') /* types have to match... */
256 {
257 status = ERR_KEYTYP;
258 goto end_of_it;
259 }
260
261
262 /* keyname o.k. - check first element + no. of values */
263
264 lastval = felem + maxvals - 1; /* last element to write */
265 if ( (felem <= 0) || (lastval > noelem) || (maxvals <=0) )
266 {
267 status = ERR_OUTLIM;
268 goto end_of_it;
269 }
270
271 keypntr = KEYALL.KEYNAMES + kentry; /* point to entry */
272
273
274 /* fill KIWORDS */
275
276 ipntr = KIWORDS + keypntr->OFFSET + felem - 1; /* get offset in KIWORDS */
277 for (nr=0; nr<maxvals; nr++)
278 *ipntr++ = *values++;
279
280 keypntr->UNIT = 0; /* not used yet */
281
282 return ERR_NORMAL;
283
284 /* here for errors */
285 end_of_it:
286 MID_E1(7,key,status,1);
287 return status;
288 }
289 /*
290
291 */
292
293 int SCKWRR(key,values,felem,maxvals,unit)
294 /*++++++++++++++++++++++++++++++++++++++++++++++++++
295 .PURPOSE
296 write data into character keyword
297 .ALGORITHM
298 .RETURNS
299 return status ( 0 = ok )
300 --------------------------------------------------*/
301
302 char *key /* IN : name of keyword */;
303 float *values /* IN : buffer with data values */;
304 int felem /* IN : first data item to be written */;
305 int maxvals /* IN : no. of elements to write */;
306 int *unit /* IN : unit-pointer */;
307
308 {
309
310 register int nr;
311
312 float *rpntr;
313
314
315 /* find kentry in keyword control table */
316
317 kentry = MID_FNDKEY(key,k_typ,&bytelem,&noelem,&kunit);
318 if (unlikely(kentry < 0))
319 {
320 status = ERR_KEYBAD;
321 goto end_of_it;
322 }
323
324 if (k_typ[0] != 'R') /* types have to match... */
325 {
326 status = ERR_KEYTYP;
327 goto end_of_it;
328 }
329
330
331 /* keyname o.k. - check first element + no. of values */
332
333 lastval = felem + maxvals - 1; /* last element to write */
334 if ( (felem <= 0) || (lastval > noelem) || (maxvals <=0) )
335 {
336 status = ERR_OUTLIM;
337 goto end_of_it;
338 }
339
340 keypntr = KEYALL.KEYNAMES + kentry; /* point to entry */
341
342
343 /* fill KRWORDS */
344
345 rpntr = KRWORDS + keypntr->OFFSET + felem - 1; /* get offset in KRWORDS */
346 for (nr=0; nr<maxvals; nr++)
347 *rpntr++ = *values++;
348
349 keypntr->UNIT = 0; /* not used yet */
350
351 return ERR_NORMAL;
352
353 /* here for errors */
354 end_of_it:
355 MID_E1(7,key,status,1);
356 return status;
357 }
358 /*
359
360 */
361
362 int SCKWRS(key,values,felem,maxvals,unit)
363 /*++++++++++++++++++++++++++++++++++++++++++++++++++
364 .PURPOSE
365 write data into size_t keyword
366 .ALGORITHM
367 .RETURNS
368 return status ( 0 = ok )
369 --------------------------------------------------*/
370
371 char *key /* IN : name of keyword */;
372 size_t *values /* IN : buffer with data values */;
373 int felem /* IN : first data item to be written */;
374 int maxvals /* IN : no. of elements to write */;
375 int *unit /* IN : unit-pointer */;
376
377 {
378
379 register int nr;
380
381 size_t *spntr;
382
383
384 /* find kentry in keyword control table */
385
386 kentry = MID_FNDKEY(key,k_typ,&bytelem,&noelem,&kunit);
387 if (unlikely(kentry < 0))
388 {
389 status = ERR_KEYBAD;
390 goto end_of_it;
391 }
392
393 if (k_typ[0] != 'S') /* types have to match... */
394 {
395 status = ERR_KEYTYP;
396 goto end_of_it;
397 }
398
399
400 /* keyname o.k. - check first element + no. of values */
401
402 lastval = felem + maxvals - 1; /* last element to write */
403 if ( (felem <= 0) || (lastval > noelem) || (maxvals <=0) )
404 {
405 status = ERR_OUTLIM;
406 goto end_of_it;
407 }
408
409 keypntr = KEYALL.KEYNAMES + kentry; /* point to entry */
410
411
412 /* fill KSWORDS */
413
414 spntr = KSWORDS + keypntr->OFFSET + felem - 1; /* get offset in KSWORDS */
415 for (nr=0; nr<maxvals; nr++)
416 *spntr++ = *values++;
417
418 keypntr->UNIT = 0; /* not used yet */
419
420 return ERR_NORMAL;
421
422 /* here for errors */
423 end_of_it:
424 MID_E1(7,key,status,1);
425 return status;
426 }
427