1 /*
2 
3 -Procedure spkobj_c ( SPK objects )
4 
5 -Abstract
6 
7    Find the set of ID codes of all objects in a specified SPK file.
8 
9 -Disclaimer
10 
11    THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE
12    CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.
13    GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE
14    ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE
15    PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS"
16    TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY
17    WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A
18    PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC
19    SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
20    SOFTWARE AND RELATED MATERIALS, HOWEVER USED.
21 
22    IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA
23    BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT
24    LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,
25    INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,
26    REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE
27    REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.
28 
29    RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF
30    THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY
31    CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE
32    ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.
33 
34 -Required_Reading
35 
36    CELLS
37    DAF
38    SETS
39    SPK
40 
41 -Keywords
42 
43    EPHEMERIS
44    UTILITY
45 
46 */
47 
48    #include "SpiceUsr.h"
49    #include "SpiceZfc.h"
50    #include "SpiceZmc.h"
51 
52 
spkobj_c(ConstSpiceChar * spk,SpiceCell * ids)53    void spkobj_c ( ConstSpiceChar  * spk,
54                    SpiceCell       * ids )
55 
56 /*
57 
58 -Brief_I/O
59 
60    Variable  I/O  Description
61    --------  ---  --------------------------------------------------
62    spk        I   Name of SPK file.
63    ids       I/O  Set of ID codes of objects in SPK file.
64 
65 -Detailed_Input
66 
67    spk            is the name of an SPK file.
68 
69    ids            is an initialized CSPICE set data structure.
70                   `ids' optionally may contain a set of ID codes on
71                   input; on output, the data already present in
72                   `ids' will be combined with ID code set found for the
73                   file `spk'.
74 
75                   If `ids' contains no data on input, its size and
76                   cardinality still must be initialized.
77 
78 -Detailed_Output
79 
80    ids            is a CSPICE set data structure which contains
81                   the union of its contents upon input with the set
82                   of ID codes of each object for which ephemeris
83                   data are present in the indicated SPK file. The
84                   elements of CSPICE sets are unique; hence each
85                   ID code in `ids' appears only once, even if the SPK
86                   file contains multiple segments for that ID code.
87 
88                   See the Examples section below for a complete
89                   example program showing how to retrieve the ID
90                   codes from `ids'.
91 
92 -Parameters
93 
94    None.
95 
96 -Exceptions
97 
98    1)  If the input file has transfer format, the error
99        SPICE(INVALIDFORMAT) is signaled.
100 
101    2)  If the input file is not a transfer file but has architecture
102        other than DAF, the error SPICE(BADARCHTYPE) is signaled.
103 
104    3)  If the input file is a binary DAF file of type other than
105        SPK, the error SPICE(BADFILETYPE) is signaled.
106 
107    4)  If the SPK file cannot be opened or read, the error will
108        be diagnosed by routines called by this routine.
109 
110    5)  If the size of the output set argument `ids' is insufficient to
111        contain the actual number of ID codes of objects covered by
112        the indicated SPK file, the error will be diagnosed by
113        routines called by this routine.
114 
115    6) The error SPICE(EMPTYSTRING) is signaled if the input
116       string `spk' does not contain at least one character, since the
117       input string cannot be converted to a Fortran-style string in
118       this case.
119 
120    7) The error SPICE(NULLPOINTER) is signaled if the input string
121       pointer `spk' is null.
122 
123 -Files
124 
125    This routine reads an SPK file.
126 
127 -Particulars
128 
129    This routine provides an API via which applications can determine
130    the set of objects for which there are ephemeris data in a
131    specified SPK file.
132 
133 -Examples
134 
135    1)  Display the coverage for each object in a specified SPK file.
136        Find the set of objects in the file.  Loop over the contents
137        of the ID code set:  find the coverage for each item in the
138        set and display the coverage.
139 
140           #include <stdio.h>
141           #include "SpiceUsr.h"
142 
143           int main()
144              {
145 
146              /.
147              Local parameters
148              ./
149              #define  FILSIZ         256
150              #define  MAXIV          1000
151              #define  WINSIZ         ( 2 * MAXIV )
152              #define  TIMLEN         51
153              #define  MAXOBJ         1000
154 
155              /.
156              Local variables
157              ./
158              SPICEDOUBLE_CELL        ( cover, WINSIZ );
159              SPICEINT_CELL           ( ids,   MAXOBJ );
160 
161              SpiceChar               lsk     [ FILSIZ ];
162              SpiceChar               spk     [ FILSIZ ];
163              SpiceChar               timstr  [ TIMLEN ];
164 
165              SpiceDouble             b;
166              SpiceDouble             e;
167 
168              SpiceInt                i;
169              SpiceInt                j;
170              SpiceInt                niv;
171              SpiceInt                obj;
172 
173 
174              /.
175              Load a leapseconds kernel for output time conversion.
176              SPKCOV itself does not require a leapseconds kernel.
177              ./
178              prompt_c ( "Name of leapseconds kernel > ", FILSIZ, lsk );
179              furnsh_c ( lsk );
180 
181              /.
182              Get name of SPK file.
183              ./
184              prompt_c ( "Name of SPK file           > ", FILSIZ, spk    );
185 
186              /.
187              Find the set of objects in the SPK file.
188              ./
189              spkobj_c ( spk, &ids );
190 
191              /.
192              We want to display the coverage for each object. Loop over
193              the contents of the ID code set, find the coverage for
194              each item in the set, and display the coverage.
195              ./
196              for ( i = 0;  i < card_c( &ids );  i++  )
197                 {
198                 /.
199                 Find the coverage window for the current object.
200                 Empty the coverage window each time so we don't
201                 include data for the previous object.
202                 ./
203                 obj  =  SPICE_CELL_ELEM_I( &ids, i );
204 
205                 scard_c  ( 0,        &cover );
206                 spkcov_c ( spk, obj, &cover );
207 
208                 /.
209                 Get the number of intervals in the coverage window.
210                 ./
211                 niv = wncard_c ( &cover );
212 
213                 /.
214                 Display a simple banner.
215                 ./
216                 printf ( "%s\n", "========================================" );
217 
218                 printf ( "Coverage for object %d\n", (int)obj );
219 
220                 /.
221                 Convert the coverage interval start and stop times to TDB
222                 calendar strings.
223                 ./
224                 for ( j = 0;  j < niv;  j++  )
225                    {
226                    /.
227                    Get the endpoints of the jth interval.
228                    ./
229                    wnfetd_c ( &cover, j, &b, &e );
230 
231                    /.
232                    Convert the endpoints to TDB calendar
233                    format time strings and display them.
234                    ./
235                    timout_c ( b,
236                               "YYYY MON DD HR:MN:SC.### (TDB) ::TDB",
237                               TIMLEN,
238                               timstr                                  );
239 
240                    printf ( "\n"
241                             "Interval:  %d\n"
242                             "Start:     %s\n",
243                             j,
244                             timstr            );
245 
246                    timout_c ( e,
247                               "YYYY MON DD HR:MN:SC.### (TDB) ::TDB",
248                               TIMLEN,
249                               timstr                                  );
250                    printf ( "Stop:      %s\n", timstr );
251 
252                    }
253 
254                 }
255              return ( 0 );
256 
257              }
258 
259 -Restrictions
260 
261    1) If an error occurs while this routine is updating the set
262       `ids', the set may be corrupted.
263 
264 -Literature_References
265 
266    None.
267 
268 -Author_and_Institution
269 
270    N.J. Bachman   (JPL)
271 
272 -Version
273 
274    -CSPICE Version 1.0.3, 14-JUN-2016 (EDW)
275 
276        Edit to example program to use "%d" with explicit casts
277        to int for printing SpiceInts with printf.
278 
279    -CSPICE Version 1.0.2, 01-JUL-2014 (NJB)
280 
281        Updated index entries.
282 
283    -CSPICE Version 1.0.1, 30-NOV-2007 (NJB)
284 
285        Corrected bug in first example program in header:
286        program now empties result window prior to collecting
287        data for each object. Deleted declaration of unused
288        constant NAMLEN.  Updated example to use wncard_c
289        rather than card_c.
290 
291    -CSPICE Version 1.0.0, 30-DEC-2004 (NJB)
292 
293 -Index_Entries
294 
295    find id codes of ephemeris objects in spk file
296    find id codes of bodies in spk file
297 
298 -&
299 */
300 
301 { /* Begin spkobj_c */
302 
303 
304    /*
305    Participate in error tracing.
306    */
307    if ( return_c() )
308    {
309       return;
310    }
311    chkin_c ( "spkobj_c" );
312 
313 
314    /*
315    Check the input string `spk' to make sure the pointer is non-null
316    and the string length is non-zero.
317    */
318    CHKFSTR ( CHK_STANDARD, "spkobj_c", spk );
319 
320    /*
321    Make sure cell data type is SpiceInt.
322    */
323    CELLTYPECHK ( CHK_STANDARD, "spkobj_c", SPICE_INT, ids );
324 
325    /*
326    Initialize the cell if necessary.
327    */
328    CELLINIT ( ids );
329 
330    /*
331    Call the f2c'd Fortran routine.
332    */
333    spkobj_ ( ( char       * ) spk,
334              ( integer    * ) (ids->base),
335              ( ftnlen       ) strlen(spk)   );
336 
337    /*
338    Sync the output cell.
339    */
340    if ( !failed_c() )
341    {
342       zzsynccl_c ( F2C, ids );
343    }
344 
345 
346    chkout_c ( "spkobj_c" );
347 
348 } /* End spkobj_c */
349