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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
const BSIZE: i32 = 128;
struct SaveVars {
BUFFER: StackArray<f64, 128>,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut BUFFER = StackArray::<f64, 128>::new(1..=BSIZE);
{
use f2rust_std::data::Val;
let mut clist = []
.into_iter()
.chain(std::iter::repeat_n(Val::D(0.0), BSIZE as usize))
.chain([]);
BUFFER
.iter_mut()
.for_each(|n| *n = clist.next().unwrap().into_f64());
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
Self { BUFFER }
}
}
/// DAF, write data to address
///
/// Write or rewrite 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 I Data to be stored 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.
///
/// DATA are the double precision data to be stored 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 the BEGIN > END, the error SPICE(DAFBEGGTEND)
/// is signaled.
/// ```
///
/// # 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 store data anywhere
/// within a DAF without knowing (or caring) about the physical
/// records in which they are stored.
///
/// Of course, if you are merely adding arrays to a DAF,
/// you should not use DAFWDA directly, but should use DAFANA
/// (add new array) and its entry points, since these update
/// the appropriate bookkeeping records automatically.
/// ```
///
/// # Examples
///
/// ```text
/// The following code fragment illustrates the use of DAFWDA
/// to update 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.
///
/// By accident, the elements were written with the wrong value for
/// the GM of the central body (the last element in each set). Each
/// set must be retrieved, updated,and rewritten.
///
/// CALL DAFUS ( SUM, ND, NI, DC, IC )
/// BEGIN = IC(5)
///
/// DO I = 1, 10
/// OFFSET = BEGIN + 11 + (I - 1) * 8
///
/// CALL DAFRDA ( HANDLE, OFFSET+1, OFFSET+8, ELEMENTS )
/// ELEMENTS(8) = NEW_GM
///
/// CALL DAFWDA ( HANDLE, OFFSET+1, OFFSET+8, ELEMENTS )
/// END DO
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// H.A. Neilan (JPL)
/// W.L. Taber (JPL)
/// I.M. Underwood (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 27-OCT-2021 (JDR) (NJB)
///
/// Added IMPLICIT NONE statement.
///
/// Local variable BUFFER is now initialized and saved.
///
/// Edited the header to comply with NAIF standard. Moved DAF
/// required reading from $Literature_References to
/// $Required_Reading section.
///
/// - 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 dafwda(
ctx: &mut SpiceContext,
handle: i32,
begin: i32,
end: i32,
data: &[f64],
) -> crate::Result<()> {
DAFWDA(handle, begin, end, data, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure DAFWDA ( DAF, write data to address )
pub fn DAFWDA(
HANDLE: i32,
BEGIN: i32,
END: i32,
DATA: &[f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let DATA = DummyArray::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 N: i32 = 0;
let mut NEXT: i32 = 0;
let mut FOUND: bool = false;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Saved variables
//
//
// Initial values
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"DAFWDA", ctx)?;
//
// Bad addresses?
//
if (BEGIN <= 0) {
SETMSG(b"Negative beginning address: #", ctx);
ERRINT(b"#", BEGIN, ctx);
SIGERR(b"SPICE(DAFNEGADDR)", ctx)?;
CHKOUT(b"DAFWDA", ctx)?;
return Ok(());
} else if (BEGIN > END) {
SETMSG(
b"Beginning address (#) greater than ending address (#)",
ctx,
);
ERRINT(b"#", BEGIN, ctx);
ERRINT(b"#", END, ctx);
SIGERR(b"SPICE(DAFBEGGTEND)", ctx)?;
CHKOUT(b"DAFWDA", ctx)?;
return Ok(());
}
//
// Convert raw addresses to record/word representations.
//
DAFARW(BEGIN, &mut BEGR, &mut BEGW, ctx)?;
DAFARW(END, &mut ENDR, &mut ENDW, ctx)?;
//
// The first and last records may have to be read, updated, and
// rewritten. Any records in between may be written directly.
//
NEXT = 1;
for RECNO in BEGR..=ENDR {
if ((RECNO == BEGR) || (RECNO == ENDR)) {
DAFRDR(
HANDLE,
RECNO,
1,
BSIZE,
save.BUFFER.as_slice_mut(),
&mut FOUND,
ctx,
)?;
if !FOUND {
CLEARD(BSIZE, save.BUFFER.as_slice_mut());
}
}
if (BEGR == ENDR) {
FIRST = BEGW;
N = ((ENDW - BEGW) + 1);
} else if (RECNO == BEGR) {
FIRST = BEGW;
N = ((BSIZE - BEGW) + 1);
} else if (RECNO == ENDR) {
FIRST = 1;
N = ENDW;
} else {
FIRST = 1;
N = BSIZE;
}
MOVED(DATA.subarray(NEXT), N, save.BUFFER.subarray_mut(FIRST));
NEXT = (NEXT + N);
DAFWDR(HANDLE, RECNO, save.BUFFER.as_slice(), ctx)?;
}
CHKOUT(b"DAFWDA", ctx)?;
Ok(())
}