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
//
// 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;
//$Procedure F_ZZDGDR ( ZZDAFGDR Test Family )
pub fn F_ZZDGDR(OK: &mut bool, ctx: &mut Context) -> f2rust_std::Result<()> {
let mut CASENM = [b' '; 80 as usize];
let mut NAME = [b' '; 1024 as usize];
let mut FNAME = [b' '; FILEN as usize];
let mut FNMTMP = [b' '; FILEN as usize];
let mut IDWORD = [b' '; 8 as usize];
let mut IFNAME = [b' '; 60 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 ARRAY = StackArray::<f64, 128>::new(1..=128);
let mut DATA = StackArray::<f64, 128>::new(1..=128);
let mut DC = StackArray::<f64, 125>::new(1..=125);
let mut RDREC = StackArray::<f64, 128>::new(1..=128);
let mut BWARD: i32 = 0;
let mut FREE: i32 = 0;
let mut FWARD: i32 = 0;
let mut HANLST = StackArray::<i32, 4>::new(1..=NUMBFF);
let mut IC = StackArray::<i32, 250>::new(1..=250);
let mut IOSTAT: i32 = 0;
let mut NATBFF: i32 = 0;
let mut ND: i32 = 0;
let mut NEXT: i32 = 0;
let mut NI: i32 = 0;
let mut NSUM: i32 = 0;
let mut NUMSUP: i32 = 0;
let mut PREV: i32 = 0;
let mut SUPBFF = StackArray::<i32, 4>::new(1..=NUMBFF);
let mut UNIT: i32 = 0;
let mut ADDFTP: bool = false;
let mut FOUND: bool = false;
//
// SPICELIB Functions
//
//
// Local Parameters
//
//
// Local Variables
//
//
// Start the test family with an open call.
//
testutil::TOPEN(b"F_ZZDGDR", ctx)?;
//
// --- Case: ------------------------------------------------------
//
testutil::TCASE(b"F_ZZDGDR Initialization", ctx)?;
//
// Retrieve the native format and other related information.
//
spicelib::ZZDDHINI(
&mut NATBFF,
SUPBFF.as_slice_mut(),
&mut NUMSUP,
STRAMH.as_arg_mut(),
STRARC.as_arg_mut(),
STRBFF.as_arg_mut(),
ctx,
)?;
//
// Setup the filename template.
//
fstr::assign(&mut FNMTMP, b"daf#.daf");
//
// Construct the contents of the DAF to create.
//
fstr::assign(&mut IDWORD, b"DAF/TEST");
ND = 2;
NI = 6;
fstr::assign(&mut IFNAME, b"TSPICE Test DAF");
FWARD = 2;
BWARD = 2;
FREE = ((4 * 128) + 1);
ADDFTP = false;
NEXT = 0;
PREV = 0;
NSUM = 2;
//
// Create and pack the summaries.
//
DC[1] = 1.0;
DC[2] = -1.0;
IC[1] = 1;
IC[2] = 2;
IC[3] = 3;
IC[4] = 4;
IC[5] = ((3 * 128) + 1);
IC[6] = (IC[5] + 64);
spicelib::DAFPS(ND, NI, DC.as_slice(), IC.as_slice(), ARRAY.as_slice_mut());
DC[1] = 2.0;
DC[2] = -2.0;
IC[1] = 2;
IC[2] = 4;
IC[3] = 6;
IC[4] = 8;
IC[5] = (IC[6] + 1);
IC[6] = (4 * 128);
spicelib::DAFPS(
ND,
NI,
DC.as_slice(),
IC.as_slice(),
ARRAY.subarray_mut(((ND + ((NI + 1) / 2)) + 1)),
);
//
// Setup the name record.
//
fstr::assign(&mut NAME, b" ");
//
// Populate the data record with a simple pattern. Our
// aim is not to validate the translation algorithm, but
// the reader module.
//
for I in 1..=128 {
DATA[I] = f64::powi(10.0, I);
}
//
// Construct the DAFs for each environment and load them
// into the handle manager.
//
for I in 1..=NUMSUP {
spicelib::REPMI(&FNMTMP, b"#", I, &mut FNAME, ctx);
//
// Start a new DAF.
//
T_DAFOPN(&FNAME, SUPBFF[I], &mut UNIT, ctx)?;
//
// Dump the file record to it.
//
T_DAFWFR(
UNIT, SUPBFF[I], &IDWORD, ND, NI, &IFNAME, FWARD, BWARD, FREE, ADDFTP, ctx,
)?;
//
// Now write the only summary record to the file.
//
T_DAFWSR(
UNIT,
2,
SUPBFF[I],
ND,
NI,
NEXT,
PREV,
NSUM,
ARRAY.as_slice(),
ctx,
)?;
//
// Insert a blank name record for completeness.
//
{
use f2rust_std::{
data::Val,
io::{self, Writer},
};
let mut writer = io::UnformattedWriter::new(ctx.io_unit(UNIT)?, Some(3))?;
IOSTAT = io::capture_iostat(|| {
writer.start()?;
writer.write_str(&NAME)?;
writer.finish()?;
Ok(())
})?;
}
testutil::CHCKSI(b"IOSTAT", IOSTAT, b"=", 0, 0, OK, ctx)?;
//
// Lastly, dump the data record and close the file.
//
T_DAFWDR(UNIT, 4, SUPBFF[I], 128, DATA.as_slice(), ctx)?;
{
use f2rust_std::io;
let specs = io::CloseSpecs {
unit: Some(UNIT),
..Default::default()
};
ctx.close(specs)?;
}
//
// Open the DAF in the handle manager.
//
spicelib::ZZDDHOPN(&FNAME, b"READ", b"DAF", &mut HANLST[I], ctx)?;
//
// Check for the absence of an exception.
//
testutil::CHCKXC(false, b" ", OK, ctx)?;
}
//
// Dynamically construct the test cases based on the contents
// of SUPBFF.
//
for I in 1..=NUMSUP {
fstr::assign(&mut CASENM, b"# reading # data.");
spicelib::REPMC(&CASENM.clone(), b"#", &STRBFF[NATBFF], &mut CASENM);
spicelib::REPMC(&CASENM.clone(), b"#", &STRBFF[SUPBFF[I]], &mut CASENM);
testutil::TCASE(&CASENM, ctx)?;
//
// Setup the inputs and outputs.
//
for J in 1..=128 {
RDREC[J] = 0.0;
}
FOUND = false;
//
// We have all the pieces, invoke the module.
//
spicelib::ZZDAFGDR(HANLST[I], 4, RDREC.as_slice_mut(), &mut FOUND, ctx)?;
//
// Check for the absence of an exception.
//
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// Check outputs.
//
testutil::CHCKSL(b"FOUND", FOUND, true, OK, ctx)?;
testutil::CHCKAD(
b"RDREC",
RDREC.as_slice(),
b"=",
DATA.as_slice(),
128,
0.0,
OK,
ctx,
)?;
}
//
// Clean up by unloading and removing the test files.
//
for I in 1..=NUMSUP {
spicelib::ZZDDHCLS(HANLST[I], b"DAF", false, ctx)?;
spicelib::REPMI(&FNMTMP, b"#", I, &mut FNAME, ctx);
testutil::KILFIL(&FNAME, ctx)?;
}
//
// --- Case: ------------------------------------------------------
//
testutil::TCASE(b"SPICE(HANDLENOTFOUND) Exception", ctx)?;
//
// Setup outputs.
//
FOUND = true;
for I in 1..=128 {
RDREC[I] = DATA[I];
}
//
// Since we know we just unloaded HANLST(1), attempt to read
// from that handle.
//
spicelib::ZZDAFGDR(HANLST[1], 4, RDREC.as_slice_mut(), &mut FOUND, ctx)?;
//
// Check for the presence of an exception.
//
testutil::CHCKXC(true, b"SPICE(HANDLENOTFOUND)", OK, ctx)?;
//
// Check outputs. FOUND should be FALSE, and RDREC should be
// untouched.
//
testutil::CHCKSL(b"FOUND", FOUND, false, OK, ctx)?;
testutil::CHCKAD(
b"RDREC",
RDREC.as_slice(),
b"=",
DATA.as_slice(),
128,
0.0,
OK,
ctx,
)?;
//
// Close out the test family.
//
testutil::T_SUCCESS(OK, ctx);
Ok(())
}