1 /* cke04.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__4 = 4;
11 
12 /* $Procedure      CKE04 ( C-kernel, evaluate pointing record, type 4 ) */
cke04_(logical * needav,doublereal * record,doublereal * cmat,doublereal * av,doublereal * clkout)13 /* Subroutine */ int cke04_(logical *needav, doublereal *record, doublereal *
14 	cmat, doublereal *av, doublereal *clkout)
15 {
16     /* System generated locals */
17     integer i__1, i__2, i__3;
18 
19     /* Builtin functions */
20     integer s_rnge(char *, integer, char *, integer);
21 
22     /* Local variables */
23     integer ideg[7];
24     doublereal qout[4];
25     integer i__;
26     doublereal q[4];
27     extern /* Subroutine */ int vhatg_(doublereal *, integer *, doublereal *);
28     integer basadd;
29     extern /* Subroutine */ int chbval_(doublereal *, integer *, doublereal *,
30 	     doublereal *, doublereal *), q2m_(doublereal *, doublereal *);
31 
32 /* $ Abstract */
33 
34 /*     Evaluate a pointing record returned by CKR04 from a CK type 4 */
35 /*     segment. Return the C-matrix and angular velocity vector */
36 /*     associated with the time CLKOUT. */
37 
38 /* $ Disclaimer */
39 
40 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
41 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
42 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
43 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
44 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
45 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
46 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
47 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
48 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
49 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
50 
51 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
52 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
53 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
54 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
55 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
56 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
57 
58 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
59 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
60 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
61 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
62 
63 /* $ Required_Reading */
64 
65 /*     CK */
66 
67 /* $ Keywords */
68 
69 /*     POINTING */
70 
71 /* $ Declarations */
72 /* $ Abstract */
73 
74 /*     Declarations of the CK data type specific and general CK low */
75 /*     level routine parameters. */
76 
77 /* $ Disclaimer */
78 
79 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
80 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
81 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
82 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
83 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
84 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
85 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
86 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
87 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
88 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
89 
90 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
91 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
92 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
93 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
94 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
95 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
96 
97 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
98 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
99 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
100 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
101 
102 /* $ Required_Reading */
103 
104 /*     CK.REQ */
105 
106 /* $ Keywords */
107 
108 /*     CK */
109 
110 /* $ Restrictions */
111 
112 /*     1) If new CK types are added, the size of the record passed */
113 /*        between CKRxx and CKExx must be registered as separate */
114 /*        parameter. If this size will be greater than current value */
115 /*        of the CKMRSZ parameter (which specifies the maximum record */
116 /*        size for the record buffer used inside CKPFS) then it should */
117 /*        be assigned to CKMRSZ as a new value. */
118 
119 /* $ Author_and_Institution */
120 
121 /*     N.J. Bachman      (JPL) */
122 /*     B.V. Semenov      (JPL) */
123 
124 /* $ Literature_References */
125 
126 /*     CK Required Reading. */
127 
128 /* $ Version */
129 
130 /* -    SPICELIB Version 3.0.0, 27-JAN-2014 (NJB) */
131 
132 /*        Updated to support CK type 6. Maximum degree for */
133 /*        type 5 was updated to be consistent with the */
134 /*        maximum degree for type 6. */
135 
136 /* -    SPICELIB Version 2.0.0, 19-AUG-2002 (NJB) */
137 
138 /*        Updated to support CK type 5. */
139 
140 /* -    SPICELIB Version 1.0.0, 05-APR-1999 (BVS) */
141 
142 /* -& */
143 
144 /*     Number of quaternion components and number of quaternion and */
145 /*     angular rate components together. */
146 
147 
148 /*     CK Type 1 parameters: */
149 
150 /*     CK1DTP   CK data type 1 ID; */
151 
152 /*     CK1RSZ   maximum size of a record passed between CKR01 */
153 /*              and CKE01. */
154 
155 
156 /*     CK Type 2 parameters: */
157 
158 /*     CK2DTP   CK data type 2 ID; */
159 
160 /*     CK2RSZ   maximum size of a record passed between CKR02 */
161 /*              and CKE02. */
162 
163 
164 /*     CK Type 3 parameters: */
165 
166 /*     CK3DTP   CK data type 3 ID; */
167 
168 /*     CK3RSZ   maximum size of a record passed between CKR03 */
169 /*              and CKE03. */
170 
171 
172 /*     CK Type 4 parameters: */
173 
174 /*     CK4DTP   CK data type 4 ID; */
175 
176 /*     CK4PCD   parameter defining integer to DP packing schema that */
177 /*              is applied when seven number integer array containing */
178 /*              polynomial degrees for quaternion and angular rate */
179 /*              components packed into a single DP number stored in */
180 /*              actual CK records in a file; the value of must not be */
181 /*              changed or compatibility with existing type 4 CK files */
182 /*              will be lost. */
183 
184 /*     CK4MXD   maximum Chebychev polynomial degree allowed in type 4 */
185 /*              records; the value of this parameter must never exceed */
186 /*              value of the CK4PCD; */
187 
188 /*     CK4SFT   number of additional DPs, which are not polynomial */
189 /*              coefficients, located at the beginning of a type 4 */
190 /*              CK record that passed between routines CKR04 and CKE04; */
191 
192 /*     CK4RSZ   maximum size of type 4 CK record passed between CKR04 */
193 /*              and CKE04; CK4RSZ is computed as follows: */
194 
195 /*                 CK4RSZ = ( CK4MXD + 1 ) * QAVSIZ + CK4SFT */
196 
197 
198 /*     CK Type 5 parameters: */
199 
200 
201 /*     CK5DTP   CK data type 5 ID; */
202 
203 /*     CK5MXD   maximum polynomial degree allowed in type 5 */
204 /*              records. */
205 
206 /*     CK5MET   number of additional DPs, which are not polynomial */
207 /*              coefficients, located at the beginning of a type 5 */
208 /*              CK record that passed between routines CKR05 and CKE05; */
209 
210 /*     CK5MXP   maximum packet size for any subtype.  Subtype 2 */
211 /*              has the greatest packet size, since these packets */
212 /*              contain a quaternion, its derivative, an angular */
213 /*              velocity vector, and its derivative.  See ck05.inc */
214 /*              for a description of the subtypes. */
215 
216 /*     CK5RSZ   maximum size of type 5 CK record passed between CKR05 */
217 /*              and CKE05; CK5RSZ is computed as follows: */
218 
219 /*                 CK5RSZ = ( CK5MXD + 1 ) * CK5MXP + CK5MET */
220 
221 
222 /*     CK Type 6 parameters: */
223 
224 
225 /*     CK6DTP   CK data type 6 ID; */
226 
227 /*     CK6MXD   maximum polynomial degree allowed in type 6 */
228 /*              records. */
229 
230 /*     CK6MET   number of additional DPs, which are not polynomial */
231 /*              coefficients, located at the beginning of a type 6 */
232 /*              CK record that passed between routines CKR06 and CKE06; */
233 
234 /*     CK6MXP   maximum packet size for any subtype.  Subtype 2 */
235 /*              has the greatest packet size, since these packets */
236 /*              contain a quaternion, its derivative, an angular */
237 /*              velocity vector, and its derivative.  See ck06.inc */
238 /*              for a description of the subtypes. */
239 
240 /*     CK6RSZ   maximum size of type 6 CK record passed between CKR06 */
241 /*              and CKE06; CK6RSZ is computed as follows: */
242 
243 /*                 CK6RSZ = CK6MET + ( CK6MXD + 1 ) * ( CK6PS3 + 1 ) */
244 
245 /*              where CK6PS3 is equal to the parameter CK06PS3 defined */
246 /*              in ck06.inc. Note that the subtype having the largest */
247 /*              packet size (subtype 2) does not give rise to the */
248 /*              largest record size, because that type is Hermite and */
249 /*              requires half the window size used by subtype 3 for a */
250 /*              given polynomial degree. */
251 
252 
253 /*     The parameter CK6PS3 must be in sync with C06PS3 defined in */
254 /*     ck06.inc. */
255 
256 
257 
258 /*     Maximum record size that can be handled by CKPFS. This value */
259 /*     must be set to the maximum of all CKxRSZ parameters (currently */
260 /*     CK5RSZ.) */
261 
262 /* $ Brief_I/O */
263 
264 /*     Variable  I/O  Description */
265 /*     --------  ---  -------------------------------------------------- */
266 /*     NEEDAV     I   True if angular velocity is requested. */
267 /*     RECORD     I   Data type 4 pointing record. */
268 /*     CMAT       O   C-matrix. */
269 /*     AV         O   Angular velocity vector. */
270 /*     CLKOUT     O   SCLK associated with C-matrix. */
271 
272 /* $ Detailed_Input */
273 
274 /*     NEEDAV     is true if angular velocity is requested. */
275 
276 /*     RECORD     is a set of double precision numbers returned by */
277 /*                CKR04. RECORD must have the following structure: */
278 
279 /*                --------------------------------------------------- */
280 /*                |    Encoded onboard time which is the closest    | */
281 /*                |  to SCLKDP and belongs to one of approximation  | */
282 /*                |                   intervals                     | */
283 /*                --------------------------------------------------- */
284 /*                |       encoded SCLK time of the midpoint of      | */
285 /*                |             interpolation interval              | */
286 /*                --------------------------------------------------- */
287 /*                |          radii of interpolation interval        | */
288 /*                |    expressed as double precision SCLK ticks     | */
289 /*                --------------------------------------------------- */
290 /*                |         Number of coefficients for q0           | */
291 /*                --------------------------------------------------- */
292 /*                |         Number of coefficients for q1           | */
293 /*                --------------------------------------------------- */
294 /*                |         Number of coefficients for q2           | */
295 /*                --------------------------------------------------- */
296 /*                |         Number of coefficients for q3           | */
297 /*                --------------------------------------------------- */
298 /*                |         Number of coefficients for AV1          | */
299 /*                --------------------------------------------------- */
300 /*                |         Number of coefficients for AV2          | */
301 /*                --------------------------------------------------- */
302 /*                |         Number of coefficients for AV3          | */
303 /*                --------------------------------------------------- */
304 /*                |               q0 Cheby coefficients             | */
305 /*                --------------------------------------------------- */
306 /*                |               q1 Cheby coefficients             | */
307 /*                --------------------------------------------------- */
308 /*                |               q2 Cheby coefficients             | */
309 /*                --------------------------------------------------- */
310 /*                |               q3 Cheby coefficients             | */
311 /*                --------------------------------------------------- */
312 /*                |         AV1 Cheby coefficients (optional)       | */
313 /*                --------------------------------------------------- */
314 /*                |         AV2 Cheby coefficients (optional)       | */
315 /*                --------------------------------------------------- */
316 /*                |         AV3 Cheby coefficients (optional)       | */
317 /*                --------------------------------------------------- */
318 
319 /* $ Detailed_Output */
320 
321 /*     CMAT       is a rotation matrix that transforms the components */
322 /*                of a vector expressed in the inertial frame given in */
323 /*                the segment to components expressed in the instrument */
324 /*                fixed frame at the returned time. */
325 
326 /*                Thus, if a vector v has components x, y, z in the */
327 /*                inertial frame, then v has components x', y', z' in */
328 /*                the instrument fixed frame where: */
329 
330 /*                     [ x' ]     [          ] [ x ] */
331 /*                     | y' |  =  |   CMAT   | | y | */
332 /*                     [ z' ]     [          ] [ z ] */
333 
334 /*                If the x', y', z' components are known, use the */
335 /*                transpose of the C-matrix to determine x, y, z as */
336 /*                follows. */
337 
338 /*                     [ x ]      [          ]T    [ x' ] */
339 /*                     | y |  =   |   CMAT   |     | y' | */
340 /*                     [ z ]      [          ]     [ z' ] */
341 /*                              (Transpose of CMAT) */
342 
343 /*     AV         is the angular velocity vector of the instrument fixed */
344 /*                frame defined by CMAT.  The angular velocity is */
345 /*                returned only if NEEDAV is true. */
346 
347 /*                The direction of the angular velocity vector gives */
348 /*                the right-handed axis about which the instrument fixed */
349 /*                reference frame is rotating. The magnitude of AV is */
350 /*                the magnitude of the instantaneous velocity of the */
351 /*                rotation, in radians per second. */
352 
353 /*                The angular velocity vector is returned in component */
354 /*                form */
355 
356 /*                         AV = [ AV1  , AV2  , AV3  ] */
357 
358 /*                which is in terms of the inertial coordinate frame */
359 /*                specified in the segment descriptor. */
360 
361 /*     CLKOUT     is the encoded SCLK associated with the returned */
362 /*                C-matrix and angular velocity vector. */
363 
364 /* $ Parameters */
365 
366 /*     See 'ckparam.inc'. */
367 
368 /* $ Exceptions */
369 
370 /*     Error free. */
371 
372 /*     No checking is done to determine whether RECORD is valid. */
373 
374 /* $ Files */
375 
376 /*     None. */
377 
378 /* $ Particulars */
379 
380 /*     For a detailed description of the structure of a type 4 pointing */
381 /*     segment, see the CK Required Reading file. */
382 
383 /*     The work done by CKE04 is to calculate quaternion and angular */
384 /*     velocity components using Chebyshev polynomial approximation */
385 /*     parameters. The second step of evaluation is to convert the */
386 /*     pointing portion of the record from quaternion form to C-matrix */
387 /*     form. */
388 
389 /*     The angular velocity vector will only be returned if it has been */
390 /*     requested. In other words, if NEEDAV is true, the routine will */
391 /*     expect the angular velocity component of the record to be */
392 /*     present. */
393 
394 /* $ Examples */
395 
396 /*     The CKRnn routines are usually used in tandem with the CKEnn */
397 /*     routines, which evaluate the record returned by CKRnn to give */
398 /*     the pointing information and output time. */
399 
400 /*     The following code fragment searches through all of the segments */
401 /*     in a file applicable to the Mars Global Surveyor spacecraft bus */
402 /*     that are of data type 4, for a particular spacecraft clock time. */
403 /*     It then evaluates the pointing for that epoch and prints the */
404 /*     result. */
405 
406 /*     C */
407 /*     C     CK parameters include file. */
408 /*     C */
409 /*           INCLUDE               'ckparam.inc' */
410 /*     C */
411 /*     C     Declarations */
412 /*     C */
413 /*           CHARACTER*(20)        SCLKCH */
414 /*           CHARACTER*(20)        SCTIME */
415 /*           CHARACTER*(40)        IDENT */
416 
417 /*           DOUBLE PRECISION      AV     ( 3 ) */
418 /*           DOUBLE PRECISION      CLKOUT */
419 /*           DOUBLE PRECISION      CMAT   ( 3, 3 ) */
420 /*           DOUBLE PRECISION      DCD    ( 2 ) */
421 /*           DOUBLE PRECISION      DESCR  ( 5 ) */
422 /*           DOUBLE PRECISION      RECORD ( CK4RSZ ) */
423 /*           DOUBLE PRECISION      SCLKDP */
424 /*           DOUBLE PRECISION      TOL */
425 
426 /*           INTEGER               HANDLE */
427 /*           INTEGER               I */
428 /*           INTEGER               ICD    ( 6 ) */
429 /*           INTEGER               INST */
430 /*           INTEGER               SC */
431 
432 /*           LOGICAL               FND */
433 /*           LOGICAL               NEEDAV */
434 /*           LOGICAL               SFND */
435 /*     C */
436 /*     C     Initial values. */
437 /*     C */
438 /*           SC     = -94 */
439 /*           INST   = -94000 */
440 /*           NEEDAV = .FALSE. */
441 /*     C */
442 /*     C     Load the MGS SCLK kernel and the C-kernel. */
443 /*     C */
444 /*           CALL FURNSH( 'MGS_SCLK.TSC' ) */
445 /*           CALL DAFOPR( 'MGS_CK4.BC', HANDLE ) */
446 /*     C */
447 /*     C     Get the spacecraft clock time. Then encode it for use */
448 /*     C     in the C-kernel. */
449 /*     C */
450 /*           CALL PROMPT( 'Enter SCLK string: ', SCLKCH ) */
451 /*           CALL SCENCD( SC, SCLKCH, SCLKDP ) */
452 /*     C */
453 /*     C     Use a tolerance of 2 seconds (half of the nominal */
454 /*     C     separation between MGS pointing instances ). */
455 /*     C */
456 /*           CALL SCTIKS ( SC, '0000000002:000', TOL ) */
457 /*     C */
458 /*     C     Search from the beginning of the CK file through all */
459 /*     C     of the segments. */
460 /*     C */
461 /*           CALL DAFBFS( HANDLE ) */
462 /*           CALL DAFFNA( SFND   ) */
463 
464 /*           FND = .FALSE. */
465 
466 /*           DO WHILE ( ( SFND ) .AND. ( .NOT. FND ) ) */
467 /*     C */
468 /*     C        Get the segment identifier and descriptor. */
469 /*     C */
470 /*              CALL DAFGN( IDENT ) */
471 /*              CALL DAFGS( DESCR ) */
472 /*     C */
473 /*     C        Unpack the segment descriptor into its integer and */
474 /*     C        double precision components. */
475 /*     C */
476 /*              CALL DAFUS( DESCR, 2, 6, DCD, ICD ) */
477 /*     C */
478 /*     C        Determine if this segment should be processed. */
479 /*     C */
480 /*              IF ( ( INST          .EQ. ICD( 1 ) ) .AND. */
481 /*          .        ( SCLKDP + TOL  .GE. DCD( 1 ) ) .AND. */
482 /*          .        ( SCLKDP - TOL  .LE. DCD( 2 ) ) .AND. */
483 /*          .        ( CK4DTP        .EQ. ICD( 3 ) )      ) THEN */
484 /*     C */
485 /*     C           Find CK 4 record covering requested time. */
486 /*     C */
487 /*                 CALL CKR04( HANDLE, DESCR, SCLKDP, TOL, NEEDAV, */
488 /*          .                  RECORD, FND ) */
489 
490 /*                 IF ( FND ) THEN */
491 /*     C */
492 /*     C              Compute pointing using found CK 4 record. */
493 /*     C */
494 /*                    CALL CKE04( NEEDAV, RECORD, CMAT, AV, CLKOUT) */
495 
496 /*                    CALL SCDECD( SC, CLKOUT, SCTIME ) */
497 
498 /*                    WRITE (*,*) */
499 /*                    WRITE (*,*) 'Segment identifier: ', IDENT */
500 /*                    WRITE (*,*) */
501 /*                    WRITE (*,*) 'Pointing returned for time: ', */
502 /*          .                      SCTIME */
503 /*                    WRITE (*,*) */
504 /*                    WRITE (*,*) 'C-matrix:' */
505 /*                    WRITE (*,*) */
506 /*                    WRITE (*,*) ( CMAT(1,I), I = 1, 3 ) */
507 /*                    WRITE (*,*) ( CMAT(2,I), I = 1, 3 ) */
508 /*                    WRITE (*,*) ( CMAT(3,I), I = 1, 3 ) */
509 /*                    WRITE (*,*) */
510 
511 /*                 END IF */
512 
513 /*              END IF */
514 
515 /*              CALL DAFFNA ( SFND ) */
516 
517 /*           END DO */
518 
519 /* $ Restrictions */
520 
521 /*     1) No checking is done on the input RECORD. */
522 
523 /* $ Literature_References */
524 
525 /*     None. */
526 
527 /* $ Author_and_Institution */
528 
529 /*     Y.K. Zaiko     (JPL) */
530 /*     B.V. Semenov   (JPL) */
531 
532 /* $ Version */
533 
534 /* -    SPICELIB Version 1.0.2, 18-APR-2014 (BVS) */
535 
536 /*        Minor header edits. */
537 
538 /* -    SPICELIB Version 1.0.1, 22-AUG-2006 (EDW) */
539 
540 /*        Replaced references to LDPOOL with references */
541 /*        to FURNSH. */
542 
543 /* -    SPICELIB Version 1.0.0, 05-MAY-1999 (YKZ) (BVS) */
544 
545 /* -& */
546 /* $ Index_Entries */
547 
548 /*     evaluate CK type_4 pointing data record */
549 
550 /* -& */
551 
552 /*     Local variables */
553 
554 
555 /*     Initial values. */
556 
557     av[0] = 0.;
558     av[1] = 0.;
559     av[2] = 0.;
560 
561 /*     Read numbers of polynomial coefficients from input record to */
562 /*     local integer array. */
563 
564     for (i__ = 1; i__ <= 7; ++i__) {
565 	ideg[(i__1 = i__ - 1) < 7 && 0 <= i__1 ? i__1 : s_rnge("ideg", i__1,
566 		"cke04_", (ftnlen)369)] = (integer) record[i__ + 2];
567     }
568 
569 /*     Evaluate polynomial function for quaternion components at time */
570 /*     RECORD( 1 ). */
571 
572     basadd = 11;
573     for (i__ = 1; i__ <= 4; ++i__) {
574 	i__3 = ideg[(i__1 = i__ - 1) < 7 && 0 <= i__1 ? i__1 : s_rnge("ideg",
575 		i__1, "cke04_", (ftnlen)380)] - 1;
576 	chbval_(&record[basadd - 1], &i__3, &record[1], record, &q[(i__2 =
577 		i__ - 1) < 4 && 0 <= i__2 ? i__2 : s_rnge("q", i__2, "cke04_",
578 		 (ftnlen)380)]);
579 	basadd += ideg[(i__1 = i__ - 1) < 7 && 0 <= i__1 ? i__1 : s_rnge(
580 		"ideg", i__1, "cke04_", (ftnlen)382)];
581     }
582 
583 /*     Normalize quaternion. */
584 
585     vhatg_(q, &c__4, qout);
586 
587 /*     Convert the quaternion to a C-matrix. */
588 
589     q2m_(qout, cmat);
590     *clkout = record[0];
591 
592 /*     Check if angular velocities have to be evaluated, then */
593 /*     evaluate them. */
594 
595     if (*needav) {
596 	for (i__ = 5; i__ <= 7; ++i__) {
597 	    i__3 = ideg[(i__1 = i__ - 1) < 7 && 0 <= i__1 ? i__1 : s_rnge(
598 		    "ideg", i__1, "cke04_", (ftnlen)406)] - 1;
599 	    chbval_(&record[basadd - 1], &i__3, &record[1], record, &av[(i__2
600 		    = i__ - 5) < 3 && 0 <= i__2 ? i__2 : s_rnge("av", i__2,
601 		    "cke04_", (ftnlen)406)]);
602 	    basadd += ideg[(i__1 = i__ - 1) < 7 && 0 <= i__1 ? i__1 : s_rnge(
603 		    "ideg", i__1, "cke04_", (ftnlen)408)];
604 	}
605     }
606 
607 /*     All done. */
608 
609     return 0;
610 } /* cke04_ */
611 
612