PageRenderTime 27ms CodeModel.GetById 27ms RepoModel.GetById 7ms app.codeStats 0ms

/src/ckgp_c.c

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