1 /* spkr02.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 
6 #include "f2c.h"
7 
8 /* Table of constant values */
9 
10 static integer c__2 = 2;
11 static integer c__6 = 6;
12 
13 /* $Procedure  SPKR02 ( SPK, read record from segment, type 2 ) */
spkr02_(integer * handle,doublereal * descr,doublereal * et,doublereal * record)14 /* Subroutine */ int spkr02_(integer *handle, doublereal *descr, doublereal *
15 	et, doublereal *record)
16 {
17     /* System generated locals */
18     integer i__1;
19 
20     /* Local variables */
21     integer nrec;
22     doublereal init;
23     integer begin;
24     extern /* Subroutine */ int chkin_(char *, ftnlen), dafus_(doublereal *,
25 	    integer *, integer *, doublereal *, integer *);
26     integer recno;
27     extern /* Subroutine */ int dafgda_(integer *, integer *, integer *,
28 	    doublereal *);
29     doublereal dc[2];
30     integer ic[6], recadr;
31     doublereal intlen;
32     extern /* Subroutine */ int chkout_(char *, ftnlen);
33     integer recsiz;
34     extern logical return_(void);
35     integer end;
36 
37 /* $ Abstract */
38 
39 /*     Read a single SPK data record from a segment of type 2 */
40 /*     (Chebyshev, position only). */
41 
42 /* $ Disclaimer */
43 
44 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
45 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
46 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
47 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
48 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
49 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
50 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
51 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
52 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
53 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
54 
55 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
56 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
57 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
58 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
59 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
60 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
61 
62 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
63 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
64 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
65 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
66 
67 /* $ Required_Reading */
68 
69 /*     SPK */
70 
71 /* $ Keywords */
72 
73 /*     EPHEMERIS */
74 
75 /* $ Declarations */
76 /* $ Brief_I/O */
77 
78 /*     Variable  I/O  Description */
79 /*     --------  ---  -------------------------------------------------- */
80 /*     HANDLE     I   File handle. */
81 /*     DESCR      I   Segment descriptor. */
82 /*     ET         I   Evaluation epoch. */
83 /*     RECORD     O   Data record. */
84 
85 /* $ Detailed_Input */
86 
87 /*     HANDLE, */
88 /*     DESCR       are the file handle and segment descriptor for */
89 /*                 an SPK segment of type 2. */
90 
91 /*     ET          is an epoch for which a data record from the */
92 /*                 specified segment is required. ET is expressed as */
93 /*                 seconds past J2000 TDB. */
94 
95 
96 /* $ Detailed_Output */
97 
98 /*     RECORD      is an array of data from the specified segment which, */
99 /*                 when evaluated at epoch ET, will give the state */
100 /*                 (position and velocity) of the target body identified */
101 /*                 by the input segment descriptor. The descriptor */
102 /*                 specifies the center of motion and reference frame of */
103 /*                 the state. */
104 
105 /*                 The structure of the record is as follows: */
106 
107 /*                    +--------------------------------------+ */
108 /*                    | record size (excluding this element) | */
109 /*                    +--------------------------------------+ */
110 /*                    | Coverage interval midpoint           | */
111 /*                    +--------------------------------------+ */
112 /*                    | Coverage interval radius             | */
113 /*                    +--------------------------------------+ */
114 /*                    | Coeffs for X position component      | */
115 /*                    +--------------------------------------+ */
116 /*                    | Coeffs for Y position component      | */
117 /*                    +--------------------------------------+ */
118 /*                    | Coeffs for Z position component      | */
119 /*                    +--------------------------------------+ */
120 
121 /*                 In the above record */
122 
123 /*                    - Times are expressed as seconds past J2000 TDB. */
124 /*                    - Position components have units of km. */
125 
126 /*                 RECORD must be declared by the caller with size large */
127 /*                 enough to accommodate the largest record that can be */
128 /*                 returned by this routine. See the INCLUDE file */
129 /*                 spkrec.inc for the correct record length. */
130 
131 /* $ Parameters */
132 
133 /*     None. */
134 
135 /* $ Exceptions */
136 
137 /*     1) Any errors that occur while looking up SPK data will be */
138 /*        diagnosed by routines in the call tree of this routine. */
139 
140 /* $ Files */
141 
142 /*     See argument HANDLE. */
143 
144 /* $ Particulars */
145 
146 /*     See the SPK Required Reading file for a description of the */
147 /*     structure of a data type 2 (Chebyshev polynomials, position */
148 /*     only) segment. */
149 
150 /* $ Examples */
151 
152 /*     The data returned by the SPKRnn routine is in its rawest form, */
153 /*     taken directly from the segment.  As such, it will be meaningless */
154 /*     to a user unless he/she understands the structure of the data type */
155 /*     completely.  Given that understanding, however, the SPKRxx */
156 /*     routines might be used to "dump" and check segment data for a */
157 /*     particular epoch. */
158 
159 
160 /*     C */
161 /*     C     Get a segment applicable to a specified body and epoch. */
162 /*     C */
163 /*           CALL SPKSFS ( BODY, ET, HANDLE, DESCR, IDENT, FOUND ) */
164 
165 /*     C */
166 /*     C     Look at parts of the descriptor. */
167 /*     C */
168 /*           CALL DAFUS ( DESCR, 2, 6, DCD, ICD ) */
169 /*           CENTER = ICD( 2 ) */
170 /*           REF    = ICD( 3 ) */
171 /*           TYPE   = ICD( 4 ) */
172 
173 /*           IF ( TYPE .EQ. 2 ) THEN */
174 /*              CALL SPKR02 ( HANDLE, DESCR, ET, RECORD ) */
175 /*                  . */
176 /*                  .  Look at the RECORD data. */
177 /*                  . */
178 /*           END IF */
179 
180 /* $ Restrictions */
181 
182 /*     None. */
183 
184 /* $ Literature_References */
185 
186 /*     NAIF Document 168.0, "S- and P- Kernel (SPK) Specification and */
187 /*     User's Guide" */
188 
189 /* $ Author_and_Institution */
190 
191 /*     I.M. Underwood  (JPL) */
192 
193 /* $ Version */
194 
195 /* -    SPICELIB Version 1.1.1, 18-JAN-2014 (NJB) */
196 
197 /*        Enhanced header and in-line documentation. */
198 
199 /* -    SPICELIB Version 1.1.0, 07-SEP-2001 (EDW) */
200 
201 /*        Replaced DAFRDA call with DAFGDA. */
202 /*        Added IMPLICIT NONE. */
203 
204 /* -    SPICELIB Version 1.0.3, 10-MAR-1992 (WLT) */
205 
206 /*        Comment section for permuted index source lines was added */
207 /*        following the header. */
208 
209 /* -    SPICELIB Version 1.0.2, 23-AUG-1991 (HAN) */
210 
211 /*        SPK02 was removed from the Required_Reading section of the */
212 /*        header. The information in the SPK02 Required Reading file */
213 /*        is now part of the SPK Required Reading file. */
214 
215 /* -    SPICELIB Version 1.0.1, 22-MAR-1990 (HAN) */
216 
217 /*        Literature references added to the header. */
218 
219 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
220 
221 /* -& */
222 /* $ Index_Entries */
223 
224 /*     read record from type_2 spk segment */
225 
226 /* -& */
227 
228 /*     SPICELIB functions */
229 
230 
231 /*     Local variables */
232 
233 
234 /*     Standard SPICE error handling. */
235 
236     if (return_()) {
237 	return 0;
238     } else {
239 	chkin_("SPKR02", (ftnlen)6);
240     }
241 
242 /*     Unpack the segment descriptor. */
243 
244     dafus_(descr, &c__2, &c__6, dc, ic);
245     begin = ic[4];
246     end = ic[5];
247 
248 /*     The segment is made up of a number of logical records, each */
249 /*     having the same size, and covering the same length of time. */
250 
251 /*     We can determine which record to return using the input epoch, */
252 /*     the initial time of the first record's coverage interval, and the */
253 /*     length of the interval covered by each record. These constants */
254 /*     are located at the end of the segment, along with the size of */
255 /*     each logical record and the total number of records. */
256 
257     i__1 = end - 3;
258     dafgda_(handle, &i__1, &end, record);
259     init = record[0];
260     intlen = record[1];
261     recsiz = (integer) record[2];
262     nrec = (integer) record[3];
263     recno = (integer) ((*et - init) / intlen) + 1;
264     recno = min(recno,nrec);
265 
266 /*     Compute the address of the desired record. */
267 
268     recadr = (recno - 1) * recsiz + begin;
269 
270 /*     Along with the record, return the size of the record. */
271 
272     record[0] = record[2];
273     i__1 = recadr + recsiz - 1;
274     dafgda_(handle, &recadr, &i__1, &record[1]);
275     chkout_("SPKR02", (ftnlen)6);
276     return 0;
277 } /* spkr02_ */
278 
279