1 /* cknm06.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__2 = 2;
11 static integer c__6 = 6;
12 
13 /* $Procedure CKNM06 ( C-kernel, number of mini-segments, type 06 ) */
cknm06_(integer * handle,doublereal * descr,integer * nmini)14 /* Subroutine */ int cknm06_(integer *handle, doublereal *descr, integer *
15 	nmini)
16 {
17     /* Builtin functions */
18     integer i_dnnt(doublereal *);
19 
20     /* Local variables */
21     extern /* Subroutine */ int chkin_(char *, ftnlen), dafus_(doublereal *,
22 	    integer *, integer *, doublereal *, integer *), dafgda_(integer *,
23 	     integer *, integer *, doublereal *);
24     doublereal dc[2];
25     integer ic[6];
26     extern logical failed_(void);
27     doublereal dpdata[1];
28     extern /* Subroutine */ int sigerr_(char *, ftnlen), chkout_(char *,
29 	    ftnlen), setmsg_(char *, ftnlen), errint_(char *, integer *,
30 	    ftnlen);
31     extern logical return_(void);
32 
33 /* $ Abstract */
34 
35 /*     Given the handle of a CK file and the descriptor of a type 6 */
36 /*     segment in that file, return the number of mini-segments */
37 /*     in the segment. */
38 
39 /* $ Disclaimer */
40 
41 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
42 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
43 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
44 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
45 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
46 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
47 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
48 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
49 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
50 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
51 
52 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
53 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
54 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
55 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
56 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
57 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
58 
59 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
60 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
61 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
62 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
63 
64 /* $ Required_Reading */
65 
66 /*     CK */
67 /*     DAF */
68 
69 /* $ Keywords */
70 
71 /*     POINTING */
72 
73 /* $ Declarations */
74 /* $ Brief_I/O */
75 
76 /*     Variable  I/O  Description */
77 /*     --------  ---  -------------------------------------------------- */
78 /*     HANDLE     I   The handle of the file containing the segment. */
79 /*     DESCR      I   The descriptor of the type 6 segment. */
80 /*     NMINI      O   The number of pointing instances in the segment. */
81 
82 /* $ Detailed_Input */
83 
84 /*     HANDLE     is the handle of the binary CK file containing the */
85 /*                segment. Normally the CK file should be open for */
86 /*                read access. See the Files section below for details. */
87 
88 /*     DESCR      The DAF descriptor of a CK data type 6 segment. */
89 
90 /* $ Detailed_Output */
91 
92 /*     NMINI      The number of mini-segments in the CK segment */
93 /*                identified by HANDLE and DESCR. */
94 
95 /* $ Parameters */
96 
97 /*     None. */
98 
99 /* $ Exceptions */
100 
101 /*     1)  If the segment indicated by DESCR is not a type 6 segment, */
102 /*         the error 'SPICE(CKWRONGDATATYPE)' is signaled. */
103 
104 /*     2)  If the specified handle does not belong to any DAF file that */
105 /*         is currently known to be open, an error is diagnosed by a */
106 /*         routine that this routine calls. */
107 
108 /*     3)  If DESCR is not a valid descriptor of a valid segment in the */
109 /*         CK file specified by HANDLE, the results of this routine are */
110 /*         unpredictable. */
111 
112 /* $ Files */
113 
114 /*     The CK file specified by HANDLE may be open for read or write */
115 /*     access. Normally, the file should have been opened for read */
116 /*     access. If the file is open for write access, the calling */
117 /*     application must ensure integrity of the CK segment being read. */
118 /*     If the structure of the segment is invalid---for example, if the */
119 /*     segment has been partially written---this routine will either */
120 /*     return invalid results, or it will cause a system-level runtime */
121 /*     error. */
122 
123 /* $ Particulars */
124 
125 /*     For a complete description of the internal structure of a type 6 */
126 /*     segment, see the CK required reading. */
127 
128 /*     This routine returns the number of discrete pointing instances */
129 /*     contained in the specified segment. It is normally used in */
130 /*     conjunction with CKMN06, which returns mini-segment parameters, */
131 /*     and with CKGR06, which returns a specified pointing instance */
132 /*     from a mini-segment. */
133 
134 /* $ Examples */
135 
136 /*     The numerical results shown for this example may differ across */
137 /*     platforms. The results depend on the SPICE kernels used as */
138 /*     input, the compiler and supporting libraries, and the machine */
139 /*     specific arithmetic implementation. */
140 
141 
142 /*     1) The following program dumps records from a CK file that */
143 /*        contains only type 6 segments. */
144 
145 
146 /*        Example code begins here. */
147 
148 
149 /*             PROGRAM GREX1 */
150 /*             IMPLICIT NONE */
151 /*       C */
152 /*       C     Dump all records from a CK that */
153 /*       C     contains only segments of type 6. */
154 /*       C */
155 
156 /*             INCLUDE 'ck06.inc' */
157 /*       C */
158 /*       C     Local parameters */
159 /*       C */
160 /*             INTEGER               ND */
161 /*             PARAMETER           ( ND     = 2 ) */
162 
163 /*             INTEGER               NI */
164 /*             PARAMETER           ( NI     = 6 ) */
165 
166 /*             INTEGER               DSCSIZ */
167 /*             PARAMETER           ( DSCSIZ = 5 ) */
168 
169 /*             INTEGER               FILSIZ */
170 /*             PARAMETER           ( FILSIZ = 255 ) */
171 
172 /*       C */
173 /*       C     RECSIZ is the size of the largest pointing */
174 /*       C     record, which corresponds to subtype 2. */
175 /*       C */
176 /*             INTEGER               RECSIZ */
177 /*             PARAMETER           ( RECSIZ = C06PS2 + 3 ) */
178 
179 /*       C */
180 /*       C     Local variables */
181 /*       C */
182 /*             CHARACTER*(FILSIZ)    CK */
183 
184 /*             DOUBLE PRECISION      DC     ( ND ) */
185 /*             DOUBLE PRECISION      DESCR  ( DSCSIZ ) */
186 /*             DOUBLE PRECISION      IVLBDS ( 2 ) */
187 /*             DOUBLE PRECISION      LSTEPC */
188 /*             DOUBLE PRECISION      RATE */
189 /*             DOUBLE PRECISION      RECORD ( RECSIZ ) */
190 
191 /*             INTEGER               DTYPE */
192 /*             INTEGER               HANDLE */
193 /*             INTEGER               IC     ( NI ) */
194 /*             INTEGER               RECNO */
195 /*             INTEGER               MSNO */
196 /*             INTEGER               NMINI */
197 /*             INTEGER               NREC */
198 /*             INTEGER               SEGNO */
199 /*             INTEGER               SUBTYP */
200 /*             INTEGER               WINSIZ */
201 
202 /*             LOGICAL               FOUND */
203 
204 
205 /*             CALL PROMPT ( 'Enter name of CK to dump > ', CK ) */
206 
207 /*             CALL DAFOPR ( CK, HANDLE ) */
208 /*       C */
209 /*       C     Dump data from each CK segment. */
210 /*       C */
211 /*             SEGNO = 0 */
212 
213 /*             CALL DAFBFS ( HANDLE ) */
214 /*             CALL DAFFNA ( FOUND  ) */
215 
216 /*             DO WHILE ( FOUND ) */
217 
218 /*                SEGNO = SEGNO + 1 */
219 
220 /*                WRITE (*,*) ' ' */
221 /*                WRITE (*,*) ' ' */
222 /*                WRITE (*,*) 'Segment number: ', SEGNO */
223 
224 /*       C */
225 /*       C        Fetch and unpack the descriptor of the */
226 /*       C        current segment; check the data type. */
227 /*       C */
228 /*                CALL DAFGS ( DESCR ) */
229 /*                CALL DAFUS ( DESCR, ND, NI, DC, IC ) */
230 
231 /*                DTYPE = IC(3) */
232 
233 /*                IF ( DTYPE .NE. 6 ) THEN */
234 
235 /*                   CALL SETMSG ( 'Data type must be 6 but was #.' ) */
236 /*                   CALL ERRINT ( '#',  DTYPE                      ) */
237 /*                   CALL SIGERR ( 'SPICE(NOTSUPPORTED)'            ) */
238 
239 /*                END IF */
240 /*       C */
241 /*       C        Get the mini-segment count for this */
242 /*       C        segment. */
243 /*       C */
244 /*                CALL CKNM06 ( HANDLE, DESCR, NMINI ) */
245 /*       C */
246 /*       C        Dump data from each mini-segment. */
247 /*       C */
248 /*                DO MSNO = 1, NMINI */
249 /*       C */
250 /*       C           Get the mini-segment's record count */
251 /*       C           and time bounds. */
252 /*       C */
253 /*                   CALL CKMP06 ( HANDLE, DESCR, MSNO,   RATE,  SUBTYP, */
254 /*            .                    WINSIZ, NREC,  IVLBDS, LSTEPC        ) */
255 
256 /*                   WRITE (*,*) ' ' */
257 /*                   WRITE (*,*) '   Mini-segment number: ', MSNO */
258 /*                   WRITE (*,*) '      Rate:           ',   RATE */
259 /*                   WRITE (*,*) '      Subtype:        ',   SUBTYP */
260 /*                   WRITE (*,*) '      Window size:    ',   WINSIZ */
261 /*                   WRITE (*,*) '      Interval start: ',   IVLBDS(1) */
262 /*                   WRITE (*,*) '      Interval stop:  ',   IVLBDS(2) */
263 /*                   WRITE (*,*) '      Last epoch:     ',   LSTEPC */
264 /*                   WRITE (*,*) ' ' */
265 
266 /*                   DO RECNO = 1, NREC */
267 
268 /*                      CALL CKGR06 ( HANDLE, DESCR, */
269 /*            .                       MSNO,   RECNO,  RECORD ) */
270 
271 /*                      WRITE (*,*) '      Record number: ', RECNO */
272 /*                      WRITE (*,*) '         SCLKDP:     ', RECORD(1) */
273 /*                      WRITE (*,*) '         Clock rate: ', RECORD(3) */
274 
275 /*                      IF ( SUBTYP .EQ. C06TP0 ) THEN */
276 
277 /*                         WRITE (*,*) '         Q(0): ', RECORD(4) */
278 /*                         WRITE (*,*) '         Q(1): ', RECORD(5) */
279 /*                         WRITE (*,*) '         Q(2): ', RECORD(6) */
280 /*                         WRITE (*,*) '         Q(3): ', RECORD(7) */
281 /*                         WRITE (*,*) '    d Q(0)/dt: ', RECORD(8) */
282 /*                         WRITE (*,*) '    d Q(1)/dt: ', RECORD(9) */
283 /*                         WRITE (*,*) '    d Q(2)/dt: ', RECORD(10) */
284 /*                         WRITE (*,*) '    d Q(3)/dt: ', RECORD(11) */
285 
286 /*                      ELSE IF ( SUBTYP .EQ. C06TP1 ) THEN */
287 
288 /*                         WRITE (*,*) '         Q(0): ', RECORD(4) */
289 /*                         WRITE (*,*) '         Q(1): ', RECORD(5) */
290 /*                         WRITE (*,*) '         Q(2): ', RECORD(6) */
291 /*                         WRITE (*,*) '         Q(3): ', RECORD(7) */
292 
293 /*                      ELSE IF ( SUBTYP .EQ. C06TP2 ) THEN */
294 
295 /*                         WRITE (*,*) '         Q(0): ', RECORD(4) */
296 /*                         WRITE (*,*) '         Q(1): ', RECORD(5) */
297 /*                         WRITE (*,*) '         Q(2): ', RECORD(6) */
298 /*                         WRITE (*,*) '         Q(3): ', RECORD(7) */
299 /*                         WRITE (*,*) '    d Q(0)/dt: ', RECORD(8) */
300 /*                         WRITE (*,*) '    d Q(1)/dt: ', RECORD(9) */
301 /*                         WRITE (*,*) '    d Q(2)/dt: ', RECORD(10) */
302 /*                         WRITE (*,*) '    d Q(3)/dt: ', RECORD(11) */
303 /*                         WRITE (*,*) '        AV(1): ', RECORD(12) */
304 /*                         WRITE (*,*) '        AV(2): ', RECORD(13) */
305 /*                         WRITE (*,*) '        AV(3): ', RECORD(14) */
306 /*                         WRITE (*,*) '   d AV(1)/dt: ', RECORD(15) */
307 /*                         WRITE (*,*) '   d AV(2)/dt: ', RECORD(16) */
308 /*                         WRITE (*,*) '   d AV(3)/dt: ', RECORD(17) */
309 
310 /*                      ELSE IF ( SUBTYP .EQ. C06TP3 ) THEN */
311 
312 /*                         WRITE (*,*) '         Q(0): ', RECORD(4) */
313 /*                         WRITE (*,*) '         Q(1): ', RECORD(5) */
314 /*                         WRITE (*,*) '         Q(2): ', RECORD(6) */
315 /*                         WRITE (*,*) '         Q(3): ', RECORD(7) */
316 /*                         WRITE (*,*) '        AV(1): ', RECORD(8) */
317 /*                         WRITE (*,*) '        AV(2): ', RECORD(9) */
318 /*                         WRITE (*,*) '        AV(3): ', RECORD(10) */
319 
320 /*                      ELSE */
321 /*                         CALL SETMSG ( 'Subtype # is not ' */
322 /*            .            //            'recognized.'         ) */
323 /*                         CALL ERRINT ( '#', SUBTYP           ) */
324 /*                         CALL SIGERR ( 'SPICE(NOTSUPPORTED)' ) */
325 /*                      END IF */
326 
327 /*                      WRITE (*,*) ' ' */
328 
329 /*                  END DO */
330 
331 /*                END DO */
332 
333 /*                CALL DAFFNA ( FOUND ) */
334 
335 /*             END DO */
336 
337 /*             END */
338 
339 
340 /*     An initial portion of the output created by this program, when */
341 /*     the program was executed on a PC/Linux/gfortran platform, for */
342 /*     a sample CK containing type 6 segments, is shown below: */
343 
344 
345 /*        Segment number:            1 */
346 
347 /*           Mini-segment number:            1 */
348 /*              Rate:             1.52587890625000000E-005 */
349 /*              Subtype:                   1 */
350 /*              Window size:              10 */
351 /*              Interval start:    11288914762710.869 */
352 /*              Interval stop:     11290384616127.203 */
353 /*              Last epoch:        11290384616127.203 */
354 
355 /*              Record number:            1 */
356 /*                 SCLKDP:        11288914762710.869 */
357 /*                 Clock rate:   1.52587890625000000E-005 */
358 /*                 Q(0):   0.46164827229286126 */
359 /*                 Q(1):  -0.70575355403199758 */
360 /*                 Q(2):  -0.29319084125475281 */
361 /*                 Q(3):  -0.45036865373250068 */
362 
363 /*              Record number:            2 */
364 /*                 SCLKDP:        11288998883607.230 */
365 /*                 Clock rate:   1.52587890625000000E-005 */
366 /*                 Q(0):   0.46162099825988423 */
367 /*                 Q(1):  -0.70570932104748119 */
368 /*                 Q(2):  -0.29323821047130305 */
369 /*                 Q(3):  -0.45043507864268195 */
370 
371 /*              Record number:            3 */
372 /*                 SCLKDP:        11289077342579.063 */
373 /*                 Clock rate:   1.52587890625000000E-005 */
374 /*                 Q(0):   0.46159435700379842 */
375 /*                 Q(1):  -0.70566850733850173 */
376 /*                 Q(2):  -0.29328062251407311 */
377 /*                 Q(3):  -0.45049870564815003 */
378 
379 
380 /* $ Restrictions */
381 
382 /*     None. */
383 
384 /* $ Literature_References */
385 
386 /*     None. */
387 
388 /* $ Author_and_Institution */
389 
390 /*     N.J. Bachman     (JPL) */
391 /*     J.M. Lynch       (JPL) */
392 /*     B.V. Semenov     (JPL) */
393 
394 /* $ Version */
395 
396 /* -    SPICELIB Version 1.0.0, 14-MAR-2014 (NJB) (JML) (BVS) */
397 
398 /* -& */
399 /* $ Index_Entries */
400 
401 /*     number of mini-segments in ck type_6 segment */
402 
403 /* -& */
404 
405 /*     SPICELIB functions */
406 
407 
408 /*     Local parameters */
409 
410 /*        ND         is the number of double precision components in an */
411 /*                   unpacked C-kernel descriptor. */
412 
413 /*        NI         is the number of integer components in an unpacked */
414 /*                   C-kernel descriptor. */
415 
416 /*        DTYPE      is the data type of the segment that this routine */
417 /*                   operates on. */
418 
419 
420 /*     Local variables */
421 
422 
423 /*     Standard SPICE error handling. */
424 
425     if (return_()) {
426 	return 0;
427     }
428     chkin_("CKNM06", (ftnlen)6);
429 
430 /*     The number of discrete pointing instances contained in a data */
431 /*     type 6 segment is stored in the last double precision word of the */
432 /*     segment. Since the address of the last word is stored in the */
433 /*     sixth integer component of the segment descriptor, it is a */
434 /*     trivial matter to extract the count. */
435 
436 /*     The unpacked descriptor contains the following information */
437 /*     about the segment: */
438 
439 /*        DC(1)  Initial encoded SCLK */
440 /*        DC(2)  Final encoded SCLK */
441 
442 /*        IC(1)  CK frame class ID (aka "instrument") */
443 /*        IC(2)  Inertial reference frame */
444 /*        IC(3)  Data type */
445 /*        IC(4)  Angular velocity flag */
446 /*        IC(5)  Initial address of segment data */
447 /*        IC(6)  Final address of segment data */
448 
449 
450     dafus_(descr, &c__2, &c__6, dc, ic);
451 
452 /*     If this segment is not of data type 6, then signal an error. */
453 
454     if (ic[2] != 6) {
455 	setmsg_("Data type of the segment should be 6: Passed descriptor sho"
456 		"ws type = #.", (ftnlen)71);
457 	errint_("#", &ic[2], (ftnlen)1);
458 	sigerr_("SPICE(CKWRONGDATATYPE)", (ftnlen)22);
459 	chkout_("CKNM06", (ftnlen)6);
460 	return 0;
461     }
462 
463 /*     The number of mini-segments is the final word in the segment. */
464 
465     dafgda_(handle, &ic[5], &ic[5], dpdata);
466     if (failed_()) {
467 	chkout_("CKNM06", (ftnlen)6);
468 	return 0;
469     }
470     *nmini = i_dnnt(dpdata);
471     chkout_("CKNM06", (ftnlen)6);
472     return 0;
473 } /* cknm06_ */
474 
475