1 /* dafah.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__5000 = 5000;
11 static logical c_false = FALSE_;
12 static integer c__2 = 2;
13 static integer c__124 = 124;
14 static integer c__250 = 250;
15 static integer c__125 = 125;
16 static integer c__128 = 128;
17 static integer c__1 = 1;
18 static logical c_true = TRUE_;
19 
20 /* $Procedure DAFAH ( DAF, assign handles ) */
dafah_0_(int n__,char * fname,char * ftype,integer * nd,integer * ni,char * ifname,integer * resv,integer * handle,integer * unit,integer * fhset,char * access,ftnlen fname_len,ftnlen ftype_len,ftnlen ifname_len,ftnlen access_len)21 /* Subroutine */ int dafah_0_(int n__, char *fname, char *ftype, integer *nd,
22 	integer *ni, char *ifname, integer *resv, integer *handle, integer *
23 	unit, integer *fhset, char *access, ftnlen fname_len, ftnlen
24 	ftype_len, ftnlen ifname_len, ftnlen access_len)
25 {
26     /* Initialized data */
27 
28     static logical first = TRUE_;
29     static integer nft = 0;
30 
31     /* System generated locals */
32     address a__1[2];
33     integer i__1, i__2, i__3[2], i__4;
34 
35     /* Builtin functions */
36     integer s_rnge(char *, integer, char *, integer), s_cmp(char *, char *,
37 	    ftnlen, ftnlen);
38     /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen), s_cat(char *,
39 	     char **, integer *, integer *, ftnlen);
40     integer s_wdue(cilist *), do_uio(integer *, char *, ftnlen), e_wdue(void);
41 
42     /* Local variables */
43     static integer ibff;
44     static char crec[1000];
45     static doublereal drec[128];
46     static integer iarc, iamh, free, ftnd[5000], ftni[5000];
47     extern /* Subroutine */ int zzdafgfr_(integer *, char *, integer *,
48 	    integer *, char *, integer *, integer *, integer *, logical *,
49 	    ftnlen, ftnlen), zzddhfnh_(char *, integer *, logical *, ftnlen),
50 	    zzdafnfr_(integer *, char *, integer *, integer *, char *,
51 	    integer *, integer *, integer *, char *, ftnlen, ftnlen, ftnlen),
52 	    zzddhcls_(integer *, char *, logical *, ftnlen), zzddhnfo_(
53 	    integer *, char *, integer *, integer *, integer *, logical *,
54 	    ftnlen), zzddhhlu_(integer *, char *, logical *, integer *,
55 	    ftnlen), zzddhluh_(integer *, integer *, logical *), zzddhopn_(
56 	    char *, char *, char *, integer *, ftnlen, ftnlen, ftnlen),
57 	    zzplatfm_(char *, char *, ftnlen, ftnlen);
58     static integer i__;
59     extern logical elemi_(integer *, integer *);
60     extern /* Subroutine */ int chkin_(char *, ftnlen);
61     static integer bward, fthan[5000];
62     extern /* Subroutine */ int ucase_(char *, char *, ftnlen, ftnlen);
63     static integer fward;
64     extern /* Subroutine */ int errch_(char *, char *, ftnlen, ftnlen);
65     static logical found;
66     static integer ftlnk[5000];
67     extern /* Subroutine */ int copyi_(integer *, integer *);
68     extern integer ltrim_(char *, ftnlen), rtrim_(char *, ftnlen);
69     extern /* Subroutine */ int ljust_(char *, char *, ftnlen, ftnlen);
70     static char ttype[4];
71     extern logical failed_(void);
72     static char dafnam[255];
73     extern /* Subroutine */ int cleard_(integer *, doublereal *), dafrwa_(
74 	    integer *, integer *, integer *);
75     static integer findex;
76     extern integer isrchi_(integer *, integer *, integer *);
77     static char format[8], idword[8];
78     static integer fhlist[5006];
79     extern /* Subroutine */ int sigerr_(char *, ftnlen), chkout_(char *,
80 	    ftnlen), errfnm_(char *, integer *, ftnlen), removi_(integer *,
81 	    integer *), setmsg_(char *, ftnlen);
82     static integer iostat;
83     extern /* Subroutine */ int errint_(char *, integer *, ftnlen), ssizei_(
84 	    integer *, integer *), insrti_(integer *, integer *);
85     extern logical return_(void);
86     static char acc[10];
87     static integer fnb, fnd;
88     static char ifn[60];
89     static integer fni, lun;
90 
91     /* Fortran I/O blocks */
92     static cilist io___25 = { 1, 0, 0, 0, 0 };
93     static cilist io___26 = { 1, 0, 0, 0, 0 };
94     static cilist io___27 = { 1, 0, 0, 0, 0 };
95     static cilist io___28 = { 1, 0, 0, 0, 0 };
96     static cilist io___29 = { 1, 0, 0, 0, 0 };
97     static cilist io___30 = { 1, 0, 0, 0, 0 };
98 
99 
100 /* $ Abstract */
101 
102 /*     Assign handles to DAFs as they are opened. */
103 
104 /* $ Disclaimer */
105 
106 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
107 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
108 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
109 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
110 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
111 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
112 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
113 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
114 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
115 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
116 
117 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
118 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
119 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
120 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
121 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
122 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
123 
124 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
125 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
126 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
127 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
128 
129 /* $ Required_Reading */
130 
131 /*     DAF */
132 
133 /* $ Keywords */
134 
135 /*     DAF */
136 /*     FILES */
137 
138 /* $ Declarations */
139 
140 /* $ Abstract */
141 
142 /*     Parameter declarations for the DAF/DAS handle manager. */
143 
144 /* $ Disclaimer */
145 
146 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
147 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
148 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
149 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
150 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
151 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
152 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
153 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
154 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
155 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
156 
157 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
158 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
159 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
160 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
161 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
162 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
163 
164 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
165 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
166 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
167 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
168 
169 /* $ Required_Reading */
170 
171 /*     DAF, DAS */
172 
173 /* $ Keywords */
174 
175 /*     PRIVATE */
176 
177 /* $ Particulars */
178 
179 /*     This include file contains parameters defining limits and */
180 /*     integer codes that are utilized in the DAF/DAS handle manager */
181 /*     routines. */
182 
183 /* $ Restrictions */
184 
185 /*     None. */
186 
187 /* $ Author_and_Institution */
188 
189 /*     F.S. Turner       (JPL) */
190 
191 /* $ Literature_References */
192 
193 /*     None. */
194 
195 /* $ Version */
196 
197 /* -    SPICELIB Version 2.5.0, 10-MAR-2014 (BVS) */
198 
199 /*        Updated for SUN-SOLARIS-64BIT-INTEL. */
200 
201 /* -    SPICELIB Version 2.4.0, 10-MAR-2014 (BVS) */
202 
203 /*        Updated for PC-LINUX-64BIT-IFORT. */
204 
205 /* -    SPICELIB Version 2.3.0, 10-MAR-2014 (BVS) */
206 
207 /*        Updated for PC-CYGWIN-GFORTRAN. */
208 
209 /* -    SPICELIB Version 2.2.0, 10-MAR-2014 (BVS) */
210 
211 /*        Updated for PC-CYGWIN-64BIT-GFORTRAN. */
212 
213 /* -    SPICELIB Version 2.1.0, 10-MAR-2014 (BVS) */
214 
215 /*        Updated for PC-CYGWIN-64BIT-GCC_C. */
216 
217 /* -    SPICELIB Version 2.0.0, 12-APR-2012 (BVS) */
218 
219 /*        Increased FTSIZE (from 1000 to 5000). */
220 
221 /* -    SPICELIB Version 1.20.0, 13-MAY-2010 (BVS) */
222 
223 /*        Updated for SUN-SOLARIS-INTEL. */
224 
225 /* -    SPICELIB Version 1.19.0, 13-MAY-2010 (BVS) */
226 
227 /*        Updated for SUN-SOLARIS-INTEL-CC_C. */
228 
229 /* -    SPICELIB Version 1.18.0, 13-MAY-2010 (BVS) */
230 
231 /*        Updated for SUN-SOLARIS-INTEL-64BIT-CC_C. */
232 
233 /* -    SPICELIB Version 1.17.0, 13-MAY-2010 (BVS) */
234 
235 /*        Updated for SUN-SOLARIS-64BIT-NATIVE_C. */
236 
237 /* -    SPICELIB Version 1.16.0, 13-MAY-2010 (BVS) */
238 
239 /*        Updated for PC-WINDOWS-64BIT-IFORT. */
240 
241 /* -    SPICELIB Version 1.15.0, 13-MAY-2010 (BVS) */
242 
243 /*        Updated for PC-LINUX-64BIT-GFORTRAN. */
244 
245 /* -    SPICELIB Version 1.14.0, 13-MAY-2010 (BVS) */
246 
247 /*        Updated for PC-64BIT-MS_C. */
248 
249 /* -    SPICELIB Version 1.13.0, 13-MAY-2010 (BVS) */
250 
251 /*        Updated for MAC-OSX-64BIT-INTEL_C. */
252 
253 /* -    SPICELIB Version 1.12.0, 13-MAY-2010 (BVS) */
254 
255 /*        Updated for MAC-OSX-64BIT-IFORT. */
256 
257 /* -    SPICELIB Version 1.11.0, 13-MAY-2010 (BVS) */
258 
259 /*        Updated for MAC-OSX-64BIT-GFORTRAN. */
260 
261 /* -    SPICELIB Version 1.10.0, 18-MAR-2009 (BVS) */
262 
263 /*        Updated for PC-LINUX-GFORTRAN. */
264 
265 /* -    SPICELIB Version 1.9.0, 18-MAR-2009 (BVS) */
266 
267 /*        Updated for MAC-OSX-GFORTRAN. */
268 
269 /* -    SPICELIB Version 1.8.0, 19-FEB-2008 (BVS) */
270 
271 /*        Updated for PC-LINUX-IFORT. */
272 
273 /* -    SPICELIB Version 1.7.0, 14-NOV-2006 (BVS) */
274 
275 /*        Updated for PC-LINUX-64BIT-GCC_C. */
276 
277 /* -    SPICELIB Version 1.6.0, 14-NOV-2006 (BVS) */
278 
279 /*        Updated for MAC-OSX-INTEL_C. */
280 
281 /* -    SPICELIB Version 1.5.0, 14-NOV-2006 (BVS) */
282 
283 /*        Updated for MAC-OSX-IFORT. */
284 
285 /* -    SPICELIB Version 1.4.0, 14-NOV-2006 (BVS) */
286 
287 /*        Updated for PC-WINDOWS-IFORT. */
288 
289 /* -    SPICELIB Version 1.3.0, 26-OCT-2005 (BVS) */
290 
291 /*        Updated for SUN-SOLARIS-64BIT-GCC_C. */
292 
293 /* -    SPICELIB Version 1.2.0, 03-JAN-2005 (BVS) */
294 
295 /*        Updated for PC-CYGWIN_C. */
296 
297 /* -    SPICELIB Version 1.1.0, 03-JAN-2005 (BVS) */
298 
299 /*        Updated for PC-CYGWIN. */
300 
301 /* -    SPICELIB Version 1.0.1, 17-JUL-2002 */
302 
303 /*        Added MAC-OSX environments. */
304 
305 /* -    SPICELIB Version 1.0.0, 07-NOV-2001 */
306 
307 /* -& */
308 
309 /*     Unit and file table size parameters. */
310 
311 /*     FTSIZE     is the maximum number of files (DAS and DAF) that a */
312 /*                user may have open simultaneously. */
313 
314 
315 /*     RSVUNT     is the number of units protected from being locked */
316 /*                to a particular handle by ZZDDHHLU. */
317 
318 
319 /*     SCRUNT     is the number of units protected for use by scratch */
320 /*                files. */
321 
322 
323 /*     UTSIZE     is the maximum number of logical units this manager */
324 /*                will utilize at one time. */
325 
326 
327 /*     Access method enumeration.  These parameters are used to */
328 /*     identify which access method is associated with a particular */
329 /*     handle.  They need to be synchronized with the STRAMH array */
330 /*     defined in ZZDDHGSD in the following fashion: */
331 
332 /*        STRAMH ( READ   ) = 'READ' */
333 /*        STRAMH ( WRITE  ) = 'WRITE' */
334 /*        STRAMH ( SCRTCH ) = 'SCRATCH' */
335 /*        STRAMH ( NEW    ) = 'NEW' */
336 
337 /*     These values are used in the file table variable FTAMH. */
338 
339 
340 /*     Binary file format enumeration.  These parameters are used to */
341 /*     identify which binary file format is associated with a */
342 /*     particular handle.  They need to be synchronized with the STRBFF */
343 /*     array defined in ZZDDHGSD in the following fashion: */
344 
345 /*        STRBFF ( BIGI3E ) = 'BIG-IEEE' */
346 /*        STRBFF ( LTLI3E ) = 'LTL-IEEE' */
347 /*        STRBFF ( VAXGFL ) = 'VAX-GFLT' */
348 /*        STRBFF ( VAXDFL ) = 'VAX-DFLT' */
349 
350 /*     These values are used in the file table variable FTBFF. */
351 
352 
353 /*     Some random string lengths... more documentation required. */
354 /*     For now this will have to suffice. */
355 
356 
357 /*     Architecture enumeration.  These parameters are used to identify */
358 /*     which file architecture is associated with a particular handle. */
359 /*     They need to be synchronized with the STRARC array defined in */
360 /*     ZZDDHGSD in the following fashion: */
361 
362 /*        STRARC ( DAF ) = 'DAF' */
363 /*        STRARC ( DAS ) = 'DAS' */
364 
365 /*     These values will be used in the file table variable FTARC. */
366 
367 
368 /*     For the following environments, record length is measured in */
369 /*     characters (bytes) with eight characters per double precision */
370 /*     number. */
371 
372 /*     Environment: Sun, Sun FORTRAN */
373 /*     Source:      Sun Fortran Programmer's Guide */
374 
375 /*     Environment: PC, MS FORTRAN */
376 /*     Source:      Microsoft Fortran Optimizing Compiler User's Guide */
377 
378 /*     Environment: Macintosh, Language Systems FORTRAN */
379 /*     Source:      Language Systems FORTRAN Reference Manual, */
380 /*                  Version 1.2, page 12-7 */
381 
382 /*     Environment: PC/Linux, g77 */
383 /*     Source:      Determined by experiment. */
384 
385 /*     Environment: PC, Lahey F77 EM/32 Version 4.0 */
386 /*     Source:      Lahey F77 EM/32 Language Reference Manual, */
387 /*                  page 144 */
388 
389 /*     Environment: HP-UX 9000/750, FORTRAN/9000 Series 700 computers */
390 /*     Source:      FORTRAN/9000 Reference-Series 700 Computers, */
391 /*                  page 5-110 */
392 
393 /*     Environment: NeXT Mach OS (Black Hardware), */
394 /*                  Absoft Fortran Version 3.2 */
395 /*     Source:      NAIF Program */
396 
397 
398 /*     The following parameter defines the size of a string used */
399 /*     to store a filenames on this target platform. */
400 
401 
402 /*     The following parameter controls the size of the character record */
403 /*     buffer used to read data from non-native files. */
404 
405 /* $ Brief_I/O */
406 
407 /*     Variable  I/O  Entry points */
408 /*     --------  ---  -------------------------------------------------- */
409 /*     FNAME     I,O  OPR, OPW, ONW, OPN (Obsolete), HFN, FNH */
410 /*     FTYPE      I   ONW */
411 /*     ND        I,O  ONW, OPN (Obsolete), HSF */
412 /*     NI        I,O  ONW, OPN (Obsolete), HSF */
413 /*     IFNAME     I   ONW, OPN (Obsolete) */
414 /*     RESV       I   ONW, OPN (Obsolete) */
415 /*     HANDLE    I,O  OPR, OPW, ONW, OPN (Obsolete), CLS, HLU, LUH, HFN, */
416 /*                    FNH, SIH */
417 /*     UNIT      I,O  HLU, LUH */
418 /*     FHSET      O   HOF */
419 /*     ACCESS     I   SIH */
420 /*     RECL       P   OPR, OPW, ONW, OPN (Obsolete) */
421 /*     FTSIZE     P   OPR, OPW, ONW, OPN (Obsolete), CLS, HLU, LUH, HFN, */
422 /*                    FNH */
423 /*     FILEN      P   SIH */
424 
425 /* $ Detailed_Input */
426 
427 /*     FNAME       on input is the name of a DAF to be opened, or */
428 /*                 the name of a DAF about which some information */
429 /*                 (handle, logical unit) is requested. */
430 
431 /*     FTYPE       on input is a code for the type of data that is */
432 /*                 contained in the DAF file. This code has no meaning or */
433 /*                 interpretation at the level of the DAF file */
434 /*                 architecture, but is provided as a convenience for */
435 /*                 higher level software. The maximum length for the file */
436 /*                 type is four (4) characters. If the input string is */
437 /*                 longer than four characters, the first nonblank */
438 /*                 character and its three, or fewer, immediate nonblank */
439 /*                 successors will be used as the file type. The file */
440 /*                 type may not contain nonprinting characters, and it IS */
441 /*                 case sensitive. */
442 
443 /*                 NAIF has reserved for its own use file types */
444 /*                 consisting of the upper case letters (A-Z) and the */
445 /*                 digits 0-9. NAIF recommends lower case or mixed case */
446 /*                 file types be used by all others in order to avoid */
447 /*                 any conflicts with NAIF file types. */
448 
449 /*     ND          on input is the number of double precision components */
450 /*                 in each array summary of a new file. */
451 
452 /*     NI          on input is the number of integer components in each */
453 /*                 array summary in a new file. */
454 
455 /*     IFNAME      is the internal file name for a DAF to be created. */
456 
457 /*     RESV        is the number of records to be reserved in a DAF */
458 /*                 to be created. */
459 
460 /*     HANDLE      on input is the handle of a DAF about which some */
461 /*                 information (file name, logical unit) is requested, */
462 /*                 or the handle of a DAF to be closed. */
463 
464 /*     UNIT        on input is the logical unit connected to a DAF */
465 /*                 about which some information (file name, handle) is */
466 /*                 requested. */
467 
468 /*     ACCESS      is the type of access a DAF is open for, that is, */
469 /*                 either reading or writing.  The values of ACCESS */
470 /*                 may be */
471 
472 /*                    'READ' */
473 /*                    'WRITE' */
474 
475 /*                 Leading and trailing blanks are ignored, and case */
476 /*                 is not significant. */
477 
478 /* $ Detailed_Output */
479 
480 /*     FNAME       on output is the name of a DAF for which */
481 /*                 the corresponding handle or logical unit has been */
482 /*                 supplied. */
483 
484 /*     ND          on output is the number of double precision */
485 /*                 components in each array summary of an existing file. */
486 
487 /*     NI          on output is the number of integer components in */
488 /*                 each array summary in an existing file. */
489 
490 /*     HANDLE      on output is the handle of a DAF for which */
491 /*                 the corresponding file name or logical unit has been */
492 /*                 supplied. */
493 
494 /*     UNIT        on output is the logical unit connected to a DAF */
495 /*                 for which the corresponding file name or handle has */
496 /*                 been supplied. */
497 
498 /*     FHSET       is a SPICELIB set containing the handles of the */
499 /*                 currently open DAFs. */
500 
501 /* $ Parameters */
502 
503 /*     RECL        is the record length of a DAF. Each record */
504 /*                 must be large enough to hold 128 double */
505 /*                 precision numbers or 1000 characters, whichever */
506 /*                 is greater. The units in which the record length */
507 /*                 must be specified vary from environment to */
508 /*                 environment. For example, VAX Fortran requires */
509 /*                 record lengths to be specified in longwords, */
510 /*                 where two longwords equal one double precision */
511 /*                 number.  See the include file 'zzddhman.inc' for */
512 /*                 details. */
513 
514 /*     FTSIZE      is the size of the file table maintained internally */
515 /*                 by DAFAH. In effect, FTSIZE is the maximum number */
516 /*                 of DAFs that the DAF routines allow to be open */
517 /*                 simultaneously.  See the include file 'zzddhman.inc' */
518 /*                 for details. */
519 
520 /*     FILEN       is the maximum filename length.  See the include file */
521 /*                 'zzddhman.inc' for details. */
522 
523 
524 /*     INTEOC      is the ASCII decimal integer code of the character */
525 /*                 recognized by SPICE as representing the end of the */
526 /*                 comment data in the reserved record area. */
527 
528 /* $ Exceptions */
529 
530 /*     1) If DAFAH is called directly, the error SPICE(BOGUSENTRY) */
531 /*        is signalled. */
532 
533 /*     2) See entry points DAFOPR, DAFOPW, DAFONW, DAFOPN, DAFCLS, */
534 /*        DAFHSF, DAFHLU, DAFLUH, DAFHFN, DAFNFH, DAFHOF, and DAFSIH for */
535 /*        exceptions specific to those entry points. */
536 
537 /* $ Files */
538 
539 /*     All DAFs opened by this routine are specified by name. */
540 
541 /* $ Particulars */
542 
543 /*     DAFAH serves as an umbrella, allowing data to be shared by its */
544 /*     entry points: */
545 
546 /*        DAFOPR         Open for read. */
547 /*        DAFOPW         Open for write. */
548 /*        DAFONW         Open new. */
549 /*        DAFOPN         Open new. (Obsolete, use DAFONW ) */
550 
551 /*        DAFCLS         Close. */
552 
553 /*        DAFHSF         Handle to summary format. */
554 
555 /*        DAFHLU         Handle to logical unit. */
556 /*        DAFLUH         Logical to handle. */
557 
558 /*        DAFHFN         Handle to name. */
559 /*        DAFFNH         File name to handle. */
560 
561 /*        DAFHOF         Handles of open files. */
562 /*        DAFSIH         Signal invalid handles. */
563 
564 /*     Before a DAF can be used, it must be opened. Entry points */
565 /*     DAFOPR and DAFOPW provide the only means for opening an */
566 /*     existing DAF. */
567 
568 /*     Several files may be opened for use simultaneously. (This makes */
569 /*     it convenient to combine data from several files to produce a */
570 /*     single result.) As each DAF is opened, it is assigned a file */
571 /*     handle, which is used to keep track of the file internally, and */
572 /*     which is used by the calling program to refer to the file in all */
573 /*     subsequent calls to DAF routines. */
574 
575 /*     DAFs may be opened for two kinds of access: read, and write. */
576 /*     Files opened for read access may not be changed in any way. Files */
577 /*     opened for write access may be both read and written. */
578 
579 /*     DAFONW is used to open a new DAF file. This routine extends the */
580 /*     functionality of DAFOPN by providing a mechanism for associating a */
581 /*     type with the data in the DAF file. The use of this entry over */
582 /*     DAFOPN is highly recommended. */
583 
584 /*     Since the only reason for creating a new file is to write */
585 /*     something in it, all new files are opened for write access. */
586 
587 /*     Entry point DAFOPN, for opening a new DAF file, has been rendered */
588 /*     obsolete by the new entry point DAFONW. The entry point DAFOPN */
589 /*     will continue to be supported for purposes of backward */
590 /*     compatibility, but its use in new software development is */
591 /*     discouraged. */
592 
593 /*     Entry point DAFCLS provides the only official means of closing */
594 /*     a DAF that is currently open. Closing a DAF any other way (for */
595 /*     example, by determining its logical unit and using the Fortran */
596 /*     CLOSE statement directly) may affect your calling program in */
597 /*     mysterious ways. */
598 
599 /*     Entry point DAFHSF allows you to determine the summary format */
600 /*     of any DAF that is currently open, without calling DAFRFR to */
601 /*     re-read the file record. */
602 
603 /*     Entry point DAFHOF allows you to determine which DAFs are open */
604 /*     at any time.  In particular, you can use DAFHOF to determine */
605 /*     whether any file handle points to an open DAF. */
606 
607 /*     Entry point DAFSIH signals errors when it is supplied with invalid */
608 /*     handles, so it serves to centralize error handling associated */
609 /*     with invalid handles. */
610 
611 /*     The remaining entry points exist mainly to translate between */
612 /*     alternative representations of DAFs. There are three ways to */
613 /*     identify any open DAF: by name, by handle, and by logical */
614 /*     unit. Given any one of these, you may use these entry points to */
615 /*     find the other two. */
616 
617 /* $ Examples */
618 
619 /*     See entry points DAFOPR, DAFOPW, DAFONW, DAFOPN, DAFCLS, DAFHSF, */
620 /*     DAFHLU, DAFLUH, DAFHFN, DAFNFH, DAFHOF, and DAFSIH for examples */
621 /*     specific to those entry points. */
622 
623 /* $ Restrictions */
624 
625 /*     1) The value of parameter RECL may need to be changed when DAFAH */
626 /*        and its entry points are ported to a new environment (CPU and */
627 /*        compiler). */
628 
629 /*     2) An integer overflow may occur if the number of files opened */
630 /*        by a single program exceeds the maximum number that can be */
631 /*        stored in an integer variable. */
632 
633 /* $ Literature_References */
634 
635 /*     1) Sun Fortran Programmer's Guide */
636 
637 /*     2) Microsoft Fortran Optimizing Compiler User's Guide */
638 
639 /*     3) Lahey F77 EM/32 Language Reference Manual, page 144 */
640 
641 /*     4) Language Systems FORTRAN Reference Manual, Version 1.2, */
642 /*        page 12-7 */
643 
644 /*     5) "FORTRAN/9000 Reference HP 9000 Series 700 Computers", */
645 /*        First Edition, June 1991, Hewlett Packard Company, page 5-110. */
646 
647 /* $ Author_and_Institution */
648 
649 /*     K.R. Gehringer  (JPL) */
650 /*     N.J. Bachman    (JPL) */
651 /*     J.M. Lynch      (JPL) */
652 /*     J.E. McLean     (JPL) */
653 /*     H.A. Neilan     (JPL) */
654 /*     M.J. Spencer    (JPL) */
655 /*     W.L. Taber      (JPL) */
656 /*     F.S. Turner     (JPL) */
657 /*     I.M. Underwood  (JPL) */
658 
659 /* $ Version */
660 
661 /* -    SPICELIB Version 9.0.1, 10-OCT-2012 (EDW) */
662 
663 /*        Edited DAFOPN Abstract section to use "Deprecated" keyword */
664 /*        and state replacement routine. */
665 
666 /*        Corrected ordering of all header sections. */
667 
668 /*        Added a functional code example to the Examples section */
669 /*        in DAFOPN and DAFCLS. */
670 
671 /*        Removed the obsolete Reference citation to "NAIF */
672 /*        Document 167.0." */
673 
674 /* -    SPICELIB Version 9.0.0, 09-NOV-2006 (NJB) */
675 
676 /*        Updated the entry point DAFONW so that a non-empty reserved */
677 /*        record area will also be a valid empty comment area.  DAFONW */
678 /*        now writes a EOC character to the first byte of the second */
679 /*        record when the input number of reserved records NRESV is */
680 /*        greater than zero. */
681 
682 /* -    SPICELIB Version 8.1.0, 02-APR-2002 (FST) */
683 
684 /*        Updated the following entry points in response to changes */
685 /*        to the handle manager interfaces: */
686 
687 /*           DAFCLS */
688 /*           DAFOPR */
689 /*           DAFOPW */
690 /*           DAFONW */
691 /*           DAFOPN */
692 
693 /*        See the Revisions section for details. */
694 
695 /*        Minor bug fix to DAFFNH.  An error was signaled but the */
696 /*        intended call to CHKOUT and RETURN statement were omitted. */
697 
698 /* -    SPICELIB Version 8.0.0, 14-NOV-2000 (FST) */
699 
700 /*        Cleaned up entry point headers by removing duplicate */
701 /*        entries from the Revisions section where appropriate. */
702 
703 /*        Integrated the new handle manager code into this module. */
704 /*        The number of DAFs the system can load is now 1000, */
705 /*        and some supported environments can read non-native */
706 /*        binary DAFs.  See the Convert User's Guide for details. */
707 
708 /* -    SPICELIB Version 7.0.4, 08-OCT-1999 (WLT) */
709 
710 /*        The environment lines were expanded so that the supported */
711 /*        environments are now explicitely given.  New */
712 /*        environments are WIN-NT */
713 
714 /* -    SPICELIB Version 7.0.3, 16-SEP-1999 (NJB) */
715 
716 /*        CSPICE environments were added.  Some typos were corrected. */
717 
718 /* -    SPICELIB Version 7.0.2, 28-JUL-1999 (WLT) */
719 
720 /*        The environment lines were expanded so that the supported */
721 /*        environments are now explicitly given.  New */
722 /*        environments are PC-DIGITAL, SGI-O32 and SGI-N32. */
723 
724 /* -    SPICELIB Version 7.0.1, 22-MAR-1999 (WLT) */
725 
726 /*        The environment lines were expanded so that the supported */
727 /*        environments are now explicitly given.  Previously, */
728 /*        environments such as SUN-SUNOS and SUN-SOLARIS were implied */
729 /*        by the environment label SUN. */
730 
731 /* -    SPICELIB Version 7.0.0, 22-MAR-1999 (FST) */
732 
733 /*        To accommodate the DAF FTP validation check, the following */
734 /*        entry points were modified: */
735 
736 /*           DAFOPR, DAFOPW, DAFONW, DAFOPN. */
737 
738 /*        See their headers and code for the details of the changes. */
739 
740 /* -    SPICELIB Version 6.0.0, 05-APR-1998 (NJB) */
741 
742 /*        Added references to the PC-LINUX environment. */
743 
744 /* -    SPICELIB Version 5.1.0, 08-MAR-1996 (KRG) */
745 
746 /*        The Following entry points have been modified: DAFONW and */
747 /*        DAFOPN. */
748 
749 /*        The modifications support the notion of a DAF comment area, */
750 /*        and involve writing NULL filled reserved records when the */
751 /*        number of reserved records is greater than zero (0). */
752 
753 /*        Some nested IF...THEN...ELSE IF...THEN...END IF constructs */
754 /*        were expanded to be independent IF...THEN...END IF tests. */
755 /*        The tests were for IOSTAT errors on cascading write statements */
756 /*        nested in the IF...ELSE IF... statements, and this was */
757 /*        confusing. These tests were restructured so that IOSTAT is */
758 /*        tested after each write statement which is equicalent to the */
759 /*        original intent and easier to read. */
760 
761 /* -    SPICELIB Version 5.0.0, 27-SEP-1993 (KRG) */
762 
763 /*        The following entry points have had code modifications: */
764 /*        DAFOPR, DAFOPW and DAFOPN. */
765 
766 /*        A new entry point has been added: DAFONW. */
767 
768 /*        The modifications are to allow a type to be associated with a */
769 /*        DAF file. */
770 
771 /*        A new parameter has been added to this subroutine's parameter */
772 /*        list, FTYPE, so that type information may be passed to the */
773 /*        entry point DAFONW. Two new variables were added to the */
774 /*        routine as well, TARCH and TTYPE, which provide temporary */
775 /*        storage for the file architecture and type. */
776 
777 /*        Several new parameters have been added to the declarations for */
778 /*        this routine: */
779 
780 /*           ARCLEN   The length of a file architecture. */
781 
782 /*           MAXPC    The maximum decimal value for the range of */
783 /*                    printable characters. */
784 
785 /*           MINPC    The minimum decimal value for the range of */
786 /*                    printable characters. */
787 
788 /*           TYPLEN   The length of a file type. */
789 
790 /*        See the individual entry points for detailed descriptions of */
791 /*        their modifications. */
792 
793 /*        Removed the variables MINHAN and NIL, as they were not used in */
794 /*        any of the entry points, yet they had values assigned to them */
795 /*        through DATA statements. */
796 
797 /*        Made all occurrences of error message formatting of filenames */
798 /*        consistent. All filenames will be single quoted in the output */
799 /*        error message. */
800 
801 /* -    SPICELIB Version 4.0.0, 25-FEB-1993 (JML) */
802 
803 /*        In the entry points DAFOPR, DAFOPW, and DAFFNH, the INQUIRE */
804 /*        statement that checks if the file is already open now also */
805 /*        checks that the file exists. */
806 
807 /*        IOSTAT is now checked after all INQUIRE statements. */
808 
809 /*        A new variable LUN is used in DAFOPR, DAFOPW, and DAFOPN */
810 /*        for the logical unit number returned by GETLUN. */
811 
812 /*        The IF-THEN statements in DAFOPR and DAFOPW were reorganized */
813 /*        to make the routines more readable. */
814 
815 /*        In DAFOPR and DAFOPW, a long error message was added for the */
816 /*        case when the NAIF/DAF id word was not recognized. Also, the */
817 /*        file is closed when this error is signalled. */
818 
819 /*        In DAFOPR and DAFOPW, IOSTAT is now checked after the file */
820 /*        record is read. */
821 
822 /*        In DAFOPR, DAFOPW, DAFOPN, and DAFFNH, the file name is */
823 /*        checked to see if it is blank. */
824 
825 /*        In DAFOPR, DAFOPW, DAFOPN, and DAFFNH, the file name passed */
826 /*        to the FORTRAN OPEN and INQUIRE statements has been chopped */
827 /*        at the last non-blank character. */
828 
829 /*        A minor error in the particulars section of the header of */
830 /*        DAFCLS was corrected.  It formerly stated that a file could be */
831 /*        open more than once for read or write access instead of just */
832 /*        read access. */
833 
834 /* -    SPICELIB Version 3.2.0, 6-OCT-1992 (HAN) */
835 
836 /*        Module was updated to include the record length and source */
837 /*        for the Hewlett Packard UX 9000/750 environment. Moved FILEN */
838 /*        to the Declarations section, and corrected Revisions section */
839 /*        to include the last code change description, 3.1.0. */
840 
841 /* -    SPICELIB Version 3.1.1, 10-MAR-1992 (WLT) */
842 
843 /*        Comment section for permuted index source lines was added */
844 /*        following the header. */
845 
846 /* -    SPICELIB Version 3.1.0, 13-NOV-1991 (MJS) */
847 
848 /*        Module was updated to operate in the Lahey F77 EM/32 */
849 /*        PC environment. */
850 
851 /* -    SPICELIB Version 3.0.0, 03-SEP-1991 (NJB) (WLT) */
852 
853 /*        DAFAH and its entry points were modified to permit multiple */
854 /*        DAFs to be open for writing at the same time.  Also, the */
855 /*        entry points DAFHOF and DAFSIH were added. */
856 
857 /* -    SPICELIB Version 2.0.0, 25-MAR-1991 (JEM) (MJS) */
858 
859 /*        The variable MINHAN was initialized to zero and the variable */
860 /*        NEXT was saved.  DAFOPW now accepts the ID word 'NAIF/NIP' */
861 /*        as well 'NAIF/DAF'.  Spelling mistakes were corrected. */
862 
863 /* -    SPICELIB Version 1.1.0, 5-NOV-1990 (HAN) */
864 
865 /*        The parameter FTSIZE was increased from 4 to 20. */
866 
867 /* -    SPICELIB Version 1.0.1, 22-MAR-1990 (HAN) */
868 
869 /*        Literature references added to the header. */
870 
871 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
872 
873 /* -& */
874 /* $ Index_Entries */
875 
876 /*     assign daf handles */
877 
878 /* -& */
879 /* $ Revisions */
880 
881 /* -    SPICELIB Version 8.1.0, 02-APR-2002 (FST) */
882 
883 /*        The entry point ZZDDHCLS in the handle manager (ZZDDHMAN) */
884 /*        had its argument list augmented to allow files to be */
885 /*        deleted on close.  This allows the removal of a series */
886 /*        of "raw" CLOSE statements in a few of the entry points */
887 /*        of this routine. */
888 
889 /* -    SPICELIB Version 8.0.0, 14-NOV-2001 (FST) */
890 
891 /*        The DAF system now utilizes the handle manager umbrella */
892 /*        (ZZDDHMAN) and its entry points to provide most of the */
893 /*        handle and logical unit based operations that DAFAH */
894 /*        previously managed. */
895 
896 /*        FTSIZE Files with UTSIZE Units: */
897 
898 /*        In previous versions of the DAF system all files opened */
899 /*        through the DAFAH entry points were connected to logical */
900 /*        units.  In contrast, the handle manager umbrella entry */
901 /*        points allow FTSIZE files to be loaded (opened), while */
902 /*        only utilizing UTSIZE (less than FTSIZE, see the include */
903 /*        file 'zzddhman.inc') logical units.  The entry points in */
904 /*        the handle manager automatically connect and disconnect */
905 /*        loaded files from their logical units as new files are */
906 /*        loaded and accessed. */
907 
908 /*        Previously, one could buffer a logical unit associated */
909 /*        with a particular handle and access the file directly */
910 /*        with Fortran I/O statements.  To preserve this capability */
911 /*        invoking DAFHLU locks a handle to its assigned logical */
912 /*        unit, until that lock is removed (see ZZDDHUNL, an entry */
913 /*        point in ZZDDHMAN) or the file is closed.  See the */
914 /*        Revisions section in the DAFHLU entry point for details. */
915 
916 /*        Another consequence of the utilization of the handle */
917 /*        manager code is that the process of connecting a file */
918 /*        name to a HANDLE may require performing up to FTSIZE */
919 /*        INQUIRE statements.  This is necessary to insure that */
920 /*        different names referring to the same file return the */
921 /*        same handle.  This was the case previously with the DAF */
922 /*        system since an INQUIRE on a different, but equivalent, */
923 /*        file name would produce the same logical unit. */
924 
925 /*        FTP Error Detection: */
926 
927 /*        The FTP error detection software is now integrated into */
928 /*        the handle manager umbrella entry points, and as such */
929 /*        is no longer present in DAFAH. */
930 
931 /*        Non-Native Files: */
932 
933 /*        In addition to expanding the number of loaded files the */
934 /*        DAF system supports, the handle manager also detects and */
935 /*        tracks binary file formats.  This allows a layer of */
936 /*        private code that has been inserted between DAF routines */
937 /*        and the Fortran I/O statements to provide translation */
938 /*        services for DAF.  Some environments are now endowed with */
939 /*        the ability to read files created with certain non-native */
940 /*        binary file formats.  See the Convert User's Guide for */
941 /*        details. */
942 
943 /* -    SPICELIB Version 7.0.0, 22-MAR-1999 (FST) */
944 
945 /*        Binary File Format Identification: */
946 
947 /*        The file record now contains an 8 character string that */
948 /*        identifies the binary file format utilized by DAFs. */
949 /*        The purpose of this string's inclusion in the file record */
950 /*        is preparatory in nature, to accelerate the migration to */
951 /*        files that support the runtime translation update that */
952 /*        is scheduled. */
953 
954 /*        FTP Validation: */
955 
956 /*        The DAF system now employs a validation scheme to assist */
957 /*        users in detecting DAFs potentially corrupted via ASCII mode */
958 /*        FTP transfers.  A string that contains sequences of */
959 /*        characters commonly corrupted by improper FTP transfers is */
960 /*        inserted into the unused portion of the file record. When any */
961 /*        DAFAH entry point attempts to open a file, this string is */
962 /*        located and examined.  If the string indicates the file is */
963 /*        corrupted, the entry point signals an error. */
964 
965 /*           Detection Scheme Implementation: */
966 
967 /*           When a new DAF is created, the entry points DAFONW and */
968 /*           DAFOPN(obsolete) retrieve the FTP validation string from */
969 /*           the defining routine (ZZFTPSTR) and insert it into the */
970 /*           tail of the file record.  A diagram illustrating the new */
971 /*           file record for 32-bit environments with single byte */
972 /*           characters follows: */
973 
974 /*              +=============+ */
975 /*              | File Record | */
976 /*              |    Data     | */
977 /*              +=============+ */
978 /*                     | */
979 /*               +=====|===+==========================+===+========+ */
980 /*               |     |   |    603 bytes of nulls    | | | nulls  | */
981 /*               +=========+==========================+=|=+========+ */
982 /*           Byte 1                                     |         1024 */
983 /*                                                 +============+ */
984 /*                                                 | FTP        | */
985 /*                                                 | Validation | */
986 /*                                                 | String     | */
987 /*                                                 +============+ */
988 
989 /*           As can be seen above, the file record is now null padded, */
990 /*           which was not the case previously. */
991 
992 /*           When an existing DAF is opened, the entry points DAFOPR */
993 /*           and DAFOPW attempt to verify that the validation string is */
994 /*           intact.  This is accomplished by reading the file */
995 /*           record into a character string, and then passing the last */
996 /*           half of this string into the validation subroutine */
997 /*           ZZFTPCHK.  Only sending the latter half of the file record */
998 /*           into ZZFTPCHK is done to prevent other portions of the file */
999 /*           record from confusing the validation process.  The following */
1000 /*           three abnormal situations may arise during validation: */
1001 
1002 /*              (1) Older DAFs without the FTP validation string are */
1003 /*                  not validated.  As far as the DAF open routines */
1004 /*                  are concerned such files are valid by default. The */
1005 /*                  only notable exception is that the garbage that */
1006 /*                  resides in the unused portion of the file record may */
1007 /*                  confuse ZZFTPCHK into thinking the validation */
1008 /*                  string is present.  (The probability of this event */
1009 /*                  is minimal and noted only for completeness.) */
1010 
1011 /*              (2) Files with an older version of the validation */
1012 /*                  string are examined for errors supported by the */
1013 /*                  contemporaneous version of the Toolkit. */
1014 
1015 /*              (3) Files with a newer version of the validation */
1016 /*                  string are examined for errors supported by the */
1017 /*                  current version of the Toolkit. */
1018 
1019 /*           Updates to the FTP Validation String: */
1020 
1021 /*           In the event that it becomes necessary to add additional */
1022 /*           test characters to the validation string, refer to */
1023 /*           ZZFTPSTR for the proper procedure.  The instructions */
1024 /*           provided there ensure that the above behavior is properly */
1025 /*           adhered to by the modifications. */
1026 
1027 /*           FTP Validation Issues in Code Portability: */
1028 
1029 /*           The scheme as currently implemented will function */
1030 /*           properly in any computing environment whose character data */
1031 /*           conforms to the single byte ASCII standards with a word */
1032 /*           size that is between 32 and 64 bits inclusive.  Refer to */
1033 /*           the above diagram that displays the new DAF file record */
1034 /*           and the following discussion for details. */
1035 
1036 /*           Since the DAF file record block contains integer data, */
1037 /*           it may expand if the word size increases above the */
1038 /*           currently supported 32 bits.  However, the FTP validation */
1039 /*           string is extracted by reading in 1000 bytes of character */
1040 /*           data and examining bytes 500-1000. (See the parameters */
1041 /*           FTPBLK and FTPSTR if you need to alter these numbers). */
1042 /*           So as long as the alteration in word size does not cause */
1043 /*           the FTP string information to shift out of bytes 500-1000 */
1044 /*           in the file record, the existing code will function */
1045 /*           properly. */
1046 
1047 /* -    SPICELIB Version 3.2.0, 6-OCT-1992 (HAN) */
1048 
1049 /*        The code was also reformatted so that a utility program can */
1050 /*        create the source file for a specific environment given a */
1051 /*        master source file. */
1052 
1053 /* -    SPICELIB Version 3.0.0, 03-SEP-1991 (NJB) (WLT) */
1054 
1055 /*        DAFAH and the entry point DAFOPW were modified to permit */
1056 /*        multiple DAFs to be open for writing at the same time. */
1057 /*        Also, the entry points DAFHOF and DAFSIH were added.  DAFHOF */
1058 /*        returns a set containing the handles of currently open DAFs. */
1059 /*        To accommodate the addition of DAFHOF, the argument FHSET */
1060 /*        was added to DAFAH's argument list, and local declarations */
1061 /*        for DAFHOF were added to DAFAH's declaration section.  DAFSIH */
1062 /*        signals an error if the file indicated by the handle is not */
1063 /*        open for the specified type of access. */
1064 
1065 /* -    SPICELIB Version 2.0.0, 24-JAN-1991 (JEM) (MJS) */
1066 
1067 /*        The entry point DAFOPW accepted only 'NAIF/DAF' as a valid */
1068 /*        ID word.  It now accepts 'NAIF/NIP' as well for */
1069 /*        backwards compatibility.  The entry point DAFOPR did not need */
1070 /*        this fix because it already accepts both ID words. */
1071 
1072 /* -    SPICELIB Version 1.1.0,  5-NOV-1990 (HAN) */
1073 
1074 /*        The parameter FTSIZE was increased from 4 to 20. The number */
1075 /*        4 was chosen for testing purposes and was not removed. */
1076 
1077 /* -& */
1078 
1079 /*     SPICELIB functions */
1080 
1081 
1082 /*     Local parameters */
1083 
1084 
1085 /*     Local variables */
1086 
1087 
1088 /*     As each file is opened, it is assigned a handle, and the */
1089 /*     internal file name is stored for comparison with other files. */
1090 /*     All names in the file table begin with FT. */
1091 
1092 /*        HAN      Handle */
1093 /*        LNK      Number of links */
1094 /*        ND, */
1095 /*        NI       Summary format */
1096 
1097 /*     The columns are stored in no particular order. New files are */
1098 /*     added to the end of the list; the list is repacked whenever a */
1099 /*     file is removed from the list. */
1100 
1101 /*     NFT is the number of files currently opened: this may not be */
1102 /*     greater than FTSIZE. FINDEX refers to a file of interest within */
1103 /*     the table. */
1104 
1105 /*     NEXT is incremented each time a file is opened to become the */
1106 /*     next file handle assigned. */
1107 
1108 
1109 /*     Other local variables */
1110 
1111 
1112 /*     Saved variables */
1113 
1114 
1115 /*     Save everything between calls. */
1116 
1117 
1118 /*     Initial values */
1119 
1120     /* Parameter adjustments */
1121     if (fhset) {
1122 	}
1123 
1124     /* Function Body */
1125     switch(n__) {
1126 	case 1: goto L_dafopr;
1127 	case 2: goto L_dafopw;
1128 	case 3: goto L_dafonw;
1129 	case 4: goto L_dafopn;
1130 	case 5: goto L_dafcls;
1131 	case 6: goto L_dafhsf;
1132 	case 7: goto L_dafhlu;
1133 	case 8: goto L_dafluh;
1134 	case 9: goto L_dafhfn;
1135 	case 10: goto L_daffnh;
1136 	case 11: goto L_dafhof;
1137 	case 12: goto L_dafsih;
1138 	}
1139 
1140 
1141 /*     Standard SPICE error handling. */
1142 
1143     if (return_()) {
1144 	return 0;
1145     } else {
1146 	chkin_("DAFAH", (ftnlen)5);
1147 	sigerr_("SPICE(BOGUSENTRY)", (ftnlen)17);
1148 	chkout_("DAFAH", (ftnlen)5);
1149     }
1150     return 0;
1151 /* $Procedure DAFOPR ( DAF, open for read ) */
1152 
1153 L_dafopr:
1154 /* $ Abstract */
1155 
1156 /*     Open a DAF for subsequent read requests. */
1157 
1158 /* $ Disclaimer */
1159 
1160 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
1161 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
1162 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
1163 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
1164 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
1165 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
1166 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
1167 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
1168 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
1169 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
1170 
1171 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
1172 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
1173 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
1174 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
1175 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
1176 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
1177 
1178 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
1179 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
1180 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
1181 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
1182 
1183 /* $ Required_Reading */
1184 
1185 /*     DAF */
1186 
1187 /* $ Keywords */
1188 
1189 /*     DAF */
1190 /*     FILES */
1191 
1192 /* $ Declarations */
1193 
1194 /*     CHARACTER*(*)         FNAME */
1195 /*     INTEGER               HANDLE */
1196 
1197 /* $ Brief_I/O */
1198 
1199 /*     Variable  I/O  Description */
1200 /*     --------  ---  -------------------------------------------------- */
1201 /*     FNAME      I   Name of DAF to be opened. */
1202 /*     HANDLE     O   Handle assigned to DAF. */
1203 
1204 /* $ Detailed_Input */
1205 
1206 /*     FNAME       is the file name of a DAF to be opened for read */
1207 /*                 access. */
1208 
1209 /* $ Detailed_Output */
1210 
1211 /*     HANDLE      is the file handle associated with the file. This */
1212 /*                 handle is used to identify the file in subsequent */
1213 /*                 calls to other DAF routines. */
1214 
1215 /* $ Parameters */
1216 
1217 /*      None. */
1218 
1219 /* $ Exceptions */
1220 
1221 /*     1) If the specified file has already been opened for read */
1222 /*        access, the handle already associated with the file is */
1223 /*        returned. */
1224 
1225 /*     2) If the specified file has already been opened for write */
1226 /*        access, an error is signaled by routines in the call */
1227 /*        tree of this routine. */
1228 
1229 /*     3) If the specified file has already been opened by a non-DAF */
1230 /*        routine, an error is signaled by routines in the call */
1231 /*        tree of this routine. */
1232 
1233 /*     4) If the specified file cannot be opened without exceeding */
1234 /*        the maximum number of files, the error SPICE(DAFFTFULL) */
1235 /*        is signaled. */
1236 
1237 /*     5) If the attempt to read the file's file record fails, */
1238 /*        the error SPICE(FILEREADFAILED) is signaled. */
1239 
1240 /*     6) If the specified file is not a DAF file, an error is */
1241 /*        signaled by routines in the call tree of this routine. */
1242 
1243 /*     7) If no logical units are available, an error is */
1244 /*        signaled by routines called by this routine. */
1245 
1246 /*     8) If the file does not exist, the error SPICE(FILENOTFOUND) */
1247 /*        is signaled by routines in the call tree of this routine. */
1248 
1249 /*     9) If an I/O error occurs in the process of opening the file, */
1250 /*        routines in the call tree of this routine signal an error. */
1251 
1252 /*    10) If the file name is blank or otherwise inappropriate */
1253 /*        routines in the call tree of this routine signal an error. */
1254 
1255 /*    11) If the file was transferred improperly via FTP, routines */
1256 /*        in the call tree of this routine signal an error. */
1257 
1258 /*    12) If the file utilizes a binary file format that is not */
1259 /*        currently supported on this platform, an error is signaled */
1260 /*        by routines in the call tree of this routine. */
1261 
1262 /* $ Files */
1263 
1264 /*     See argument FNAME. */
1265 
1266 /* $ Particulars */
1267 
1268 /*     Most DAFs require only read access. If you do not need to */
1269 /*     change the contents of a file, you should open it with DAFOPR. */
1270 
1271 /* $ Examples */
1272 
1273 /*     Example (1): */
1274 
1275 /*     In the following code fragment, DAFOPR is used to open a file, */
1276 /*     which is then searched for DAFs containing data for a particular */
1277 /*     object. */
1278 
1279 /*        CALL DAFOPR ( FNAME, HANDLE ) */
1280 /*        CALL DAFBFS ( HANDLE ) */
1281 /*        CALL DAFFNA ( FOUND  ) */
1282 
1283 /*        DO WHILE ( FOUND ) */
1284 /*           CALL DAFGS ( SUM ) */
1285 /*           CALL DAFUS ( SUM, ND, NI, DC, IC ) */
1286 
1287 /*           IF ( IC(1) .EQ. TARGET_OBJECT ) THEN */
1288 /*            . */
1289 /*            . */
1290 
1291 /*           END IF */
1292 
1293 /*           CALL DAFFNA ( FOUND ) */
1294 /*        END DO */
1295 
1296 
1297 /*     Example (2): */
1298 
1299 /*     Use a simple routine to output the double precision and integer */
1300 /*     values stored in an SPK's segments descriptors. This function */
1301 /*     opens a DAF for read, performs a forwards search for the DAF */
1302 /*     arrays, prints segments description for each array found, then */
1303 /*     closes the DAF. */
1304 
1305 /*           PROGRAM DAF_T */
1306 
1307 /*           INTEGER             HANDLE */
1308 
1309 /*     C */
1310 /*     C     Define the summary parameters appropriate */
1311 /*     C     for an SPK file. */
1312 /*     C */
1313 /*           INTEGER             ND */
1314 /*           PARAMETER         ( ND = 2 ) */
1315 
1316 /*           INTEGER             NI */
1317 /*           PARAMETER         ( NI = 6 ) */
1318 
1319 /*           INTEGER             IC( NI ) */
1320 
1321 /*           DOUBLE PRECISION    DC( ND ) */
1322 
1323 /*           CHARACTER*(32)      KERNEL */
1324 
1325 /*           LOGICAL             FOUND */
1326 
1327 
1328 /*     C */
1329 /*     C     Open a DAF for read. Return a HANDLE referring to the file. */
1330 /*     C */
1331 /*           KERNEL = 'de421.bsp' */
1332 /*           CALL DAFOPR ( KERNEL, HANDLE ) */
1333 
1334 /*     C */
1335 /*     C     Begin a forward search on the file. */
1336 /*     C */
1337 /*           CALL DAFBFS ( HANDLE ) */
1338 
1339 /*     C */
1340 /*     C     Search until a DAF array is found. */
1341 /*     C */
1342 /*           CALL DAFFNA ( FOUND ) */
1343 
1344 /*     C */
1345 /*     C     Loop while the search finds subsequent DAF arrays. */
1346 /*     C */
1347 /*           DO WHILE ( FOUND ) */
1348 
1349 /*              CALL DAFGS ( SUM ) */
1350 /*              CALL DAFUS ( SUM, ND, NI, DC, IC ) */
1351 
1352 /*              WRITE(*,*)                'Doubles: ', DC(1:ND) */
1353 /*              WRITE(*, FMT='(A,6I9)' ) 'Integers: ', IC(1:NI) */
1354 
1355 /*     C */
1356 /*     C        Check for another segment. */
1357 /*     C */
1358 /*              CALL DAFFNA ( FOUND ) */
1359 
1360 /*           END DO */
1361 
1362 /*     C */
1363 /*     C     Safely close the DAF. */
1364 /*     C */
1365 /*           CALL DAFCLS ( HANDLE ) */
1366 
1367 /*           END */
1368 
1369 /*     The program outputs: */
1370 
1371 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
1372 /*     Integers:         1        0        1        2      641   310404 */
1373 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
1374 /*     Integers:         2        0        1        2   310405   423048 */
1375 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
1376 /*     Integers:         3        0        1        2   423049   567372 */
1377 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
1378 /*     Integers:         4        0        1        2   567373   628976 */
1379 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
1380 /*     Integers:         5        0        1        2   628977   674740 */
1381 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
1382 /*     Integers:         6        0        1        2   674741   715224 */
1383 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
1384 /*     Integers:         7        0        1        2   715225   750428 */
1385 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
1386 /*     Integers:         8        0        1        2   750429   785632 */
1387 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
1388 /*     Integers:         9        0        1        2   785633   820836 */
1389 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
1390 /*     Integers:        10        0        1        2   820837   944040 */
1391 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
1392 /*     Integers:       301        3        1        2   944041  1521324 */
1393 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
1394 /*     Integers:       399        3        1        2  1521325  2098608 */
1395 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
1396 /*     Integers:       199        1        1        2  2098609  2098620 */
1397 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
1398 /*     Integers:       299        2        1        2  2098621  2098632 */
1399 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
1400 /*     Integers:       499        4        1        2  2098633  2098644 */
1401 
1402 /*      Note, the final entries in the integer array contains the segment */
1403 /*      start/end indexes. The output indicates the search proceeded */
1404 /*      from the start of the file (low value index) towards the end */
1405 /*      (high value index). */
1406 
1407 /* $ Restrictions */
1408 
1409 /*     1) Files opened using this routine must be closed with DAFCLS. */
1410 
1411 /* $ Literature_References */
1412 
1413 /*     None. */
1414 
1415 /* $ Author_and_Institution */
1416 
1417 /*     K.R. Gehringer  (JPL) */
1418 /*     N.J. Bachman    (JPL) */
1419 /*     J.M. Lynch      (JPL) */
1420 /*     W.L. Taber      (JPL) */
1421 /*     F.S. Turner     (JPL) */
1422 /*     I.M. Underwood  (JPL) */
1423 
1424 /* $ Version */
1425 
1426 /* -    SPICELIB Version 8.1.1, 10-OCT-2012 (EDW) */
1427 
1428 /*        Added a functional code example to the Examples section. */
1429 
1430 /*        Removed the unneeded Revisions section. */
1431 
1432 /*        Removed the obsolete Reference citation to "NAIF */
1433 /*        Document 167.0." */
1434 
1435 /*        Corrected ordering of header section. */
1436 
1437 /* -    SPICELIB Version 8.1.0, 02-APR-2002 (FST) */
1438 
1439 /*        This routine was updated to accomodate changes to the */
1440 /*        handle manager interface.  See DAFAH's Revision section */
1441 /*        for details. */
1442 
1443 /* -    SPICELIB Version 8.0.0, 13-NOV-2001 (FST) */
1444 
1445 /*        This routine was updated to utilize the new handle manager */
1446 /*        software to manage binary file formats and consolidated */
1447 /*        I/O code. */
1448 
1449 /* -    SPICELIB Version 7.0.4, 08-OCT-1999 (WLT) */
1450 
1451 /*        The environment lines were expanded so that the supported */
1452 /*        environments are now explicitely given.  New */
1453 /*        environments are WIN-NT */
1454 
1455 /* -    SPICELIB Version 7.0.3, 16-SEP-1999 (NJB) */
1456 
1457 /*        CSPICE environments were added.  Some typos were corrected. */
1458 
1459 /* -    SPICELIB Version 7.0.2, 28-JUL-1999 (WLT) */
1460 
1461 /*        The environment lines were expanded so that the supported */
1462 /*        environments are now explicitly given.  New */
1463 /*        environments are PC-DIGITAL, SGI-O32 and SGI-N32. */
1464 
1465 /* -    SPICELIB Version 7.0.1, 17-MAR-1999 (WLT) */
1466 
1467 /*        The environment lines were expanded so that the supported */
1468 /*        environments are now explicitly given.  Previously, */
1469 /*        environments such as SUN-SUNOS and SUN-SOLARIS were implied */
1470 /*        by the environment label SUN. */
1471 
1472 /* -    SPICELIB Version 5.0.0, 03-MAR-1999 (FST) */
1473 
1474 /*        This entry point now attempts to locate and validate the */
1475 /*        FTP validation string contained in the file record. */
1476 
1477 /*        See the Revisions section under DAFAH for a discussion */
1478 /*        of the impact of the changes made for this version. */
1479 
1480 /* -    SPICELIB Version 4.0.0, 27-SEP-1993 (KRG) */
1481 
1482 /*        This routine was modified to use a subroutine to obtain the */
1483 /*        architecture of the file rather than using hard coded values */
1484 /*        for comparison with the file ID word. This was done in order to */
1485 /*        isolate the code which checks to determine a file architecture */
1486 /*        and to make the identification of file types easier through a */
1487 /*        change to the file ID word. */
1488 
1489 /*        In particular, the changes to this routine support the change */
1490 /*        of the file ID word from 'NAIF/DAF' or 'NAIF/NIP' to 'DAF/xxxx' */
1491 /*        where 'xxxx' represents a four character mnemonic code for the */
1492 /*        type of data in the file. */
1493 
1494 /*        Removed the error SPICE(DAFNOIDWORD) as it was no longer */
1495 /*        relevant. */
1496 
1497 /*        Added the error SPICE(NOTADAFFILE) if this routine is called */
1498 /*        with a file that does not contain an ID word identifying the */
1499 /*        file as a DAF file. */
1500 
1501 /*        Changed the long error message when the error */
1502 /*        SPICE(NOTADAFFILE) is signalled to suggest that a common error */
1503 /*        is attempting to load a text version of the desired file rather */
1504 /*        than the binary version. */
1505 
1506 /* -    SPICELIB Version 3.0.0, 25-FEB-1993 (JML) */
1507 
1508 /*        The INQUIRE statement that checks if the file is already open */
1509 /*        now also checks that the file exists. */
1510 
1511 /*        A new variable LUN is used for the logical unit number */
1512 /*        returned by GETLUN. */
1513 
1514 /*        The IF-THEN statements were reorganized to improve readability. */
1515 
1516 /*        A long error message is now set when the DAF id word is not */
1517 /*        recognized.  Also, the file is closed when this error is */
1518 /*        signalled. */
1519 
1520 /*        IOSTAT is checked after the file record is read. */
1521 
1522 /*        The file name is checked to see if it is blank. */
1523 
1524 /*        The file name string that is passed to the FORTRAN OPEN and */
1525 /*        INQUIRE statements has been chopped at the last non-blank */
1526 /*        character. */
1527 
1528 /* -    SPICELIB Version 2.0.1, 10-MAR-1992 (WLT) */
1529 
1530 /*        Comment section for permuted index source lines was added */
1531 /*        following the header. */
1532 
1533 /* -    SPICELIB Version 2.0.0, 03-SEP-1991 (NJB) (WLT) */
1534 
1535 /*        This routine was updated so that it now keeps current the set */
1536 /*        of DAF handles returned by DAFHOF. */
1537 
1538 /*        Some error messages were changed so that they specify */
1539 /*        names of relevant DAFs. */
1540 
1541 /* -    SPICELIB Version 1.0.1, 22-MAR-1990 (HAN) */
1542 
1543 /*        Literature references added to the header. */
1544 
1545 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
1546 
1547 /* -& */
1548 /* $ Index_Entries */
1549 
1550 /*     open daf for read */
1551 
1552 /* -& */
1553 
1554 /*     Standard SPICE error handling. */
1555 
1556     if (return_()) {
1557 	return 0;
1558     } else {
1559 	chkin_("DAFOPR", (ftnlen)6);
1560     }
1561 
1562 /*     Initialize the handle list, if necessary. */
1563 
1564     if (first) {
1565 	ssizei_(&c__5000, fhlist);
1566 	first = FALSE_;
1567     }
1568 
1569 /*     Attempt to open the file; perform any appropriate checks. */
1570 
1571     zzddhopn_(fname, "READ", "DAF", handle, fname_len, (ftnlen)4, (ftnlen)3);
1572 
1573 /*     Check FAILED(); return if an error has occurred. */
1574 
1575     if (failed_()) {
1576 	chkout_("DAFOPR", (ftnlen)6);
1577 	return 0;
1578     }
1579 
1580 /*     See if this file is already present in the file table.  If it */
1581 /*     is simply increment its link count by one, check out and */
1582 /*     return. */
1583 
1584     findex = isrchi_(handle, &nft, fthan);
1585     if (findex != 0) {
1586 	ftlnk[(i__1 = findex - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("ftlnk",
1587 		 i__1, "dafah_", (ftnlen)1343)] = ftlnk[(i__2 = findex - 1) <
1588 		5000 && 0 <= i__2 ? i__2 : s_rnge("ftlnk", i__2, "dafah_", (
1589 		ftnlen)1343)] + 1;
1590 	chkout_("DAFOPR", (ftnlen)6);
1591 	return 0;
1592     }
1593 
1594 /*     Retrieve ND and NI from the file record. */
1595 
1596     zzdafgfr_(handle, idword, &fnd, &fni, ifn, &fward, &bward, &free, &found,
1597 	    (ftnlen)8, (ftnlen)60);
1598     if (! found) {
1599 	zzddhcls_(handle, "DAF", &c_false, (ftnlen)3);
1600 	setmsg_("Error reading the file record from the binary DAF file '#'.",
1601 		 (ftnlen)59);
1602 	errch_("#", fname, (ftnlen)1, fname_len);
1603 	sigerr_("SPICE(FILEREADFAILED)", (ftnlen)21);
1604 	chkout_("DAFOPR", (ftnlen)6);
1605 	return 0;
1606     }
1607 
1608 /*     At this point, we know that we have a valid DAF file, and we're */
1609 /*     set up to read from it, so ... */
1610 
1611 /*     Update the file table to include information about our newly */
1612 /*     opened DAF. */
1613 
1614     ++nft;
1615     fthan[(i__1 = nft - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("fthan", i__1,
1616 	    "dafah_", (ftnlen)1381)] = *handle;
1617     ftnd[(i__1 = nft - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("ftnd", i__1,
1618 	    "dafah_", (ftnlen)1382)] = fnd;
1619     ftni[(i__1 = nft - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("ftni", i__1,
1620 	    "dafah_", (ftnlen)1383)] = fni;
1621     ftlnk[(i__1 = nft - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("ftlnk", i__1,
1622 	    "dafah_", (ftnlen)1384)] = 1;
1623 
1624 /*     Insert the new handle into our handle set. */
1625 
1626     insrti_(handle, fhlist);
1627     chkout_("DAFOPR", (ftnlen)6);
1628     return 0;
1629 /* $Procedure DAFOPW ( DAF, open for write ) */
1630 
1631 L_dafopw:
1632 /* $ Abstract */
1633 
1634 /*     Open a DAF for subsequent write requests. */
1635 
1636 /* $ Disclaimer */
1637 
1638 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
1639 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
1640 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
1641 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
1642 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
1643 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
1644 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
1645 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
1646 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
1647 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
1648 
1649 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
1650 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
1651 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
1652 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
1653 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
1654 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
1655 
1656 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
1657 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
1658 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
1659 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
1660 
1661 /* $ Required_Reading */
1662 
1663 /*     DAF */
1664 
1665 /* $ Keywords */
1666 
1667 /*     DAF */
1668 /*     FILES */
1669 
1670 /* $ Declarations */
1671 
1672 /*     CHARACTER*(*)         FNAME */
1673 /*     INTEGER               HANDLE */
1674 
1675 /* $ Brief_I/O */
1676 
1677 /*     Variable  I/O  Description */
1678 /*     --------  ---  -------------------------------------------------- */
1679 /*     FNAME      I   Name of DAF to be opened. */
1680 /*     HANDLE     O   Handle assigned to DAF. */
1681 
1682 /* $ Detailed_Input */
1683 
1684 /*     FNAME       is the name of a DAF to be opened with write */
1685 /*                 access. */
1686 
1687 /* $ Detailed_Output */
1688 
1689 /*     HANDLE      is the file handle associated with the file. This */
1690 /*                 handle is used to identify the file in subsequent */
1691 /*                 calls to other DAF routines. */
1692 
1693 /* $ Parameters */
1694 
1695 /*      None. */
1696 
1697 /* $ Exceptions */
1698 
1699 /*     1) If the specified file has already been opened, either by */
1700 /*        the DAF routines or by other code, an error is signaled by */
1701 /*        routines in the call tree of this routine.  Note that this */
1702 /*        response is not paralleled by DAFOPR, which allows you */
1703 /*        to open a DAF for reading even if it is already open for */
1704 /*        reading. */
1705 
1706 /*     2) If the specified file cannot be opened without exceeding */
1707 /*        the maximum number of files, the error SPICE(DAFFTFULL) */
1708 /*        is signaled. */
1709 
1710 /*     3) If the attempt to read the file's file record fails, the */
1711 /*        error SPICE(FILEREADFAILED) will be signalled. */
1712 
1713 /*     4) If the specified file is not a DAF file, an error is */
1714 /*        signaled by routines in the call tree of this routine. */
1715 
1716 /*     5) If no logical units are available, an error is */
1717 /*        signaled by routines called by this routine. */
1718 
1719 /*     6) If the file does not exist, the error SPICE(FILENOTFOUND) */
1720 /*        is signaled by routines in the call tree of this routine. */
1721 
1722 /*     7) If an I/O error occurs in the process of opening the file, */
1723 /*        routines in the call tree of this routine signal an error. */
1724 
1725 /*     8) If the file name is blank or otherwise inappropriate */
1726 /*        routines in the call tree of this routine signal an error. */
1727 
1728 /*     9) If the file was transferred improperly via FTP, routines */
1729 /*        in the call tree of this routine signal an error. */
1730 
1731 /*    10) If the file utilizes a non-native binary file format, an */
1732 /*        error is signaled by routines in the call tree of this */
1733 /*        routine. */
1734 
1735 /* $ Files */
1736 
1737 /*     See argument FNAME. */
1738 
1739 /* $ Particulars */
1740 
1741 /*     Most DAFs require only read access. If you do not need to */
1742 /*     change the contents of a file, you should open it with DAFOPR. */
1743 /*     Use DAFOPW when you need to */
1744 
1745 /*        -- change (update) one or more summaries, names, or */
1746 /*           arrays within a file; or */
1747 
1748 /*        -- add new arrays to a file. */
1749 
1750 /* $ Examples */
1751 
1752 /*     In the following code fragment, DAFOPW is used to open a */
1753 /*     file, which is then searched for arrays containing data for */
1754 /*     a particular object. The code for the object is then changed */
1755 /*     (perhaps to reflect some new convention). */
1756 
1757 /*        CALL DAFOPW ( FNAME, HANDLE ) */
1758 /*        CALL DAFBFS ( HANDLE ) */
1759 /*        CALL DAFFNA ( FOUND  ) */
1760 
1761 /*        DO WHILE ( FOUND ) */
1762 /*           CALL DAFGS ( SUM ) */
1763 /*           CALL DAFUS ( SUM, ND, NI, DC, IC ) */
1764 
1765 /*           IF ( IC(1) .EQ. OLD_CODE ) THEN */
1766 /*              IC(1) = NEW_CODE */
1767 
1768 /*              CALL DAFPS ( ND, NI, DC, IC, SUM ) */
1769 /*              CALL DAFRS ( SUM ) */
1770 /*           END IF */
1771 
1772 /*           CALL DAFFNA ( FOUND ) */
1773 /*        END DO */
1774 
1775 /* $ Restrictions */
1776 
1777 /*     1) Only file of the native binary file format may be opened */
1778 /*        with this routine. */
1779 
1780 /*     2) Files opened using this routine must be closed with DAFCLS. */
1781 
1782 /* $ Literature_References */
1783 
1784 /*     None. */
1785 
1786 /* $ Author_and_Institution */
1787 
1788 /*     K.R. Gehringer  (JPL) */
1789 /*     N.J. Bachman    (JPL) */
1790 /*     J.M. Lynch      (JPL) */
1791 /*     J.E. McLean     (JPL) */
1792 /*     W.L. Taber      (JPL) */
1793 /*     F.S. Turner     (JPL) */
1794 /*     I.M. Underwood  (JPL) */
1795 
1796 /* $ Version */
1797 
1798 /* -    SPICELIB Version 8.1.1, 10-OCT-2012 (EDW) */
1799 
1800 /*        Corrected ordering of header section. */
1801 
1802 /*        Removed the obsolete Reference citation to "NAIF */
1803 /*        Document 167.0." */
1804 
1805 /* -    SPICELIB Version 8.1.0, 02-APR-2002 (FST) */
1806 
1807 /*        This routine was updated to accomodate changes to the */
1808 /*        handle manager interface.  See DAFAH's Revision section */
1809 /*        for details. */
1810 
1811 /* -    SPICELIB Version 8.0.0, 13-NOV-2001 (FST) */
1812 
1813 /*        This routine was updated to utilize the new handle manager */
1814 /*        software to manage binary file formats and consolidated */
1815 /*        I/O code. */
1816 
1817 /* -    SPICELIB Version 7.0.4, 08-OCT-1999 (WLT) */
1818 
1819 /*        The environment lines were expanded so that the supported */
1820 /*        environments are now explicitely given.  New */
1821 /*        environments are WIN-NT */
1822 
1823 /* -    SPICELIB Version 7.0.3, 16-SEP-1999 (NJB) */
1824 
1825 /*        CSPICE environments were added.  Some typos were corrected. */
1826 
1827 /* -    SPICELIB Version 7.0.2, 28-JUL-1999 (WLT) */
1828 
1829 /*        The environment lines were expanded so that the supported */
1830 /*        environments are now explicitly given.  New */
1831 /*        environments are PC-DIGITAL, SGI-O32 and SGI-N32. */
1832 
1833 /* -    SPICELIB Version 7.0.1, 17-MAR-1999 (WLT) */
1834 
1835 /*        The environment lines were expanded so that the supported */
1836 /*        environments are now explicitly given.  Previously, */
1837 /*        environments such as SUN-SUNOS and SUN-SOLARIS were implied */
1838 /*        by the environment label SUN. */
1839 
1840 /* -    SPICELIB Version 6.0.0, 03-MAR-1999 (FST) */
1841 
1842 /*        This entry point now attempts to locate and validate the */
1843 /*        FTP validation string contained in the file record. */
1844 
1845 /* -    SPICELIB Version 5.0.0, 27-SEP-1993 (KRG) */
1846 
1847 /*        This routine was modified to use a subroutine to obtain the */
1848 /*        architecture of the file rather than using hard coded values */
1849 /*        for comparing to the file ID word. This was done in order to */
1850 /*        isolate the code which checks to determine a file architecture, */
1851 /*        and to make the identification of file types easier through a */
1852 /*        change to the file ID word. */
1853 
1854 /*        In particular, the changes to this routine support the change */
1855 /*        of the file ID word from 'NAIF/DAF' or 'NAIF/NIP' to 'DAF/xxxx' */
1856 /*        where 'xxxx' represents a four character mnemonic code for the */
1857 /*        type of data in the file. */
1858 
1859 /*        Removed the error SPICE(DAFNOIDWORD) as it was no longer */
1860 /*        relevant. */
1861 
1862 /*        Added the error SPICE(NOTADAFFILE) if this routine is called */
1863 /*        with a file that does not contain an ID word identifying the */
1864 /*        file as a DAF file. */
1865 
1866 /*        Changed the long error message when the error */
1867 /*        SPICE(NOTADAFFILE) is signalled to suggest that a common error */
1868 /*        is attempting to load a text version of the desired file rather */
1869 /*        than the binary version. */
1870 
1871 /* -    SPICELIB Version 4.0.0, 25-FEB-1993 (JML) */
1872 
1873 /*        The INQUIRE statement that checks if the file is already open */
1874 /*        now also checks that the file exists. */
1875 
1876 /*        A new variable LUN is used for the logical unit number */
1877 /*        returned by GETLUN. */
1878 
1879 /*        The IF-THEN statements were reorganized to improve readability. */
1880 
1881 /*        A long error message is now set when the DAF id word is not */
1882 /*        recognized.  Also, the file is closed when this error is */
1883 /*        signalled. */
1884 
1885 /*        IOSTAT is now checked after the file record is read. */
1886 
1887 /*        The file name is checked to see if it is blank. */
1888 
1889 /*        The file name string that is passed to the FORTRAN OPEN and */
1890 /*        INQUIRE statements has been chopped at the last non-blank */
1891 /*        character. */
1892 
1893 /* -    SPICELIB Version 3.0.1, 10-MAR-1992 (WLT) */
1894 
1895 /*        Comment section for permuted index source lines was added */
1896 /*        following the header. */
1897 
1898 /* -    SPICELIB Version 3.0.0, 03-SEP-1991 (NJB) (WLT) */
1899 
1900 /*        DAFOPW now allows multiple files to be open for writing. */
1901 
1902 /*        This routine was updated so that it now keeps current the set */
1903 /*        of DAF handles returned by DAFHOF. */
1904 
1905 /* -    SPICELIB Version 2.0.0, 24-JAN-1991 (JEM) */
1906 
1907 /*        DAFOPW now accepts the ID word 'NAIF/NIP' as well 'NAIF/DAF'. */
1908 
1909 /* -    SPICELIB Version 1.0.1, 22-MAR-1990 (HAN) */
1910 
1911 /*        Literature references added to the header. */
1912 
1913 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
1914 
1915 /* -& */
1916 /* $ Index_Entries */
1917 
1918 /*     open daf for write */
1919 
1920 /* -& */
1921 /* $ Revisions */
1922 
1923 /* -    SPICELIB Version 6.0.0, 03-MAR-1999 (FST) */
1924 
1925 /*        See the Revisions section under DAFAH for a discussion */
1926 /*        of the impact of the changes made for this version. */
1927 
1928 /* -    SPICELIB Version 2.0.0, 03-SEP-1991 (NJB) (WLT) */
1929 
1930 /*        DAFOPW now allows multiple files to be open for writing. */
1931 
1932 /*        This routine was updated so that it now keeps current the set */
1933 /*        of DAF handles returned by DAFHOF. */
1934 
1935 /*        Some error messages were changed so that they specify */
1936 /*        names of relevant DAFs. */
1937 /* -& */
1938 
1939 /*     Standard SPICE error handling. */
1940 
1941     if (return_()) {
1942 	return 0;
1943     } else {
1944 	chkin_("DAFOPW", (ftnlen)6);
1945     }
1946 
1947 /*     Initialize the handle list, if necessary. */
1948 
1949     if (first) {
1950 	ssizei_(&c__5000, fhlist);
1951 	first = FALSE_;
1952     }
1953 
1954 /*     Check to see if there is room in the file table. */
1955 
1956     if (nft == 5000) {
1957 	setmsg_("The file table is full, with # entries. Could not open '#'.",
1958 		 (ftnlen)59);
1959 	errint_("#", &c__5000, (ftnlen)1);
1960 	errch_("#", fname, (ftnlen)1, fname_len);
1961 	sigerr_("SPICE(DAFFTFULL)", (ftnlen)16);
1962 	chkout_("DAFOPW", (ftnlen)6);
1963 	return 0;
1964     }
1965 
1966 /*     Attempt to open the file; perform any appropriate checks. */
1967 
1968     zzddhopn_(fname, "WRITE", "DAF", handle, fname_len, (ftnlen)5, (ftnlen)3);
1969 
1970 /*     Check FAILED(); return if an error has occurred. */
1971 
1972     if (failed_()) {
1973 	chkout_("DAFOPW", (ftnlen)6);
1974 	return 0;
1975     }
1976 
1977 /*     Retrieve ND and NI from the file record. */
1978 
1979     zzdafgfr_(handle, idword, &fnd, &fni, ifn, &fward, &bward, &free, &found,
1980 	    (ftnlen)8, (ftnlen)60);
1981     if (! found) {
1982 	zzddhcls_(handle, "DAF", &c_false, (ftnlen)3);
1983 	setmsg_("Error reading the file record from the binary DAF file '#'.",
1984 		 (ftnlen)59);
1985 	errch_("#", fname, (ftnlen)1, fname_len);
1986 	errint_("#", &iostat, (ftnlen)1);
1987 	sigerr_("SPICE(FILEREADFAILED)", (ftnlen)21);
1988 	chkout_("DAFOPW", (ftnlen)6);
1989 	return 0;
1990     }
1991 
1992 /*     At this point, we know that we have a valid DAF file, and we're */
1993 /*     set up to write to it or read from it, so ... */
1994 
1995 /*     Update the file table to include information about our */
1996 /*     newly opened DAF. */
1997 
1998     ++nft;
1999     fthan[(i__1 = nft - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("fthan", i__1,
2000 	    "dafah_", (ftnlen)1791)] = *handle;
2001     ftnd[(i__1 = nft - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("ftnd", i__1,
2002 	    "dafah_", (ftnlen)1792)] = fnd;
2003     ftni[(i__1 = nft - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("ftni", i__1,
2004 	    "dafah_", (ftnlen)1793)] = fni;
2005     ftlnk[(i__1 = nft - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("ftlnk", i__1,
2006 	    "dafah_", (ftnlen)1794)] = 1;
2007 
2008 /*     Insert the new handle into our handle set. */
2009 
2010     insrti_(handle, fhlist);
2011     chkout_("DAFOPW", (ftnlen)6);
2012     return 0;
2013 /* $Procedure DAFONW ( DAF, open new ) */
2014 
2015 L_dafonw:
2016 /* $ Abstract */
2017 
2018 /*     Open a new DAF for subsequent write requests. */
2019 
2020 /* $ Disclaimer */
2021 
2022 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
2023 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
2024 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
2025 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
2026 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
2027 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
2028 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
2029 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
2030 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
2031 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
2032 
2033 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
2034 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
2035 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
2036 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
2037 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
2038 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
2039 
2040 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
2041 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
2042 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
2043 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
2044 
2045 /* $ Required_Reading */
2046 
2047 /*     DAF */
2048 
2049 /* $ Keywords */
2050 
2051 /*     DAF */
2052 /*     FILES */
2053 
2054 /* $ Declarations */
2055 
2056 /*     CHARACTER*(*)         FNAME */
2057 /*     CHARACTER*(*)         FTYPE */
2058 /*     INTEGER               ND */
2059 /*     INTEGER               NI */
2060 /*     CHARACTER*(*)         IFNAME */
2061 /*     INTEGER               RESV */
2062 /*     INTEGER               HANDLE */
2063 
2064 /* $ Brief_I/O */
2065 
2066 /*     Variable  I/O  Description */
2067 /*     --------  ---  -------------------------------------------------- */
2068 /*     FNAME      I   Name of DAF to be opened. */
2069 /*     FTYPE      I   Mnemonic code for type of data in the DAF file. */
2070 /*     ND         I   Number of double precision components in summaries. */
2071 /*     NI         I   Number of integer components in summaries. */
2072 /*     IFNAME     I   Internal file name. */
2073 /*     RESV       I   Number of records to reserve. */
2074 /*     HANDLE     O   Handle assigned to DAF. */
2075 
2076 /* $ Detailed_Input */
2077 
2078 /*     FNAME       is the name of a new DAF to be created (and */
2079 /*                 consequently opened for write access). */
2080 
2081 /*     FTYPE       is a code for type of data placed into a DAF file. */
2082 /*                 The first nonblank character and the three (3) */
2083 /*                 characters immediately following it, giving four (4) */
2084 /*                 characters, are used to represent the type of the data */
2085 /*                 placed in the DAF file. This is provided as a */
2086 /*                 convenience for higher level software. It is an error */
2087 /*                 if this string is blank. When written to the DAF file, */
2088 /*                 the value for the type IS case sensitive; what you put */
2089 /*                 in is what you get out, so be careful. */
2090 
2091 /*                 NAIF has reserved for its own use file types */
2092 /*                 consisting of the upper case letters (A-Z) and the */
2093 /*                 digits 0-9. NAIF recommends lower case or mixed case */
2094 /*                 file types be used by all others in order to avoid */
2095 /*                 any conflicts with NAIF file types. */
2096 
2097 /*     ND          is the number of double precision components */
2098 /*                 in each array summary of the new file. */
2099 
2100 /*     NI          is the number of integer components in each */
2101 /*                 array summary in the new file. */
2102 
2103 /*     IFNAME      is the internal file name (containing as many as 60 */
2104 /*                 characters) for the new file. This should uniquely */
2105 /*                 identify the file. */
2106 
2107 /*     RESV        is the number of records in the new file to be */
2108 /*                 reserved; these records will not be used to store any */
2109 /*                 data belonging to DAF arrays subsequently written to */
2110 /*                 the file. The user may reserve records 2 through (2 + */
2111 /*                 RESV - 1) in the file. SPICE kernels based on the DAF */
2112 /*                 format use the reserved record area to store optional */
2113 /*                 textual information; for these kernels, the reserved */
2114 /*                 records contain the file's "comment area." */
2115 
2116 /*                 When RESV is non-zero, this routine writes an */
2117 /*                 end-of-comments character into the first byte of */
2118 /*                 record 2, and fills the rest of the allocated records */
2119 /*                 will null (ASCII code 0) characters. */
2120 
2121 /* $ Detailed_Output */
2122 
2123 /*     HANDLE      is the file handle associated with the file. This */
2124 /*                 handle is used to identify the file in subsequent */
2125 /*                 calls to other DAF routines. */
2126 
2127 /* $ Parameters */
2128 
2129 /*     INTEOC      is the ASCII decimal integer code of the character */
2130 /*                 recognized by SPICE as representing the end of the */
2131 /*                 comment data in the reserved record area. */
2132 
2133 /* $ Exceptions */
2134 
2135 /*     1) If the specified file cannot be opened without exceeding */
2136 /*        the maximum number of files, the error SPICE(DAFFTFULL) */
2137 /*        is signalled. */
2138 
2139 /*     2) If the input argument ND is out of the range [0, 124] */
2140 /*        or if NI is out of the range [2, 250], the error */
2141 /*        SPICE(DAFINVALIDPARAMS) is signalled. */
2142 
2143 /*     3) If */
2144 
2145 /*           ND + ( NI + 1 ) / 2   >  125 */
2146 
2147 /*        the error SPICE(DAFINVALIDPARAMS) is signalled. */
2148 
2149 /*     4) If the number of records to be reserved is not zero or */
2150 /*        positive, the error SPICE(DAFNORESV) is signalled. */
2151 
2152 /*     5) If an I/O error occurs in the process of creating the file, */
2153 /*        routines in the call tree of this routine signal an error. */
2154 
2155 /*     6) If (for some reason) the initial records in the file cannot */
2156 /*        be written, the error SPICE(DAFWRITEFAIL) is signalled. */
2157 
2158 /*     7) If no logical units are available, the error is */
2159 /*        signaled by routines called by this routine. */
2160 
2161 /*     8) If the file name is blank or otherwise inappropriate */
2162 /*        routines in the call tree of this routine signal an error. */
2163 
2164 /*     9) If the file type is blank, the error SPICE(BLANKFILETYPE) */
2165 /*        is signalled. */
2166 
2167 /*     10) If the file type contains nonprinting characters, decimal */
2168 /*         0-31 and 127-255, the error SPICE(ILLEGALCHARACTER) is */
2169 /*         signalled. */
2170 
2171 /* $ Files */
2172 
2173 /*     See argument FNAME. */
2174 
2175 /* $ Particulars */
2176 
2177 /*     This routine supersedes DAFOPN as the method for opening a new DAF */
2178 /*     file. It includes a data type identifier as part of the ID word of */
2179 /*     a DAF file it creates. */
2180 
2181 /*     The DAFs created by DAFONW have initialized file records but */
2182 /*     do not yet contain any arrays.  See the DAF Required Reading */
2183 /*     for a discussion of file records. */
2184 
2185 /* $ Examples */
2186 
2187 /*     In the following code fragment, DAFONW is used to open a file, */
2188 /*     to which a new array is then added. This file will have the data */
2189 /*     type 'TEST' which may be used to distinguish production data from */
2190 /*     test data at a user subroutine level. */
2191 
2192 /*        FNAME = 'test.bin' */
2193 /*        FTYPE = 'TEST' */
2194 
2195 /*        CALL DAFONW   ( FNAME, FTYPE,  ND,  NI,  IFNAME, 0, HANDLE ) */
2196 
2197 /*        CALL DAFBNA   ( HANDLE, SUM, NAME  ) */
2198 /*        CALL GET_DATA ( DATA,   N,   FOUND ) */
2199 
2200 /*        DO WHILE ( FOUND ) */
2201 /*           CALL DAFADA   ( DATA, N        ) */
2202 /*           CALL GET_DATA ( DATA, N, FOUND ) */
2203 /*        END DO */
2204 
2205 /*        CALL DAFENA */
2206 
2207 /* $ Restrictions */
2208 
2209 /*     1) Files opened using this routine must be closed with DAFCLS. */
2210 
2211 /* $ Literature_References */
2212 
2213 /*     None. */
2214 
2215 /* $ Author_and_Institution */
2216 
2217 /*     K.R. Gehringer  (JPL) */
2218 /*     N.J. Bachman    (JPL) */
2219 /*     J.M. Lynch      (JPL) */
2220 /*     H.A. Neilan     (JPL) */
2221 /*     W.L. Taber      (JPL) */
2222 /*     F.S. Turner     (JPL) */
2223 /*     I.M. Underwood  (JPL) */
2224 
2225 /* $ Version */
2226 
2227 /* -    SPICELIB Version 9.0.1, 10-OCT-2012 (EDW) */
2228 
2229 /*        Corrected ordering of header section. */
2230 
2231 /*        Removed the obsolete Reference citation to "NAIF */
2232 /*        Document 167.0." */
2233 
2234 /* -    SPICELIB Version 9.0.0, 09-NOV-2006 (NJB) */
2235 
2236 /*        DAFONW now writes a EOC character to the first byte */
2237 /*        of the second record when NRESV > 0. */
2238 
2239 /* -    SPICELIB Version 8.1.0, 02-APR-2002 (FST) */
2240 
2241 /*        This routine was updated to accomodate changes to the */
2242 /*        handle manager interface.  See DAFAH's Revision section */
2243 /*        for details. */
2244 
2245 /* -    SPICELIB Version 8.0.0, 13-NOV-2001 (FST) */
2246 
2247 /*        This routine was updated to utilize the new handle manager */
2248 /*        software to manage binary file formats and consolidated */
2249 /*        I/O code. */
2250 
2251 /* -    SPICELIB Version 7.0.4, 08-OCT-1999 (WLT) */
2252 
2253 /*        The environment lines were expanded so that the supported */
2254 /*        environments are now explicitely given.  New */
2255 /*        environments are WIN-NT */
2256 
2257 /* -    SPICELIB Version 7.0.3, 16-SEP-1999 (NJB) */
2258 
2259 /*        CSPICE environments were added.  Some typos were corrected. */
2260 
2261 /* -    SPICELIB Version 7.0.2, 28-JUL-1999 (WLT) */
2262 
2263 /*        The environment lines were expanded so that the supported */
2264 /*        environments are now explicitly given.  New */
2265 /*        environments are PC-DIGITAL, SGI-O32 and SGI-N32. */
2266 
2267 /* -    SPICELIB Version 7.0.1, 17-MAR-1999 (WLT) */
2268 
2269 /*        The environment lines were expanded so that the supported */
2270 /*        environments are now explicitly given.  Previously, */
2271 /*        environments such as SUN-SUNOS and SUN-SOLARIS were implied */
2272 /*        by the environment label SUN. */
2273 
2274 /* -    SPICELIB Version 2.0.0, 03-MAR-1999 (FST) */
2275 
2276 /*        The entry point was modified to insert the FTP validation */
2277 /*        string, as well as the binary file format into the file record. */
2278 
2279 /* -    SPICELIB Version 1.1.0, 08-MAR-1996 (KRG) */
2280 
2281 /*        The modifications support the notion of a DAF comment area, */
2282 /*        and involve writing NULL filled reserved records when the */
2283 /*        number of reserved records is greater than zero (0). */
2284 
2285 /*        Some nested IF...THEN...ELSE IF...THEN...END IF constructs */
2286 /*        were expanded to be independent IF...THEN...END IF tests. */
2287 /*        The tests were for IOSTAT errors on cascading write statements */
2288 /*        nested in the IF...ELSE IF... statements, and this was */
2289 /*        confusing. These tests were restructured so that IOSTAT is */
2290 /*        tested after each write statement which is equicalent to the */
2291 /*        original intent and easier to read. */
2292 
2293 /* -    SPICELIB Version 1.0.0, 29-SEP-1993 (KRG) */
2294 
2295 /*        This routine implements the notion of a file type for DAF */
2296 /*        files. It allows type information to be added to the file ID */
2297 /*        word. */
2298 
2299 /*        This routine is a modified version of DAFOPN. See the revision */
2300 /*        history of that entry point for details of changes before the */
2301 /*        creation of this entry point. */
2302 
2303 /* -& */
2304 /* $ Index_Entries */
2305 
2306 /*     open new daf with type */
2307 
2308 /* -& */
2309 /* $ Revisions */
2310 
2311 /* -    SPICELIB Version 2.0.0, 03-MAR-1999 (FST) */
2312 
2313 /*        See the Revisions section under DAFAH for a discussion */
2314 /*        of the impact of the changes made for this version. */
2315 
2316 /* -& */
2317 
2318 /*     Standard SPICE error handling. */
2319 
2320     if (return_()) {
2321 	return 0;
2322     } else {
2323 	chkin_("DAFONW", (ftnlen)6);
2324     }
2325 
2326 /*     Initialize the handle list, if necessary. */
2327 
2328     if (first) {
2329 	ssizei_(&c__5000, fhlist);
2330 	first = FALSE_;
2331     }
2332 
2333 /*     Check to see if there is room in the file table. */
2334 
2335     if (nft == 5000) {
2336 	setmsg_("The file table is full, with # entries. Could not open '#'.",
2337 		 (ftnlen)59);
2338 	errint_("#", &c__5000, (ftnlen)1);
2339 	errch_("#", fname, (ftnlen)1, fname_len);
2340 	sigerr_("SPICE(DAFFTFULL)", (ftnlen)16);
2341 	chkout_("DAFONW", (ftnlen)6);
2342 	return 0;
2343     }
2344 
2345 /*     Check if the file type is blank. */
2346 
2347     if (s_cmp(ftype, " ", ftype_len, (ftnlen)1) == 0) {
2348 	setmsg_("The file type is blank.", (ftnlen)23);
2349 	sigerr_("SPICE(BLANKFILETYPE)", (ftnlen)20);
2350 	chkout_("DAFONW", (ftnlen)6);
2351 	return 0;
2352     }
2353 
2354 /*     Check for nonprinting characters in the file type. */
2355 
2356     fnb = ltrim_(ftype, ftype_len);
2357     i__1 = rtrim_(ftype, ftype_len);
2358     for (i__ = fnb; i__ <= i__1; ++i__) {
2359 	if (*(unsigned char *)&ftype[i__ - 1] > 126 || *(unsigned char *)&
2360 		ftype[i__ - 1] < 32) {
2361 	    setmsg_("The file type contains nonprinting characters.", (ftnlen)
2362 		    46);
2363 	    sigerr_("SPICE(ILLEGALCHARACTER)", (ftnlen)23);
2364 	    chkout_("DAFONW", (ftnlen)6);
2365 	    return 0;
2366 	}
2367     }
2368 
2369 /*     Set the value the file type in a temporary variable to be sure of */
2370 /*     its length and then set the value of the ID word. Only 4 */
2371 /*     characters are allowed for the file type, and they are the first */
2372 /*     nonblank character and its three (3), or fewer, immediate */
2373 /*     successors in the input string FTYPE. */
2374 
2375     s_copy(ttype, ftype + (fnb - 1), (ftnlen)4, ftype_len - (fnb - 1));
2376 /* Writing concatenation */
2377     i__3[0] = 4, a__1[0] = "DAF/";
2378     i__3[1] = 4, a__1[1] = ttype;
2379     s_cat(idword, a__1, i__3, &c__2, (ftnlen)8);
2380 
2381 /*     Make sure ND and NI are in range. */
2382 
2383     if (*nd < 0 || *nd > 124) {
2384 	setmsg_("ND was #, should be in range [0,#].", (ftnlen)35);
2385 	errint_("#", nd, (ftnlen)1);
2386 	errint_("#", &c__124, (ftnlen)1);
2387 	sigerr_("SPICE(DAFINVALIDPARAMS)", (ftnlen)23);
2388 	chkout_("DAFONW", (ftnlen)6);
2389 	return 0;
2390     }
2391     if (*ni < 2 || *ni > 250) {
2392 	setmsg_("NI was #, should be in range [2,#].", (ftnlen)35);
2393 	errint_("#", ni, (ftnlen)1);
2394 	errint_("#", &c__250, (ftnlen)1);
2395 	sigerr_("SPICE(DAFINVALIDPARAMS)", (ftnlen)23);
2396 	chkout_("DAFONW", (ftnlen)6);
2397 	return 0;
2398     }
2399     if (*nd + (*ni + 1) / 2 > 125) {
2400 	setmsg_("Summary size was #, should not exceed #.", (ftnlen)40);
2401 	i__1 = *nd + (*ni + 1) / 2;
2402 	errint_("#", &i__1, (ftnlen)1);
2403 	errint_("#", &c__125, (ftnlen)1);
2404 	sigerr_("SPICE(DAFINVALIDPARAMS)", (ftnlen)23);
2405 	chkout_("DAFONW", (ftnlen)6);
2406 	return 0;
2407     }
2408 
2409 /*     The user must reserve some non-negative number of records. */
2410 
2411     if (*resv < 0) {
2412 	setmsg_("An attempt was made to reserve a negative number (#) of rec"
2413 		"ords.", (ftnlen)64);
2414 	errint_("#", resv, (ftnlen)1);
2415 	sigerr_("SPICE(DAFNORESV)", (ftnlen)16);
2416 	chkout_("DAFONW", (ftnlen)6);
2417 	return 0;
2418     }
2419 
2420 /*     Attempt to create the file; perform any appropriate checks. */
2421 
2422     zzddhopn_(fname, "NEW", "DAF", handle, fname_len, (ftnlen)3, (ftnlen)3);
2423 
2424 /*     Check FAILED(); return if an error has occurred. */
2425 
2426     if (failed_()) {
2427 	chkout_("DAFONW", (ftnlen)6);
2428 	return 0;
2429     }
2430     s_copy(ifn, ifname, (ftnlen)60, ifname_len);
2431     fnd = *nd;
2432     fni = *ni;
2433     fward = *resv + 2;
2434     bward = fward;
2435     s_copy(crec, " ", (ftnlen)1000, (ftnlen)1);
2436     cleard_(&c__128, drec);
2437     i__1 = fward + 2;
2438     dafrwa_(&i__1, &c__1, &free);
2439 
2440 /*     Fetch a logical unit for HANDLE. */
2441 
2442     zzddhhlu_(handle, "DAF", &c_false, &lun, (ftnlen)3);
2443 
2444 /*     Check FAILED(); return if an error has occurred. */
2445 
2446     if (failed_()) {
2447 	chkout_("DAFONW", (ftnlen)6);
2448 	return 0;
2449     }
2450 
2451 /*     Fetch the system file format. */
2452 
2453     zzplatfm_("FILE_FORMAT", format, (ftnlen)11, (ftnlen)8);
2454 
2455 /*     Write the new file record to the logical unit, LUN. */
2456 
2457     zzdafnfr_(&lun, idword, &fnd, &fni, ifn, &fward, &bward, &free, format, (
2458 	    ftnlen)8, (ftnlen)60, (ftnlen)8);
2459 
2460 /*     Check to see whether or not ZZDAFNFR generated an error writing */
2461 /*     the file record to the logical unit.  In the event an error */
2462 /*     occurs, checkout and return. */
2463 
2464     if (failed_()) {
2465 	chkout_("DAFONW", (ftnlen)6);
2466 	return 0;
2467     }
2468 
2469 /*     Write NULL filled reserved records. */
2470 
2471     if (*resv > 0) {
2472 	for (i__ = 1; i__ <= 1000; ++i__) {
2473 	    *(unsigned char *)&crec[i__ - 1] = '\0';
2474 	}
2475 	i__1 = *resv + 1;
2476 	for (i__ = 2; i__ <= i__1; ++i__) {
2477 
2478 /*            Place an end-of-comments marker in the first byte */
2479 /*            of the first record. */
2480 
2481 	    if (i__ == 2) {
2482 		*(unsigned char *)crec = '\4';
2483 	    } else {
2484 		*(unsigned char *)crec = '\0';
2485 	    }
2486 	    io___25.ciunit = lun;
2487 	    io___25.cirec = i__;
2488 	    iostat = s_wdue(&io___25);
2489 	    if (iostat != 0) {
2490 		goto L100001;
2491 	    }
2492 	    iostat = do_uio(&c__1, crec, (ftnlen)1000);
2493 	    if (iostat != 0) {
2494 		goto L100001;
2495 	    }
2496 	    iostat = e_wdue();
2497 L100001:
2498 	    if (iostat != 0) {
2499 		zzddhcls_(handle, "DAF", &c_true, (ftnlen)3);
2500 		setmsg_("Attempt to write file '#' failed. Value of IOSTAT w"
2501 			"as #.", (ftnlen)56);
2502 		errch_("#", fname, (ftnlen)1, fname_len);
2503 		errint_("#", &iostat, (ftnlen)1);
2504 		sigerr_("SPICE(DAFWRITEFAIL)", (ftnlen)19);
2505 		chkout_("DAFONW", (ftnlen)6);
2506 		return 0;
2507 	    }
2508 	}
2509     }
2510     io___26.ciunit = lun;
2511     io___26.cirec = fward;
2512     iostat = s_wdue(&io___26);
2513     if (iostat != 0) {
2514 	goto L100002;
2515     }
2516     iostat = do_uio(&c__128, (char *)&drec[0], (ftnlen)sizeof(doublereal));
2517     if (iostat != 0) {
2518 	goto L100002;
2519     }
2520     iostat = e_wdue();
2521 L100002:
2522     if (iostat != 0) {
2523 	zzddhcls_(handle, "DAF", &c_true, (ftnlen)3);
2524 	setmsg_("Attempt to write file '#' failed. Value of IOSTAT was #.", (
2525 		ftnlen)56);
2526 	errch_("#", fname, (ftnlen)1, fname_len);
2527 	errint_("#", &iostat, (ftnlen)1);
2528 	sigerr_("SPICE(DAFWRITEFAIL)", (ftnlen)19);
2529 	chkout_("DAFONW", (ftnlen)6);
2530 	return 0;
2531     }
2532     io___27.ciunit = lun;
2533     io___27.cirec = fward + 1;
2534     iostat = s_wdue(&io___27);
2535     if (iostat != 0) {
2536 	goto L100003;
2537     }
2538     iostat = do_uio(&c__1, crec, (ftnlen)1000);
2539     if (iostat != 0) {
2540 	goto L100003;
2541     }
2542     iostat = e_wdue();
2543 L100003:
2544     if (iostat != 0) {
2545 	zzddhcls_(handle, "DAF", &c_true, (ftnlen)3);
2546 	setmsg_("Attempt to write file '#' failed. Value of IOSTAT was #.", (
2547 		ftnlen)56);
2548 	errch_("#", fname, (ftnlen)1, fname_len);
2549 	errint_("#", &iostat, (ftnlen)1);
2550 	sigerr_("SPICE(DAFWRITEFAIL)", (ftnlen)19);
2551 	chkout_("DAFONW", (ftnlen)6);
2552 	return 0;
2553     }
2554 
2555 /*     Update the file table to include information about our newly */
2556 /*     opened DAF. */
2557 
2558     ++nft;
2559     fthan[(i__1 = nft - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("fthan", i__1,
2560 	    "dafah_", (ftnlen)2377)] = *handle;
2561     ftnd[(i__1 = nft - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("ftnd", i__1,
2562 	    "dafah_", (ftnlen)2378)] = fnd;
2563     ftni[(i__1 = nft - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("ftni", i__1,
2564 	    "dafah_", (ftnlen)2379)] = fni;
2565     ftlnk[(i__1 = nft - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("ftlnk", i__1,
2566 	    "dafah_", (ftnlen)2380)] = 1;
2567 
2568 /*     Insert the new handle into our handle set. */
2569 
2570     insrti_(handle, fhlist);
2571     chkout_("DAFONW", (ftnlen)6);
2572     return 0;
2573 /* $Procedure DAFOPN ( DAF, open new ) */
2574 
2575 L_dafopn:
2576 /* $ Abstract */
2577 
2578 /*     Deprecated. The routine DAFONW supersedes this routine. */
2579 /*     NAIF supports this routine only to provide backward */
2580 /*     compatibility. */
2581 
2582 /*     Open a new DAF for subsequent write requests. */
2583 
2584 /* $ Disclaimer */
2585 
2586 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
2587 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
2588 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
2589 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
2590 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
2591 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
2592 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
2593 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
2594 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
2595 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
2596 
2597 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
2598 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
2599 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
2600 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
2601 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
2602 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
2603 
2604 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
2605 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
2606 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
2607 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
2608 
2609 /* $ Required_Reading */
2610 
2611 /*     DAF */
2612 
2613 /* $ Keywords */
2614 
2615 /*     DAF */
2616 /*     FILES */
2617 
2618 /* $ Declarations */
2619 
2620 /*     CHARACTER*(*)         FNAME */
2621 /*     INTEGER               ND */
2622 /*     INTEGER               NI */
2623 /*     CHARACTER*(*)         IFNAME */
2624 /*     INTEGER               RESV */
2625 /*     INTEGER               HANDLE */
2626 
2627 /* $ Brief_I/O */
2628 
2629 /*     Variable  I/O  Description */
2630 /*     --------  ---  -------------------------------------------------- */
2631 /*     FNAME      I   Name of DAF to be opened. */
2632 /*     ND         I   Number of double precision components in summaries. */
2633 /*     NI         I   Number of integer components in summaries. */
2634 /*     IFNAME     I   Internal file name. */
2635 /*     RESV       I   Number of records to reserve. */
2636 /*     HANDLE     O   Handle assigned to DAF. */
2637 
2638 /* $ Detailed_Input */
2639 
2640 /*     FNAME       is the name of a new DAF to be created (and */
2641 /*                 consequently open for write access). */
2642 
2643 /*     ND          is the number of double precision components */
2644 /*                 in each array summary of the new file. */
2645 
2646 /*     NI          is the number of integer components in each */
2647 /*                 array summary in the new file. */
2648 
2649 /*     IFNAME      is the internal file name (containing as many as 60 */
2650 /*                 characters) for the new file. This should uniquely */
2651 /*                 identify the file. */
2652 
2653 /*     RESV        is the number of records in the new file to be */
2654 /*                 reserved for non-DAF use. The user may reserve */
2655 /*                 records 2 through (2 + RESV - 1) in the file. */
2656 /*                 These records are not used to store DAF data, */
2657 /*                 and are in fact invisible to all DAF routines. */
2658 
2659 /* $ Detailed_Output */
2660 
2661 /*     HANDLE      is the file handle associated with the file. This */
2662 /*                 handle is used to identify the file in subsequent */
2663 /*                 calls to other DAF routines. */
2664 
2665 /* $ Parameters */
2666 
2667 /*      None. */
2668 
2669 /* $ Exceptions */
2670 
2671 /*     1) If the specified file cannot be opened without exceeding */
2672 /*        the maximum number of files, the error SPICE(DAFFTFULL) */
2673 /*        is signalled. */
2674 
2675 /*     2) If the input argument ND is out of the range [0, 124] */
2676 /*        or if NI is out of the range [2, 250], the error */
2677 /*        SPICE(DAFINVALIDPARAMS) is signalled. */
2678 
2679 /*     3) If */
2680 
2681 /*           ND + ( NI + 1 ) / 2   >  125 */
2682 
2683 /*        the error SPICE(DAFINVALIDPARAMS) is signalled. */
2684 
2685 /*     4) If the number of records to be reserved is not zero or */
2686 /*        positive, the error SPICE(DAFNORESV) is signalled. */
2687 
2688 /*     5) If an I/O error occurs in the process of creating the file, */
2689 /*        routines in the call tree of this routine signal an error. */
2690 
2691 /*     6) If (for some reason) the initial records in the file cannot */
2692 /*        be written, the error SPICE(DAFWRITEFAIL) is signalled. */
2693 
2694 /*     7) If no logical units are available, the error is */
2695 /*        signaled by routines called by this routine. */
2696 
2697 /*     8) If the file name is blank, or otherwise inappropriate */
2698 /*        routines in the call tree of this routine signal an error. */
2699 
2700 /* $ Files */
2701 
2702 /*     See argument FNAME. */
2703 
2704 /* $ Particulars */
2705 
2706 /*     The DAFs created by DAFOPN have initialized file records but */
2707 /*     do not yet contain any arrays.  See the DAF Required Reading */
2708 /*     for a discussion of file records. */
2709 
2710 /*     This entry point has been made obsolete by the entry point DAFONW. */
2711 /*     It is supported for reasons of backward compatibility only. New */
2712 /*     software development should use the entry point DAFONW. */
2713 
2714 /* $ Examples */
2715 
2716 /*     In the following code fragment, DAFOPN is used to open a file, */
2717 /*     to which a new array is then added. */
2718 
2719 /*        CALL DAFOPN   ( FNAME,  ND,  NI,  IFNAME, 0, HANDLE ) */
2720 
2721 /*        CALL DAFBNA   ( HANDLE, SUM, NAME  ) */
2722 /*        CALL GET_DATA ( DATA,   N,   FOUND ) */
2723 
2724 /*        DO WHILE ( FOUND ) */
2725 /*           CALL DAFADA   ( DATA, N        ) */
2726 /*           CALL GET_DATA ( DATA, N, FOUND ) */
2727 /*        END DO */
2728 
2729 /*        CALL DAFENA */
2730 
2731 /* $ Restrictions */
2732 
2733 /*     1) Files opened using this routine must be closed with DAFCLS. */
2734 
2735 /* $ Literature_References */
2736 
2737 /*     None. */
2738 
2739 /* $ Author_and_Institution */
2740 
2741 /*     K.R. Gehringer  (JPL) */
2742 /*     N.J. Bachman    (JPL) */
2743 /*     J.M. Lynch      (JPL) */
2744 /*     H.A. Neilan     (JPL) */
2745 /*     W.L. Taber      (JPL) */
2746 /*     F.S. Turner     (JPL) */
2747 /*     I.M. Underwood  (JPL) */
2748 
2749 /* $ Version */
2750 
2751 /* -    SPICELIB Version 8.1.1, 10-OCT-2012 (EDW) */
2752 
2753 /*        Edited Abstract section to use "Deprecated" keyword */
2754 /*        and state replacement routine. */
2755 
2756 /*        Corrected ordering of header section. */
2757 
2758 /*        Removed the obsolete Reference citation to "NAIF */
2759 /*        Document 167.0." */
2760 
2761 /* -    SPICELIB Version 8.1.0, 02-APR-2002 (FST) */
2762 
2763 /*        This routine was updated to accomodate changes to the */
2764 /*        handle manager interface.  See DAFAH's Revision section */
2765 /*        for details. */
2766 
2767 /* -    SPICELIB Version 8.0.0, 13-NOV-2001 (FST) */
2768 
2769 /*        This routine was updated to utilize the new handle manager */
2770 /*        software to manage binary file formats and consolidated */
2771 /*        I/O code. */
2772 
2773 /* -    SPICELIB Version 7.0.4, 08-OCT-1999 (WLT) */
2774 
2775 /*        The environment lines were expanded so that the supported */
2776 /*        environments are now explicitely given.  New */
2777 /*        environments are WIN-NT */
2778 
2779 /* -    SPICELIB Version 7.0.3, 16-SEP-1999 (NJB) */
2780 
2781 /*        CSPICE environments were added.  Some typos were corrected. */
2782 
2783 /* -    SPICELIB Version 7.0.2, 28-JUL-1999 (WLT) */
2784 
2785 /*        The environment lines were expanded so that the supported */
2786 /*        environments are now explicitly given.  New */
2787 /*        environments are PC-DIGITAL, SGI-O32 and SGI-N32. */
2788 
2789 /* -    SPICELIB Version 7.0.1, 17-MAR-1999 (WLT) */
2790 
2791 /*        The environment lines were expanded so that the supported */
2792 /*        environments are now explicitly given.  Previously, */
2793 /*        environments such as SUN-SUNOS and SUN-SOLARIS were implied */
2794 /*        by the environment label SUN. */
2795 
2796 /* -    SPICELIB Version 4.0.0, 03-MAR-1999 (FST) */
2797 
2798 /*        The entry point was modified to insert the FTP validation */
2799 /*        string, as well as the binary file format into the file record. */
2800 
2801 /* -    SPICELIB Version 3.1.0, 08-MAR-1996 (KRG) */
2802 
2803 /*        The modifications support the notion of a DAF comment area, */
2804 /*        and involve writing NULL filled reserved records when the */
2805 /*        number of reserved records is greater than zero (0). */
2806 
2807 /*        Some nested IF...THEN...ELSE IF...THEN...END IF constructs */
2808 /*        were expanded to be independent IF...THEN...END IF tests. */
2809 /*        The tests were for IOSTAT errors on cascading write statements */
2810 /*        nested in the IF...ELSE IF... statements, and this was */
2811 /*        confusing. These tests were restructured so that IOSTAT is */
2812 /*        tested after each write statement which is equicalent to the */
2813 /*        original intent and easier to read. */
2814 
2815 /* -    SPICELIB Version 3.0.0, 29-SEP-1993 (KRG) */
2816 
2817 /*        Modified the logical structure of some */
2818 /*           IF ... THEN ... ELSE IF... END IF */
2819 /*        statements which were testing different items in each ELSE IF */
2820 /*        clause for failure into separate IF ... END IF statements. This */
2821 /*        improved the readability and supportability of the code. */
2822 
2823 /* -    SPICELIB Version 2.1.0, 25-FEB-1993 (JML) */
2824 
2825 /*        A new variable LUN is used for the logical unit number */
2826 /*        returned by GETLUN. */
2827 
2828 /*        The file name is checked to see if it is blank. */
2829 
2830 /*        The file name string that is passed to the FORTRAN OPEN and */
2831 /*        INQUIRE statements has been chopped at the last non-blank */
2832 /*        character. */
2833 
2834 /* -    SPICELIB Version 2.0.1, 10-MAR-1992 (WLT) */
2835 
2836 /*        Comment section for permuted index source lines was added */
2837 /*        following the header. */
2838 
2839 /* -    SPICELIB Version 2.0.0, 03-SEP-1991 (NJB) (HAN) (WLT) */
2840 
2841 /*        Updated to allow multiple DAFs to be open for write */
2842 /*        access simultaneously.  An error in a calling sequence */
2843 /*        shown in the Examples section was corrected. */
2844 
2845 /*        This routine was updated so that it now keeps current the set */
2846 /*        of DAF handles returned by DAFHOF. */
2847 
2848 /* -    SPICELIB Version 1.0.1, 22-MAR-1990 (HAN) */
2849 
2850 /*        Literature references added to the header. */
2851 
2852 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
2853 
2854 /* -& */
2855 /* $ Index_Entries */
2856 
2857 /*     open new daf */
2858 
2859 /* -& */
2860 /* $ Revisions */
2861 
2862 /* -    SPICELIB Version 4.0.0, 03-MAR-1999 (FST) */
2863 
2864 /*        See the Revisions section under DAFAH for a discussion */
2865 /*        of the impact of the changes made for this version. */
2866 
2867 /* -    SPICELIB Version 2.0.0, 03-SEP-1991 (NJB) (HAN) (WLT) */
2868 
2869 /*        Updated to allow multiple DAFs to be open for write */
2870 /*        access simultaneously. */
2871 
2872 /*        This routine was updated so that it now keeps current the set */
2873 /*        of DAF handles returned by DAFHOF. */
2874 
2875 /*        Invalid values of ND and NI are now screened; two new */
2876 /*        exceptions were added to the $Exceptions header section. */
2877 
2878 /*        The calling sequence of DAFADA shown in the first example */
2879 /*        in the Examples section was reversed; this was fixed. */
2880 
2881 /*        Some error messages were changed so that they specify */
2882 /*        names of relevant DAFs. */
2883 /* -& */
2884 
2885 /*     Standard SPICE error handling. */
2886 
2887     if (return_()) {
2888 	return 0;
2889     } else {
2890 	chkin_("DAFOPN", (ftnlen)6);
2891     }
2892 
2893 /*     Initialize the handle list, if necessary. */
2894 
2895     if (first) {
2896 	ssizei_(&c__5000, fhlist);
2897 	first = FALSE_;
2898     }
2899 
2900 /*     Check to see if there is room in the file table. */
2901 
2902     if (nft == 5000) {
2903 	setmsg_("The file table is full, with # entries. Could not open '#'.",
2904 		 (ftnlen)59);
2905 	errint_("#", &c__5000, (ftnlen)1);
2906 	errch_("#", fname, (ftnlen)1, fname_len);
2907 	sigerr_("SPICE(DAFFTFULL)", (ftnlen)16);
2908 	chkout_("DAFOPN", (ftnlen)6);
2909 	return 0;
2910     }
2911 
2912 /*     Make sure ND and NI are in range. */
2913 
2914     if (*nd < 0 || *nd > 124) {
2915 	setmsg_("ND was #, should be in range [0,#].", (ftnlen)35);
2916 	errint_("#", nd, (ftnlen)1);
2917 	errint_("#", &c__124, (ftnlen)1);
2918 	sigerr_("SPICE(DAFINVALIDPARAMS)", (ftnlen)23);
2919 	chkout_("DAFOPN", (ftnlen)6);
2920 	return 0;
2921     }
2922     if (*ni < 2 || *ni > 250) {
2923 	setmsg_("NI was #, should be in range [2,#].", (ftnlen)35);
2924 	errint_("#", ni, (ftnlen)1);
2925 	errint_("#", &c__250, (ftnlen)1);
2926 	sigerr_("SPICE(DAFINVALIDPARAMS)", (ftnlen)23);
2927 	chkout_("DAFOPN", (ftnlen)6);
2928 	return 0;
2929     }
2930     if (*nd + (*ni + 1) / 2 > 125) {
2931 	setmsg_("Summary size was #, should not exceed #.", (ftnlen)40);
2932 	i__1 = *nd + (*ni + 1) / 2;
2933 	errint_("#", &i__1, (ftnlen)1);
2934 	errint_("#", &c__125, (ftnlen)1);
2935 	sigerr_("SPICE(DAFINVALIDPARAMS)", (ftnlen)23);
2936 	chkout_("DAFOPN", (ftnlen)6);
2937 	return 0;
2938     }
2939 
2940 /*     The user must reserve some non-negative number of records. */
2941 
2942     if (*resv < 0) {
2943 	setmsg_("An attempt was made to reserve a negative number (#) of rec"
2944 		"ords.", (ftnlen)64);
2945 	errint_("#", resv, (ftnlen)1);
2946 	sigerr_("SPICE(DAFNORESV)", (ftnlen)16);
2947 	chkout_("DAFOPN", (ftnlen)6);
2948 	return 0;
2949     }
2950 
2951 /*     Attempt to create the file; perform any appropriate checks. */
2952 
2953     zzddhopn_(fname, "NEW", "DAF", handle, fname_len, (ftnlen)3, (ftnlen)3);
2954 
2955 /*     Check FAILED(); return if an error has occurred. */
2956 
2957     if (failed_()) {
2958 	chkout_("DAFOPN", (ftnlen)6);
2959 	return 0;
2960     }
2961     s_copy(ifn, ifname, (ftnlen)60, ifname_len);
2962     fnd = *nd;
2963     fni = *ni;
2964     fward = *resv + 2;
2965     bward = fward;
2966     s_copy(crec, " ", (ftnlen)1000, (ftnlen)1);
2967     cleard_(&c__128, drec);
2968     i__1 = fward + 2;
2969     dafrwa_(&i__1, &c__1, &free);
2970 
2971 /*     Fetch a logical unit for HANDLE. */
2972 
2973     zzddhhlu_(handle, "DAF", &c_false, &lun, (ftnlen)3);
2974 
2975 /*     Check FAILED(); return if an error has occurred. */
2976 
2977     if (failed_()) {
2978 	chkout_("DAFOPN", (ftnlen)6);
2979 	return 0;
2980     }
2981 
2982 /*     Fetch the system file format. */
2983 
2984     zzplatfm_("FILE_FORMAT", format, (ftnlen)11, (ftnlen)8);
2985 
2986 /*     Write the new file record to the logical unit, LUN. */
2987 
2988     zzdafnfr_(&lun, "NAIF/DAF", &fnd, &fni, ifn, &fward, &bward, &free,
2989 	    format, (ftnlen)8, (ftnlen)60, (ftnlen)8);
2990 
2991 /*     Check to see whether or not ZZDAFNFR generated an error writing */
2992 /*     the file record to the logical unit.  In the event an error */
2993 /*     occurs, checkout and return. */
2994 
2995     if (failed_()) {
2996 	chkout_("DAFOPN", (ftnlen)6);
2997 	return 0;
2998     }
2999 
3000 /*     Write NULL filled reserved records. */
3001 
3002     if (*resv > 0) {
3003 	for (i__ = 1; i__ <= 1000; ++i__) {
3004 	    *(unsigned char *)&crec[i__ - 1] = '\0';
3005 	}
3006 	i__1 = *resv + 1;
3007 	for (i__ = 2; i__ <= i__1; ++i__) {
3008 	    io___28.ciunit = lun;
3009 	    io___28.cirec = i__;
3010 	    iostat = s_wdue(&io___28);
3011 	    if (iostat != 0) {
3012 		goto L100004;
3013 	    }
3014 	    iostat = do_uio(&c__1, crec, (ftnlen)1000);
3015 	    if (iostat != 0) {
3016 		goto L100004;
3017 	    }
3018 	    iostat = e_wdue();
3019 L100004:
3020 	    if (iostat != 0) {
3021 		zzddhcls_(handle, "DAF", &c_true, (ftnlen)3);
3022 		setmsg_("Attempt to write file '#' failed. Value of IOSTAT w"
3023 			"as #.", (ftnlen)56);
3024 		errch_("#", fname, (ftnlen)1, fname_len);
3025 		errint_("#", &iostat, (ftnlen)1);
3026 		sigerr_("SPICE(DAFWRITEFAIL)", (ftnlen)19);
3027 		chkout_("DAFOPN", (ftnlen)6);
3028 		return 0;
3029 	    }
3030 	}
3031     }
3032     io___29.ciunit = lun;
3033     io___29.cirec = fward;
3034     iostat = s_wdue(&io___29);
3035     if (iostat != 0) {
3036 	goto L100005;
3037     }
3038     iostat = do_uio(&c__128, (char *)&drec[0], (ftnlen)sizeof(doublereal));
3039     if (iostat != 0) {
3040 	goto L100005;
3041     }
3042     iostat = e_wdue();
3043 L100005:
3044     if (iostat != 0) {
3045 	zzddhcls_(handle, "DAF", &c_true, (ftnlen)3);
3046 	setmsg_("Attempt to write file '#' failed. Value of IOSTAT was #.", (
3047 		ftnlen)56);
3048 	errch_("#", fname, (ftnlen)1, fname_len);
3049 	errint_("#", &iostat, (ftnlen)1);
3050 	sigerr_("SPICE(DAFWRITEFAIL)", (ftnlen)19);
3051 	chkout_("DAFOPN", (ftnlen)6);
3052 	return 0;
3053     }
3054     io___30.ciunit = lun;
3055     io___30.cirec = fward + 1;
3056     iostat = s_wdue(&io___30);
3057     if (iostat != 0) {
3058 	goto L100006;
3059     }
3060     iostat = do_uio(&c__1, crec, (ftnlen)1000);
3061     if (iostat != 0) {
3062 	goto L100006;
3063     }
3064     iostat = e_wdue();
3065 L100006:
3066     if (iostat != 0) {
3067 	zzddhcls_(handle, "DAF", &c_true, (ftnlen)3);
3068 	setmsg_("Attempt to write file '#' failed. Value of IOSTAT was #.", (
3069 		ftnlen)56);
3070 	errch_("#", fname, (ftnlen)1, fname_len);
3071 	errint_("#", &iostat, (ftnlen)1);
3072 	sigerr_("SPICE(DAFWRITEFAIL)", (ftnlen)19);
3073 	chkout_("DAFOPN", (ftnlen)6);
3074 	return 0;
3075     }
3076 
3077 /*     Update the file table to include information about */
3078 /*     our newly opened DAF. */
3079 
3080     ++nft;
3081     fthan[(i__1 = nft - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("fthan", i__1,
3082 	    "dafah_", (ftnlen)2921)] = *handle;
3083     ftnd[(i__1 = nft - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("ftnd", i__1,
3084 	    "dafah_", (ftnlen)2922)] = fnd;
3085     ftni[(i__1 = nft - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("ftni", i__1,
3086 	    "dafah_", (ftnlen)2923)] = fni;
3087     ftlnk[(i__1 = nft - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("ftlnk", i__1,
3088 	    "dafah_", (ftnlen)2924)] = 1;
3089 
3090 /*     Insert the new handle into our handle set. */
3091 
3092     insrti_(handle, fhlist);
3093     chkout_("DAFOPN", (ftnlen)6);
3094     return 0;
3095 /* $Procedure DAFCLS ( DAF, close ) */
3096 
3097 L_dafcls:
3098 /* $ Abstract */
3099 
3100 /*     Close the DAF associated with a given handle. */
3101 
3102 /* $ Disclaimer */
3103 
3104 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
3105 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
3106 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
3107 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
3108 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
3109 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
3110 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
3111 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
3112 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
3113 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
3114 
3115 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
3116 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
3117 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
3118 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
3119 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
3120 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
3121 
3122 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
3123 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
3124 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
3125 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
3126 
3127 /* $ Required_Reading */
3128 
3129 /*     DAF */
3130 
3131 /* $ Keywords */
3132 
3133 /*     DAF */
3134 /*     FILES */
3135 
3136 /* $ Declarations */
3137 
3138 /*     INTEGER               HANDLE */
3139 
3140 /* $ Brief_I/O */
3141 
3142 /*     Variable  I/O  Description */
3143 /*     --------  ---  -------------------------------------------------- */
3144 /*     HANDLE     I   Handle of DAF to be closed. */
3145 
3146 /* $ Detailed_Input */
3147 
3148 /*     HANDLE      is the file handle of a previously opened DAF file. */
3149 
3150 /* $ Detailed_Output */
3151 
3152 /*     None. */
3153 
3154 /* $ Parameters */
3155 
3156 /*      None. */
3157 
3158 /* $ Exceptions */
3159 
3160 /*     1) If the specified handle does not belong to a DAF */
3161 /*        that is currently open, nothing happens. */
3162 
3163 /*     2) If this routine is used to close an HANDLE not associated */
3164 /*        with a DAF, routines called by this routine signal an error. */
3165 
3166 /* $ Files */
3167 
3168 /*     None. */
3169 
3170 /* $ Particulars */
3171 
3172 /*     Because DAFAH and its entry points must keep track of what */
3173 /*     files are open at any given time, it is important that DAF */
3174 /*     files be closed only with DAFCLS, to prevent the remaining */
3175 /*     DAF routines from failing, sometimes mysteriously. */
3176 
3177 /*     Note that when a file is opened more than once for read access, */
3178 /*     DAFOPR returns the same handle each time it is re-opened. */
3179 /*     Each time the file is closed, DAFCLS checks to see if any other */
3180 /*     claims on the file are still active before physically closing */
3181 /*     the file. */
3182 
3183 /* $ Examples */
3184 
3185 /*     Example(1): */
3186 
3187 /*     In the following code fragment, the arrays in a file are */
3188 /*     examined in order to determine whether the file contains */
3189 /*     any arrays whose names begin with the word TEST. */
3190 /*     The complete names for these arrays are printed to */
3191 /*     the screen. The file is closed at the end of the search. */
3192 
3193 /*        CALL DAFOPR ( FNAME, HANDLE ) */
3194 /*        CALL DAFBFS ( HANDLE ) */
3195 /*        CALL DAFFNA ( FOUND  ) */
3196 
3197 /*        DO WHILE ( FOUND ) */
3198 /*           CALL DAFGN ( NAME ) */
3199 
3200 /*           IF ( NAME(1:5) .EQ. 'TEST ' ) THEN */
3201 /*              WRITE (*,*) NAME */
3202 /*           END IF */
3203 
3204 /*           CALL DAFFNA ( FOUND ) */
3205 /*        END DO */
3206 
3207 /*        CALL DAFCLS ( HANDLE ) */
3208 
3209 /*     Note that if the file has been opened already by a DAF routine */
3210 /*     at some other place in the calling program, it remains open. */
3211 /*     This makes it possible to examine files that have been opened for */
3212 /*     use by other modules without interfering with the operation of */
3213 /*     those routines. */
3214 
3215 
3216 /*     Example (2): */
3217 
3218 /*     Use a simple routine to output the double precision and integer */
3219 /*     values stored in an SPK's segments descriptors. This function */
3220 /*     opens a DAF for read, performs a forwards search for the DAF */
3221 /*     arrays, prints segments description for each array found, then */
3222 /*     closes the DAF. */
3223 
3224 /*           PROGRAM DAF_T */
3225 
3226 /*           INTEGER             HANDLE */
3227 
3228 /*     C */
3229 /*     C     Define the summary parameters appropriate */
3230 /*     C     for an SPK file. */
3231 /*     C */
3232 /*           INTEGER             ND */
3233 /*           PARAMETER         ( ND = 2 ) */
3234 
3235 /*           INTEGER             NI */
3236 /*           PARAMETER         ( NI = 6 ) */
3237 
3238 /*           INTEGER             IC( NI ) */
3239 
3240 /*           DOUBLE PRECISION    DC( ND ) */
3241 
3242 /*           CHARACTER*(32)      KERNEL */
3243 
3244 /*           LOGICAL             FOUND */
3245 
3246 
3247 /*     C */
3248 /*     C     Open a DAF for read. Return a HANDLE referring to the file. */
3249 /*     C */
3250 /*           KERNEL = 'de421.bsp' */
3251 /*           CALL DAFOPR ( KERNEL, HANDLE ) */
3252 
3253 /*     C */
3254 /*     C     Begin a forward search on the file. */
3255 /*     C */
3256 /*           CALL DAFBFS ( HANDLE ) */
3257 
3258 /*     C */
3259 /*     C     Search until a DAF array is found. */
3260 /*     C */
3261 /*           CALL DAFFNA ( FOUND ) */
3262 
3263 /*     C */
3264 /*     C     Loop while the search finds subsequent DAF arrays. */
3265 /*     C */
3266 /*           DO WHILE ( FOUND ) */
3267 
3268 /*              CALL DAFGS ( SUM ) */
3269 /*              CALL DAFUS ( SUM, ND, NI, DC, IC ) */
3270 
3271 /*              WRITE(*,*)                'Doubles: ', DC(1:ND) */
3272 /*              WRITE(*, FMT='(A,6I9)' ) 'Integers: ', IC(1:NI) */
3273 
3274 /*     C */
3275 /*     C        Check for another segment. */
3276 /*     C */
3277 /*              CALL DAFFNA ( FOUND ) */
3278 
3279 /*           END DO */
3280 
3281 /*     C */
3282 /*     C     Safely close the DAF. */
3283 /*     C */
3284 /*           CALL DAFCLS ( HANDLE ) */
3285 
3286 /*           END */
3287 
3288 /*     The program outputs: */
3289 
3290 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
3291 /*     Integers:         1        0        1        2      641   310404 */
3292 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
3293 /*     Integers:         2        0        1        2   310405   423048 */
3294 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
3295 /*     Integers:         3        0        1        2   423049   567372 */
3296 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
3297 /*     Integers:         4        0        1        2   567373   628976 */
3298 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
3299 /*     Integers:         5        0        1        2   628977   674740 */
3300 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
3301 /*     Integers:         6        0        1        2   674741   715224 */
3302 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
3303 /*     Integers:         7        0        1        2   715225   750428 */
3304 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
3305 /*     Integers:         8        0        1        2   750429   785632 */
3306 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
3307 /*     Integers:         9        0        1        2   785633   820836 */
3308 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
3309 /*     Integers:        10        0        1        2   820837   944040 */
3310 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
3311 /*     Integers:       301        3        1        2   944041  1521324 */
3312 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
3313 /*     Integers:       399        3        1        2  1521325  2098608 */
3314 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
3315 /*     Integers:       199        1        1        2  2098609  2098620 */
3316 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
3317 /*     Integers:       299        2        1        2  2098621  2098632 */
3318 /*      Doubles:   -3169195200.0000000        1696852800.0000000 */
3319 /*     Integers:       499        4        1        2  2098633  2098644 */
3320 
3321 /*      Note, the final entries in the integer array contains the segment */
3322 /*      start/end indexes. The output indicates the search proceeded */
3323 /*      from the start of the file (low value index) towards the end */
3324 /*      (high value index). */
3325 
3326 /* $ Restrictions */
3327 
3328 /*     None. */
3329 
3330 /* $ Literature_References */
3331 
3332 /*     None. */
3333 
3334 /* $ Author_and_Institution */
3335 
3336 /*     N.J. Bachman    (JPL) */
3337 /*     K.R. Gehringer  (JPL) */
3338 /*     W.L. Taber      (JPL) */
3339 /*     F.S. Turner     (JPL) */
3340 /*     I.M. Underwood  (JPL) */
3341 
3342 /* $ Version */
3343 
3344 /* -    SPICELIB Version 8.1.1, 10-OCT-2012 (EDW) */
3345 
3346 /*        Added a functional code example to the Examples section. */
3347 
3348 /*        Removed the unneeded Revisions section. */
3349 
3350 /*        Removed the obsolete Reference citation to "NAIF */
3351 /*        Document 167.0." */
3352 
3353 /*        Corrected ordering of header section. */
3354 
3355 /* -    SPICELIB Version 8.1.0, 02-APR-2002 (FST) */
3356 
3357 /*        This routine was updated to accomodate changes to the */
3358 /*        handle manager interface.  See DAFAH's Revision section */
3359 /*        for details. */
3360 
3361 /* -    SPICELIB Version 8.0.0, 13-NOV-2001 (FST) */
3362 
3363 /*        This routine was updated to utilize the new handle manager */
3364 /*        software to manage binary file formats and consolidated */
3365 /*        I/O code. */
3366 
3367 /* -    SPICELIB Version 7.0.4, 08-OCT-1999 (WLT) */
3368 
3369 /*        The environment lines were expanded so that the supported */
3370 /*        environments are now explicitely given.  New */
3371 /*        environments are WIN-NT */
3372 
3373 /* -    SPICELIB Version 7.0.3, 16-SEP-1999 (NJB) */
3374 
3375 /*        CSPICE environments were added.  Some typos were corrected. */
3376 
3377 /* -    SPICELIB Version 7.0.2, 28-JUL-1999 (WLT) */
3378 
3379 /*        The environment lines were expanded so that the supported */
3380 /*        environments are now explicitly given.  New */
3381 /*        environments are PC-DIGITAL, SGI-O32 and SGI-N32. */
3382 
3383 /* -    SPICELIB Version 7.0.1, 17-MAR-1999 (WLT) */
3384 
3385 /*        The environment lines were expanded so that the supported */
3386 /*        environments are now explicitly given.  Previously, */
3387 /*        environments such as SUN-SUNOS and SUN-SOLARIS were implied */
3388 /*        by the environment label SUN. */
3389 
3390 /* -    SPICELIB Version 2.0.3, 29-SEP-1993 (KRG) */
3391 
3392 /*        Removed references to specific DAF file open routines in the */
3393 /*        $ Detailed_Input section of the header. This was done in order */
3394 /*        to minimize documentation changes if these open routines ever */
3395 /*        change. */
3396 
3397 /* -    SPICELIB Version 2.0.2, 25-FEB-1993 (JML) */
3398 
3399 /*        A minor error in the particulars section of the header was */
3400 /*        corrected.  It formerly stated that a file could be open more */
3401 /*        than once for read or write access instead of just read access. */
3402 
3403 /* -    SPICELIB Version 2.0.1, 10-MAR-1992 (WLT) */
3404 
3405 /*        Comment section for permuted index source lines was added */
3406 /*        following the header. */
3407 
3408 /* -    SPICELIB Version 2.0.0, 03-SEP-1991 (NJB) (WLT) */
3409 
3410 /*        This routine was updated so that it now keeps current the set */
3411 /*        of DAF handles returned by DAFHOF. */
3412 
3413 /*        Upgraded to support file handle checking routines */
3414 /*        DAFHOF and DAFSIH.  DAFCLS now initializes the file */
3415 /*        handle list if necessary, and removes from the list */
3416 /*        the handles of files it closes. */
3417 
3418 /* -    SPICELIB Version 1.0.1, 22-MAR-1990 (HAN) */
3419 
3420 /*        Literature references added to the header. */
3421 
3422 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
3423 
3424 /* -& */
3425 /* $ Index_Entries */
3426 
3427 /*     close daf */
3428 
3429 /* -& */
3430 
3431 /*     Standard SPICE error handling. */
3432 
3433     if (return_()) {
3434 	return 0;
3435     } else {
3436 	chkin_("DAFCLS", (ftnlen)6);
3437     }
3438 
3439 /*     Initialize the handle list, if necessary. */
3440 
3441     if (first) {
3442 	ssizei_(&c__5000, fhlist);
3443 	first = FALSE_;
3444     }
3445 
3446 /*     Is this file even open? If so, decrement the number of links */
3447 /*     to the file. If the number of links drops to zero, physically */
3448 /*     close the file and remove it from the file buffer. */
3449 
3450 /*     If the file is not open: no harm, no foul. */
3451 
3452     findex = isrchi_(handle, &nft, fthan);
3453     if (findex > 0) {
3454 	ftlnk[(i__1 = findex - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge("ftlnk",
3455 		 i__1, "dafah_", (ftnlen)3305)] = ftlnk[(i__2 = findex - 1) <
3456 		5000 && 0 <= i__2 ? i__2 : s_rnge("ftlnk", i__2, "dafah_", (
3457 		ftnlen)3305)] - 1;
3458 	if (ftlnk[(i__1 = findex - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge(
3459 		"ftlnk", i__1, "dafah_", (ftnlen)3307)] == 0) {
3460 	    zzddhcls_(handle, "DAF", &c_false, (ftnlen)3);
3461 	    i__1 = nft - 1;
3462 	    for (i__ = findex; i__ <= i__1; ++i__) {
3463 		fthan[(i__2 = i__ - 1) < 5000 && 0 <= i__2 ? i__2 : s_rnge(
3464 			"fthan", i__2, "dafah_", (ftnlen)3312)] = fthan[(i__4
3465 			= i__) < 5000 && 0 <= i__4 ? i__4 : s_rnge("fthan",
3466 			i__4, "dafah_", (ftnlen)3312)];
3467 		ftlnk[(i__2 = i__ - 1) < 5000 && 0 <= i__2 ? i__2 : s_rnge(
3468 			"ftlnk", i__2, "dafah_", (ftnlen)3313)] = ftlnk[(i__4
3469 			= i__) < 5000 && 0 <= i__4 ? i__4 : s_rnge("ftlnk",
3470 			i__4, "dafah_", (ftnlen)3313)];
3471 		ftnd[(i__2 = i__ - 1) < 5000 && 0 <= i__2 ? i__2 : s_rnge(
3472 			"ftnd", i__2, "dafah_", (ftnlen)3314)] = ftnd[(i__4 =
3473 			i__) < 5000 && 0 <= i__4 ? i__4 : s_rnge("ftnd", i__4,
3474 			 "dafah_", (ftnlen)3314)];
3475 		ftni[(i__2 = i__ - 1) < 5000 && 0 <= i__2 ? i__2 : s_rnge(
3476 			"ftni", i__2, "dafah_", (ftnlen)3315)] = ftni[(i__4 =
3477 			i__) < 5000 && 0 <= i__4 ? i__4 : s_rnge("ftni", i__4,
3478 			 "dafah_", (ftnlen)3315)];
3479 	    }
3480 	    --nft;
3481 
3482 /*           Delete the handle from our handle set. */
3483 
3484 	    removi_(handle, fhlist);
3485 	}
3486     }
3487     chkout_("DAFCLS", (ftnlen)6);
3488     return 0;
3489 /* $Procedure DAFHSF ( DAF, handle to summary format ) */
3490 
3491 L_dafhsf:
3492 /* $ Abstract */
3493 
3494 /*     Return the summary format associated with a handle. */
3495 
3496 /* $ Disclaimer */
3497 
3498 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
3499 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
3500 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
3501 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
3502 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
3503 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
3504 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
3505 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
3506 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
3507 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
3508 
3509 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
3510 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
3511 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
3512 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
3513 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
3514 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
3515 
3516 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
3517 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
3518 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
3519 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
3520 
3521 /* $ Required_Reading */
3522 
3523 /*     DAF */
3524 
3525 /* $ Keywords */
3526 
3527 /*     CONVERSION */
3528 /*     DAF */
3529 /*     FILES */
3530 
3531 /* $ Declarations */
3532 
3533 /*     INTEGER               HANDLE */
3534 /*     INTEGER               ND */
3535 /*     INTEGER               NI */
3536 
3537 /* $ Brief_I/O */
3538 
3539 /*     Variable  I/O  Description */
3540 /*     --------  ---  -------------------------------------------------- */
3541 /*     HANDLE     I   Handle of a DAF file. */
3542 /*     ND         O   Number of double precision components in summaries. */
3543 /*     NI         O   Number of integer components in summaries. */
3544 
3545 /* $ Detailed_Input */
3546 
3547 /*     HANDLE      is the handle associated with a previously opened */
3548 /*                 DAF file. */
3549 
3550 /* $ Detailed_Output */
3551 
3552 /*     ND, */
3553 /*     NI          are the numbers of double precision and integer */
3554 /*                 components, respectively, in each array summary */
3555 /*                 in the specified file. */
3556 
3557 /* $ Parameters */
3558 
3559 /*      None. */
3560 
3561 /* $ Exceptions */
3562 
3563 /*     1) If the specified handle does not belong to any file that is */
3564 /*        currently known to be open, the error SPICE(DAFNOSUCHHANDLE) */
3565 /*        is signalled. */
3566 
3567 /* $ Files */
3568 
3569 /*     None. */
3570 
3571 /* $ Particulars */
3572 
3573 /*     The summary format must be known in order to pack or unpack */
3574 /*     an array summary.  See the DAF Required Reading for a discussion */
3575 /*     of summary formats. */
3576 
3577 /* $ Examples */
3578 
3579 /*     1)  Find the number of d.p. `words' in a DAF having an */
3580 /*         arbitrary summary format. */
3581 
3582 
3583 /*                  PROGRAM NWORDS */
3584 /*            C */
3585 /*            C     Count the number of d.p. words of data in a */
3586 /*            C     DAF.  Exclude array summaries, reserved records, */
3587 /*            C     the file record, and character records. */
3588 /*            C */
3589 /*                  INTEGER               FILEN */
3590 /*                  PARAMETER           ( FILEN  = 128 ) */
3591 
3592 /*                  INTEGER               MAXND */
3593 /*                  PARAMETER           ( MAXND  = 124 ) */
3594 
3595 /*                  INTEGER               MAXNI */
3596 /*                  PARAMETER           ( MAXNI  = 250 ) */
3597 
3598 /*                  INTEGER               MAXSUM */
3599 /*                  PARAMETER           ( MAXSUM = 125 ) */
3600 
3601 /*                  CHARACTER*(FILEN)     DAF */
3602 
3603 /*                  DOUBLE PRECISION      DC    ( MAXND  ) */
3604 /*                  DOUBLE PRECISION      SUM   ( MAXSUM ) */
3605 
3606 /*                  INTEGER               FA */
3607 /*                  INTEGER               HANDLE */
3608 /*                  INTEGER               IA */
3609 /*                  INTEGER               IC    ( MAXNI ) */
3610 /*                  INTEGER               N */
3611 /*                  INTEGER               ND */
3612 /*                  INTEGER               NI */
3613 
3614 /*                  LOGICAL               FOUND */
3615 
3616 /*                  DATA                  N   /  0  / */
3617 
3618 /*                  WRITE (*,*)          'Enter file name' */
3619 /*                  READ  (*,FMT='(A)')   DAF */
3620 
3621 /*            C */
3622 /*            C     Open the DAF and find the summary format. */
3623 /*            C */
3624 /*                  CALL DAFOPR ( DAF,    HANDLE ) */
3625 /*                  CALL DAFHSF ( HANDLE, ND, NI ) */
3626 
3627 /*            C */
3628 /*            C     Start a forward search and examine each array in */
3629 /*            C     turn. */
3630 /*            C */
3631 /*                  CALL DAFBFS ( HANDLE ) */
3632 /*                  CALL DAFFNA ( FOUND  ) */
3633 
3634 /*                  DO WHILE ( FOUND ) */
3635 /*            C */
3636 /*            C        Obtain the array summary, unpack it, and get */
3637 /*            C        the initial and final array addresses from */
3638 /*            C        the integer descriptor component. */
3639 /*            C */
3640 /*                     CALL DAFGS ( SUM ) */
3641 /*                     CALL DAFUS ( SUM, ND, NI, DC, IC ) */
3642 
3643 /*                     IA  =  IC ( NI - 1 ) */
3644 /*                     FA  =  IC ( NI     ) */
3645 
3646 /*                     N   =  FA - IA + 1 + N */
3647 
3648 /*                     CALL DAFFNA ( FOUND ) */
3649 
3650 /*                  END DO */
3651 
3652 /*                  WRITE (*,*) 'Number of d.p. words is ', N */
3653 
3654 /*                  END */
3655 
3656 /* $ Restrictions */
3657 
3658 /*     None. */
3659 
3660 /* $ Literature_References */
3661 
3662 /*     NONE. */
3663 
3664 /* $ Author_and_Institution */
3665 
3666 /*     N.J. Bachman    (JPL) */
3667 /*     K.R. Gehringer  (JPL) */
3668 /*     W.L. Taber      (JPL) */
3669 /*     F.S. Turner     (JPL) */
3670 /*     I.M. Underwood  (JPL) */
3671 
3672 /* $ Version */
3673 
3674 /* -    SPICELIB Version 8.0.1, 10-OCT-2012 (EDW) */
3675 
3676 /*        Corrected ordering of header section. */
3677 
3678 /*        Removed the obsolete Reference citation to "NAIF */
3679 /*        Document 167.0." */
3680 
3681 /* -    SPICELIB Version 8.0.0, 13-NOV-2001 (FST) */
3682 
3683 /*        This routine was updated to utilize the new handle manager */
3684 /*        software to manage binary file formats and consolidated */
3685 /*        I/O code. */
3686 
3687 /* -    SPICELIB Version 7.0.4, 08-OCT-1999 (WLT) */
3688 
3689 /*        The environment lines were expanded so that the supported */
3690 /*        environments are now explicitely given.  New */
3691 /*        environments are WIN-NT */
3692 
3693 /* -    SPICELIB Version 7.0.3, 16-SEP-1999 (NJB) */
3694 
3695 /*        CSPICE environments were added.  Some typos were corrected. */
3696 
3697 /* -    SPICELIB Version 7.0.2, 28-JUL-1999 (WLT) */
3698 
3699 /*        The environment lines were expanded so that the supported */
3700 /*        environments are now explicitly given.  New */
3701 /*        environments are PC-DIGITAL, SGI-O32 and SGI-N32. */
3702 
3703 /* -    SPICELIB Version 7.0.1, 17-MAR-1999 (WLT) */
3704 
3705 /*        The environment lines were expanded so that the supported */
3706 /*        environments are now explicitly given.  Previously, */
3707 /*        environments such as SUN-SUNOS and SUN-SOLARIS were implied */
3708 /*        by the environment label SUN. */
3709 
3710 /* -    SPICELIB Version 1.0.4, 29-SEP-1993 (KRG) */
3711 
3712 /*        Removed references to specific DAF file open routines in the */
3713 /*        $ Detailed_Input section of the header. This was done in order */
3714 /*        to minimize documentation changes if these open routines ever */
3715 /*        change. */
3716 
3717 /* -    SPICELIB Version 1.0.3, 10-MAR-1992 (WLT) */
3718 
3719 /*        Comment section for permuted index source lines was added */
3720 /*        following the header. */
3721 
3722 /* -    SPICELIB Version 1.0.2, 03-SEP-1990 (NJB) */
3723 
3724 /*        Example added to the $Examples section. */
3725 
3726 /* -    SPICELIB Version 1.0.1, 22-MAR-1990 (HAN) */
3727 
3728 /*        Literature references added to the header. */
3729 
3730 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
3731 
3732 /* -& */
3733 /* $ Index_Entries */
3734 
3735 /*     handle to daf summary format */
3736 
3737 /* -& */
3738 
3739 /*     Standard SPICE error handling. */
3740 
3741     if (return_()) {
3742 	return 0;
3743     } else {
3744 	chkin_("DAFHSF", (ftnlen)6);
3745     }
3746     findex = isrchi_(handle, &nft, fthan);
3747     if (findex > 0) {
3748 	*nd = ftnd[(i__1 = findex - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge(
3749 		"ftnd", i__1, "dafah_", (ftnlen)3600)];
3750 	*ni = ftni[(i__1 = findex - 1) < 5000 && 0 <= i__1 ? i__1 : s_rnge(
3751 		"ftni", i__1, "dafah_", (ftnlen)3601)];
3752     } else {
3753 	setmsg_("There is no DAF open with handle = #", (ftnlen)36);
3754 	errint_("#", handle, (ftnlen)1);
3755 	sigerr_("SPICE(DAFNOSUCHHANDLE)", (ftnlen)22);
3756     }
3757     chkout_("DAFHSF", (ftnlen)6);
3758     return 0;
3759 /* $Procedure DAFHLU ( DAF, handle to logical unit ) */
3760 
3761 L_dafhlu:
3762 /* $ Abstract */
3763 
3764 /*     Return the logical unit associated with a handle. */
3765 
3766 /* $ Disclaimer */
3767 
3768 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
3769 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
3770 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
3771 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
3772 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
3773 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
3774 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
3775 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
3776 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
3777 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
3778 
3779 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
3780 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
3781 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
3782 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
3783 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
3784 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
3785 
3786 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
3787 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
3788 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
3789 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
3790 
3791 /* $ Required_Reading */
3792 
3793 /*     DAF */
3794 
3795 /* $ Keywords */
3796 
3797 /*     CONVERSION */
3798 /*     DAF */
3799 /*     FILES */
3800 
3801 /* $ Declarations */
3802 
3803 /*     INTEGER               HANDLE */
3804 /*     INTEGER               UNIT */
3805 
3806 /* $ Brief_I/O */
3807 
3808 /*     Variable  I/O  Description */
3809 /*     --------  ---  -------------------------------------------------- */
3810 /*     HANDLE     I   Handle of a DAF file. */
3811 /*     UNIT       O   Corresponding logical unit. */
3812 
3813 /* $ Detailed_Input */
3814 
3815 /*     HANDLE      is the handle associated with a previously opened */
3816 /*                 DAF file. */
3817 
3818 /* $ Detailed_Output */
3819 
3820 /*     UNIT        is the Fortran logical unit to which the file is */
3821 /*                 connected. */
3822 
3823 /* $ Parameters */
3824 
3825 /*      None. */
3826 
3827 /* $ Exceptions */
3828 
3829 /*     1) If an error occurs while attempting to fetch a logical */
3830 /*        unit, routines in the call tree process and signal any */
3831 /*        appropriate errors.  The value of UNIT in this case is */
3832 /*        undefined. */
3833 
3834 /* $ Files */
3835 
3836 /*     None. */
3837 
3838 /* $ Particulars */
3839 
3840 /*     The best reason for knowing the logical unit to which a DAF */
3841 /*     is connected is to read or write from the records reserved in a */
3842 /*     file. Since these records are by definition invisible to the DAF */
3843 /*     routines, you must read and write them directly. */
3844 
3845 /* $ Examples */
3846 
3847 /*     In the following code fragment, the first reserved record in */
3848 /*     a newly created DAF is used to store the name and address */
3849 /*     of the person who created it. */
3850 
3851 /*        FTYPE = 'TEST' */
3852 /*        CALL DAFONW ( FNAME, FTYPE, 3, 6, IFNAME, 5, HANDLE ) */
3853 /*        CALL DAFHLU ( HANDLE, UNIT ) */
3854 
3855 /*        WRITE (UNIT,REC=2) 'Ellis Wyatt, JPL ', */
3856 /*       .                   '4800 Oak Grove Drive ', */
3857 /*       .                   'Room 301-125A ', */
3858 /*       .                   'Pasadena, CA 91109' */
3859 
3860 /* $ Restrictions */
3861 
3862 /*     1) This routine may only be used to retrieve logical units */
3863 /*        for DAFs loaded or created using the interfaces available */
3864 /*        in this entry point umbrella.  Using this entry point to */
3865 /*        retrieve units for files not loaded through these interfaces */
3866 /*        may result in unexpected behavior. */
3867 
3868 /* $ Literature_References */
3869 
3870 /*     None. */
3871 
3872 /* $ Author_and_Institution */
3873 
3874 /*     N.J. Bachman    (JPL) */
3875 /*     K.R. Gehringer  (JPL) */
3876 /*     W.L. Taber      (JPL) */
3877 /*     R.E. Thurman    (JPL) */
3878 /*     F.S. Turner     (JPL) */
3879 /*     I.M. Underwood  (JPL) */
3880 
3881 /* $ Version */
3882 
3883 /* -    SPICELIB Version 8.0.1, 10-OCT-2012 (EDW) */
3884 
3885 /*        Corrected ordering of header section. */
3886 
3887 /*        Removed the obsolete Reference citation to "NAIF */
3888 /*        Document 167.0." */
3889 
3890 /* -    SPICELIB Version 8.0.0, 13-NOV-2001 (FST) */
3891 
3892 /*        This routine was updated to utilize the new handle manager */
3893 /*        software to manage binary file formats and consolidated */
3894 /*        I/O code. */
3895 
3896 /* -    SPICELIB Version 7.0.4, 08-OCT-1999 (WLT) */
3897 
3898 /*        The environment lines were expanded so that the supported */
3899 /*        environments are now explicitely given.  New */
3900 /*        environments are WIN-NT */
3901 
3902 /* -    SPICELIB Version 7.0.3, 16-SEP-1999 (NJB) */
3903 
3904 /*        CSPICE environments were added.  Some typos were corrected. */
3905 
3906 /* -    SPICELIB Version 7.0.2, 28-JUL-1999 (WLT) */
3907 
3908 /*        The environment lines were expanded so that the supported */
3909 /*        environments are now explicitly given.  New */
3910 /*        environments are PC-DIGITAL, SGI-O32 and SGI-N32. */
3911 
3912 /* -    SPICELIB Version 7.0.1, 17-MAR-1999 (WLT) */
3913 
3914 /*        The environment lines were expanded so that the supported */
3915 /*        environments are now explicitly given.  Previously, */
3916 /*        environments such as SUN-SUNOS and SUN-SOLARIS were implied */
3917 /*        by the environment label SUN. */
3918 
3919 /* -    SPICELIB Version 1.0.3, 29-SEP-1993 (KRG) */
3920 
3921 /*        Removed references to specific DAF file open routines in the */
3922 /*        $ Detailed_Input section of the header. This was done in order */
3923 /*        to minimize documentation changes if these open routines ever */
3924 /*        change. */
3925 
3926 /*        Changed the example to use the new entry point DAFONW. */
3927 
3928 /* -    SPICELIB Version 1.0.2, 10-MAR-1992 (WLT) */
3929 
3930 /*        Comment section for permuted index source lines was added */
3931 /*        following the header. */
3932 
3933 /* -    SPICELIB Version 1.0.1, 22-MAR-1990 (HAN) */
3934 
3935 /*        Literature references added to the header. */
3936 
3937 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
3938 
3939 /* -& */
3940 /* $ Index_Entries */
3941 
3942 /*     daf handle to logical unit */
3943 
3944 /* -& */
3945 /* $ Revisions */
3946 
3947 /* -    SPICELIB Version 8.0.0, 15-NOV-2000 (FST) */
3948 
3949 /*        Successfully invoking this module has the side effect of */
3950 /*        locking UNIT to HANDLE.  This 'lock' guarentees until */
3951 /*        HANDLE is closed (or unlocked) that the file associated */
3952 /*        with HANDLE is always open and attached to logical unit */
3953 /*        UNIT.  To unlock a handle without closing the file, use */
3954 /*        ZZDDHUNL, an entry point in the handle manager umbrella, */
3955 /*        ZZDDHMAN. */
3956 
3957 /*        The system can lock at most UTSIZE-SCRUNT-RSVUNT */
3958 /*        simultaneously (see the include file 'zzddhman.inc' for */
3959 /*        specific values of these parameters), but unnecessarily */
3960 /*        locking handles to their logical units may cause performance */
3961 /*        degradation.  The handle manager will have less logical */
3962 /*        units to utilize when disconnecting and reconnecting */
3963 /*        loaded files. */
3964 
3965 /* -    Beta Version 1.1.0, 1-NOV-1989 (RET) */
3966 
3967 /*        DAFHLU now only checks in and checks out if the one exception */
3968 /*        occurs. The purpose of this change was to help speed up a */
3969 /*        routine that gets called constantly by higher level DAF */
3970 /*        routines. */
3971 
3972 /* -& */
3973 
3974 /*     Standard SPICE error handling. */
3975 
3976     if (return_()) {
3977 	return 0;
3978     } else {
3979 	chkin_("DAFHLU", (ftnlen)6);
3980     }
3981     zzddhhlu_(handle, "DAF", &c_true, unit, (ftnlen)3);
3982     chkout_("DAFHLU", (ftnlen)6);
3983     return 0;
3984 /* $Procedure DAFLUH ( DAF, logical unit to handle ) */
3985 
3986 L_dafluh:
3987 /* $ Abstract */
3988 
3989 /*     Return the handle associated with a logical unit. */
3990 
3991 /* $ Disclaimer */
3992 
3993 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
3994 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
3995 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
3996 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
3997 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
3998 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
3999 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
4000 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
4001 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
4002 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
4003 
4004 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
4005 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
4006 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
4007 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
4008 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
4009 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
4010 
4011 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
4012 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
4013 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
4014 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
4015 
4016 /* $ Required_Reading */
4017 
4018 /*     DAF */
4019 
4020 /* $ Keywords */
4021 
4022 /*     CONVERSION */
4023 /*     DAF */
4024 /*     FILES */
4025 
4026 /* $ Declarations */
4027 
4028 /*     INTEGER               UNIT */
4029 /*     INTEGER               HANDLE */
4030 
4031 /* $ Brief_I/O */
4032 
4033 /*     Variable  I/O  Description */
4034 /*     --------  ---  -------------------------------------------------- */
4035 /*     UNIT       I   Logical unit connected to a DAF. */
4036 /*     HANDLE     O   Corresponding DAF file handle. */
4037 
4038 /* $ Detailed_Input */
4039 
4040 /*     UNIT        is the logical unit to which a DAF has been */
4041 /*                 connected after it has been opened. */
4042 
4043 /* $ Detailed_Output */
4044 
4045 /*     HANDLE      is the handle associated with the file. */
4046 
4047 /* $ Parameters */
4048 
4049 /*      None. */
4050 
4051 /* $ Exceptions */
4052 
4053 /*     1) If the specified unit is not connected to any file that is */
4054 /*        currently loaded as a DAF, the error SPICE(DAFNOSUCHUNIT) */
4055 /*        is signaled.  The value of HANDLE returned is undefined in */
4056 /*        this case. */
4057 
4058 /* $ Files */
4059 
4060 /*     None. */
4061 
4062 /* $ Particulars */
4063 
4064 /*     It is unlikely, but possible, that a calling program would know */
4065 /*     the logical unit to which a file is connected without knowing the */
4066 /*     handle associated with the file. DAFLUH is provided mostly for */
4067 /*     completeness. */
4068 
4069 /* $ Examples */
4070 
4071 /*     In the following code fragment, the handle associated with */
4072 /*     a DAF is retrieved using the logical unit to which the */
4073 /*     file is connected. The handle is then used to determine the */
4074 /*     name of the file. */
4075 
4076 /*        CALL DAFLUH ( UNIT,   HANDLE ) */
4077 /*        CALL DAFHFN ( HANDLE, FNAME ) */
4078 
4079 /* $ Restrictions */
4080 
4081 /*     1) This routine may only be used to retrieve handles for logical */
4082 /*        units connected to DAFs loaded or created using the interfaces */
4083 /*        available in this entry point umbrella.  Using this entry point */
4084 /*        to retrieve handles for files not loaded through these */
4085 /*        interfaces may result in unexpected behavior. */
4086 
4087 /* $ Literature_References */
4088 
4089 /*     None. */
4090 
4091 /* $ Author_and_Institution */
4092 
4093 /*     N.J. Bachman    (JPL) */
4094 /*     K.R. Gehringer  (JPL) */
4095 /*     W.L. Taber      (JPL) */
4096 /*     F.S. Turner     (JPL) */
4097 /*     I.M. Underwood  (JPL) */
4098 
4099 /* $ Version */
4100 
4101 /* -    SPICELIB Version 8.0.1, 10-OCT-2012 (EDW) */
4102 
4103 /*        Corrected ordering of header section. */
4104 
4105 /*        Removed the obsolete Reference citation to "NAIF */
4106 /*        Document 167.0." */
4107 
4108 /* -    SPICELIB Version 8.0.0, 13-NOV-2001 (FST) */
4109 
4110 /*        This routine was updated to utilize the new handle manager */
4111 /*        software to manage binary file formats and consolidated */
4112 /*        I/O code. */
4113 
4114 /* -    SPICELIB Version 7.0.4, 08-OCT-1999 (WLT) */
4115 
4116 /*        The environment lines were expanded so that the supported */
4117 /*        environments are now explicitely given.  New */
4118 /*        environments are WIN-NT */
4119 
4120 /* -    SPICELIB Version 7.0.3, 16-SEP-1999 (NJB) */
4121 
4122 /*        CSPICE environments were added.  Some typos were corrected. */
4123 
4124 /* -    SPICELIB Version 7.0.2, 28-JUL-1999 (WLT) */
4125 
4126 /*        The environment lines were expanded so that the supported */
4127 /*        environments are now explicitly given.  New */
4128 /*        environments are PC-DIGITAL, SGI-O32 and SGI-N32. */
4129 
4130 /* -    SPICELIB Version 7.0.1, 17-MAR-1999 (WLT) */
4131 
4132 /*        The environment lines were expanded so that the supported */
4133 /*        environments are now explicitly given.  Previously, */
4134 /*        environments such as SUN-SUNOS and SUN-SOLARIS were implied */
4135 /*        by the environment label SUN. */
4136 
4137 /* -    SPICELIB Version 1.0.3, 29-SEP-1993 (KRG) */
4138 
4139 /*        Removed references to specific DAF file open routines in the */
4140 /*        $ Detailed_Input section of the header. This was done in order */
4141 /*        to minimize documentation changes if these open routines ever */
4142 /*        change. */
4143 
4144 /* -    SPICELIB Version 1.0.2, 10-MAR-1992 (WLT) */
4145 
4146 /*        Comment section for permuted index source lines was added */
4147 /*        following the header. */
4148 
4149 /* -    SPICELIB Version 1.0.1, 22-MAR-1990 (HAN) */
4150 
4151 /*        Literature references added to the header. */
4152 
4153 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
4154 
4155 /* -& */
4156 /* $ Index_Entries */
4157 
4158 /*     logical unit to daf handle */
4159 
4160 /* -& */
4161 
4162 /*     Standard SPICE error handling. */
4163 
4164     if (return_()) {
4165 	return 0;
4166     } else {
4167 	chkin_("DAFLUH", (ftnlen)6);
4168     }
4169     zzddhluh_(unit, handle, &found);
4170     if (! found) {
4171 	*handle = 0;
4172 	setmsg_("There is no file open with unit = #", (ftnlen)35);
4173 	errint_("#", unit, (ftnlen)1);
4174 	sigerr_("SPICE(DAFNOSUCHUNIT)", (ftnlen)20);
4175 	chkout_("DAFLUH", (ftnlen)6);
4176 	return 0;
4177     }
4178 
4179 /*     Now make certain that the HANDLE is associated with a DAF. */
4180 
4181     zzddhnfo_(handle, dafnam, &iarc, &ibff, &iamh, &found, (ftnlen)255);
4182     if (iarc != 1) {
4183 	*handle = 0;
4184 	setmsg_("The file, '#', connected to unit # is not a DAF.", (ftnlen)
4185 		48);
4186 	errfnm_("#", unit, (ftnlen)1);
4187 	errint_("#", unit, (ftnlen)1);
4188 	sigerr_("SPICE(DAFNOSUCHUNIT)", (ftnlen)20);
4189 	chkout_("DAFLUH", (ftnlen)6);
4190 	return 0;
4191     }
4192     chkout_("DAFLUH", (ftnlen)6);
4193     return 0;
4194 /* $Procedure DAFHFN ( DAF, handle to file name ) */
4195 
4196 L_dafhfn:
4197 /* $ Abstract */
4198 
4199 /*     Return the name of the file associated with a handle. */
4200 
4201 /* $ Disclaimer */
4202 
4203 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
4204 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
4205 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
4206 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
4207 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
4208 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
4209 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
4210 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
4211 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
4212 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
4213 
4214 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
4215 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
4216 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
4217 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
4218 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
4219 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
4220 
4221 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
4222 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
4223 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
4224 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
4225 
4226 /* $ Required_Reading */
4227 
4228 /*     DAF */
4229 
4230 /* $ Keywords */
4231 
4232 /*     CONVERSION */
4233 /*     DAF */
4234 /*     FILES */
4235 
4236 /* $ Declarations */
4237 
4238 /*     INTEGER               HANDLE */
4239 /*     CHARACTER*(*)         FNAME */
4240 
4241 /* $ Brief_I/O */
4242 
4243 /*     Variable  I/O  Description */
4244 /*     --------  ---  -------------------------------------------------- */
4245 /*     HANDLE     I   Handle of a DAF file. */
4246 /*     FNAME      O   Corresponding file name. */
4247 
4248 /* $ Detailed_Input */
4249 
4250 /*     HANDLE      is the handle associated with a previously opened */
4251 /*                 DAF file. */
4252 
4253 /* $ Detailed_Output */
4254 
4255 /*     UNIT        is the name of the file. */
4256 
4257 /* $ Parameters */
4258 
4259 /*      None. */
4260 
4261 /* $ Exceptions */
4262 
4263 /*     1) If the specified handle does not belong to any file that is */
4264 /*        currently known to be loaded as a DAF, the error */
4265 /*        SPICE(DAFNOSUCHHANDLE) is signaled. */
4266 
4267 /* $ Files */
4268 
4269 /*     None. */
4270 
4271 /* $ Particulars */
4272 
4273 /*     It may be desirable to recover the names of one or more DAF */
4274 /*     files in a different part of the program from the one in which */
4275 /*     they were opened. Note that the names returned by DAFHFN may */
4276 /*     not be identical to the names used to open the files. Under */
4277 /*     most operating systems, a particular file can be accessed using */
4278 /*     many different names. DAFHFN returns one of them. */
4279 
4280 /* $ Examples */
4281 
4282 /*     In the following code fragment, the name of a DAF is */
4283 /*     recovered using the handle associated with the file. */
4284 
4285 /*        CALL DAFOPR ( 'sample.DAF', HANDLE ) */
4286 /*         . */
4287 /*         . */
4288 
4289 /*        CALL DAFHFN ( HANDLE, FNAME ) */
4290 
4291 /*     Depending on the circumstances (operating system, compiler, */
4292 /*     default directory) the value of FNAME might resemble any of */
4293 /*     the following: */
4294 
4295 /*        'USER$DISK:[WYATT.IMAGES]SAMPLE.DAF;4' */
4296 
4297 /*        '/wyatt/images/sample.DAF' */
4298 
4299 /*        'A:\IMAGES\SAMPLE.DAF' */
4300 
4301 /*     On the other hand, it might not. */
4302 
4303 /* $ Restrictions */
4304 
4305 /*     1) This routine may only be used to retrieve the names of DAFs */
4306 /*        loaded or created using the interfaces available in this entry */
4307 /*        point umbrella.  Using this entry point to retrieve names for */
4308 /*        files not loaded through these interfaces may result in */
4309 /*        unexpected behavior. */
4310 
4311 /* $ Literature_References */
4312 
4313 /*     None. */
4314 
4315 /* $ Author_and_Institution */
4316 
4317 /*     N.J. Bachman    (JPL) */
4318 /*     K.R. Gehringer  (JPL) */
4319 /*     J.M. Lynch      (JPL) */
4320 /*     W.L. Taber      (JPL) */
4321 /*     F.S. Turner     (JPL) */
4322 /*     I.M. Underwood  (JPL) */
4323 
4324 /* $ Version */
4325 
4326 /* -    SPICELIB Version 8.0.1, 10-OCT-2012 (EDW) */
4327 
4328 /*        Corrected ordering of header section. */
4329 
4330 /*        Removed the obsolete Reference citation to "NAIF */
4331 /*        Document 167.0." */
4332 
4333 /* -    SPICELIB Version 8.0.0, 13-NOV-2001 (FST) */
4334 
4335 /*        This routine was updated to utilize the new handle manager */
4336 /*        software to manage binary file formats and consolidated */
4337 /*        I/O code. */
4338 
4339 /* -    SPICELIB Version 7.0.4, 08-OCT-1999 (WLT) */
4340 
4341 /*        The environment lines were expanded so that the supported */
4342 /*        environments are now explicitely given.  New */
4343 /*        environments are WIN-NT */
4344 
4345 /* -    SPICELIB Version 7.0.3, 16-SEP-1999 (NJB) */
4346 
4347 /*        CSPICE environments were added.  Some typos were corrected. */
4348 
4349 /* -    SPICELIB Version 7.0.2, 28-JUL-1999 (WLT) */
4350 
4351 /*        The environment lines were expanded so that the supported */
4352 /*        environments are now explicitly given.  New */
4353 /*        environments are PC-DIGITAL, SGI-O32 and SGI-N32. */
4354 
4355 /* -    SPICELIB Version 7.0.1, 17-MAR-1999 (WLT) */
4356 
4357 /*        The environment lines were expanded so that the supported */
4358 /*        environments are now explicitly given.  Previously, */
4359 /*        environments such as SUN-SUNOS and SUN-SOLARIS were implied */
4360 /*        by the environment label SUN. */
4361 
4362 /* -    SPICELIB Version 1.1.1, 29-SEP-1993 (KRG) */
4363 
4364 /*        Removed references to specific DAF file open routines in the */
4365 /*        $ Detailed_Input section of the header. This was done in order */
4366 /*        to minimize documentation changes if these open routines ever */
4367 /*        change. */
4368 
4369 /* -    SPICELIB Version 1.1.0, 25-FEB-1993 (JML) */
4370 
4371 /*        IOSTAT is checked after the INQUIRE statement. */
4372 
4373 /* -    SPICELIB Version 1.0.2, 10-MAR-1992 (WLT) */
4374 
4375 /*        Comment section for permuted index source lines was added */
4376 /*        following the header. */
4377 
4378 /* -    SPICELIB Version 1.0.1, 22-MAR-1990 (HAN) */
4379 
4380 /*        Literature references added to the header. */
4381 
4382 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
4383 
4384 /* -& */
4385 /* $ Index_Entries */
4386 
4387 /*     daf handle to file name */
4388 
4389 /* -& */
4390 
4391 /*     Standard SPICE error handling. */
4392 
4393     if (return_()) {
4394 	return 0;
4395     } else {
4396 	chkin_("DAFHFN", (ftnlen)6);
4397     }
4398     zzddhnfo_(handle, dafnam, &iarc, &ibff, &iamh, &found, (ftnlen)255);
4399     if (! found || iarc != 1) {
4400 	setmsg_("There is no file open with handle = #", (ftnlen)37);
4401 	errint_("#", handle, (ftnlen)1);
4402 	sigerr_("SPICE(DAFNOSUCHHANDLE)", (ftnlen)22);
4403 	chkout_("DAFHFN", (ftnlen)6);
4404 	return 0;
4405     }
4406     s_copy(fname, dafnam, fname_len, (ftnlen)255);
4407     chkout_("DAFHFN", (ftnlen)6);
4408     return 0;
4409 /* $Procedure DAFFNH ( DAF, file name to handle ) */
4410 
4411 L_daffnh:
4412 /* $ Abstract */
4413 
4414 /*     Return handle associated with a file name. */
4415 
4416 /* $ Disclaimer */
4417 
4418 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
4419 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
4420 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
4421 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
4422 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
4423 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
4424 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
4425 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
4426 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
4427 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
4428 
4429 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
4430 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
4431 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
4432 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
4433 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
4434 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
4435 
4436 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
4437 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
4438 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
4439 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
4440 
4441 /* $ Required_Reading */
4442 
4443 /*     DAF */
4444 
4445 /* $ Keywords */
4446 
4447 /*     CONVERSION */
4448 /*     DAF */
4449 /*     FILES */
4450 
4451 /* $ Declarations */
4452 
4453 /*     CHARACTER*(*)         FNAME */
4454 /*     INTEGER               HANDLE */
4455 
4456 /* $ Brief_I/O */
4457 
4458 /*     Variable  I/O  Description */
4459 /*     --------  ---  -------------------------------------------------- */
4460 /*     FNAME      I   Name of a DAF file. */
4461 /*     HANDLE     O   Corresponding DAF file handle. */
4462 
4463 /* $ Detailed_Input */
4464 
4465 /*     FNAME       is the name of a previously opened DAF file. */
4466 
4467 /* $ Detailed_Output */
4468 
4469 /*     HANDLE      is the handle associated with the file. */
4470 
4471 /* $ Parameters */
4472 
4473 /*      None. */
4474 
4475 /* $ Exceptions */
4476 
4477 /*     1) If the specified name does not specify any file currently known */
4478 /*        to be loaded as a DAF the error SPICE(DAFNOSUCHFILE) is */
4479 /*        signaled.  The value of HANDLE is undefined in this case. */
4480 
4481 /*     2) If the file does not exist, an error is signaled by routines */
4482 /*        in the call tree of this routine.  The value of HANDLE is */
4483 /*        undefined in this case. */
4484 
4485 /*     3) Any I/O errors generated in the process of connecting the */
4486 /*        specified name with a handle cause errors to be signaled */
4487 /*        by routines in the call tree of this routine.  The value of */
4488 /*        HANDLE is undefined in this case. */
4489 
4490 /* $ Files */
4491 
4492 /*     None. */
4493 
4494 /* $ Particulars */
4495 
4496 /*     It is sometimes easier to work with file names (which are */
4497 /*     meaningful, and often predictable) than with file handles */
4498 /*     (which are neither), especially in interactive situations. */
4499 /*     However, nearly every DAF routines requires that you use file */
4500 /*     handles to refer to files. DAFFNH is provided to bridge the gap */
4501 /*     between the two representations. */
4502 
4503 /* $ Examples */
4504 
4505 /*     In the following code fragment, the handle associated with a */
4506 /*     DAF is recovered using the name of the file. */
4507 
4508 /*        CALL DAFOPR ( 'sample.DAF', HANDLE ) */
4509 /*         . */
4510 /*         . */
4511 
4512 /*        CALL DAFFNH ( 'sample.DAF', HANDLE ) */
4513 
4514 /* $ Restrictions */
4515 
4516 /*     1) Only file names of DAFs loaded with interfaces present in */
4517 /*        this entry point umbrella should be passed into this routine. */
4518 
4519 /* $ Literature_References */
4520 
4521 /*     None. */
4522 
4523 /* $ Author_and_Institution */
4524 
4525 /*     K.R. Gehringer  (JPL) */
4526 /*     J.M. Lynch      (JPL) */
4527 /*     H.A. Neilan     (JPL) */
4528 /*     W.L. Taber      (JPL) */
4529 /*     F.S. Turner     (JPL) */
4530 /*     I.M. Underwood  (JPL) */
4531 
4532 /* $ Version */
4533 
4534 /* -    SPICELIB Version 8.1.1, 10-OCT-2012 (EDW) */
4535 
4536 /*        Eliminated unneeded Revisions section. */
4537 
4538 /*        Corrected ordering of header section. */
4539 
4540 /*        Removed the obsolete Reference citation to "NAIF */
4541 /*        Document 167.0." */
4542 
4543 /* -    SPICELIB Version 8.1.0, 02-APR-2002 (FST) */
4544 
4545 /*        Fixed a bug, where an error was signaled but the call to */
4546 /*        CHKOUT and the RETURN statement were omitted. */
4547 
4548 /* -    SPICELIB Version 8.0.0, 13-NOV-2001 (FST) */
4549 
4550 /*        This routine was updated to utilize the new handle manager */
4551 /*        software to manage binary file formats and consolidated */
4552 /*        I/O code. */
4553 
4554 /*        In previous version of DAFAH, this module simply */
4555 /*        performed an INQUIRE on FNAME and looked in the */
4556 /*        file table for the logical unit returned. */
4557 
4558 /*        The integration of the new handle manager interfaces */
4559 /*        into this entry point has the possibility of increasing */
4560 /*        the complexity of this routine when more than UTSIZE */
4561 /*        files are loaded.  Essentially, when given an arbitrary */
4562 /*        name, a total of FTSIZE INQUIRE statements may be executed */
4563 /*        to accurately connect FNAME with HANDLE.  See ZZDDHFNH and */
4564 /*        ZZDDHF2H for details. */
4565 
4566 /* -    SPICELIB Version 7.0.4, 08-OCT-1999 (WLT) */
4567 
4568 /*        The environment lines were expanded so that the supported */
4569 /*        environments are now explicitely given.  New */
4570 /*        environments are WIN-NT */
4571 
4572 /* -    SPICELIB Version 7.0.3, 16-SEP-1999 (NJB) */
4573 
4574 /*        CSPICE environments were added.  Some typos were corrected. */
4575 
4576 /* -    SPICELIB Version 7.0.2, 28-JUL-1999 (WLT) */
4577 
4578 /*        The environment lines were expanded so that the supported */
4579 /*        environments are now explicitly given.  New */
4580 /*        environments are PC-DIGITAL, SGI-O32 and SGI-N32. */
4581 
4582 /* -    SPICELIB Version 7.0.1, 17-MAR-1999 (WLT) */
4583 
4584 /*        The environment lines were expanded so that the supported */
4585 /*        environments are now explicitly given.  Previously, */
4586 /*        environments such as SUN-SUNOS and SUN-SOLARIS were implied */
4587 /*        by the environment label SUN. */
4588 
4589 /* -    SPICELIB Version 2.0.1, 29-SEP-1993 (KRG) */
4590 
4591 /*        Removed references to specific DAF file open routines in the */
4592 /*        $ Detailed_Input section of the header. This was done in order */
4593 /*        to minimize documentation changes if these open routines ever */
4594 /*        change. */
4595 
4596 /* -    SPICELIB Version 2.0.0, 25-FEB-1993 (JML) */
4597 
4598 /*        The INQUIRE statement that checks if the file is open now also */
4599 /*        checks that the file exists. Two new exceptions were added as */
4600 /*        a result of this change. */
4601 
4602 /*        A RETURN statement was added after the error signalled when */
4603 /*        the file is not open. */
4604 
4605 /*        The file name is checked to see if it is blank. */
4606 
4607 /*        The file name string that is passed to the FORTRAN INQUIRE */
4608 /*        statement has been chopped at the last non-blank character. */
4609 
4610 /* -    SPICELIB Version 1.1.2, 10-MAR-1992 (WLT) */
4611 
4612 /*        Comment section for permuted index source lines was added */
4613 /*        following the header. */
4614 
4615 /* -    SPICELIB Version 1.1.1,  18-SEP-1991 (HAN) */
4616 
4617 /*        The Revisions section was incorrectly named Version. This has */
4618 /*        been fixed. */
4619 
4620 /* -    SPICELIB Version 1.1.0,  5-NOV-1990 (HAN) */
4621 
4622 /*        Call to CHKIN was corrected. The module was checking in */
4623 /*        as 'DAFFHN'. */
4624 
4625 /* -    SPICELIB Version 1.0.1, 22-MAR-1990 (HAN) */
4626 
4627 /*        Literature references added to the header. */
4628 
4629 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
4630 
4631 /* -& */
4632 /* $ Index_Entries */
4633 
4634 /*     file name to daf handle */
4635 
4636 /* -& */
4637 
4638 /*     Standard SPICE error handling. */
4639 
4640     if (return_()) {
4641 	return 0;
4642     } else {
4643 	chkin_("DAFFNH", (ftnlen)6);
4644     }
4645     zzddhfnh_(fname, handle, &found, fname_len);
4646     if (! found) {
4647 	*handle = 0;
4648 	setmsg_("There is no file in the DAF table with file name = '#'", (
4649 		ftnlen)54);
4650 	errch_("#", fname, (ftnlen)1, fname_len);
4651 	sigerr_("SPICE(DAFNOSUCHFILE)", (ftnlen)20);
4652 	chkout_("DAFFNH", (ftnlen)6);
4653 	return 0;
4654     }
4655 
4656 /*     Now make certain that HANDLE is associated with a DAF. */
4657 
4658     zzddhnfo_(handle, dafnam, &iarc, &ibff, &iamh, &found, (ftnlen)255);
4659     if (iarc != 1) {
4660 	*handle = 0;
4661 	setmsg_("The file, '#', is not a DAF.", (ftnlen)28);
4662 	errch_("#", fname, (ftnlen)1, fname_len);
4663 	sigerr_("SPICE(DAFNOSUCHFILE)", (ftnlen)20);
4664 	chkout_("DAFFNH", (ftnlen)6);
4665 	return 0;
4666     }
4667     chkout_("DAFFNH", (ftnlen)6);
4668     return 0;
4669 /* $Procedure DAFHOF ( DAF, handles of open files ) */
4670 
4671 L_dafhof:
4672 /* $ Abstract */
4673 
4674 /*     Return a SPICELIB set containing the handles of all currently */
4675 /*     open DAFS. */
4676 
4677 /* $ Disclaimer */
4678 
4679 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
4680 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
4681 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
4682 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
4683 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
4684 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
4685 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
4686 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
4687 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
4688 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
4689 
4690 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
4691 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
4692 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
4693 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
4694 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
4695 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
4696 
4697 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
4698 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
4699 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
4700 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
4701 
4702 /* $ Required_Reading */
4703 
4704 /*     DAF */
4705 /*     SETS */
4706 
4707 /* $ Keywords */
4708 
4709 /*     DAF */
4710 /*     FILES */
4711 
4712 /* $ Declarations */
4713 
4714 /*     INTEGER               LBCELL */
4715 /*     PARAMETER           ( LBCELL = -5 ) */
4716 
4717 /*     INTEGER               FHSET ( LBCELL : * ) */
4718 
4719 /* $ Brief_I/O */
4720 
4721 /*     Variable  I/O  Description */
4722 /*     --------  ---  -------------------------------------------------- */
4723 /*     FHSET      O   A set containing handles of currently open DAFS. */
4724 
4725 /* $ Detailed_Input */
4726 
4727 /*     None. */
4728 
4729 /* $ Detailed_Output */
4730 
4731 /*     FHSET          is a SPICELIB set containing the file handles of */
4732 /*                    all currently open DAFs. */
4733 
4734 /* $ Parameters */
4735 
4736 /*     None. */
4737 
4738 /* $ Exceptions */
4739 
4740 /*     1)  If the set FHSET is not initialized, the error will be */
4741 /*         diagnosed by routines called by this routine. */
4742 
4743 /*     2)  If the set FHSET is too small to accommodate the set of */
4744 /*         handles to be returned, the error will be diagnosed by */
4745 /*         routines called by this routine. */
4746 
4747 /* $ Files */
4748 
4749 /*     None. */
4750 
4751 /* $ Particulars */
4752 
4753 /*     This routine allows subroutines to test file handles for */
4754 /*     validity before performing operations on them, such as */
4755 /*     finding the name of the file designated by a handle.  Many */
4756 /*     DAF operations on handles cause errors to be signalled if */
4757 /*     the handles are invalid. */
4758 
4759 /* $ Examples */
4760 
4761 /*     1)  Find out how may DAFs are open for writing. */
4762 
4763 /*            C */
4764 /*            C    Find out which DAFs are open. */
4765 /*            C */
4766 /*                 CALL DAFHOF  ( FHSET ) */
4767 
4768 /*            C */
4769 /*            C    Count the ones open for writing.  These have */
4770 /*            C    negative file handles. */
4771 /*            C */
4772 /*                 COUNT = 0 */
4773 
4774 /*                 DO I = 1, CARDC(FHSET) */
4775 
4776 /*                    IF ( FHSET(I) .LT. 0 ) THEN */
4777 /*                       COUNT = COUNT + 1 */
4778 /*                    END IF */
4779 
4780 /*                 END DO */
4781 
4782 /* $ Restrictions */
4783 
4784 /*     None. */
4785 
4786 /* $ Literature_References */
4787 
4788 /*     None. */
4789 
4790 /* $ Author_and_Institution */
4791 
4792 /*     N.J. Bachman   (JPL) */
4793 /*     W.L. Taber     (JPL) */
4794 /*     F.S. Turner    (JPL) */
4795 
4796 /* $ Version */
4797 
4798 /* -    SPICELIB Version 8.0.1, 10-OCT-2012 (EDW) */
4799 
4800 /*        Corrected ordering of header section. */
4801 
4802 /* -    SPICELIB Version 8.0.0, 13-NOV-2001 (FST) */
4803 
4804 /*        This routine was updated to utilize the new handle manager */
4805 /*        software to manage binary file formats and consolidated */
4806 /*        I/O code. */
4807 
4808 /* -    SPICELIB Version 7.0.4, 08-OCT-1999 (WLT) */
4809 
4810 /*        The environment lines were expanded so that the supported */
4811 /*        environments are now explicitely given.  New */
4812 /*        environments are WIN-NT */
4813 
4814 /* -    SPICELIB Version 7.0.3, 16-SEP-1999 (NJB) */
4815 
4816 /*        CSPICE environments were added.  Some typos were corrected. */
4817 
4818 /* -    SPICELIB Version 7.0.2, 28-JUL-1999 (WLT) */
4819 
4820 /*        The environment lines were expanded so that the supported */
4821 /*        environments are now explicitly given.  New */
4822 /*        environments are PC-DIGITAL, SGI-O32 and SGI-N32. */
4823 
4824 /* -    SPICELIB Version 7.0.1, 17-MAR-1999 (WLT) */
4825 
4826 /*        The environment lines were expanded so that the supported */
4827 /*        environments are now explicitly given.  Previously, */
4828 /*        environments such as SUN-SUNOS and SUN-SOLARIS were implied */
4829 /*        by the environment label SUN. */
4830 
4831 /* -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
4832 
4833 /*        Comment section for permuted index source lines was added */
4834 /*        following the header. */
4835 
4836 /* -    SPICELIB Version 1.0.0, 03-SEP-1991 (NJB) (WLT) */
4837 
4838 /* -& */
4839 /* $ Index_Entries */
4840 
4841 /*     return the set of handles for open daf files */
4842 
4843 /* -& */
4844 
4845 /*     Standard SPICE error handling. */
4846 
4847     if (return_()) {
4848 	return 0;
4849     } else {
4850 	chkin_("DAFHOF", (ftnlen)6);
4851     }
4852 
4853 /*     Initialize the handle list, if necessary. */
4854 
4855     if (first) {
4856 	ssizei_(&c__5000, fhlist);
4857 	first = FALSE_;
4858     }
4859 
4860 /*     Just stuff our local list into the set. */
4861 
4862     copyi_(fhlist, fhset);
4863     chkout_("DAFHOF", (ftnlen)6);
4864     return 0;
4865 /* $Procedure DAFSIH ( DAF, signal invalid handles ) */
4866 
4867 L_dafsih:
4868 /* $ Abstract */
4869 
4870 /*     Signal an error if a DAF file handle does not designate a DAF */
4871 /*     that is open for a specified type of access. */
4872 
4873 /* $ Disclaimer */
4874 
4875 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
4876 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
4877 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
4878 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
4879 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
4880 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
4881 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
4882 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
4883 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
4884 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
4885 
4886 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
4887 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
4888 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
4889 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
4890 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
4891 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
4892 
4893 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
4894 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
4895 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
4896 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
4897 
4898 /* $ Required_Reading */
4899 
4900 /*     DAF */
4901 /*     ERROR */
4902 /*     SETS */
4903 
4904 /* $ Keywords */
4905 
4906 /*     DAF */
4907 /*     FILES */
4908 
4909 /* $ Declarations */
4910 
4911 /*     INTEGER               HANDLE */
4912 /*     CHARACTER*(*)         ACCESS */
4913 
4914 /* $ Brief_I/O */
4915 
4916 /*     Variable  I/O  Description */
4917 /*     --------  ---  -------------------------------------------------- */
4918 /*     HANDLE     I   HANDLE to be validated. */
4919 /*     ACCESS     I   String indicating access type. */
4920 
4921 /* $ Detailed_Input */
4922 
4923 /*     HANDLE         is a DAF handle to validate.  For HANDLE to be */
4924 /*                    considered valid, it must specify a DAF that is */
4925 /*                    open for the type of access specified by the input */
4926 /*                    argument ACCESS. */
4927 
4928 
4929 /*     ACCESS         is a string indicating the type of access that */
4930 /*                    the DAF specified by the input argument HANDLE */
4931 /*                    must be open for.  The values of ACCESS may be */
4932 
4933 
4934 /*                       'READ'      File must be open for read access */
4935 /*                                   by DAF routines.  All open DAFs */
4936 /*                                   may be read. */
4937 
4938 /*                       'WRITE'     File must be open for write access */
4939 /*                                   by DAF routines. */
4940 
4941 /*                                   Note that files open for write */
4942 /*                                   access may be read as well as */
4943 /*                                   written. */
4944 
4945 
4946 /*                    Leading and trailing blanks in ACCESS are ignored, */
4947 /*                    and case is not significant. */
4948 
4949 /* $ Detailed_Output */
4950 
4951 /*     None. */
4952 
4953 /* $ Parameters */
4954 
4955 /*     None. */
4956 
4957 /* $ Exceptions */
4958 
4959 /*     1)  If the input argument ACCESS has an unrecognized value, */
4960 /*         the error SPICE(INVALIDOPTION) is signalled. */
4961 
4962 /* $ Files */
4963 
4964 /*     None. */
4965 
4966 /* $ Particulars */
4967 
4968 /*     This routine signals the error SPICE(DAFINVALIDACCESS) if the */
4969 /*     DAF designated by the input argument HANDLE is not open */
4970 /*     for the specified type of access.  If HANDLE does not designate */
4971 /*     an open DAF, the error SPICE(DAFNOSUCHHANDLE) is signalled. */
4972 
4973 /*     This routine allows subroutines to test file handles for */
4974 /*     validity before performing operations on them, such as */
4975 /*     finding the name of the file designated by a handle.  Many */
4976 /*     DAF operations on handles may cause unpredictable program */
4977 /*     behavior if the handles are invalid.  This routine should */
4978 /*     be used in situations where the appropriate action to take upon */
4979 /*     determining that a handle is invalid is to signal an error. */
4980 /*     DAFSIH centralizes the error response for this type of error in a */
4981 /*     single routine. */
4982 
4983 /*     In cases where it is necessary to determine the validity of a */
4984 /*     file handle, but it is not an error for the handle to refer */
4985 /*     to a closed file, the entry point DAFHOF should be used instead */
4986 /*     of DAFSIH. */
4987 
4988 /* $ Examples */
4989 
4990 /*     1)  Add data to a DAF specified by a file handle.  Signal an */
4991 /*         error if the file is not open for writing.  Check the */
4992 /*         SPICELIB error status function FAILED after calling */
4993 /*         DAFSIH, so that the routine will return if DAFSIH */
4994 /*         signalled an error (we're presuming that this code */
4995 /*         fragment would be used in a subroutine). */
4996 
4997 /*            C */
4998 /*            C     Check that HANDLE is valid, then add data to the */
4999 /*            C     file specified by HANDLE. */
5000 /*            C */
5001 /*                  CALL DAFSIH  (  HANDLE, 'WRITE' ) */
5002 
5003 /*                  IF ( FAILED() ) THEN */
5004 /*                     RETURN */
5005 /*                  END IF */
5006 
5007 /*                  CALL DAFBNA (  HANDLE,  SUM,    NAME ) */
5008 /*                  CALL DAFADA (  DATA,    N            ) */
5009 /*                  CALL DAFENA */
5010 
5011 /*     2)  Find the size of an array in a DAF specified by a file */
5012 /*         handle.  Signal an error if the file is not open for reading. */
5013 
5014 /*            C */
5015 /*            C     Check that HANDLE is valid, then obtain the */
5016 /*            C     current array summary and compute the size of */
5017 /*            C     the current array. */
5018 /*            C */
5019 /*                  CALL DAFSIH  ( HANDLE, 'READ' ) */
5020 
5021 /*                  IF ( FAILED() ) THEN */
5022 /*                     RETURN */
5023 /*                  END IF */
5024 
5025 /*            C */
5026 /*            C     Obtain the summary format, then the integer and d.p. */
5027 /*            C     components of the summary.  Finally, compute the */
5028 /*            C     array length. */
5029 /*            C */
5030 /*                  CALL DAFHSF (  HANDLE, ND, NI          ) */
5031 /*                  CALL DAFGS  (  SUMMRY                  ) */
5032 /*                  CALL DAFUS  (  SUMMRY, ND, NI, DC, IC  ) */
5033 
5034 /*                  IA      =  IC( NI - 1 ) */
5035 /*                  FA      =  IC( NI     ) */
5036 /*                  LENGTH  =  FA  -  IA  +  1 */
5037 
5038 /*     3)  Make sure that a file handle designates an open DAF.  Signal */
5039 /*         an error if it does not. */
5040 
5041 /*         Note that if a DAF is open at all, read access is allowed. */
5042 
5043 /*                  CALL DAFSIH ( HANDLE, 'READ' ) */
5044 
5045 /*                  IF ( FAILED() ) THEN */
5046 /*                     RETURN */
5047 /*                  END IF */
5048 
5049 /* $ Restrictions */
5050 
5051 /*     None. */
5052 
5053 /* $ Literature_References */
5054 
5055 /*     None. */
5056 
5057 /* $ Author_and_Institution */
5058 
5059 /*     K.R. Gehringer (JPL) */
5060 /*     N.J. Bachman   (JPL) */
5061 /*     J.M. Lynch     (JPL) */
5062 /*     W.L. Taber     (JPL) */
5063 /*     F.S. Turner    (JPL) */
5064 
5065 /* $ Version */
5066 
5067 /* -    SPICELIB Version 8.0.1, 10-OCT-2012 (EDW) */
5068 
5069 /*        Corrected ordering of header section. */
5070 
5071 /* -    SPICELIB Version 8.0.0, 13-NOV-2001 (FST) */
5072 
5073 /*        This routine was updated to utilize the new handle manager */
5074 /*        software to manage binary file formats and consolidated */
5075 /*        I/O code. */
5076 
5077 /* -    SPICELIB Version 7.0.4, 08-OCT-1999 (WLT) */
5078 
5079 /*        The environment lines were expanded so that the supported */
5080 /*        environments are now explicitely given.  New */
5081 /*        environments are WIN-NT */
5082 
5083 /* -    SPICELIB Version 7.0.3, 16-SEP-1999 (NJB) */
5084 
5085 /*        CSPICE environments were added.  Some typos were corrected. */
5086 
5087 /* -    SPICELIB Version 7.0.2, 28-JUL-1999 (WLT) */
5088 
5089 /*        The environment lines were expanded so that the supported */
5090 /*        environments are now explicitly given.  New */
5091 /*        environments are PC-DIGITAL, SGI-O32 and SGI-N32. */
5092 
5093 /* -    SPICELIB Version 7.0.1, 17-MAR-1999 (WLT) */
5094 
5095 /*        The environment lines were expanded so that the supported */
5096 /*        environments are now explicitly given.  Previously, */
5097 /*        environments such as SUN-SUNOS and SUN-SOLARIS were implied */
5098 /*        by the environment label SUN. */
5099 
5100 /* -    SPICELIB Version 1.2.1, 29-SEP-1993 (KRG) */
5101 
5102 /*        Removed references to specific DAF file open routines in the */
5103 /*        $ Detailed_Input section of the header. This was done in order */
5104 /*        to minimize documentation changes if these open routines ever */
5105 /*        change. */
5106 
5107 /* -    SPICELIB Version 1.2.0, 25-FEB-1993 (JML) */
5108 
5109 /*        IOSTAT is now checked after the INQUIRE statement. */
5110 
5111 /* -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
5112 
5113 /*        Comment section for permuted index source lines was added */
5114 /*        following the header. */
5115 
5116 /* -    SPICELIB Version 1.0.0, 03-SEP-1991 (NJB) (WLT) */
5117 
5118 /* -& */
5119 /* $ Index_Entries */
5120 
5121 /*     signal an error for invalid daf handles */
5122 
5123 /* -& */
5124 
5125 /*     Standard SPICE error handling. */
5126 
5127     if (return_()) {
5128 	return 0;
5129     } else {
5130 	chkin_("DAFSIH", (ftnlen)6);
5131     }
5132 
5133 /*     Initialize the handle list, if necessary. */
5134 
5135     if (first) {
5136 	ssizei_(&c__5000, fhlist);
5137 	first = FALSE_;
5138     }
5139 
5140 /*     Get an upper case, left-justified copy of ACCESS. */
5141 
5142     ljust_(access, acc, access_len, (ftnlen)10);
5143     ucase_(acc, acc, (ftnlen)10, (ftnlen)10);
5144 
5145 /*     Make sure we recognize the access type specified by the caller. */
5146 
5147     if (s_cmp(acc, "READ", (ftnlen)10, (ftnlen)4) != 0 && s_cmp(acc, "WRITE",
5148 	    (ftnlen)10, (ftnlen)5) != 0) {
5149 	setmsg_("Unrecognized access type.  Type was #. ", (ftnlen)39);
5150 	errch_("#", access, (ftnlen)1, access_len);
5151 	sigerr_("SPICE(INVALIDOPTION)", (ftnlen)20);
5152 	chkout_("DAFSIH", (ftnlen)6);
5153 	return 0;
5154     }
5155 
5156 /*     Retrieve information about this HANDLE. */
5157 
5158     zzddhnfo_(handle, dafnam, &iarc, &ibff, &iamh, &found, (ftnlen)255);
5159 
5160 /*     See whether the input handle is in our list at all.  It's */
5161 /*     unlawful for the handle to be absent.  All open DAFs are */
5162 /*     readable, so in the case that ACC is 'READ', we're done if */
5163 /*     the DAF is open. */
5164 
5165     if (! found || ! elemi_(handle, fhlist)) {
5166 	setmsg_("There is no file open with handle = #", (ftnlen)37);
5167 	errint_("#", handle, (ftnlen)1);
5168 	sigerr_("SPICE(DAFNOSUCHHANDLE)", (ftnlen)22);
5169 	chkout_("DAFSIH", (ftnlen)6);
5170 	return 0;
5171 
5172 /*     If the access type is 'WRITE', the DAF must be open for writing. */
5173 /*     This is not the case if the value of IAMH returned from the handle */
5174 /*     manager is not READ. */
5175 
5176     } else if (s_cmp(acc, "WRITE", (ftnlen)10, (ftnlen)5) == 0 && iamh == 1) {
5177 	setmsg_("DAF not open for write.  Handle = #, file = '#'", (ftnlen)47)
5178 		;
5179 	errint_("#", handle, (ftnlen)1);
5180 	errch_("#", dafnam, (ftnlen)1, (ftnlen)255);
5181 	sigerr_("SPICE(DAFINVALIDACCESS)", (ftnlen)23);
5182 	chkout_("DAFSIH", (ftnlen)6);
5183 	return 0;
5184     }
5185 
5186 /*     The DAF's handle is o.k. */
5187 
5188     chkout_("DAFSIH", (ftnlen)6);
5189     return 0;
5190 } /* dafah_ */
5191 
dafah_(char * fname,char * ftype,integer * nd,integer * ni,char * ifname,integer * resv,integer * handle,integer * unit,integer * fhset,char * access,ftnlen fname_len,ftnlen ftype_len,ftnlen ifname_len,ftnlen access_len)5192 /* Subroutine */ int dafah_(char *fname, char *ftype, integer *nd, integer *
5193 	ni, char *ifname, integer *resv, integer *handle, integer *unit,
5194 	integer *fhset, char *access, ftnlen fname_len, ftnlen ftype_len,
5195 	ftnlen ifname_len, ftnlen access_len)
5196 {
5197     return dafah_0_(0, fname, ftype, nd, ni, ifname, resv, handle, unit,
5198 	    fhset, access, fname_len, ftype_len, ifname_len, access_len);
5199     }
5200 
dafopr_(char * fname,integer * handle,ftnlen fname_len)5201 /* Subroutine */ int dafopr_(char *fname, integer *handle, ftnlen fname_len)
5202 {
5203     return dafah_0_(1, fname, (char *)0, (integer *)0, (integer *)0, (char *)
5204 	    0, (integer *)0, handle, (integer *)0, (integer *)0, (char *)0,
5205 	    fname_len, (ftnint)0, (ftnint)0, (ftnint)0);
5206     }
5207 
dafopw_(char * fname,integer * handle,ftnlen fname_len)5208 /* Subroutine */ int dafopw_(char *fname, integer *handle, ftnlen fname_len)
5209 {
5210     return dafah_0_(2, fname, (char *)0, (integer *)0, (integer *)0, (char *)
5211 	    0, (integer *)0, handle, (integer *)0, (integer *)0, (char *)0,
5212 	    fname_len, (ftnint)0, (ftnint)0, (ftnint)0);
5213     }
5214 
dafonw_(char * fname,char * ftype,integer * nd,integer * ni,char * ifname,integer * resv,integer * handle,ftnlen fname_len,ftnlen ftype_len,ftnlen ifname_len)5215 /* Subroutine */ int dafonw_(char *fname, char *ftype, integer *nd, integer *
5216 	ni, char *ifname, integer *resv, integer *handle, ftnlen fname_len,
5217 	ftnlen ftype_len, ftnlen ifname_len)
5218 {
5219     return dafah_0_(3, fname, ftype, nd, ni, ifname, resv, handle, (integer *)
5220 	    0, (integer *)0, (char *)0, fname_len, ftype_len, ifname_len, (
5221 	    ftnint)0);
5222     }
5223 
dafopn_(char * fname,integer * nd,integer * ni,char * ifname,integer * resv,integer * handle,ftnlen fname_len,ftnlen ifname_len)5224 /* Subroutine */ int dafopn_(char *fname, integer *nd, integer *ni, char *
5225 	ifname, integer *resv, integer *handle, ftnlen fname_len, ftnlen
5226 	ifname_len)
5227 {
5228     return dafah_0_(4, fname, (char *)0, nd, ni, ifname, resv, handle, (
5229 	    integer *)0, (integer *)0, (char *)0, fname_len, (ftnint)0,
5230 	    ifname_len, (ftnint)0);
5231     }
5232 
dafcls_(integer * handle)5233 /* Subroutine */ int dafcls_(integer *handle)
5234 {
5235     return dafah_0_(5, (char *)0, (char *)0, (integer *)0, (integer *)0, (
5236 	    char *)0, (integer *)0, handle, (integer *)0, (integer *)0, (char
5237 	    *)0, (ftnint)0, (ftnint)0, (ftnint)0, (ftnint)0);
5238     }
5239 
dafhsf_(integer * handle,integer * nd,integer * ni)5240 /* Subroutine */ int dafhsf_(integer *handle, integer *nd, integer *ni)
5241 {
5242     return dafah_0_(6, (char *)0, (char *)0, nd, ni, (char *)0, (integer *)0,
5243 	    handle, (integer *)0, (integer *)0, (char *)0, (ftnint)0, (ftnint)
5244 	    0, (ftnint)0, (ftnint)0);
5245     }
5246 
dafhlu_(integer * handle,integer * unit)5247 /* Subroutine */ int dafhlu_(integer *handle, integer *unit)
5248 {
5249     return dafah_0_(7, (char *)0, (char *)0, (integer *)0, (integer *)0, (
5250 	    char *)0, (integer *)0, handle, unit, (integer *)0, (char *)0, (
5251 	    ftnint)0, (ftnint)0, (ftnint)0, (ftnint)0);
5252     }
5253 
dafluh_(integer * unit,integer * handle)5254 /* Subroutine */ int dafluh_(integer *unit, integer *handle)
5255 {
5256     return dafah_0_(8, (char *)0, (char *)0, (integer *)0, (integer *)0, (
5257 	    char *)0, (integer *)0, handle, unit, (integer *)0, (char *)0, (
5258 	    ftnint)0, (ftnint)0, (ftnint)0, (ftnint)0);
5259     }
5260 
dafhfn_(integer * handle,char * fname,ftnlen fname_len)5261 /* Subroutine */ int dafhfn_(integer *handle, char *fname, ftnlen fname_len)
5262 {
5263     return dafah_0_(9, fname, (char *)0, (integer *)0, (integer *)0, (char *)
5264 	    0, (integer *)0, handle, (integer *)0, (integer *)0, (char *)0,
5265 	    fname_len, (ftnint)0, (ftnint)0, (ftnint)0);
5266     }
5267 
daffnh_(char * fname,integer * handle,ftnlen fname_len)5268 /* Subroutine */ int daffnh_(char *fname, integer *handle, ftnlen fname_len)
5269 {
5270     return dafah_0_(10, fname, (char *)0, (integer *)0, (integer *)0, (char *)
5271 	    0, (integer *)0, handle, (integer *)0, (integer *)0, (char *)0,
5272 	    fname_len, (ftnint)0, (ftnint)0, (ftnint)0);
5273     }
5274 
dafhof_(integer * fhset)5275 /* Subroutine */ int dafhof_(integer *fhset)
5276 {
5277     return dafah_0_(11, (char *)0, (char *)0, (integer *)0, (integer *)0, (
5278 	    char *)0, (integer *)0, (integer *)0, (integer *)0, fhset, (char *
5279 	    )0, (ftnint)0, (ftnint)0, (ftnint)0, (ftnint)0);
5280     }
5281 
dafsih_(integer * handle,char * access,ftnlen access_len)5282 /* Subroutine */ int dafsih_(integer *handle, char *access, ftnlen access_len)
5283 {
5284     return dafah_0_(12, (char *)0, (char *)0, (integer *)0, (integer *)0, (
5285 	    char *)0, (integer *)0, handle, (integer *)0, (integer *)0,
5286 	    access, (ftnint)0, (ftnint)0, (ftnint)0, access_len);
5287     }
5288 
5289