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

/src/ckw04a.c

https://github.com/mattbornski/spice
C | 764 lines | 79 code | 234 blank | 451 comment | 9 complexity | 0ffb5be2ad4db3bbac1bce0774f11485 MD5 | raw file
  1. /* ckw04a.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__142 = 142;
  8. static integer c__7 = 7;
  9. static doublereal c_b20 = 128.;
  10. /* $Procedure CKW04A ( CK type 04: Add data to a segment ) */
  11. /* Subroutine */ int ckw04a_(integer *handle, integer *npkts, integer *pktsiz,
  12. doublereal *pktdat, doublereal *sclkdp)
  13. {
  14. /* System generated locals */
  15. integer i__1, i__2;
  16. /* Builtin functions */
  17. integer s_rnge(char *, integer, char *, integer);
  18. /* Local variables */
  19. integer k;
  20. extern /* Subroutine */ int chkin_(char *, ftnlen);
  21. integer dispm, kk;
  22. extern /* Subroutine */ int errhan_(char *, integer *, ftnlen);
  23. integer displm;
  24. extern /* Subroutine */ int sigerr_(char *, ftnlen);
  25. integer numcft[7];
  26. extern /* Subroutine */ int chkout_(char *, ftnlen), setmsg_(char *,
  27. ftnlen), errint_(char *, integer *, ftnlen);
  28. extern logical return_(void);
  29. extern /* Subroutine */ int sgwvpk_(integer *, integer *, integer *,
  30. doublereal *, integer *, doublereal *), zzck4i2d_(integer *,
  31. integer *, doublereal *, doublereal *);
  32. /* $ Abstract */
  33. /* Add data to a type 4 CK segment currently being written to */
  34. /* the file associated with HANDLE. See also CKW04B and CKW04E. */
  35. /* $ Disclaimer */
  36. /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
  37. /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
  38. /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
  39. /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
  40. /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
  41. /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
  42. /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
  43. /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
  44. /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
  45. /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
  46. /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
  47. /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
  48. /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
  49. /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
  50. /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
  51. /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
  52. /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
  53. /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
  54. /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
  55. /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
  56. /* $ Required_Reading */
  57. /* CK.REQ */
  58. /* DAF.REQ */
  59. /* GS.REQ */
  60. /* $ Keywords */
  61. /* POINTING */
  62. /* $ Declarations */
  63. /* $ Abstract */
  64. /* Declarations of the CK data type specific and general CK low */
  65. /* level routine parameters. */
  66. /* $ Disclaimer */
  67. /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
  68. /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
  69. /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
  70. /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
  71. /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
  72. /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
  73. /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
  74. /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
  75. /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
  76. /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
  77. /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
  78. /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
  79. /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
  80. /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
  81. /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
  82. /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
  83. /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
  84. /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
  85. /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
  86. /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
  87. /* $ Required_Reading */
  88. /* CK.REQ */
  89. /* $ Keywords */
  90. /* CK */
  91. /* $ Restrictions */
  92. /* 1) If new CK types are added, the size of the record passed */
  93. /* between CKRxx and CKExx must be registered as separate */
  94. /* parameter. If this size will be greater than current value */
  95. /* of the CKMRSZ parameter (which specifies the maximum record */
  96. /* size for the record buffer used inside CKPFS) then it should */
  97. /* be assigned to CKMRSZ as a new value. */
  98. /* $ Author_and_Institution */
  99. /* N.J. Bachman (JPL) */
  100. /* B.V. Semenov (JPL) */
  101. /* $ Literature_References */
  102. /* CK Required Reading. */
  103. /* $ Version */
  104. /* - SPICELIB Version 2.0.0, 19-AUG-2002 (NJB) */
  105. /* Updated to support CK type 5. */
  106. /* - SPICELIB Version 1.0.0, 05-APR-1999 (BVS) */
  107. /* -& */
  108. /* Number of quaternion components and number of quaternion and */
  109. /* angular rate components together. */
  110. /* CK Type 1 parameters: */
  111. /* CK1DTP CK data type 1 ID; */
  112. /* CK1RSZ maximum size of a record passed between CKR01 */
  113. /* and CKE01. */
  114. /* CK Type 2 parameters: */
  115. /* CK2DTP CK data type 2 ID; */
  116. /* CK2RSZ maximum size of a record passed between CKR02 */
  117. /* and CKE02. */
  118. /* CK Type 3 parameters: */
  119. /* CK3DTP CK data type 3 ID; */
  120. /* CK3RSZ maximum size of a record passed between CKR03 */
  121. /* and CKE03. */
  122. /* CK Type 4 parameters: */
  123. /* CK4DTP CK data type 4 ID; */
  124. /* CK4PCD parameter defining integer to DP packing schema that */
  125. /* is applied when seven number integer array containing */
  126. /* polynomial degrees for quaternion and angular rate */
  127. /* components packed into a single DP number stored in */
  128. /* actual CK records in a file; the value of must not be */
  129. /* changed or compatibility with existing type 4 CK files */
  130. /* will be lost. */
  131. /* CK4MXD maximum Chebychev polynomial degree allowed in type 4 */
  132. /* records; the value of this parameter must never exceed */
  133. /* value of the CK4PCD; */
  134. /* CK4SFT number of additional DPs, which are not polynomial */
  135. /* coefficients, located at the beginning of a type 4 */
  136. /* CK record that passed between routines CKR04 and CKE04; */
  137. /* CK4RSZ maximum size of type 4 CK record passed between CKR04 */
  138. /* and CKE04; CK4RSZ is computed as follows: */
  139. /* CK4RSZ = ( CK4MXD + 1 ) * QAVSIZ + CK4SFT */
  140. /* CK Type 5 parameters: */
  141. /* CK5DTP CK data type 5 ID; */
  142. /* CK5MXD maximum polynomial degree allowed in type 5 */
  143. /* records. */
  144. /* CK5MET number of additional DPs, which are not polynomial */
  145. /* coefficients, located at the beginning of a type 5 */
  146. /* CK record that passed between routines CKR05 and CKE05; */
  147. /* CK5MXP maximum packet size for any subtype. Subtype 2 */
  148. /* has the greatest packet size, since these packets */
  149. /* contain a quaternion, its derivative, an angular */
  150. /* velocity vector, and its derivative. See ck05.inc */
  151. /* for a description of the subtypes. */
  152. /* CK5RSZ maximum size of type 5 CK record passed between CKR05 */
  153. /* and CKE05; CK5RSZ is computed as follows: */
  154. /* CK5RSZ = ( CK5MXD + 1 ) * CK5MXP + CK5MET */
  155. /* Maximum record size that can be handled by CKPFS. This value */
  156. /* must be set to the maximum of all CKxRSZ parameters (currently */
  157. /* CK4RSZ.) */
  158. /* $ Brief_I/O */
  159. /* VARIABLE I/O DESCRIPTION */
  160. /* -------- --- -------------------------------------------------- */
  161. /* HANDLE I The handle of an DAF file opened for writing. */
  162. /* NPKTS I Number of data packets to write to a segment. */
  163. /* PKTSIZ I The numbers of values in the data packets */
  164. /* PKTDAT I The data packets. */
  165. /* SCLKDP I The SCLK times associated with the data packets. */
  166. /* $ Detailed_Input */
  167. /* HANDLE is the file handle of a CK file in which a CK type 4 */
  168. /* segment is currently being written. */
  169. /* NPKTS is the number of data packets to write to a segment. */
  170. /* PKTSIZ is the number of values in all data packets. */
  171. /* PKTDAT is the data packets. The data packets in this array */
  172. /* must be organized as described in the $ Particulars */
  173. /* section of the header. */
  174. /* SCLKDP contains the initial SCLK times corresponding to the */
  175. /* Chebyshev coefficients in PKTSIZ. The I'th time is */
  176. /* start time of the I'th packet coverage interval. */
  177. /* The times must form a strictly increasing sequence. */
  178. /* $ Detailed_Output */
  179. /* None. Data is stored in a segment in the DAF file */
  180. /* associated with HANDLE. */
  181. /* $ Parameters */
  182. /* See 'ckparam.inc'. */
  183. /* $ Exceptions */
  184. /* 1) If the number of coefficient sets and epochs is not positive, */
  185. /* the error SPICE(INVALIDARGUMENT) will be signalled. */
  186. /* 2) If size of any input packet is greater that maximum allowed */
  187. /* type 4 CK record size minus one, the error */
  188. /* SPICE(INVALIDARGUMENT) will be signalled. */
  189. /* $ Files */
  190. /* See HANDLE in the $ Detailed_Input section. */
  191. /* $ Particulars */
  192. /* This routine adds data to a type 4 CK segment that is currently */
  193. /* being written to the associated with HANDLE. The segment must */
  194. /* have been started by a call to the routine CKW04B, the routine */
  195. /* which begins a type 4 CK segment. */
  196. /* This routine is one of a set of three routines for creating and */
  197. /* adding data to type 4 CK segments. These routines are: */
  198. /* CKW04B: Begin a type 4 CK segment. This routine must be */
  199. /* called before any data may be added to a type 4 */
  200. /* segment. */
  201. /* CKW04A: Add data to a type 4 CK segment. This routine may be */
  202. /* called any number of times after a call to CKW04B to */
  203. /* add type 4 records to the CK segment that was */
  204. /* started. */
  205. /* CKW04E: End a type 4 CK segment. This routine is called to */
  206. /* make the type 4 segment a permanent addition to the */
  207. /* DAF file. Once this routine is called, no further type */
  208. /* 4 records may be added to the segment. A new segment */
  209. /* must be started. */
  210. /* A type 4 CK segment consists of coefficient sets for variable */
  211. /* order Chebyshev polynomials over consecutive time intervals of a */
  212. /* variable length. The gaps between intervals are allowed. The */
  213. /* Chebyshev polynomials represent individual SPICE-style quaternion */
  214. /* components q0, q1, q2 and q3 and individual angular velocities */
  215. /* AV1, AV2 and AV3 if they are included with the data. */
  216. /* See the discussion of quaternion styles below. */
  217. /* The pointing data supplied to the type 4 CK writer (CKW04A) */
  218. /* is packed into an array as a sequence of records, */
  219. /* ---------------------------------------------------- */
  220. /* | Record 1 | Record 2 | .. | Record N-1 | Record N | */
  221. /* ---------------------------------------------------- */
  222. /* with each record in data packets has the following format. */
  223. /* ---------------------------------------------------- */
  224. /* | The midpoint of the approximation interval | */
  225. /* ---------------------------------------------------- */
  226. /* | The radius of the approximation interval | */
  227. /* ---------------------------------------------------- */
  228. /* | Number of coefficients for q0 | */
  229. /* ---------------------------------------------------- */
  230. /* | Number of coefficients for q1 | */
  231. /* ---------------------------------------------------- */
  232. /* | Number of coefficients for q2 | */
  233. /* ---------------------------------------------------- */
  234. /* | Number of coefficients for q3 | */
  235. /* ---------------------------------------------------- */
  236. /* | Number of coefficients for AV1 | */
  237. /* ---------------------------------------------------- */
  238. /* | Number of coefficients for AV2 | */
  239. /* ---------------------------------------------------- */
  240. /* | Number of coefficients for AV3 | */
  241. /* ---------------------------------------------------- */
  242. /* | q0 Cheby coefficients | */
  243. /* ---------------------------------------------------- */
  244. /* | q1 Cheby coefficients | */
  245. /* ---------------------------------------------------- */
  246. /* | q2 Cheby coefficients | */
  247. /* ---------------------------------------------------- */
  248. /* | q3 Cheby coefficients | */
  249. /* ---------------------------------------------------- */
  250. /* | AV1 Cheby coefficients (optional) | */
  251. /* ---------------------------------------------------- */
  252. /* | AV2 Cheby coefficients (optional) | */
  253. /* ---------------------------------------------------- */
  254. /* | AV3 Cheby coefficients (optional) | */
  255. /* ---------------------------------------------------- */
  256. /* Quaternion Styles */
  257. /* ----------------- */
  258. /* There are different "styles" of quaternions used in */
  259. /* science and engineering applications. Quaternion styles */
  260. /* are characterized by */
  261. /* - The order of quaternion elements */
  262. /* - The quaternion multiplication formula */
  263. /* - The convention for associating quaternions */
  264. /* with rotation matrices */
  265. /* Two of the commonly used styles are */
  266. /* - "SPICE" */
  267. /* > Invented by Sir William Rowan Hamilton */
  268. /* > Frequently used in mathematics and physics textbooks */
  269. /* - "Engineering" */
  270. /* > Widely used in aerospace engineering applications */
  271. /* SPICELIB subroutine interfaces ALWAYS use SPICE quaternions. */
  272. /* Quaternions of any other style must be converted to SPICE */
  273. /* quaternions before they are passed to SPICELIB routines. */
  274. /* Relationship between SPICE and Engineering Quaternions */
  275. /* ------------------------------------------------------ */
  276. /* Let M be a rotation matrix such that for any vector V, */
  277. /* M*V */
  278. /* is the result of rotating V by theta radians in the */
  279. /* counterclockwise direction about unit rotation axis vector A. */
  280. /* Then the SPICE quaternions representing M are */
  281. /* (+/-) ( cos(theta/2), */
  282. /* sin(theta/2) A(1), */
  283. /* sin(theta/2) A(2), */
  284. /* sin(theta/2) A(3) ) */
  285. /* while the engineering quaternions representing M are */
  286. /* (+/-) ( -sin(theta/2) A(1), */
  287. /* -sin(theta/2) A(2), */
  288. /* -sin(theta/2) A(3), */
  289. /* cos(theta/2) ) */
  290. /* For both styles of quaternions, if a quaternion q represents */
  291. /* a rotation matrix M, then -q represents M as well. */
  292. /* Given an engineering quaternion */
  293. /* QENG = ( q0, q1, q2, q3 ) */
  294. /* the equivalent SPICE quaternion is */
  295. /* QSPICE = ( q3, -q0, -q1, -q2 ) */
  296. /* Associating SPICE Quaternions with Rotation Matrices */
  297. /* ---------------------------------------------------- */
  298. /* Let FROM and TO be two right-handed reference frames, for */
  299. /* example, an inertial frame and a spacecraft-fixed frame. Let the */
  300. /* symbols */
  301. /* V , V */
  302. /* FROM TO */
  303. /* denote, respectively, an arbitrary vector expressed relative to */
  304. /* the FROM and TO frames. Let M denote the transformation matrix */
  305. /* that transforms vectors from frame FROM to frame TO; then */
  306. /* V = M * V */
  307. /* TO FROM */
  308. /* where the expression on the right hand side represents left */
  309. /* multiplication of the vector by the matrix. */
  310. /* Then if the unit-length SPICE quaternion q represents M, where */
  311. /* q = (q0, q1, q2, q3) */
  312. /* the elements of M are derived from the elements of q as follows: */
  313. /* +- -+ */
  314. /* | 2 2 | */
  315. /* | 1 - 2*( q2 + q3 ) 2*(q1*q2 - q0*q3) 2*(q1*q3 + q0*q2) | */
  316. /* | | */
  317. /* | | */
  318. /* | 2 2 | */
  319. /* M = | 2*(q1*q2 + q0*q3) 1 - 2*( q1 + q3 ) 2*(q2*q3 - q0*q1) | */
  320. /* | | */
  321. /* | | */
  322. /* | 2 2 | */
  323. /* | 2*(q1*q3 - q0*q2) 2*(q2*q3 + q0*q1) 1 - 2*( q1 + q2 ) | */
  324. /* | | */
  325. /* +- -+ */
  326. /* Note that substituting the elements of -q for those of q in the */
  327. /* right hand side leaves each element of M unchanged; this shows */
  328. /* that if a quaternion q represents a matrix M, then so does the */
  329. /* quaternion -q. */
  330. /* To map the rotation matrix M to a unit quaternion, we start by */
  331. /* decomposing the rotation matrix as a sum of symmetric */
  332. /* and skew-symmetric parts: */
  333. /* 2 */
  334. /* M = [ I + (1-cos(theta)) OMEGA ] + [ sin(theta) OMEGA ] */
  335. /* symmetric skew-symmetric */
  336. /* OMEGA is a skew-symmetric matrix of the form */
  337. /* +- -+ */
  338. /* | 0 -n3 n2 | */
  339. /* | | */
  340. /* OMEGA = | n3 0 -n1 | */
  341. /* | | */
  342. /* | -n2 n1 0 | */
  343. /* +- -+ */
  344. /* The vector N of matrix entries (n1, n2, n3) is the rotation axis */
  345. /* of M and theta is M's rotation angle. Note that N and theta */
  346. /* are not unique. */
  347. /* Let */
  348. /* C = cos(theta/2) */
  349. /* S = sin(theta/2) */
  350. /* Then the unit quaternions Q corresponding to M are */
  351. /* Q = +/- ( C, S*n1, S*n2, S*n3 ) */
  352. /* The mappings between quaternions and the corresponding rotations */
  353. /* are carried out by the SPICELIB routines */
  354. /* Q2M {quaternion to matrix} */
  355. /* M2Q {matrix to quaternion} */
  356. /* M2Q always returns a quaternion with scalar part greater than */
  357. /* or equal to zero. */
  358. /* SPICE Quaternion Multiplication Formula */
  359. /* --------------------------------------- */
  360. /* Given a SPICE quaternion */
  361. /* Q = ( q0, q1, q2, q3 ) */
  362. /* corresponding to rotation axis A and angle theta as above, we can */
  363. /* represent Q using "scalar + vector" notation as follows: */
  364. /* s = q0 = cos(theta/2) */
  365. /* v = ( q1, q2, q3 ) = sin(theta/2) * A */
  366. /* Q = s + v */
  367. /* Let Q1 and Q2 be SPICE quaternions with respective scalar */
  368. /* and vector parts s1, s2 and v1, v2: */
  369. /* Q1 = s1 + v1 */
  370. /* Q2 = s2 + v2 */
  371. /* We represent the dot product of v1 and v2 by */
  372. /* <v1, v2> */
  373. /* and the cross product of v1 and v2 by */
  374. /* v1 x v2 */
  375. /* Then the SPICE quaternion product is */
  376. /* Q1*Q2 = s1*s2 - <v1,v2> + s1*v2 + s2*v1 + (v1 x v2) */
  377. /* If Q1 and Q2 represent the rotation matrices M1 and M2 */
  378. /* respectively, then the quaternion product */
  379. /* Q1*Q2 */
  380. /* represents the matrix product */
  381. /* M1*M2 */
  382. /* $ Examples */
  383. /* Assume that we have: */
  384. /* HANDLE is the handle of an CK file opened with write */
  385. /* access. */
  386. /* SEGID is a character string of no more than 40 characters */
  387. /* which provides a pedigree for the data in the CK */
  388. /* segment we will create. */
  389. /* INST is the SPICE ID code for the instrument whose */
  390. /* pointing data is to be placed into the file. */
  391. /* AVFLAG angular rates flag. */
  392. /* REFFRM is the name of the SPICE reference frame for the */
  393. /* pointing data. */
  394. /* BEGTIM is the starting encoded SCLK time for which the */
  395. /* segment is valid. */
  396. /* ENDTIM is the ending encoded SCLK time for which the segment */
  397. /* is valid. */
  398. /* N is the number of type 4 records that we want to */
  399. /* put into a segment in an CK file. */
  400. /* NPKTS is integer array which contains the lengths of */
  401. /* variable size data packets */
  402. /* RECRDS contains N type 4 records packaged for the CK */
  403. /* file. */
  404. /* SCSTRT contains the initial encoded SC time for each of */
  405. /* the records contained in RECRDS, where */
  406. /* SCSTRT(I) < SCSTRT(I+1), I = 1, N-1 */
  407. /* SCSTRT(1) <= FIRST, SCSTRT(N) < LAST */
  408. /* Then the following code fragment demonstrates how to create */
  409. /* a type 4 CK segment if all of the data for the segment is */
  410. /* available at one time. */
  411. /* C */
  412. /* C Begin the segment. */
  413. /* C */
  414. /* CALL CKW04B ( HANDLE, BEGTIM, INST, REF, AVFLAG, SEGID ) */
  415. /* C */
  416. /* C Add the data to the segment all at once. */
  417. /* C */
  418. /* CALL CKW04A ( HANDLE, N, NPKTS, RECRDS, SCSTRT ) */
  419. /* C */
  420. /* C End the segment, making the segment a permanent */
  421. /* C addition to the CK file. */
  422. /* C */
  423. /* CALL CKW04E ( HANDLE, ENDTIM ) */
  424. /* $ Restrictions */
  425. /* 1) The type 4 CK segment to which the data is added must have */
  426. /* been started by the routine CKW04B, the routine which begins */
  427. /* a type 4 CK segment. */
  428. /* $ Literature_References */
  429. /* None. */
  430. /* $ Author_and_Institution */
  431. /* Y.K. Zaiko (JPL) */
  432. /* B.V. Semenov (JPL) */
  433. /* $ Version */
  434. /* - SPICELIB Version 1.1.1, 26-FEB-2008 (NJB) */
  435. /* Updated header; added information about SPICE */
  436. /* quaternion conventions. */
  437. /* - SPICELIB Version 1.1.0, 07-SEP-2001 (EDW) */
  438. /* Removed DAFHLU call; replaced ERRFNM call with ERRHAN. */
  439. /* Added IMPLICIT NONE. */
  440. /* - SPICELIB Version 1.0.0, 05-MAY-1999 (YKZ) (BVS) */
  441. /* -& */
  442. /* $ Index_Entries */
  443. /* add data to a type_4 ck segment */
  444. /* -& */
  445. /* Spicelib functions. */
  446. /* Local parameters. */
  447. /* The number of elements by which coefficients in each packet */
  448. /* have to be shifted to the left after numbers of coefficients */
  449. /* were packed into a single integer. */
  450. /* Local Variables. */
  451. /* Standard SPICELIB error handling. */
  452. if (return_()) {
  453. return 0;
  454. } else {
  455. chkin_("CKW04A", (ftnlen)6);
  456. }
  457. /* First, check if the number of coefficient sets and epochs */
  458. /* is positive and whether each packet is smaller than the */
  459. /* maximum size of a record that CKPFS can handle. */
  460. i__1 = *npkts;
  461. for (k = 1; k <= i__1; ++k) {
  462. if (pktsiz[k - 1] <= 0) {
  463. setmsg_("The number of coefficient sets and epochs in the # data"
  464. " packet (record) to be added to the DAF segment in the f"
  465. "ile '#' was not positive. Its value was: #.", (ftnlen)154)
  466. ;
  467. errint_("#", &k, (ftnlen)1);
  468. errhan_("#", handle, (ftnlen)1);
  469. errint_("#", &pktsiz[k - 1], (ftnlen)1);
  470. sigerr_("SPICE(INVALIDARGUMENT)", (ftnlen)22);
  471. chkout_("CKW04A", (ftnlen)6);
  472. return 0;
  473. }
  474. /* We do .GE. comparison because a type 4 CK record passed */
  475. /* inside CKPFS will have one more element -- time at which */
  476. /* the pointing will be evaluated. */
  477. if (pktsiz[k - 1] >= 143) {
  478. setmsg_("The total size of the # data packet (record) to be adde"
  479. "d to the DAF segment in the file '#' is greater than the"
  480. " maximum allowed type 4 record size #. Its value was: #.",
  481. (ftnlen)167);
  482. errint_("#", &k, (ftnlen)1);
  483. errhan_("#", handle, (ftnlen)1);
  484. errint_("#", &c__142, (ftnlen)1);
  485. errint_("#", &pktsiz[k - 1], (ftnlen)1);
  486. sigerr_("SPICE(INVALIDARGUMENT)", (ftnlen)22);
  487. chkout_("CKW04A", (ftnlen)6);
  488. return 0;
  489. }
  490. }
  491. displm = 0;
  492. dispm = 0;
  493. /* The cycle below encodes groups of numbers of coefficients in */
  494. /* data packets to single double precision numbers and shift */
  495. /* data in packets to the left to decrease the data packet */
  496. /* lengths. */
  497. i__1 = *npkts;
  498. for (k = 1; k <= i__1; ++k) {
  499. /* Encode integer numbers of coefficients for each component */
  500. /* to single double precision variable */
  501. for (kk = 1; kk <= 7; ++kk) {
  502. numcft[(i__2 = kk - 1) < 7 && 0 <= i__2 ? i__2 : s_rnge("numcft",
  503. i__2, "ckw04a_", (ftnlen)577)] = (integer) pktdat[kk + 2
  504. + displm - 1];
  505. }
  506. zzck4i2d_(numcft, &c__7, &c_b20, &pktdat[dispm + 2]);
  507. /* Shift coefficients sets to the left to overwrite numbers of */
  508. /* packets */
  509. i__2 = pktsiz[k - 1];
  510. for (kk = 4; kk <= i__2; ++kk) {
  511. pktdat[kk + dispm - 1] = pktdat[kk + 6 + displm - 1];
  512. }
  513. /* Shift middle value and radii of interval */
  514. pktdat[dispm] = pktdat[displm];
  515. pktdat[dispm + 1] = pktdat[displm + 1];
  516. displm += pktsiz[k - 1];
  517. /* Length of each data packet became less for 6 elements because */
  518. /* of encoding of 7 double precision numbers, which are the */
  519. /* numbers of polynomial coefficients, to one double precision */
  520. /* number */
  521. pktsiz[k - 1] += -6;
  522. dispm += pktsiz[k - 1];
  523. }
  524. /* Add the data. */
  525. sgwvpk_(handle, npkts, pktsiz, pktdat, npkts, sclkdp);
  526. /* No need to check FAILED() here, since all we do is check out. */
  527. /* Leave it up to the caller. */
  528. chkout_("CKW04A", (ftnlen)6);
  529. return 0;
  530. } /* ckw04a_ */