1 /* ckw04e.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      CKW04E ( CK type 04: End a segment ) */
ckw04e_(integer * handle,doublereal * endtim)14 /* Subroutine */ int ckw04e_(integer *handle, doublereal *endtim)
15 {
16     extern /* Subroutine */ int dafgs_(doublereal *), chkin_(char *, ftnlen),
17 	    dafps_(integer *, integer *, doublereal *, integer *, doublereal *
18 	    ), dafrs_(doublereal *);
19     doublereal descr[5];
20     extern /* Subroutine */ int dafus_(doublereal *, integer *, integer *,
21 	    doublereal *, integer *);
22     logical found;
23     extern /* Subroutine */ int sgwes_(integer *), dafbbs_(integer *),
24 	    daffpa_(logical *);
25     extern logical failed_(void);
26     extern /* Subroutine */ int sigerr_(char *, ftnlen), chkout_(char *,
27 	    ftnlen), setmsg_(char *, ftnlen);
28     extern logical return_(void);
29     doublereal dcd[2];
30     integer icd[6];
31 
32 /* $ Abstract */
33 
34 /*     End the type 04 CK segment currently being written to the DAF */
35 /*     file associated with HANDLE. See also CKW04B and CKW04E. */
36 
37 /* $ Disclaimer */
38 
39 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
40 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
41 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
42 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
43 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
44 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
45 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
46 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
47 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
48 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
49 
50 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
51 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
52 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
53 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
54 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
55 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
56 
57 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
58 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
59 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
60 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
61 
62 /* $ Required_Reading */
63 
64 /*     CK */
65 /*     DAF */
66 
67 /* $ Keywords */
68 
69 /*     POINTING */
70 
71 /* $ Declarations */
72 /* $ Brief_I/O */
73 
74 /*     VARIABLE  I/O  DESCRIPTION */
75 /*     --------  ---  -------------------------------------------------- */
76 /*     HANDLE     I   The handle of an CK file open for writing. */
77 /*     ENDTIM     I   The segment coverage end encoded SCLK time. */
78 
79 /* $ Detailed_Input */
80 
81 /*     HANDLE     is the file handle of an CK file that has been */
82 /*                opened for writing, and to which a type 4 CK segment */
83 /*                is being written. */
84 
85 /*     ENDTIM     is the encoded SCLK time for the end of the segment */
86 /*                coverage. */
87 
88 /* $ Detailed_Output */
89 
90 /*     None.       The type 4 segment in the DAF file associated with */
91 /*                 HANDLE will be ended, making the addition of the */
92 /*                 data to the file permanent. */
93 
94 /* $ Parameters */
95 
96 /*     None. */
97 
98 /* $ Exceptions */
99 
100 /*     1)  Errors reading or writing the file indicated by HANDLE will */
101 /*         be diagnosed by routine in the call tree of this routine. */
102 
103 /* $ Files */
104 
105 /*     See the argument HANDLE. */
106 
107 /* $ Particulars */
108 
109 /*     This routine ends a type 4 CK segment which is being written to */
110 /*     the DAF file associated with HANDLE. Ending the DAF segment is a */
111 /*     necessary step in the process of making the data a permanent part */
112 /*     of the DAF file. */
113 
114 /*     This routine is one of a set of three routines for creating and */
115 /*     adding data to type 4 CK segments. These routines are: */
116 
117 /*        CKW04B: Begin a type 4 CK segment. This routine must be */
118 /*                called before any data may be added to a type 4 */
119 /*                segment. */
120 
121 /*        CKW04A: Add data to a type 4 CK segment. This routine may be */
122 /*                called any number of times after a call to CKW04B to */
123 /*                add type 4 records to the CK segment that was */
124 /*                started. */
125 
126 /*        CKW04E: End a type 4 CK segment. This routine is called to */
127 /*                make the type 4 segment a permanent addition to the */
128 /*                DAF file. Once this routine is called, no further type */
129 /*                4 records may be added to the segment. A new segment */
130 /*                must be started. */
131 
132 /*     A type 4 CK segment consists of coefficient sets for variable */
133 /*     order Chebyshev polynomials over consecutive time intervals of */
134 /*     a variable length. The gaps between intervals are allowed. */
135 /*     The Chebyshev polynomials represent individual quaternion */
136 /*     components q0, q1, q2 and q3 and individual angular velocities */
137 /*     AV1, AV2 and AV3 if they are included with the data. */
138 
139 /*     The pointing data supplied to the type 4 CK writer (CKW04A) */
140 /*     is packed into an array as a sequence of records, */
141 
142 /*        ---------------------------------------------------- */
143 /*        | Record 1 | Record 2 | .. | Record N-1 | Record N | */
144 /*        ---------------------------------------------------- */
145 
146 /*     with each record in data packets has the following format. */
147 
148 /*        ---------------------------------------------------- */
149 /*        | The midpoint of the approximation interval       | */
150 /*        ---------------------------------------------------- */
151 /*        | The radius of the approximation interval         | */
152 /*        ---------------------------------------------------- */
153 /*        | Number of coefficients for q0                    | */
154 /*        ---------------------------------------------------- */
155 /*        | Number of coefficients for q1                    | */
156 /*        ---------------------------------------------------- */
157 /*        | Number of coefficients for q2                    | */
158 /*        ---------------------------------------------------- */
159 /*        | Number of coefficients for q3                    | */
160 /*        ---------------------------------------------------- */
161 /*        | Number of coefficients for AV1                   | */
162 /*        ---------------------------------------------------- */
163 /*        | Number of coefficients for AV2                   | */
164 /*        ---------------------------------------------------- */
165 /*        | Number of coefficients for AV3                   | */
166 /*        ---------------------------------------------------- */
167 /*        | q0 Cheby coefficients                            | */
168 /*        ---------------------------------------------------- */
169 /*        | q1 Cheby coefficients                            | */
170 /*        ---------------------------------------------------- */
171 /*        | q2 Cheby coefficients                            | */
172 /*        ---------------------------------------------------- */
173 /*        | q3 Cheby coefficients                            | */
174 /*        ---------------------------------------------------- */
175 /*        | AV1 Cheby coefficients (optional)                | */
176 /*        ---------------------------------------------------- */
177 /*        | AV2 Cheby coefficients (optional)                | */
178 /*        ---------------------------------------------------- */
179 /*        | AV3 Cheby coefficients (optional)                | */
180 /*        ---------------------------------------------------- */
181 
182 /* $ Examples */
183 
184 /*     Assume that we have: */
185 
186 /*        HANDLE   is the handle of an CK file opened with write */
187 /*                 access. */
188 
189 /*        SEGID    is a character string of no more than 40 characters */
190 /*                 which provides a pedigree for the data in the CK */
191 /*                 segment we will create. */
192 
193 /*        INST     is the SPICE ID code for the instrument whose */
194 /*                 pointing data is to be placed into the file. */
195 
196 /*        AVFLAG   angular rates flag. */
197 
198 /*        REFFRM   is the name of the SPICE reference frame for the */
199 /*                 pointing data. */
200 
201 /*        BEGTIM   is the starting encoded SCLK time for which the */
202 /*                 segment is valid. */
203 
204 /*        ENDTIM   is the ending encoded SCLK time for which the segment */
205 /*                 is valid. */
206 
207 /*        N        is the number of type 4 records that we want to */
208 /*                 put into a segment in an CK file. */
209 
210 /*        NPKTS    is integer array which contains the lengths of */
211 /*                 variable size data packets */
212 
213 /*        RECRDS   contains N type 4 records packaged for the CK */
214 /*                 file. */
215 
216 /*        SCSTRT   contains the initial encoded SC time for each of */
217 /*                 the records contained in RECRDS, where */
218 
219 /*                    SCSTRT(I) < SCSTRT(I+1), I = 1, N-1 */
220 
221 /*                    SCSTRT(1) <= FIRST, SCSTRT(N) < LAST */
222 
223 /*     Then the following code fragment demonstrates how to create */
224 /*     a type 4 CK segment if all of the data for the segment is */
225 /*     available at one time. */
226 
227 /*     C */
228 /*     C     Begin the segment. */
229 /*     C */
230 /*           CALL CKW04B ( HANDLE, BEGTIM, INST, REF, AVFLAG, SEGID ) */
231 /*     C */
232 /*     C     Add the data to the segment all at once. */
233 /*     C */
234 /*           CALL CKW04A ( HANDLE, N, NPKTS, RECRDS, SCSTRT ) */
235 /*     C */
236 /*     C     End the segment, making the segment a permanent */
237 /*     C     addition to the CK file. */
238 /*     C */
239 /*           CALL CKW04E ( HANDLE, ENDTIM ) */
240 
241 /* $ Restrictions */
242 
243 /*     1) The type 4 CK segment being closed must have been started by */
244 /*        the routine CKW04B, the routine which begins a type 4 CK */
245 /*        segment. */
246 
247 /* $ Literature_References */
248 
249 /*     None. */
250 
251 /* $ Author_and_Institution */
252 
253 /*     Y.K. Zaiko     (JPL) */
254 /*     B.V. Semenov   (JPL) */
255 
256 /* $ Version */
257 
258 /* -    SPICELIB Version 1.0.1, 18-APR-2014 (BVS) */
259 
260 /*        Minor header edits. */
261 
262 /* -    SPICELIB Version 1.0.0, 05-MAY-1999 (YKZ) (BVS) */
263 
264 /* -& */
265 /* $ Index_Entries */
266 
267 /*     end a type_4 ck segment */
268 
269 /* -& */
270 
271 /*     SPICELIB functions. */
272 
273 
274 /*     Local parameters. */
275 
276 
277 /*     DAF ND and NI values for CK files and length of a DAF descriptor. */
278 
279 
280 /*     Local variables. */
281 
282 
283 /*     Standard SPICELIB error handling. */
284 
285     if (return_()) {
286 	return 0;
287     } else {
288 	chkin_("CKW04E", (ftnlen)6);
289     }
290 
291 /*     This is simple, just call the routine which ends a generic */
292 /*     segment. */
293 
294     sgwes_(handle);
295     if (failed_()) {
296 	chkout_("CKW04E", (ftnlen)6);
297 	return 0;
298     }
299 
300 /*     Now update the descriptor with the end time. Locate the segment */
301 /*     with a backward search. */
302 
303     dafbbs_(handle);
304     daffpa_(&found);
305     if (! found) {
306 
307 /*        We have a bug. */
308 
309 	setmsg_("The segment which was just written could not be found by a "
310 		"DAF search. This  indicates a serious error.  Contact NAIF.",
311 		(ftnlen)118);
312 	sigerr_("SPICE(BUG)", (ftnlen)10);
313 	chkout_("CKW04E", (ftnlen)6);
314 	return 0;
315     }
316 
317 /*     Get the descriptor, set the end time, and update the descriptor */
318 /*     in the file. */
319 
320     dafgs_(descr);
321     dafus_(descr, &c__2, &c__6, dcd, icd);
322     dcd[1] = *endtim;
323     dafps_(&c__2, &c__6, dcd, icd, descr);
324     dafrs_(descr);
325 
326 /*     All done. */
327 
328     chkout_("CKW04E", (ftnlen)6);
329     return 0;
330 } /* ckw04e_ */
331 
332