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