rsspice 0.1.0

Pure Rust port of the SPICE Toolkit for space geometry
Documentation
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
//
// 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_ZED'S ( ZZDAFGSR Test Family )
pub fn F_ZZDGSR(OK: &mut bool, ctx: &mut Context) -> f2rust_std::Result<()> {
    let mut CASENM = [b' '; 80 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 PAARY = StackArray::<f64, 128>::new(1..=128);
    let mut RDREC = StackArray::<f64, 128>::new(1..=128);
    let mut TDC = StackArray::<f64, 125>::new(1..=125);
    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 MXNSUM: i32 = 0;
    let mut NATBFF: i32 = 0;
    let mut NEXT: i32 = 0;
    let mut NSUM: i32 = 0;
    let mut NUMSUP: i32 = 0;
    let mut PREV: i32 = 0;
    let mut SUMSIZ: i32 = 0;
    let mut SUPBFF = StackArray::<i32, 4>::new(1..=NUMBFF);
    let mut TIC = StackArray::<i32, 250>::new(1..=250);
    let mut UNIT: i32 = 0;
    let mut ADDFTP: bool = false;
    let mut FOUND: bool = false;

    //
    // Local Variables
    //

    //
    // Start the test family with an open call.
    //
    testutil::TOPEN(b"F_ZZDGSR", ctx)?;

    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"F_ZZDGSR 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.  These values
    // are just to satisfy the arguments of T_DAFWFR, as we are only
    // creating a test file to exercise ZZDAFGSR.
    //
    fstr::assign(&mut IDWORD, b"DAF/TEST");
    fstr::assign(&mut IFNAME, b"TSPICE Test DAF");
    FWARD = 2;
    BWARD = 2;
    FREE = ((128 * 125) + 1);
    ADDFTP = true;

    //
    // Construct the DAFs for each supported architecture, load them
    // into the handle manager and perform the necessary tests.
    //
    for I in 1..=NUMSUP {
        spicelib::REPMI(&FNMTMP, b"#", I, &mut FNAME, ctx);

        //
        // Now loop over all possible combinations of ND and NI.
        // J ranges over the possible values of ND, while K over NI.
        //
        //  DO J = 0, 124
        //     DO K = 2, 2*(125-J)
        //
        // In the interest of increasing execution speed on most of
        // the test platforms only perform the following, commonly
        // used summary tests.
        //
        for J in 2..=2 {
            for K in 5..=6 {
                //
                // Declare a new test case, since we are constructing them
                // dynamically.
                //
                fstr::assign(&mut CASENM, b"# reading # data. ND = #, NI = #.");
                spicelib::REPMC(&CASENM.clone(), b"#", &STRBFF[NATBFF], &mut CASENM);
                spicelib::REPMC(&CASENM.clone(), b"#", &STRBFF[SUPBFF[I]], &mut CASENM);
                spicelib::REPMI(&CASENM.clone(), b"#", J, &mut CASENM, ctx);
                spicelib::REPMI(&CASENM.clone(), b"#", K, &mut CASENM, ctx);

                testutil::TCASE(&CASENM, ctx)?;

                //
                // Open the new DAF.
                //
                T_DAFOPN(&FNAME, SUPBFF[I], &mut UNIT, ctx)?;

                //
                // Dump the semi-bogus file record into the new DAF.
                //
                T_DAFWFR(
                    UNIT, SUPBFF[I], &IDWORD, J, K, &IFNAME, FWARD, BWARD, FREE, ADDFTP, ctx,
                )?;

                //
                // Compute the maximum number of summaries each summary
                // record can hold for these values of ND and NI.
                //
                MXNSUM = (125 / (J + ((K + 1) / 2)));
                SUMSIZ = (J + ((K + 1) / 2));

                //
                // Now construct the summaries we are going to store
                // in each summary record.  We will saturate ARRAY
                // with a sequence of packed summaries.
                //
                for L in 1..=MXNSUM {
                    //
                    // Construct the DP components.
                    //
                    for M in 1..=J {
                        DC[M] = ((L as f64) * (M as f64));
                    }

                    //
                    // Construct the integer components
                    //
                    for M in 1..=K {
                        IC[M] = (L * M);
                    }

                    spicelib::DAFPS(
                        J,
                        K,
                        DC.as_slice(),
                        IC.as_slice(),
                        ARRAY.subarray_mut((((L - 1) * SUMSIZ) + 1)),
                    );
                }

                //
                // Now construct each summary record that is to be
                // written into the DAF.  The first L summaries from
                // ARRAY will be copied into the target record along
                // with bogus values for NEXT, PREV, and L itself as
                // NSUM.  The remainder of the record is zeroed out
                // for the safety of the reverse conversion module's
                // sake.
                //
                for L in 0..=MXNSUM {
                    //
                    // We are just going to assign bogus values to NEXT and
                    // PREV, because we are not really going to be reading
                    // this with any of the high level DAF routines.
                    //
                    NEXT = 2;
                    PREV = 2;
                    NSUM = L;

                    //
                    // We have the baseline ARRAY of MXNSUM packed
                    // summaries.  Start populating records, by copying
                    // the appropriate number of packed summaries into
                    // PAARY.
                    //
                    spicelib::CLEARD(128, PAARY.as_slice_mut());
                    spicelib::MOVED(ARRAY.as_slice(), (L * SUMSIZ), PAARY.as_slice_mut());

                    //
                    // Write the summary record to the new DAF.
                    //
                    T_DAFWSR(
                        UNIT,
                        (L + 2),
                        SUPBFF[I],
                        J,
                        K,
                        NEXT,
                        PREV,
                        NSUM,
                        PAARY.as_slice(),
                        ctx,
                    )?;
                }

                //
                // Close the DAF.
                //
                {
                    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)?;

                //
                // Now check each record in the file we just created.
                //
                for L in 0..=MXNSUM {
                    //
                    // Setup the inputs and outputs.
                    //
                    spicelib::CLEARI(250, TIC.as_slice_mut());
                    spicelib::CLEARD(125, TDC.as_slice_mut());

                    FOUND = false;

                    //
                    // Invoke the module.
                    //
                    spicelib::ZZDAFGSR(
                        HANLST[I],
                        (L + 2),
                        J,
                        K,
                        DATA.as_slice_mut(),
                        &mut FOUND,
                        ctx,
                    )?;

                    //
                    // Check for the absence of an exception.
                    //
                    testutil::CHCKXC(false, b" ", OK, ctx)?;

                    //
                    // Now check the results. Start by examining the
                    // values stored in the record for NEXT, PREV,
                    // and NSUM.
                    //
                    testutil::CHCKSD(b"NEXT", DATA[1], b"=", (NEXT as f64), 0.0, OK, ctx)?;
                    testutil::CHCKSD(b"PREV", DATA[2], b"=", (PREV as f64), 0.0, OK, ctx)?;
                    testutil::CHCKSD(b"NSUM", DATA[3], b"=", (L as f64), 0.0, OK, ctx)?;

                    //
                    // Now verify the contents of each summary.
                    //
                    for M in 1..=L {
                        //
                        // Unpack the summary for the test array that was
                        // written to the file.
                        //
                        spicelib::DAFUS(
                            ARRAY.subarray((((M - 1) * SUMSIZ) + 1)),
                            J,
                            K,
                            DC.as_slice_mut(),
                            IC.as_slice_mut(),
                        );

                        //
                        // Unpack the next summary from DATA.
                        //
                        spicelib::DAFUS(
                            DATA.subarray((4 + ((M - 1) * SUMSIZ))),
                            J,
                            K,
                            TDC.as_slice_mut(),
                            TIC.as_slice_mut(),
                        );

                        //
                        // Compare the contents of the summaries.
                        //
                        testutil::CHCKAD(
                            b"DC",
                            TDC.as_slice(),
                            b"=",
                            DC.as_slice(),
                            J,
                            0.0,
                            OK,
                            ctx,
                        )?;
                        testutil::CHCKAI(b"IC", TIC.as_slice(), b"=", IC.as_slice(), K, OK, ctx)?;
                    }
                }

                //
                // Close the file, removing it from the handle manager.
                //
                spicelib::ZZDDHCLS(HANLST[I], b"DAF", false, ctx)?;

                //
                // Kill the file, so we can reuse the name safely.
                //
                testutil::KILFIL(&FNAME, ctx)?;
            }
        }
    }

    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"SPICE(HANDLENOTFOUND) Exception", ctx)?;

    //
    // Setup outputs and expected values.
    //
    FOUND = true;

    spicelib::CLEARD(128, DATA.as_slice_mut());
    spicelib::CLEARD(128, RDREC.as_slice_mut());

    //
    // Since we know we just unloaded HANLST(NUMSUP), attempt to read
    // from that handle.
    //
    spicelib::ZZDAFGSR(
        HANLST[NUMSUP],
        2,
        124,
        2,
        RDREC.as_slice_mut(),
        &mut FOUND,
        ctx,
    )?;

    //
    // Check for the presence of the 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(())
}