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 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 IDLEN: i32 = 8;
const NINTS: i32 = 20;
const NCHARS: i32 = (NINTS * 4);
const MINPCH: i32 = 32;
const MAXPCH: i32 = 126;
struct SaveVars {
NATBFF: i32,
SUPBFF: StackArray<i32, 4>,
NUMSUP: i32,
FIRST: bool,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut NATBFF: i32 = 0;
let mut SUPBFF = StackArray::<i32, 4>::new(1..=NUMBFF);
let mut NUMSUP: i32 = 0;
let mut FIRST: bool = false;
FIRST = true;
NATBFF = 0;
Self {
NATBFF,
SUPBFF,
NUMSUP,
FIRST,
}
}
}
//$Procedure ZZDDHMNM ( Return unique enough DP number for a file )
pub fn ZZDDHMNM(UNIT: i32, ctx: &mut Context) -> f2rust_std::Result<f64> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let mut ZZDDHMNM: f64 = 0.0;
let mut ARCH = [b' '; IDLEN as usize];
let mut IDWORD = [b' '; IDLEN as usize];
let mut TYPE = [b' '; IDLEN as usize];
let mut STRBUF = [b' '; NCHARS as usize];
let mut STRAMH = ActualCharArray::new(STRSIZ, 1..=NUMAMH);
let mut STRARC = ActualCharArray::new(STRSIZ, 1..=NUMARC);
let mut STRBFF = ActualCharArray::new(STRSIZ, 1..=NUMBFF);
let mut MNM: f64 = 0.0;
let mut BFF: i32 = 0;
let mut INTARR = StackArray::<i32, 20>::new(1..=NINTS);
let mut IOSTAT: i32 = 0;
let mut SUPIDX: i32 = 0;
//
// SPICELIB Functions
//
//
// Local parameters.
//
// Character buffer size consistent with the number of integers
// that will be read from the file.
//
//
// Minimum and maximum values for the range of ASCII printing
// characters.
//
//
// Local variables.
//
//
// Saved variables.
//
//
// Data statements.
//
//
// Set default output value to zero.
//
MNM = 0.0;
ZZDDHMNM = 0.0;
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(ZZDDHMNM);
} else {
CHKIN(b"ZZDDHMNM", ctx)?;
}
//
// Perform some initialization tasks.
//
if save.FIRST {
ZZDDHINI(
&mut save.NATBFF,
save.SUPBFF.as_slice_mut(),
&mut save.NUMSUP,
STRAMH.as_arg_mut(),
STRARC.as_arg_mut(),
STRBFF.as_arg_mut(),
ctx,
)?;
//
// Check FAILED() to handle the unlikely event that
// ZZDDHINI signaled SPICE(BUG).
//
if FAILED(ctx) {
CHKOUT(b"ZZDDHMNM", ctx)?;
return Ok(ZZDDHMNM);
}
//
// Do not perform initialization tasks again.
//
save.FIRST = false;
}
//
// Read ID word string followed by NINTS integers from the first
// record of the file.
//
{
use f2rust_std::{
data::Val,
io::{self, Reader},
};
let mut reader = io::UnformattedReader::new(ctx.io_unit(UNIT)?, Some(1))?;
IOSTAT = io::capture_iostat(|| {
reader.start()?;
reader.read_str(&mut IDWORD)?;
for n in INTARR.iter_mut() {
*n = reader.read_i32()?;
}
reader.finish()?;
Ok(())
})?;
}
if (IOSTAT == 0) {
//
// Read succeeded. Try to determine the file architecture and
// type from the ID word. To do this, mimic the part of GETFAT
// that deals only with the ID word. First replace any non
// printing ASCII characters in the ID word with blanks, then use
// IDW2AT on the "cleaned" ID word to get architecture and type.
//
for I in 1..=IDLEN {
if ((intrinsics::ICHAR(fstr::substr(&IDWORD, I..=I)) < MINPCH)
|| (intrinsics::ICHAR(fstr::substr(&IDWORD, I..=I)) > MAXPCH))
{
fstr::assign(fstr::substr_mut(&mut IDWORD, I..=I), b" ");
}
}
IDW2AT(&IDWORD, &mut ARCH, &mut TYPE, ctx)?;
//
// Compute the output value based on the file architecture.
//
if fstr::eq(&ARCH, b"DAF") {
//
// For DAF files, try to get the file's binary format.
//
ZZDDHPPF(UNIT, DAF, &mut BFF, ctx)?;
if FAILED(ctx) {
CHKOUT(b"ZZDDHMNM", ctx)?;
return Ok(ZZDDHMNM);
}
//
// If the file is in a non-native format, we will need to read
// the first record again, now directly as characters, and
// translate these character to native integers.
//
if (BFF != save.NATBFF) {
//
// First, check if run-time translation is supported for
// this BFF. This check, stolen from ZZDDHMAN, is needed
// because ZZXLATEI accepts only BFFs for which translation
// is guaranteed to be supported on this platform. If it
// is not supported, simply get out (note that the default
// return value was set to zero at the start.)
//
SUPIDX = ISRCHI(BFF, save.NUMSUP, save.SUPBFF.as_slice());
if (SUPIDX == 0) {
CHKOUT(b"ZZDDHMNM", ctx)?;
return Ok(ZZDDHMNM);
}
//
// Read the first record as characters and do translation.
//
{
use f2rust_std::{
data::Val,
io::{self, Reader},
};
let mut reader = io::UnformattedReader::new(ctx.io_unit(UNIT)?, Some(1))?;
IOSTAT = io::capture_iostat(|| {
reader.start()?;
reader.read_str(&mut IDWORD)?;
reader.read_str(&mut STRBUF)?;
reader.finish()?;
Ok(())
})?;
}
ZZXLATEI(BFF, &STRBUF, NINTS, INTARR.as_slice_mut(), ctx)?;
if FAILED(ctx) {
CHKOUT(b"ZZDDHMNM", ctx)?;
return Ok(ZZDDHMNM);
}
}
//
// Add integers from the file record to the output value.
//
for I in 1..=NINTS {
MNM = (MNM + INTARR[I] as f64);
}
//
// Read more integers from the start of the first descriptor
// record without regard to the file's binary format and,
// if successful, add them to the total.
//
{
use f2rust_std::{
data::Val,
io::{self, Reader},
};
let mut reader = io::UnformattedReader::new(ctx.io_unit(UNIT)?, Some(INTARR[18]))?;
IOSTAT = io::capture_iostat(|| {
reader.start()?;
for n in INTARR.iter_mut() {
*n = reader.read_i32()?;
}
reader.finish()?;
Ok(())
})?;
}
if (IOSTAT == 0) {
for I in 1..=NINTS {
MNM = (MNM + INTARR[I] as f64);
}
}
} else if fstr::eq(&ARCH, b"DAS") {
//
// For DAS files, for now, add up integers from the first
// record to get the output value.
//
for I in 1..=NINTS {
MNM = (MNM + INTARR[I] as f64);
}
} else {
//
// For all other files, add up integers from the first record
// to get the output value.
//
for I in 1..=NINTS {
MNM = (MNM + INTARR[I] as f64);
}
}
} else {
//
// The read of the file record failed. Do nothing as the output
// value has already been set at the start of the function.
//
}
ZZDDHMNM = MNM;
CHKOUT(b"ZZDDHMNM", ctx)?;
Ok(ZZDDHMNM)
}