PageRenderTime 25ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/src/cke04.c

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