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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
const IDWLEN: i32 = 8;
const IFNLEN: i32 = 60;
/// DAF, read file record
///
/// Read the contents of the file record of a DAF.
///
/// # Required Reading
///
/// * [DAF](crate::required_reading::daf)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// HANDLE I Handle of an open DAF file.
/// ND O Number of double precision components in summaries.
/// NI O Number of integer components in summaries.
/// IFNAME O Internal file name.
/// FWARD O Forward list pointer.
/// BWARD O Backward list pointer.
/// FREE O Free address pointer.
/// ```
///
/// # Detailed Input
///
/// ```text
/// HANDLE is the handle assigned to a DAF file opened for
/// reading.
/// ```
///
/// # Detailed Output
///
/// ```text
/// ND,
/// NI are the numbers of double precision and integer
/// components, respectively, in each array summary in
/// the specified file.
///
/// IFNAME is the internal file name stored in the first
/// (or file) record of the specified file.
///
/// FWARD is the forward list pointer. This points to the
/// first summary record in the file. (Records between
/// the first record and the first summary record are
/// reserved when the file is created, and are invisible
/// to DAF routines.)
///
/// BWARD is the backward list pointer. This points
/// to the final summary record in the file.
///
/// FREE is the free address pointer. This contains the
/// first free address in the file. (That is, the
/// initial address of the next array to be added
/// to the file.)
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the handle passed to this routine is not the handle of an
/// open DAF file, an error is signaled by a routine in the call
/// tree of this routine.
///
/// 2) If the specified DAF file is not open for read access, an
/// error is signaled by a routine in the call tree of this
/// routine.
///
/// 3) If the specified record cannot (for some reason) be read,
/// the error SPICE(DAFFRNOTFOUND) is signaled.
/// ```
///
/// # Particulars
///
/// ```text
/// The file record of a DAF is the only record that contains
/// any global information about the file. This record is created
/// when the file is created, and is updated only when new arrays
/// are added.
///
/// Like character records, file records are not buffered.
/// ```
///
/// # Examples
///
/// ```text
/// In the following example, the value of the forward list
/// pointer is examined in order to determine the number of
/// reserved records in the DAF. These records are then read
/// and the contents printed to the screen.
///
/// CALL DAFRFR ( HANDLE, ND, NI, IFNAME, FWARD, BWARD, FREE )
/// CALL DAFHLU ( HANDLE, UNIT )
///
/// DO I = 2, FWARD - 1
/// READ (UNIT,REC=I) PRIVATE(1:1000)
/// WRITE (*,*) PRIVATE(1:1000)
/// END DO
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// K.R. Gehringer (JPL)
/// H.A. Neilan (JPL)
/// W.L. Taber (JPL)
/// F.S. Turner (JPL)
/// I.M. Underwood (JPL)
/// E.D. Wright (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 3.2.0, 02-JUL-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 3.1.0, 30-DEC-2009 (EDW)
///
/// Expanded DAFFRNOTFOUND error message to identify the file
/// handle corresponding to the error condition.
///
/// Reordered header sections to conform to SPICE format.
/// Merged the $Revisions sections, now deleted, with $Version.
///
/// - SPICELIB Version 3.0.0, 16-NOV-2001 (FST)
///
/// Updated this routine to utilize interfaces built on
/// the new handle manager to perform I/O operations.
///
/// This routine now utilizes ZZDAFGFR to retrieve information
/// from the file record. As this private interface takes a
/// handle and performs the necessary logical unit to handle
/// mapping, the call to DAFHLU was removed. The DAFSIH call
/// remains, since this insures that HANDLE is known to DAFAH.
///
/// - SPICELIB Version 2.0.0, 04-OCT-1993 (KRG)
///
/// The error SPICE(DAFNOIDWORD) is no longer signaled by this
/// routine. The reason for this is that if DAFSIH returns OK then
/// the handle passed to this routine is indeed a valid DAF file
/// handle, otherwise the error is diagnosed by DAFSIH.
///
/// Added a call to DAFSIH to signal an invalid handle and a test
/// of FAILED () after it. This is to make sure that the DAF file
/// is open for reading. If this call succeeds, we know that we
/// have a valid DAF handle, so there is no need to check FAILED
/// after the call to DAFHLU.
///
/// The variable name DAFWRD was changed to IDWORD.
///
/// Added two new exceptions to the $Exceptions section: 1 and 2.
/// The remaining exception (3) was already present. The exceptions
/// that were added are not new, but are being documented for the
/// first time.
///
///
/// - SPICELIB Version 1.0.3, 06-OCT-1992 (HAN)
///
/// Corrected a typo in the $Brief_I/O section. ND was listed
/// twice as an input, and NI was not listed.
///
/// - SPICELIB Version 1.0.2, 10-MAR-1992 (WLT)
///
/// Comment section for permuted index source lines was added
/// following the header.
///
/// - SPICELIB Version 1.0.1, 22-MAR-1990 (HAN)
///
/// Literature references added to the header.
///
/// - SPICELIB Version 1.0.0, 31-JAN-1990 (IMU)
/// ```
pub fn dafrfr(
ctx: &mut SpiceContext,
handle: i32,
nd: &mut i32,
ni: &mut i32,
ifname: &mut str,
fward: &mut i32,
bward: &mut i32,
free: &mut i32,
) -> crate::Result<()> {
DAFRFR(
handle,
nd,
ni,
fstr::StrBytes::new(ifname).as_mut(),
fward,
bward,
free,
ctx.raw_context(),
)?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure DAFRFR ( DAF, read file record )
pub fn DAFRFR(
HANDLE: i32,
ND: &mut i32,
NI: &mut i32,
IFNAME: &mut [u8],
FWARD: &mut i32,
BWARD: &mut i32,
FREE: &mut i32,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut IDWORD = [b' '; IDWLEN as usize];
let mut FOUND: bool = false;
//
// SPICELIB functions
//
//
// Local Parameters
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"DAFRFR", ctx)?;
}
//
// Do some initializations
//
fstr::assign(&mut IDWORD, b" ");
//
// Check to be sure that HANDLE is attached to a file that is open
// with read access. If the call fails, check out and return.
//
DAFSIH(HANDLE, b"READ", ctx)?;
if FAILED(ctx) {
CHKOUT(b"DAFRFR", ctx)?;
return Ok(());
}
//
// Retrieve all but the internal file name directly from the
// file record. Read the internal file name into a temporary
// string, to be sure of the length. Check FOUND.
//
ZZDAFGFR(
HANDLE,
&mut IDWORD,
ND,
NI,
IFNAME,
FWARD,
BWARD,
FREE,
&mut FOUND,
ctx,
)?;
if !FOUND {
SETMSG(b"File record not found for file handle #1. Check if program code uses handle #2 for a read or write operation.", ctx);
ERRINT(b"#1", HANDLE, ctx);
ERRINT(b"#2", HANDLE, ctx);
SIGERR(b"SPICE(DAFFRNOTFOUND)", ctx)?;
CHKOUT(b"DAFRFR", ctx)?;
return Ok(());
}
CHKOUT(b"DAFRFR", ctx)?;
Ok(())
}