PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/cke03.c

https://github.com/mattbornski/spice
C | 545 lines | 66 code | 147 blank | 332 comment | 7 complexity | 49e1e3bf4aa078a87b546e2c27e9ab69 MD5 | raw file
  1. /* cke03.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. #include "f2c.h"
  6. /* Table of constant values */
  7. static integer c__4 = 4;
  8. static integer c__3 = 3;
  9. /* $Procedure CKE03 ( C-kernel, evaluate pointing record, data type 3 ) */
  10. /* Subroutine */ int cke03_(logical *needav, doublereal *record, doublereal *
  11. cmat, doublereal *av, doublereal *clkout)
  12. {
  13. /* System generated locals */
  14. doublereal d__1;
  15. /* Local variables */
  16. doublereal frac, axis[3];
  17. extern /* Subroutine */ int vequ_(doublereal *, doublereal *), mtxm_(
  18. doublereal *, doublereal *, doublereal *), mxmt_(doublereal *,
  19. doublereal *, doublereal *);
  20. doublereal cmat1[9] /* was [3][3] */, cmat2[9] /* was [3][3] */, t,
  21. angle, delta[9] /* was [3][3] */;
  22. extern /* Subroutine */ int chkin_(char *, ftnlen), moved_(doublereal *,
  23. integer *, doublereal *), vlcom_(doublereal *, doublereal *,
  24. doublereal *, doublereal *, doublereal *);
  25. doublereal q1[4], q2[4], t1, t2;
  26. extern logical failed_(void);
  27. extern /* Subroutine */ int raxisa_(doublereal *, doublereal *,
  28. doublereal *), axisar_(doublereal *, doublereal *, doublereal *),
  29. chkout_(char *, ftnlen);
  30. doublereal av1[3], av2[3];
  31. extern logical return_(void);
  32. extern /* Subroutine */ int q2m_(doublereal *, doublereal *);
  33. doublereal rot[9] /* was [3][3] */;
  34. /* $ Abstract */
  35. /* Evaluate a pointing record returned by CKR03 from a CK type 3 */
  36. /* segment. Return the C-matrix and angular velocity vector associated */
  37. /* with the time CLKOUT. */
  38. /* $ Disclaimer */
  39. /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
  40. /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
  41. /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
  42. /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
  43. /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
  44. /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
  45. /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
  46. /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
  47. /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
  48. /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
  49. /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
  50. /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
  51. /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
  52. /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
  53. /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
  54. /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
  55. /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
  56. /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
  57. /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
  58. /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
  59. /* $ Required_Reading */
  60. /* CK */
  61. /* ROTATION */
  62. /* $ Keywords */
  63. /* POINTING */
  64. /* $ Declarations */
  65. /* $ Brief_I/O */
  66. /* Variable I/O Description */
  67. /* -------- --- -------------------------------------------------- */
  68. /* NEEDAV I True if angular velocity is requested. */
  69. /* RECORD I Data type 3 pointing record. */
  70. /* CMAT O C-matrix. */
  71. /* AV O Angular velocity vector. */
  72. /* CLKOUT O SCLK associated with C-matrix. */
  73. /* $ Detailed_Input */
  74. /* NEEDAV is true if angular velocity is requested. */
  75. /* RECORD is a set of double precision numbers returned by CKR03 */
  76. /* that contain sufficient information from a type 3 CK */
  77. /* segment to evaluate the C-matrix and the angular */
  78. /* velocity vector at a particular time. Depending on */
  79. /* the contents of RECORD, this routine will either */
  80. /* interpolate between two pointing instances that */
  81. /* bracket a request time, or it will simply return the */
  82. /* pointing given by a single pointing instance. */
  83. /* When pointing at the request time can be determined */
  84. /* by linearly interpolating between the two pointing */
  85. /* instances that bracket that time, the bracketing */
  86. /* pointing instances are returned in RECORD as follows: */
  87. /* RECORD( 1 ) = Left bracketing SCLK time. */
  88. /* RECORD( 2 ) = lq0 \ */
  89. /* RECORD( 3 ) = lq1 \ Left bracketing */
  90. /* RECORD( 4 ) = lq2 / quaternion. */
  91. /* RECORD( 5 ) = lq3 / */
  92. /* RECORD( 6 ) = lav1 \ Left bracketing */
  93. /* RECORD( 7 ) = lav2 | angular velocity */
  94. /* RECORD( 8 ) = lav3 / ( optional ) */
  95. /* RECORD( 9 ) = Right bracketing SCLK time. */
  96. /* RECORD( 10 ) = rq0 \ */
  97. /* RECORD( 11 ) = rq1 \ Right bracketing */
  98. /* RECORD( 12 ) = rq2 / quaternion. */
  99. /* RECORD( 13 ) = rq3 / */
  100. /* RECORD( 14 ) = rav1 \ Right bracketing */
  101. /* RECORD( 15 ) = rav2 | angular velocity */
  102. /* RECORD( 16 ) = rav3 / ( optional ) */
  103. /* RECORD( 17 ) = pointing request time */
  104. /* The quantities lq0 - lq3 and rq0 - rq3 are the */
  105. /* components of the quaternions that represent the */
  106. /* C-matrices associated with the times that bracket */
  107. /* the requested time. */
  108. /* The quantities lav1, lav2, lav3 and rav1, rav2, rav3 */
  109. /* are the components of the angular velocity vectors at */
  110. /* the respective bracketing times. The components of the */
  111. /* angular velocity vectors are specified relative to the */
  112. /* inertial reference frame of the segment. */
  113. /* When the routine is to simply return the pointing */
  114. /* given by a particular pointing instance, then the */
  115. /* values of that pointing instance are returned in both */
  116. /* parts of RECORD ( i.e. RECORD(1-9) and RECORD(10-16) ). */
  117. /* $ Detailed_Output */
  118. /* CMAT is a rotation matrix that transforms the components */
  119. /* of a vector expressed in the inertial frame given in */
  120. /* the segment to components expressed in the instrument */
  121. /* fixed frame at the returned time. */
  122. /* Thus, if a vector v has components x, y, z in the */
  123. /* inertial frame, then v has components x', y', z' in the */
  124. /* instrument fixed frame where: */
  125. /* [ x' ] [ ] [ x ] */
  126. /* | y' | = | CMAT | | y | */
  127. /* [ z' ] [ ] [ z ] */
  128. /* If the x', y', z' components are known, use the */
  129. /* transpose of the C-matrix to determine x, y, z as */
  130. /* follows. */
  131. /* [ x ] [ ]T [ x' ] */
  132. /* | y | = | CMAT | | y' | */
  133. /* [ z ] [ ] [ z' ] */
  134. /* (Transpose of CMAT) */
  135. /* AV is the angular velocity vector of the instrument fixed */
  136. /* frame defined by CMAT. The angular velocity is */
  137. /* returned only if NEEDAV is true. */
  138. /* The direction of the angular velocity vector gives */
  139. /* the right-handed axis about which the instrument fixed */
  140. /* reference frame is rotating. The magnitude of AV is */
  141. /* the magnitude of the instantaneous velocity of the */
  142. /* rotation, in radians per second. */
  143. /* The angular velocity vector is returned in component */
  144. /* form */
  145. /* AV = [ AV1 , AV2 , AV3 ] */
  146. /* which is in terms of the inertial coordinate frame */
  147. /* specified in the segment descriptor. */
  148. /* CLKOUT is the encoded SCLK associated with the returned */
  149. /* C-matrix and angular velocity vector. */
  150. /* $ Parameters */
  151. /* None. */
  152. /* $ Exceptions */
  153. /* 1) No explicit checking is done to determine whether RECORD is */
  154. /* valid. However, routines in the call tree of this routine */
  155. /* may signal errors if inputs are invalid or otherwise */
  156. /* in appropriate. */
  157. /* $ Files */
  158. /* None. */
  159. /* $ Particulars */
  160. /* If the array RECORD contains pointing instances that bracket the */
  161. /* request time then CKE03 will linearly interpolate between those */
  162. /* two values to obtain pointing at the request time. If the */
  163. /* pointing instances in RECORD are for the same time, then this */
  164. /* routine will simply unpack the record and convert the quaternion */
  165. /* to a C-matrix. */
  166. /* The linear interpolation performed by this routine is defined */
  167. /* as follows: */
  168. /* 1) Let t be the time for which pointing is requested and */
  169. /* let CMAT1 and CMAT2 be C-matrices associated with times */
  170. /* t1 and t2 where: */
  171. /* t1 < t2, and t1 <= t, and t <= t2. */
  172. /* 2) Assume that the spacecraft frame rotates about a fixed */
  173. /* axis at a constant angular rate from time t1 to time t2. */
  174. /* The angle and rotation axis can be obtained from the */
  175. /* rotation matrix ROT12 where: */
  176. /* T T */
  177. /* CMAT2 = ROT12 * CMAT1 */
  178. /* or */
  179. /* T */
  180. /* ROT12 = CMAT2 * CMAT1 */
  181. /* ROT12 ==> ( ANGLE, AXIS ) */
  182. /* 3) To obtain pointing at time t, rotate the spacecraft frame */
  183. /* about the vector AXIS from its orientation at time t1 by the */
  184. /* angle THETA where: */
  185. /* ( t - t1 ) */
  186. /* THETA = ANGLE * ----------- */
  187. /* ( t2 - t1 ) */
  188. /* 4) Thus if ROT1t is the matrix that rotates vectors by the */
  189. /* angle THETA about the vector AXIS, then the output C-matrix */
  190. /* is given by: */
  191. /* T T */
  192. /* CMAT = ROT1t * CMAT1 */
  193. /* T */
  194. /* CMAT = CMAT1 * ROT1t */
  195. /* 5) The angular velocity is treated independently of the */
  196. /* C-matrix. If it is requested, then the AV at time t is */
  197. /* the weighted average of the angular velocity vectors at */
  198. /* the times t1 and t2: */
  199. /* ( t - t1 ) */
  200. /* W = ----------- */
  201. /* ( t2 - t1 ) */
  202. /* AV = ( 1 - W ) * AV1 + W * AV2 */
  203. /* $ Examples */
  204. /* The CKRnn routines are usually used in tandem with the CKEnn */
  205. /* routines, which evaluate the record returned by CKRnn to give */
  206. /* the pointing information and output time. */
  207. /* The following code fragment searches through all of the segments */
  208. /* in a file applicable to the Mars Observer spacecraft bus that */
  209. /* are of data type 3, for a particular spacecraft clock time. */
  210. /* It then evaluates the pointing for that epoch and prints the */
  211. /* result. */
  212. /* CHARACTER*(20) SCLKCH */
  213. /* CHARACTER*(20) SCTIME */
  214. /* CHARACTER*(40) IDENT */
  215. /* INTEGER I */
  216. /* INTEGER SC */
  217. /* INTEGER INST */
  218. /* INTEGER HANDLE */
  219. /* INTEGER DTYPE */
  220. /* INTEGER ICD ( 6 ) */
  221. /* DOUBLE PRECISION SCLKDP */
  222. /* DOUBLE PRECISION TOL */
  223. /* DOUBLE PRECISION CLKOUT */
  224. /* DOUBLE PRECISION DESCR ( 5 ) */
  225. /* DOUBLE PRECISION DCD ( 2 ) */
  226. /* DOUBLE PRECISION RECORD ( 17 ) */
  227. /* DOUBLE PRECISION CMAT ( 3, 3 ) */
  228. /* DOUBLE PRECISION AV ( 3 ) */
  229. /* LOGICAL NEEDAV */
  230. /* LOGICAL FND */
  231. /* LOGICAL SFND */
  232. /* SC = -94 */
  233. /* INST = -94000 */
  234. /* DTYPE = 3 */
  235. /* NEEDAV = .FALSE. */
  236. /* C */
  237. /* C Load the MO SCLK kernel and the C-kernel. */
  238. /* C */
  239. /* CALL FURNSH ( 'MO_SCLK.TSC' ) */
  240. /* CALL DAFOPR ( 'MO_CK.BC', HANDLE ) */
  241. /* C */
  242. /* C Get the spacecraft clock time. Then encode it for use */
  243. /* C in the C-kernel. */
  244. /* C */
  245. /* WRITE (*,*) 'Enter spacecraft clock time string:' */
  246. /* READ (*,FMT='(A)') SCLKCH */
  247. /* CALL SCENCD ( SC, SCLKCH, SCLKDP ) */
  248. /* C */
  249. /* C Use a tolerance of 2 seconds ( half of the nominal */
  250. /* C separation between MO pointing instances ). */
  251. /* C */
  252. /* CALL SCTIKS ( SC, '0000000002:000', TOL ) */
  253. /* C */
  254. /* C Search from the beginning of the CK file through all */
  255. /* C of the segments. */
  256. /* C */
  257. /* CALL DAFBFS ( HANDLE ) */
  258. /* CALL DAFFNA ( SFND ) */
  259. /* FND = .FALSE. */
  260. /* DO WHILE ( ( SFND ) .AND. ( .NOT. FND ) ) */
  261. /* C */
  262. /* C Get the segment identifier and descriptor. */
  263. /* C */
  264. /* CALL DAFGN ( IDENT ) */
  265. /* CALL DAFGS ( DESCR ) */
  266. /* C */
  267. /* C Unpack the segment descriptor into its integer and */
  268. /* C double precision components. */
  269. /* C */
  270. /* CALL DAFUS ( DESCR, 2, 6, DCD, ICD ) */
  271. /* C */
  272. /* C Determine if this segment should be processed. */
  273. /* C */
  274. /* IF ( ( INST .EQ. ICD( 1 ) ) .AND. */
  275. /* . ( SCLKDP + TOL .GE. DCD( 1 ) ) .AND. */
  276. /* . ( SCLKDP - TOL .LE. DCD( 2 ) ) .AND. */
  277. /* . ( DTYPE .EQ. ICD( 3 ) ) ) THEN */
  278. /* CALL CKR03 ( HANDLE, DESCR, SCLKDP, TOL, NEEDAV, */
  279. /* . RECORD, FND ) */
  280. /* IF ( FND ) THEN */
  281. /* CALL CKE03 (NEEDAV,RECORD,CMAT,AV,CLKOUT) */
  282. /* CALL SCDECD ( SC, CLKOUT, SCTIME ) */
  283. /* WRITE (*,*) */
  284. /* WRITE (*,*) 'Segment identifier: ', IDENT */
  285. /* WRITE (*,*) */
  286. /* WRITE (*,*) 'Pointing returned for time: ', */
  287. /* . SCTIME */
  288. /* WRITE (*,*) */
  289. /* WRITE (*,*) 'C-matrix:' */
  290. /* WRITE (*,*) */
  291. /* WRITE (*,*) ( CMAT(1,I), I = 1, 3 ) */
  292. /* WRITE (*,*) ( CMAT(2,I), I = 1, 3 ) */
  293. /* WRITE (*,*) ( CMAT(3,I), I = 1, 3 ) */
  294. /* WRITE (*,*) */
  295. /* END IF */
  296. /* END IF */
  297. /* CALL DAFFNA ( SFND ) */
  298. /* END DO */
  299. /* $ Restrictions */
  300. /* 1) No explicit checking is done on the input RECORD. */
  301. /* $ Literature_References */
  302. /* None. */
  303. /* $ Author_and_Institution */
  304. /* J.M. Lynch (JPL) */
  305. /* F.S. Turner (JPL) */
  306. /* $ Version */
  307. /* - SPICELIB Version 2.0.1, 22-AUG-2006 (EDW) */
  308. /* Replaced references to LDPOOL with references */
  309. /* to FURNSH. */
  310. /* - SPICELIB Version 2.0.0, 13-JUN-2002 (FST) */
  311. /* This routine now participates in error handling properly. */
  312. /* - SPICELIB Version 1.0.0, 25-NOV-1992 (JML) */
  313. /* -& */
  314. /* $ Index_Entries */
  315. /* evaluate ck type_3 pointing data record */
  316. /* -& */
  317. /* $ Revisions */
  318. /* - SPICELIB Version 2.0.0, 13-JUN-2002 (FST) */
  319. /* Calls to CHKIN and CHKOUT in the standard SPICE error */
  320. /* handling style were added. Versions prior to 2.0.0 */
  321. /* were error free, however changes to RAXISA from error */
  322. /* free to error signaling forced this update. */
  323. /* Additionally, FAILED is now checked after the call to */
  324. /* RAXISA. This prevents garbage from being placed into */
  325. /* the output arguments. */
  326. /* -& */
  327. /* SPICELIB functions */
  328. /* Local variables */
  329. /* Standard SPICE error handling. */
  330. if (return_()) {
  331. return 0;
  332. } else {
  333. chkin_("CKE03", (ftnlen)5);
  334. }
  335. /* Unpack the record, for easier reading. */
  336. t = record[16];
  337. t1 = record[0];
  338. t2 = record[8];
  339. moved_(&record[1], &c__4, q1);
  340. moved_(&record[5], &c__3, av1);
  341. moved_(&record[9], &c__4, q2);
  342. moved_(&record[13], &c__3, av2);
  343. /* If T1 and T2 are the same then no interpolation or extrapolation */
  344. /* is performed. Simply convert the quaternion to a C-matrix and */
  345. /* return. */
  346. if (t1 == t2) {
  347. q2m_(q1, cmat);
  348. *clkout = t1;
  349. if (*needav) {
  350. vequ_(av1, av);
  351. }
  352. chkout_("CKE03", (ftnlen)5);
  353. return 0;
  354. }
  355. /* Interpolate between the two pointing instances to obtain pointing */
  356. /* at the request time. */
  357. /* Calculate what fraction of the interval the request time */
  358. /* represents. */
  359. frac = (t - t1) / (t2 - t1);
  360. /* Convert the left and right quaternions to C-matrices. */
  361. q2m_(q1, cmat1);
  362. q2m_(q2, cmat2);
  363. /* Find the matrix that rotates the spacecraft instrument frame from */
  364. /* the orientation specified by CMAT1 to that specified by CMAT2. */
  365. /* Then find the axis and angle of that rotation matrix. */
  366. /* T T */
  367. /* CMAT2 = ROT * CMAT1 */
  368. /* T */
  369. /* ROT = CMAT2 * CMAT1 */
  370. mtxm_(cmat2, cmat1, rot);
  371. raxisa_(rot, axis, &angle);
  372. if (failed_()) {
  373. chkout_("CKE03", (ftnlen)5);
  374. return 0;
  375. }
  376. /* Calculate the matrix that rotates vectors about the vector AXIS */
  377. /* by the angle ANGLE * FRAC. */
  378. d__1 = angle * frac;
  379. axisar_(axis, &d__1, delta);
  380. /* The interpolated pointing at the request time is given by CMAT */
  381. /* where: */
  382. /* T T */
  383. /* CMAT = DELTA * CMAT1 */
  384. /* and */
  385. /* T */
  386. /* CMAT = CMAT1 * DELTA */
  387. mxmt_(cmat1, delta, cmat);
  388. /* Set CLKOUT equal to the time that pointing is being returned. */
  389. *clkout = t;
  390. /* If angular velocity is requested then take a weighted average */
  391. /* of the angular velocities at the left and right endpoints. */
  392. if (*needav) {
  393. d__1 = 1. - frac;
  394. vlcom_(&d__1, av1, &frac, av2, av);
  395. }
  396. chkout_("CKE03", (ftnlen)5);
  397. return 0;
  398. } /* cke03_ */