1 /* ckgp.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 static integer c__9 = 9;
13 
14 /* $Procedure      CKGP ( C-kernel, get pointing ) */
ckgp_(integer * inst,doublereal * sclkdp,doublereal * tol,char * ref,doublereal * cmat,doublereal * clkout,logical * found,ftnlen ref_len)15 /* Subroutine */ int ckgp_(integer *inst, doublereal *sclkdp, doublereal *tol,
16 	 char *ref, doublereal *cmat, doublereal *clkout, logical *found,
17 	ftnlen ref_len)
18 {
19     /* Initialized data */
20 
21     static logical first = TRUE_;
22 
23     logical pfnd, sfnd;
24     integer sclk;
25     extern /* Subroutine */ int sct2e_(integer *, doublereal *, doublereal *),
26 	     zznamfrm_(integer *, char *, integer *, char *, integer *,
27 	    ftnlen, ftnlen);
28     integer type1, type2;
29     extern /* Subroutine */ int zzctruin_(integer *);
30     char segid[40];
31     extern /* Subroutine */ int chkin_(char *, ftnlen);
32     doublereal descr[5];
33     extern /* Subroutine */ int dafus_(doublereal *, integer *, integer *,
34 	    doublereal *, integer *), ckbss_(integer *, doublereal *,
35 	    doublereal *, logical *), ckpfs_(integer *, doublereal *,
36 	    doublereal *, doublereal *, logical *, doublereal *, doublereal *,
37 	     doublereal *, logical *), moved_(doublereal *, integer *,
38 	    doublereal *), cksns_(integer *, doublereal *, char *, logical *,
39 	    ftnlen);
40     static char svref[32];
41     logical gotit;
42     static integer svctr1[2];
43     extern logical failed_(void);
44     doublereal av[3], et;
45     integer handle;
46     extern /* Subroutine */ int refchg_(integer *, integer *, doublereal *,
47 	    doublereal *);
48     logical needav;
49     extern /* Subroutine */ int ckmeta_(integer *, char *, integer *, ftnlen);
50     integer refseg, center;
51     extern /* Subroutine */ int frinfo_(integer *, integer *, integer *,
52 	    integer *, logical *);
53     integer refreq, typeid;
54     extern /* Subroutine */ int chkout_(char *, ftnlen);
55     doublereal tmpmat[9]	/* was [3][3] */;
56     static integer svrefr;
57     extern logical return_(void);
58     doublereal dcd[2];
59     integer icd[6];
60     extern /* Subroutine */ int mxm_(doublereal *, doublereal *, doublereal *)
61 	    ;
62     doublereal rot[9]	/* was [3][3] */;
63 
64 /* $ Abstract */
65 
66 /*     Get pointing (attitude) for a specified spacecraft clock time. */
67 
68 /* $ Disclaimer */
69 
70 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
71 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
72 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
73 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
74 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
75 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
76 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
77 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
78 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
79 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
80 
81 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
82 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
83 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
84 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
85 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
86 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
87 
88 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
89 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
90 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
91 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
92 
93 /* $ Required_Reading */
94 
95 /*     CK */
96 /*     SCLK */
97 
98 /* $ Keywords */
99 
100 /*     POINTING */
101 
102 /* $ Declarations */
103 /* $ Abstract */
104 
105 /*     The parameters below form an enumerated list of the recognized */
106 /*     frame types.  They are: INERTL, PCK, CK, TK, DYN.  The meanings */
107 /*     are outlined below. */
108 
109 /* $ Disclaimer */
110 
111 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
112 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
113 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
114 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
115 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
116 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
117 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
118 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
119 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
120 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
121 
122 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
123 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
124 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
125 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
126 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
127 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
128 
129 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
130 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
131 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
132 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
133 
134 /* $ Parameters */
135 
136 /*     INERTL      an inertial frame that is listed in the routine */
137 /*                 CHGIRF and that requires no external file to */
138 /*                 compute the transformation from or to any other */
139 /*                 inertial frame. */
140 
141 /*     PCK         is a frame that is specified relative to some */
142 /*                 INERTL frame and that has an IAU model that */
143 /*                 may be retrieved from the PCK system via a call */
144 /*                 to the routine TISBOD. */
145 
146 /*     CK          is a frame defined by a C-kernel. */
147 
148 /*     TK          is a "text kernel" frame.  These frames are offset */
149 /*                 from their associated "relative" frames by a */
150 /*                 constant rotation. */
151 
152 /*     DYN         is a "dynamic" frame.  These currently are */
153 /*                 parameterized, built-in frames where the full frame */
154 /*                 definition depends on parameters supplied via a */
155 /*                 frame kernel. */
156 
157 /*     ALL         indicates any of the above classes. This parameter */
158 /*                 is used in APIs that fetch information about frames */
159 /*                 of a specified class. */
160 
161 
162 /* $ Author_and_Institution */
163 
164 /*     N.J. Bachman    (JPL) */
165 /*     W.L. Taber      (JPL) */
166 
167 /* $ Literature_References */
168 
169 /*     None. */
170 
171 /* $ Version */
172 
173 /* -    SPICELIB Version 4.0.0, 08-MAY-2012 (NJB) */
174 
175 /*       The parameter ALL was added to support frame fetch APIs. */
176 
177 /* -    SPICELIB Version 3.0.0, 28-MAY-2004 (NJB) */
178 
179 /*       The parameter DYN was added to support the dynamic frame class. */
180 
181 /* -    SPICELIB Version 2.0.0, 12-DEC-1996 (WLT) */
182 
183 /*        Various unused frames types were removed and the */
184 /*        frame time TK was added. */
185 
186 /* -    SPICELIB Version 1.0.0, 10-DEC-1995 (WLT) */
187 
188 /* -& */
189 
190 /*     End of INCLUDE file frmtyp.inc */
191 
192 /* $ Abstract */
193 
194 /*     This include file defines the dimension of the counter */
195 /*     array used by various SPICE subsystems to uniquely identify */
196 /*     changes in their states. */
197 
198 /* $ Disclaimer */
199 
200 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
201 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
202 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
203 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
204 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
205 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
206 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
207 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
208 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
209 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
210 
211 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
212 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
213 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
214 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
215 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
216 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
217 
218 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
219 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
220 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
221 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
222 
223 /* $ Parameters */
224 
225 /*     CTRSIZ      is the dimension of the counter array used by */
226 /*                 various SPICE subsystems to uniquely identify */
227 /*                 changes in their states. */
228 
229 /* $ Author_and_Institution */
230 
231 /*     B.V. Semenov    (JPL) */
232 
233 /* $ Literature_References */
234 
235 /*     None. */
236 
237 /* $ Version */
238 
239 /* -    SPICELIB Version 1.0.0, 29-JUL-2013 (BVS) */
240 
241 /* -& */
242 
243 /*     End of include file. */
244 
245 /* $ Brief_I/O */
246 
247 /*     Variable  I/O  Description */
248 /*     --------  ---  -------------------------------------------------- */
249 /*     INST       I   NAIF ID of instrument, spacecraft, or structure. */
250 /*     SCLKDP     I   Encoded spacecraft clock time. */
251 /*     TOL        I   Time tolerance. */
252 /*     REF        I   Reference frame. */
253 /*     CMAT       O   C-matrix pointing data. */
254 /*     CLKOUT     O   Output encoded spacecraft clock time. */
255 /*     FOUND      O   True when requested pointing is available. */
256 
257 /* $ Detailed_Input */
258 
259 /*     INST       is the NAIF integer ID for the instrument, spacecraft, */
260 /*                or other structure for which pointing is requested. */
261 /*                For brevity we will refer to this object as the */
262 /*                "instrument," and the frame fixed to this object as */
263 /*                the "instrument frame" or "instrument-fixed" frame. */
264 
265 /*     SCLKDP     is the encoded spacecraft clock time for which */
266 /*                pointing is requested. */
267 
268 /*                The SPICELIB routines SCENCD and SCE2C respectively */
269 /*                convert spacecraft clock strings and ephemeris time to */
270 /*                encoded spacecraft clock.  The inverse conversions are */
271 /*                performed by SCDECD and SCT2E. */
272 
273 /*     TOL        is a time tolerance in ticks, the units of encoded */
274 /*                spacecraft clock time. */
275 
276 /*                The SPICELIB routine SCTIKS converts a spacecraft */
277 /*                clock tolerance duration from its character string */
278 /*                representation to ticks.  SCFMT performs the inverse */
279 /*                conversion. */
280 
281 /*                The C-matrix returned by CKGP is the one whose time */
282 /*                tag is closest to SCLKDP and within TOL units of */
283 /*                SCLKDP.  (More in Particulars, below.) */
284 
285 /*                In general, because using a non-zero tolerance */
286 /*                affects selection of the segment from which the */
287 /*                data is obtained, users are strongly discouraged */
288 /*                from using a non-zero tolerance when reading CKs */
289 /*                with continuous data. Using a non-zero tolerance */
290 /*                should be reserved exclusively to reading CKs with */
291 /*                discrete data because in practice obtaining data */
292 /*                from such CKs using a zero tolerance is often not */
293 /*                possible due to time round off. */
294 
295 /*     REF        is the desired reference frame for the returned */
296 /*                pointing.  The returned C-matrix CMAT gives the */
297 /*                orientation of the instrument designated by INST */
298 /*                relative to the frame designated by REF.  When a */
299 /*                vector specified relative to frame REF is left- */
300 /*                multiplied by CMAT, the vector is rotated to the */
301 /*                frame associated with INST.  See the discussion of */
302 /*                CMAT below for details. */
303 
304 /*                Consult the SPICE document "Frames" for a discussion */
305 /*                of supported reference frames. */
306 
307 /* $ Detailed_Output */
308 
309 /*     CMAT       is a rotation matrix that transforms the components of */
310 /*                a vector expressed in the reference frame specified by */
311 /*                REF to components expressed in the frame tied to the */
312 /*                instrument, spacecraft, or other structure at time */
313 /*                CLKOUT (see below). */
314 
315 /*                Thus, if a vector v has components x,y,z in the REF */
316 /*                reference frame, then v has components x',y',z' in the */
317 /*                instrument fixed frame at time CLKOUT: */
318 
319 /*                     [ x' ]     [          ] [ x ] */
320 /*                     | y' |  =  |   CMAT   | | y | */
321 /*                     [ z' ]     [          ] [ z ] */
322 
323 /*                If you know x', y', z', use the transpose of the */
324 /*                C-matrix to determine x, y, z as follows: */
325 
326 /*                     [ x ]      [          ]T    [ x' ] */
327 /*                     | y |  =   |   CMAT   |     | y' | */
328 /*                     [ z ]      [          ]     [ z' ] */
329 /*                              (Transpose of CMAT) */
330 
331 
332 /*     CLKOUT     is the encoded spacecraft clock time associated with */
333 /*                the returned C-matrix. This value may differ from the */
334 /*                requested time, but never by more than the input */
335 /*                tolerance TOL. */
336 
337 /*                The particulars section below describes the search */
338 /*                algorithm used by CKGP to satisfy a pointing */
339 /*                request.  This algorithm determines the pointing */
340 /*                instance (and therefore the associated time value) */
341 /*                that is returned. */
342 
343 /*     FOUND      is true if a record was found to satisfy the pointing */
344 /*                request.  FOUND will be false otherwise. */
345 
346 /* $ Parameters */
347 
348 /*     None. */
349 
350 /* $ Exceptions */
351 
352 /*     1)  If a C-kernel file has not been loaded using FURNSH prior to */
353 /*         a call to this routine, an error is signaled by a routine in */
354 /*         the call tree of this routine. */
355 
356 /*     2)  If TOL is negative, found is set to .FALSE. */
357 
358 /*     3)  If REF is not a supported reference frame, an error is */
359 /*         signaled by a routine in the call tree of this routine and */
360 /*         FOUND is set to .FALSE. */
361 
362 /* $ Files */
363 
364 /*     CKGP searches through files loaded by FURNSH to locate a */
365 /*     segment that can satisfy the request for pointing for instrument */
366 /*     INST at time SCLKDP.  You must load a C-kernel file using FURNSH */
367 /*     prior to calling this routine. */
368 
369 /* $ Particulars */
370 
371 /*     How the tolerance argument is used */
372 /*     ================================== */
373 
374 
375 /*     Reading a type 1 CK segment (discrete pointing instances) */
376 /*     --------------------------------------------------------- */
377 
378 /*     In the diagram below */
379 
380 /*        - "0" is used to represent discrete pointing instances */
381 /*          (quaternions and associated time tags). */
382 
383 /*        - "( )" are used to represent the end points of the time */
384 /*          interval covered by a segment in a CK file. */
385 
386 /*        - SCLKDP is the time at which you requested pointing. */
387 /*          The location of SCLKDP relative to the time tags of the */
388 /*          pointing instances is indicated by the "+" sign. */
389 
390 /*        - TOL is the time tolerance specified in the pointing */
391 /*          request.  The square brackets "[ ]" represent the */
392 /*          endpoints of the time interval */
393 
394 /*             SCLKDP-TOL : SCLKDP+TOL */
395 
396 /*        - The quaternions occurring in the segment need not be */
397 /*          evenly spaced in time. */
398 
399 
400 /*     Case 1:  pointing is available */
401 /*     ------------------------------ */
402 
403 /*                              SCLKDP */
404 /*                                   \   TOL */
405 /*                                    | / */
406 /*                                    |/\ */
407 /*     Your request                [--+--] */
408 /*                                 .  .  . */
409 /*     Segment      (0-----0--0--0--0--0--0---0--0------------0--0--0--0) */
410 /*                                     ^ */
411 /*                                     | */
412 /*                         CKGP returns this instance. */
413 
414 
415 /*     Case 2:  pointing is not available */
416 /*     ---------------------------------- */
417 
418 /*                                                   SCLKDP */
419 /*                                                      \   TOL */
420 /*                                                       | / */
421 /*                                                       |/\ */
422 /*     Your request                                   [--+--] */
423 /*                                                    .  .  . */
424 /*     Segment      (0-----0--0--0--0--0--0---0--0--0---------0--0--0--0) */
425 
426 
427 /*                         CKGP returns no pointing; the output */
428 /*                         FOUND flag is set to .FALSE. */
429 
430 
431 
432 /*     Reading a type 2, 3, 4, or 5 CK segment (continuous pointing) */
433 /*     ------------------------------------------------------------- */
434 
435 /*     In the diagrams below */
436 
437 /*        - "==" is used to represent periods of continuous pointing. */
438 
439 /*        - "--" is used to represent gaps in the pointing coverage. */
440 
441 /*        - "( )" are used to represent the end points of the time */
442 /*          interval covered by a segment in a CK file. */
443 
444 /*        - SCLKDP is the time at which you requested pointing. */
445 /*          The location of SCLKDP relative to the time tags of the */
446 /*          pointing instances is indicated by the "+" sign. */
447 
448 /*        - TOL is the time tolerance specified in the pointing */
449 /*          request.  The square brackets "[ ]" represent the */
450 /*          endpoints of the time interval */
451 
452 /*             SCLKDP-TOL : SCLKDP+TOL */
453 
454 /*        - The quaternions occurring in the periods of continuous */
455 /*          pointing need not be evenly spaced in time. */
456 
457 
458 /*     Case 1:  pointing is available at the request time */
459 /*     -------------------------------------------------- */
460 
461 /*                             SCLKDP */
462 /*                                   \   TOL */
463 /*                                    | / */
464 /*                                    |/\ */
465 /*     Your request                [--+--] */
466 /*                                 .  .  . */
467 /*                                 .  .  . */
468 /*                                 .  .  . */
469 /*     Segment            (==---===========---=======----------===--) */
470 /*                                    ^ */
471 /*                                    | */
472 
473 /*                   The request time lies within an interval where */
474 /*                   continuous pointing is available. CKGP returns */
475 /*                   pointing at the requested epoch. */
476 
477 
478 /*     Case 2:  pointing is available "near" the request time */
479 /*     ------------------------------------------------------ */
480 
481 /*                                    SCLKDP */
482 /*                                          \   TOL */
483 /*                                           | / */
484 /*                                           |/\ */
485 /*     Your request                       [--+--] */
486 /*                                        .  .  . */
487 /*     Segment            (==---===========----=======---------===--) */
488 /*                                             ^ */
489 /*                                             | */
490 
491 /*                   The request time lies in a gap:  an interval where */
492 /*                   continuous pointing is *not* available.  CKGP */
493 /*                   returns pointing for the epoch closest to the */
494 /*                   request time SCLKDP. */
495 
496 
497 /*     Case 3:  pointing is not available */
498 /*     ---------------------------------- */
499 
500 /*                                                 SCLKDP */
501 /*                                                       \   TOL */
502 /*                                                        | / */
503 /*                                                        |/\ */
504 /*     Your request                                    [--+--] */
505 /*                                                     .  .  . */
506 /*     Segment            (==---===========----=======---------===--) */
507 
508 /*                         CKGP returns no pointing; the output */
509 /*                         FOUND flag is set to .FALSE. */
510 
511 
512 
513 /*     Tolerance and segment priority */
514 /*     ============================== */
515 
516 /*     CKGP searches through loaded C-kernels to satisfy a pointing */
517 /*     request. Last-loaded files are searched first. Individual files */
518 /*     are searched in backwards order, so that between competing */
519 /*     segments (segments containing data for the same object, for */
520 /*     overlapping time ranges), the one closest to the end of the file */
521 /*     has highest priority. */
522 
523 /*     The search ends when a segment is found that can provide pointing */
524 /*     for the specified instrument at a time falling within the */
525 /*     specified tolerance on either side of the request time. Within */
526 /*     that segment, the instance closest to the input time is located */
527 /*     and returned. */
528 
529 /*     The following four cases illustrate this search procedure. */
530 /*     Segments A and B are in the same file, with segment A located */
531 /*     further towards the end of the file than segment B. Both segments */
532 /*     A and B contain discrete pointing data, indicated by the number */
533 /*     0. */
534 
535 
536 /*     Case 1:  Pointing is available in the first segment searched. */
537 /*              Because segment A has the highest priority and can */
538 /*              satisfy the request, segment B is not searched. */
539 
540 
541 /*                                  SCLKDP */
542 /*                                        \  TOL */
543 /*                                         | / */
544 /*                                         |/\ */
545 /*     Your request                     [--+--] */
546 /*                                      .  .  . */
547 /*     Segment A          (0-----------------0--------0--0-----0) */
548 /*                                           ^ */
549 /*                                           | */
550 /*                                           | */
551 /*                               CKGP returns this instance */
552 
553 /*     Segment B     (0--0--0--0--0--0--0--0--0--0--0--0--0--0--0--0--0) */
554 
555 
556 
557 /*     Case 2:  Pointing is not available in the first segment searched. */
558 /*              Because segment A cannot satisfy the request, segment B */
559 /*              is searched. */
560 
561 
562 /*                             SCLKDP */
563 /*                                  \   TOL */
564 /*                                   | / */
565 /*                                   |/\ */
566 /*     Your request               [--+--] */
567 /*                                .  .  . */
568 /*     Segment A          (0-----------------0--------0--0-----0) */
569 /*                                .  .  . */
570 /*     Segment B     (0--0--0--0--0--0--0--0--0--0--0--0--0--0--0--0--0) */
571 /*                                   ^ */
572 /*                                   | */
573 /*                       CKGP returns this instance */
574 
575 
576 /*     Segments that contain continuous pointing data are searched in */
577 /*     the same manner as segments containing discrete pointing data. */
578 /*     For request times that fall within the bounds of continuous */
579 /*     intervals, CKGP will return pointing at the request time. When */
580 /*     the request time does not fall within an interval, then a time at */
581 /*     an endpoint of an interval may be returned if it is the closest */
582 /*     time in the segment to the user request time and is also within */
583 /*     the tolerance. */
584 
585 /*     In the following examples, segment A is located further towards */
586 /*     the end of the file than segment C. Segment A contains discrete */
587 /*     pointing data and segment C contains continuous data, indicated */
588 /*     by the "=" character. */
589 
590 
591 /*     Case 3:  Pointing is not available in the first segment searched. */
592 /*              Because segment A cannot satisfy the request, segment C */
593 /*              is searched. */
594 
595 /*                             SCLKDP */
596 /*                                   \  TOL */
597 /*                                    | / */
598 /*                                    |/\ */
599 /*     Your request                [--+--] */
600 /*                                 .  .  . */
601 /*                                 .  .  . */
602 /*     Segment A          (0-----------------0--------0--0-----0) */
603 /*                                 .  .  . */
604 /*                                 .  .  . */
605 /*     Segment C          (---=============-----====--------==--) */
606 /*                                    ^ */
607 /*                                    | */
608 /*                                    | */
609 /*                         CKGP returns this instance */
610 
611 
612 /*     In the next case, assume that the order of segments A and C in the */
613 /*     file is reversed:  A is now closer to the front, so data from */
614 /*     segment C are considered first. */
615 
616 
617 /*     Case 4:  Pointing is available in the first segment searched. */
618 /*              Because segment C has the highest priority and can */
619 /*              satisfy the request, segment A is not searched. */
620 
621 /*                                             SCLKDP */
622 /*                                            / */
623 /*                                           |  TOL */
624 /*                                           | / */
625 /*                                           |/\ */
626 /*     Your request                       [--+--] */
627 /*                                        .  .  . */
628 /*                                        .  .  . */
629 /*     Segment C          (---=============-----====--------==--) */
630 /*                                             ^ */
631 /*                                             | */
632 /*                                CKGP returns this instance */
633 
634 /*     Segment A          (0-----------------0--------0--0-----0) */
635 /*                                           ^ */
636 /*                                           | */
637 /*                                     "Best" answer */
638 
639 
640 /*     The next case illustrates an unfortunate side effect of using */
641 /*     a non-zero tolerance when reading multi-segment CKs with */
642 /*     continuous data. In all cases when the look-up interval */
643 /*     formed using tolerance overlaps a segment boundary and */
644 /*     the request time falls within the coverage of the lower */
645 /*     priority segment, the data at the end of the higher priority */
646 /*     segment will be picked instead of the data from the lower */
647 /*     priority segment. */
648 
649 
650 /*     Case 5:  Pointing is available in the first segment searched. */
651 /*              Because segment C has the highest priority and can */
652 /*              satisfy the request, segment A is not searched. */
653 
654 /*                                             SCLKDP */
655 /*                                            / */
656 /*                                           |  TOL */
657 /*                                           | / */
658 /*                                           |/\ */
659 /*     Your request                       [--+--] */
660 /*                                        .  .  . */
661 /*                                        .  .  . */
662 /*     Segment C                                (===============) */
663 /*                                              ^ */
664 /*                                              | */
665 /*                                CKGP returns this instance */
666 
667 /*     Segment A          (=====================) */
668 /*                                           ^ */
669 /*                                           | */
670 /*                                     "Best" answer */
671 
672 /* $ Examples */
673 
674 /*     Suppose you have two C-kernel files containing data for the */
675 /*     Voyager 2 narrow angle camera.  One file contains predict values, */
676 /*     and the other contains corrected pointing for a selected group */
677 /*     of images, that is, for a subset of images from the first file. */
678 
679 /*     The following example program uses CKGP to get C-matrices for a */
680 /*     set of images whose SCLK counts (un-encoded character string */
681 /*     versions) are contained in the array SCLKCH. */
682 
683 /*     If available, the program will get the corrected pointing values. */
684 /*     Otherwise, predict values will be used. */
685 
686 /*     For each C-matrix, a unit  pointing vector is constructed */
687 /*     and printed. */
688 
689 
690 /*     C */
691 /*     C     Constants for this program. */
692 /*     C */
693 /*     C     -- The code for the Voyager 2 spacecraft clock is -32 */
694 /*     C */
695 /*     C     -- The code for the narrow angle camera on the Voyager 2 */
696 /*     C        spacecraft is -32001. */
697 /*     C */
698 /*     C    --  Spacecraft clock times for successive Voyager images */
699 /*     C        always differ by more than 0:0:400.  This is an */
700 /*     C        acceptable tolerance, and must be converted to "ticks" */
701 /*     C        (units of encoded SCLK) for input to CKGP. */
702 /*     C */
703 /*     C     -- The reference frame we want is FK4. */
704 /*     C */
705 /*     C     -- The narrow angle camera boresight defines the third */
706 /*     C        axis of the instrument-fixed coordinate system. */
707 /*     C        Therefore, the vector ( 0, 0, 1 ) represents */
708 /*     C        the boresight direction in the camera-fixed frame. */
709 /*     C */
710 /*           IMPLICIT NONE */
711 
712 /*           INTEGER               FILEN */
713 /*           PARAMETER           ( FILEN  = 255 ) */
714 
715 /*           INTEGER               NPICS */
716 /*           PARAMETER           ( NPICS  = 2 ) */
717 
718 /*           INTEGER               TIMLEN */
719 /*           PARAMETER           ( TIMLEN = 30 ) */
720 
721 /*           INTEGER               REFLEN */
722 /*           PARAMETER           ( REFLEN = 32 ) */
723 
724 /*           CHARACTER*(TIMLEN)    CLKCH */
725 /*           CHARACTER*(FILEN)     CKPRED */
726 /*           CHARACTER*(FILEN)     CKCORR */
727 /*           CHARACTER*(REFLEN)    REF */
728 /*           CHARACTER*(FILEN)     SCLK */
729 /*           CHARACTER*(TIMLEN)    SCLKCH ( NPICS ) */
730 /*           CHARACTER*(TIMLEN)    TOLVGR */
731 
732 /*           DOUBLE PRECISION      CLKOUT */
733 /*           DOUBLE PRECISION      CMAT   ( 3, 3 ) */
734 /*           DOUBLE PRECISION      SCLKDP */
735 /*           DOUBLE PRECISION      TOLTIK */
736 /*           DOUBLE PRECISION      VCFIX  ( 3 ) */
737 /*           DOUBLE PRECISION      VINERT ( 3 ) */
738 
739 /*           INTEGER               SC */
740 /*           INTEGER               I */
741 /*           INTEGER               INST */
742 
743 /*           LOGICAL               FOUND */
744 
745 /*           CKPRED     = 'voyager2_predict.bc' */
746 /*           CKCORR     = 'voyager2_corrected.bc' */
747 /*           SCLK       = 'voyager2_sclk.tsc' */
748 /*           SC         = -32 */
749 /*           INST       = -32001 */
750 /*           SCLKCH(1)  = '4/08966:30:768' */
751 /*           SCLKCH(2)  = '4/08970:58:768' */
752 /*           TOLVGR     = '0:0:400' */
753 /*           REF        = 'FK4' */
754 /*           VCFIX( 1 ) =  0.D0 */
755 /*           VCFIX( 2 ) =  0.D0 */
756 /*           VCFIX( 3 ) =  1.D0 */
757 
758 /*     C */
759 /*     C     Loading the files in this order ensures that the */
760 /*     C     corrected file will get searched first. */
761 /*     C */
762 /*           CALL FURNSH ( CKPRED ) */
763 /*           CALL FURNSH ( CKCORR ) */
764 
765 /*     C */
766 /*     C     Need to load a Voyager 2 SCLK kernel to convert from */
767 /*     C     clock strings to ticks. */
768 /*     C */
769 /*           CALL FURNSH ( SCLK ) */
770 
771 /*     C */
772 /*     C     Convert tolerance from VGR formatted character string */
773 /*     C     SCLK to ticks which are units of encoded SCLK. */
774 /*     C */
775 /*           CALL SCTIKS ( SC, TOLVGR, TOLTIK ) */
776 
777 
778 /*           DO I = 1, NPICS */
779 /*     C */
780 /*     C        CKGP requires encoded spacecraft clock. */
781 /*     C */
782 /*              CALL SCENCD ( SC, SCLKCH( I ), SCLKDP ) */
783 
784 /*              CALL CKGP ( INST,   SCLKDP, TOLTIK, REF, CMAT, */
785 /*          .               CLKOUT, FOUND                      ) */
786 
787 /*              IF ( FOUND ) THEN */
788 
789 /*     C */
790 /*     C           Use the transpose of the C-matrix to transform the */
791 /*     C           boresight vector from camera-fixed to reference */
792 /*     C           coordinates. */
793 /*     C */
794 /*                 CALL MTXV   ( CMAT, VCFIX,  VINERT ) */
795 /*                 CALL SCDECD ( SC,   CLKOUT, CLKCH  ) */
796 
797 /*                 WRITE (*,*) 'VGR 2 SCLK Time:         ', CLKCH */
798 /*                 WRITE (*,*) 'VGR 2 NA ISS boresight ' */
799 /*          .      //          'pointing vector: ',         VINERT */
800 
801 /*              ELSE */
802 
803 /*                 WRITE (*,*) 'Pointing not found for time ', SCLKCH(I) */
804 
805 /*              END IF */
806 
807 /*           END DO */
808 
809 /*           END */
810 
811 
812 /* $ Restrictions */
813 
814 /*     None. */
815 
816 /* $ Literature_References */
817 
818 /*     None. */
819 
820 /* $ Author_and_Institution */
821 
822 /*     C.H. Acton     (JPL) */
823 /*     N.J. Bachman   (JPL) */
824 /*     W.L. Taber     (JPL) */
825 /*     J.M. Lynch     (JPL) */
826 /*     B.V. Semenov   (JPL) */
827 /*     M.J. Spencer   (JPL) */
828 /*     R.E. Thurman   (JPL) */
829 /*     I.M. Underwood (JPL) */
830 
831 /* $ Version */
832 
833 /* -    SPICELIB Version 5.4.0, 23-SEP-2013 (BVS) */
834 
835 /*        Updated to save the input frame name and POOL state counter */
836 /*        and to do frame name-ID conversion only if the counter has */
837 /*        changed. */
838 
839 /* -    SPICELIB Version 5.3.1, 09-JUN-2010 (BVS) */
840 
841 /*        Header update: description of the tolerance and Particulars */
842 /*        section were expanded to address some problems arising from */
843 /*        using a non-zero tolerance. */
844 
845 /* -    SPICELIB Version 5.3.0, 23-APR-2010 (NJB) */
846 
847 /*        Bug fix: this routine now obtains the rotation */
848 /*        from the request frame to the applicable CK segment's */
849 /*        base frame via a call to REFCHG. Formerly the routine */
850 /*        used FRMCHG, which required that angular velocity data */
851 /*        be available for this transformation. */
852 
853 /* -    SPICELIB Version 5.2.0, 25-AUG-2005 (NJB) */
854 
855 /*        Updated to remove non-standard use of duplicate arguments */
856 /*        in MXM call. */
857 
858 /* -    SPICELIB Version 5.1.2, 29-JAN-2004 (NJB) */
859 
860 /*        Header update:  description of input argument REF was */
861 /*        expanded. */
862 
863 /* -    SPICELIB Version 5.1.1, 27-JUL-2003 (CHA) (NJB) */
864 
865 /*        Various header corrections were made. */
866 
867 /* -    SPICELIB Version 3.2.0, 23-FEB-1999 (WLT) */
868 
869 /*        The previous editions of this routine did not properly handle */
870 /*        the case when TOL was negative.  The routine now returns a */
871 /*        value of .FALSE. for FOUND as is advertised above. */
872 
873 /* -    SPICELIB Version 3.1.0, 13-APR-1998 (WLT) */
874 
875 /*        The call to CHKOUT in the case when FAILED returned the */
876 /*        value TRUE used to check out with the name 'CKGPAV'.  This */
877 /*        has been changed to a CKGP. */
878 
879 /* -    SPICELIB Version 3.0.0, 19-SEP-1994 (WLT) */
880 
881 /*        The routine was upgraded to support non-inertial frames. */
882 
883 /* -    SPICELIB Version 2.0.1, 10-MAR-1992 (WLT) */
884 
885 /*        Comment section for permuted index source lines was added */
886 /*        following the header. */
887 
888 /* -    SPICELIB Version 2.0.0, 30-AUG-1991 (JML) */
889 
890 /*        The Particulars section was updated to show how the */
891 /*        search algorithm processes segments with continuous */
892 /*        pointing data. */
893 
894 /*        The example program now loads an SCLK kernel. */
895 
896 /*        FAILED is checked after the call to IRFROT to handle the */
897 /*        case where the reference frame is invalid and the error */
898 /*        handling is not set to abort. */
899 
900 /*        FAILED is checked in the DO WHILE loop to handle the case */
901 /*        where an error is detected by a SPICELIB routine inside the */
902 /*        loop and the error handling is not set to abort. */
903 
904 /* -    SPICELIB Version 1.0.1, 02-NOV-1990 (JML) */
905 
906 /*        The restriction that a C-kernel file must be loaded */
907 /*        was explicitly stated. */
908 
909 
910 /* -    SPICELIB Version 1.0.0, 07-SEP-1990 (RET) (IMU) */
911 
912 /* -& */
913 /* $ Index_Entries */
914 
915 /*     get ck pointing */
916 
917 /* -& */
918 /* $ Revisions */
919 
920 /* -    SPICELIB Version 5.2.0, 25-AUG-2005 (NJB) */
921 
922 /*        Updated to remove non-standard use of duplicate arguments */
923 /*        in MXM call. */
924 
925 /* -    SPICELIB Version 3.1.0, 20-DEC-1995 (WLT) */
926 
927 /*        A call to FRINFO did not have enough arguments and */
928 /*        went undetected until Howard Taylor of ACT.  Many */
929 /*        thanks go out to Howard for tracking down this error. */
930 
931 /* -    SPICELIB Version 3.0.0, 19-SEP-1994 (WLT) */
932 
933 /*        The routine was upgraded to support non-inertial frames. */
934 
935 /*        Calls to NAMIRF and IRFROT were replaced with calls to */
936 /*        NAMFRM and FRMCHG respectively. */
937 
938 
939 /* -    SPICELIB Version 1.0.2, 30-AUG-1991 (JML) */
940 
941 /*        1) The Particulars section was updated to show how the */
942 /*           search algorithm processes segments with continuous */
943 /*           pointing data. */
944 
945 /*        2) The example program now loads an SCLK kernel. */
946 
947 /*        3) FAILED is checked after the call to IRFROT to handle the */
948 /*           case where the reference frame is invalid and the error */
949 /*           handling is not set to abort. */
950 
951 /*        4) FAILED is checked in the DO WHILE loop to handle the case */
952 /*           where an error is detected by a SPICELIB routine inside the */
953 /*           loop and the error handling is not set to abort. */
954 
955 /* -    SPICELIB Version 1.0.1, 02-NOV-1990 (JML) */
956 
957 /*        1) The restriction that a C-kernel file must be loaded */
958 /*           was explicitly stated. */
959 /*        2) Minor changes were made to the wording of the header. */
960 
961 
962 /* -    Beta Version 1.1.0, 29-AUG-1990 (MJS) */
963 
964 /*        The following changes were made as a result of the */
965 /*        NAIF CK Code and Documentation Review: */
966 
967 /*        1) The variable SCLK was changed to SCLKDP. */
968 /*        2) The variable INSTR was changed to INST. */
969 /*        3) The variable IDENT was changed to SEGID. */
970 /*        4) The declarations for the parameters NDC, NIC, NC, and */
971 /*           IDLEN were moved from the "Declarations" section of the */
972 /*           header to the "Local parameters" section of the code below */
973 /*           the header. These parameters are not meant to modified by */
974 /*           users. */
975 /*        5) The header was updated to reflect the changes. */
976 
977 /* -    Beta Version 1.0.0, 04-MAY-1990 (RET) (IMU) */
978 
979 /* -& */
980 
981 /*     SPICELIB functions */
982 
983 
984 /*     Local parameters */
985 
986 /*        NDC        is the number of double precision components in an */
987 /*                   unpacked C-kernel segment descriptor. */
988 
989 /*        NIC        is the number of integer components in an unpacked */
990 /*                   C-kernel segment descriptor. */
991 
992 /*        NC         is the number of components in a packed C-kernel */
993 /*                   descriptor.  All DAF summaries have this formulaic */
994 /*                   relationship between the number of its integer and */
995 /*                   double precision components and the number of packed */
996 /*                   components. */
997 
998 /*        IDLEN      is the length of the C-kernel segment identifier. */
999 /*                   All DAF names have this formulaic relationship */
1000 /*                   between the number of summary components and */
1001 /*                   the length of the name (You will notice that */
1002 /*                   a name and a summary have the same length in bytes.) */
1003 
1004 
1005 /*     Saved frame name length. */
1006 
1007 
1008 /*     Local variables */
1009 
1010 
1011 /*     Saved frame name/ID item declarations. */
1012 
1013 
1014 /*     Saved frame name/ID items. */
1015 
1016 
1017 /*     Initial values. */
1018 
1019 
1020 /*     Standard SPICE error handling. */
1021 
1022     if (return_()) {
1023 	return 0;
1024     } else {
1025 	chkin_("CKGP", (ftnlen)4);
1026     }
1027 
1028 /*     Initialization. */
1029 
1030     if (first) {
1031 
1032 /*        Initialize counter. */
1033 
1034 	zzctruin_(svctr1);
1035 	first = FALSE_;
1036     }
1037 
1038 /*     Don't need angular velocity data. */
1039 /*     Assume the segment won't be found until it really is. */
1040 
1041     needav = FALSE_;
1042     *found = FALSE_;
1043 
1044 /*     If the tolerance is less than zero, we go no further. */
1045 
1046     if (*tol < 0.) {
1047 	chkout_("CKGP", (ftnlen)4);
1048 	return 0;
1049     }
1050 
1051 /*     Begin a search for this instrument and time, and get the first */
1052 /*     applicable segment. */
1053 
1054     ckbss_(inst, sclkdp, tol, &needav);
1055     cksns_(&handle, descr, segid, &sfnd, (ftnlen)40);
1056 
1057 /*     Keep trying candidate segments until a segment can produce a */
1058 /*     pointing instance within the specified time tolerance of the */
1059 /*     input time. */
1060 
1061 /*     Check FAILED to prevent an infinite loop if an error is detected */
1062 /*     by a SPICELIB routine and the error handling is not set to abort. */
1063 
1064     while(sfnd && ! failed_()) {
1065 	ckpfs_(&handle, descr, sclkdp, tol, &needav, cmat, av, clkout, &pfnd);
1066 	if (pfnd) {
1067 
1068 /*           Found one. If the C-matrix doesn't already rotate from the */
1069 /*           requested frame, convert it to one that does. */
1070 
1071 	    dafus_(descr, &c__2, &c__6, dcd, icd);
1072 	    refseg = icd[1];
1073 
1074 /*           Look up the id code for the requested reference frame. */
1075 
1076 	    zznamfrm_(svctr1, svref, &svrefr, ref, &refreq, (ftnlen)32,
1077 		    ref_len);
1078 	    if (refreq != refseg) {
1079 
1080 /*              We may need to convert the output ticks CLKOUT to ET */
1081 /*              so that we can get the needed state transformation */
1082 /*              matrix.  This is the case if either of the frames */
1083 /*              is non-inertial. */
1084 
1085 		frinfo_(&refreq, &center, &type1, &typeid, &gotit);
1086 		frinfo_(&refseg, &center, &type2, &typeid, &gotit);
1087 		if (type1 == 1 && type2 == 1) {
1088 
1089 /*                 Any old value of ET will do in this case.  We'll */
1090 /*                 use zero. */
1091 
1092 		    et = 0.;
1093 		} else {
1094 
1095 /*                 Look up the spacecraft clock id to use to convert */
1096 /*                 the output CLKOUT to ET. */
1097 
1098 		    ckmeta_(inst, "SCLK", &sclk, (ftnlen)4);
1099 		    sct2e_(&sclk, clkout, &et);
1100 		}
1101 
1102 /*              Get the transformation from the requested frame to */
1103 /*              the segment frame at ET. */
1104 
1105 		refchg_(&refreq, &refseg, &et, rot);
1106 
1107 /*              If REFCHG detects that the reference frame is invalid */
1108 /*              then return from this routine with FOUND equal to false. */
1109 
1110 		if (failed_()) {
1111 		    chkout_("CKGP", (ftnlen)4);
1112 		    return 0;
1113 		}
1114 
1115 /*              Transform the attitude information: convert CMAT so that */
1116 /*              it maps from request frame to C-matrix frame. */
1117 
1118 		mxm_(cmat, rot, tmpmat);
1119 		moved_(tmpmat, &c__9, cmat);
1120 	    }
1121 	    *found = TRUE_;
1122 	    chkout_("CKGP", (ftnlen)4);
1123 	    return 0;
1124 	}
1125 	cksns_(&handle, descr, segid, &sfnd, (ftnlen)40);
1126     }
1127     chkout_("CKGP", (ftnlen)4);
1128     return 0;
1129 } /* ckgp_ */
1130 
1131