PageRenderTime 33ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/ckgr01.c

https://github.com/mattbornski/spice
C | 403 lines | 56 code | 107 blank | 240 comment | 9 complexity | 6340fa88ac8ff1377c62a321b258c54e MD5 | raw file
  1. /* ckgr01.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__2 = 2;
  8. static integer c__6 = 6;
  9. /* $Procedure CKGR01 ( C-kernel, get record, type 01 ) */
  10. /* Subroutine */ int ckgr01_(integer *handle, doublereal *descr, integer *
  11. recno, doublereal *record)
  12. {
  13. /* System generated locals */
  14. integer i__1;
  15. /* Local variables */
  16. integer addr__, nrec, psiz;
  17. doublereal n;
  18. extern /* Subroutine */ int chkin_(char *, ftnlen), dafus_(doublereal *,
  19. integer *, integer *, doublereal *, integer *), dafgda_(integer *,
  20. integer *, integer *, doublereal *), sigerr_(char *, ftnlen),
  21. chkout_(char *, ftnlen), setmsg_(char *, ftnlen), errint_(char *,
  22. integer *, ftnlen);
  23. extern logical return_(void);
  24. doublereal dcd[2];
  25. integer beg, icd[6];
  26. /* $ Abstract */
  27. /* Given the handle and descriptor of a data type 1 segment in a */
  28. /* CK file, return a specified pointing record from that segment. */
  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 */
  52. /* DAF */
  53. /* $ Keywords */
  54. /* POINTING */
  55. /* $ Declarations */
  56. /* $ Brief_I/O */
  57. /* Variable I/O Description */
  58. /* -------- --- -------------------------------------------------- */
  59. /* HANDLE I The handle of the file containing the segment. */
  60. /* DESCR I The segment descriptor. */
  61. /* RECNO I The number of the pointing record to be returned. */
  62. /* RECORD O The pointing record. */
  63. /* $ Detailed_Input */
  64. /* HANDLE is the handle of the binary CK file containing the */
  65. /* desired segment. The file should have been opened */
  66. /* for read access, either by CKLPF or DAFOPR. */
  67. /* DESCR is the packed descriptor of the data type 1 segment. */
  68. /* RECNO is the number of the individual pointing record to be */
  69. /* returned from the data type 1 segment. */
  70. /* $ Detailed_Output */
  71. /* RECORD is the pointing record indexed by RECNO in the segment. */
  72. /* The contents are as follows: */
  73. /* RECORD( 1 ) = CLKOUT */
  74. /* RECORD( 2 ) = q0 */
  75. /* RECORD( 3 ) = q1 */
  76. /* RECORD( 4 ) = q2 */
  77. /* RECORD( 5 ) = q3 */
  78. /* RECORD( 6 ) = Av1 ] */
  79. /* RECORD( 7 ) = Av2 |-- Returned optionally */
  80. /* RECORD( 8 ) = Av3 ] */
  81. /* CLKOUT is the encoded spacecraft clock time associated */
  82. /* with the returned pointing values. */
  83. /* The quantities q0 - q3 represent a quaternion. */
  84. /* The quantities Av1, Av2, and Av3 represent the */
  85. /* angular velocity vector, and are returned only if the */
  86. /* segment contains angular velocity data. The */
  87. /* components of the angular velocity vector are */
  88. /* specified relative to the inertial reference */
  89. /* frame of the segment. */
  90. /* $ Parameters */
  91. /* None. */
  92. /* $ Exceptions */
  93. /* 1) If the segment is not of data type 1, the error */
  94. /* SPICE(CKWRONGDATATYPE) is signalled. */
  95. /* 2) If RECNO is less than one or greater than the number of */
  96. /* records in the specified segment, the error */
  97. /* SPICE(CKNONEXISTREC) is signalled. */
  98. /* 3) If the specified handle does not belong to any file that is */
  99. /* currently known to be open, an error is diagnosed by a */
  100. /* routine that this routine calls. */
  101. /* 4) If DESCR is not a valid, packed descriptor of a segment in */
  102. /* the CK file specified by HANDLE, the results of this routine */
  103. /* are unpredictable. */
  104. /* $ Files */
  105. /* The file specified by HANDLE should be open for read access. */
  106. /* $ Particulars */
  107. /* For a detailed description of the structure of a type 1 segment, */
  108. /* see the CK required reading. */
  109. /* This is a utility routine that performs as follows. It finds out */
  110. /* how many records are in the segment, checks to see if the request */
  111. /* fits the bounds of the segment, and then moves directly to get */
  112. /* the requested data. */
  113. /* $ Examples */
  114. /* The following code fragment prints the records of the first */
  115. /* segment in a CK file. Suppose MOC.CK is valid CK file that */
  116. /* contains segments of data type 1. */
  117. /* INTEGER ICD ( 6 ) */
  118. /* INTEGER HANDLE */
  119. /* INTEGER NREC */
  120. /* INTEGER I */
  121. /* DOUBLE PRECISION DCD ( 2 ) */
  122. /* DOUBLE PRECISION DESCR ( 5 ) */
  123. /* DOUBLE PRECISION RECORD ( 8 ) */
  124. /* LOGICAL FOUND */
  125. /* C */
  126. /* C First load the file. (The file may also be opened by using */
  127. /* C CKLPF.) */
  128. /* C */
  129. /* CALL DAFOPR ( 'MOC.CK', HANDLE ) */
  130. /* C */
  131. /* C Begin forward search. Find first array. */
  132. /* C */
  133. /* CALL DAFBFS ( HANDLE ) */
  134. /* CALL DAFFNA ( FOUND ) */
  135. /* C */
  136. /* C Get segment descriptor. */
  137. /* C */
  138. /* CALL DAFGS ( DESCR ) */
  139. /* C */
  140. /* C Unpack the segment descriptor into its double precision */
  141. /* C and integer components. */
  142. /* C */
  143. /* CALL DAFUS ( DESCR, 2, 6, DCD, ICD ) */
  144. /* C */
  145. /* C The data type for a segment is located in the third integer */
  146. /* C component of the descriptor. */
  147. /* C */
  148. /* IF ( ICD( 3 ) .EQ. 1 ) THEN */
  149. /* C */
  150. /* C How many records does this segment contain? */
  151. /* C */
  152. /* CALL CKNR01 ( HANDLE, DESCR, NREC ) */
  153. /* DO I = 1, NREC */
  154. /* C */
  155. /* C Get the record associated with record number I. */
  156. /* C */
  157. /* CALL CKGR01 ( HANDLE, DESCR, I, RECORD ) */
  158. /* WRITE (*,*) 'Record ', I, ':' */
  159. /* WRITE (*,*) RECORD */
  160. /* END DO */
  161. /* END IF */
  162. /* $ Restrictions */
  163. /* The binay CK file containing the segment whose descriptor was */
  164. /* passed to this routine must be opened for read access by either */
  165. /* CKLPF or DAFOPR. */
  166. /* $ Literature_References */
  167. /* None. */
  168. /* $ Author_and_Institution */
  169. /* J.E. McLean (JPL) */
  170. /* M.J. Spencer (JPL) */
  171. /* R.E. Thurman (JPL) */
  172. /* I.M. Underwood (JPL) */
  173. /* $ Version */
  174. /* - SPICELIB Version 1.1.0, 07-SEP-2001 (EDW) */
  175. /* Replaced DAFRDA call with DAFGDA. */
  176. /* Added IMPLICIT NONE. */
  177. /* - SPICELIB Version 1.0.3, 10-MAR-1992 (WLT) */
  178. /* Comment section for permuted index source lines was added */
  179. /* following the header. */
  180. /* - SPICELIB Version 1.0.2, 06-MAR-1991 (JML) */
  181. /* A correction was made to the example program in the */
  182. /* header. The array of double precision components of */
  183. /* the descriptor ( DCD ) had originally been declared */
  184. /* as an integer. */
  185. /* - SPICELIB Version 1.0.1, 02-NOV-1990 (JML) */
  186. /* The restriction that a C-kernel file must be loaded */
  187. /* was explicitly stated. */
  188. /* - SPICELIB Version 1.0.0, 07-SEP-1990 (RET) (IMU) */
  189. /* -& */
  190. /* $ Index_Entries */
  191. /* get ck type_1 record */
  192. /* -& */
  193. /* $ Revisions */
  194. /* - SPICELIB Version 1.1.0, 07-SEP-2000 (EDW) */
  195. /* Replaced DAFRDA call with DAFGDA. */
  196. /* - SPICELIB Version 1.0.2, 06-MAR-1991 (JML) */
  197. /* A correction was made to the example program in the */
  198. /* header. The array of double precision components of */
  199. /* the descriptor ( DCD ) had originally been declared */
  200. /* as an integer. */
  201. /* - SPICELIB Version 1.0.1, 02-NOV-1990 (JML) */
  202. /* 1) The restriction that a C-kernel file must be loaded */
  203. /* was explicitly stated. */
  204. /* 2) ROTATIONS was removed from the required reading section. */
  205. /* 3) Minor changes were made to the wording of the header. */
  206. /* - Beta Version 1.1.0, 28-AUG-1990 (MJS) (JEM) */
  207. /* The following changes were made as a result of the */
  208. /* NAIF CK Code and Documentation Review: */
  209. /* 1) The name of this routine was changed from CK01GR to */
  210. /* CKGR01 in order to be consistent with the SPICELIB */
  211. /* naming convention. */
  212. /* 2) The declarations for the parameters QSIZ, QAVSIZ, NDC, and */
  213. /* NIC were moved from the "Declarations" section of the */
  214. /* header to the "Local parameters" section of the code below */
  215. /* the header. These parameters are not meant to modified by */
  216. /* users. */
  217. /* 3) The header was corrected, improved, and updated to reflect */
  218. /* the changes. */
  219. /* 4) The in-code comments were improved. */
  220. /* - Beta Version 1.0.0, 23-MAY-1990 (RET) (IMU) */
  221. /* -& */
  222. /* SPICELIB functions */
  223. /* Local parameters */
  224. /* NDC is the number of double precision components in an */
  225. /* unpacked C-kernel segment descriptor. */
  226. /* NIC is the number of integer components in an unpacked */
  227. /* C-kernel segment descriptor. */
  228. /* QSIZ is the number of double precision numbers making up */
  229. /* the quaternion portion of a pointing record. */
  230. /* QAVSIZ is the number of double precision numbers making up */
  231. /* the quaternion and angular velocity portion of a */
  232. /* pointing record. */
  233. /* Local variables */
  234. /* Standard SPICE error handling. */
  235. if (return_()) {
  236. return 0;
  237. } else {
  238. chkin_("CKGR01", (ftnlen)6);
  239. }
  240. /* The unpacked descriptor contains the following information */
  241. /* about the segment: */
  242. /* DCD(1) Initial encoded SCLK */
  243. /* DCD(2) Final encoded SCLK */
  244. /* ICD(1) Instrument */
  245. /* ICD(2) Inertial reference frame */
  246. /* ICD(3) Data type */
  247. /* ICD(4) Angular velocity flag */
  248. /* ICD(5) Initial address of segment data */
  249. /* ICD(6) Final address of segment data */
  250. /* From the descriptor, determine */
  251. /* 1 - Is this really a type 1 segment? */
  252. /* 2 - The beginning address of the segment. */
  253. /* 3 - The number of records in the segment (it's the last number */
  254. /* in the segment). */
  255. /* 4 - The existence of angular velocity data, which determines how */
  256. /* big the pointing portion of the returned record will be. */
  257. dafus_(descr, &c__2, &c__6, dcd, icd);
  258. if (icd[2] != 1) {
  259. setmsg_("Data type of the segment should be 1: Passed descriptor sho"
  260. "ws type = #.", (ftnlen)71);
  261. errint_("#", &icd[2], (ftnlen)1);
  262. sigerr_("SPICE(CKWRONGDATATYPE)", (ftnlen)22);
  263. chkout_("CKGR01", (ftnlen)6);
  264. return 0;
  265. }
  266. beg = icd[4];
  267. dafgda_(handle, &icd[5], &icd[5], &n);
  268. nrec = (integer) n;
  269. if (icd[3] == 1) {
  270. psiz = 7;
  271. } else {
  272. psiz = 4;
  273. }
  274. /* If a request was made for a record which doesn't exist, then */
  275. /* signal an error and leave. */
  276. if (*recno < 1 || *recno > nrec) {
  277. setmsg_("Requested record number (#) does not exist. There are # rec"
  278. "ords in the segment.", (ftnlen)79);
  279. errint_("#", recno, (ftnlen)1);
  280. errint_("#", &nrec, (ftnlen)1);
  281. sigerr_("SPICE(CKNONEXISTREC)", (ftnlen)20);
  282. chkout_("CKGR01", (ftnlen)6);
  283. return 0;
  284. }
  285. /* Get the pointing record indexed by RECNO. */
  286. addr__ = beg + psiz * (*recno - 1);
  287. i__1 = addr__ + (psiz - 1);
  288. dafgda_(handle, &addr__, &i__1, &record[1]);
  289. /* Next get the SCLK time. Need to go past all of the NREC pointing */
  290. /* records (PSIZ * NREC numbers), and then to the RECNOth SCLK */
  291. /* time. */
  292. addr__ = beg + psiz * nrec + *recno - 1;
  293. dafgda_(handle, &addr__, &addr__, record);
  294. chkout_("CKGR01", (ftnlen)6);
  295. return 0;
  296. } /* ckgr01_ */