Debian Codegraph @

libsrc/st/scd.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 scd +++++++++++++++++++++++
29 .LANGUAGE C
30 .IDENTIFICATION Module scd.c
31 .AUTHOR K. Banse ESO - Garching
32 .KEYWORDS standard interfaces, descriptors
33 .ENVIRONMENT VMS and UNIX
34 .COMMENTS
35 holds SCDRDx (x=C,D,I,R,L, Z,X)
36
37 .VERSION [2.00] 871125: new and hopefully final version ...
38
39 090326 last modif
40 ----------------------------------------------------------------------------*/
41
42
43 #include <stdio.h>
44 #include <stdlib.h>
45
46 #include <fileexts.h>
47 #include <proto_st.h>
48
49
50 static char realdescr[52], help[72];
51
52 static int dsclen;
53
54 /*
55
56 */
57
58 int SCDRDC(imno,descr,noelm,felem,maxvals,actvals,values,unit,null)
59
60 /*++++++++++++++++++++++++++++++++++++++++++++++++++
61 .PURPOSE
62 read the contents of a character descriptor and its extensions
63 .ALGORITHM
64 'actval' will be set to the actual no. of values returned
65 .RETURNS
66 return status ( 0 = o.k. )
67 --------------------------------------------------*/
68
69 int imno /* IN : no. of data frame */;
70 char *descr /* IN : descriptor name */;
71 int noelm /* IN : no. of "elements" in type, i.e. CHAR*noelm */;
72 int felem /* IN : position of 1st element to be accessed */;
73 int maxvals /* IN : max. no. of values to be returned */;
74 int *actvals /* OUT: actual no. of values returned */;
75 char *values /* OUT: array of type char */;
76 int *unit /* OUT: unit pointer */;
77 int *null /* OUT: no. of null values in data \
78 will only be applied, if not -1 */;
79
80 {
81 int mm, kk, koff;
82 int status, chanl, bytelem, noelem, dblock, dindx;
83 int dunit, snull, first;
84
85 char dtype[4];
86
87 struct FCB_STRUCT *fcbp;
88
89 struct FCT_STRUCT *fctpntr;
90
91
92
93
94 *actvals = 0;
95
96 if ( (imno < 0) || (imno >= FCT.MAXENT) )
97 {
98 status = ERR_INPINV;
99 goto end_of_it;
100 }
101
102 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
103
104 fctpntr = FCT.ENTRIES + imno;
105
106 if (unlikely(fctpntr->LINK[0] >= 2)) /* if son, use father's imno */
107 {
108 imno = fctpntr->LINK[1];
109 fctpntr = FCT.ENTRIES + imno;
110 }
111
112 chanl = fctpntr->IOCHAN;
113 fcbp = fctpntr->FZP;
114
115
116 /* find descriptor in directory */
117
118 dtype[0] = 'C';
119 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
120 &noelem,&dunit,&dblock,&dindx,help);
121 if (status != ERR_NORMAL) goto end_of_it;
122
123 mm = noelem * bytelem; /* real size of descr. */
124 koff = (felem-1) * noelm; /* requested offset */
125 kk = mm - koff; /* size available */
126
127
128 /* check parameters */
129
130 if ( (felem <= 0) || (noelm < 1) || (kk < noelm) || (maxvals <= 0) )
131 {
132 status = ERR_INPINV; /* invalid input parameters */
133 goto end_of_it;
134 }
135 kk /= noelm; /* no. of elements/values available */
136
137
138 /* now go + get the data */
139
140 first = koff + 1; /* first byte to access */
141 if (kk > maxvals) kk = maxvals; /* minimize no. of data */
142 mm = kk * noelm;
143
144 snull = -1;
145
146 (void) MID_RDSCRC(chanl,dblock,dindx,first,mm,values,&snull);
147
148 *null = snull;
149 *actvals = kk;
150 *unit = dunit;
151 return status;
152
153 end_of_it: /* here for errors */
154 MID_E2(6,imno,descr,status,1);
155 return status;
156 }
157 /*
158
159 */
160
161 int SCDRDD(imno,descr,felem,maxvals,actvals,values,unit,null)
162
163 /*++++++++++++++++++++++++++++++++++++++++++++++++++
164 .PURPOSE
165 read the contents of a double precision descriptor and its extensions
166 .ALGORITHM
167 'actval' will be set to the actual no. of values returned
168 .RETURNS
169 return status ( 0 = o.k. )
170 --------------------------------------------------*/
171
172 int imno /* IN : no. of data frame */;
173 char *descr /* IN : descriptor name */;
174 int felem /* IN : position of 1st element to be accessed */;
175 int maxvals /* IN : max. no. of values to be returned */;
176 int *actvals /* OUT: actual no. of values returned */;
177 double *values /* OUT: array of type double */;
178 int *unit /* OUT: unit pointer */;
179 int *null /* OUT: no. of null values in data
180 will only be applied, if not -1 */;
181
182 {
183 int actv, n, *ipntr;
184 int status, chanl, bytelem, noelem, dblock, dindx;
185 int dunit, snull, first;
186
187 char dtype[4];
188
189 struct FCB_STRUCT *fcbp;
190
191 struct FCT_STRUCT *fctpntr;
192
193
194
195
196
197 *actvals = 0;
198
199 if ( (imno < 0) || (imno >= FCT.MAXENT) )
200 {
201 status = ERR_INPINV;
202 goto end_of_it;
203 }
204
205 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
206
207 fctpntr = FCT.ENTRIES + imno;
208 if (unlikely(fctpntr->LINK[0] >= 2)) /* if son, use father's imno */
209 { /* all except START goes to father */
210 if (strcmp(realdescr,"START") == 0)
211 goto next_step;
212
213 imno = fctpntr->LINK[1];
214 fctpntr = FCT.ENTRIES + imno;
215 }
216
217 next_step:
218 fcbp = fctpntr->FZP;
219 chanl = fctpntr->IOCHAN;
220
221
222 /* find descriptor in directory */
223
224 dtype[0] = 'D';
225 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
226 &noelem,&dunit,&dblock,&dindx,help);
227
228 if (status != ERR_NORMAL)
229 { /* see if real descr instead */
230 dtype[0] = 'R';
231 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
232 &noelem,&dunit,&dblock,&dindx,help);
233 }
234 if (status != ERR_NORMAL) goto end_of_it;
235
236
237 /* check parameters */
238
239 if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) )
240 {
241 status = ERR_INPINV; /* invalid input parameters */
242 goto end_of_it;
243 }
244
245
246 /* minimize no. of data */
247
248 actv = noelem - felem + 1; /* max. no. of values */
249 if (actv > maxvals) actv = maxvals;
250 *actvals = actv;
251
252
253 /* now go + get the data - type D is handled via integer descriptors... */
254
255 snull = -1;
256 if (dtype[0] == 'R')
257 {
258 float *rvals;
259 char *mypntr;
260
261 n = (int) sizeof(float) * actv;
262 mypntr = malloc((size_t) n);
263 if (mypntr == (char *) 0)
264 {
265 status = ERR_MEMOUT;
266 goto end_of_it;
267 }
268 rvals = (float *)mypntr;
269
270 (void) MID_RDSCRR(chanl,dblock,dindx,felem,actv,rvals,&snull);
271 for (n=0; n<actv; n++) values[n] = (double) *rvals++;
272 (void) free (mypntr);
273 }
274 else
275 {
276 n = DD_SIZE / II_SIZE;
277 first = n*felem - 1;
278 actv *= n;
279 ipntr = (int *) values;
280 MID_RDSCRI(chanl,dblock,dindx,first,actv,ipntr,&snull);
281 }
282 *null = snull;
283 *unit = dunit;
284
285 return status;
286
287 end_of_it: /* here for errors */
288 MID_E2(6,imno,descr,status,1);
289 return status;
290 }
291 /*
292
293 */
294
295 int SCDRDS(imno,descr,felem,maxvals,actvals,values,unit,null)
296
297 /*++++++++++++++++++++++++++++++++++++++++++++++++++
298 .PURPOSE
299 read the contents of a size_t descriptor and its extensions
300 .ALGORITHM
301 'actval' will be set to the actual no. of values returned
302 .RETURNS
303 return status ( 0 = o.k. )
304 --------------------------------------------------*/
305
306 int imno /* IN : no. of data frame */;
307 char *descr /* IN : descriptor name */;
308 int felem /* IN : position of 1st element to be accessed */;
309 int maxvals /* IN : max. no. of values to be returned */;
310 int *actvals /* OUT: actual no. of values returned */;
311 size_t *values /* OUT: array of type size_t */;
312 int *unit /* OUT: unit pointer */;
313 int *null /* OUT: no. of null values in data
314 will only be applied, if not -1 */;
315
316 {
317 int actv, n, *ipntr;
318 int status, chanl, bytelem, noelem, dblock, dindx;
319 int dunit, snull, first;
320
321 char dtype[4];
322
323 struct FCB_STRUCT *fcbp;
324
325 struct FCT_STRUCT *fctpntr;
326
327
328
329
330 *actvals = 0;
331
332 if ( (imno < 0) || (imno >= FCT.MAXENT) )
333 {
334 status = ERR_INPINV;
335 goto end_of_it;
336 }
337
338 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
339
340 fctpntr = FCT.ENTRIES + imno;
341 if (unlikely(fctpntr->LINK[0] >= 2)) /* if son, use father's imno */
342 { /* all except START goes to father */
343 imno = fctpntr->LINK[1];
344 fctpntr = FCT.ENTRIES + imno;
345 }
346
347 fcbp = fctpntr->FZP;
348 chanl = fctpntr->IOCHAN;
349
350
351 /* find descriptor in directory */
352
353 dtype[0] = 'S';
354 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
355 &noelem,&dunit,&dblock,&dindx,help);
356 if (status != ERR_NORMAL) goto end_of_it;
357
358
359 /* check parameters */
360
361 if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) )
362 {
363 status = ERR_INPINV; /* invalid input parameters */
364 goto end_of_it;
365 }
366
367
368 /* minimize no. of data */
369
370 actv = noelem - felem + 1; /* max. no. of values */
371 if (actv > maxvals) actv = maxvals;
372 *actvals = actv;
373
374
375 /* now go + get the data - type S is handled via integer descriptors... */
376
377 snull = -1;
378 n = SS_SIZE / II_SIZE;
379 first = n*felem - 1;
380 actv *= n;
381 ipntr = (int *) values;
382 MID_RDSCRI(chanl,dblock,dindx,first,actv,ipntr,&snull);
383 *null = snull;
384 *unit = dunit;
385
386 return status;
387
388 end_of_it: /* here for errors */
389 MID_E2(6,imno,descr,status,1);
390 return status;
391 }
392 /*
393
394 */
395
396 int SCDRDL(imno,descr,felem,maxvals,actvals,values,unit,null)
397
398 /*++++++++++++++++++++++++++++++++++++++++++++++++++
399 .PURPOSE
400 read the contents of a logical descriptor and its extensions
401 .ALGORITHM
402 'actval' will be set to the actual no. of values returned
403 .RETURNS
404 return status ( 0 = o.k. )
405 --------------------------------------------------*/
406
407 int imno /* IN : no. of data frame */;
408 char *descr /* IN : descriptor name */;
409 int felem /* IN : position of 1st element to be accessed */;
410 int maxvals /* IN : max. no. of values to be returned */;
411 int *actvals /* OUT: actual no. of values returned */;
412 int *values /* OUT: array of type int */;
413 int *unit /* OUT: unit pointer */;
414 int *null /* OUT: no. of null values in data
415 will only be applied, if not -1 */;
416
417 {
418 int status, chanl, bytelem, noelem, dblock, dindx;
419 int dunit, snull, *iptr;
420 register int nr;
421
422 char dtype[4];
423
424 struct FCB_STRUCT *fcbp;
425
426 struct FCT_STRUCT *fctpntr;
427
428
429
430
431 *actvals = 0;
432
433 if ( (imno < 0) || (imno >= FCT.MAXENT) )
434 {
435 status = ERR_INPINV;
436 goto end_of_it;
437 }
438
439 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
440
441 fctpntr = FCT.ENTRIES + imno;
442 if (unlikely(fctpntr->LINK[0] >= 2)) /* if son, use father's imno */
443 {
444 imno = fctpntr->LINK[1];
445 fctpntr = FCT.ENTRIES + imno;
446 }
447
448 chanl = fctpntr->IOCHAN;
449 fcbp = fctpntr->FZP;
450
451
452 /* find descriptor in directory */
453
454 dtype[0] = 'L';
455 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
456 &noelem,&dunit,&dblock,&dindx,help);
457 if (status != ERR_NORMAL) goto end_of_it;
458
459
460
461 /* check parameters */
462
463 if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) )
464 {
465 status = ERR_INPINV; /* invalid input parameters */
466 goto end_of_it;
467 }
468
469
470 /* minimize no. of data */
471
472 *actvals = noelem - felem + 1; /* max. no. of values */
473 if (*actvals > maxvals) *actvals = maxvals;
474
475
476 /* now go + get the data */
477
478 snull = -1;
479 (void) MID_RDSCRI(chanl,dblock,dindx,felem,*actvals,values,&snull);
480
481 iptr = values;
482 for (nr=0; nr<*actvals; nr++)
483 {
484 if (*iptr != 0) *iptr = 1; /* enforce 0/1 as only output */
485 iptr++;
486 }
487
488 *null = snull;
489 *unit = dunit;
490 return status;
491
492
493 end_of_it: /* here for errors */
494 MID_E2(6,imno,descr,status,1);
495 return status;
496 }
497 /*
498
499 */
500
501 int SCDRDI(imno,descr,felem,maxvals,actvals,values,unit,null)
502
503 /*++++++++++++++++++++++++++++++++++++++++++++++++++
504 .PURPOSE
505 read the contents of an integer descriptor and its extensions
506 .ALGORITHM
507 'actval' will be set to the actual no. of values returned
508 .RETURNS
509 return status ( 0 = o.k. )
510 --------------------------------------------------*/
511
512 int imno /* IN : no. of data frame */;
513 char *descr /* IN : descriptor name */;
514 int felem /* IN : position of 1st element to be accessed */;
515 int maxvals /* IN : max. no. of values to be returned */;
516 int *actvals /* OUT: actual no. of values returned */;
517 int *values /* OUT: array of type int */;
518 int *unit /* OUT: unit pointer */;
519 int *null /* OUT: no. of null values in data
520 will only be applied, if not -1 */;
521
522 {
523 int status, chanl, bytelem, noelem, dblock, dindx;
524 int dunit, snull;
525
526 char dtype[4];
527
528 struct FCB_STRUCT *fcbp;
529
530 struct FCT_STRUCT *fctpntr;
531
532
533
534
535 *actvals = 0;
536
537 if ( (imno < 0) || (imno >= FCT.MAXENT) )
538 {
539 status = ERR_INPINV;
540 goto end_of_it;
541 }
542
543 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
544
545 fctpntr = FCT.ENTRIES + imno;
546 if (unlikely(fctpntr->LINK[0] >= 2)) /* if son, use father's imno */
547 { /* all except NAXIS, NPIX => father */
548 if (strcmp(realdescr,"NAXIS") == 0)
549 goto next_step;
550 else if (strcmp(realdescr,"NPIX") == 0)
551 goto next_step;
552
553 imno = fctpntr->LINK[1];
554 fctpntr = FCT.ENTRIES + imno;
555 }
556
557 next_step:
558 chanl = fctpntr->IOCHAN;
559 fcbp = fctpntr->FZP;
560
561
562 /* find descriptor in directory */
563
564 dtype[0] = 'I';
565 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
566 &noelem,&dunit,&dblock,&dindx,help);
567 if (status != ERR_NORMAL) goto end_of_it;
568
569
570
571 /* check parameters */
572
573 if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) )
574 {
575 status = ERR_INPINV; /* invalid input parameters */
576 goto end_of_it;
577 }
578
579
580 /* minimize no. of data */
581
582 *actvals = noelem - felem + 1; /* max. no. of values */
583 if (*actvals > maxvals) *actvals = maxvals;
584
585
586 /* now go + get the data */
587
588 snull = -1;
589 (void) MID_RDSCRI(chanl,dblock,dindx,felem,*actvals,values,&snull);
590 *null = snull;
591 *unit = dunit;
592 return status;
593
594
595 end_of_it: /* here for errors */
596 MID_E2(6,imno,descr,status,1);
597 return status;
598 }
599 /*
600
601 */
602
603 int SCDRDR(imno,descr,felem,maxvals,actvals,values,unit,null)
604
605 /*++++++++++++++++++++++++++++++++++++++++++++++++++
606 .PURPOSE
607 read the contents of a real descriptor and its extensions
608 .ALGORITHM
609 'actval' will be set to the actual no. of values returned
610 .RETURNS
611 return status ( 0 = o.k. )
612 --------------------------------------------------*/
613
614 int imno /* IN : no. of data frame */;
615 char *descr /* IN : descriptor name */;
616 int felem /* IN : position of 1st element to be accessed */;
617 int maxvals /* IN : max. no. of values to be returned */;
618 int *actvals /* OUT: actual no. of values returned */;
619 float *values /* OUT: array of type real */;
620 int *unit /* OUT: unit pointer */;
621 int *null /* OUT: no. of null values in data
622 will only be applied, if not -1 */;
623
624 {
625 int n, actv;
626 int status, chanl, bytelem, noelem, dblock, dindx;
627 int dunit, snull, first;
628
629 char dtype[4];
630
631 struct FCB_STRUCT *fcbp;
632
633 struct FCT_STRUCT *fctpntr;
634
635
636
637
638 *actvals = 0;
639
640 if ( (imno < 0) || (imno >= FCT.MAXENT) ) /* check imno */
641 {
642 status = ERR_INPINV;
643 goto end_of_it;
644 }
645
646 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
647
648 fctpntr = FCT.ENTRIES + imno;
649 if (unlikely(fctpntr->LINK[0] >= 2)) /* if son, use father's imno */
650 {
651 imno = fctpntr->LINK[1];
652 fctpntr = FCT.ENTRIES + imno;
653 }
654
655 chanl = fctpntr->IOCHAN;
656 fcbp = fctpntr->FZP;
657
658
659 /* find descriptor in directory */
660
661 dtype[0] = 'R';
662 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
663 &noelem,&dunit,&dblock,&dindx,help);
664
665 if (status != ERR_NORMAL)
666 { /* see if double descr instead */
667 dtype[0] = 'D';
668 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
669 &noelem,&dunit,&dblock,&dindx,help);
670 }
671 if (status != ERR_NORMAL) goto end_of_it;
672
673
674 /* check parameters */
675
676 if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) )
677 {
678 status = ERR_INPINV; /* invalid input parameters */
679 goto end_of_it;
680 }
681
682
683 /* minimize no. of data */
684
685 actv = noelem - felem + 1; /* max. no. of values */
686 if (actv > maxvals) actv = maxvals;
687 *actvals = actv;
688
689
690 /* now go + get the data - type D is handled via integer descriptors... */
691
692 snull = -1;
693 if (dtype[0] == 'D')
694 {
695 int *ipntr;
696 double *dvals;
697 char *mypntr;
698
699 n = (int) sizeof(double) * actv;
700 mypntr = malloc((size_t) n); /* allocate space for */
701 if (mypntr == (char *) 0) /* for double temp data */
702 {
703 status = ERR_MEMOUT;
704 goto end_of_it;
705 }
706 dvals = (double *)mypntr;
707
708 n = DD_SIZE / II_SIZE; /* double stuff is stored */
709 first = n*felem - 1; /* integer data */
710 actv *= n;
711 ipntr = (int *)mypntr;
712 (void) MID_RDSCRI(chanl,dblock,dindx,first,actv,ipntr,&snull);
713
714 for (n=0; n<actv; n++) values[n] = (float) *dvals++;
715 (void) free (mypntr);
716 }
717 else
718 (void) MID_RDSCRR(chanl,dblock,dindx,felem,actv,values,&snull);
719
720 *null = snull;
721 *unit = dunit;
722 return status;
723
724 end_of_it: /* here for errors */
725 MID_E2(6,imno,descr,status,1);
726 return status;
727 }
728 /*
729
730 */
731
732 int SCDRDH(imno,descr,felem,maxvals,actvals,values,totvals)
733
734 /*++++++++++++++++++++++++++++++++++++++++++++++++++
735 .PURPOSE
736 read the help text of descriptor and its extensions
737 .ALGORITHM
738 `actval' will be set to the actual no. of values returned
739 if no help text, `totvals' = -1
740 .RETURNS
741 return status ( 0 = o.k. )
742 --------------------------------------------------*/
743
744 int imno /* IN : no. of data frame */;
745 char *descr /* IN : descriptor name */;
746 int felem /* IN : position of 1st element to be accessed */;
747 int maxvals /* IN : max. no. of values to be returned */;
748 int *actvals /* OUT: actual no. of values returned */;
749 char *values /* OUT: char. buf for help text */;
750 int *totvals /* OUT: total size of help string */;
751
752 {
753 int kk, dunit;
754 int status, chanl, bytelem, noelem, dblock, dindx;
755
756 char dtype[80];
757
758 struct FCB_STRUCT *fcbp;
759
760 struct FCT_STRUCT *fctpntr;
761
762
763
764
765 if ( (imno < 0) || (imno >= FCT.MAXENT) )
766 {
767 status = ERR_INPINV;
768 goto end_of_it;
769 }
770
771 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
772
773 *actvals = 0;
774 fctpntr = FCT.ENTRIES + imno;
775 if (unlikely(fctpntr->LINK[0] >= 2)) /* if son, use father's imno */
776 {
777 imno = fctpntr->LINK[1];
778 fctpntr = FCT.ENTRIES + imno;
779 }
780
781 chanl = fctpntr->IOCHAN;
782 fcbp = fctpntr->FZP;
783
784
785 /* find descriptor in directory */
786
787 dtype[0] = ' ';
788 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
789 &noelem,&dunit,&dblock,&dindx,dtype);
790 kk = (int) strlen(dtype);
791 if (kk < 1)
792 *totvals = -1;
793 else
794 {
795 if (kk > maxvals) kk = maxvals;
796 (void) memcpy(values,dtype,(size_t)(kk+1));
797 *totvals = *actvals = kk;
798 }
799 return status;
800
801 end_of_it: /* here for errors */
802 MID_E2(6,imno,descr,status,1);
803 return status;
804 }
805 /*
806
807 */
808
809 int SCDRDZ(imno,dirsize,direlem)
810
811 /*++++++++++++++++++++++++++++++++++++++++++++++++++
812 .PURPOSE
813 display the descriptor directory
814 .ALGORITHM
815 use MID_xDSCDIR to do the job
816 .RETURNS
817 return status ( 0 = o.k. )
818 --------------------------------------------------*/
819
820 int imno /* IN : no. of data frame */;
821 int *dirsize /* OUT : no. of chars. used by descr-directory */;
822 int *direlem /* OUT : no. of descr. (incl. directory) */;
823
824 {
825 int dblock, dindx, dunit;
826
827 char dtype[4];
828
829 struct FCB_STRUCT *fcbp;
830
831 struct FCT_STRUCT *fctpntr;
832
833
834
835
836 if ( (imno < 0) || (imno >= FCT.MAXENT) )
837 {
838 MID_E2(6,imno,"Z-DIRECORY.MIDAS",ERR_INPINV,1);
839 return ERR_INPINV;
840 }
841
842 fctpntr = FCT.ENTRIES + imno;
843 if (unlikely(fctpntr->LINK[0] >= 2)) /* if son, use father's imno */
844 {
845 imno = fctpntr->LINK[1];
846 fctpntr = FCT.ENTRIES + imno;
847 }
848
849 fcbp = fctpntr->FZP;
850 (void) MID_YDSCDIR(imno,'Z',dtype,dtype,dirsize,direlem,
851 &dunit,&dblock,&dindx,help);
852
853 return ERR_NORMAL;
854 }
855 /*
856
857 */
858
859 int SCDRDX(imno,flag,name,type,bytelem,noelem,hnc)
860
861 /*++++++++++++++++++++++++++++++++++++++++++++++++++
862 .PURPOSE
863 in 1. step get complete descriptor directory
864 next return descriptor info like SCDINF
865 .ALGORITHM
866 use MID_xDSCDIR to do the job
867 .RETURNS
868 return status ( 0 = o.k. )
869 --------------------------------------------------*/
870
871 int imno; /* IN: imno of data frame */
872 int flag; /* IN: action flag
873 = 0, free space again
874 = 1, read in complete descr. directory
875 = 2, as 1 and also return total no. of descriptors
876 = 10, return descr. info of next descr. */
877 char *name; /* OUT: name of next descr. = ' ' if no more descr. */
878 char *type; /* OUT: type of next descr. */
879 int *bytelem; /* OUT: no. of bytes per element */
880 int *noelem; /* OUT: no. of elements */
881 int *hnc; /* OUT: no. of help text chars */
882
883 {
884 int status, chanl, nullo;
885 static int dirlen, nlen, myimno=-1;
886
887 char *dscpntr;
888 static char *cpt, *xdscdir = (char *) 0;
889
890 struct FCB_STRUCT *fcbp;
891
892 struct FCT_STRUCT *fctpntr;
893
894
895
896
897 fctpntr = FCT.ENTRIES + imno;
898
899 if (flag == 0)
900 {
901 if (xdscdir != (char *) 0)
902 {
903 free (xdscdir);
904 xdscdir = (char *) 0;
905 }
906 return ERR_NORMAL;
907 }
908
909
910 if ( (imno < 0) || (imno >= FCT.MAXENT) )
911 {
912 status= ERR_INPINV; /* wrong argument `npos' */
913 goto end_of_it;
914 }
915
916 fctpntr = FCT.ENTRIES + imno;
917 if (unlikely(fctpntr->LINK[0] >= 2)) /* if son, use father's imno */
918 {
919 imno = fctpntr->LINK[1];
920 fctpntr = FCT.ENTRIES + imno;
921 }
922
923 chanl = fctpntr->IOCHAN;
924 fcbp = fctpntr->FZP;
925
926
927 dscpntr = (char *) &YDSCDIR_ENTRY;
928
929 if (flag != 10)
930 {
931 myimno = imno;
932 dirlen = fcbp->DFILLED;
933
934 if (xdscdir != (char *) 0) (void)free (xdscdir);
935 xdscdir = (char *) malloc((size_t) (dirlen+4));
936
937 nullo = -1;
938 (void) MID_RDSCRC(chanl,fcbp->PTRLDB,0,1,dirlen,xdscdir,&nullo);
939 cpt = xdscdir;
940
941
942 /* for flag = 2, we have to go through directory once */
943
944 if (flag == 2)
945 {
946 register int nr, npos;
947
948 nr = 0; npos = 0;
949 while (nr < dirlen)
950 {
951 if (*cpt != '\0') npos ++; /* test if deleted descr. */
952 cpt += fcbp->DIRENTRY; nr += fcbp->DIRENTRY;
953 }
954 *noelem = npos;
955 cpt = xdscdir; /* set back to start */
956 }
957
958 cpt += fcbp->DIRENTRY; /* skip directory itself */
959 nlen = fcbp->DIRENTRY; /* set to already used length */
960 }
961
962 else
963 {
964 if (myimno != imno) /* no call with flag=1 before... */
965 {
966 status = ERR_INPINV;
967 goto end_of_it;
968 }
969
970 dYloop:
971 if (nlen < dirlen)
972 {
973 if (*cpt == '\0') /* test if deleted entry */
974 {
975 cpt += fcbp->DIRENTRY; nlen += fcbp->DIRENTRY;
976 goto dYloop;
977 }
978 else
979 (void) memcpy(dscpntr,cpt,(size_t)fcbp->DIRENTRY);
980
981 cpt += fcbp->DIRENTRY;
982 nlen += fcbp->DIRENTRY; /* follow with pointer */
983 }
984 else
985 {
986 if (xdscdir != (char *) 0)
987 {
988 (void)free (xdscdir);
989 xdscdir = (char *) 0;
990 }
991 *name = ' ';
992 *noelem = -1; /* mark the end */
993 return ERR_NORMAL;
994 }
995
996 (void) memcpy(name,YDSC_PNTR->NAMESTR,(size_t)YDSC_PNTR->NAMELEN);
997 *(name + YDSC_PNTR->NAMELEN) = '\0';
998 /* passed param `type' must be at least 4 chars */
999 (void) MID_TYPINFO(YDSC_PNTR->TYPE,YDSC_PNTR->BYTELEM,type,4);
1000 *noelem = YDSC_PNTR->NOELEM;
1001 *bytelem = YDSC_PNTR->BYTELEM;
1002 *hnc = YDSC_PNTR->HELPLEN;
1003 }
1004
1005 return ERR_NORMAL;
1006
1007
1008 end_of_it:
1009 MID_E2(6,imno,"descriptor.directory",status,1);
1010 return status;
1011 }
1012 /*
1013
1014 */
1015
1016 int SCDHRC(imno,descr,noelm,felem,maxvals,actvals,values,htxt,hmax,unit,null)
1017
1018 /*++++++++++++++++++++++++++++++++++++++++++++++++++
1019 .PURPOSE
1020 read the contents of a character descriptor and its help text
1021 .ALGORITHM
1022 'actval' will be set to the actual no. of values returned
1023 .RETURNS
1024 return status ( 0 = o.k. )
1025 --------------------------------------------------*/
1026
1027 int imno /* IN : no. of data frame */;
1028 char *descr /* IN : descriptor name */;
1029 int noelm /* IN : no. of "elements" in type, i.e. CHAR*noelm */;
1030 int felem /* IN : position of 1st element to be accessed */;
1031 int maxvals /* IN : max. no. of values to be returned */;
1032 int *actvals /* OUT: actual no. of values returned */;
1033 char *values /* OUT: array for descriptor data */;
1034 char *htxt; /* OUT: help text */
1035 int hmax; /* OUT: max. no. of chars in help text */
1036 int *unit /* OUT: unit pointer */;
1037 int *null /* OUT: no. of null values in data
1038 will only be applied, if not -1 */;
1039
1040 {
1041 int mm, kk, koff;
1042 int status, chanl, bytelem, noelem, dblock, dindx;
1043 int dunit, snull, first;
1044
1045 char dtype[4];
1046
1047 struct FCB_STRUCT *fcbp;
1048
1049 struct FCT_STRUCT *fctpntr;
1050
1051
1052
1053
1054 if ( (imno < 0) || (imno >= FCT.MAXENT) )
1055 {
1056 status = ERR_INPINV;
1057 goto end_of_it;
1058 }
1059
1060 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
1061
1062 fctpntr = FCT.ENTRIES + imno;
1063 if (unlikely(fctpntr->LINK[0] >= 2)) /* if son, use father's imno */
1064 {
1065 imno = fctpntr->LINK[1];
1066 fctpntr = FCT.ENTRIES + imno;
1067 }
1068
1069 chanl = fctpntr->IOCHAN;
1070 fcbp = fctpntr->FZP;
1071
1072
1073 /* find descriptor in directory */
1074
1075 htxt[0] = '\0';
1076 dtype[0] = 'C';
1077 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
1078 &noelem,&dunit,&dblock,&dindx,htxt);
1079 if (status != ERR_NORMAL) goto end_of_it;
1080
1081 mm = noelem * bytelem; /* real size of descr. */
1082 koff = (felem-1) * noelm; /* requested offset */
1083 kk = mm - koff; /* size available */
1084
1085
1086 /* check parameters */
1087
1088 if ( (felem <= 0) || (noelm < 1) || (kk < noelm) || (maxvals <= 0) )
1089 {
1090 status = ERR_INPINV; /* invalid input parameters */
1091 goto end_of_it;
1092 }
1093 kk /= noelm; /* no. of elements/values available */
1094
1095
1096 /* now go + get the data */
1097
1098 first = koff + 1; /* first byte to access */
1099 if (kk > maxvals) kk = maxvals; /* minimize no. of data */
1100 mm = kk * noelm;
1101
1102 snull = -1;
1103 (void) MID_RDSCRC(chanl,dblock,dindx,first,mm,values,&snull);
1104
1105 *null = snull;
1106 *actvals = kk;
1107 *unit = dunit;
1108 return status;
1109
1110 end_of_it: /* here for errors */
1111 MID_E2(6,imno,descr,status,1);
1112 return status;
1113 }
1114 /*
1115
1116 */
1117
1118 int SCDHRD(imno,descr,felem,maxvals,actvals,values,htxt,hmax,unit,null)
1119
1120 /*++++++++++++++++++++++++++++++++++++++++++++++++++
1121 .PURPOSE
1122 read the contents of a double precision descriptor and its help text
1123 .ALGORITHM
1124 'actval' will be set to the actual no. of values returned
1125 .RETURNS
1126 return status ( 0 = o.k. )
1127 --------------------------------------------------*/
1128
1129 int imno /* IN : no. of data frame */;
1130 char *descr /* IN : descriptor name */;
1131 int felem /* IN : position of 1st element to be accessed */;
1132 int maxvals /* IN : max. no. of values to be returned */;
1133 int *actvals /* OUT: actual no. of values returned */;
1134 double *values /* OUT: array of type double */;
1135 char *htxt; /* OUT: help text */
1136 int hmax; /* IN : max. no. of chars. for help text */
1137 int *unit /* OUT: unit pointer */;
1138 int *null /* OUT: no. of null values in data
1139 will only be applied, if not -1 */;
1140
1141 {
1142 int actv, n, *ipntr;
1143 int status, chanl, bytelem, noelem, dblock, dindx;
1144 int dunit, snull, first;
1145
1146 char dtype[4];
1147
1148 struct FCB_STRUCT *fcbp;
1149
1150 struct FCT_STRUCT *fctpntr;
1151
1152
1153
1154
1155
1156
1157 if ( (imno < 0) || (imno >= FCT.MAXENT) )
1158 {
1159 status = ERR_INPINV;
1160 goto end_of_it;
1161 }
1162
1163 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
1164
1165 fctpntr = FCT.ENTRIES + imno;
1166 if (unlikely(fctpntr->LINK[0] >= 2)) /* if son, use father's imno */
1167 { /* all except START goes to father */
1168 if (strcmp(realdescr,"START") == 0)
1169 goto next_step;
1170
1171 imno = fctpntr->LINK[1];
1172 fctpntr = FCT.ENTRIES + imno;
1173 }
1174
1175 next_step:
1176 fcbp = fctpntr->FZP;
1177 chanl = fctpntr->IOCHAN;
1178
1179
1180 /* find descriptor in directory */
1181
1182 htxt[0] = '\0';
1183 dtype[0] = 'D';
1184 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
1185 &noelem,&dunit,&dblock,&dindx,htxt);
1186 if (status != ERR_NORMAL)
1187 { /* see if real descr instead */
1188 dtype[0] = 'R';
1189 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
1190 &noelem,&dunit,&dblock,&dindx,htxt);
1191 }
1192 if (status != ERR_NORMAL) goto end_of_it;
1193
1194
1195 /* check parameters */
1196
1197 if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) )
1198 {
1199 status = ERR_INPINV; /* invalid input parameters */
1200 goto end_of_it;
1201 }
1202
1203
1204 /* minimize no. of data */
1205
1206 actv = noelem - felem + 1; /* max. no. of values */
1207 if (actv > maxvals) actv = maxvals;
1208 *actvals = actv;
1209
1210
1211 /* now go + get the data - type D is handled via integer descriptors... */
1212
1213 snull = -1;
1214 if (dtype[0] == 'R')
1215 {
1216 float *rvals;
1217 char *mypntr;
1218
1219 n = (int)sizeof(float) * actv;
1220 mypntr = malloc((size_t) n);
1221 if (mypntr == (char *) 0)
1222 {
1223 status = ERR_MEMOUT;
1224 goto end_of_it;
1225 }
1226 rvals = (float *)mypntr;
1227
1228 (void) MID_RDSCRR(chanl,dblock,dindx,felem,actv,rvals,&snull);
1229 for (n=0; n<actv; n++) values[n] = (double) *rvals++;
1230 (void) free (mypntr);
1231 }
1232 else
1233 {
1234 n = DD_SIZE / II_SIZE;
1235 first = n*felem - 1;
1236 actv *= n;
1237 ipntr = (int *) values;
1238 MID_RDSCRI(chanl,dblock,dindx,first,actv,ipntr,&snull);
1239 }
1240 *null = snull;
1241 *unit = dunit;
1242 return status;
1243
1244 end_of_it: /* here for errors */
1245 MID_E2(6,imno,descr,status,1);
1246 return status;
1247 }
1248 /*
1249
1250 */
1251
1252 int SCDHRS(imno,descr,felem,maxvals,actvals,values,htxt,hmax,unit,null)
1253
1254 /*++++++++++++++++++++++++++++++++++++++++++++++++++
1255 .PURPOSE
1256 read the contents of a size_t descriptor and its help text
1257 .ALGORITHM
1258 'actval' will be set to the actual no. of values returned
1259 .RETURNS
1260 return status ( 0 = o.k. )
1261 --------------------------------------------------*/
1262
1263 int imno /* IN : no. of data frame */;
1264 char *descr /* IN : descriptor name */;
1265 int felem /* IN : position of 1st element to be accessed */;
1266 int maxvals /* IN : max. no. of values to be returned */;
1267 int *actvals /* OUT: actual no. of values returned */;
1268 size_t *values /* OUT: array of type size_t */;
1269 char *htxt; /* OUT: help text */
1270 int hmax; /* IN : max. no. of chars. for help text */
1271 int *unit /* OUT: unit pointer */;
1272 int *null /* OUT: no. of null values in data
1273 will only be applied, if not -1 */;
1274
1275 {
1276 int actv, n, *ipntr;
1277 int status, chanl, bytelem, noelem, dblock, dindx;
1278 int dunit, snull, first;
1279
1280 char dtype[4];
1281
1282 struct FCB_STRUCT *fcbp;
1283
1284 struct FCT_STRUCT *fctpntr;
1285
1286
1287
1288
1289
1290 if ( (imno < 0) || (imno >= FCT.MAXENT) )
1291 {
1292 status = ERR_INPINV;
1293 goto end_of_it;
1294 }
1295
1296 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
1297
1298 fctpntr = FCT.ENTRIES + imno;
1299 if (unlikely(fctpntr->LINK[0] >= 2)) /* if son, use father's imno */
1300 { /* all except START goes to father */
1301 imno = fctpntr->LINK[1];
1302 fctpntr = FCT.ENTRIES + imno;
1303 }
1304
1305 fcbp = fctpntr->FZP;
1306 chanl = fctpntr->IOCHAN;
1307
1308
1309 /* find descriptor in directory */
1310
1311 htxt[0] = '\0';
1312 dtype[0] = 'S';
1313 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
1314 &noelem,&dunit,&dblock,&dindx,htxt);
1315 if (status != ERR_NORMAL) goto end_of_it;
1316
1317
1318 /* check parameters */
1319
1320 if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) )
1321 {
1322 status = ERR_INPINV; /* invalid input parameters */
1323 goto end_of_it;
1324 }
1325
1326
1327 /* minimize no. of data */
1328
1329 actv = noelem - felem + 1; /* max. no. of values */
1330 if (actv > maxvals) actv = maxvals;
1331 *actvals = actv;
1332
1333
1334 /* now go + get the data - type S is handled via integer descriptors... */
1335
1336 snull = -1;
1337 n = SS_SIZE / II_SIZE;
1338 first = n*felem - 1;
1339 actv *= n;
1340 ipntr = (int *) values;
1341 MID_RDSCRI(chanl,dblock,dindx,first,actv,ipntr,&snull);
1342 *null = snull;
1343 *unit = dunit;
1344 return status;
1345
1346 end_of_it: /* here for errors */
1347 MID_E2(6,imno,descr,status,1);
1348 return status;
1349 }
1350 /*
1351
1352 */
1353
1354 int SCDHRL(imno,descr,felem,maxvals,actvals,values,htxt,hmax,unit,null)
1355
1356 /*++++++++++++++++++++++++++++++++++++++++++++++++++
1357 .PURPOSE
1358 read the contents of a logical descriptor and its help text
1359 .ALGORITHM
1360 'actval' will be set to the actual no. of values returned
1361 .RETURNS
1362 return status ( 0 = o.k. )
1363 --------------------------------------------------*/
1364
1365 int imno /* IN : no. of data frame */;
1366 char *descr /* IN : descriptor name */;
1367 int felem /* IN : position of 1st element to be accessed */;
1368 int maxvals /* IN : max. no. of values to be returned */;
1369 int *actvals /* OUT: actual no. of values returned */;
1370 int *values /* OUT: array of type int */;
1371 char *htxt; /* OUT: help text */
1372 int hmax; /* IN : max. no. of chars. for help text */
1373 int *unit /* OUT: unit pointer */;
1374 int *null /* OUT: no. of null values in data
1375 will only be applied, if not -1 */;
1376
1377 {
1378 int status, chanl, bytelem, noelem, dblock, dindx;
1379 int dunit, snull;
1380
1381 char dtype[4];
1382
1383 struct FCB_STRUCT *fcbp;
1384
1385 struct FCT_STRUCT *fctpntr;
1386
1387
1388
1389
1390
1391 if ( (imno < 0) || (imno >= FCT.MAXENT) )
1392 {
1393 status = ERR_INPINV;
1394 goto end_of_it;
1395 }
1396
1397 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
1398
1399 fctpntr = FCT.ENTRIES + imno;
1400 if (unlikely(fctpntr->LINK[0] >= 2)) /* if son, use father's imno */
1401 {
1402 imno = fctpntr->LINK[1];
1403 fctpntr = FCT.ENTRIES + imno;
1404 }
1405
1406 chanl = fctpntr->IOCHAN;
1407 fcbp = fctpntr->FZP;
1408
1409
1410 /* find descriptor in directory */
1411
1412 htxt[0] = '\0';
1413 dtype[0] = 'L';
1414 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
1415 &noelem,&dunit,&dblock,&dindx,htxt);
1416 if (status != ERR_NORMAL) goto end_of_it;
1417
1418
1419 /* check parameters */
1420
1421 if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) )
1422 {
1423 status = ERR_INPINV; /* invalid input parameters */
1424 goto end_of_it;
1425 }
1426
1427
1428 /* minimize no. of data */
1429
1430 *actvals = noelem - felem + 1; /* max. no. of values */
1431 if (*actvals > maxvals) *actvals = maxvals;
1432
1433
1434 /* now go + get the data */
1435
1436 snull = -1;
1437 (void) MID_RDSCRI(chanl,dblock,dindx,felem,*actvals,values,&snull);
1438 *null = snull;
1439 *unit = dunit;
1440 return status;
1441
1442
1443 end_of_it: /* here for errors */
1444 MID_E2(6,imno,descr,status,1);
1445 return status;
1446 }
1447 /*
1448
1449 */
1450
1451 int SCDHRI(imno,descr,felem,maxvals,actvals,values,htxt,hmax,unit,null)
1452
1453 /*++++++++++++++++++++++++++++++++++++++++++++++++++
1454 .PURPOSE
1455 read the contents of an integer descriptor and its help text
1456 .ALGORITHM
1457 'actval' will be set to the actual no. of values returned
1458 .RETURNS
1459 return status ( 0 = o.k. )
1460 --------------------------------------------------*/
1461
1462 int imno /* IN : no. of data frame */;
1463 char *descr /* IN : descriptor name */;
1464 int felem /* IN : position of 1st element to be accessed */;
1465 int maxvals /* IN : max. no. of values to be returned */;
1466 int *actvals /* OUT: actual no. of values returned */;
1467 int *values /* OUT: array of type int */;
1468 char *htxt; /* OUT: help text */
1469 int hmax; /* IN : max. no. of chars. for help text */
1470 int *unit /* OUT: unit pointer */;
1471 int *null /* OUT: no. of null values in data
1472 will only be applied, if not -1 */;
1473
1474 {
1475 int status, chanl, bytelem, noelem, dblock, dindx;
1476 int dunit, snull;
1477
1478 char dtype[4];
1479
1480 struct FCB_STRUCT *fcbp;
1481
1482 struct FCT_STRUCT *fctpntr;
1483
1484
1485
1486
1487 if ( (imno < 0) || (imno >= FCT.MAXENT) )
1488 {
1489 status = ERR_INPINV;
1490 goto end_of_it;
1491 }
1492
1493 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
1494
1495 fctpntr = FCT.ENTRIES + imno;
1496 if (unlikely(fctpntr->LINK[0] >= 2)) /* if son, use father's imno */
1497 { /* all except NAXIS, NPIX => father */
1498 if (strcmp(realdescr,"NAXIS") == 0)
1499 goto next_step;
1500 else if (strcmp(realdescr,"NPIX") == 0)
1501 goto next_step;
1502
1503 imno = fctpntr->LINK[1];
1504 fctpntr = FCT.ENTRIES + imno;
1505 }
1506
1507 next_step:
1508 chanl = fctpntr->IOCHAN;
1509 fcbp = fctpntr->FZP;
1510
1511
1512 /* find descriptor in directory */
1513
1514 htxt[0] = '\0';
1515 dtype[0] = 'I';
1516 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
1517 &noelem,&dunit,&dblock,&dindx,htxt);
1518 if (status != ERR_NORMAL) goto end_of_it;
1519
1520
1521 /* check parameters */
1522
1523 if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) )
1524 {
1525 status = ERR_INPINV; /* invalid input parameters */
1526 goto end_of_it;
1527 }
1528
1529
1530 /* minimize no. of data */
1531
1532 *actvals = noelem - felem + 1; /* max. no. of values */
1533 if (*actvals > maxvals) *actvals = maxvals;
1534
1535
1536 /* now go + get the data */
1537
1538 snull = -1;
1539 (void) MID_RDSCRI(chanl,dblock,dindx,felem,*actvals,values,&snull);
1540 *null = snull;
1541 *unit = dunit;
1542 return status;
1543
1544 end_of_it: /* here for errors */
1545 MID_E2(6,imno,descr,status,1);
1546 return status;
1547 }
1548 /*
1549
1550 */
1551
1552 int SCDHRR(imno,descr,felem,maxvals,actvals,values,htxt,hmax,unit,null)
1553
1554 /*++++++++++++++++++++++++++++++++++++++++++++++++++
1555 .PURPOSE
1556 read the contents of a real descriptor and its help text
1557 .ALGORITHM
1558 'actval' will be set to the actual no. of values returned
1559 .RETURNS
1560 return status ( 0 = o.k. )
1561 --------------------------------------------------*/
1562
1563 int imno /* IN : no. of data frame */;
1564 char *descr /* IN : descriptor name */;
1565 int felem /* IN : position of 1st element to be accessed */;
1566 int maxvals /* IN : max. no. of values to be returned */;
1567 int *actvals /* OUT: actual no. of values returned */;
1568 float *values /* OUT: array of type real */;
1569 char *htxt; /* OUT: help text */
1570 int hmax; /* IN : max. no. of chars. for help text */
1571 int *unit /* OUT: unit pointer */;
1572 int *null /* OUT: no. of null values in data
1573 will only be applied, if not -1 */;
1574
1575 {
1576 int n, actv;
1577 int status, chanl, bytelem, noelem, dblock, dindx;
1578 int dunit, snull, first;
1579
1580 char dtype[4];
1581
1582 struct FCB_STRUCT *fcbp;
1583
1584 struct FCT_STRUCT *fctpntr;
1585
1586
1587
1588
1589 if ( (imno < 0) || (imno >= FCT.MAXENT) ) /* check imno */
1590 {
1591 status = ERR_INPINV;
1592 goto end_of_it;
1593 }
1594
1595 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
1596
1597 fctpntr = FCT.ENTRIES + imno;
1598 if (unlikely(fctpntr->LINK[0] >= 2)) /* if son, use father's imno */
1599 {
1600 imno = fctpntr->LINK[1];
1601 fctpntr = FCT.ENTRIES + imno;
1602 }
1603
1604 chanl = fctpntr->IOCHAN;
1605 fcbp = fctpntr->FZP;
1606
1607
1608 /* find descriptor in directory */
1609
1610 htxt[0] = '\0';
1611 dtype[0] = 'R';
1612 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
1613 &noelem,&dunit,&dblock,&dindx,htxt);
1614
1615 if (status != ERR_NORMAL)
1616 { /* see if double descr instead */
1617 dtype[0] = 'D';
1618 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
1619 &noelem,&dunit,&dblock,&dindx,htxt);
1620 }
1621 if (status != ERR_NORMAL) goto end_of_it;
1622
1623
1624 /* check parameters */
1625
1626 if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) )
1627 {
1628 status = ERR_INPINV; /* invalid input parameters */
1629 goto end_of_it;
1630 }
1631
1632
1633 /* minimize no. of data */
1634
1635 actv = noelem - felem + 1; /* max. no. of values */
1636 if (actv > maxvals) actv = maxvals;
1637 *actvals = actv;
1638
1639
1640 /* now go + get the data - type D is handled via integer descriptors... */
1641
1642 snull = -1;
1643 if (dtype[0] == 'D')
1644 {
1645 int *ipntr;
1646 double *dvals;
1647 char *mypntr;
1648
1649 n = (int)sizeof(double) * actv;
1650 mypntr = malloc((size_t) n); /* allocate space for */
1651 if (mypntr == (char *) 0) /* for double temp data */
1652 {
1653 status = ERR_MEMOUT;
1654 goto end_of_it;
1655 }
1656 dvals = (double *)mypntr;
1657
1658 n = DD_SIZE / II_SIZE; /* double stuff is stored */
1659 first = n*felem - 1; /* integer data */
1660 actv *= n;
1661 ipntr = (int *)mypntr;
1662 (void) MID_RDSCRI(chanl,dblock,dindx,first,actv,ipntr,&snull);
1663
1664 for (n=0; n<actv; n++) values[n] = (float) *dvals++;
1665 (void) free (mypntr);
1666 }
1667 else
1668 (void) MID_RDSCRR(chanl,dblock,dindx,felem,actv,values,&snull);
1669
1670 *null = snull;
1671 *unit = dunit;
1672 return status;
1673
1674 end_of_it: /* here for errors */
1675 MID_E2(6,imno,descr,status,1);
1676 return status;
1677 }
1678