1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
const VERIDX: i32 = 1;
const LLBIDX: i32 = (VERIDX + 1);
const LLEIDX: i32 = (LLBIDX + 1);
const NULPTR: i32 = -1;
const BWDIDX: i32 = 1;
const FWDIDX: i32 = (BWDIDX + 1);
const IBSIDX: i32 = (FWDIDX + 1);
const ISZIDX: i32 = (IBSIDX + 1);
const DBSIDX: i32 = (ISZIDX + 1);
const DSZIDX: i32 = (DBSIDX + 1);
const CBSIDX: i32 = (DSZIDX + 1);
const CSZIDX: i32 = (CBSIDX + 1);
const DLADSZ: i32 = CSZIDX;
const FMTVER: i32 = 1000000;
const NCHREC: i32 = 1024;
/// DLA, find previous segment
///
/// Find the segment preceding a specified segment in a DLA file.
///
/// # Required Reading
///
/// * [DAS](crate::required_reading::das)
/// * [DLA](crate::required_reading::dla)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// HANDLE I Handle of open DLA file.
/// DLADSC I Descriptor of a segment in DLA file.
/// PRVDSC O Descriptor of previous segment in DLA file.
/// FOUND O Flag indicating whether a segment was found.
/// ```
///
/// # Detailed Input
///
/// ```text
/// HANDLE is the integer handle associated with the file to be
/// searched. This handle is used to identify the file in
/// subsequent calls to other DLA or DAS routines.
///
/// DLADSC is the descriptor of a DLA segment in the file
/// associated with HANDLE. The descriptor of the
/// segment preceding DLADSC is sought.
///
/// The segment descriptor layout is:
///
/// +---------------+
/// | BACKWARD PTR | Linked list backward pointer
/// +---------------+
/// | FORWARD PTR | Linked list forward pointer
/// +---------------+
/// | BASE INT ADDR | Base DAS integer address
/// +---------------+
/// | INT COMP SIZE | Size of integer segment component
/// +---------------+
/// | BASE DP ADDR | Base DAS d.p. address
/// +---------------+
/// | DP COMP SIZE | Size of d.p. segment component
/// +---------------+
/// | BASE CHR ADDR | Base DAS character address
/// +---------------+
/// | CHR COMP SIZE | Size of character segment component
/// +---------------+
/// ```
///
/// # Detailed Output
///
/// ```text
/// PRVDSC is the descriptor of the DLA segment preceding the
/// segment associated with the input argument DLADSC.
///
/// PRVDSC is valid only if the output argument FOUND is
/// .TRUE.
///
/// FOUND is a logical flag indicating whether the previous
/// segment was found. FOUND has the value .TRUE. if the
/// segment was found; otherwise FOUND is .FALSE.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the input file handle is invalid, an error is
/// signaled by a routine in the call tree of this routine.
///
/// 2) If a failure occurs while reading the DLA file, an error
/// is signaled by a routine in the call tree of this routine.
/// ```
///
/// # Files
///
/// ```text
/// See description of input argument HANDLE.
/// ```
///
/// # Particulars
///
/// ```text
/// DLA files are built using the DAS low-level format; DLA files are
/// a specialized type of DAS file in which data are organized as a
/// doubly linked list of segments. Each segment's data belong to
/// contiguous components of character, double precision, and integer
/// type.
///
/// This routine supports backward traversal of a DLA file's segment
/// list. A backward traversal may be started from any segment in
/// the file; it is not necessary to call DLABBS first. The role of
/// DLABBS is simply to return the descriptor of the last segment in
/// the file.
/// ```
///
/// # Examples
///
/// ```text
/// The numerical results shown for this example may differ across
/// platforms. The results depend on the SPICE kernels used as
/// input, the compiler and supporting libraries, and the machine
/// specific arithmetic implementation.
///
/// 1) Open a DLA file for read access, traverse the segment
/// list from back to front, and display segment address
/// and size attributes.
///
///
/// Example code begins here.
///
///
/// PROGRAM DLAFPS_EX1
/// IMPLICIT NONE
///
/// INCLUDE 'dla.inc'
///
/// C
/// C Local parameters
/// C
/// INTEGER FILSIZ
/// PARAMETER ( FILSIZ = 255 )
///
/// C
/// C Local variables
/// C
/// CHARACTER*(FILSIZ) FNAME
///
/// INTEGER CURRNT ( DLADSZ )
/// INTEGER DLADSC ( DLADSZ )
/// INTEGER HANDLE
/// INTEGER NSEGS
/// INTEGER SEGNO
///
/// LOGICAL FOUND
///
/// C
/// C Prompt for the name of the file to search.
/// C
/// CALL PROMPT ( 'Name of DLA file > ', FNAME )
///
/// C
/// C Open the DLA file for read access. Since DLA
/// C files use the DAS architecture, we can use DAS
/// C routines to open and close the file.
/// C
/// CALL DASOPR ( FNAME, HANDLE )
///
/// C
/// C Count the segments in the file; this allows us
/// C to label the segments in our display.
/// C
/// NSEGS = 0
/// CALL DLABBS ( HANDLE, DLADSC, FOUND )
///
/// DO WHILE ( FOUND )
///
/// NSEGS = NSEGS + 1
/// CALL MOVEI ( DLADSC, DLADSZ, CURRNT )
/// CALL DLAFPS ( HANDLE, CURRNT, DLADSC, FOUND )
///
/// END DO
///
/// C
/// C Begin a backward search. Let DLADSC contain
/// C the descriptor of the last segment.
/// C
/// SEGNO = NSEGS + 1
///
/// CALL DLABBS ( HANDLE, DLADSC, FOUND )
///
/// DO WHILE ( FOUND )
/// C
/// C Display the contents of the current segment
/// C descriptor.
/// C
/// SEGNO = SEGNO - 1
///
/// WRITE (*,*) ' '
/// WRITE (*,*) ' '
/// WRITE (*,*) 'Segment number = ', SEGNO
/// WRITE (*,*) ' '
/// WRITE (*,*) 'Backward segment pointer = ',
/// . DLADSC(BWDIDX)
/// WRITE (*,*) 'Forward segment pointer = ',
/// . DLADSC(FWDIDX)
/// WRITE (*,*) 'Character component base address = ',
/// . DLADSC(CBSIDX)
/// WRITE (*,*) 'Character component size = ',
/// . DLADSC(CSZIDX)
/// WRITE (*,*) 'D.p. base address = ',
/// . DLADSC(DBSIDX)
/// WRITE (*,*) 'D.p. component size = ',
/// . DLADSC(DSZIDX)
/// WRITE (*,*) 'Integer base address = ',
/// . DLADSC(IBSIDX)
/// WRITE (*,*) 'Integer component size = ',
/// . DLADSC(ISZIDX)
/// WRITE (*,*) ' '
///
/// C
/// C Find the previous segment.
/// C
/// C To avoid using DLADSC as both input and output
/// C in the following call (this use is not allowed
/// C by the ANSI Fortran 77 standard), we copy DLADSC
/// C into the variable CURRNT. We then find the
/// C segment preceding CURRNT.
/// C
/// CALL MOVEI ( DLADSC, DLADSZ, CURRNT )
/// CALL DLAFPS ( HANDLE, CURRNT, DLADSC, FOUND )
///
/// END DO
///
/// C
/// C Close the file using the DAS close routine.
/// C
/// CALL DASCLS ( HANDLE )
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, using the DSK file named phobos512.bds, the output
/// was:
///
///
/// Name of DLA file > phobos512.bds
///
///
/// Segment number = 1
///
/// Backward segment pointer = -1
/// Forward segment pointer = -1
/// Character component base address = 0
/// Character component size = 0
/// D.p. base address = 0
/// D.p. component size = 4737076
/// Integer base address = 11
/// Integer component size = 29692614
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 06-JUL-2021 (JDR)
///
/// Changed input argument name DESCR to DLADSC for consistency
/// with other routines.
///
/// Edited the header to comply with NAIF standard.
/// Added solution for code example.
///
/// - SPICELIB Version 1.0.0, 06-JAN-2017 (NJB)
///
/// Original version 21-APR-2010 (NJB)
/// ```
pub fn dlafps(
ctx: &mut SpiceContext,
handle: i32,
dladsc: &[i32],
prvdsc: &mut [i32],
found: &mut bool,
) -> crate::Result<()> {
DLAFPS(handle, dladsc, prvdsc, found, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure DLAFPS ( DLA, find previous segment )
pub fn DLAFPS(
HANDLE: i32,
DLADSC: &[i32],
PRVDSC: &mut [i32],
FOUND: &mut bool,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let DLADSC = DummyArray::new(DLADSC, 1..);
let mut PRVDSC = DummyArrayMut::new(PRVDSC, 1..);
let mut BWD: i32 = 0;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"DLAFPS", ctx)?;
//
// Nothing found yet.
//
*FOUND = false;
//
// Extract the backward pointer from the segment descriptor.
//
BWD = DLADSC[BWDIDX];
if (BWD == NULPTR) {
//
// There is no segment preceding the input segment.
//
CHKOUT(b"DLAFPS", ctx)?;
return Ok(());
}
//
// Look up the previous descriptor
//
DASRDI(
HANDLE,
BWD,
((BWD + DLADSZ) - 1),
PRVDSC.as_slice_mut(),
ctx,
)?;
*FOUND = true;
CHKOUT(b"DLAFPS", ctx)?;
Ok(())
}