PageRenderTime 34ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/src/zzckcv05.c

https://github.com/mattbornski/spice
C | 549 lines | 135 code | 138 blank | 276 comment | 30 complexity | c76b3ddbf00ff723f24c70db29e1d81d MD5 | raw file
  1. /* zzckcv05.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. /* $Procedure ZZCKCV05 ( Private --- C-kernel segment coverage, type 05 ) */
  7. /* Subroutine */ int zzckcv05_(integer *handle, integer *arrbeg, integer *
  8. arrend, integer *sclkid, doublereal *dc, doublereal *tol, char *
  9. timsys, doublereal *schedl, ftnlen timsys_len)
  10. {
  11. /* System generated locals */
  12. integer i__1;
  13. doublereal d__1;
  14. /* Builtin functions */
  15. integer i_dnnt(doublereal *);
  16. /* Local variables */
  17. logical bail;
  18. integer nrec;
  19. doublereal tick;
  20. integer ndir;
  21. extern /* Subroutine */ int sct2e_(integer *, doublereal *, doublereal *);
  22. doublereal begin;
  23. extern /* Subroutine */ int chkin_(char *, ftnlen), errch_(char *, char *,
  24. ftnlen, ftnlen);
  25. logical istdb;
  26. extern /* Subroutine */ int errdp_(char *, doublereal *, ftnlen);
  27. integer intat, invls, rsize;
  28. doublereal start;
  29. extern logical eqstr_(char *, char *, ftnlen, ftnlen);
  30. extern /* Subroutine */ int dafgda_(integer *, integer *, integer *,
  31. doublereal *);
  32. doublereal et;
  33. integer intbeg;
  34. doublereal buffer[4];
  35. integer tickat;
  36. doublereal finish;
  37. extern /* Subroutine */ int sigerr_(char *, ftnlen), chkout_(char *,
  38. ftnlen), setmsg_(char *, ftnlen), errint_(char *, doublereal *,
  39. ftnlen), wninsd_(doublereal *, doublereal *, doublereal *);
  40. integer lsttik, lstint;
  41. extern logical return_(void);
  42. integer subtyp;
  43. /* $ Abstract */
  44. /* SPICE Private routine intended solely for the support of SPICE */
  45. /* routines. Users should not call this routine directly due */
  46. /* to the volatile nature of this routine. */
  47. /* Determine the "window" of coverage of a type 05 C-kernel segment. */
  48. /* $ Disclaimer */
  49. /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
  50. /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
  51. /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
  52. /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
  53. /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
  54. /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
  55. /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
  56. /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
  57. /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
  58. /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
  59. /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
  60. /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
  61. /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
  62. /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
  63. /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
  64. /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
  65. /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
  66. /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
  67. /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
  68. /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
  69. /* $ Required_Reading */
  70. /* CK */
  71. /* DAF */
  72. /* $ Keywords */
  73. /* CK */
  74. /* UTILITY */
  75. /* PRIVATE */
  76. /* $ Declarations */
  77. /* $ Abstract */
  78. /* Declare parameters specific to CK type 05. */
  79. /* $ Disclaimer */
  80. /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
  81. /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
  82. /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
  83. /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
  84. /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
  85. /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
  86. /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
  87. /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
  88. /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
  89. /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
  90. /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
  91. /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
  92. /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
  93. /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
  94. /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
  95. /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
  96. /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
  97. /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
  98. /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
  99. /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
  100. /* $ Required_Reading */
  101. /* CK */
  102. /* $ Keywords */
  103. /* CK */
  104. /* $ Restrictions */
  105. /* None. */
  106. /* $ Author_and_Institution */
  107. /* N.J. Bachman (JPL) */
  108. /* $ Literature_References */
  109. /* None. */
  110. /* $ Version */
  111. /* - SPICELIB Version 1.0.0, 20-AUG-2002 (NJB) */
  112. /* -& */
  113. /* CK type 5 subtype codes: */
  114. /* Subtype 0: Hermite interpolation, 8-element packets. Quaternion */
  115. /* and quaternion derivatives only, no angular velocity */
  116. /* vector provided. Quaternion elements are listed */
  117. /* first, followed by derivatives. Angular velocity is */
  118. /* derived from the quaternions and quaternion */
  119. /* derivatives. */
  120. /* Subtype 1: Lagrange interpolation, 4-element packets. Quaternion */
  121. /* only. Angular velocity is derived by differentiating */
  122. /* the interpolating polynomials. */
  123. /* Subtype 2: Hermite interpolation, 14-element packets. */
  124. /* Quaternion and angular angular velocity vector, as */
  125. /* well as derivatives of each, are provided. The */
  126. /* quaternion comes first, then quaternion derivatives, */
  127. /* then angular velocity and its derivatives. */
  128. /* Subtype 3: Lagrange interpolation, 7-element packets. Quaternion */
  129. /* and angular velocity vector provided. The quaternion */
  130. /* comes first. */
  131. /* Packet sizes associated with the various subtypes: */
  132. /* End of file ck05.inc. */
  133. /* $ Brief_I/O */
  134. /* VARIABLE I/O DESCRIPTION */
  135. /* -------- --- -------------------------------------------------- */
  136. /* HANDLE I Handle of a C-kernel open for read access */
  137. /* ARRBEG I Beginning DAF address */
  138. /* ARREND I Ending DAF address */
  139. /* SCLKID I ID of SCLK associated with segment. */
  140. /* DC I D.p. component of CK segment descriptor. */
  141. /* TOL I Tolerance in ticks. */
  142. /* TIMSYS I Time system used to represent coverage. */
  143. /* SCHEDL I/O An initialized window/schedule of interval */
  144. /* $ Detailed_Input */
  145. /* HANDLE is the handle of some DAF that is open for reading. */
  146. /* ARRBEG is the beginning address of a type 05 segment */
  147. /* ARREND is the ending address of a type 05 segment. */
  148. /* SCLKID is the ID code of the spacecraft clock associated with */
  149. /* the object for which the segment contains pointing. */
  150. /* This is the ID code used by the SCLK conversion */
  151. /* routines. */
  152. /* DC is the double precision component of the descriptor of */
  153. /* the CK segment. The components are the segment start */
  154. /* and stop times. */
  155. /* Each interpolation interval is replaced with its */
  156. /* intersection with the segment coverage interval */
  157. /* [ DC(1), DC(2) ] */
  158. /* before being expanded by TOL. Interpolation intervals */
  159. /* that don't intersect the segment coverage interval are */
  160. /* discarded, even if after expansion by TOL they would */
  161. /* have non-empty intersection with the segment coverage */
  162. /* interval. */
  163. /* TOL is a tolerance value expressed in ticks of the */
  164. /* spacecraft clock associated with the segment. After */
  165. /* truncation by the segment coverage interval, and */
  166. /* before insertion into the coverage window, each */
  167. /* non-empty truncated interpolation interval is expanded */
  168. /* by TOL: the left endpoint of each interval is reduced */
  169. /* by TOL and the right endpoint is increased by TOL. */
  170. /* Any intervals that overlap as a result of the */
  171. /* expansion are merged. */
  172. /* The coverage window returned when TOL > 0 indicates */
  173. /* the coverage provided by the file to the CK readers */
  174. /* CKGPAV and CKGP when that value of TOL is passed to */
  175. /* them as an input. */
  176. /* TIMSYS is a string indicating the time system used in the */
  177. /* output coverage window. TIMSYS may have the values: */
  178. /* 'SCLK' Elements of SCHEDL are expressed in */
  179. /* encoded SCLK ("ticks"), where the clock */
  180. /* is associated with the object designated */
  181. /* by IDCODE. */
  182. /* 'TDB' Elements of SCHEDL are expressed as */
  183. /* seconds past J2000 TDB. */
  184. /* TIMSYS must be consistent with the system used for */
  185. /* the contents of SCHEDL on input, if any. */
  186. /* SCHEDL is a schedule (window) of intervals, to which the */
  187. /* intervals of coverage for this segment will be added. */
  188. /* $ Detailed_Output */
  189. /* SCHEDL the input schedule updated to include the intervals */
  190. /* of coverage for this segment. The schedule has */
  191. /* been adjusted to account for the provided tolerance */
  192. /* value. Coverage lying outside the interval */
  193. /* DC(1) - TOL : DC(2) + TOL */
  194. /* is excluded. */
  195. /* The elements of SCHEDL are given in the time system */
  196. /* indicated by TIMSYS. */
  197. /* $ Parameters */
  198. /* Several parameters associated with the type 05 C-kernel */
  199. /* are utilized to compute the packet size of each subtype. */
  200. /* See the include file 'ck05.inc' for details. */
  201. /* $ Files */
  202. /* This routine reads the contents of the file associated with */
  203. /* HANDLE to locate coverage intervals. */
  204. /* $ Exceptions */
  205. /* 1) The error SPICE(NOTSUPPORTED) is signaled if the subtype of */
  206. /* the CK type 05 segment is not recognized. */
  207. /* 2) Routines in the call tree of this routine may signal errors */
  208. /* if insufficient room in SCHEDL exists or other error */
  209. /* conditions relating to file access arise. */
  210. /* 3) If TOL is negative, the error SPICE(VALUEOUTOFRANGE) is */
  211. /* signaled. */
  212. /* 4) If TIMSYS is not recognized, the error SPICE(INVALIDOPTION) */
  213. /* is signaled. */
  214. /* 5) If a time conversion error occurs, the error will be */
  215. /* diagnosed by a routine in the call tree of this routine. */
  216. /* $ Particulars */
  217. /* This is a utility routine that determines the intervals */
  218. /* of coverage for a type 05 C-kernel segment. */
  219. /* $ Examples */
  220. /* See CKCOV. */
  221. /* $ Restrictions */
  222. /* None. */
  223. /* $ Author_and_Institution */
  224. /* N.J. Bachman (JPL) */
  225. /* W.L. Taber (JPL) */
  226. /* F.S. Turner (JPL) */
  227. /* $ Literature_References */
  228. /* None. */
  229. /* $ Version */
  230. /* - SPICELIB Version 1.0.0, 07-JAN-2005 (NJB) (FST) (WLT) */
  231. /* -& */
  232. /* SPICELIB Functions */
  233. /* Local Variables */
  234. /* Standard SPICE error handling. */
  235. if (return_()) {
  236. return 0;
  237. } else {
  238. chkin_("ZZCKCV05", (ftnlen)8);
  239. }
  240. /* Check tolerance value. */
  241. if (*tol < 0.) {
  242. setmsg_("Tolerance must be non-negative; actual value was #.", (
  243. ftnlen)51);
  244. errdp_("#", tol, (ftnlen)1);
  245. sigerr_("SPICE(VALUEOUTOFRANGE)", (ftnlen)22);
  246. chkout_("ZZCKCV05", (ftnlen)8);
  247. return 0;
  248. }
  249. /* Set a logical flag indicating whether the time systm is SCLK. */
  250. istdb = eqstr_(timsys, "TDB", timsys_len, (ftnlen)3);
  251. /* Check time system. */
  252. if (! istdb) {
  253. if (! eqstr_(timsys, "SCLK", timsys_len, (ftnlen)4)) {
  254. setmsg_("Time system spec TIMSYS was #; allowed values are SCLK "
  255. "and TDB.", (ftnlen)63);
  256. errch_("#", timsys, (ftnlen)1, timsys_len);
  257. sigerr_("SPICE(INVALIDOPTION)", (ftnlen)20);
  258. chkout_("ZZCKCV05", (ftnlen)8);
  259. return 0;
  260. }
  261. }
  262. /* Get the meta-data associated with this segment that we */
  263. /* require to produce the schedule. */
  264. /* BUFFER(1) = Subtype Code */
  265. /* BUFFER(2) = Window Size */
  266. /* BUFFER(3) = Number of Interpolation Intervals */
  267. /* BUFFER(4) = Number of Packets */
  268. i__1 = *arrend - 3;
  269. dafgda_(handle, &i__1, arrend, buffer);
  270. subtyp = i_dnnt(buffer);
  271. invls = i_dnnt(&buffer[2]);
  272. nrec = i_dnnt(&buffer[3]);
  273. ndir = (nrec - 1) / 100;
  274. /* Compute the packet size. This requires parameters listed */
  275. /* in the include file 'ck05.inc' and is based on the subtype. */
  276. if (subtyp == 0) {
  277. rsize = 8;
  278. } else if (subtyp == 1) {
  279. rsize = 4;
  280. } else if (subtyp == 2) {
  281. rsize = 14;
  282. } else if (subtyp == 3) {
  283. rsize = 7;
  284. } else {
  285. setmsg_("CK type 5 subtype <#> is not supported.", (ftnlen)39);
  286. errint_("#", buffer, (ftnlen)1);
  287. sigerr_("SPICE(NOTSUPPORTED)", (ftnlen)19);
  288. chkout_("ZZCKCV05", (ftnlen)8);
  289. return 0;
  290. }
  291. /* Recall that the segment is layed out as: */
  292. /* +------------------------------+ */
  293. /* | | */
  294. /* | Pointing | */
  295. /* | | */
  296. /* +------------------------------+ */
  297. /* | | */
  298. /* | SCLK times | */
  299. /* | | */
  300. /* +------------------------+ */
  301. /* | | */
  302. /* | SCLK directory | */
  303. /* | | */
  304. /* +------------------------+ */
  305. /* | | */
  306. /* | Interval start times | */
  307. /* | | */
  308. /* +------------------------+ */
  309. /* | | */
  310. /* | Start times directory | */
  311. /* | | */
  312. /* +------------------------+ */
  313. /* | Seconds per tick | */
  314. /* +------------------------+ */
  315. /* | Subtype code | */
  316. /* +------------------------+ */
  317. /* | Window size | */
  318. /* +------------------------+ */
  319. /* | | */
  320. /* | Number of intervals | */
  321. /* | | */
  322. /* +------------------------+ */
  323. /* | | */
  324. /* | Number of pointing | */
  325. /* | instances | */
  326. /* | | */
  327. /* +------------------------+ */
  328. tickat = *arrbeg + rsize * nrec;
  329. lsttik = tickat + nrec - 1;
  330. intbeg = *arrbeg + rsize * nrec + nrec + ndir;
  331. intat = intbeg;
  332. lstint = intbeg + invls - 1;
  333. dafgda_(handle, &intat, &intat, &start);
  334. dafgda_(handle, &tickat, &tickat, &tick);
  335. while(tick < start && tickat < lsttik) {
  336. ++tickat;
  337. dafgda_(handle, &tickat, &tickat, &tick);
  338. }
  339. /* If we did not find a TICK at least as big as START, we can */
  340. /* just return now. */
  341. if (tick < start) {
  342. chkout_("ZZCKCV05", (ftnlen)8);
  343. return 0;
  344. }
  345. bail = FALSE_;
  346. while(intat <= lstint && tickat <= lsttik && ! bail) {
  347. /* At this point, we have an interval that begins at START */
  348. /* and ends at FINISH (unless of course we never found a "good" */
  349. /* TICK to start with.) */
  350. begin = start;
  351. /* If the start of the interval was the start of the LAST */
  352. /* interval available, we can short cut the remainder of the */
  353. /* reads. */
  354. if (intat == lstint) {
  355. dafgda_(handle, &lsttik, &lsttik, &finish);
  356. bail = TRUE_;
  357. /* The routine will return at the end of this loop */
  358. /* iteration. But first, we may have to update BEGIN */
  359. /* and FINISH, depending on the values of TOL and TIMSYS, */
  360. /* and we have to insert these values into SCHEDL. */
  361. /* We'll carry out these tasks at the end of this IF block. */
  362. } else {
  363. /* This is the expected case. Get the start of the next */
  364. /* interval. */
  365. ++intat;
  366. dafgda_(handle, &intat, &intat, &start);
  367. /* Read forward from the last tick until we reach the */
  368. /* START of the next interval or until we run out of TICKS. */
  369. while(tick < start && tickat < lsttik) {
  370. finish = tick;
  371. ++tickat;
  372. dafgda_(handle, &tickat, &tickat, &tick);
  373. }
  374. /* A structurally correct CK-5 segment should never allow the */
  375. /* next test to pass, but it's just easier to check than */
  376. /* police the writers of C-kernels. The only way to get into */
  377. /* the block below is if TICKAT .EQ. LSTTIK */
  378. if (tick < start) {
  379. finish = tick;
  380. ++tickat;
  381. }
  382. }
  383. /* Truncate the interval using the segment bounds. */
  384. begin = max(begin,dc[0]);
  385. finish = min(finish,dc[1]);
  386. /* Adjust the interval using the tolerance. Empty */
  387. /* intervals *do not get expanded*; this choice is */
  388. /* consistent with the type 5 reading algorithm. */
  389. if (begin <= finish) {
  390. if (*tol > 0.) {
  391. /* Computing MAX */
  392. d__1 = begin - *tol;
  393. begin = max(d__1,0.);
  394. finish += *tol;
  395. }
  396. }
  397. /* Convert the time to TDB if necessary. */
  398. if (istdb) {
  399. sct2e_(sclkid, &begin, &et);
  400. begin = et;
  401. sct2e_(sclkid, &finish, &et);
  402. finish = et;
  403. }
  404. /* Insert the interval into the window. */
  405. if (begin <= finish) {
  406. wninsd_(&begin, &finish, schedl);
  407. }
  408. }
  409. chkout_("ZZCKCV05", (ftnlen)8);
  410. return 0;
  411. } /* zzckcv05_ */