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