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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const FTSIZE: i32 = 5000;
const RSVUNT: i32 = 2;
const SCRUNT: i32 = 1;
const UTSIZE: i32 = ((20 + SCRUNT) + RSVUNT);
const READ: i32 = 1;
const WRITE: i32 = 2;
const SCRTCH: i32 = 3;
const NEW: i32 = 4;
const NUMAMH: i32 = 4;
const BIGI3E: i32 = 1;
const LTLI3E: i32 = 2;
const VAXGFL: i32 = 3;
const VAXDFL: i32 = 4;
const NUMBFF: i32 = 4;
const STRSIZ: i32 = 8;
const STRLEN: i32 = ((STRSIZ + 1) * NUMBFF);
const DAF: i32 = 1;
const DAS: i32 = 2;
const NUMARC: i32 = 2;
const RECL: i32 = 1024;
const FILEN: i32 = 255;
const CBFSIZ: i32 = 1024;
const RECLEN: i32 = 1024;
const DPRLEN: i32 = 128;
const INRLEN: i32 = (2 * DPRLEN);
const INTLEN: i32 = 4;
struct SaveVars {
STRBFF: ActualCharArray,
NATBFF: i32,
FIRST: bool,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut STRBFF = ActualCharArray::new(STRSIZ, 1..=NUMBFF);
let mut NATBFF: i32 = 0;
let mut FIRST: bool = false;
FIRST = true;
NATBFF = 0;
Self {
STRBFF,
NATBFF,
FIRST,
}
}
}
//$Procedure T_DAFWSR ( Write a DAF summary/descriptor record to file )
pub fn T_DAFWSR(
UNIT: i32,
RECNO: i32,
OUTBFF: i32,
ND: i32,
NI: i32,
NEXT: i32,
PREV: i32,
NSUM: i32,
ARRAY: &[f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let ARRAY = DummyArray::new(ARRAY, 1..);
let mut RECORD = [b' '; RECLEN as usize];
let mut TMPSTR = [b' '; STRSIZ as usize];
let mut DPREC = StackArray::<f64, 128>::new(1..=DPRLEN);
let mut DPBUF = StackArray::<f64, 128>::new(1..=DPRLEN);
let INBUF = StackArray::<i32, 256>::new(1..=INRLEN);
let mut NUMINT: i32 = 0;
let mut CINDEX: i32 = 0;
let mut DINDEX: i32 = 0;
let mut IOSTAT: i32 = 0;
//
// SPICELIB Functions
//
//
// Local Parameters
//
//
// Local Variables
//
//
// Equivalence DPBUF to INBUF to handle unpacking.
//
//
// Saved Variables
//
//
// Data Statements
//
//
// Standard SPICE error handling.
//
if spicelib::RETURN(ctx) {
return Ok(());
} else {
spicelib::CHKIN(b"T_DAFWSR", ctx)?;
}
//
// Perform some initialization tasks.
//
if save.FIRST {
//
// Populate STRBFF with the appropriate binary file
// format labels.
//
for I in 1..=NUMBFF {
spicelib::ZZDDHGSD(b"BFF", I, &mut save.STRBFF[I], ctx);
}
//
// Fetch the native binary file format.
//
spicelib::ZZPLATFM(b"FILE_FORMAT", &mut TMPSTR, ctx);
spicelib::UCASE(&TMPSTR.clone(), &mut TMPSTR, ctx);
save.NATBFF = spicelib::ISRCHC(&TMPSTR, NUMBFF, save.STRBFF.as_arg());
if (save.NATBFF == 0) {
spicelib::SETMSG(b"The binary file format, \'#\', is not supported by this version of the toolkit. This is a serious problem, contact NAIF.", ctx);
spicelib::ERRCH(b"#", &TMPSTR, ctx);
spicelib::SIGERR(b"SPICE(BUG)", ctx)?;
spicelib::CHKOUT(b"T_DAFWSR", ctx)?;
return Ok(());
}
//
// Do not perform initialization tasks again.
//
save.FIRST = false;
}
//
// Check to see if OUTBFF is valid. This should never occur if this
// routine is called properly.
//
if ((OUTBFF < 1) || (OUTBFF > NUMBFF)) {
spicelib::SETMSG(b"The integer code used to indicate the binary file format of the input integers, #, is out of range. This error should never occur.", ctx);
spicelib::ERRINT(b"#", OUTBFF, ctx);
spicelib::SIGERR(b"SPICE(BUG)", ctx)?;
spicelib::CHKOUT(b"T_DAFWSR", ctx)?;
return Ok(());
}
//
// First, determine if we are to write to the native file format.
//
if (OUTBFF == save.NATBFF) {
//
// Clear DPREC.
//
spicelib::CLEARD(DPRLEN, DPREC.as_slice_mut());
DPREC[1] = (NEXT as f64);
DPREC[2] = (PREV as f64);
DPREC[3] = (NSUM as f64);
spicelib::MOVED(
ARRAY.as_slice(),
(NSUM * (ND + ((NI + 1) / 2))),
DPREC.subarray_mut(4),
);
{
use f2rust_std::{
data::Val,
io::{self, Writer},
};
let mut writer = io::UnformattedWriter::new(ctx.io_unit(UNIT)?, Some(RECNO))?;
IOSTAT = io::capture_iostat(|| {
writer.start()?;
for I in intrinsics::range(1, DPRLEN, 1) {
writer.write_f64(DPREC[I])?;
}
writer.finish()?;
Ok(())
})?;
}
if (IOSTAT != 0) {
spicelib::SETMSG(b"Unable to write to #. IOSTAT was #", ctx);
spicelib::ERRFNM(b"#", UNIT, ctx)?;
spicelib::ERRINT(b"#", IOSTAT, ctx);
spicelib::SIGERR(b"SPICE(FILEWRITEFAILED)", ctx)?;
spicelib::CHKOUT(b"T_DAFWSR", ctx)?;
return Ok(());
}
//
// Handle the non-native case.
//
} else {
//
// Clear RECORD.
//
fstr::assign(&mut RECORD, b" ");
//
// Populate RECORD.
//
DPREC[1] = (NEXT as f64);
DPREC[2] = (PREV as f64);
DPREC[3] = (NSUM as f64);
T_XLTFWD(
DPREC.as_slice(),
3,
OUTBFF,
fstr::substr_mut(&mut RECORD, 1..=((2 * INTLEN) * 3)),
ctx,
)?;
//
// Set the index into RECORD to start placing summaries.
//
CINDEX = (((2 * INTLEN) * 3) + 1);
//
// Now process the summaries.
//
for I in 1..=NSUM {
//
// Set the starting index into ARRAY for the next summary.
//
DINDEX = (((I - 1) * (ND + ((NI + 1) / 2))) + 1);
//
// Convert the DPs.
//
T_XLTFWD(
ARRAY.subarray(DINDEX),
ND,
OUTBFF,
fstr::substr_mut(&mut RECORD, CINDEX..=((CINDEX + (ND * (2 * INTLEN))) - 1)),
ctx,
)?;
//
// Increment CINDEX and DINDEX to the position where the
// integers will be placed and located.
//
DINDEX = (DINDEX + ND);
CINDEX = (CINDEX + (ND * (2 * INTLEN)));
//
// Unpack the integer components.
//
spicelib::MOVED(ARRAY.subarray(DINDEX), ((NI + 1) / 2), DPBUF.as_slice_mut());
//
// Translate the integers. We are translating 2*((NI+1)/2)
// integers, which is not always NI integers. Rather than
// introduce special exception for the two cases (NI odd and
// NI even, we will just translate the garbage in the last
// integer in the odd case.
//
NUMINT = (2 * ((NI + 1) / 2));
T_XLTFWI(
DummyArray::<i32>::from_equiv(DPBUF.as_slice(), 1..=INRLEN).as_slice(),
NUMINT,
OUTBFF,
fstr::substr_mut(&mut RECORD, CINDEX..=((CINDEX + (NUMINT * INTLEN)) - 1)),
ctx,
)?;
//
// Increment CINDEX. We ignore DINDEX because it will be
// set properly at the start of the loop.
//
CINDEX = (CINDEX + (NUMINT * INTLEN));
}
//
// Dump the record to the file.
//
{
use f2rust_std::{
data::Val,
io::{self, Writer},
};
let mut writer = io::UnformattedWriter::new(ctx.io_unit(UNIT)?, Some(RECNO))?;
IOSTAT = io::capture_iostat(|| {
writer.start()?;
writer.write_str(&RECORD)?;
writer.finish()?;
Ok(())
})?;
}
if (IOSTAT != 0) {
spicelib::SETMSG(b"Unable to write to #. IOSTAT was #", ctx);
spicelib::ERRFNM(b"#", UNIT, ctx)?;
spicelib::ERRINT(b"#", IOSTAT, ctx);
spicelib::SIGERR(b"SPICE(FILEWRITEFAILED)", ctx)?;
spicelib::CHKOUT(b"T_DAFWSR", ctx)?;
return Ok(());
}
}
spicelib::CHKOUT(b"T_DAFWSR", ctx)?;
Ok(())
}