1 /* dlabbs.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 DLABBS ( DLA, begin backward search ) */
dlabbs_(integer * handle,integer * descr,logical * found)13 /* Subroutine */ int dlabbs_(integer *handle, integer *descr, logical *found)
14 {
15     /* System generated locals */
16     integer i__1;
17 
18     /* Local variables */
19     integer this__;
20     extern /* Subroutine */ int chkin_(char *, ftnlen);
21     extern logical failed_(void);
22     extern /* Subroutine */ int dasrdi_(integer *, integer *, integer *,
23 	    integer *), chkout_(char *, ftnlen);
24     extern logical return_(void);
25 
26 /* $ Abstract */
27 
28 /*     Begin a backward segment search in a DLA file. */
29 
30 /* $ Disclaimer */
31 
32 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
33 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
34 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
35 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
36 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
37 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
38 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
39 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
40 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
41 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
42 
43 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
44 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
45 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
46 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
47 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
48 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
49 
50 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
51 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
52 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
53 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
54 
55 /* $ Required_Reading */
56 
57 /*     DAS */
58 /*     DLA */
59 
60 /* $ Keywords */
61 
62 /*     DAS */
63 /*     DLA */
64 /*     FILES */
65 
66 /* $ Declarations */
67 
68 /*     Include file dla.inc */
69 
70 /*     This include file declares parameters for DLA format */
71 /*     version zero. */
72 
73 /*        Version 3.0.1 17-OCT-2016 (NJB) */
74 
75 /*           Corrected comment: VERIDX is now described as a DAS */
76 /*           integer address rather than a d.p. address. */
77 
78 /*        Version 3.0.0 20-JUN-2006 (NJB) */
79 
80 /*           Changed name of parameter DSCSIZ to DLADSZ. */
81 
82 /*        Version 2.0.0 09-FEB-2005 (NJB) */
83 
84 /*           Changed descriptor layout to make backward pointer */
85 /*           first element.  Updated DLA format version code to 1. */
86 
87 /*           Added parameters for format version and number of bytes per */
88 /*           DAS comment record. */
89 
90 /*        Version 1.0.0 28-JAN-2004 (NJB) */
91 
92 
93 /*     DAS integer address of DLA version code. */
94 
95 
96 /*     Linked list parameters */
97 
98 /*     Logical arrays (aka "segments") in a DAS linked array (DLA) file */
99 /*     are organized as a doubly linked list.  Each logical array may */
100 /*     actually consist of character, double precision, and integer */
101 /*     components.  A component of a given data type occupies a */
102 /*     contiguous range of DAS addresses of that type.  Any or all */
103 /*     array components may be empty. */
104 
105 /*     The segment descriptors in a SPICE DLA (DAS linked array) file */
106 /*     are connected by a doubly linked list.  Each node of the list is */
107 /*     represented by a pair of integers acting as forward and backward */
108 /*     pointers.  Each pointer pair occupies the first two integers of a */
109 /*     segment descriptor in DAS integer address space.  The DLA file */
110 /*     contains pointers to the first integers of both the first and */
111 /*     last segment descriptors. */
112 
113 /*     At the DLA level of a file format implementation, there is */
114 /*     no knowledge of the data contents.  Hence segment descriptors */
115 /*     provide information only about file layout (in contrast with */
116 /*     the DAF system).  Metadata giving specifics of segment contents */
117 /*     are stored within the segments themselves in DLA-based file */
118 /*     formats. */
119 
120 
121 /*     Parameter declarations follow. */
122 
123 /*     DAS integer addresses of first and last segment linked list */
124 /*     pointer pairs.  The contents of these pointers */
125 /*     are the DAS addresses of the first integers belonging */
126 /*     to the first and last link pairs, respectively. */
127 
128 /*     The acronyms "LLB" and "LLE" denote "linked list begin" */
129 /*     and "linked list end" respectively. */
130 
131 
132 /*     Null pointer parameter. */
133 
134 
135 /*     Segment descriptor parameters */
136 
137 /*     Each segment descriptor occupies a contiguous */
138 /*     range of DAS integer addresses. */
139 
140 /*        The segment descriptor layout is: */
141 
142 /*           +---------------+ */
143 /*           | BACKWARD PTR  | Linked list backward pointer */
144 /*           +---------------+ */
145 /*           | FORWARD PTR   | Linked list forward pointer */
146 /*           +---------------+ */
147 /*           | BASE INT ADDR | Base DAS integer address */
148 /*           +---------------+ */
149 /*           | INT COMP SIZE | Size of integer segment component */
150 /*           +---------------+ */
151 /*           | BASE DP ADDR  | Base DAS d.p. address */
152 /*           +---------------+ */
153 /*           | DP COMP SIZE  | Size of d.p. segment component */
154 /*           +---------------+ */
155 /*           | BASE CHR ADDR | Base DAS character address */
156 /*           +---------------+ */
157 /*           | CHR COMP SIZE | Size of character segment component */
158 /*           +---------------+ */
159 
160 /*     Parameters defining offsets for segment descriptor elements */
161 /*     follow. */
162 
163 
164 /*     Descriptor size: */
165 
166 
167 /*     Other DLA parameters: */
168 
169 
170 /*     DLA format version.  (This number is expected to occur very */
171 /*     rarely at integer address VERIDX in uninitialized DLA files.) */
172 
173 
174 /*     Characters per DAS comment record. */
175 
176 
177 /*     End of include file dla.inc */
178 
179 /* $ Brief_I/O */
180 
181 /*     Variable  I/O  Description */
182 /*     --------  ---  -------------------------------------------------- */
183 /*     HANDLE     I   Handle of open DLA file. */
184 /*     DESCR      O   Descriptor of last segment in DLA file. */
185 /*     FOUND      O   Flag indicating whether a segment was found. */
186 
187 /* $ Detailed_Input */
188 
189 /*     HANDLE      is the integer handle associated with the file to be */
190 /*                 searched. This handle is used to identify the file in */
191 /*                 subsequent calls to other DLA or DAS routines. */
192 
193 /* $ Detailed_Output */
194 
195 /*     DESCR       is the descriptor of the last DLA segment in the */
196 /*                 file associated with HANDLE. */
197 
198 /*                 The segment descriptor layout is: */
199 
200 /*                  +---------------+ */
201 /*                  | BACKWARD PTR  | Linked list backward pointer */
202 /*                  +---------------+ */
203 /*                  | FORWARD PTR   | Linked list forward pointer */
204 /*                  +---------------+ */
205 /*                  | BASE INT ADDR | Base DAS integer address */
206 /*                  +---------------+ */
207 /*                  | INT COMP SIZE | Size of integer segment component */
208 /*                  +---------------+ */
209 /*                  | BASE DP ADDR  | Base DAS d.p. address */
210 /*                  +---------------+ */
211 /*                  | DP COMP SIZE  | Size of d.p. segment component */
212 /*                  +---------------+ */
213 /*                  | BASE CHR ADDR | Base DAS character address */
214 /*                  +---------------+ */
215 /*                  | CHR COMP SIZE | Size of character segment component */
216 /*                  +---------------+ */
217 
218 /*                 DESCR is valid only if the output argument FOUND is */
219 /*                 .TRUE. */
220 
221 
222 /*     FOUND       is a logical flag indicating whether a segment was */
223 /*                 found.  FOUND has the value .TRUE. if the file */
224 /*                 contains at least one segment; otherwise FOUND is */
225 /*                 .FALSE. */
226 
227 /* $ Parameters */
228 
229 /*     None. */
230 
231 /* $ Exceptions */
232 
233 /*     1) If the input file handle is invalid, the error will be */
234 /*        diagnosed by routines in the call tree of this routine. */
235 
236 /*     2) If an error occurs while reading the DLA file, the error */
237 /*        will be diagnosed by routines in the call tree of this */
238 /*        routine. */
239 
240 /*     3) If the input descriptor is invalid, this routine will */
241 /*        fail in an unpredictable manner. */
242 
243 /* $ Files */
244 
245 /*     See description of input argument HANDLE. */
246 
247 /* $ Particulars */
248 
249 /*     DLA files are built using the DAS low-level format; DLA files are */
250 /*     a specialized type of DAS file in which data are organized as a */
251 /*     doubly linked list of segments.  Each segment's data belong to */
252 /*     contiguous components of character, double precision, and integer */
253 /*     type. */
254 
255 /*     This routine supports backward traversal of a DLA file's segment */
256 /*     list.  Note that it is not necessary to call this routine to */
257 /*     conduct a backward traversal; all that is necessary is to have */
258 /*     access to the last descriptor in the file, which this routine */
259 /*     provides. */
260 
261 /* $ Examples */
262 
263 /*     1)  Open a DLA file for read access, traverse the segment */
264 /*         list from back to front, and display segment address */
265 /*         and size attributes. */
266 
267 
268 /*                  PROGRAM EX1 */
269 /*                  IMPLICIT NONE */
270 
271 /*                  INCLUDE 'dla.inc' */
272 
273 /*            C */
274 /*            C     Local parameters */
275 /*            C */
276 /*                  INTEGER               FILSIZ */
277 /*                  PARAMETER           ( FILSIZ = 255 ) */
278 
279 /*            C */
280 /*            C     Local variables */
281 /*            C */
282 /*                  CHARACTER*(FILSIZ)    FNAME */
283 
284 /*                  INTEGER               CURRNT ( DLADSZ ) */
285 /*                  INTEGER               DESCR  ( DLADSZ ) */
286 /*                  INTEGER               HANDLE */
287 /*                  INTEGER               NSEGS */
288 /*                  INTEGER               SEGNO */
289 
290 /*                  LOGICAL               FOUND */
291 
292 /*            C */
293 /*            C     Prompt for the name of the file to search. */
294 /*            C */
295 /*                  CALL PROMPT ( 'Name of DLA file > ', FNAME ) */
296 
297 /*            C */
298 /*            C     Open the DLA file for read access.  Since DLA */
299 /*            C     files use the DAS architecture, we can use DAS */
300 /*            C     routines to open and close the file. */
301 /*            C */
302 /*                  CALL DASOPR ( FNAME, HANDLE ) */
303 
304 /*            C */
305 /*            C     Count the segments in the file; this allows us */
306 /*            C     to label the segments in our display. */
307 /*            C */
308 /*                  NSEGS = 0 */
309 /*                  CALL DLABBS ( HANDLE, DESCR, FOUND ) */
310 
311 /*                  DO WHILE ( FOUND ) */
312 
313 /*                     NSEGS = NSEGS + 1 */
314 /*                     CALL MOVEI  ( DESCR,  DLADSZ, CURRNT       ) */
315 /*                     CALL DLAFPS ( HANDLE, CURRNT, DESCR, FOUND ) */
316 
317 /*                  END DO */
318 
319 /*            C */
320 /*            C     Begin a backward search.  Let DESCR contain */
321 /*            C     the descriptor of the last segment. */
322 /*            C */
323 /*                  SEGNO = NSEGS + 1 */
324 
325 /*                  CALL DLABBS ( HANDLE, DESCR, FOUND ) */
326 
327 /*                  DO WHILE ( FOUND ) */
328 /*            C */
329 /*            C        Display the contents of the current segment */
330 /*            C        descriptor. */
331 /*            C */
332 /*                     SEGNO = SEGNO - 1 */
333 
334 /*                     WRITE (*,*) ' ' */
335 /*                     WRITE (*,*) ' ' */
336 /*                     WRITE (*,*) 'Segment number = ', SEGNO */
337 /*                     WRITE (*,*) ' ' */
338 /*                     WRITE (*,*) 'Backward segment pointer         = ', */
339 /*                 .               DESCR(BWDIDX) */
340 /*                     WRITE (*,*) 'Forward segment pointer          = ', */
341 /*                 .               DESCR(FWDIDX) */
342 /*                     WRITE (*,*) 'Character component base address = ', */
343 /*                 .               DESCR(CBSIDX) */
344 /*                     WRITE (*,*) 'Character component size         = ', */
345 /*                 .               DESCR(CSZIDX) */
346 /*                     WRITE (*,*) 'D.p. base address                = ', */
347 /*                 .               DESCR(DBSIDX) */
348 /*                     WRITE (*,*) 'D.p. component size              = ', */
349 /*                 .               DESCR(DSZIDX) */
350 /*                     WRITE (*,*) 'Integer base address             = ', */
351 /*                 .               DESCR(IBSIDX) */
352 /*                     WRITE (*,*) 'Integer component size           = ', */
353 /*                 .               DESCR(ISZIDX) */
354 /*                     WRITE (*,*) ' ' */
355 
356 /*            C */
357 /*            C        Find the previous segment. */
358 /*            C */
359 /*            C        To avoid using DESCR as both input and output */
360 /*            C        in the following call (this use is not allowed */
361 /*            C        by the ANSI Fortran 77 standard), we copy DESCR */
362 /*            C        into the variable CURRNT.  We then find the */
363 /*            C        segment preceding CURRNT. */
364 /*            C */
365 /*                     CALL MOVEI  ( DESCR,  DLADSZ, CURRNT       ) */
366 /*                     CALL DLAFPS ( HANDLE, CURRNT, DESCR, FOUND ) */
367 
368 /*                  END DO */
369 
370 /*            C */
371 /*            C     Close the file using the DAS close routine. */
372 /*            C */
373 /*                  CALL DASCLS ( HANDLE ) */
374 
375 /*                  END */
376 
377 
378 /* $ Restrictions */
379 
380 /*     None. */
381 
382 /* $ Literature_References */
383 
384 /*     None. */
385 
386 /* $ Author_and_Institution */
387 
388 /*     N.J. Bachman    (JPL) */
389 
390 /* $ Version */
391 
392 /* -    SPICELIB Version 1.0.0, 21-APR-2010 (NJB) */
393 
394 /* -& */
395 /* $ Index_Entries */
396 
397 /*     begin backward search in dla file */
398 
399 /* -& */
400 
401 /*     SPICELIB functions */
402 
403 
404 /*     Local variables */
405 
406 
407 /*     Standard SPICE error handling. */
408 
409     if (return_()) {
410 	return 0;
411     }
412     chkin_("DLABBS", (ftnlen)6);
413 
414 /*     Nothing found yet. */
415 
416     *found = FALSE_;
417 
418 /*     Look up the pointer to the last DLA segment descriptor in the */
419 /*     file.  Then look up the segment descriptor itself. */
420 
421     dasrdi_(handle, &c__3, &c__3, &this__);
422     if (failed_() || this__ == -1) {
423 
424 /*        If the pointer THIS is null, there are no segments in the */
425 /*        file. */
426 
427 	chkout_("DLABBS", (ftnlen)6);
428 	return 0;
429     }
430 
431 /*     Return the last descriptor. */
432 
433     i__1 = this__ + 7;
434     dasrdi_(handle, &this__, &i__1, descr);
435     *found = TRUE_;
436     chkout_("DLABBS", (ftnlen)6);
437     return 0;
438 } /* dlabbs_ */
439 
440