1 /* sgmeta.f -- translated by f2c (version 19980913).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include "f2c.h"
7
8 /* Table of constant values */
9
10 static integer c__1 = 1;
11 static integer c__2 = 2;
12 static integer c__15 = 15;
13
14 /* $Procedure SGMETA ( Generic segments: Fetch meta data value ) */
sgmeta_(integer * handle,doublereal * descr,integer * mnemon,integer * value)15 /* Subroutine */ int sgmeta_(integer *handle, doublereal *descr, integer *
16 mnemon, integer *value)
17 {
18 /* Initialized data */
19
20 static integer lstbeg = -1;
21 static integer lsthan = 0;
22
23 /* System generated locals */
24 integer i__1, i__2, i__3;
25 static doublereal equiv_0[2];
26
27 /* Builtin functions */
28 integer s_rnge(char *, integer, char *, integer), i_dnnt(doublereal *);
29
30 /* Local variables */
31 static integer meta[17];
32 integer begm1, i__, begin;
33 extern /* Subroutine */ int chkin_(char *, ftnlen);
34 #define dtemp (equiv_0)
35 extern /* Subroutine */ int moved_(doublereal *, integer *, doublereal *);
36 doublereal xmeta[17];
37 #define itemp ((integer *)equiv_0)
38 extern /* Subroutine */ int dafgda_(integer *, integer *, integer *,
39 doublereal *);
40 integer niovr2, nd;
41 extern logical failed_(void);
42 integer ni;
43 extern /* Subroutine */ int dafhsf_(integer *, integer *, integer *);
44 integer begmta, endmta, ametas;
45 static logical nieven;
46 static integer ioffst;
47 extern /* Subroutine */ int sigerr_(char *, ftnlen), chkout_(char *,
48 ftnlen);
49 doublereal dmtasz;
50 static integer metasz;
51 extern /* Subroutine */ int setmsg_(char *, ftnlen), errint_(char *,
52 integer *, ftnlen);
53 extern logical return_(void);
54 integer end;
55
56 /* $ Abstract */
57
58 /* Obtain the value of a specified generic segment meta data item. */
59
60 /* $ Disclaimer */
61
62 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
63 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
64 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
65 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
66 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
67 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
68 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
69 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
70 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
71 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
72
73 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
74 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
75 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
76 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
77 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
78 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
79
80 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
81 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
82 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
83 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
84
85 /* $ Required_Reading */
86
87 /* DAF Required Reading */
88
89 /* $ Keywords */
90
91 /* GENERIC SEGMENTS */
92
93 /* $ Declarations */
94 /* $ Brief_I/O */
95
96 /* VARIABLE I/O DESCRIPTION */
97 /* -------- --- -------------------------------------------------- */
98 /* HANDLE I Handle of a DAF open for reading. */
99 /* DESCR I Descriptor for a generic segment in the DAF. */
100 /* MNEMON I An integer mnemonic for the desired meta data. */
101 /* VALUE O The value of the meta data item requested. */
102
103 /* $ Detailed_Input */
104
105 /* HANDLE is the handle of a DAF opened for reading that */
106 /* contains the generic segment described by DESCR. */
107
108 /* DESCR is the descriptor of a generic segment. This must */
109 /* be the descriptor for a generic segment in the DAF */
110 /* associated with HANDLE. */
111
112 /* MNEMON is the mnemonic used to represent the desired piece of */
113 /* meta data. See the file 'sgparam.inc' for details, the */
114 /* mnemonics, and their values. */
115
116 /* $ Detailed_Output */
117
118 /* VALUE is the value of the meta data item associated with */
119 /* the mnemonic MNEMON that is in the generic segment */
120 /* specified by HANDLE and DESCR. */
121
122 /* $ Parameters */
123
124 /* This subroutine makes use of parameters defined in the file */
125 /* 'sgparam.inc'. */
126
127 /* $ Files */
128
129 /* See the description of HANDLE above. */
130
131 /* $ Exceptions */
132
133 /* 1) If the mnemonic for the meta data item is not valid, the error */
134 /* SPICE(UNKNOWNMETAITEM) will be signalled. */
135
136 /* 2) If the last address in the DAF segment that reports the number */
137 /* of meta data items that exist in the segment is less than */
138 /* MNMETA, the error SPICE(INVALIDMETADATA) will be signaled. */
139
140 /* $ Particulars */
141
142 /* This routine is a utility for fetching the meta data associated */
143 /* with a DAF generic segment. */
144
145 /* A DAF generic segment contains several logical data partitions: */
146
147 /* 1) A partition for constant values to be associated with each */
148 /* data packet in the segment. */
149
150 /* 2) A partition for the data packets. */
151
152 /* 3) A partition for reference values. */
153
154 /* 4) A partition for a packet directory, if the segment contains */
155 /* variable sized packets. */
156
157 /* 5) A partition for a reference value directory. */
158
159 /* 6) A reserved partition that is not currently used. This */
160 /* partition is only for the use of the NAIF group at the Jet */
161 /* Propulsion Laboratory (JPL). */
162
163 /* 7) A partition for the meta data which describes the locations */
164 /* and sizes of other partitions as well as providing some */
165 /* additional descriptive information about the generic */
166 /* segment. */
167
168 /* +============================+ */
169 /* | Constants | */
170 /* +============================+ */
171 /* | Packet 1 | */
172 /* |----------------------------| */
173 /* | Packet 2 | */
174 /* |----------------------------| */
175 /* | . | */
176 /* | . | */
177 /* | . | */
178 /* |----------------------------| */
179 /* | Packet N | */
180 /* +============================+ */
181 /* | Reference Values | */
182 /* +============================+ */
183 /* | Packet Directory | */
184 /* +============================+ */
185 /* | Reference Directory | */
186 /* +============================+ */
187 /* | Reserved Area | */
188 /* +============================+ */
189 /* | Segment Meta Data | */
190 /* +----------------------------+ */
191
192 /* Only the placement of the meta data at the end of a segment is */
193 /* required. The other data partitions may occur in any order in the */
194 /* segment because the meta data will contain pointers to the */
195 /* appropriate locations of the other data partitions within the */
196 /* segment. */
197
198 /* The meta data for the segment should be obtained only through */
199 /* use of this routine, SGMETA. */
200
201 /* $ Examples */
202
203 /* Suppose that we would like to know how many constants, data */
204 /* packets, and reference values are in the generic segment that we */
205 /* have located in the DAF file associated with HANDLE. */
206
207 /* C */
208 /* C Get the number of constants. */
209 /* C */
210 /* CALL SGMETA ( HANDLE, DESCR, NCON, NCONST ) */
211 /* C */
212 /* C Get the number of data packets. */
213 /* C */
214 /* CALL SGMETA ( HANDLE, DESCR, NPKT, NPKTS ) */
215 /* C */
216 /* C Get the number of constants. */
217 /* C */
218 /* CALL SGMETA ( HANDLE, DESCR, NREF, NREFS ) */
219
220 /* C */
221 /* C Print the values. */
222 /* C */
223 /* WRITE (*, *) 'Number of Constants : ', NCONST */
224 /* WRITE (*, *) 'Number of Data Packets : ', NPKTS */
225 /* WRITE (*, *) 'Number of Reference Values: ', NREFS */
226
227 /* $ Restrictions */
228
229 /* The segment described by DESCR MUST be a generic segment, */
230 /* otherwise the results of this routine are not predictable. */
231
232 /* $ Author_and_Institution */
233
234 /* K.R. Gehringer (JPL) */
235 /* W.L. Taber (JPL) */
236 /* F.S. Turner (JPL) */
237
238 /* $ Literature_References */
239
240 /* None. */
241
242 /* $ Version */
243
244 /* - SPICELIB Version 1.4.0, 07-SEP-2001 (EDW) */
245
246 /* Replaced DAFRDA call with DAFGDA. */
247
248 /* - SPICELIB Version 1.3.0, 14-JUN-1999 (FST) */
249
250 /* Altered the check in/out structure to be more reasonable. */
251 /* This introduced redundant code, but only to increase the */
252 /* efficiency of the normal mode of operation. */
253
254 /* - SPICELIB Version 1.2.0, 24-SEP-1998 (FST) */
255
256 /* Modified the code that handles reading the meta data from the */
257 /* DAF to handle the case when the number of meta data items in */
258 /* the file exceeds the current maximum defined in sgparam.inc. */
259 /* In the event that this situation occurs, the routine loads */
260 /* what meta data it can interpret and ignores the rest. In */
261 /* this event if NMETA is requested, it is returned as MXMETA in */
262 /* sgparam.inc. */
263
264 /* An additional exception is now trapped by the routine. If */
265 /* a generic segment in a DAF reports less than the known minimum */
266 /* number of meta data items, then the routine signals the */
267 /* error SPICE(INVALIDMETADATA). */
268
269 /* The conditions that cause the SPICE(UNKNOWNMETAITEM) to be */
270 /* signaled have been altered. Now if the integer mnemonic */
271 /* is not between 1 and METASZ inclusive, or NMETA the error */
272 /* is signaled. In the versions preceding this change, for */
273 /* segments that reported less than NMETA items of meta data */
274 /* could not use this routine to request the number of meta */
275 /* data items without signalling SPICE(UNKNOWNMETAITEM). */
276
277 /* - SPICELIB Version 1.1.0, 11-APR-1995 (KRG) */
278
279 /* Modified the code that deals with the EQUIVALENCEd part */
280 /* descriptor. We now call MOVED rather than using a direct */
281 /* assignment. */
282
283 /* - SPICELIB Version 1.0.0, 11-APR-1995 (KRG) (WLT) */
284
285 /* -& */
286 /* $ Index_Entries */
287
288 /* retrieve a meta data value for a generic segment */
289
290 /* -& */
291
292 /* Spicelib Functions */
293
294
295 /* Local Parameters */
296
297 /* Include the mnemonic values for the generic segment declarations. */
298
299
300 /* Local Variables */
301
302
303 /* $ Abstract */
304
305 /* Parameter declarations for the generic segments subroutines. */
306
307 /* $ Disclaimer */
308
309 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
310 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
311 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
312 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
313 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
314 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
315 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
316 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
317 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
318 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
319
320 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
321 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
322 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
323 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
324 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
325 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
326
327 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
328 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
329 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
330 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
331
332 /* $ Required_Reading */
333
334 /* DAF Required Reading */
335
336 /* $ Keywords */
337
338 /* GENERIC SEGMENTS */
339
340 /* $ Particulars */
341
342 /* This include file contains the parameters used by the generic */
343 /* segments subroutines, SGxxxx. A generic segment is a */
344 /* generalization of a DAF array which places a particular structure */
345 /* on the data contained in the array, as described below. */
346
347 /* This file defines the mnemonics that are used for the index types */
348 /* allowed in generic segments as well as mnemonics for the meta data */
349 /* items which are used to describe a generic segment. */
350
351 /* A DAF generic segment contains several logical data partitions: */
352
353 /* 1) A partition for constant values to be associated with each */
354 /* data packet in the segment. */
355
356 /* 2) A partition for the data packets. */
357
358 /* 3) A partition for reference values. */
359
360 /* 4) A partition for a packet directory, if the segment contains */
361 /* variable sized packets. */
362
363 /* 5) A partition for a reference value directory. */
364
365 /* 6) A reserved partition that is not currently used. This */
366 /* partition is only for the use of the NAIF group at the Jet */
367 /* Propulsion Laboratory (JPL). */
368
369 /* 7) A partition for the meta data which describes the locations */
370 /* and sizes of other partitions as well as providing some */
371 /* additional descriptive information about the generic */
372 /* segment. */
373
374 /* +============================+ */
375 /* | Constants | */
376 /* +============================+ */
377 /* | Packet 1 | */
378 /* |----------------------------| */
379 /* | Packet 2 | */
380 /* |----------------------------| */
381 /* | . | */
382 /* | . | */
383 /* | . | */
384 /* |----------------------------| */
385 /* | Packet N | */
386 /* +============================+ */
387 /* | Reference Values | */
388 /* +============================+ */
389 /* | Packet Directory | */
390 /* +============================+ */
391 /* | Reference Directory | */
392 /* +============================+ */
393 /* | Reserved Area | */
394 /* +============================+ */
395 /* | Segment Meta Data | */
396 /* +----------------------------+ */
397
398 /* Only the placement of the meta data at the end of a generic */
399 /* segment is required. The other data partitions may occur in any */
400 /* order in the generic segment because the meta data will contain */
401 /* pointers to their appropriate locations within the generic */
402 /* segment. */
403
404 /* The meta data for a generic segment should only be obtained */
405 /* through use of the subroutine SGMETA. The meta data should not be */
406 /* written through any mechanism other than the ending of a generic */
407 /* segment begun by SGBWFS or SGBWVS using SGWES. */
408
409 /* $ Restrictions */
410
411 /* 1) If new reference index types are added, the new type(s) should */
412 /* be defined to be the consecutive integer(s) after the last */
413 /* defined reference index type used. In this way a value for */
414 /* the maximum allowed index type may be maintained. This value */
415 /* must also be updated if new reference index types are added. */
416
417 /* 2) If new meta data items are needed, mnemonics for them must be */
418 /* added to the end of the current list of mnemonics and before */
419 /* the NMETA mnemonic. In this way compatibility with files having */
420 /* a different, but smaller, number of meta data items may be */
421 /* maintained. See the description and example below. */
422
423 /* $ Author_and_Institution */
424
425 /* N.J. Bachman (JPL) */
426 /* K.R. Gehringer (JPL) */
427 /* W.L. Taber (JPL) */
428 /* F.S. Turner (JPL) */
429
430 /* $ Literature_References */
431
432 /* Generic Segments Required Reading. */
433 /* DAF Required Reading. */
434
435 /* $ Version */
436
437 /* - SPICELIB Version 1.1.1, 28-JAN-2004 (NJB) */
438
439 /* Header update: equations for comptutations of packet indices */
440 /* for the cases of index types 0 and 1 were corrected. */
441
442 /* - SPICELIB Version 1.1.0, 25-09-98 (FST) */
443
444 /* Added parameter MNMETA, the minimum number of meta data items */
445 /* that must be present in a generic DAF segment. */
446
447 /* - SPICELIB Version 1.0.0, 04-03-95 (KRG) (WLT) */
448
449 /* -& */
450
451 /* Mnemonics for the type of reference value index. */
452
453 /* Two forms of indexing are provided: */
454
455 /* 1) An implicit form of indexing based on using two values, a */
456 /* starting value, which will have an index of 1, and a step */
457 /* size between reference values, which are used to compute an */
458 /* index and a reference value associated with a specified key */
459 /* value. See the descriptions of the implicit types below for */
460 /* the particular formula used in each case. */
461
462 /* 2) An explicit form of indexing based on a reference value for */
463 /* each data packet. */
464
465
466 /* Reference Index Type 0 */
467 /* ---------------------- */
468
469 /* Implied index. The index and reference value of a data packet */
470 /* associated with a specified key value are computed from the two */
471 /* generic segment reference values using the formula below. The two */
472 /* generic segment reference values, REF(1) and REF(2), represent, */
473 /* respectively, a starting value and a step size between reference */
474 /* values. The index of the data packet associated with a key value */
475 /* of VALUE is given by: */
476
477 /* / VALUE - REF(1) \ */
478 /* INDEX = 1 + INT | -------------------- | */
479 /* \ REF(2) / */
480
481 /* and the reference value associated with VALUE is given by: */
482
483 /* REFVAL = REF(1) + DBLE (INDEX-1) * REF(2) */
484
485
486 /* Reference Index Type 1 */
487 /* ---------------------- */
488
489 /* Implied index. The index and reference value of a data packet */
490 /* associated with a specified key value are computed from the two */
491 /* generic segment reference values using the formula below. The two */
492 /* generic segment reference values, REF(1) and REF(2), represent, */
493 /* respectively, a starting value and a step size between reference */
494 /* values. The index of the data packet associated with a key value */
495 /* of VALUE is given by: */
496
497 /* / VALUE - REF(1) \ */
498 /* INDEX = 1 + INT | 0.5 + -------------------- | */
499 /* \ REF(2) / */
500
501
502 /* and the reference value associated with VALUE is given by: */
503
504 /* REFVAL = REF(1) + DBLE (INDEX-1) * REF(2) */
505
506 /* We get the larger index in the event that VALUE is halfway between */
507 /* X(I) and X(I+1), where X(I) = BUFFER(1) + DBLE (I-1) * REFDAT(2). */
508
509
510 /* Reference Index Type 2 */
511 /* ---------------------- */
512
513 /* Explicit index. In this case the number of packets must equal the */
514 /* number of reference values. The index of the packet associated */
515 /* with a key value of VALUE is the index of the last reference item */
516 /* that is strictly less than VALUE. The reference values must be in */
517 /* ascending order, REF(I) < REF(I+1). */
518
519
520 /* Reference Index Type 3 */
521 /* ---------------------- */
522
523 /* Explicit index. In this case the number of packets must equal the */
524 /* number of reference values. The index of the packet associated */
525 /* with a key value of VALUE is the index of the last reference item */
526 /* that is less than or equal to VALUE. The reference values must be */
527 /* in ascending order, REF(I) < REF(I+1). */
528
529
530 /* Reference Index Type 4 */
531 /* ---------------------- */
532
533 /* Explicit index. In this case the number of packets must equal the */
534 /* number of reference values. The index of the packet associated */
535 /* with a key value of VALUE is the index of the reference item */
536 /* that is closest to the value of VALUE. In the event of a "tie" */
537 /* the larger index is selected. The reference values must be in */
538 /* ascending order, REF(I) < REF(I+1). */
539
540
541 /* These parameters define the valid range for the index types. An */
542 /* index type code, MYTYPE, for a generic segment must satisfy the */
543 /* relation MNIDXT <= MYTYPE <= MXIDXT. */
544
545
546 /* The following meta data items will appear in all generic segments. */
547 /* Other meta data items may be added if a need arises. */
548
549 /* 1) CONBAS Base Address of the constants in a generic segment. */
550
551 /* 2) NCON Number of constants in a generic segment. */
552
553 /* 3) RDRBAS Base Address of the reference directory for a */
554 /* generic segment. */
555
556 /* 4) NRDR Number of items in the reference directory of a */
557 /* generic segment. */
558
559 /* 5) RDRTYP Type of the reference directory 0, 1, 2 ... for a */
560 /* generic segment. */
561
562 /* 6) REFBAS Base Address of the reference items for a generic */
563 /* segment. */
564
565 /* 7) NREF Number of reference items in a generic segment. */
566
567 /* 8) PDRBAS Base Address of the Packet Directory for a generic */
568 /* segment. */
569
570 /* 9) NPDR Number of items in the Packet Directory of a generic */
571 /* segment. */
572
573 /* 10) PDRTYP Type of the packet directory 0, 1, ... for a generic */
574 /* segment. */
575
576 /* 11) PKTBAS Base Address of the Packets for a generic segment. */
577
578 /* 12) NPKT Number of Packets in a generic segment. */
579
580 /* 13) RSVBAS Base Address of the Reserved Area in a generic */
581 /* segment. */
582
583 /* 14) NRSV Number of items in the reserved area of a generic */
584 /* segment. */
585
586 /* 15) PKTSZ Size of the packets for a segment with fixed width */
587 /* data packets or the size of the largest packet for a */
588 /* segment with variable width data packets. */
589
590 /* 16) PKTOFF Offset of the packet data from the start of a packet */
591 /* record. Each data packet is placed into a packet */
592 /* record which may have some bookkeeping information */
593 /* prepended to the data for use by the generic */
594 /* segments software. */
595
596 /* 17) NMETA Number of meta data items in a generic segment. */
597
598 /* Meta Data Item 1 */
599 /* ----------------- */
600
601
602 /* Meta Data Item 2 */
603 /* ----------------- */
604
605
606 /* Meta Data Item 3 */
607 /* ----------------- */
608
609
610 /* Meta Data Item 4 */
611 /* ----------------- */
612
613
614 /* Meta Data Item 5 */
615 /* ----------------- */
616
617
618 /* Meta Data Item 6 */
619 /* ----------------- */
620
621
622 /* Meta Data Item 7 */
623 /* ----------------- */
624
625
626 /* Meta Data Item 8 */
627 /* ----------------- */
628
629
630 /* Meta Data Item 9 */
631 /* ----------------- */
632
633
634 /* Meta Data Item 10 */
635 /* ----------------- */
636
637
638 /* Meta Data Item 11 */
639 /* ----------------- */
640
641
642 /* Meta Data Item 12 */
643 /* ----------------- */
644
645
646 /* Meta Data Item 13 */
647 /* ----------------- */
648
649
650 /* Meta Data Item 14 */
651 /* ----------------- */
652
653
654 /* Meta Data Item 15 */
655 /* ----------------- */
656
657
658 /* Meta Data Item 16 */
659 /* ----------------- */
660
661
662 /* If new meta data items are to be added to this list, they should */
663 /* be added above this comment block as described below. */
664
665 /* INTEGER NEW1 */
666 /* PARAMETER ( NEW1 = PKTOFF + 1 ) */
667
668 /* INTEGER NEW2 */
669 /* PARAMETER ( NEW2 = NEW1 + 1 ) */
670
671 /* INTEGER NEWEST */
672 /* PARAMETER ( NEWEST = NEW2 + 1 ) */
673
674 /* and then the value of NMETA must be changed as well to be: */
675
676 /* INTEGER NMETA */
677 /* PARAMETER ( NMETA = NEWEST + 1 ) */
678
679 /* Meta Data Item 17 */
680 /* ----------------- */
681
682
683 /* Maximum number of meta data items. This is always set equal to */
684 /* NMETA. */
685
686
687 /* Minimum number of meta data items that must be present in a DAF */
688 /* generic segment. This number is to remain fixed even if more */
689 /* meta data items are added for compatibility with old DAF files. */
690
691
692 /* Standard SPICE error handling. */
693
694 if (return_()) {
695 return 0;
696 }
697
698 /* Handle the case when we are looking at the same file and segment */
699 /* descriptor first. This will result in duplicated code, but will */
700 /* increase efficiency for the usual execution case. We need not */
701 /* worry about the first time through, since LSTHAN and LSTBEG are */
702 /* set to values that are bogus for actual DAF files. */
703
704 if (*handle == lsthan) {
705
706 /* Get the begin and end values from the descriptor. They are */
707 /* located in the last two "integer" positions of the descriptor. */
708
709 if (nieven) {
710 moved_(&descr[ioffst - 1], &c__1, dtemp);
711 begin = itemp[0];
712 end = itemp[1];
713 } else {
714 moved_(&descr[ioffst - 1], &c__2, dtemp);
715 begin = itemp[1];
716 end = itemp[2];
717 }
718
719 /* Check the segment start address. This will tell us whether we */
720 /* are looking at the same segment. */
721
722 if (lstbeg == begin) {
723
724 /* The only acceptable integer mnemonics at this point are 1 */
725 /* through METASZ inclusive, and NMETA. All other requests */
726 /* should signal the SPICE(UNKNOWNMETAITEM) error, since the */
727 /* current segment has no knowledge of these values. */
728
729 if (*mnemon <= 0 || *mnemon > metasz && *mnemon != 17) {
730 chkin_("SGMETA", (ftnlen)6);
731 *value = -1;
732 setmsg_("The item requested, #, is not one of the recognized"
733 " meta data items associated with this generic segmen"
734 "t.", (ftnlen)105);
735 errint_("#", mnemon, (ftnlen)1);
736 sigerr_("SPICE(UNKNOWNMETAITEM)", (ftnlen)22);
737 chkout_("SGMETA", (ftnlen)6);
738 return 0;
739 }
740
741 /* Set the value for the desired meta data item and return. */
742
743 *value = meta[(i__1 = *mnemon - 1) < 17 && 0 <= i__1 ? i__1 :
744 s_rnge("meta", i__1, "sgmeta_", (ftnlen)364)];
745 return 0;
746 }
747 }
748
749 /* At this point we are going to have to load the meta data. If */
750 /* the new handle and the old handle are the same, then the above */
751 /* code has already retrieved the relevant segment addresses. If not */
752 /* we need to fetch them. First check in. */
753
754 chkin_("SGMETA", (ftnlen)6);
755 if (*handle != lsthan) {
756 dafhsf_(handle, &nd, &ni);
757 if (failed_()) {
758 chkout_("SGMETA", (ftnlen)6);
759 return 0;
760 }
761 niovr2 = ni / 2;
762 nieven = niovr2 << 1 == ni;
763 ioffst = nd + niovr2;
764 lsthan = *handle;
765
766 /* Get the begin and end values from the descriptor. They are */
767 /* located in the last two "integer" positions of the descriptor. */
768
769 if (nieven) {
770 moved_(&descr[ioffst - 1], &c__1, dtemp);
771 begin = itemp[0];
772 end = itemp[1];
773 } else {
774 moved_(&descr[ioffst - 1], &c__2, dtemp);
775 begin = itemp[1];
776 end = itemp[2];
777 }
778 }
779
780 /* Save the new begin address. Remember we have either just computed */
781 /* this from the IF block above, or we computed it in the very */
782 /* first IF block. */
783
784 lstbeg = begin;
785
786 /* Compute the begin address of the meta data and compute the */
787 /* end address of the number we will be collecting. */
788
789 dafgda_(handle, &end, &end, &dmtasz);
790 if (failed_()) {
791 chkout_("SGMETA", (ftnlen)6);
792 return 0;
793 }
794 metasz = i_dnnt(&dmtasz);
795
796 /* Store the actual meta size in AMETAS, in case METASZ ends up */
797 /* being modified to conform to our current understanding of */
798 /* meta data items. */
799
800 ametas = metasz;
801
802 /* Check to see if METASZ is an unacceptable value. */
803
804 if (metasz < 15) {
805 *value = -1;
806 setmsg_("This segment reports that it has # meta data items. Every g"
807 "eneric segment must have at least #.", (ftnlen)95);
808 errint_("#", &metasz, (ftnlen)1);
809 errint_("#", &c__15, (ftnlen)1);
810 sigerr_("SPICE(INVALIDMETADATA)", (ftnlen)22);
811 chkout_("SGMETA", (ftnlen)6);
812 return 0;
813
814 /* If it is not, we may need to fix a few things to work around some */
815 /* older files that have been delivered. We perform these kludges */
816 /* here. Originally, the number of meta data items was not */
817 /* considered to be part of the meta data. It now is, so if we */
818 /* encounter an older version of the file, we need to increment the */
819 /* meta data size by 1. The number of meta data items is always */
820 /* after all of the meta data items, so we can do this. */
821
822 } else if (metasz == 15) {
823 ++metasz;
824 ametas = metasz;
825
826 /* If not check to see if METASZ is greater than the known MXMETA. */
827 /* If it is then this segment most likely was constructed from */
828 /* some newer version of the toolkit. Load what meta data we */
829 /* currently know about as laid out in sgparam.inc. */
830
831 } else if (metasz > 17) {
832
833 /* Leave AMETAS alone, since we need to know how far back */
834 /* into the DAF file to begin reading. */
835
836 metasz = 17;
837 }
838
839 /* The address computations that follow are precisely the same */
840 /* as the previous version of the file, except when AMETAS is not */
841 /* METASZ. This only happens when METASZ is greater than MXMETA. */
842
843 begmta = end - ametas + 1;
844 endmta = begmta + metasz - 1;
845 dafgda_(handle, &begmta, &endmta, xmeta);
846 if (failed_()) {
847 chkout_("SGMETA", (ftnlen)6);
848 return 0;
849 }
850
851 /* Convert all of the meta data values into integers. */
852
853 i__1 = metasz;
854 for (i__ = 1; i__ <= i__1; ++i__) {
855 meta[(i__2 = i__ - 1) < 17 && 0 <= i__2 ? i__2 : s_rnge("meta", i__2,
856 "sgmeta_", (ftnlen)503)] = i_dnnt(&xmeta[(i__3 = i__ - 1) <
857 17 && 0 <= i__3 ? i__3 : s_rnge("xmeta", i__3, "sgmeta_", (
858 ftnlen)503)]);
859 }
860
861 /* The kludge continues... NMETA and MXMETA are ALWAYS the same */
862 /* value, and any missing values must appear between the last known */
863 /* value, META(METASZ-1), and the end value, META(NMETA), so we zero */
864 /* them out. */
865
866 meta[16] = metasz;
867 for (i__ = metasz; i__ <= 16; ++i__) {
868 meta[(i__1 = i__ - 1) < 17 && 0 <= i__1 ? i__1 : s_rnge("meta", i__1,
869 "sgmeta_", (ftnlen)515)] = 0;
870 }
871
872 /* Adjust the bases so that the N'th item of a partition is at */
873 /* address META(PARTITION_BASE) + N */
874
875 begm1 = begin - 1;
876 meta[0] += begm1;
877 meta[5] += begm1;
878 meta[2] += begm1;
879 meta[7] += begm1;
880 meta[10] += begm1;
881 meta[12] += begm1;
882
883 /* The only acceptable integer mnemonics at this point are 1 through */
884 /* METASZ inclusive, and NMETA. All other requests should signal */
885 /* the SPICE(UNKNOWNMETAITEM) error, since the current segment has */
886 /* no knowledge of these values. */
887
888 if (*mnemon <= 0 || *mnemon > metasz && *mnemon != 17) {
889 *value = -1;
890 setmsg_("The item requested, #, is not one of the recognized meta da"
891 "ta items associated with this generic segment.", (ftnlen)105);
892 errint_("#", mnemon, (ftnlen)1);
893 sigerr_("SPICE(UNKNOWNMETAITEM)", (ftnlen)22);
894 chkout_("SGMETA", (ftnlen)6);
895 return 0;
896 }
897
898 /* Set the value for the desired meta data item, check out if we */
899 /* need to, and return. */
900
901 *value = meta[(i__1 = *mnemon - 1) < 17 && 0 <= i__1 ? i__1 : s_rnge(
902 "meta", i__1, "sgmeta_", (ftnlen)555)];
903 chkout_("SGMETA", (ftnlen)6);
904 return 0;
905 } /* sgmeta_ */
906
907 #undef itemp
908 #undef dtemp
909
910
911