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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
const BSIZE: i32 = 128;
/// DAF, read data from address
///
/// Deprecated: This routine has been superseded by the SPICELIB
/// routines DAFGDA and DAFGSR. This routine is supported for purposes
/// of backward compatibility only.
///
/// Read the double precision data bounded by two addresses within
/// a DAF.
///
/// # Required Reading
///
/// * [DAF](crate::required_reading::daf)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// HANDLE I Handle of a DAF.
/// BEGIN,
/// END I Initial, final address within file.
/// DATA O Data contained between BEGIN and END.
/// ```
///
/// # Detailed Input
///
/// ```text
/// HANDLE is the handle of a DAF.
///
/// BEGIN,
/// END are the initial and final addresses of a contiguous
/// set of double precision numbers within a DAF.
/// Presumably, these make up all or part of a particular
/// array.
/// ```
///
/// # Detailed Output
///
/// ```text
/// DATA are the double precision data contained between
/// the specified addresses within the specified file.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If BEGIN is zero or negative, the error SPICE(DAFNEGADDR)
/// is signaled.
///
/// 2) If BEGIN > END, the error SPICE(DAFBEGGTEND) is signaled.
///
/// 3) If the file associated with HANDLE is not of the native
/// binary file format, the error SPICE(UNSUPPORTEDBFF) is
/// signaled.
///
/// 4) If HANDLE is invalid, an error is signaled by a routine in
/// the call tree of this routine.
/// ```
///
/// # Particulars
///
/// ```text
/// The principal reason that DAFs are so easy to use is that
/// the data in each DAF are considered to be one long contiguous
/// set of double precision numbers. You can grab data from anywhere
/// within a DAF without knowing (or caring) about the physical
/// records in which they are stored.
///
/// This routine has been made obsolete by the routines DAFGDA and
/// DAFGSR. This routine is supported for reasons of backward
/// compatibility only. New software development should utilize
/// DAFGDA or DAFGSR.
/// ```
///
/// # Examples
///
/// ```text
/// The following code fragment illustrates the use of DAFRDA
/// to read data from an imaginary array. The array begins with a
/// directory containing 11 epochs. Each pair of epochs bounds
/// an interval, and each interval is covered by a set of eight
/// osculating elements.
///
/// CALL DAFUS ( SUM, ND, NI, DC, IC )
/// BEGIN = IC(5)
/// END = IC(6)
///
/// CALL DAFRDA ( HANDLE, BEGIN, BEGIN+10, EPOCHS )
///
/// DO I = 1, 10
/// IF ( ET .GE. EPOCHS(I) .AND. ET .LE. EPOCHS(I+1) ) THEN
/// OFFSET = IC(5) + 11 + (I - 1) * 8
///
/// CALL DAFRDA ( HANDLE, OFFSET+1, OFFSET+8, ELEMENTS )
/// RETURN
/// END IF
/// END DO
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// H.A. Neilan (JPL)
/// B.V. Semenov (JPL)
/// W.L. Taber (JPL)
/// F.S. Turner (JPL)
/// I.M. Underwood (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 2.1.0, 26-OCT-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 2.0.2, 18-MAY-2010 (BVS)
///
/// Index line now states that this routine is deprecated.
///
/// - SPICELIB Version 2.0.1, 27-OCT-2003 (NJB)
///
/// The header now states that this routine is deprecated.
/// The $Exceptions header section has been extended.
/// Minor additional header updates were made.
///
/// - SPICELIB Version 2.0.0, 16-NOV-2001 (FST)
///
/// Added SPICE(UNSUPPORTEDBFF) exception to the routine.
///
/// - 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)
/// ```
///
/// # Revisions
///
/// ```text
/// - SPICELIB Version 2.0.0, 16-NOV-2001 (FST)
///
/// The exception SPICE(UNSUPPORTEDBFF) was added to guarantee
/// this routine's functionality remains unchanged as a result
/// of the updates to the underlying DAF software's utilization of
/// the handle manager. In versions of the Toolkit prior to this,
/// all DAFs loaded were of the native binary file format.
/// While rather unlikely, this routine could be used to read
/// the contents of summary records in addition to the usual
/// data records. The non-native to native translation process
/// for these two different types of records in general are not
/// the same. Rather than attempt to interpret the caller's
/// intent, this routine is deprecated and restricted to
/// functioning only on DAFs of the native binary file format.
///
/// - Beta Version 1.1.0, 1-NOV-1989 (RET)
///
/// DAFRDA now only checks in and checks out if one of the two
/// possible exceptions occurs. The purpose of this change was to
/// help speed up a routine that gets called constantly by higher
/// level DAF routines.
/// ```
pub fn dafrda(
ctx: &mut SpiceContext,
handle: i32,
begin: i32,
end: i32,
data: &mut [f64],
) -> crate::Result<()> {
DAFRDA(handle, begin, end, data, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure DAFRDA ( DAF, read data from address )
pub fn DAFRDA(
HANDLE: i32,
BEGIN: i32,
END: i32,
DATA: &mut [f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut DATA = DummyArrayMut::new(DATA, 1..);
let mut BEGR: i32 = 0;
let mut BEGW: i32 = 0;
let mut ENDR: i32 = 0;
let mut ENDW: i32 = 0;
let mut FIRST: i32 = 0;
let mut LAST: i32 = 0;
let mut NEXT: i32 = 0;
let mut FOUND: bool = false;
let mut NATIVE: bool = false;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
}
//
// Check to see if HANDLE is associated with a DAF of the native
// binary file format.
//
ZZDDHISN(HANDLE, &mut NATIVE, &mut FOUND, ctx)?;
//
// If the HANDLE was located, then check whether the binary file
// format is native. Otherwise, defer diagnosing the missing
// handle to DAFRDR.
//
if (FOUND && !NATIVE) {
CHKIN(b"DAFRDA", ctx)?;
SETMSG(b"The binary file format for file \'#\' is not native. This routine operates only on files of the native format.", ctx);
ERRHAN(b"#", HANDLE, ctx)?;
SIGERR(b"SPICE(UNSUPPORTEDBFF)", ctx)?;
CHKOUT(b"DAFRDA", ctx)?;
return Ok(());
}
//
// Bad addresses?
//
if (BEGIN <= 0) {
CHKIN(b"DAFRDA", ctx)?;
SETMSG(b"Negative value for BEGIN address: #", ctx);
ERRINT(b"#", BEGIN, ctx);
SIGERR(b"SPICE(DAFNEGADDR)", ctx)?;
CHKOUT(b"DAFRDA", ctx)?;
return Ok(());
} else if (BEGIN > END) {
CHKIN(b"DAFRDA", ctx)?;
SETMSG(
b"Beginning address (#) greater than ending address (#).",
ctx,
);
ERRINT(b"#", BEGIN, ctx);
ERRINT(b"#", END, ctx);
SIGERR(b"SPICE(DAFBEGGTEND)", ctx)?;
CHKOUT(b"DAFRDA", ctx)?;
return Ok(());
}
//
// Convert raw addresses to record/word representations.
//
DAFARW(BEGIN, &mut BEGR, &mut BEGW, ctx)?;
DAFARW(END, &mut ENDR, &mut ENDW, ctx)?;
//
// Get as many records as needed. Return the last part of the
// first record, the first part of the last record, and all of
// every record in between. Any record not found is assumed to
// be filled with zeros.
//
NEXT = 1;
for RECNO in BEGR..=ENDR {
if (BEGR == ENDR) {
FIRST = BEGW;
LAST = ENDW;
} else if (RECNO == BEGR) {
FIRST = BEGW;
LAST = BSIZE;
} else if (RECNO == ENDR) {
FIRST = 1;
LAST = ENDW;
} else {
FIRST = 1;
LAST = BSIZE;
}
DAFRDR(
HANDLE,
RECNO,
FIRST,
LAST,
DATA.subarray_mut(NEXT),
&mut FOUND,
ctx,
)?;
if !FOUND {
CLEARD(((LAST - FIRST) + 1), DATA.subarray_mut(NEXT));
}
NEXT = (NEXT + ((LAST - FIRST) + 1));
}
Ok(())
}