1 /* spk14a.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 /* $Procedure      SPK14A ( SPK type 14: Add data to a segment ) */
spk14a_(integer * handle,integer * ncsets,doublereal * coeffs,doublereal * epochs)9 /* Subroutine */ int spk14a_(integer *handle, integer *ncsets, doublereal *
10 	coeffs, doublereal *epochs)
11 {
12     extern /* Subroutine */ int chkin_(char *, ftnlen), errhan_(char *,
13 	    integer *, ftnlen), sigerr_(char *, ftnlen), chkout_(char *,
14 	    ftnlen), sgwfpk_(integer *, integer *, doublereal *, integer *,
15 	    doublereal *), setmsg_(char *, ftnlen), errint_(char *, integer *,
16 	     ftnlen);
17     extern logical return_(void);
18 
19 /* $ Abstract */
20 
21 /*     Add data to a type 14 SPK segment associated with HANDLE. See */
22 /*     also SPK14B and SPK14E. */
23 
24 /* $ Disclaimer */
25 
26 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
27 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
28 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
29 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
30 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
31 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
32 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
33 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
34 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
35 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
36 
37 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
38 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
39 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
40 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
41 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
42 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
43 
44 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
45 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
46 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
47 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
48 
49 /* $ Required_Reading */
50 
51 /*     SPK */
52 
53 /* $ Keywords */
54 
55 /*     SPK */
56 
57 /* $ Declarations */
58 /* $ Brief_I/O */
59 
60 /*     VARIABLE  I/O  DESCRIPTION */
61 /*     --------  ---  -------------------------------------------------- */
62 /*     HANDLE     I   The handle of an SPK file open for writing. */
63 /*     NCSETS     I   The number of coefficient sets and epochs. */
64 /*     COEFFS     I   The collection of coefficient sets. */
65 /*     EPOCHS     I   The epochs associated with the coefficient sets. */
66 
67 /* $ Detailed_Input */
68 
69 /*     HANDLE   is the file handle of an SPK file that has been */
70 /*              opened for writing. */
71 
72 /*     NCSETS   is the number of Chebyshev coefficient sets and epochs */
73 /*              to be stored in the segment. */
74 
75 /*     COEFFS   contains a time-ordered array of Chebyshev coefficient */
76 /*              sets for computing the state vector of a body packed one */
77 /*              after the other into an array. A state vector contains */
78 /*              the position, X, Y, Z coordinates, and the velocities, */
79 /*              dX/dt, dY/dt, dZ/dt, for the position of a body relative */
80 /*              to a center of motion. */
81 
82 /*              See the $ Particulars section for details on how to store */
83 /*              the coefficient sets in the array. */
84 
85 /*     EPOCHS   contains the initial epochs (ephemeris seconds past */
86 /*              J2000) corresponding to the Chebyshev coefficients in */
87 /*              COEFFS. The I'th epoch is associated with the I'th */
88 /*              Chebyshev coefficient set. The epochs must form a */
89 /*              strictly increasing sequence. */
90 
91 /* $ Detailed_Output */
92 
93 /*     None.    The ephemeris data is stored in a segment in the SPK file */
94 /*              associated with HANDLE. */
95 
96 /*              See the $ Particulars section for details about the */
97 /*              structure of a type 14 SPK segment. */
98 
99 /* $ Parameters */
100 
101 /*     None. */
102 
103 /* $ Particulars */
104 
105 /*     This routine adds data to a type 14 SPK segment that is associated */
106 /*     with HANDLE. The segment must have been started by a call to the */
107 /*     routine SPK14B, the routine which begins a type 14 SPK segment. */
108 
109 /*     This routine is one of a set of three routines for creating and */
110 /*     adding data to type 14 SPK segments. These routines are: */
111 
112 /*        SPK14B: Begin a type 14 SPK segment. This routine must be */
113 /*                called before any data may be added to a type 14 */
114 /*                segment. */
115 
116 /*        SPK14A: Add data to a type 14 SPK segment. This routine may be */
117 /*                called any number of times after a call to SPK14B to */
118 /*                add type 14 records to the SPK segment that was */
119 /*                started. */
120 
121 /*        SPK14E: End a type 14 SPK segment. This routine is called to */
122 /*                make the type 14 segment a permanent addition to the */
123 /*                SPK file. Once this routine is called, no further type */
124 /*                14 records may be added to the segment. A new segment */
125 /*                must be started. */
126 
127 /*     A type 14 SPK segment consists of coefficient sets for fixed order */
128 /*     Chebyshev polynomials over consecutive time intervals, where the */
129 /*     time intervals need not all be of the same length. The Chebyshev */
130 /*     polynomials represent the position, X, Y, and Z coordinates, and */
131 /*     the velocities, dX/dt, dY/dt, and dZ/dt, of BODY relative to */
132 /*     CENTER. */
133 
134 /*     The ephemeris data supplied to the type 14 SPK writer is packed */
135 /*     into an array as a sequence of logical records, */
136 
137 /*        ----------------------------------------------------- */
138 /*        | Record 1 | Record 2 | ... | Record N-1 | Record N | */
139 /*        ----------------------------------------------------- */
140 
141 /*     with each record has the following format. */
142 
143 /*           ------------------------------------------------ */
144 /*           |  The midpoint of the approximation interval  | */
145 /*           ------------------------------------------------ */
146 /*           |  The radius of the approximation interval    | */
147 /*           ------------------------------------------------ */
148 /*           |  CHBDEG+1 coefficients for the X coordinate  | */
149 /*           ------------------------------------------------ */
150 /*           |  CHBDEG+1 coefficients for the Y coordinate  | */
151 /*           ------------------------------------------------ */
152 /*           |  CHBDEG+1 coefficients for the Z coordinate  | */
153 /*           ------------------------------------------------ */
154 /*           |  CHBDEG+1 coefficients for the X velocity    | */
155 /*           ------------------------------------------------ */
156 /*           |  CHBDEG+1 coefficients for the Y velocity    | */
157 /*           ------------------------------------------------ */
158 /*           |  CHBDEG+1 coefficients for the Z velocity    | */
159 /*           ------------------------------------------------ */
160 
161 /* $ Examples */
162 
163 /*     Assume we have the following for each of the examples that */
164 /*     follow. */
165 
166 /*        HANDLE   is the handle of an SPK file opened with write */
167 /*                 access. */
168 
169 /*        SEGID    is a character string of no more than 40 characters */
170 /*                 which provides a pedigree for the data in the SPK */
171 /*                 segment we will create. */
172 
173 /*        BODY     is the SPICE ID code for the body whose ephemeris */
174 /*                 is to be placed into the file. */
175 
176 /*        CENTER   is the center of motion for the ephemeris of BODY. */
177 
178 /*        REFFRM   is the name of the SPICE inertial reference frame */
179 /*                 for the ephemeris. */
180 
181 /*        FIRST    is the starting epoch, in seconds past J2000, for */
182 /*                 the ephemeris data to be placed into the segment. */
183 
184 /*        LAST     is the ending epoch, in seconds past J2000, for */
185 /*                 the ephemeris data to be placed into the segment. */
186 
187 /*     Example 1: */
188 
189 /*        For this example, we also assume that: */
190 
191 /*           N        is the number of type 14 records that we want to */
192 /*                    put into a segment in an SPK file. */
193 
194 /*           RECRDS   contains N type 14 records packaged for the SPK */
195 /*                    file. */
196 
197 /*           ETSTRT   contains the initial epochs for each of the */
198 /*                    records contained in RECRDS, where */
199 
200 /*                       ETSTRT(I) < ETSTRT(I+1), I = 1, N-1 */
201 
202 /*                       ETSTRT(1) <= FIRST, ETSTRT(N) < LAST */
203 
204 /*                       ETSTRT(I+1), I = 1, N-1, is the ending epoch for */
205 /*                       record I as well as the initial epoch for record */
206 /*                       I+1. */
207 
208 /*        Then the following code fragment demonstrates how to create a */
209 /*        type 14 SPK segment if all of the data for the segment is */
210 /*        available at one time. */
211 
212 /*        C */
213 /*        C     Begin the segment. */
214 /*        C */
215 /*              CALL SPK14B ( HANDLE, SEGID, BODY, CENTER, REFFRM, */
216 /*             .              FIRST,  LAST,  CHBDEG                ) */
217 /*        C */
218 /*        C     Add the data to the segment all at once. */
219 /*        C */
220 /*              CALL SPK14A ( HANDLE, N, RECRDS, ETSTRT ) */
221 /*        C */
222 /*        C     End the segment, making the segment a permanent addition */
223 /*        C     to the SPK file. */
224 /*        C */
225 /*              CALL SPK14E ( HANDLE ) */
226 
227 /*     Example 2: */
228 
229 /*        In this example we want to add type 14 SPK records, as */
230 /*        described above in the $ Particulars section, to the segment */
231 /*        being written as they are generated.  The ability to write the */
232 /*        records in this way is useful if computer memory is limited. It */
233 /*        may also be convenient from a programming perspective to write */
234 /*        the records one at a time. */
235 
236 /*        For this example, assume that we want to generate N type 14 SPK */
237 /*        records, one for each of N time intervals, writing them all to */
238 /*        the same segment in the SPK file. Let */
239 
240 /*           N        be the number of type 14 records that we want to */
241 /*                    generate and put into a segment in an SPK file. */
242 
243 /*           RECORD   be an array with enough room to hold a single type */
244 /*                    14 record, i.e. RECORD should have dimension at */
245 /*                    least 6 * (CHBDEG + 1 ) + 2. */
246 
247 /*           START    be an array of N times that are the beginning */
248 /*                    epochs for each of the intervals of interest. The */
249 /*                    times should be in increasing order and the start */
250 /*                    time for the first interval should equal the */
251 /*                    starting time for the segment. */
252 
253 /*                       START(I) < START(I+1), I = 1, N-1 */
254 
255 /*                       START(1) = FIRST */
256 
257 /*           STOP     be an array of N times that are the ending epochs */
258 /*                    for each of the intervals of interest. The times */
259 /*                    should be in increasing order and the stop time for */
260 /*                    interval I should equal the start time for interval */
261 /*                    I+1, i.e., we want to have continuous coverage in */
262 /*                    time across all of the records. Also, the stop time */
263 /*                    for the last interval should equal the ending time */
264 /*                    for the segment. */
265 
266 /*                       STOP(I) < STOP(I+1), I = 1, N-1 */
267 
268 /*                       STOP(I) = START(I+1), I = 1, N-1 */
269 
270 /*                       STOP(N) = LAST */
271 
272 /*           GENREC( TIME1, TIME2, RECORD ) */
273 
274 /*                    be a subroutine that generates a type 14 SPK record */
275 /*                    for a time interval specified by TIME1 and TIME2. */
276 
277 /*        Then the following code fragment demonstrates how to create a */
278 /*        type 14 SPK segment if all of the data for the segment is not */
279 /*        available at one time. */
280 
281 /*        C */
282 /*        C     Begin the segment. */
283 /*        C */
284 /*              CALL SPK14B ( HANDLE, SEGID, BODY, CENTER, REFFRM, */
285 /*             .              FIRST, LAST, CHBDEG                  ) */
286 
287 /*        C */
288 /*        C     Generate the records and write them to the segment in the */
289 /*        C     SPK file one at at time. */
290 /*        C */
291 /*              DO I = 1, N */
292 
293 /*                 CALL GENREC ( START(I), STOP(I), RECORD   ) */
294 /*                 CALL SPK14A ( HANDLE, 1, RECORD, START(I) ) */
295 
296 /*              END DO */
297 
298 /*        C */
299 /*        C     End the segment, making the segment a permanent addition */
300 /*        C     to the SPK file. */
301 /*        C */
302 /*              CALL SPK14E ( HANDLE ) */
303 
304 /* $ Restrictions */
305 
306 /*     1) The type 14 SPK segment to which we are adding data must have */
307 /*        been started by the routine SPK14B, the routine which begins a */
308 /*        type 14 SPK segment. */
309 
310 /* $ Exceptions */
311 
312 /*     1) If the number of coefficient sets and epochs is not positive, */
313 /*        the error SPICE(INVALIDARGUMENT) will be signalled. */
314 
315 /* $ Files */
316 
317 /*     None. */
318 
319 /* $ Author_and_Institution */
320 
321 /*     K.R. Gehringer      (JPL) */
322 
323 /* $ Literature_References */
324 
325 /*     None. */
326 
327 /* $ Version */
328 
329 /* -    SPICELIB Version 1.1.0, 07-SEP-2001 (EDW) */
330 
331 /*        Removed DAFHLU call; replaced ERRFN call with ERRHAN. */
332 
333 /* -    SPICELIB Version 1.0.0, 06-MAR-1995 (KRG) */
334 
335 /* -& */
336 /* $ Index_Entries */
337 
338 /*     add data to a type_14 spk segment */
339 
340 /* -& */
341 
342 /*     Spicelib functions */
343 
344 
345 /*     Standard SPICELIB error handling. */
346 
347     if (return_()) {
348 	return 0;
349     } else {
350 	chkin_("SPK14A", (ftnlen)6);
351     }
352 
353 /*     First, check to see if the number of coefficient sets and epochs */
354 /*     is positive. */
355 
356     if (*ncsets <= 0) {
357 	setmsg_("The number of coefficient sets and epochs to be added to th"
358 		"e SPK segment in the file '#' was not positive. Its value wa"
359 		"s: #.", (ftnlen)124);
360 	errhan_("#", handle, (ftnlen)1);
361 	errint_("#", ncsets, (ftnlen)1);
362 	sigerr_("SPICE(INVALIDARGUMENT)", (ftnlen)22);
363 	chkout_("SPK14A", (ftnlen)6);
364 	return 0;
365     }
366 
367 /*     Add the data. */
368 
369     sgwfpk_(handle, ncsets, coeffs, ncsets, epochs);
370 
371 /*     No need to check FAILED() here, since all we do is check out. */
372 /*     Leave it up to the caller. */
373 
374     chkout_("SPK14A", (ftnlen)6);
375     return 0;
376 } /* spk14a_ */
377 
378