1 /*
2 
3 -Procedure getfat_c ( Get file architecture and type )
4 
5 -Abstract
6 
7    Determine the file architecture and file type of most SPICE kernel
8    files.
9 
10 -Disclaimer
11 
12    THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE
13    CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.
14    GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE
15    ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE
16    PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS"
17    TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY
18    WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A
19    PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC
20    SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
21    SOFTWARE AND RELATED MATERIALS, HOWEVER USED.
22 
23    IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA
24    BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT
25    LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,
26    INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,
27    REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE
28    REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.
29 
30    RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF
31    THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY
32    CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE
33    ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.
34 
35 -Required_Reading
36 
37    None.
38 
39 -Keywords
40 
41    KERNEL
42    UTILITY
43 
44 */
45 
46    #include "SpiceUsr.h"
47    #include "SpiceZfc.h"
48    #include "SpiceZst.h"
49    #include "SpiceZmc.h"
50 
getfat_c(ConstSpiceChar * file,SpiceInt arclen,SpiceInt typlen,SpiceChar * arch,SpiceChar * type)51    void getfat_c ( ConstSpiceChar   * file,
52                    SpiceInt           arclen,
53                    SpiceInt           typlen,
54                    SpiceChar        * arch,
55                    SpiceChar        * type   )
56 
57 /*
58 
59 -Brief_I/O
60 
61    VARIABLE  I/O  DESCRIPTION
62    --------  ---  --------------------------------------------------
63    file       I   The name of a file to be examined.
64    arclen     I   Maximum length of output architecture string.
65    typlen     I   Maximum length of output type
66    string.
67    arch       O   The architecture of the kernel file.
68    type       O   The type of the kernel file.
69 
70 -Detailed_Input
71 
72    arclen     is the maximum length of output architecture string arch,
73               including the terminating null.  For example, if arch
74               is to hold strings having 10 characters of actual data,
75               arclen should be set to 1l.
76 
77    typlen     is the maximum length of output file type string type,
78               including the terminating null.  For example, if type
79               is to hold strings having 10 characters of actual data,
80               arclen should be set to 1l.
81 
82    file       is the name of a SPICE kernel file whose architecture
83               and type are desired. This file must be closed when
84               this routine is called.
85 
86 -Detailed_Output
87 
88    arch        is the file architecture of the SPICE kernel file
89                specified by file. If the architecture cannot be
90                determined or is not recognized the value "?" is
91                returned.
92 
93                Architectures currently recognized are:
94 
95                   DAF - The file is based on the DAF architecture.
96                   DAS - The file is based on the DAS architecture.
97                   XFR - The file is in a SPICE transfer file format.
98                   DEC - The file is an old SPICE decimal text file.
99                   ASC -- An ASCII text file.
100                   KPL -- Kernel Pool File (i.e., a text kernel)
101                   TXT -- An ASCII text file.
102                   TE1 -- Text E-Kernel type 1.
103                    ?  - The architecture could not be determined.
104 
105                This variable must be at least 3 characters long.
106 
107    type        is the type of the SPICE kernel file. If the type
108                can not be determined the value "?" is returned.
109 
110                Kernel file types may be any sequence of at most four
111                printing characters. NAIF has reserved for its use
112                types which contain all upper case letters.
113 
114                A file type of "PRE" means that the file is a
115                pre-release file.
116 
117                This variable may be at most 4 characters long.
118 
119 -Parameters
120 
121    None.
122 
123 -Exceptions
124 
125    1)  The underlying code translated to C from Fortran effectively
126        performs a Fortran INQUIRE on the specified file.  If this
127        operation fails for some reason, the error SPICE(INQUIREERROR)
128        will be signaled.
129 
130    2)  If the file specified by FILE is already open, the error
131        SPICE(FILECURRENTLYOPEN) will be signaled.
132 
133    3)  If the file specified by FILE does not exist, the error
134        SPICE(NOSUCHFILE) will be signaled.
135 
136    4)  If the attempt to open the file specified by FILE fails, the
137        error SPICE(FILEOPENFAILED) will be signaled.
138 
139    5)  If all attempts to open the file specified by FILE fail, the
140        error SPICE(FILEOPENFAILED) will be signaled.
141 
142    6)  If all attempts to read from the file specified be FILE
143        fail, the error SPICE(FILEREADFAILED) will be signaled.
144 
145    7)  The error SPICE(EMPTYSTRING) is signaled if the input
146        string does not contain at least one character, since the
147        input string cannot be converted to a Fortran-style string
148        in this case.
149 
150    8)  The error SPICE(NULLPOINTER) is signaled if the input string
151        pointer is null.
152 
153    9)  If either output string pointer is null, the error
154        SPICE(NULLPOINTER) is signaled.
155 
156    10) If an output string has length less than two characters, it
157        is too short to contain one character of output data plus a null
158        terminator, so it cannot be passed to the underlying Fortran
159        routine.  In this event, the error SPICE(STRINGTOOSHORT) is
160        signaled.
161 
162 
163 -Files
164 
165    The SPICE kernel file specified by FILE is opened and then
166    closed by this routine to determine its file architecture and
167    type. Names of open files should not be passed to this routine.
168 
169 -Particulars
170 
171    This subroutine is a support utility routine that determines the
172    architecture and type of a SPICE kernel file.
173 
174 -Examples
175 
176    Suppose you wish to write a single routine for loading binary
177    kernels. You can use this routine to determine the type of the
178    file and  then pass the file to the appropriate low level file
179    loader to handle the actual loading of the file.
180 
181       getfat_c ( file, arch, type );
182 
183       if ( eqstr_c( type, "spk" ) )
184       {
185          spklef_c ( file, &handle );
186       }
187 
188       else if ( eqstr_c( type, "ck" ) )
189       {
190          cklpf_c ( file, &handle );
191       }
192 
193       else if ( eqstr_c( type, "ek" ) )
194       {
195          eklef ( file, handle );
196       }
197 
198       else
199       {
200          printf ( "%s\n",
201                   "The file could not be identified as aknown\n"
202                   "kernel type.  Did you load the wrong file\n"
203                   "by mistake?"                                 );
204       }
205 
206 
207 -Restrictions
208 
209    The file to be examined must be closed when this routine is
210    invoked.
211 
212 -Literature_References
213 
214    None.
215 
216 -Author_and_Institution
217 
218    N.J. Bachman    (JPL)
219    K.R. Gehringer  (JPL)
220    H.A. Neilan     (JPL)
221    W.L. Taber      (JPL)
222 
223 -Version
224 
225    -CSPICE Version 1.0.0, 18-AUG-1998 (NJB)
226 
227 -Index_Entries
228 
229    determine the architecture and type of a kernel file
230 
231 -&
232 */
233 
234 { /* Begin getfat_c */
235 
236 
237    /*
238    Participate in error tracing.
239    */
240    chkin_c ( "getfat_c" );
241 
242    /*
243    Check the input file name to make sure the pointer is non-null
244    and the string length is non-zero.
245    */
246    CHKFSTR ( CHK_STANDARD, "getfat_c", file );
247 
248    /*
249    Make sure the output architecture string has at least enough room
250    for one output character and a null terminator.  Also check for a
251    null pointer.
252    */
253    CHKOSTR ( CHK_STANDARD, "getfat_c", arch, arclen );
254 
255    /*
256    Make sure the output file type string has at least enough room
257    for one output character and a null terminator.  Also check for a
258    null pointer.
259    */
260    CHKOSTR ( CHK_STANDARD, "getfat_c", type, typlen );
261 
262    getfat_ (  ( char   * ) file,
263               ( char   * ) arch,
264               ( char   * ) type,
265               ( ftnlen   ) strlen(file),
266               ( ftnlen   ) arclen-1,
267               ( ftnlen   ) typlen-1      );
268 
269 
270    /*
271    Convert each Fortran output string to a C string by placing a
272    null after the last non-blank character.  This operation is valid
273    whether or not the CSPICE routine signaled an error.
274    */
275 
276    F2C_ConvertStr ( arclen, arch );
277    F2C_ConvertStr ( typlen, type );
278 
279 
280    chkout_c ( "getfat_c" );
281 
282 } /* End getfat_c */
283