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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
const BSIZE: i32 = 128;
/// DAF, read data from address
///
/// 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.
/// BADDR,
/// EADDR I Initial, final address within file.
/// DATA O Data contained between BADDR and EADDR.
/// ```
///
/// # Detailed Input
///
/// ```text
/// HANDLE is the handle of a DAF.
///
/// BADDR,
/// EADDR 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 BADDR is zero or negative, the error SPICE(DAFNEGADDR)
/// is signaled.
///
/// 2) If BADDR > EADDR, the error SPICE(DAFBEGGTEND) is signaled.
///
/// 3) If HANDLE is invalid, an error is signaled by a routine in the
/// call tree of this routine.
///
/// 4) If the range of addresses covered between BADDR and EADDR
/// includes records that do not contain strictly double
/// precision data, then the values returned in DATA are
/// undefined. See the $Restrictions section below for details.
/// ```
///
/// # 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 replaces DAFRDA as the principle mechanism for
/// reading the contents of DAF arrays.
/// ```
///
/// # 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 type 8 SPK for read access, retrieve the data for
/// the first segment and identify the beginning and end addresses,
/// the number of data elements within, the size of the data
/// array, and print the first two records.
///
/// Use the SPK kernel below as input type 8 SPK file for the
/// example.
///
/// mer1_ls_040128_iau2000_v1.bsp
///
/// Each segment contains only two records which provide the start
/// and end position for the MER-1 rover landing site in the
/// IAU_MARS frame. Since the landing site does not change over
/// time, it is expected that both records are equal.
///
///
/// Example code begins here.
///
///
/// PROGRAM DAFGDA_EX1
/// IMPLICIT NONE
///
/// C
/// C Local constants.
/// C
/// CHARACTER*(*) FMT
/// PARAMETER ( FMT = '(6F10.3)' )
///
/// INTEGER MAXDAT
/// PARAMETER ( MAXDAT = 1000 )
///
/// INTEGER MAXSUM
/// PARAMETER ( MAXSUM = 125 )
///
/// INTEGER ND
/// PARAMETER ( ND = 2 )
///
/// INTEGER NI
/// PARAMETER ( NI = 6 )
///
/// C
/// C Local variables.
/// C
/// DOUBLE PRECISION DAFSUM ( MAXSUM )
/// DOUBLE PRECISION DATA ( MAXDAT )
/// DOUBLE PRECISION DC ( ND )
///
/// INTEGER BADDR
/// INTEGER EADDR
/// INTEGER HANDLE
/// INTEGER IC ( NI )
/// INTEGER SIZE
///
/// LOGICAL FOUND
///
/// C
/// C Open the type 8 SPK for read access, then read the
/// C data from the first segment.
/// C
/// CALL DAFOPR ( 'mer1_ls_040128_iau2000_v1.bsp', HANDLE )
///
/// C
/// C Begin a forward search; find the first segment; read the
/// C segment summary.
/// C
/// CALL DAFBFS ( HANDLE )
/// CALL DAFFNA ( FOUND )
/// CALL DAFGS ( DAFSUM )
/// CALL DAFUS ( DAFSUM, ND, NI, DC, IC )
///
/// C
/// C Retrieve the data begin and end addresses.
/// C
/// BADDR = IC(5)
/// EADDR = IC(6)
///
/// WRITE(*,'(A,I4)') 'Beginning address : ', BADDR
/// WRITE(*,'(A,I4)') 'Ending address : ', EADDR
/// WRITE(*,'(A,I4)') 'Number of data elements : ',
/// . EADDR - BADDR + 1
///
/// C
/// C Extract all data bounded by the begin and end addresses.
/// C
/// CALL DAFGDA ( HANDLE, BADDR, EADDR, DATA )
///
/// C
/// C Check the data.
/// C
/// WRITE(*,'(A)') 'The first and second states '
/// . // 'stored in the segment:'
/// WRITE(*,FMT) DATA(1), DATA(2), DATA(3),
/// . DATA(4), DATA(5), DATA(6)
/// WRITE(*,FMT) DATA(7), DATA(8), DATA(9),
/// . DATA(10), DATA(11), DATA(12)
///
/// C
/// C Safely close the file
/// C
/// CALL DAFCLS ( HANDLE )
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// Beginning address : 897
/// Ending address : 912
/// Number of data elements : 16
/// The first and second states stored in the segment:
/// 3376.422 -326.649 -115.392 0.000 0.000 0.000
/// 3376.422 -326.649 -115.392 0.000 0.000 0.000
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) There are several types of records in a DAF. This routine
/// is only to be used to read double precision data bounded
/// between two DAF addresses. The range of addresses input
/// may not cross data and summary record boundaries.
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// F.S. Turner (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 13-AUG-2021 (JDR)
///
/// Changed the input argument names BEGIN and END to BADDR to
/// EADDR for consistency with other routines.
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard. Added
/// complete code example. Removed unnecessary $Revisions section.
///
/// - SPICELIB Version 1.0.0, 16-NOV-2001 (FST)
/// ```
pub fn dafgda(
ctx: &mut SpiceContext,
handle: i32,
baddr: i32,
eaddr: i32,
data: &mut [f64],
) -> crate::Result<()> {
DAFGDA(handle, baddr, eaddr, data, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure DAFGDA ( DAF, read data from address )
pub fn DAFGDA(
HANDLE: i32,
BADDR: i32,
EADDR: 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;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
}
//
// Bad addresses?
//
if (BADDR <= 0) {
CHKIN(b"DAFGDA", ctx)?;
SETMSG(b"Negative value for BADDR address: #", ctx);
ERRINT(b"#", BADDR, ctx);
SIGERR(b"SPICE(DAFNEGADDR)", ctx)?;
CHKOUT(b"DAFGDA", ctx)?;
return Ok(());
} else if (BADDR > EADDR) {
CHKIN(b"DAFGDA", ctx)?;
SETMSG(
b"Beginning address (#) greater than ending address (#).",
ctx,
);
ERRINT(b"#", BADDR, ctx);
ERRINT(b"#", EADDR, ctx);
SIGERR(b"SPICE(DAFBEGGTEND)", ctx)?;
CHKOUT(b"DAFGDA", ctx)?;
return Ok(());
}
//
// Convert raw addresses to record/word representations.
//
DAFARW(BADDR, &mut BEGR, &mut BEGW, ctx)?;
DAFARW(EADDR, &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;
}
DAFGDR(
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(())
}