PageRenderTime 91ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/ckgpav_c.c

https://github.com/mattbornski/spice
C | 759 lines | 28 code | 16 blank | 715 comment | 0 complexity | 81bfbed513fc1301121c0f3efc9cebfb MD5 | raw file
  1. /*
  2. -Procedure ckgpav_c ( C-kernel, get pointing and angular velocity )
  3. -Abstract
  4. Get pointing (attitude) and angular velocity for a specified
  5. spacecraft clock time.
  6. -Disclaimer
  7. THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE
  8. CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.
  9. GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE
  10. ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE
  11. PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS"
  12. TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY
  13. WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A
  14. PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC
  15. SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
  16. SOFTWARE AND RELATED MATERIALS, HOWEVER USED.
  17. IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA
  18. BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT
  19. LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20. INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,
  21. REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE
  22. REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.
  23. RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF
  24. THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY
  25. CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE
  26. ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.
  27. -Required_Reading
  28. CK
  29. SCLK
  30. -Keywords
  31. POINTING
  32. */
  33. #include "SpiceUsr.h"
  34. #include "SpiceZfc.h"
  35. #include "SpiceZmc.h"
  36. void ckgpav_c ( SpiceInt inst,
  37. SpiceDouble sclkdp,
  38. SpiceDouble tol,
  39. ConstSpiceChar * ref,
  40. SpiceDouble cmat[3][3],
  41. SpiceDouble av[3],
  42. SpiceDouble * clkout,
  43. SpiceBoolean * found )
  44. /*
  45. -Brief_I/O
  46. Variable I/O Description
  47. -------- --- --------------------------------------------------
  48. inst I NAIF ID of instrument, spacecraft, or structure.
  49. sclkdp I Encoded spacecraft clock time.
  50. tol I Time tolerance.
  51. ref I Reference frame.
  52. cmat O C-matrix pointing data.
  53. av O Angular velocity vector.
  54. clkout O Output encoded spacecraft clock time.
  55. found O True when requested pointing is available.
  56. -Detailed_Input
  57. inst is the NAIF integer ID for the instrument, spacecraft, or
  58. other structure for which pointing and angular velocity
  59. are requested. For brevity we will refer to this object
  60. as the "instrument," and the frame fixed to this object
  61. as the "instrument frame" or "instrument-fixed" frame.
  62. sclkdp is the encoded spacecraft clock time for which
  63. pointing and angular velocity are requested.
  64. The CSPICE routines scencd_c and sce2c_c respectively
  65. convert spacecraft clock strings and ephemeris time
  66. to encoded spacecraft clock. The inverse conversions
  67. are performed by scdecd_c and sct2e_c.
  68. tol is a time tolerance in ticks, the units of encoded
  69. spacecraft clock time.
  70. The CSPICE routine sctiks_c converts a spacecraft clock
  71. tolerance duration from its character string
  72. representation to ticks. scfmt_c performs the inverse
  73. conversion.
  74. The C-matrix - angular velocity vector pair returned by
  75. ckgpav_c is the one whose time tag is closest to `sclkdp'
  76. and within `tol' units of `sclkdp'. (More in
  77. Particulars, below.)
  78. In general, because using a non-zero tolerance
  79. affects selection of the segment from which the
  80. data is obtained, users are strongly discouraged
  81. from using a non-zero tolerance when reading CKs
  82. with continuous data. Using a non-zero tolerance
  83. should be reserved exclusively to reading CKs with
  84. discrete data because in practice obtaining data
  85. from such CKs using a zero tolerance is often not
  86. possible due to time round off.
  87. ref is the desired reference frame for the returned pointing
  88. and angular velocity. The returned C-matrix `cmat' gives
  89. the orientation of the instrument designated by `inst'
  90. relative to the frame designated by `ref'. When a vector
  91. specified relative to frame `ref' is left-multiplied by
  92. `cmat', the vector is rotated to the frame associated
  93. with `inst'. The returned angular velocity vector `av'
  94. expresses the angular velocity of the instrument
  95. designated by `inst' relative to the frame designated by
  96. `ref'. See the discussion of `cmat' and `av' below
  97. for details.
  98. Consult the SPICE document "Frames" for a discussion
  99. of supported reference frames.
  100. -Detailed_Output
  101. cmat is a rotation matrix that transforms the components of a
  102. vector expressed in the frame specified by `ref' to
  103. components expressed in the frame tied to the instrument,
  104. spacecraft, or other structure at time `clkout' (see
  105. below).
  106. Thus, if a vector v has components x,y,z in the `ref'
  107. reference frame, then v has components x',y',z' in the
  108. instrument fixed frame at time `clkout':
  109. [ x' ] [ ] [ x ]
  110. | y' | = | cmat | | y |
  111. [ z' ] [ ] [ z ]
  112. If you know x', y', z', use the transpose of the
  113. C-matrix to determine x, y, z as follows:
  114. [ x ] [ ]T [ x' ]
  115. | y | = | cmat | | y' |
  116. [ z ] [ ] [ z' ]
  117. (Transpose of cmat)
  118. av is the angular velocity vector. This is the axis about
  119. which the reference frame tied to the instrument is
  120. rotating in the right-handed sense at time `clkout'. The
  121. magnitude of `av' is the magnitude of the instantaneous
  122. velocity of the rotation, in radians per second.
  123. The components of `av' are given relative to the
  124. reference frame specified by the input argument `ref'.
  125. clkout is the encoded spacecraft clock time associated with
  126. the returned C-matrix and the returned angular
  127. velocity vector. This value may differ from the
  128. requested time, but never by more than the input
  129. tolerance `tol'.
  130. The particulars section below describes the search
  131. algorithm used by ckgpav_c to satisfy a pointing request.
  132. This algorithm determines the pointing instance
  133. (and therefore the associated time value) that is
  134. returned.
  135. found is SPICETRUE if a record was found to satisfy the
  136. pointing request. `found' will be SPICEFALSE otherwise.
  137. -Parameters
  138. None.
  139. -Exceptions
  140. 1) If a C-kernel file has not been loaded using furnsh_c prior to a
  141. call to this routine, an error is signaled by a routine in the
  142. call tree of this routine.
  143. 2) If `tol' is negative, found is set to SPICEFALSE.
  144. 3) If `ref' is not a supported reference frame, an error is
  145. signaled by a routine in the call tree of this routine and
  146. `found' is set to SPICEFALSE.
  147. -Files
  148. ckgpav_c searches through files loaded by furnsh_c to locate a
  149. segment that satisfies the request for pointing and angular velocity
  150. for the instrument `inst' at time `sclkdp'. You must load at least
  151. one C-kernel file via furnsh_c prior to calling this routine.
  152. -Particulars
  153. How the tolerance argument is used
  154. ==================================
  155. Reading a type 1 CK segment (discrete pointing instances)
  156. ---------------------------------------------------------
  157. In the diagram below
  158. - "0" is used to represent discrete pointing instances
  159. (quaternions, angular velocity vectors, and associated
  160. time tags).
  161. - "( )" are used to represent the end points of the time
  162. interval covered by a segment in a CK file.
  163. - `sclkdp' is the time at which you requested pointing.
  164. The location of `sclkdp' relative to the time tags of the
  165. pointing instances is indicated by the "+" sign.
  166. - `tol' is the time tolerance specified in the pointing
  167. request. The square brackets "[ ]" represent the
  168. endpoints of the time interval
  169. sclkdp-tol : sclkdp+tol
  170. - The quaternions occurring in the segment need not be
  171. evenly spaced in time.
  172. Case 1: pointing is available
  173. ------------------------------
  174. sclkdp
  175. \ tol
  176. | /
  177. |/\
  178. Your request [--+--]
  179. . . .
  180. Segment (0-----0--0--0--0--0--0---0--0------------0--0--0--0)
  181. ^
  182. |
  183. ckgpav_c returns this instance.
  184. Case 2: pointing is not available
  185. ----------------------------------
  186. sclkdp
  187. \ tol
  188. | /
  189. |/\
  190. Your request [--+--]
  191. . . .
  192. Segment (0-----0--0--0--0--0--0---0--0--0---------0--0--0--0)
  193. ckgpav_c returns no pointing; the output
  194. `found' flag is set to SPICEFALSE.
  195. Reading a type 2, 3, 4, or 5 CK segment (continuous pointing)
  196. -------------------------------------------------------------
  197. In the diagrams below
  198. - "==" is used to represent periods of continuous pointing.
  199. - "--" is used to represent gaps in the pointing coverage.
  200. - "( )" are used to represent the end points of the time
  201. interval covered by a segment in a CK file.
  202. - `sclkdp' is the time at which you requested pointing.
  203. The location of `sclkdp' relative to the time tags of the
  204. pointing instances is indicated by the "+" sign.
  205. - `tol' is the time tolerance specified in the pointing
  206. request. The square brackets "[ ]" represent the
  207. endpoints of the time interval
  208. sclkdp-tol : sclkdp+tol
  209. - The quaternions occurring in the periods of continuous
  210. pointing need not be evenly spaced in time.
  211. Case 1: pointing is available at the request time
  212. --------------------------------------------------
  213. sclkdp
  214. \ tol
  215. | /
  216. |/\
  217. Your request [--+--]
  218. . . .
  219. . . .
  220. . . .
  221. Segment (==---===========---=======----------===--)
  222. ^
  223. |
  224. The request time lies within an interval where
  225. continuous pointing is available. ckgpav_c returns
  226. pointing at the requested epoch.
  227. Case 2: pointing is available "near" the request time
  228. ------------------------------------------------------
  229. sclkdp
  230. \ tol
  231. | /
  232. |/\
  233. Your request [--+--]
  234. . . .
  235. Segment (==---===========----=======---------===--)
  236. ^
  237. |
  238. The request time lies in a gap: an interval where
  239. continuous pointing is *not* available. ckgpav_c
  240. returns pointing for the epoch closest to the
  241. request time `sclkdp'.
  242. Case 3: pointing is not available
  243. ----------------------------------
  244. sclkdp
  245. \ tol
  246. | /
  247. |/\
  248. Your request [--+--]
  249. . . .
  250. Segment (==---===========----=======---------===--)
  251. ckgpav_c returns no pointing; the output
  252. `found' flag is set to SPICEFALSE.
  253. Tolerance and segment priority
  254. ==============================
  255. ckgpav_c searches through loaded C-kernels to satisfy a pointing
  256. request. Last-loaded files are searched first. Individual files are
  257. searched in backwards order, so that between competing segments
  258. (segments containing data for the same object, for overlapping time
  259. ranges), the one closest to the end of the file has highest
  260. priority. ckgpav_c considers only those segments that contain both
  261. pointing and angular velocity data, as indicated by the segment
  262. descriptor.
  263. The search ends when a segment is found that can provide pointing
  264. and angular velocity for the specified instrument at a time
  265. falling within the specified tolerance on either side of the
  266. request time. Within that segment, the instance closest to the
  267. input time is located and returned.
  268. The following four cases illustrate this search procedure. Segments
  269. A and B are in the same file, with segment A located further
  270. towards the end of the file than segment B. Both segments A and B
  271. contain discrete pointing data, indicated by the number 0.
  272. Case 1: Pointing is available in the first segment searched.
  273. Because segment A has the highest priority and can
  274. satisfy the request, segment B is not searched.
  275. sclkdp
  276. \ tol
  277. | /
  278. |/\
  279. Your request [--+--]
  280. . . .
  281. Segment A (0-----------------0--------0--0-----0)
  282. ^
  283. |
  284. |
  285. ckgpav_c returns this instance
  286. Segment B (0--0--0--0--0--0--0--0--0--0--0--0--0--0--0--0--0)
  287. Case 2: Pointing is not available in the first segment searched.
  288. Because segment A cannot satisfy the request, segment B
  289. is searched.
  290. sclkdp
  291. \ tol
  292. | /
  293. |/\
  294. Your request [--+--]
  295. . . .
  296. Segment A (0-----------------0--------0--0-----0)
  297. . . .
  298. Segment B (0--0--0--0--0--0--0--0--0--0--0--0--0--0--0--0--0)
  299. ^
  300. |
  301. ckgpav_c returns this instance
  302. Segments that contain continuous pointing data are searched in the
  303. same manner as segments containing discrete pointing data. For
  304. request times that fall within the bounds of continuous intervals,
  305. ckgpav_c will return pointing at the request time. When the request
  306. time does not fall within an interval, then a time at an endpoint of
  307. an interval may be returned if it is the closest time in the segment
  308. to the user request time and is also within the tolerance.
  309. In the following examples, segment A is located further towards the
  310. end of the file than segment C. Segment A contains discrete pointing
  311. data and segment C contains continuous data, indicated by the "="
  312. character.
  313. Case 3: Pointing is not available in the first segment searched.
  314. Because segment A cannot satisfy the request, segment C
  315. is searched.
  316. sclkdp
  317. \ tol
  318. | /
  319. |/\
  320. Your request [--+--]
  321. . . .
  322. . . .
  323. Segment A (0-----------------0--------0--0-----0)
  324. . . .
  325. . . .
  326. Segment C (---=============-----====--------==--)
  327. ^
  328. |
  329. |
  330. ckgpav_c returns this instance
  331. In the next case, assume that the order of segments A and C in the
  332. file is reversed: A is now closer to the front, so data from
  333. segment C are considered first.
  334. Case 4: Pointing is available in the first segment searched.
  335. Because segment C has the highest priority and can
  336. satisfy the request, segment A is not searched.
  337. sclkdp
  338. /
  339. | tol
  340. | /
  341. |/\
  342. Your request [--+--]
  343. . . .
  344. . . .
  345. Segment C (---=============-----====--------==--)
  346. ^
  347. |
  348. ckgpav_c returns this instance
  349. Segment A (0-----------------0--------0--0-----0)
  350. ^
  351. |
  352. "Best" answer
  353. The next case illustrates an unfortunate side effect of using
  354. a non-zero tolerance when reading multi-segment CKs with
  355. continuous data. In all cases when the look-up interval
  356. formed using tolerance overlaps a segment boundary and
  357. the request time falls within the coverage of the lower
  358. priority segment, the data at the end of the higher priority
  359. segment will be picked instead of the data from the lower
  360. priority segment.
  361. Case 5: Pointing is available in the first segment searched.
  362. Because segment C has the highest priority and can
  363. satisfy the request, segment A is not searched.
  364. sclkdp
  365. /
  366. | tol
  367. | /
  368. |/\
  369. Your request [--+--]
  370. . . .
  371. . . .
  372. Segment C (===============)
  373. ^
  374. |
  375. ckgpav_c returns this instance
  376. Segment A (=====================)
  377. ^
  378. |
  379. "Best" answer
  380. -Examples
  381. Suppose you have two C-kernel files containing pointing for the
  382. Voyager 2 narrow angle camera. One file contains predict (planned)
  383. values, and the other contains corrected pointing for a selected
  384. group of images, that is, for a subset of images from the first
  385. file.
  386. The following example program uses ckgpav_c to get C-matrices and
  387. associated angular velocity vectors for a set of images whose
  388. SCLK counts (un-encoded character string versions) are contained
  389. in the array `sclkch'.
  390. If available, the program will get the corrected pointing values.
  391. Otherwise, predict values will be used.
  392. For each C-matrix, a unit pointing vector is constructed and printed
  393. along with the angular velocity vector.
  394. Note: if the C-kernels of interest do not contain angular velocity
  395. data, then the CSPICE routine ckgp_c should be used to read the
  396. pointing data. An example program in the header of the CSPICE
  397. routine ckgp_c demonstrates this.
  398. #include <stdio.h>
  399. #include "SpiceUsr.h"
  400. int main ()
  401. {
  402. /.
  403. Constants for this program:
  404. -- The code for the Voyager 2 spacecraft clock is -32
  405. -- The code for the narrow angle camera on the Voyager 2
  406. spacecraft is -32001.
  407. -- Spacecraft clock times for successive Voyager images always
  408. differ by more than 0:0:400. This is an acceptable
  409. tolerance, and must be converted to "ticks" (units of
  410. encoded SCLK) for input to ckgpav_c.
  411. -- The reference frame we want is FK4.
  412. -- The narrow angle camera boresight defines the third
  413. axis of the instrument-fixed reference frame.
  414. Therefore, the vector ( 0, 0, 1 ) represents
  415. the boresight direction in the camera-fixed frame.
  416. ./
  417. #define SC -32
  418. #define INST -32001
  419. #define REF "FK4"
  420. #define TOLVGR "0:0:400"
  421. #define NPICS 2
  422. #define MAXCLK 30
  423. #define CKPRED "voyager2_predict.bc"
  424. #define CKCORR "voyager2_corrected.bc"
  425. #define SCLK "voyager2_sclk.tsc"
  426. SpiceBoolean found;
  427. SpiceChar sclkch [NPICS][MAXCLK] =
  428. { { "4/08966:30:768" },
  429. { "4/08970:58:768" } };
  430. SpiceChar clkch [MAXCLK];
  431. SpiceDouble av [3];
  432. SpiceDouble cmat [3][3];
  433. SpiceDouble clkout;
  434. SpiceDouble sclkdp;
  435. SpiceDouble toltik;
  436. SpiceDouble vinert [3];
  437. SpiceInt i;
  438. /.
  439. Loading the files in this order ensures that the
  440. corrected file will get searched first.
  441. ./
  442. furnsh_c ( CKPRED );
  443. furnsh_c ( CKCORR );
  444. /.
  445. Need to load a Voyager 2 SCLK kernel to convert from
  446. clock string to ticks. Although not required for
  447. the Voyager spacecraft clocks, most modern spacecraft
  448. clocks require a leapseconds kernel to be loaded in
  449. addition to an SCLK kernel.
  450. ./
  451. furnsh_c ( SCLK );
  452. /.
  453. Convert tolerance from VGR formatted character string
  454. SCLK to ticks, which are units of encoded SCLK.
  455. ./
  456. sctiks_c ( SC, TOLVGR, &toltik );
  457. for ( i = 0; i < NPICS; i++ )
  458. {
  459. /.
  460. ckgpav_c requires encoded spacecraft clock time.
  461. ./
  462. scencd_c ( SC, sclkch[ i ], &sclkdp );
  463. ckgpav_c ( INST, sclkdp, toltik, REF,
  464. cmat, av, &clkout, &found );
  465. if ( found )
  466. {
  467. /.
  468. The boresight vector, relative to inertial coordinates,
  469. is just the third row of the C-matrix.
  470. ./
  471. vequ_c ( cmat[2], vinert );
  472. scdecd_c ( SC, clkout, MAXCLK, clkch );
  473. printf ( "VGR 2 SCLK time: %s\n", clkch );
  474. printf ( "VGR 2 NA ISS boresight pointing vector: "
  475. "%f %f %f\n",
  476. vinert[0],
  477. vinert[1],
  478. vinert[2] );
  479. printf ( "Angular velocity vector: %f %f %f\n",
  480. av[0],
  481. av[1],
  482. av[2] );
  483. }
  484. else
  485. {
  486. printf ( "Pointing not found for time %s\n", sclkch[i] );
  487. }
  488. }
  489. return ( 0 );
  490. }
  491. -Restrictions
  492. Only loaded C-kernel segments containing both pointing and angular
  493. velocity data will be searched by this reader. Segments containing
  494. only pointing data will be skipped over.
  495. -Literature_References
  496. None.
  497. -Author_and_Institution
  498. C.H. Acton (JPL)
  499. N.J. Bachman (JPL)
  500. W.L. Taber (JPL)
  501. J.M. Lynch (JPL)
  502. B.V. Semenov (JPL)
  503. M.J. Spencer (JPL)
  504. R.E. Thurman (JPL)
  505. I.M. Underwood (JPL)
  506. -Version
  507. -CSPICE Version 1.2.3, 03-JUN-2010 (BVS)
  508. Header update: description of the tolerance and Particulars
  509. section were expanded to address some problems arising from
  510. using a non-zero tolerance.
  511. -CSPICE Version 1.2.2, 29-JAN-2004 (NJB)
  512. Header update: the description of the input argument `ref'
  513. was expanded.
  514. -CSPICE Version 1.2.1, 27-JUL-2003 (CHA) (NJB)
  515. Various header corrections were made.
  516. -CSPICE Version 1.2.0, 02-SEP-1999 (NJB)
  517. Local type logical variable now used for found flag used in
  518. interface of ckgpav_.
  519. -CSPICE Version 1.1.0, 08-FEB-1998 (NJB)
  520. References to C2F_CreateStr_Sig were removed; code was
  521. cleaned up accordingly. String checks are now done using
  522. the macro CHKFSTR.
  523. -CSPICE Version 1.0.0, 25-OCT-1997 (NJB)
  524. Based on SPICELIB Version 5.0.0, 28-JUL-1997 (WLT)
  525. -Index_Entries
  526. get ck pointing and angular velocity
  527. -&
  528. */
  529. { /* Begin ckgpav_c */
  530. /*
  531. Local variables
  532. */
  533. logical fnd;
  534. /*
  535. Participate in error handling
  536. */
  537. chkin_c ( "ckgpav_c");
  538. /*
  539. Check the input string ref to make sure the pointer is non-null
  540. and the string length is non-zero.
  541. */
  542. CHKFSTR ( CHK_STANDARD, "ckgpav_c", ref );
  543. ckgpav_( ( integer * ) &inst,
  544. ( doublereal * ) &sclkdp,
  545. ( doublereal * ) &tol,
  546. ( char * ) ref,
  547. ( doublereal * ) cmat,
  548. ( doublereal * ) av,
  549. ( doublereal * ) clkout,
  550. ( logical * ) &fnd,
  551. ( ftnlen ) strlen(ref) );
  552. /*
  553. Assign the SpiceBoolean found flag.
  554. */
  555. *found = fnd;
  556. /*
  557. Transpose the c-matrix on output.
  558. */
  559. xpose_c ( cmat, cmat );
  560. chkout_c ( "ckgpav_c");
  561. } /* End ckgpav_c */