1 /* dlabns.f -- translated by f2c (version 19980913).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include "f2c.h"
7
8 /* Table of constant values */
9
10 static integer c__2 = 2;
11 static integer c__3 = 3;
12 static integer c_n1 = -1;
13 static integer c__8 = 8;
14
15 /* $Procedure DLABNS ( DLA, begin new segment ) */
dlabns_(integer * handle)16 /* Subroutine */ int dlabns_(integer *handle)
17 {
18 integer addr__, this__;
19 extern /* Subroutine */ int chkin_(char *, ftnlen), filli_(integer *,
20 integer *, integer *);
21 integer descr[8], lastc, lastd, lasti;
22 extern logical failed_(void);
23 extern /* Subroutine */ int dasadi_(integer *, integer *, integer *),
24 daslla_(integer *, integer *, integer *, integer *), dasrdi_(
25 integer *, integer *, integer *, integer *), dasudi_(integer *,
26 integer *, integer *, integer *), dassih_(integer *, char *,
27 ftnlen), chkout_(char *, ftnlen);
28 extern logical return_(void);
29 integer sgptrs[2];
30
31 /* $ Abstract */
32
33 /* Begin a new segment in a DLA file. */
34
35 /* $ Disclaimer */
36
37 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
38 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
39 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
40 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
41 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
42 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
43 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
44 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
45 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
46 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
47
48 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
49 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
50 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
51 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
52 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
53 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
54
55 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
56 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
57 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
58 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
59
60 /* $ Required_Reading */
61
62 /* DAS */
63 /* DLA */
64
65 /* $ Keywords */
66
67 /* DAS */
68 /* DLA */
69 /* FILES */
70
71 /* $ Declarations */
72
73 /* Include file dla.inc */
74
75 /* This include file declares parameters for DLA format */
76 /* version zero. */
77
78 /* Version 3.0.1 17-OCT-2016 (NJB) */
79
80 /* Corrected comment: VERIDX is now described as a DAS */
81 /* integer address rather than a d.p. address. */
82
83 /* Version 3.0.0 20-JUN-2006 (NJB) */
84
85 /* Changed name of parameter DSCSIZ to DLADSZ. */
86
87 /* Version 2.0.0 09-FEB-2005 (NJB) */
88
89 /* Changed descriptor layout to make backward pointer */
90 /* first element. Updated DLA format version code to 1. */
91
92 /* Added parameters for format version and number of bytes per */
93 /* DAS comment record. */
94
95 /* Version 1.0.0 28-JAN-2004 (NJB) */
96
97
98 /* DAS integer address of DLA version code. */
99
100
101 /* Linked list parameters */
102
103 /* Logical arrays (aka "segments") in a DAS linked array (DLA) file */
104 /* are organized as a doubly linked list. Each logical array may */
105 /* actually consist of character, double precision, and integer */
106 /* components. A component of a given data type occupies a */
107 /* contiguous range of DAS addresses of that type. Any or all */
108 /* array components may be empty. */
109
110 /* The segment descriptors in a SPICE DLA (DAS linked array) file */
111 /* are connected by a doubly linked list. Each node of the list is */
112 /* represented by a pair of integers acting as forward and backward */
113 /* pointers. Each pointer pair occupies the first two integers of a */
114 /* segment descriptor in DAS integer address space. The DLA file */
115 /* contains pointers to the first integers of both the first and */
116 /* last segment descriptors. */
117
118 /* At the DLA level of a file format implementation, there is */
119 /* no knowledge of the data contents. Hence segment descriptors */
120 /* provide information only about file layout (in contrast with */
121 /* the DAF system). Metadata giving specifics of segment contents */
122 /* are stored within the segments themselves in DLA-based file */
123 /* formats. */
124
125
126 /* Parameter declarations follow. */
127
128 /* DAS integer addresses of first and last segment linked list */
129 /* pointer pairs. The contents of these pointers */
130 /* are the DAS addresses of the first integers belonging */
131 /* to the first and last link pairs, respectively. */
132
133 /* The acronyms "LLB" and "LLE" denote "linked list begin" */
134 /* and "linked list end" respectively. */
135
136
137 /* Null pointer parameter. */
138
139
140 /* Segment descriptor parameters */
141
142 /* Each segment descriptor occupies a contiguous */
143 /* range of DAS integer addresses. */
144
145 /* The segment descriptor layout is: */
146
147 /* +---------------+ */
148 /* | BACKWARD PTR | Linked list backward pointer */
149 /* +---------------+ */
150 /* | FORWARD PTR | Linked list forward pointer */
151 /* +---------------+ */
152 /* | BASE INT ADDR | Base DAS integer address */
153 /* +---------------+ */
154 /* | INT COMP SIZE | Size of integer segment component */
155 /* +---------------+ */
156 /* | BASE DP ADDR | Base DAS d.p. address */
157 /* +---------------+ */
158 /* | DP COMP SIZE | Size of d.p. segment component */
159 /* +---------------+ */
160 /* | BASE CHR ADDR | Base DAS character address */
161 /* +---------------+ */
162 /* | CHR COMP SIZE | Size of character segment component */
163 /* +---------------+ */
164
165 /* Parameters defining offsets for segment descriptor elements */
166 /* follow. */
167
168
169 /* Descriptor size: */
170
171
172 /* Other DLA parameters: */
173
174
175 /* DLA format version. (This number is expected to occur very */
176 /* rarely at integer address VERIDX in uninitialized DLA files.) */
177
178
179 /* Characters per DAS comment record. */
180
181
182 /* End of include file dla.inc */
183
184 /* $ Brief_I/O */
185
186 /* Variable I/O Description */
187 /* -------- --- -------------------------------------------------- */
188 /* HANDLE I Handle of open DLA file. */
189
190 /* $ Detailed_Input */
191
192 /* HANDLE is the integer handle associated with the DLA file to */
193 /* be updated. This handle is used to identify the file */
194 /* in subsequent calls to other DLA or DAS routines. */
195
196 /* The DLA file must be open for write access. A new DLA */
197 /* segment is started in the indicated file. The file */
198 /* is left open, since normally data will be written to */
199 /* the file following a call to this routine. */
200
201 /* $ Detailed_Output */
202
203 /* None. See the Particulars and Examples header sections for */
204 /* a description of the actions performed by this routine. */
205
206 /* $ Parameters */
207
208 /* None. */
209
210 /* $ Exceptions */
211
212 /* 1) If the input file handle does not refer to a DAS file that is */
213 /* open for write access, the error will be diagnosed by routines */
214 /* in the call tree of this routine. */
215
216 /* 2) If an error occurs while reading or writing to the DLA file, */
217 /* the error will be diagnosed by routines in the call tree of */
218 /* this routine. */
219
220 /* $ Files */
221
222 /* See description of input argument HANDLE. */
223
224 /* $ Particulars */
225
226 /* DLA files are built using the DAS low-level format; DLA files are */
227 /* a specialized type of DAS file in which data are organized as a */
228 /* doubly linked list of segments. Each segment's data belong to */
229 /* contiguous components of character, double precision, and integer */
230 /* type. */
231
232 /* This routine supports creation of a DLA segment. DLA segments */
233 /* are created by appending data to the DAS integer, double */
234 /* precision, and character address spaces of a DLA file. The new */
235 /* segment's descriptor is located immediately before the integer */
236 /* component of the segment's data. */
237
238 /* When a new segment is added to a DLA file, the segment is */
239 /* inserted into the file's doubly linked segment list. If the new */
240 /* segment is the first, the DLA file's first and last list entry */
241 /* pointers are updated to point to the new segment; specifically, */
242 /* these pointers point to the first integer of the new segment's */
243 /* descriptor. The backward pointer of the new segment is set to */
244 /* null in this case. */
245
246 /* If the new segment is not the first, the DLA file's list end */
247 /* pointer is updated to point to the new segment, and the forward */
248 /* pointer of the previous segment also is updated to point to the */
249 /* first integer of the new segment's descriptor. The backward */
250 /* pointer of the new segment points to the first integer of the */
251 /* previous segment's descriptor. */
252
253 /* The normal sequence of operations required to create a DLA */
254 /* segment is as follows: */
255
256 /* Call DLAOPN to create a new, empty DLA file. */
257
258 /* For each segment to be created, */
259
260 /* Call DLABNS to begin a segment. */
261
262 /* Use the DAS "add" and "update" routines to populate */
263 /* the segment with data. */
264
265 /* Call DLAENS to end the segment. */
266
267 /* Call DASCLS to segregate and close the DLA file. */
268
269
270 /* $ Examples */
271
272 /* 1) Create a DLA file containing one segment; the segment */
273 /* contains character, double precision, and integer data. */
274 /* After writing and closing the file, open the file for */
275 /* read access; dump the data to standard output. */
276
277
278 /* PROGRAM EX1 */
279 /* IMPLICIT NONE */
280
281 /* INCLUDE 'dla.inc' */
282
283 /* C */
284 /* C Local parameters */
285 /* C */
286 /* CHARACTER*(*) DLA */
287 /* PARAMETER ( DLA = 'test.dla' ) */
288
289 /* INTEGER IFNLEN */
290 /* PARAMETER ( IFNLEN = 60 ) */
291
292 /* INTEGER LNSIZE */
293 /* PARAMETER ( LNSIZE = 80 ) */
294
295 /* INTEGER MAXC */
296 /* PARAMETER ( MAXC = 5 ) */
297
298 /* INTEGER MAXD */
299 /* PARAMETER ( MAXD = 50 ) */
300
301 /* INTEGER MAXI */
302 /* PARAMETER ( MAXI = 100 ) */
303
304 /* C */
305 /* C Local variables */
306 /* C */
307 /* CHARACTER*(LNSIZE) CVALS ( MAXC ) */
308 /* CHARACTER*(LNSIZE) CVALS2 ( MAXC ) */
309 /* CHARACTER*(IFNLEN) IFNAME */
310
311 /* DOUBLE PRECISION DVALS ( MAXD ) */
312 /* DOUBLE PRECISION DVALS2 ( MAXD ) */
313
314 /* INTEGER BASE */
315 /* INTEGER DESCR ( DLADSZ ) */
316 /* INTEGER HANDLE */
317 /* INTEGER I */
318 /* INTEGER IVALS ( MAXI ) */
319 /* INTEGER IVALS2 ( MAXI ) */
320 /* INTEGER J */
321 /* INTEGER K */
322 /* INTEGER N */
323 /* INTEGER NCOMCH */
324
325 /* LOGICAL FOUND */
326
327 /* C */
328 /* C Set the internal file name. Don't reserve characters in */
329 /* C the DAS comment area. */
330 /* C */
331 /* IFNAME = 'Example DLA file for testing' */
332 /* NCOMCH = 0 */
333
334 /* C */
335 /* C Open a new DLA file. */
336 /* C */
337 /* CALL DLAOPN ( DLA, 'DLA', IFNAME, NCOMCH, HANDLE ) */
338
339 /* C */
340 /* C Begin a new segment. */
341 /* C */
342 /* CALL DLABNS ( HANDLE ) */
343
344 /* C */
345 /* C Add character data to the segment. */
346 /* C */
347 /* DO I = 1, MAXC */
348
349 /* DO J = 1, LNSIZE */
350
351 /* K = MOD( J+I-1, 10 ) */
352
353 /* CALL INTSTR ( K, CVALS(I)(J:J) ) */
354
355 /* END DO */
356
357 /* END DO */
358
359 /* CALL DASADC ( HANDLE, MAXC*LNSIZE, 1, LNSIZE, CVALS ) */
360
361 /* C */
362 /* C Add integer and double precision data to the segment. */
363 /* C */
364 /* DO I = 1, MAXI */
365 /* IVALS(I) = I */
366 /* END DO */
367
368 /* CALL DASADI ( HANDLE, MAXI, IVALS ) */
369
370 /* DO I = 1, MAXD */
371 /* DVALS(I) = I */
372 /* END DO */
373
374 /* CALL DASADD ( HANDLE, MAXD, DVALS ) */
375
376 /* C */
377 /* C End the segment. */
378 /* C */
379 /* CALL DLAENS ( HANDLE ) */
380
381 /* C */
382 /* C Close the file. The routine DASCLS flushes the DAS */
383 /* C buffers and segregates the file before closing it. */
384 /* C */
385 /* CALL DASCLS ( HANDLE ) */
386
387 /* C */
388 /* C Now read the file and check the data. */
389 /* C */
390 /* CALL DASOPR ( DLA, HANDLE ) */
391
392 /* C */
393 /* C Obtain the segment descriptor for the sole segment */
394 /* C in the file. We need not check the found flag */
395 /* C in this case because we know there is one segment */
396 /* C in the file. */
397 /* C */
398 /* CALL DLABFS ( HANDLE, DESCR, FOUND ) */
399
400 /* C */
401 /* C Fetch character data from the segment. Obtain the */
402 /* C base address of the character data and the */
403 /* C character count from the descriptor. */
404 /* C */
405 /* BASE = DESCR(CBSIDX) */
406 /* N = DESCR(CSZIDX) */
407
408 /* CALL DASRDC ( HANDLE, BASE+1, BASE+N, 1, LNSIZE, CVALS2 ) */
409
410 /* C */
411 /* C Display the character data. */
412 /* C */
413 /* WRITE (*,*) ' ' */
414 /* WRITE (*,*) 'Character array' */
415
416 /* DO I = 1, N/LNSIZE */
417 /* WRITE (*,*) CVALS2(I) */
418 /* END DO */
419
420 /* C */
421 /* C Fetch and display the integer and double precision data. */
422 /* C */
423 /* BASE = DESCR(IBSIDX) */
424 /* N = DESCR(ISZIDX) */
425
426 /* CALL DASRDI( HANDLE, BASE+1, BASE+N, IVALS2 ) */
427
428 /* WRITE (*,*) ' ' */
429 /* WRITE (*,*) 'Integer array' */
430 /* WRITE (*,*) IVALS2 */
431
432
433 /* BASE = DESCR(DBSIDX) */
434 /* N = DESCR(DSZIDX) */
435
436 /* CALL DASRDD( HANDLE, BASE+1, BASE+N, DVALS2 ) */
437
438 /* WRITE (*,*) ' ' */
439 /* WRITE (*,*) 'Double precision array' */
440 /* WRITE (*,*) DVALS2 */
441
442 /* C */
443 /* C Close the file. This step is unnecessary in this */
444 /* C program, but is a good practice in general */
445 /* C because closing the file frees resources. */
446 /* C */
447 /* CALL DASCLS ( HANDLE ) */
448
449 /* END */
450
451
452 /* $ Restrictions */
453
454 /* None. */
455
456 /* $ Literature_References */
457
458 /* None. */
459
460 /* $ Author_and_Institution */
461
462 /* N.J. Bachman (JPL) */
463
464 /* $ Version */
465
466 /* - SPICELIB Version 1.0.0, 08-FEB-2017 (NJB) */
467
468 /* Updated version info. */
469
470 /* 13-JUL-2012 (NJB) */
471
472 /* Bug fix: deleted unused line of code. */
473 /* Fixed some header typos. */
474
475 /* 08-OCT-2009 (NJB) */
476
477 /* Updated header. */
478
479 /* 11-FEB-2005 (NJB) */
480
481 /* -& */
482 /* $ Index_Entries */
483
484 /* begin new segment in dla file */
485
486 /* -& */
487
488 /* SPICELIB functions */
489
490
491 /* Local parameters */
492
493
494 /* Local variables */
495
496
497 /* Standard SPICE error handling. */
498
499 if (return_()) {
500 return 0;
501 }
502 chkin_("DLABNS", (ftnlen)6);
503
504 /* Make sure the input handle refers to a DAS file that */
505 /* is open for write access. */
506
507 dassih_(handle, "WRITE", (ftnlen)5);
508 if (failed_()) {
509 chkout_("DLABNS", (ftnlen)6);
510 return 0;
511 }
512
513 /* Look up the pointers to the first and last DLA segment */
514 /* descriptors in the file. If no segments are present, */
515 /* the pointers will contain the value NULPTR. */
516
517 dasrdi_(handle, &c__2, &c__3, sgptrs);
518
519 /* Find the last DAS logical addresses in use for each data type. */
520
521 daslla_(handle, &lastc, &lastd, &lasti);
522
523 /* Initialize a DLA descriptor with null values. If this */
524 /* is not the first segment in the file, the backward pointer */
525 /* must be set to point to the previous descriptor. It's */
526 /* valid to overwrite the descriptor pointer in either case */
527 /* due to the initialization of the file's last segment pointer */
528 /* to NULPTR. */
529
530 filli_(&c_n1, &c__8, descr);
531 descr[0] = sgptrs[1];
532
533 /* Set the descriptor's component base addresses now. The */
534 /* base addresses are *predecessors* of the first address of */
535 /* each data type. This choice slightly simplifies arithmetic */
536 /* needed to express the address range occupied by a segment */
537 /* component: the range is */
538
539 /* base + 1 : base + size */
540
541 /* For the integer address, add on the size of the descriptor */
542 /* we're about to write. */
543
544 descr[2] = lasti + 8;
545 descr[4] = lastd;
546 descr[6] = lastc;
547
548 /* Append the descriptor to the file. */
549
550 dasadi_(handle, &c__8, descr);
551
552 /* THIS is the pointer to the current descriptor. */
553
554 this__ = lasti + 1;
555
556 /* If this is not the first segment, the forward pointer of the */
557 /* previous descriptor must be updated to point to this descriptor. */
558
559 if (sgptrs[1] != -1) {
560 addr__ = sgptrs[1] + 1;
561 dasudi_(handle, &addr__, &addr__, &this__);
562 }
563
564 /* Update the segment list pointers in the file. The begin pointer */
565 /* must be updated only if it's null. The end pointer will point to */
566 /* this segment. */
567
568 if (sgptrs[0] == -1) {
569 dasudi_(handle, &c__2, &c__2, &this__);
570 }
571 dasudi_(handle, &c__3, &c__3, &this__);
572
573 /* Leave the file open. The segment is now ready to be */
574 /* populated with data. The routines DASADC, DASADD, and */
575 /* DASADI should be used to append data to the segment. */
576
577 chkout_("DLABNS", (ftnlen)6);
578 return 0;
579 } /* dlabns_ */
580
581