1 /* dafana.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 integer c__20 = 20;
12 static integer c__1 = 1;
13 static integer c__128 = 128;
14 
15 /* $Procedure DAFANA ( DAF, add new array ) */
dafana_0_(int n__,integer * handle,doublereal * sum,char * name__,doublereal * data,integer * n,ftnlen name_len)16 /* Subroutine */ int dafana_0_(int n__, integer *handle, doublereal *sum,
17 	char *name__, doublereal *data, integer *n, ftnlen name_len)
18 {
19     /* Initialized data */
20 
21     static logical first = TRUE_;
22     static integer sthead = -1;
23     static integer stfptr = -1;
24 
25     /* System generated locals */
26     integer i__1, i__2, i__3, i__4, i__5;
27 
28     /* Builtin functions */
29     integer s_rnge(char *, integer, char *, integer);
30     /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen);
31 
32     /* Local variables */
33     static integer cloc, dloc, free, stfh[20], word, prev, next, i__, p;
34     extern logical elemi_(integer *, integer *);
35     extern /* Subroutine */ int chkin_(char *, ftnlen), dafps_(integer *,
36 	    integer *, doublereal *, integer *, doublereal *);
37     static integer bward;
38     extern /* Subroutine */ int dafus_(doublereal *, integer *, integer *,
39 	    doublereal *, integer *);
40     static integer fward;
41     extern /* Subroutine */ int errch_(char *, char *, ftnlen, ftnlen),
42 	    moved_(doublereal *, integer *, doublereal *);
43     static logical found;
44     static integer nextp;
45     static doublereal dc[124];
46     static integer ic[250], nd;
47     extern logical failed_(void);
48     static char dafnam[255];
49     static integer ni;
50     extern /* Subroutine */ int dafhof_(integer *), dafhfn_(integer *, char *,
51 	     ftnlen), dafwda_(integer *, integer *, integer *, doublereal *),
52 	    dafhsf_(integer *, integer *, integer *), dafsih_(integer *, char
53 	    *, ftnlen);
54     static char ifname[60];
55     extern /* Subroutine */ int cleard_(integer *, doublereal *), dafrcr_(
56 	    integer *, integer *, char *, ftnlen), dafrdr_(integer *, integer
57 	    *, integer *, integer *, doublereal *, logical *), dafrfr_(
58 	    integer *, integer *, integer *, char *, integer *, integer *,
59 	    integer *, ftnlen);
60     static char namrec[1000];
61     static logical staddg[20];
62     extern /* Subroutine */ int dafwdr_(integer *, integer *, doublereal *),
63 	    dafwcr_(integer *, integer *, char *, ftnlen), dafarw_(integer *,
64 	    integer *, integer *), dafrwa_(integer *, integer *, integer *),
65 	    errhan_(char *, integer *, ftnlen);
66     static integer stbegn[20];
67     extern /* Subroutine */ int dafwfr_(integer *, integer *, integer *, char
68 	    *, integer *, integer *, integer *, ftnlen);
69     static integer stfree[20];
70     static char stname[1000*20];
71     extern /* Subroutine */ int sigerr_(char *, ftnlen);
72     static integer narray;
73     extern /* Subroutine */ int chkout_(char *, ftnlen);
74     static doublereal sumrec[128];
75     static char stifnm[60*20];
76     static integer namsiz, opnset[5006];
77     extern /* Subroutine */ int ssizei_(integer *, integer *);
78     static integer stlast[20];
79     extern /* Subroutine */ int setmsg_(char *, ftnlen);
80     extern logical return_(void);
81     static integer stpool[20];
82     extern /* Subroutine */ int errint_(char *, integer *, ftnlen);
83     static integer stfrst[20];
84     static doublereal stlsum[2500]	/* was [125][20] */;
85     static integer sumsiz;
86 
87 /* $ Abstract */
88 
89 /*     Add a new array to an existing DAF. */
90 
91 /* $ Disclaimer */
92 
93 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
94 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
95 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
96 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
97 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
98 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
99 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
100 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
101 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
102 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
103 
104 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
105 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
106 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
107 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
108 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
109 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
110 
111 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
112 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
113 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
114 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
115 
116 /* $ Required_Reading */
117 
118 /*     DAF */
119 
120 /* $ Keywords */
121 
122 /*     FILES */
123 
124 /* $ Declarations */
125 
126 /* $ Abstract */
127 
128 /*     Parameter declarations for the DAF/DAS handle manager. */
129 
130 /* $ Disclaimer */
131 
132 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
133 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
134 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
135 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
136 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
137 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
138 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
139 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
140 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
141 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
142 
143 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
144 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
145 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
146 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
147 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
148 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
149 
150 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
151 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
152 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
153 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
154 
155 /* $ Required_Reading */
156 
157 /*     DAF, DAS */
158 
159 /* $ Keywords */
160 
161 /*     PRIVATE */
162 
163 /* $ Particulars */
164 
165 /*     This include file contains parameters defining limits and */
166 /*     integer codes that are utilized in the DAF/DAS handle manager */
167 /*     routines. */
168 
169 /* $ Restrictions */
170 
171 /*     None. */
172 
173 /* $ Author_and_Institution */
174 
175 /*     F.S. Turner       (JPL) */
176 
177 /* $ Literature_References */
178 
179 /*     None. */
180 
181 /* $ Version */
182 
183 /* -    SPICELIB Version 2.5.0, 10-MAR-2014 (BVS) */
184 
185 /*        Updated for SUN-SOLARIS-64BIT-INTEL. */
186 
187 /* -    SPICELIB Version 2.4.0, 10-MAR-2014 (BVS) */
188 
189 /*        Updated for PC-LINUX-64BIT-IFORT. */
190 
191 /* -    SPICELIB Version 2.3.0, 10-MAR-2014 (BVS) */
192 
193 /*        Updated for PC-CYGWIN-GFORTRAN. */
194 
195 /* -    SPICELIB Version 2.2.0, 10-MAR-2014 (BVS) */
196 
197 /*        Updated for PC-CYGWIN-64BIT-GFORTRAN. */
198 
199 /* -    SPICELIB Version 2.1.0, 10-MAR-2014 (BVS) */
200 
201 /*        Updated for PC-CYGWIN-64BIT-GCC_C. */
202 
203 /* -    SPICELIB Version 2.0.0, 12-APR-2012 (BVS) */
204 
205 /*        Increased FTSIZE (from 1000 to 5000). */
206 
207 /* -    SPICELIB Version 1.20.0, 13-MAY-2010 (BVS) */
208 
209 /*        Updated for SUN-SOLARIS-INTEL. */
210 
211 /* -    SPICELIB Version 1.19.0, 13-MAY-2010 (BVS) */
212 
213 /*        Updated for SUN-SOLARIS-INTEL-CC_C. */
214 
215 /* -    SPICELIB Version 1.18.0, 13-MAY-2010 (BVS) */
216 
217 /*        Updated for SUN-SOLARIS-INTEL-64BIT-CC_C. */
218 
219 /* -    SPICELIB Version 1.17.0, 13-MAY-2010 (BVS) */
220 
221 /*        Updated for SUN-SOLARIS-64BIT-NATIVE_C. */
222 
223 /* -    SPICELIB Version 1.16.0, 13-MAY-2010 (BVS) */
224 
225 /*        Updated for PC-WINDOWS-64BIT-IFORT. */
226 
227 /* -    SPICELIB Version 1.15.0, 13-MAY-2010 (BVS) */
228 
229 /*        Updated for PC-LINUX-64BIT-GFORTRAN. */
230 
231 /* -    SPICELIB Version 1.14.0, 13-MAY-2010 (BVS) */
232 
233 /*        Updated for PC-64BIT-MS_C. */
234 
235 /* -    SPICELIB Version 1.13.0, 13-MAY-2010 (BVS) */
236 
237 /*        Updated for MAC-OSX-64BIT-INTEL_C. */
238 
239 /* -    SPICELIB Version 1.12.0, 13-MAY-2010 (BVS) */
240 
241 /*        Updated for MAC-OSX-64BIT-IFORT. */
242 
243 /* -    SPICELIB Version 1.11.0, 13-MAY-2010 (BVS) */
244 
245 /*        Updated for MAC-OSX-64BIT-GFORTRAN. */
246 
247 /* -    SPICELIB Version 1.10.0, 18-MAR-2009 (BVS) */
248 
249 /*        Updated for PC-LINUX-GFORTRAN. */
250 
251 /* -    SPICELIB Version 1.9.0, 18-MAR-2009 (BVS) */
252 
253 /*        Updated for MAC-OSX-GFORTRAN. */
254 
255 /* -    SPICELIB Version 1.8.0, 19-FEB-2008 (BVS) */
256 
257 /*        Updated for PC-LINUX-IFORT. */
258 
259 /* -    SPICELIB Version 1.7.0, 14-NOV-2006 (BVS) */
260 
261 /*        Updated for PC-LINUX-64BIT-GCC_C. */
262 
263 /* -    SPICELIB Version 1.6.0, 14-NOV-2006 (BVS) */
264 
265 /*        Updated for MAC-OSX-INTEL_C. */
266 
267 /* -    SPICELIB Version 1.5.0, 14-NOV-2006 (BVS) */
268 
269 /*        Updated for MAC-OSX-IFORT. */
270 
271 /* -    SPICELIB Version 1.4.0, 14-NOV-2006 (BVS) */
272 
273 /*        Updated for PC-WINDOWS-IFORT. */
274 
275 /* -    SPICELIB Version 1.3.0, 26-OCT-2005 (BVS) */
276 
277 /*        Updated for SUN-SOLARIS-64BIT-GCC_C. */
278 
279 /* -    SPICELIB Version 1.2.0, 03-JAN-2005 (BVS) */
280 
281 /*        Updated for PC-CYGWIN_C. */
282 
283 /* -    SPICELIB Version 1.1.0, 03-JAN-2005 (BVS) */
284 
285 /*        Updated for PC-CYGWIN. */
286 
287 /* -    SPICELIB Version 1.0.1, 17-JUL-2002 */
288 
289 /*        Added MAC-OSX environments. */
290 
291 /* -    SPICELIB Version 1.0.0, 07-NOV-2001 */
292 
293 /* -& */
294 
295 /*     Unit and file table size parameters. */
296 
297 /*     FTSIZE     is the maximum number of files (DAS and DAF) that a */
298 /*                user may have open simultaneously. */
299 
300 
301 /*     RSVUNT     is the number of units protected from being locked */
302 /*                to a particular handle by ZZDDHHLU. */
303 
304 
305 /*     SCRUNT     is the number of units protected for use by scratch */
306 /*                files. */
307 
308 
309 /*     UTSIZE     is the maximum number of logical units this manager */
310 /*                will utilize at one time. */
311 
312 
313 /*     Access method enumeration.  These parameters are used to */
314 /*     identify which access method is associated with a particular */
315 /*     handle.  They need to be synchronized with the STRAMH array */
316 /*     defined in ZZDDHGSD in the following fashion: */
317 
318 /*        STRAMH ( READ   ) = 'READ' */
319 /*        STRAMH ( WRITE  ) = 'WRITE' */
320 /*        STRAMH ( SCRTCH ) = 'SCRATCH' */
321 /*        STRAMH ( NEW    ) = 'NEW' */
322 
323 /*     These values are used in the file table variable FTAMH. */
324 
325 
326 /*     Binary file format enumeration.  These parameters are used to */
327 /*     identify which binary file format is associated with a */
328 /*     particular handle.  They need to be synchronized with the STRBFF */
329 /*     array defined in ZZDDHGSD in the following fashion: */
330 
331 /*        STRBFF ( BIGI3E ) = 'BIG-IEEE' */
332 /*        STRBFF ( LTLI3E ) = 'LTL-IEEE' */
333 /*        STRBFF ( VAXGFL ) = 'VAX-GFLT' */
334 /*        STRBFF ( VAXDFL ) = 'VAX-DFLT' */
335 
336 /*     These values are used in the file table variable FTBFF. */
337 
338 
339 /*     Some random string lengths... more documentation required. */
340 /*     For now this will have to suffice. */
341 
342 
343 /*     Architecture enumeration.  These parameters are used to identify */
344 /*     which file architecture is associated with a particular handle. */
345 /*     They need to be synchronized with the STRARC array defined in */
346 /*     ZZDDHGSD in the following fashion: */
347 
348 /*        STRARC ( DAF ) = 'DAF' */
349 /*        STRARC ( DAS ) = 'DAS' */
350 
351 /*     These values will be used in the file table variable FTARC. */
352 
353 
354 /*     For the following environments, record length is measured in */
355 /*     characters (bytes) with eight characters per double precision */
356 /*     number. */
357 
358 /*     Environment: Sun, Sun FORTRAN */
359 /*     Source:      Sun Fortran Programmer's Guide */
360 
361 /*     Environment: PC, MS FORTRAN */
362 /*     Source:      Microsoft Fortran Optimizing Compiler User's Guide */
363 
364 /*     Environment: Macintosh, Language Systems FORTRAN */
365 /*     Source:      Language Systems FORTRAN Reference Manual, */
366 /*                  Version 1.2, page 12-7 */
367 
368 /*     Environment: PC/Linux, g77 */
369 /*     Source:      Determined by experiment. */
370 
371 /*     Environment: PC, Lahey F77 EM/32 Version 4.0 */
372 /*     Source:      Lahey F77 EM/32 Language Reference Manual, */
373 /*                  page 144 */
374 
375 /*     Environment: HP-UX 9000/750, FORTRAN/9000 Series 700 computers */
376 /*     Source:      FORTRAN/9000 Reference-Series 700 Computers, */
377 /*                  page 5-110 */
378 
379 /*     Environment: NeXT Mach OS (Black Hardware), */
380 /*                  Absoft Fortran Version 3.2 */
381 /*     Source:      NAIF Program */
382 
383 
384 /*     The following parameter defines the size of a string used */
385 /*     to store a filenames on this target platform. */
386 
387 
388 /*     The following parameter controls the size of the character record */
389 /*     buffer used to read data from non-native files. */
390 
391 /* $ Brief_I/O */
392 
393 /*     Variable  I/O  Entry */
394 /*     --------  ---  -------------------------------------------------- */
395 /*     HANDLE     I   DAFBNA, DAFCAD */
396 /*     SUM        I   DAFBNA */
397 /*     NAME       I   DAFBNA */
398 /*     DATA       I   DAFADA */
399 /*     N          I   DAFADA */
400 /*     TBSIZE     P   DAFANA */
401 
402 /* $ Detailed_Input */
403 
404 /*     HANDLE      is the handle of a DAF opened for write access */
405 /*                 by a previous call to DAFOPW or DAFOPN. */
406 
407 /*     SUM         is the summary for the array being added. */
408 
409 /*     NAME        is the name of the array being added. */
410 
411 /*     DATA        contains all or part of the data in the array. */
412 
413 /*     N           is the number of elements in DATA. */
414 
415 /* $ Detailed_Output */
416 
417 /*     None. */
418 
419 /* $ Parameters */
420 
421 /*     TBSIZE      is the size of the file table maintained internally */
422 /*                 by DAFANA,  TBSIZE is the maximum number of DAFs */
423 /*                 that can be in use simultaneously by this routine. */
424 
425 /* $ Files */
426 
427 /*     See argument HANDLE, above. */
428 
429 /* $ Exceptions */
430 
431 /*     1) If DAFANA is called directly, the error SPICE(BOGUSENTRY) */
432 /*        is signalled. */
433 
434 /*     2) See entry points DAFBNA, DAFADA, DAFENA, and DAFCAD */
435 /*        for exceptions specific to those entry points. */
436 
437 /* $ Particulars */
438 
439 /*     DAFANA serves as an umbrella, allowing data to be shared by its */
440 /*     entry points: */
441 
442 /*        DAFBNA         Begin new array. */
443 /*        DAFADA         Add data to array. */
444 /*        DAFCAD         Continue adding data. */
445 /*        DAFENA         End new array. */
446 
447 /*     The main function of these entry points is to simplify the */
448 /*     addition of new arrays to existing DAFs. */
449 
450 /*     An application can add data to a single DAF, or to multiple DAFs, */
451 /*     simultaneously.  In the case of writing to a single DAF, the */
452 /*     creation of a new array requires four steps: */
453 
454 /*        1) Open a DAF for write access, using either DAFOPW */
455 /*           (if the file already exists) or DAFOPN (if it does not). */
456 
457 /*              CALL DAFOPW ( FNAME, HANDLE ) */
458 
459 /*        2) Begin the new DAF by calling DAFBNA, */
460 
461 /*              CALL DAFBNA ( HANDLE, SUM, NAME ) */
462 
463 /*        3) Add data to the array by calling DAFADA as many times */
464 /*           as necessary, */
465 
466 /*              CALL GET_DATA ( DATA, N, FOUND ) */
467 
468 /*              DO WHILE ( FOUND ) */
469 /*                 CALL DAFADA   ( DATA, N        ) */
470 /*                 CALL GET_DATA ( DATA, N, FOUND ) */
471 /*              END DO */
472 
473 /*        4) End the array by calling DAFENA, */
474 
475 /*              CALL DAFENA */
476 
477 /*     Note that the data can be added in chunks of any size, so long */
478 /*     as the chunks are ordered correctly. */
479 
480 /*     In applications that add data to multiple DAFs simultaneously, it */
481 /*     is necessary to specify which DAF to add data to.  The DAFANA */
482 /*     entry points that allow specification of a DAF via a file handle */
483 /*     argument are DAFBNA (DAF, begin new array) and DAFCAD (DAF, */
484 /*     continue adding data).  As in the single-DAF case, arrays are */
485 /*     started by calls to DAFBNA, and data is added to arrays by calls */
486 /*     to DAFADA.  The last DAF designated by the input file handle */
487 /*     supplied to DAFBNA or DAFCAD is the `current DAF'.  If a */
488 /*     DAF contains an array started by a call to DAFBNA but not yet */
489 /*     completed by a call to DAFENA, we call this array the `current */
490 /*     array' for that DAF.  Each call to DAFADA will add data to the */
491 /*     current array in the current DAF.  A call to DAFENA will make the */
492 /*     current array in the current DAF a permanent addition to that DAF. */
493 
494 /*     The notion of `current DAF' as discussed here applies only to */
495 /*     DAFs acted upon by entry points of DAFANA.  In DAFFA, there is a */
496 /*     DAF that is treated as the `current DAF' for searching; there is */
497 /*     no connection between the DAFs regarded as current by DAFANA and */
498 /*     DAFFA. */
499 
500 /*     In the following example, we write data obtained from the routine */
501 /*     GET_DATA into two separate DAFs.  The first N/2 elements of the */
502 /*     array DATA will be written to the first DAF; the rest of the */
503 /*     array will be written to the second DAF. */
504 
505 
506 /*        1) Open the DAFs for write access, using either DAFOPW */
507 /*           (if the files already exist) or DAFOPN (if they do not). */
508 
509 /*              CALL DAFOPW ( FNAME1, HANDL1 ) */
510 /*              CALL DAFOPW ( FNAME2, HANDL2 ) */
511 
512 /*        2) Begin the new DAFs by calling DAFBNA, */
513 
514 /*              CALL DAFBNA ( HANDL1, SUM1, NAME1 ) */
515 /*              CALL DAFBNA ( HANDL2, SUM2, NAME2 ) */
516 
517 /*        3) Add data to the arrays by calling DAFCAD and DAFADA as many */
518 /*           times as necessary, selecting the file to add data to by */
519 /*           calling DAFCAD: */
520 
521 /*              CALL GET_DATA ( DATA, N, FOUND ) */
522 
523 /*              DO WHILE ( FOUND ) */
524 
525 /*                 CALL DAFCAD   ( HANDL1                          ) */
526 /*                 CALL DAFADA   ( DATA,               N/2         ) */
527 
528 /*                 CALL DAFCAD   ( HANDL2                          ) */
529 /*                 CALL DAFADA   ( DATA( N/2 + 1 ),    N - N/2     ) */
530 
531 /*                 CALL GET_DATA ( DATA, N, FOUND ) */
532 
533 /*              END DO */
534 
535 /*        4) End each array by calling DAFENA, selecting the file */
536 /*           in which to end the array by calling DAFCAD: */
537 
538 /*              CALL DAFCAD ( HANDL1 ) */
539 /*              CALL DAFENA */
540 
541 /*              CALL DAFCAD ( HANDL2 ) */
542 /*              CALL DAFENA */
543 
544 
545 /* $ Examples */
546 
547 /*     1)  The following code fragment illustrates one possible way */
548 /*         to copy an array from one DAF (with handle ORIGIN) to another */
549 /*         (with handle COPY), SIZE words at a time. */
550 
551 /*            CALL DAFGS  ( SUM  ) */
552 /*            CALL DAFGN  ( NAME ) */
553 /*            CALL DAFHSF ( ORIGIN, ND, NI ) */
554 /*            CALL DAFUS  ( SUM,    ND, NI, DC, IC ) */
555 
556 /*            BEGIN = IC(NI-1) */
557 /*            END   = IC(NI  ) */
558 
559 /*            CALL DAFBNA ( COPY, SUM, NAME ) */
560 
561 /*            DO WHILE ( BEGIN .LE. END ) */
562 /*               CHUNK = MIN ( BEGIN + SIZE - 1, END ) */
563 
564 /*               CALL DAFRDA ( ORIGIN, BEGIN, CHUNK, DATA ) */
565 /*               CALL DAFADA ( DATA,   SIZE ) */
566 
567 /*               BEGIN = BEGIN + SIZE */
568 /*            END DO */
569 
570 /*            CALL DAFENA */
571 
572 
573 /*     2)  A simple example demonstrating simultaneous addition */
574 /*         of data to multiple DAFs.  We read data from a text */
575 /*         file containing three columns of numbers, and we write */
576 /*         the data from each column out to a separate DAF.  The */
577 /*         format of the input text file is as follows: */
578 
579 /*            +-                   -+ */
580 /*            |  n11    n12    n13  | */
581 /*            |  n21    n22    n23  | */
582 /*            |   .      .      .   | */
583 /*            |   .      .      .   | */
584 /*            |   .      .      .   | */
585 /*            +-                   -+ */
586 
587 /*         Here the symbol nij indicates the jth number on the ith line */
588 /*         of the file. */
589 
590 /*         The delimiters between the numbers in each column may be */
591 /*         commas or blanks. */
592 
593 /*         The input file is called NUMBERS.TXT.  The output files are */
594 /*         called */
595 
596 /*            COLUMN1.DAF */
597 /*            COLUMN2.DAF */
598 /*            COLUMN3.DAF */
599 
600 /*         To confirm that the DAFs created by this program contain the */
601 /*         correct contents, we will read the data from each DAF and */
602 /*         combine it to create a new text file call RESULT.TXT.  This */
603 /*         file should contain the same data as NUMBERS.TXT.  If */
604 /*         RESULT.TXT is copied as NUMBERS.TXT and used as the input for */
605 /*         a second run of this program, the output file RESULT.TXT */
606 /*         from the second program run should match, up to round-off */
607 /*         error in the numbers, the input file NUMBERS.TXT containing */
608 /*         the output of the first program run.  If the numbers in */
609 /*         NUMBERS.TXT are integers, the match should be exact. */
610 
611 
612 /*                  PROGRAM WRTDAF */
613 /*            C */
614 /*            C     Read columns of d.p. numbers from a text file */
615 /*            C     and write the data from each column into a */
616 /*            C     separate DAF.  Read these DAFs and create a */
617 /*            C     second text file containing the same data as */
618 /*            C     the input text file. */
619 /*            C */
620 /*            C     Since we do not need to retain any descriptive */
621 /*            C     information about the DAFs inside of the files */
622 /*            C     themselves, we'll use a summary format having */
623 /*            C     two integer components (the minimum--these are */
624 /*            C     reserved for use by the DAF routines) and zero */
625 /*            C     double precision components. */
626 /*            C */
627 /*            C     The internal file names and array names will */
628 /*            C     simply indicate the data sources. */
629 /*            C */
630 
631 /*            C */
632 /*            C     Local parameters */
633 /*            C */
634 /*                  INTEGER               FNMLEN */
635 /*                  PARAMETER           ( FNMLEN = 20 ) */
636 
637 /*                  INTEGER               LINLEN */
638 /*                  PARAMETER           ( LINLEN = 80 ) */
639 
640 /*                  INTEGER               MAXCOL */
641 /*                  PARAMETER           ( MAXCOL =  3 ) */
642 
643 /*                  INTEGER               ND */
644 /*                  PARAMETER           ( ND     =  0 ) */
645 
646 /*                  INTEGER               NDAF */
647 /*                  PARAMETER           ( NDAF   =  3 ) */
648 
649 /*                  INTEGER               NI */
650 /*                  PARAMETER           ( NI     =  2 ) */
651 
652 /*                  INTEGER               NUMLEN */
653 /*                  PARAMETER           ( NUMLEN = 30 ) */
654 
655 /*                  INTEGER               SIG */
656 /*                  PARAMETER           ( SIG    = 14 ) */
657 
658 /*            C */
659 /*            C     Local variables */
660 /*            C */
661 /*                  CHARACTER*(FNMLEN)    DAF    ( NDAF   ) */
662 /*                  CHARACTER*(FNMLEN)    INFILE */
663 /*                  CHARACTER*(LINLEN)    LINE */
664 /*                  CHARACTER*(NUMLEN)    NUMCH  ( MAXCOL ) */
665 /*                  CHARACTER*(LINLEN)    PRSERR */
666 /*                  CHARACTER*(FNMLEN)    RESULT */
667 
668 /*                  DOUBLE PRECISION      DC     ( 1      ) */
669 /*                  DOUBLE PRECISION      NUMBER ( MAXCOL ) */
670 /*                  DOUBLE PRECISION      SUMMRY ( 1      ) */
671 
672 /*                  INTEGER               FA */
673 /*                  INTEGER               HAN    ( NDAF   ) */
674 /*                  INTEGER               I */
675 /*                  INTEGER               IA */
676 /*                  INTEGER               IC     ( NI     ) */
677 /*                  INTEGER               J */
678 /*                  INTEGER               LENGTH */
679 /*                  INTEGER               NCOLS */
680 /*                  INTEGER               PTR */
681 
682 /*                  LOGICAL               EOF */
683 /*                  LOGICAL               FOUND */
684 
685 /*            C */
686 /*            C     Initial values */
687 /*            C */
688 /*                  DATA   DAF     /  'COLUMN1.DAF', */
689 /*                 .                  'COLUMN2.DAF', */
690 /*                 .                  'COLUMN3.DAF'  / */
691 
692 /*                  DATA   INFILE  /  'NUMBERS.TXT'  / */
693 /*                  DATA   RESULT  /  'RESULT.TXT'   / */
694 
695 
696 /*            C */
697 /*            C     Use SPICELIB call tracing. */
698 /*            C */
699 /*                  CALL CHKIN ( 'WRTDAF' ) */
700 
701 /*            C */
702 /*            C     Create the new DAFs, and start a new array in each */
703 /*            C     one.  Just use the file name for the internal file */
704 /*            C     name and array name, for each DAF.  No assignments */
705 /*            C     are required for the array summaries. */
706 /*            C */
707 /*                  DO I = 1, 3 */
708 /*                     CALL DAFOPN ( DAF(I), ND, NI, DAF(I), 0, HAN(I) ) */
709 /*                     CALL DAFBNA ( HAN(I), SUMMRY, DAF(I)            ) */
710 /*                  END DO */
711 
712 /*            C */
713 /*            C     Now read numbers from the text file, line by line, */
714 /*            C     and add the numbers from each column to the */
715 /*            C     corresponding DAF. */
716 /*            C */
717 /*                  CALL RDTEXT ( INFILE, LINE, EOF ) */
718 
719 /*                  DO WHILE ( .NOT. EOF ) */
720 /*            C */
721 /*            C        Parse the numbers in the input line.  They */
722 /*            C        may be separated by commas or blanks (the second */
723 /*            C        argument of LPARSM is a list of allowed */
724 /*            C        delimiters).  Parse the strings found by LPARSM. */
725 /*            C */
726 /*            C        For brevity, we won't check the number of columns */
727 /*            C        found, or the parse error flag. */
728 /*            C */
729 /*                     CALL LPARSM ( LINE, ' ,', MAXCOL, NCOLS, NUMCH ) */
730 
731 /*                     DO I = 1, NCOLS */
732 /*                        CALL NPARSD ( NUMCH(I), NUMBER(I), PRSERR, PTR) */
733 /*                     END DO */
734 
735 /*            C */
736 /*            C        Add the number from the ith column to the array */
737 /*            C        in the ith DAF.  We'll use DAFCAD to select */
738 /*            C        the correct DAF to add data to. */
739 /*            C */
740 /*                     DO I = 1, NDAF */
741 /*                        CALL DAFCAD ( HAN(I)       ) */
742 /*                        CALL DAFADA ( NUMBER(I), 1 ) */
743 /*                     END DO */
744 
745 /*            C */
746 /*            C        Get the next line. */
747 /*            C */
748 /*                     CALL RDTEXT ( INFILE, LINE, EOF ) */
749 
750 /*                  END DO */
751 
752 /*            C */
753 /*            C     Finish (`end') the arrays.  Again, we'll use DAFCAD */
754 /*            C     to select the DAFs in which the arrays are to be */
755 /*            C     finished.  After finishing each array, close the DAF */
756 /*            C     containing it. */
757 /*            C */
758 /*                  DO I = 1, NDAF */
759 /*                     CALL DAFCAD ( HAN(I) ) */
760 /*                     CALL DAFENA */
761 /*                     CALL DAFCLS ( HAN(I) ) */
762 /*                  END DO */
763 
764 /*            C */
765 /*            C     Now for the verification step.  We'll try to */
766 /*            C     build a text file containing the same data as */
767 /*            C     the orginal input file.  The format of the numbers, */
768 /*            C     the delimiters separating the numbers, spacing, and */
769 /*            C     non-printing characters may differ.  However, if this */
770 /*            C     file is used as the input file, and if the numbers */
771 /*            C     used in the file are integers, WRTDAF will create an */
772 /*            C     exact copy of it. */
773 /*            C */
774 
775 /*            C */
776 /*            C     Open the DAFs for reading. */
777 /*            C */
778 /*                  DO I = 1, NDAF */
779 /*                     CALL DAFOPR ( DAF(I), HAN(I) ) */
780 /*                  END DO */
781 
782 /*            C */
783 /*            C     Obtain the start and end addresses of the */
784 /*            C     data in each DAF.  To do this, we'll need to */
785 /*            C     obtain and unpack the array summaries. */
786 /*            C */
787 /*            C     If all went well, the addresses should be the */
788 /*            C     same for each DAF.  We'll assume that the initial */
789 /*            C     and final addresses in the first DAF are correct */
790 /*            C     for all three. */
791 /*            C */
792 /*                  CALL DAFBFS ( HAN(1) ) */
793 /*                  CALL DAFFNA ( FOUND  ) */
794 /*                  CALL DAFGS  ( SUMMRY ) */
795 /*                  CALL DAFUS  ( SUMMRY, ND, NI, DC, IC ) */
796 
797 /*                  IA      =  IC( NI-1 ) */
798 /*                  FA      =  IC( NI   ) */
799 /*                  LENGTH  =  FA - IA + 1 */
800 
801 /*            C */
802 /*            C     Now read numbers from the DAFs and build up */
803 /*            C     lines of text.  Write these lines out to our */
804 /*            C     output text file. */
805 /*            C */
806 /*                  DO I = 0,  LENGTH - 1 */
807 
808 /*                     LINE = ' ' */
809 
810 /*                     DO J = 1, NDAF */
811 /*                        CALL DAFRDA ( HAN(J),    IA+I, IA+I, NUMBER(J)) */
812 /*                        CALL DPSTR  ( NUMBER(J), SIG,        NUMCH(J) ) */
813 /*                        CALL SUFFIX ( NUMCH(J),  5,          LINE     ) */
814 /*                     END DO */
815 
816 /*                     CALL WRLINE ( RESULT, LINE ) */
817 
818 /*                  END DO */
819 
820 /*            C */
821 /*            C     Close the output text file and the DAFs. */
822 /*            C */
823 /*                  CALL CLLINE ( RESULT ) */
824 
825 /*                  DO I = 1, NDAF */
826 /*                     CALL DAFCLS( HAN(I) ) */
827 /*                  END DO */
828 
829 /*                  END */
830 
831 
832 /* $ Restrictions */
833 
834 /*     None. */
835 
836 /* $ Literature_References */
837 
838 /*     NAIF Document 167.0, "Double Precision Array Files (DAF) */
839 /*     Specification and User's Guide" */
840 
841 /* $ Author_and_Institution */
842 
843 /*     N.J. Bachman    (JPL) */
844 /*     W.L. Taber      (JPL) */
845 /*     I.M. Underwood  (JPL) */
846 
847 /* $ Version */
848 
849 /* -    SPICELIB Version 3.0.0, 16-NOV-2001 (FST) */
850 
851 /*        Updated the entry points of DAFANA to enable its */
852 /*        internal state table size, TBSIZE, to be smaller */
853 /*        than the file table maintained by DAFAH: FTSIZE. */
854 
855 /* -    SPICELIB Version 2.1.0, 11-JUL-1995 (KRG) */
856 
857 /*        Updated to remove potential compiler warnings from the */
858 /*        truncation of double precision numbers to integers. */
859 
860 /*        Also changed was a numeric constant from 1.D0 to the */
861 /*        equivalent, but more aesthetically pleasing 1.0D0. */
862 
863 /* -    SPICELIB Version 2.0.1, 10-MAR-1992 (WLT) */
864 
865 /*        Comment section for permuted index source lines was added */
866 /*        following the header. */
867 
868 /* -    SPICELIB Version 2.0.0, 04-SEP-1991 (NJB) (WLT) */
869 
870 /*        Updated to support simultaneous writes to multiple DAFs. */
871 /*        The $Examples section of this routine now illustrates */
872 /*        usage of the routine DAFCAD. */
873 
874 /* -    SPICELIB Version 1.0.1, 22-MAR-1990 (HAN) */
875 
876 /*        Literature references added to the header. */
877 
878 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
879 
880 /* -& */
881 /* $ Index_Entries */
882 
883 /*     add new daf array */
884 
885 /* -& */
886 /* $ Revisions */
887 
888 /* -    SPICELIB Version 3.0.0, 16-NOV-2001 (FST) */
889 
890 /*        This umbrella and its entry points were updated to */
891 /*        work properly with the changes in the DAF system as */
892 /*        a result of its utilization of the new handle manager. */
893 
894 /*        Since DAFAH now tracks FTSIZE files as defined in */
895 /*        the include file 'zzddhman.inc', it was decided that */
896 /*        in the interest of releasing the toolkit this module */
897 /*        would undergo simple changes.  As such most previous */
898 /*        references to FTSIZE in this umbrella have been replaced */
899 /*        with TBSIZE where appropriate.  DAFBNA now signals an */
900 /*        error if there is not enough room to add a new DAF's */
901 /*        dossier to the state table.  Also, after attempting to */
902 /*        clean up all files listed in the state table that are */
903 /*        not currently open, DAFBNA attempts to locate the */
904 /*        first dossier with STADDG set to FALSE.  This is then */
905 /*        freed to make room for the new DAF.  If DAFBNA fails */
906 /*        to locate such a dossier in the state table, it */
907 /*        signals the error SPICE(STFULL). */
908 
909 /*        The parameter FILEN was removed, as it is defined */
910 /*        on an environmental basis in the include file */
911 /*        'zzddhman.inc'. */
912 
913 
914 /* -    SPICELIB Version 2.1.0, 11-JUL-1995 (KRG) */
915 
916 /*        Updated to remove potential compiler warnings from the */
917 /*        truncation of double precision numbers to integers. Two */
918 /*        assignments to NARRAY were updated, being changed from: */
919 
920 /*           NARRAY = SUMREC(ARYCNT) */
921 
922 /*        to */
923 
924 /*           NARRAY = IDINT ( SUMREC(ARYCNT) ) */
925 
926 /*        Also changed was a numeric constant from 1.D0 to the */
927 /*        equivalent, but more aesthetically pleasing 1.0D0. */
928 
929 /* -    SPICELIB Version 2.0.0, 04-SEP-1991 (NJB) (WLT) */
930 
931 /*        Updated to support simultaneous writes to multiple DAFs. */
932 
933 /*        In previous versions of DAFANA, data could be added to only */
934 /*        one DAF array at a time.  In fact, DAFAH allowed only one */
935 /*        DAF to be open for writing at any time.  Therefore, there was */
936 /*        no question about which DAF was being operated on by either of */
937 /*        the DAFANA entry points that don't accept file handles as */
938 /*        input arguments:  DAFADA and DAFENA.  In the current version */
939 /*        of DAFANA, the entry points that don't accept file handles as */
940 /*        inputs operate on the `current DAF'.  The current DAF is the */
941 /*        last one in which a new array was started by DAFBNA, or in */
942 /*        which addition of data to an array was continued by the new */
943 /*        entry point DAFCAD.  DAFCAD was added to allow users to set */
944 /*        the current DAF, so that additions of data to arrays in */
945 /*        multiple DAFs can be interleaved. */
946 
947 /*        Note that the notion of `current DAF' as discussed here applies */
948 /*        only to DAFs acted upon by entry points of DAFANA.  In DAFFA, */
949 /*        there is a DAF that is treated as the `current DAF' for */
950 /*        searching; there is no connection between the DAFs regarded */
951 /*        as current by DAFANA and DAFFA. */
952 
953 /*        The two principal changes to DAFANA are the addition of the */
954 /*        new entry point DAFCAD, and the addition of a data structure */
955 /*        called the `state table'.  The state table is a collection of */
956 /*        parallel arrays that maintain information about the state */
957 /*        of each data addition that is currently in progress.  The */
958 /*        state table arrays are indexed by a singly linked list pool; */
959 /*        this mechanism allows addition and deletion of information */
960 /*        about data additions without requiring movement of data */
961 /*        already in the state table. */
962 
963 /*        The linked list pool contains an `active' list and a `free' */
964 /*        list. Nodes in the active list are used to index elements of */
965 /*        the state table where information about additions in progress */
966 /*        is stored.  The head node of the active list is of particular */
967 /*        significance:  the state information pointed to by this node */
968 /*        is that of the current DAF.  Nodes in the free list index */
969 /*        elements of the state table that are available for use. */
970 
971 /*        When an array is started in a DAF that is not already `known' */
972 /*        to DAFANA, information about the DAF is added to the state */
973 /*        table.  If there are no free elements in the state table, */
974 /*        the routine starting the array (DAFBNA) will perform garbage */
975 /*        collection:  the routine will test the handles of each file */
976 /*        about which information in stored in the state table to see */
977 /*        whether that file is still open.  Nodes containing information */
978 /*        about DAFs that are no longer open will be moved to the free */
979 /*        list. */
980 
981 /*        Whenever a DAF becomes the current DAF, the linked list */
982 /*        that indexes the state table is adjusted so that the node */
983 /*        pointing to information about the current DAF is at the head */
984 /*        of the active list.  This way, a slight efficiency is gained */
985 /*        when repeated data additions are made to the same DAF, since */
986 /*        the linear search through the state table for information on */
987 /*        that DAF will be shortened. */
988 
989 /*        Since the algorithms for maintenance of linked lists are well */
990 /*        known, they are not documented here.  However, see the */
991 /*        internals of the SPICELIB routine SPKBSR for a nice diagram */
992 /*        describing a similar data structure. */
993 
994 /*        The state table contains two arrays that are quite large: */
995 /*        there are buffers that contain the name and array summary for */
996 /*        each array under construction.   A parallel situation exists */
997 /*        in DAFFA, where there are buffers that contain the last */
998 /*        character record and summary record read from each DAF.  The */
999 /*        total storage required for these arrays (in DAFANA and DAFFA */
1000 /*        together) is 4000 * TBSIZE bytes.  For this reason, it may be */
1001 /*        a good idea to reduce the value of TBSIZE in SPICELIB versions */
1002 /*        for machines where memory is scarce. */
1003 
1004 /*        On a completely different topic:  the local declarations in */
1005 /*        DAFANA have been alphabetized and separated by type, except */
1006 /*        for those relating to the state table.  Several hard-coded */
1007 /*        constants have been replaced by parameters. */
1008 /* -& */
1009 
1010 /*     SPICELIB functions */
1011 
1012 
1013 /*     Local parameters */
1014 
1015 
1016 /*     Local variables */
1017 
1018 
1019 /*     State variables. */
1020 
1021 /*     These variables define the state of each DAF to which data */
1022 /*     is currently being added.  For each DAF that we're writing to, we */
1023 /*     maintain a copy of: */
1024 
1025 /*        STFH           File handle. */
1026 
1027 /*        STIFNM         Internal file name. */
1028 
1029 /*        STADDG         (`State table: adding') Flag indicating */
1030 /*                       whether addition of data to an array is in */
1031 /*                       progress. */
1032 
1033 /*        STFRST         Record number of initial summary record. */
1034 
1035 /*        STLAST         Record number of final summary record. */
1036 
1037 /*        STBEGN         Beginning address of new array. */
1038 
1039 /*        STFREE         Address of next free word. */
1040 
1041 /*        STLSUM         Local copy of the array summary for the current */
1042 /*                       array. */
1043 
1044 /*        STNAME         Local copy of the array name for the current */
1045 /*                       array. */
1046 
1047 
1048 /*     These variables are maintained in a table of parallel arrays; */
1049 /*     the size of the table is TBSIZE. */
1050 
1051 
1052 
1053 /*     The table of state variables is indexed by a singly linked list */
1054 /*     of pointers.  This mechanism avoids the work of moving */
1055 /*     the state variable data about as information about DAFs is */
1056 /*     added to or deleted from the table. */
1057 
1058 /*     The structure containing the linked list pointers is called a */
1059 /*     `pool.'  The pool contains a list of `active' nodes and a list */
1060 /*     of free nodes.  The head nodes of the active and free lists are */
1061 /*     maintained as the variables STHEAD (`state table head') and */
1062 /*     STFPTR (`state table free pointer'), respectively.  Every node in */
1063 /*     the pool is on exactly one of these lists. */
1064 
1065 
1066 /*     The pool starts out with all of the nodes on the free list. */
1067 /*     DAFBNA initializes the pool.  As new DAFs are written to, */
1068 /*     DAFBNA adds information about them to the state table.  Every */
1069 /*     time a DAF array is started by DAFBNA, or selected for */
1070 /*     continuation by DAFCAD, the routine in question `moves' the */
1071 /*     DAF's state information to the head of the active list, if the */
1072 /*     state information is not already there.  This re-organization is */
1073 /*     accomplished by deleting the node for the DAF from its current */
1074 /*     position in the active list and inserting the node at the head of */
1075 /*     the list.  Thus, the change is made merely by setting pointers, */
1076 /*     not by moving chunks of data in the state table. */
1077 
1078 /*     It may happen that there is no room left in the state table */
1079 /*     to accommodate information about a new DAF.  In this case, */
1080 /*     garbage collection must be performed:  DAFBNA frees all nodes in */
1081 /*     the table that index DAFs that are not currently open. */
1082 
1083 /*     Note that the routine DAFADA does not modify the state table; it */
1084 /*     merely adds data to the DAF that is at the head of the active */
1085 /*     list. */
1086 
1087 
1088 /*     Other local variables */
1089 
1090 
1091 /*     Save everything between calls */
1092 
1093 
1094 /*     Initial values */
1095 
1096     /* Parameter adjustments */
1097     if (sum) {
1098 	}
1099     if (data) {
1100 	}
1101 
1102     /* Function Body */
1103     switch(n__) {
1104 	case 1: goto L_dafbna;
1105 	case 2: goto L_dafada;
1106 	case 3: goto L_dafena;
1107 	case 4: goto L_dafcad;
1108 	}
1109 
1110 
1111 /*     Standard SPICE error handling. */
1112 
1113     if (return_()) {
1114 	return 0;
1115     } else {
1116 	chkin_("DAFANA", (ftnlen)6);
1117 	sigerr_("SPICE(BOGUSENTRY)", (ftnlen)17);
1118 	chkout_("DAFANA", (ftnlen)6);
1119     }
1120     return 0;
1121 /* $Procedure DAFBNA ( DAF, begin new array ) */
1122 
1123 L_dafbna:
1124 /* $ Abstract */
1125 
1126 /*     Begin a new array in a DAF. */
1127 
1128 /* $ Disclaimer */
1129 
1130 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
1131 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
1132 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
1133 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
1134 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
1135 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
1136 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
1137 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
1138 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
1139 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
1140 
1141 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
1142 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
1143 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
1144 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
1145 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
1146 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
1147 
1148 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
1149 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
1150 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
1151 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
1152 
1153 /* $ Required_Reading */
1154 
1155 /*     DAF */
1156 
1157 /* $ Keywords */
1158 
1159 /*     FILES */
1160 
1161 /* $ Declarations */
1162 
1163 /*     INTEGER               HANDLE */
1164 /*     DOUBLE PRECISION      SUM     ( * ) */
1165 /*     CHARACTER*(*)         NAME */
1166 
1167 /* $ Brief_I/O */
1168 
1169 /*     Variable  I/O  Entry */
1170 /*     --------  ---  -------------------------------------------------- */
1171 /*     HANDLE     I   Handle of DAF. */
1172 /*     SUM        I   Summary of new array. */
1173 /*     NAME       I   Name of new array. */
1174 
1175 /* $ Detailed_Input */
1176 
1177 /*     HANDLE      is the handle of a DAF opened for write access */
1178 /*                 by a previous call to DAFOPW or DAFOPN. */
1179 
1180 /*     SUM         is the summary of a new array to be added to the */
1181 /*                 specified file. The addresses (the final two integer */
1182 /*                 components) need not be filled in. */
1183 
1184 /*     NAME        is the name of the new array. */
1185 
1186 /* $ Detailed_Output */
1187 
1188 /*     None. */
1189 
1190 /* $ Parameters */
1191 
1192 /*      None. */
1193 
1194 /* $ Files */
1195 
1196 /*     See argument HANDLE, above. */
1197 
1198 /* $ Exceptions */
1199 
1200 /*     1) If the input handle is not that of a DAF that is open */
1201 /*        for writing, the error is diagnosed by routines called by */
1202 /*        this routine.  These files are implicitly of the native */
1203 /*        binary file format. */
1204 
1205 /*     2) If the input array name is too long to fit in the number */
1206 /*        of characters allowed by the summary format of the DAF */
1207 /*        designated by HANDLE, the excess characters are truncated. */
1208 /*        No error is signalled. */
1209 
1210 /*     3) If there is not enough room in the state table to add */
1211 /*        the DAF associated with HANDLE, the error SPICE(STFULL) */
1212 /*        is signaled. */
1213 
1214 /* $ Particulars */
1215 
1216 /*     Only one array can be added to a DAF at any one time, so */
1217 /*     calling DAFBNA cancels any addition to the file specified */
1218 /*     by HANDLE that may be in progress. No warning is issued. */
1219 
1220 /* $ Examples */
1221 
1222 /*     See DAFANA. */
1223 
1224 /* $ Restrictions */
1225 
1226 /*     None. */
1227 
1228 /* $ Literature_References */
1229 
1230 /*     NAIF Document 167.0, "Double Precision Array Files (DAF) */
1231 /*     Specification and User's Guide" */
1232 
1233 /* $ Author_and_Institution */
1234 
1235 /*     N.J. Bachman    (JPL) */
1236 /*     W.L. Taber      (JPL) */
1237 /*     I.M. Underwood  (JPL) */
1238 
1239 /* $ Version */
1240 
1241 /* -    SPICELIB Version 3.0.0, 16-NOV-2001 (FST) */
1242 
1243 /*        Updated DAFBNA to support changes made to the DAF */
1244 /*        system that utilize the new handle manager.  See */
1245 /*        the Revisions section of DAFANA for a detailed */
1246 /*        discussion of the changes. */
1247 
1248 /* -    SPICELIB Version 2.0.1, 10-MAR-1992 (WLT) */
1249 
1250 /*        Comment section for permuted index source lines was added */
1251 /*        following the header. */
1252 
1253 /* -    SPICELIB Version 2.0.0, 04-SEP-1991 (NJB) (WLT) */
1254 
1255 /*        Modified to support simultaneous writes to multiple DAFs. */
1256 
1257 /* -    SPICELIB Version 1.0.1, 22-MAR-1990 (HAN) */
1258 
1259 /*        Literature references added to the header. */
1260 
1261 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
1262 
1263 /* -& */
1264 /* $ Index_Entries */
1265 
1266 /*     begin new daf array */
1267 
1268 /* -& */
1269 /* $ Revisions */
1270 
1271 /* -    SPICELIB Version 2.0.0, 04-SEP-1991 (NJB) (WLT) */
1272 
1273 /*        Modified to support simultaneous writes to multiple DAFs. */
1274 /*        DAFBNA now adds information about DAFs to the state table, */
1275 /*        deletes information about closed DAFs from the state table, */
1276 /*        and intializes the state pool. */
1277 /* -& */
1278 
1279 /*     Standard SPICE error handling. */
1280 
1281     if (return_()) {
1282 	return 0;
1283     } else {
1284 	chkin_("DAFBNA", (ftnlen)6);
1285     }
1286 
1287 /*     Check out the file handle before going any further. */
1288 
1289     dafsih_(handle, "WRITE", (ftnlen)5);
1290     if (failed_()) {
1291 	chkout_("DAFBNA", (ftnlen)6);
1292 	return 0;
1293     }
1294 
1295 /*     Initialize the state table pool, if this hasn't been done yet. */
1296 /*     Also initialize the cell used to obtain the set of handles of */
1297 /*     open DAFs. */
1298 
1299     if (first) {
1300 	ssizei_(&c__5000, opnset);
1301 	for (i__ = 1; i__ <= 19; ++i__) {
1302 	    stpool[(i__1 = i__ - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stpool"
1303 		    , i__1, "dafana_", (ftnlen)1067)] = i__ + 1;
1304 	}
1305 	stpool[19] = -1;
1306 	stfptr = 1;
1307 	sthead = -1;
1308 	first = FALSE_;
1309     }
1310 
1311 /*     We know that the beginning of the array will be the first */
1312 /*     free address in the file. We also need the summary format. */
1313 /*     Get both items from the file record. */
1314 
1315 /*     We won't use the information we're obtaining now until */
1316 /*     after we've placed the state information for the current */
1317 /*     DAF at the head of the active list, but we want to make sure */
1318 /*     that we can actually read the file record first.  So, we */
1319 /*     do the read now and avoid modifying the active list if the */
1320 /*     read fails. */
1321 
1322     dafrfr_(handle, &nd, &ni, ifname, &fward, &bward, &free, (ftnlen)60);
1323 
1324 /*     If we couldn't read the file record, bail out now. */
1325 
1326     if (failed_()) {
1327 	chkout_("DAFBNA", (ftnlen)6);
1328 	return 0;
1329     }
1330 
1331 /*     See whether we already have an entry for this DAF in the */
1332 /*     state table.  Find the previous node if possible. */
1333 
1334     p = sthead;
1335     prev = -1;
1336     found = FALSE_;
1337     while(p != -1 && ! found) {
1338 	if (stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
1339 		i__1, "dafana_", (ftnlen)1109)] == *handle) {
1340 	    found = TRUE_;
1341 	} else {
1342 	    prev = p;
1343 	    p = stpool[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stp"
1344 		    "ool", i__1, "dafana_", (ftnlen)1113)];
1345 	}
1346     }
1347 
1348 /*     At this point, either FOUND is false, or P points to a */
1349 /*     state table entry describing the DAF indicated by HANDLE. */
1350 /*     In the latter case, PREV is the predecessor of P. */
1351 
1352 
1353     if (found) {
1354 
1355 /*        We already have a dossier on this DAF.  We already have */
1356 /*        the information on the summary format, but we must re-set */
1357 /*        the rest of our state information. */
1358 
1359 /*        Rather than doing the update here, we do it outside of this */
1360 /*        IF block.  That way, the update gets done in just one place. */
1361 /*        This just makes life easier:  if the collection of state */
1362 /*        variables is changed, there are fewer places to forget to */
1363 /*        make the required code changes. */
1364 
1365 /*        Move the node for this DAF to the head of the active list, */
1366 /*        if it is not already there: */
1367 
1368 /*           - Make the predecessor of P point to the successor of P. */
1369 
1370 /*           - Make P point to the head of the active list. */
1371 
1372 /*           - Make P the active list head node. */
1373 
1374 
1375 	if (p != sthead) {
1376 
1377 /*           P is in the active list, but is not at the head.  So, */
1378 /*           the predecessor of P is not NIL. */
1379 
1380 	    stpool[(i__1 = prev - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stpo"
1381 		    "ol", i__1, "dafana_", (ftnlen)1151)] = stpool[(i__2 = p -
1382 		    1) < 20 && 0 <= i__2 ? i__2 : s_rnge("stpool", i__2,
1383 		    "dafana_", (ftnlen)1151)];
1384 	    stpool[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stpool",
1385 		    i__1, "dafana_", (ftnlen)1152)] = sthead;
1386 	    sthead = p;
1387 	}
1388     } else {
1389 
1390 /*        We don't yet have any information on this DAF.  Make a new */
1391 /*        state table entry for the DAF.  We may need to make room for */
1392 /*        the new information by freeing space allocated to DAFs that */
1393 /*        are no longer open. */
1394 
1395 	if (stfptr == -1) {
1396 
1397 /*           Oops, we're out of space.  Time for garbage collection. */
1398 /*           Test each file handle to see whether it designates a DAF */
1399 /*           that is still open.  DAFHOF will tell us which handles */
1400 /*           point to open DAFs. */
1401 
1402 	    dafhof_(opnset);
1403 	    p = sthead;
1404 	    prev = -1;
1405 
1406 /*           For every DAF file represented in the state table, we'll */
1407 /*           delete the corresponding state information if the DAF is */
1408 /*           now closed.  We traverse the active list, examining each */
1409 /*           file handle as we go. */
1410 
1411 	    while(p != -1) {
1412 		if (elemi_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 :
1413 			s_rnge("stfh", i__1, "dafana_", (ftnlen)1185)],
1414 			opnset)) {
1415 
1416 /*                 The file is open. Have a look at the next node. */
1417 
1418 		    prev = p;
1419 		    p = stpool[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 :
1420 			    s_rnge("stpool", i__1, "dafana_", (ftnlen)1190)];
1421 		} else {
1422 
1423 /*                 This file handle is not on the list, so free the */
1424 /*                 node pointing to the information about the DAF it */
1425 /*                 designated: */
1426 
1427 /*                    - Save the successor of P. */
1428 
1429 /*                    - Link the predecessor of node P to the successor */
1430 /*                      of P, if the predecessor is not NIL. */
1431 
1432 /*                    - If it happens that P is the head node of the */
1433 /*                      active list, set the head equal to the */
1434 /*                      successor of P. */
1435 
1436 /*                    - Link P into the free list. */
1437 
1438 /*                    - Set P equal to its saved successor. */
1439 
1440 /*                    - (PREV remains unchanged.) */
1441 
1442 
1443 		    nextp = stpool[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 :
1444 			    s_rnge("stpool", i__1, "dafana_", (ftnlen)1214)];
1445 		    if (p == sthead) {
1446 
1447 /*                    Re-assign STHEAD so that we don't lose the head */
1448 /*                    of the active list.  P has no predecessor in this */
1449 /*                    case, so there's no need to set the forward pointer */
1450 /*                    of node PREV. */
1451 
1452 			sthead = nextp;
1453 		    } else {
1454 
1455 /*                    Since P is not the head node of the active list, */
1456 /*                    PREV is not NIL, so we'll need to set the forward */
1457 /*                    pointer of node PREV. */
1458 
1459 			stpool[(i__1 = prev - 1) < 20 && 0 <= i__1 ? i__1 :
1460 				s_rnge("stpool", i__1, "dafana_", (ftnlen)
1461 				1231)] = nextp;
1462 		    }
1463 		    stpool[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge(
1464 			    "stpool", i__1, "dafana_", (ftnlen)1236)] =
1465 			    stfptr;
1466 		    stfptr = p;
1467 		    p = nextp;
1468 		}
1469 	    }
1470 
1471 /*           At this point, we've freed all nodes from the active */
1472 /*           list that were used to index information about DAFs that */
1473 /*           are no longer open.  Now see if we still need to make */
1474 /*           room.  If so, locate the first dossier with STADDG(P) */
1475 /*           set to FALSE.  We know then that this file is not */
1476 /*           currently involved in an array addition. */
1477 
1478 	    if (stfptr == -1) {
1479 		found = FALSE_;
1480 		p = sthead;
1481 		prev = -1;
1482 		while(p != -1 && ! found) {
1483 
1484 /*                 If STADDG(P) is TRUE, then we must continue */
1485 /*                 searching. */
1486 
1487 		    if (staddg[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 :
1488 			    s_rnge("staddg", i__1, "dafana_", (ftnlen)1264)])
1489 			    {
1490 			prev = p;
1491 			p = stpool[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 :
1492 				s_rnge("stpool", i__1, "dafana_", (ftnlen)
1493 				1267)];
1494 		    } else {
1495 			found = TRUE_;
1496 
1497 /*                    No array is presently being added to the DAF */
1498 /*                    associated with this dossier, so free the */
1499 /*                    node pointing to the information about the DAF it */
1500 /*                    designated: */
1501 
1502 /*                    - Save the successor of P. */
1503 
1504 /*                    - Link the predecessor of node P to the successor */
1505 /*                      of P, if the predecessor is not NIL. */
1506 
1507 /*                    - If it happens that P is the head node of the */
1508 /*                      active list, set the head equal to the */
1509 /*                      successor of P. */
1510 
1511 /*                    - Link P into the free list. */
1512 
1513 /*                    - Set P equal to its saved successor. */
1514 
1515 /*                    - (PREV remains unchanged.) */
1516 
1517 
1518 			nextp = stpool[(i__1 = p - 1) < 20 && 0 <= i__1 ?
1519 				i__1 : s_rnge("stpool", i__1, "dafana_", (
1520 				ftnlen)1294)];
1521 			if (p == sthead) {
1522 
1523 /*                       Re-assign STHEAD so that we don't lose the head */
1524 /*                       of the active list.  P has no predecessor in */
1525 /*                       this case, so there's no need to set the */
1526 /*                       forward pointer of node PREV. */
1527 
1528 			    sthead = nextp;
1529 			} else {
1530 
1531 /*                       Since P is not the head node of the active list, */
1532 /*                       PREV is not NIL, so we'll need to set the */
1533 /*                       forward pointer of node PREV. */
1534 
1535 			    stpool[(i__1 = prev - 1) < 20 && 0 <= i__1 ? i__1
1536 				    : s_rnge("stpool", i__1, "dafana_", (
1537 				    ftnlen)1311)] = nextp;
1538 			}
1539 			stpool[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 :
1540 				s_rnge("stpool", i__1, "dafana_", (ftnlen)
1541 				1316)] = stfptr;
1542 			stfptr = p;
1543 			p = nextp;
1544 		    }
1545 		}
1546 	    }
1547 
1548 /*           Now, check to see if there is now room to add the dossier */
1549 /*           for the new DAF to the state table.  If not signal an error. */
1550 
1551 	    if (stfptr == -1) {
1552 		setmsg_("Attempt to initiate create a new array in DAF '#' h"
1553 			"as failed. DAFANA's state table has room to manage w"
1554 			"riting to # new arrays simultaneously, but there is "
1555 			"no room left in the table for this DAF.", (ftnlen)194)
1556 			;
1557 		errhan_("#", handle, (ftnlen)1);
1558 		errint_("#", &c__20, (ftnlen)1);
1559 		sigerr_("SPICE(STFULL)", (ftnlen)13);
1560 		chkout_("DAFBNA", (ftnlen)6);
1561 		return 0;
1562 	    }
1563 	}
1564 
1565 /*        If we reach here, then we have room in the state table for */
1566 /*        the new DAF.  The first free node is indicated by SFTPTR. */
1567 /*        Allocate this node and use it to index the state information */
1568 /*        for the new DAF. */
1569 
1570 	p = stfptr;
1571 
1572 /*        Update the free list pointer, link P to the previous head */
1573 /*        of the active list, and make P the head of the active list. */
1574 
1575 	stfptr = stpool[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge(
1576 		"stpool", i__1, "dafana_", (ftnlen)1360)];
1577 	stpool[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stpool",
1578 		i__1, "dafana_", (ftnlen)1361)] = sthead;
1579 	sthead = p;
1580     }
1581 
1582 /*     At this point, P is the head node of the active list, and P is */
1583 /*     the index in the state table of the information for the current */
1584 /*     DAF. */
1585 
1586 
1587 /*     Set the state information for the current array. */
1588 
1589     stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh", i__1, "daf"
1590 	    "ana_", (ftnlen)1375)] = *handle;
1591     s_copy(stifnm + ((i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stifnm"
1592 	    , i__1, "dafana_", (ftnlen)1376)) * 60, ifname, (ftnlen)60, (
1593 	    ftnlen)60);
1594     staddg[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("staddg", i__1,
1595 	    "dafana_", (ftnlen)1377)] = TRUE_;
1596     stfrst[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfrst", i__1,
1597 	    "dafana_", (ftnlen)1378)] = fward;
1598     stlast[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stlast", i__1,
1599 	    "dafana_", (ftnlen)1379)] = bward;
1600     stbegn[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stbegn", i__1,
1601 	    "dafana_", (ftnlen)1380)] = free;
1602     stfree[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfree", i__1,
1603 	    "dafana_", (ftnlen)1381)] = free;
1604 
1605 /*     Find out how big the array summary is supposed to be. */
1606 
1607     dafhsf_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
1608 	    i__1, "dafana_", (ftnlen)1386)], &nd, &ni);
1609     sumsiz = nd + (ni + 1) / 2;
1610 
1611 /*     Set the local copies of the array's summary and name. */
1612 
1613     moved_(sum, &sumsiz, &stlsum[(i__1 = p * 125 - 125) < 2500 && 0 <= i__1 ?
1614 	    i__1 : s_rnge("stlsum", i__1, "dafana_", (ftnlen)1393)]);
1615     s_copy(stname + ((i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stname"
1616 	    , i__1, "dafana_", (ftnlen)1395)) * 1000, name__, (ftnlen)1000,
1617 	    name_len);
1618     chkout_("DAFBNA", (ftnlen)6);
1619     return 0;
1620 /* $Procedure DAFADA ( DAF, add data to array ) */
1621 
1622 L_dafada:
1623 /* $ Abstract */
1624 
1625 /*     Add one or more double precision words of data to the newest */
1626 /*     array in the current DAF. */
1627 
1628 /* $ Disclaimer */
1629 
1630 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
1631 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
1632 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
1633 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
1634 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
1635 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
1636 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
1637 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
1638 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
1639 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
1640 
1641 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
1642 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
1643 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
1644 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
1645 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
1646 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
1647 
1648 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
1649 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
1650 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
1651 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
1652 
1653 /* $ Required_Reading */
1654 
1655 /*     DAF */
1656 
1657 /* $ Keywords */
1658 
1659 /*     FILES */
1660 
1661 /* $ Declarations */
1662 
1663 /*     DOUBLE PRECISION      DATA     ( * ) */
1664 /*     INTEGER               N */
1665 
1666 /* $ Brief_I/O */
1667 
1668 /*     Variable  I/O  Entry */
1669 /*     --------  ---  -------------------------------------------------- */
1670 /*     DATA       I   Elements of the new array. */
1671 /*     N          I   Number of elements in DATA. */
1672 
1673 /* $ Detailed_Input */
1674 
1675 /*     DATA        is an arbitrary number of double precision words to */
1676 /*                 be added to the data in the array being created. */
1677 
1678 /*     N           is the number of double precision words in DATA. */
1679 
1680 /* $ Detailed_Output */
1681 
1682 /*     None. */
1683 
1684 /* $ Parameters */
1685 
1686 /*      None. */
1687 
1688 /* $ Files */
1689 
1690 /*     None. */
1691 
1692 /* $ Exceptions */
1693 
1694 /*     1) If there are no DAFs to which data is currently being added, */
1695 /*        the error SPICE(DAFNOWRITE) is signalled. */
1696 
1697 /*     2) If a new array has not been started in the current DAF (by a */
1698 /*        call to DAFBNA), the error SPICE(DAFNEWCONFLICT) is signalled. */
1699 
1700 /*     3) If N is less than one, no data are added to the file. */
1701 
1702 /* $ Particulars */
1703 
1704 /*     DAFADA adds data to the last array begun by DAFBNA or selected */
1705 /*     by DAFCAD. */
1706 
1707 /*     Data can be added to a DAF in chunks of any size, so long */
1708 /*     as the chunks are added in the proper order. */
1709 
1710 /* $ Examples */
1711 
1712 /*     See example for DAFADA in the header of DAFANA. */
1713 
1714 /* $ Restrictions */
1715 
1716 /*     None. */
1717 
1718 /* $ Literature_References */
1719 
1720 /*     NAIF Document 167.0, "Double Precision Array Files (DAF) */
1721 /*     Specification and User's Guide" */
1722 
1723 /* $ Author_and_Institution */
1724 
1725 /*     N.J. Bachman    (JPL) */
1726 /*     W.L. Taber      (JPL) */
1727 /*     I.M. Underwood  (JPL) */
1728 
1729 /* $ Version */
1730 
1731 /* -    SPICELIB Version 3.0.0, 16-NOV-2001 (FST) */
1732 
1733 /*        Updated entry points to support changes made to the DAF */
1734 /*        system that utilize the new handle manager.  See */
1735 /*        the Revisions section of DAFANA for a detailed */
1736 /*        discussion of the changes. */
1737 
1738 /* -    SPICELIB Version 2.0.1, 10-MAR-1992 (WLT) */
1739 
1740 /*        Comment section for permuted index source lines was added */
1741 /*        following the header. */
1742 
1743 /* -    SPICELIB Version 2.0.0, 04-SEP-1991 (NJB) (WLT) */
1744 
1745 /*        Updated to work with new DAF routines that allow writing */
1746 /*        to multiple DAFs simultaneously.  Functionality for */
1747 /*        applications that write to one DAF at a time is unchanged. */
1748 
1749 /* -    SPICELIB Version 1.0.1, 22-MAR-1990 (HAN) */
1750 
1751 /*        Literature references added to the header. */
1752 
1753 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
1754 
1755 /* -& */
1756 /* $ Index_Entries */
1757 
1758 /*     add data to daf array */
1759 
1760 /* -& */
1761 /* $ Revisions */
1762 
1763 /* -    SPICELIB Version 2.0.0, 04-SEP-1991 (NJB) (WLT) */
1764 
1765 /*        Updated to work with new DAF routines that allow writing */
1766 /*        to multiple DAFs simultaneously.  Functionality for */
1767 /*        applications that write to one DAF at a time is unchanged. */
1768 
1769 /* -& */
1770 
1771 /*     Standard SPICE error handling. */
1772 
1773     if (return_()) {
1774 	return 0;
1775     } else {
1776 	chkin_("DAFADA", (ftnlen)6);
1777     }
1778 
1779 /*     This routine operates on the DAF at the head of the active list. */
1780 
1781     p = sthead;
1782 
1783 /*     We must make sure that the requested addition can be performed. */
1784 /*     We don't validate the file handle here because this is one place */
1785 /*     where we are concerned about speed.  The low-level writer routine */
1786 /*     DAFWDR will handle the check. */
1787 
1788     if (p == -1) {
1789 	setmsg_("No DAF is currently being written.", (ftnlen)34);
1790 	sigerr_("SPICE(DAFNOWRITE)", (ftnlen)17);
1791 	chkout_("DAFADA", (ftnlen)6);
1792 	return 0;
1793 
1794 /*     An array cannot be extended unless begun first. */
1795 
1796     } else if (! staddg[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge(
1797 	    "staddg", i__1, "dafana_", (ftnlen)1592)]) {
1798 
1799 /*        Validate the current handle, then get the name of the DAF. */
1800 
1801 	dafsih_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
1802 		 i__1, "dafana_", (ftnlen)1596)], "WRITE", (ftnlen)5);
1803 	if (failed_()) {
1804 	    chkout_("DAFADA", (ftnlen)6);
1805 	    return 0;
1806 	}
1807 	dafhfn_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
1808 		 i__1, "dafana_", (ftnlen)1603)], dafnam, (ftnlen)255);
1809 	setmsg_("An attempt was made to add data to an array that has not ye"
1810 		"t been begun, in file #.", (ftnlen)83);
1811 	errch_("#", dafnam, (ftnlen)1, (ftnlen)255);
1812 	sigerr_("SPICE(DAFNEWCONFLICT)", (ftnlen)21);
1813 	chkout_("DAFADA", (ftnlen)6);
1814 	return 0;
1815 
1816 /*     Start adding data at the first free address, then update that */
1817 /*     address to get ready for the next addition. */
1818 
1819     } else if (*n >= 1) {
1820 	i__4 = stfree[(i__3 = p - 1) < 20 && 0 <= i__3 ? i__3 : s_rnge("stfr"
1821 		"ee", i__3, "dafana_", (ftnlen)1617)] + *n - 1;
1822 	dafwda_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
1823 		 i__1, "dafana_", (ftnlen)1617)], &stfree[(i__2 = p - 1) < 20
1824 		&& 0 <= i__2 ? i__2 : s_rnge("stfree", i__2, "dafana_", (
1825 		ftnlen)1617)], &i__4, data);
1826 	stfree[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfree",
1827 		i__1, "dafana_", (ftnlen)1618)] = stfree[(i__2 = p - 1) < 20
1828 		&& 0 <= i__2 ? i__2 : s_rnge("stfree", i__2, "dafana_", (
1829 		ftnlen)1618)] + *n;
1830     }
1831     chkout_("DAFADA", (ftnlen)6);
1832     return 0;
1833 /* $Procedure DAFENA ( DAF, end new array ) */
1834 
1835 L_dafena:
1836 /* $ Abstract */
1837 
1838 /*     End the addition of data to the newest array in the current DAF. */
1839 
1840 /* $ Disclaimer */
1841 
1842 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
1843 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
1844 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
1845 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
1846 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
1847 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
1848 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
1849 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
1850 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
1851 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
1852 
1853 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
1854 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
1855 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
1856 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
1857 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
1858 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
1859 
1860 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
1861 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
1862 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
1863 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
1864 
1865 /* $ Required_Reading */
1866 
1867 /*     DAF */
1868 
1869 /* $ Keywords */
1870 
1871 /*     FILES */
1872 
1873 /* $ Declarations */
1874 
1875 /*     None. */
1876 
1877 /* $ Brief_I/O */
1878 
1879 /*     None. */
1880 
1881 /* $ Detailed_Input */
1882 
1883 /*     None. */
1884 
1885 /* $ Detailed_Output */
1886 
1887 /*     None. */
1888 
1889 /* $ Parameters */
1890 
1891 /*     None. */
1892 
1893 /* $ Files */
1894 
1895 /*     None. */
1896 
1897 /* $ Exceptions */
1898 
1899 /*     1) If there are no DAFs to which data is currently being added, */
1900 /*        the error SPICE(DAFNOWRITE) is signalled, or the error will */
1901 /*        be detected by routines called by this routine. */
1902 
1903 /*     2) If a new array has not been started in the current DAF (by a */
1904 /*        call to DAFBNA), the error SPICE(DAFNEWCONFLICT) is signalled. */
1905 
1906 /* $ Particulars */
1907 
1908 /*     DAFENA makes the current array a permanent addition to the */
1909 /*     current DAF. */
1910 
1911 /*     The pointers within the file are not changed until an array */
1912 /*     is ended successfully.  If an error occurs or if the current */
1913 /*     DAF is closed before DAFENA is called, the last array will */
1914 /*     not be visible to the DAF reader routines. */
1915 
1916 /* $ Examples */
1917 
1918 /*     See DAFANA. */
1919 
1920 /* $ Restrictions */
1921 
1922 /*     None. */
1923 
1924 /* $ Literature_References */
1925 
1926 /*     NAIF Document 167.0, "Double Precision Array Files (DAF) */
1927 /*     Specification and User's Guide" */
1928 
1929 /* $ Author_and_Institution */
1930 
1931 /*     N.J. Bachman    (JPL) */
1932 /*     W.L. Taber      (JPL) */
1933 /*     I.M. Underwood  (JPL) */
1934 
1935 /* $ Version */
1936 
1937 /* -    SPICELIB Version 3.0.0, 16-NOV-2001 (FST) */
1938 
1939 /*        Updated entry points to support changes made to the DAF */
1940 /*        system that utilize the new handle manager.  See */
1941 /*        the Revisions section of DAFANA for a detailed */
1942 /*        discussion of the changes. */
1943 
1944 /* -    SPICELIB Version 2.1.0, 11-JUL-1995 (KRG) */
1945 
1946 /*        Updated to remove potential compiler warnings from the */
1947 /*        truncation of double precision numbers to integers. */
1948 
1949 /*        Also changed was a numeric constant from 1.D0 to the */
1950 /*        equivalent, but more aesthetically pleasing 1.0D0. */
1951 
1952 /* -    SPICELIB Version 2.0.1, 10-MAR-1992 (WLT) */
1953 
1954 /*        Comment section for permuted index source lines was added */
1955 /*        following the header. */
1956 
1957 /* -    SPICELIB Version 2.0.0, 04-SEP-1991 (NJB) (WLT) */
1958 
1959 /*        Updated to work with new DAF routines that allow writing */
1960 /*        to multiple DAFs simultaneously.  Functionality for */
1961 /*        applications that write to one DAF at a time is unchanged. */
1962 
1963 /* -    SPICELIB Version 1.0.1, 22-MAR-1990 (HAN) */
1964 
1965 /*        Literature references added to the header. */
1966 
1967 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
1968 
1969 /* -& */
1970 /* $ Index_Entries */
1971 
1972 /*     end new daf array */
1973 
1974 /* -& */
1975 /* $ Revisions */
1976 
1977 /* -    SPICELIB Version 2.1.0, 11-JUL-1995 (KRG) */
1978 
1979 /*        Updated to remove potential compiler warnings from the */
1980 /*        truncation of double precision numbers to integers. Two */
1981 /*        assignments to NARRAY were updated, being changed from: */
1982 
1983 /*           NARRAY = SUMREC(ARYCNT) */
1984 
1985 /*        to */
1986 
1987 /*           NARRAY = IDINT ( SUMREC(ARYCNT) ) */
1988 
1989 /*        Also changed was a numeric constant from 1.D0 to the */
1990 /*        equivalent, but more aesthetically pleasing 1.0D0. */
1991 
1992 /* -    SPICELIB Version 2.0.1, 10-MAR-1992 (WLT) */
1993 
1994 /*        Comment section for permuted index source lines was added */
1995 /*        following the header. */
1996 
1997 /* -    SPICELIB Version 2.0.0, 04-SEP-1991 (NJB) (WLT) */
1998 
1999 /*        Updated to work with new DAF routines that allow writing */
2000 /*        to multiple DAFs simultaneously.  Functionality for */
2001 /*        applications that write to one DAF at a time is unchanged. */
2002 
2003 /* -& */
2004 
2005 /*     Standard SPICE error handling. */
2006 
2007     if (return_()) {
2008 	return 0;
2009     } else {
2010 	chkin_("DAFENA", (ftnlen)6);
2011     }
2012 
2013 /*     This routine operates on the DAF at the head of the active list. */
2014 
2015     p = sthead;
2016     if (p == -1) {
2017 	setmsg_("No DAF is currently being written.", (ftnlen)34);
2018 	sigerr_("SPICE(DAFNOWRITE)", (ftnlen)17);
2019 	chkout_("DAFENA", (ftnlen)6);
2020 	return 0;
2021 
2022 /*     A new array cannot be ended unless begun first. */
2023 
2024     } else if (! staddg[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge(
2025 	    "staddg", i__1, "dafana_", (ftnlen)1832)]) {
2026 
2027 /*        Validate the current handle, then get the name of the DAF. */
2028 
2029 	dafsih_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
2030 		 i__1, "dafana_", (ftnlen)1836)], "WRITE", (ftnlen)5);
2031 	if (failed_()) {
2032 	    chkout_("DAFENA", (ftnlen)6);
2033 	    return 0;
2034 	}
2035 	dafhfn_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
2036 		 i__1, "dafana_", (ftnlen)1843)], dafnam, (ftnlen)255);
2037 	setmsg_("An attempt was made to end an array that has not yet been b"
2038 		"egun, in file #.", (ftnlen)75);
2039 	errch_("#", dafnam, (ftnlen)1, (ftnlen)255);
2040 	sigerr_("SPICE(DAFNEWCONFLICT)", (ftnlen)21);
2041 	chkout_("DAFENA", (ftnlen)6);
2042 	return 0;
2043     }
2044 
2045 /*     No more data. The array ends just before the next free */
2046 /*     address. The summary should be complete except for the */
2047 /*     initial and final addresses of the data, of which we */
2048 /*     have been keeping track. */
2049 
2050     dafhsf_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
2051 	    i__1, "dafana_", (ftnlen)1859)], &nd, &ni);
2052     dafus_(&stlsum[(i__1 = p * 125 - 125) < 2500 && 0 <= i__1 ? i__1 : s_rnge(
2053 	    "stlsum", i__1, "dafana_", (ftnlen)1861)], &nd, &ni, dc, ic);
2054     ic[(i__1 = ni - 2) < 250 && 0 <= i__1 ? i__1 : s_rnge("ic", i__1, "dafan"
2055 	    "a_", (ftnlen)1863)] = stbegn[(i__2 = p - 1) < 20 && 0 <= i__2 ?
2056 	    i__2 : s_rnge("stbegn", i__2, "dafana_", (ftnlen)1863)];
2057     ic[(i__1 = ni - 1) < 250 && 0 <= i__1 ? i__1 : s_rnge("ic", i__1, "dafan"
2058 	    "a_", (ftnlen)1864)] = stfree[(i__2 = p - 1) < 20 && 0 <= i__2 ?
2059 	    i__2 : s_rnge("stfree", i__2, "dafana_", (ftnlen)1864)] - 1;
2060     dafps_(&nd, &ni, dc, ic, &stlsum[(i__1 = p * 125 - 125) < 2500 && 0 <=
2061 	    i__1 ? i__1 : s_rnge("stlsum", i__1, "dafana_", (ftnlen)1866)]);
2062 
2063 /*     The summary should be stored in the final summary record (the */
2064 /*     one at the end of the file). Get that entire record, and the */
2065 /*     corresponding name record. */
2066 
2067     dafrdr_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
2068 	    i__1, "dafana_", (ftnlen)1873)], &stlast[(i__2 = p - 1) < 20 && 0
2069 	    <= i__2 ? i__2 : s_rnge("stlast", i__2, "dafana_", (ftnlen)1873)],
2070 	     &c__1, &c__128, sumrec, &found);
2071     i__3 = stlast[(i__2 = p - 1) < 20 && 0 <= i__2 ? i__2 : s_rnge("stlast",
2072 	    i__2, "dafana_", (ftnlen)1874)] + 1;
2073     dafrcr_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
2074 	    i__1, "dafana_", (ftnlen)1874)], &i__3, namrec, (ftnlen)1000);
2075     narray = (integer) sumrec[2];
2076 
2077 /*     The number of arrays determines where the summary and name */
2078 /*     are stored within the summary record. Adding this array increases */
2079 /*     the number of arrays by one. */
2080 
2081     sumsiz = nd + (ni + 1) / 2;
2082     dloc = narray * sumsiz + 4;
2083     moved_(&stlsum[(i__1 = p * 125 - 125) < 2500 && 0 <= i__1 ? i__1 : s_rnge(
2084 	    "stlsum", i__1, "dafana_", (ftnlen)1885)], &sumsiz, &sumrec[(i__2
2085 	    = dloc - 1) < 128 && 0 <= i__2 ? i__2 : s_rnge("sumrec", i__2,
2086 	    "dafana_", (ftnlen)1885)]);
2087     namsiz = sumsiz << 3;
2088     cloc = narray * namsiz + 1;
2089     s_copy(namrec + (cloc - 1), stname + ((i__1 = p - 1) < 20 && 0 <= i__1 ?
2090 	    i__1 : s_rnge("stname", i__1, "dafana_", (ftnlen)1890)) * 1000,
2091 	    cloc + namsiz - 1 - (cloc - 1), (ftnlen)1000);
2092     sumrec[2] += 1.;
2093     narray = (integer) sumrec[2];
2094 
2095 /*     Usually, adding an array does not fill the final summary */
2096 /*     record, and it can simply be replaced. */
2097 
2098     if (narray < 125 / sumsiz) {
2099 	dafwdr_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
2100 		 i__1, "dafana_", (ftnlen)1901)], &stlast[(i__2 = p - 1) < 20
2101 		&& 0 <= i__2 ? i__2 : s_rnge("stlast", i__2, "dafana_", (
2102 		ftnlen)1901)], sumrec);
2103 	i__3 = stlast[(i__2 = p - 1) < 20 && 0 <= i__2 ? i__2 : s_rnge("stla"
2104 		"st", i__2, "dafana_", (ftnlen)1902)] + 1;
2105 	dafwcr_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
2106 		 i__1, "dafana_", (ftnlen)1902)], &i__3, namrec, (ftnlen)1000)
2107 		;
2108 
2109 /*     When the record becomes full, a new one must be written. */
2110 /*     However, this fact should be transparent to the user. */
2111 
2112     } else {
2113 
2114 /*        The new summary record will be stored in the next free record */
2115 /*        in the file. This summary record should point to it. */
2116 
2117 /*        To find out which record the next free address is in, we use */
2118 /*        DAFARW (`address to record and word'). */
2119 
2120 	i__2 = stfree[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfr"
2121 		"ee", i__1, "dafana_", (ftnlen)1917)] - 1;
2122 	dafarw_(&i__2, &next, &word);
2123 	++next;
2124 	sumrec[0] = (doublereal) next;
2125 	dafwdr_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
2126 		 i__1, "dafana_", (ftnlen)1921)], &stlast[(i__2 = p - 1) < 20
2127 		&& 0 <= i__2 ? i__2 : s_rnge("stlast", i__2, "dafana_", (
2128 		ftnlen)1921)], sumrec);
2129 	i__3 = stlast[(i__2 = p - 1) < 20 && 0 <= i__2 ? i__2 : s_rnge("stla"
2130 		"st", i__2, "dafana_", (ftnlen)1922)] + 1;
2131 	dafwcr_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
2132 		 i__1, "dafana_", (ftnlen)1922)], &i__3, namrec, (ftnlen)1000)
2133 		;
2134 
2135 /*        The new summary record should point backwards to the one just */
2136 /*        written, and should point forwards to nothing. Of course, */
2137 /*        it contains no summaries, and no names. */
2138 
2139 	cleard_(&c__128, sumrec);
2140 	sumrec[0] = 0.;
2141 	sumrec[1] = (doublereal) stlast[(i__1 = p - 1) < 20 && 0 <= i__1 ?
2142 		i__1 : s_rnge("stlast", i__1, "dafana_", (ftnlen)1931)];
2143 	sumrec[2] = 0.;
2144 	s_copy(namrec, " ", (ftnlen)1000, (ftnlen)1);
2145 	dafwdr_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
2146 		 i__1, "dafana_", (ftnlen)1935)], &next, sumrec);
2147 	i__2 = next + 1;
2148 	dafwcr_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
2149 		 i__1, "dafana_", (ftnlen)1936)], &i__2, namrec, (ftnlen)1000)
2150 		;
2151 
2152 /*        If a new summary record  was added, the first free address */
2153 /*        lies just beyond the end of the matching character record. */
2154 
2155 /*        We use DAFRWA (`record and word to address') to calculate */
2156 /*        the next free address. */
2157 
2158 	stlast[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stlast",
2159 		i__1, "dafana_", (ftnlen)1945)] = next;
2160 	i__3 = stlast[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stla"
2161 		"st", i__1, "dafana_", (ftnlen)1946)] + 2;
2162 	dafrwa_(&i__3, &c__1, &stfree[(i__2 = p - 1) < 20 && 0 <= i__2 ? i__2
2163 		: s_rnge("stfree", i__2, "dafana_", (ftnlen)1946)]);
2164     }
2165 
2166 /*     The new value STFREE(P) must be rewritten in the file record each */
2167 /*     time a new array is added. If a new record was added, the new */
2168 /*     value of STLAST(P) will be rewritten as well. */
2169 
2170     dafwfr_(&stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
2171 	    i__1, "dafana_", (ftnlen)1955)], &nd, &ni, stifnm + ((i__2 = p -
2172 	    1) < 20 && 0 <= i__2 ? i__2 : s_rnge("stifnm", i__2, "dafana_", (
2173 	    ftnlen)1955)) * 60, &stfrst[(i__3 = p - 1) < 20 && 0 <= i__3 ?
2174 	    i__3 : s_rnge("stfrst", i__3, "dafana_", (ftnlen)1955)], &stlast[(
2175 	    i__4 = p - 1) < 20 && 0 <= i__4 ? i__4 : s_rnge("stlast", i__4,
2176 	    "dafana_", (ftnlen)1955)], &stfree[(i__5 = p - 1) < 20 && 0 <=
2177 	    i__5 ? i__5 : s_rnge("stfree", i__5, "dafana_", (ftnlen)1955)], (
2178 	    ftnlen)60);
2179 
2180 /*     Ready for another array. */
2181 
2182     staddg[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("staddg", i__1,
2183 	    "dafana_", (ftnlen)1966)] = FALSE_;
2184     chkout_("DAFENA", (ftnlen)6);
2185     return 0;
2186 /* $Procedure      DAFCAD ( DAF, continue adding data ) */
2187 
2188 L_dafcad:
2189 /* $ Abstract */
2190 
2191 /*     Select a DAF that already has a new array in progress as the */
2192 /*     one to continue adding data to. */
2193 
2194 /* $ Disclaimer */
2195 
2196 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
2197 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
2198 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
2199 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
2200 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
2201 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
2202 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
2203 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
2204 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
2205 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
2206 
2207 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
2208 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
2209 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
2210 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
2211 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
2212 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
2213 
2214 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
2215 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
2216 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
2217 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
2218 
2219 /* $ Required_Reading */
2220 
2221 /*     DAF */
2222 
2223 /* $ Keywords */
2224 
2225 /*     FILES */
2226 
2227 /* $ Declarations */
2228 
2229 /*     INTEGER               HANDLE */
2230 
2231 /* $ Brief_I/O */
2232 
2233 /*     Variable  I/O  Description */
2234 /*     --------  ---  -------------------------------------------------- */
2235 /*     HANDLE     I   Handle of DAF to continue adding data to. */
2236 
2237 /* $ Detailed_Input */
2238 
2239 /*     HANDLE         is the handle of a DAF that is open for write */
2240 /*                    access and in which a new array has been */
2241 /*                    started by a call to DAFBNA. */
2242 
2243 /* $ Detailed_Output */
2244 
2245 /*     None. */
2246 
2247 /* $ Parameters */
2248 
2249 /*     None. */
2250 
2251 /* $ Exceptions */
2252 
2253 /*     1) If the input handle is not that of a DAF that is open */
2254 /*        for writing, the error will be diagnosed by routines called */
2255 /*        by this routine. */
2256 
2257 /*     2) If no array is currently being added to in the file indicated */
2258 /*        by HANDLE, the error will be diagnosed by this routine or */
2259 /*        routines called by this routine.  If DAFCAD can detect the */
2260 /*        problem, the error SPICE(NOARRAYSTARTED) will be signalled. */
2261 
2262 /* $ Files */
2263 
2264 /*     None. */
2265 
2266 /* $ Particulars */
2267 
2268 /*     DAFCAD supports simultaneous addition of data to arrays in */
2269 /*     multiple DAFs.  In applications that use this capability, */
2270 /*     DAFCAD should be called prior to each call to DAFADA or DAFENA */
2271 /*     to specify which DAF is to be acted upon. */
2272 
2273 /*     Here is a code fragment that adds a new array to each of N */
2274 /*     existing DAFs, simultaneously.  The data to be added to each */
2275 /*     is broken up into M chunks; one chunk is written to each DAF */
2276 /*     at a time.  The data is contained in the array CHUNK, dimensioned */
2277 
2278 /*         DOUBLE PRECISION      CHUNK ( MAXDAT, M, N ) */
2279 
2280 /*     The actual amount of data in the Jth chunk for the Ith file is */
2281 /*     given by */
2282 
2283 /*         AMOUNT (J,I) */
2284 
2285 
2286 
2287 /*         DO I = 1, N */
2288 /*            CALL DAFOPW ( HANDLE(I) ) */
2289 /*            CALL DAFBNA ( HANDLE(I) ) */
2290 /*         END DO */
2291 
2292 /*         DO J = 1, M */
2293 
2294 /*            DO I = 1, N */
2295 /*               CALL DAFCAD  ( HANDLE(I)                  ) */
2296 /*               CALL DAFADA  ( CHUNK(1,J,I),  AMOUNT(J,I) ) */
2297 /*            END DO */
2298 
2299 /*         END DO */
2300 
2301 /*         DO I = 1, N */
2302 /*            CALL DAFCAD  ( HANDLE(I) ) */
2303 /*            CALL DAFENA */
2304 /*         END DO */
2305 
2306 
2307 /*     Note that if we write all of the data for each array to just one */
2308 /*     DAF at a time, we don't need to use DAFCAD: */
2309 
2310 /*        DO I = 1, N */
2311 
2312 /*           CALL DAFOPW ( HANDLE(I) ) */
2313 /*           CALL DAFBNA ( HANDLE(I) ) */
2314 
2315 /*           DO J = 1, M */
2316 /*              CALL DAFADA ( CHUNK(1,J,I),  AMOUNT(J,I) ) */
2317 /*           END DO */
2318 
2319 /*           CALL DAFENA */
2320 
2321 /*        END DO */
2322 
2323 
2324 /* $ Examples */
2325 
2326 /*     See DAFANA. */
2327 
2328 /* $ Restrictions */
2329 
2330 /*     None. */
2331 
2332 /* $ Literature_References */
2333 
2334 /*     None. */
2335 
2336 /* $ Author_and_Institution */
2337 
2338 /*     N.J. Bachman   (JPL) */
2339 /*     W.L. Taber     (JPL) */
2340 
2341 /* $ Version */
2342 
2343 /* -    SPICELIB Version 3.0.0, 16-NOV-2001 (FST) */
2344 
2345 /*        Updated entry points to support changes made to the DAF */
2346 /*        system that utilize the new handle manager.  See */
2347 /*        the Revisions section of DAFANA for a detailed */
2348 /*        discussion of the changes. */
2349 
2350 /* -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
2351 
2352 /*        Comment section for permuted index source lines was added */
2353 /*        following the header. */
2354 
2355 /* -    SPICELIB Version 1.0.0, 04-SEP-1991 (NJB) (WLT) */
2356 
2357 /* -& */
2358 /* $ Index_Entries */
2359 
2360 /*     continue adding data to a daf */
2361 /*     select a daf to continue adding data to */
2362 
2363 /* -& */
2364 
2365 /*     Standard SPICE error handling. */
2366 
2367     if (return_()) {
2368 	return 0;
2369     } else {
2370 	chkin_("DAFCAD", (ftnlen)6);
2371     }
2372 
2373 /*     Check out the file handle before going any further. */
2374 
2375     dafsih_(handle, "WRITE", (ftnlen)5);
2376     if (failed_()) {
2377 	chkout_("DAFCAD", (ftnlen)6);
2378 	return 0;
2379     }
2380 
2381 /*     See whether we already have an entry for this DAF in the */
2382 /*     state table.  Find the previous node if possible. */
2383 
2384     p = sthead;
2385     prev = -1;
2386     found = FALSE_;
2387     while(p != -1 && ! found) {
2388 	if (stfh[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stfh",
2389 		i__1, "dafana_", (ftnlen)2189)] == *handle) {
2390 	    found = TRUE_;
2391 	} else {
2392 	    prev = p;
2393 	    p = stpool[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stp"
2394 		    "ool", i__1, "dafana_", (ftnlen)2193)];
2395 	}
2396     }
2397 
2398 /*     Either FOUND is false, or P is the index in the state table of */
2399 /*     the DAF specified by HANDLE, and PREV is the predecessor of P. */
2400 
2401 
2402 /*     You can't continue writing to a DAF that you're not */
2403 /*     already writing to. */
2404 
2405     if (! found) {
2406 	dafhfn_(handle, dafnam, (ftnlen)255);
2407 	setmsg_("No write in progress to #. (Handle was #.) ", (ftnlen)43);
2408 	errch_("#", dafnam, (ftnlen)1, (ftnlen)255);
2409 	errint_("#", handle, (ftnlen)1);
2410 	sigerr_("SPICE(NOARRAYSTARTED)", (ftnlen)21);
2411 	chkout_("DAFCAD", (ftnlen)6);
2412 	return 0;
2413     } else if (! staddg[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge(
2414 	    "staddg", i__1, "dafana_", (ftnlen)2217)]) {
2415 	dafhfn_(handle, dafnam, (ftnlen)255);
2416 	setmsg_("No write in progress to #. (Handle was #.) ", (ftnlen)43);
2417 	errch_("#", dafnam, (ftnlen)1, (ftnlen)255);
2418 	errint_("#", handle, (ftnlen)1);
2419 	sigerr_("SPICE(NOARRAYSTARTED)", (ftnlen)21);
2420 	chkout_("DAFCAD", (ftnlen)6);
2421 	return 0;
2422     }
2423 
2424 /*     Move the node for this DAF to the head of the active list, */
2425 /*     if it is not already there: */
2426 
2427 /*        - Make the predecessor of P point to the successor of P. */
2428 
2429 /*        - Make P point to the head of the active list. */
2430 
2431 /*        - Make P the active list head node. */
2432 
2433 
2434     if (p != sthead) {
2435 
2436 /*        P is in the active list, but is not at the head.  So, */
2437 /*        the predecessor of P is not NIL. */
2438 
2439 	stpool[(i__1 = prev - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stpool",
2440 		i__1, "dafana_", (ftnlen)2246)] = stpool[(i__2 = p - 1) < 20
2441 		&& 0 <= i__2 ? i__2 : s_rnge("stpool", i__2, "dafana_", (
2442 		ftnlen)2246)];
2443 	stpool[(i__1 = p - 1) < 20 && 0 <= i__1 ? i__1 : s_rnge("stpool",
2444 		i__1, "dafana_", (ftnlen)2247)] = sthead;
2445 	sthead = p;
2446     }
2447     chkout_("DAFCAD", (ftnlen)6);
2448     return 0;
2449 } /* dafana_ */
2450 
dafana_(integer * handle,doublereal * sum,char * name__,doublereal * data,integer * n,ftnlen name_len)2451 /* Subroutine */ int dafana_(integer *handle, doublereal *sum, char *name__,
2452 	doublereal *data, integer *n, ftnlen name_len)
2453 {
2454     return dafana_0_(0, handle, sum, name__, data, n, name_len);
2455     }
2456 
dafbna_(integer * handle,doublereal * sum,char * name__,ftnlen name_len)2457 /* Subroutine */ int dafbna_(integer *handle, doublereal *sum, char *name__,
2458 	ftnlen name_len)
2459 {
2460     return dafana_0_(1, handle, sum, name__, (doublereal *)0, (integer *)0,
2461 	    name_len);
2462     }
2463 
dafada_(doublereal * data,integer * n)2464 /* Subroutine */ int dafada_(doublereal *data, integer *n)
2465 {
2466     return dafana_0_(2, (integer *)0, (doublereal *)0, (char *)0, data, n, (
2467 	    ftnint)0);
2468     }
2469 
dafena_(void)2470 /* Subroutine */ int dafena_(void)
2471 {
2472     return dafana_0_(3, (integer *)0, (doublereal *)0, (char *)0, (doublereal
2473 	    *)0, (integer *)0, (ftnint)0);
2474     }
2475 
dafcad_(integer * handle)2476 /* Subroutine */ int dafcad_(integer *handle)
2477 {
2478     return dafana_0_(4, handle, (doublereal *)0, (char *)0, (doublereal *)0, (
2479 	    integer *)0, (ftnint)0);
2480     }
2481 
2482