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
//
// GENERATED FILE
//

use super::*;
use f2rust_std::*;

pub const LBCELL: i32 = -5;
pub const WINMAX: i32 = 20000;
const MSGMAX: i32 = 32;
const MXPASS: i32 = 20;
const MAXLOG: i32 = 100000;

struct SaveVars {
    SVMSLG: ActualCharArray2D,
    SVCNFN: ActualArray2D<f64>,
    SVULOG: ActualArray2D<f64>,
    SVFSEQ: StackArray<i32, 20>,
    SVISEQ: StackArray<i32, 20>,
    SVNUPD: i32,
    SVNFIN: i32,
    SVNINI: i32,
    SVSQIX: i32,
    SVUSEQ: ActualArray<i32>,
}

impl SaveInit for SaveVars {
    fn new() -> Self {
        let mut SVMSLG = ActualCharArray2D::new(MSGMAX, 1..=2, 1..=MXPASS);
        let mut SVCNFN = ActualArray2D::<f64>::new(LBCELL..=WINMAX, 1..=MXPASS);
        let mut SVULOG = ActualArray2D::<f64>::new(1..=3, 1..=MAXLOG);
        let mut SVFSEQ = StackArray::<i32, 20>::new(1..=MXPASS);
        let mut SVISEQ = StackArray::<i32, 20>::new(1..=MXPASS);
        let mut SVNUPD: i32 = 0;
        let mut SVNFIN: i32 = 0;
        let mut SVNINI: i32 = 0;
        let mut SVSQIX: i32 = 0;
        let mut SVUSEQ = ActualArray::<i32>::new(1..=MAXLOG);

        Self {
            SVMSLG,
            SVCNFN,
            SVULOG,
            SVFSEQ,
            SVISEQ,
            SVNUPD,
            SVNFIN,
            SVNINI,
            SVSQIX,
            SVUSEQ,
        }
    }
}

//$Procedure      T_GFTREP ( GF, progress report test utilities )
pub fn T_GFTREP(
    CNFINE: &[f64],
    MSGPRE: &[u8],
    MSGSUF: &[u8],
    IVBEG: f64,
    IVEND: f64,
    ET: f64,
    NMAX: i32,
    MW: i32,
    NCALLS: i32,
    CNFLOG: &[f64],
    MSGLOG: CharArray,
    REPLOG: &[f64],
    SEQLOG: &[i32],
    ctx: &mut Context,
) -> f2rust_std::Result<()> {
    //
    // SPICELIB functions
    //

    //
    // Local parameters
    //

    //
    // Local variables
    //

    //
    // Saved variables
    //
    //
    // Save everything.
    //

    spicelib::CHKIN(b"T_GFTREP", ctx)?;
    spicelib::SIGERR(b"SPICE(BOGUSENTRY)", ctx)?;
    spicelib::CHKOUT(b"T_GFTREP", ctx)?;

    Ok(())
}

//$Procedure  T_GFUINI ( GF, progress report test utility init )
pub fn T_GFUINI(ctx: &mut Context) -> f2rust_std::Result<()> {
    let save = ctx.get_vars::<SaveVars>();
    let save = &mut *save.borrow_mut();

    spicelib::CHKIN(b"T_GFUINI", ctx)?;

    save.SVNINI = 0;
    save.SVNUPD = 0;
    save.SVNFIN = 0;

    spicelib::CLEARD((3 * MAXLOG), save.SVULOG.as_slice_mut());

    for I in 1..=MXPASS {
        spicelib::SSIZED(WINMAX, save.SVCNFN.subarray_mut([LBCELL, I]), ctx)?;

        fstr::assign(save.SVMSLG.get_mut([1, I]), b" ");
        fstr::assign(save.SVMSLG.get_mut([2, I]), b" ");
    }

    save.SVSQIX = 0;

    spicelib::CLEARI(MXPASS, save.SVISEQ.as_slice_mut());
    spicelib::CLEARI(MAXLOG, save.SVUSEQ.as_slice_mut());
    spicelib::CLEARI(MXPASS, save.SVFSEQ.as_slice_mut());

    spicelib::CHKOUT(b"T_GFUINI", ctx)?;
    Ok(())
}

//$Procedure  T_GFREPI ( GF, GFREPI stand-in )
pub fn T_GFREPI(
    CNFINE: &[f64],
    MSGPRE: &[u8],
    MSGSUF: &[u8],
    ctx: &mut Context,
) -> f2rust_std::Result<()> {
    let save = ctx.get_vars::<SaveVars>();
    let save = &mut *save.borrow_mut();

    let CNFINE = DummyArray::new(CNFINE, LBCELL..);

    spicelib::CHKIN(b"T_GFREPI", ctx)?;

    //
    // Increment the progress report initialization count.
    //
    save.SVNINI = (save.SVNINI + 1);

    if (save.SVNINI > MXPASS) {
        spicelib::SETMSG(b"Too many initialization calls: number of progress reporting initialization calls (to T_GRREPI) since setup is #; room in static T_GFTREP buffers is #.", ctx);
        spicelib::ERRINT(b"#", save.SVNINI, ctx);
        spicelib::ERRINT(b"#", MXPASS, ctx);
        spicelib::SIGERR(b"SPICE(OVERFLOW)", ctx)?;
        spicelib::CHKOUT(b"T_GFREPI", ctx)?;
        return Ok(());
    }

    //
    // Increment the call sequence index, and save this
    // index in the initialization sequence log.
    //
    save.SVSQIX = (save.SVSQIX + 1);
    save.SVISEQ[save.SVNINI] = save.SVSQIX;

    //
    // Store the inputs in the initialization log.
    //
    spicelib::COPYD(
        CNFINE.as_slice(),
        save.SVCNFN.subarray_mut([LBCELL, save.SVNINI]),
        ctx,
    )?;

    fstr::assign(save.SVMSLG.get_mut([1, save.SVNINI]), MSGPRE);
    fstr::assign(save.SVMSLG.get_mut([2, save.SVNINI]), MSGSUF);

    spicelib::CHKOUT(b"T_GFREPI", ctx)?;
    Ok(())
}

//$Procedure  T_GFRINI ( GF, return values passed to T_GFREPI )
pub fn T_GFRINI(
    NMAX: i32,
    MW: i32,
    NCALLS: &mut i32,
    SEQLOG: &mut [i32],
    CNFLOG: &mut [f64],
    MSGLOG: CharArrayMut,
    ctx: &mut Context,
) -> f2rust_std::Result<()> {
    let save = ctx.get_vars::<SaveVars>();
    let save = &mut *save.borrow_mut();

    let mut CNFLOG = DummyArrayMut2D::new(CNFLOG, LBCELL..=MW, 1..);
    let mut MSGLOG = DummyCharArrayMut2D::new(MSGLOG, None, 1..=2, 1..);
    let mut SEQLOG = DummyArrayMut::new(SEQLOG, 1..);

    spicelib::CHKIN(b"T_GFRINI", ctx)?;

    //
    // Make sure we have room for the output.
    //
    if (save.SVNINI > NMAX) {
        spicelib::SETMSG(b"Number of progress reporting initialization calls (to T_GRREPI) since setup is #; room in output buffer is #.", ctx);
        spicelib::ERRINT(b"#", save.SVNINI, ctx);
        spicelib::ERRINT(b"#", NMAX, ctx);
        spicelib::SIGERR(b"SPICE(BUG)", ctx)?;
        spicelib::CHKOUT(b"T_GFRINI", ctx)?;
        return Ok(());
    }

    //
    // Set the outputs:
    //
    //    - Number of calls to T_GFREPI
    //    - Sequence numbers of the calls to T_GFREPI
    //    - Input confinement windows
    //    - Input messages
    //

    *NCALLS = save.SVNINI;

    spicelib::MOVEI(save.SVISEQ.as_slice(), save.SVNINI, SEQLOG.as_slice_mut());

    for I in 1..=save.SVNINI {
        spicelib::COPYD(
            save.SVCNFN.subarray([LBCELL, I]),
            CNFLOG.subarray_mut([LBCELL, I]),
            ctx,
        )?;

        fstr::assign(MSGLOG.get_mut([1, I]), save.SVMSLG.get([1, I]));
        fstr::assign(MSGLOG.get_mut([2, I]), save.SVMSLG.get([2, I]));
    }

    spicelib::CHKOUT(b"T_GFRINI", ctx)?;
    Ok(())
}

//$Procedure  T_GFREPU ( GF, GFREPU stand-in )
pub fn T_GFREPU(IVBEG: f64, IVEND: f64, ET: f64, ctx: &mut Context) -> f2rust_std::Result<()> {
    let save = ctx.get_vars::<SaveVars>();
    let save = &mut *save.borrow_mut();

    spicelib::CHKIN(b"T_GFREPU", ctx)?;

    //
    // Increment the progress report update count.
    //
    save.SVNUPD = (save.SVNUPD + 1);

    if (save.SVNUPD > MAXLOG) {
        spicelib::SETMSG(b"Too many update calls: number of progress reporting update calls (to T_GRREPU) since setup is #; room in static T_GFTREP buffers is #.", ctx);
        spicelib::ERRINT(b"#", save.SVNUPD, ctx);
        spicelib::ERRINT(b"#", MAXLOG, ctx);
        spicelib::SIGERR(b"SPICE(OVERFLOW)", ctx)?;
        spicelib::CHKOUT(b"T_GFREPU", ctx)?;
        return Ok(());
    }

    //
    // Increment the call sequence index, and save this
    // index in the update sequence log.
    //
    save.SVSQIX = (save.SVSQIX + 1);

    save.SVUSEQ[save.SVNUPD] = save.SVSQIX;

    //
    // Store the inputs in the update log.
    //
    save.SVULOG[[1, save.SVNUPD]] = IVBEG;
    save.SVULOG[[2, save.SVNUPD]] = IVEND;
    save.SVULOG[[3, save.SVNUPD]] = ET;

    spicelib::CHKOUT(b"T_GFREPU", ctx)?;
    Ok(())
}

//$Procedure  T_GFRPLO ( GF, return values passed to T_GFREPU )
pub fn T_GFRPLO(
    NMAX: i32,
    NCALLS: &mut i32,
    SEQLOG: &mut [i32],
    REPLOG: &mut [f64],
    ctx: &mut Context,
) -> f2rust_std::Result<()> {
    let save = ctx.get_vars::<SaveVars>();
    let save = &mut *save.borrow_mut();

    let mut REPLOG = DummyArrayMut2D::new(REPLOG, 1..=3, 1..);
    let mut SEQLOG = DummyArrayMut::new(SEQLOG, 1..);

    spicelib::CHKIN(b"T_GFRPLO", ctx)?;

    //
    // Make sure we have room for the output.
    //
    if (save.SVNUPD > NMAX) {
        spicelib::SETMSG(b"Number of progress reporting update calls (to T_GRREPU) since setup is #; room in buffer is #.", ctx);
        spicelib::ERRINT(b"#", save.SVNUPD, ctx);
        spicelib::ERRINT(b"#", NMAX, ctx);
        spicelib::SIGERR(b"SPICE(BUG)", ctx)?;
        spicelib::CHKOUT(b"T_GFRPLO", ctx)?;
        return Ok(());
    }

    //
    // Set the outputs:
    //
    //    - Number of calls to T_GFREPU
    //
    //    - Sequence numbers of the calls to T_GFREPU
    //
    //    - Update log, which contains
    //
    //        > interval begin times
    //        > interval end times
    //        > ET values
    //

    *NCALLS = save.SVNUPD;

    spicelib::MOVEI(save.SVUSEQ.as_slice(), save.SVNUPD, SEQLOG.as_slice_mut());

    for I in 1..=save.SVNUPD {
        REPLOG[[1, I]] = save.SVULOG[[1, I]];
        REPLOG[[2, I]] = save.SVULOG[[2, I]];
        REPLOG[[3, I]] = save.SVULOG[[3, I]];
    }

    spicelib::CHKOUT(b"T_GFRPLO", ctx)?;
    Ok(())
}

//$Procedure  T_GFREPF ( GF, GFREPF stand-in )
pub fn T_GFREPF(ctx: &mut Context) -> f2rust_std::Result<()> {
    let save = ctx.get_vars::<SaveVars>();
    let save = &mut *save.borrow_mut();

    spicelib::CHKIN(b"T_GFREPF", ctx)?;

    //
    // Increment the progress report termination count.
    //
    save.SVNFIN = (save.SVNFIN + 1);

    if (save.SVNFIN > MAXLOG) {
        spicelib::SETMSG(b"Too many termination calls: number of progress reporting termination calls (to T_GRREPF) since setup is #; room in static T_GFTREP buffers is #.", ctx);
        spicelib::ERRINT(b"#", save.SVNFIN, ctx);
        spicelib::ERRINT(b"#", MAXLOG, ctx);
        spicelib::SIGERR(b"SPICE(OVERFLOW)", ctx)?;
        spicelib::CHKOUT(b"T_GFREPF", ctx)?;
        return Ok(());
    }

    //
    // Increment the call sequence index, and save this
    // index in the termination sequence log.
    //
    save.SVSQIX = (save.SVSQIX + 1);
    save.SVFSEQ[save.SVNFIN] = save.SVSQIX;

    spicelib::CHKOUT(b"T_GFREPF", ctx)?;
    Ok(())
}

//$Procedure  T_GFRTRM ( GF, return values passed to T_GFREPU )
pub fn T_GFRTRM(
    NMAX: i32,
    NCALLS: &mut i32,
    SEQLOG: &mut [i32],
    ctx: &mut Context,
) -> f2rust_std::Result<()> {
    let save = ctx.get_vars::<SaveVars>();
    let save = &mut *save.borrow_mut();

    let mut SEQLOG = DummyArrayMut::new(SEQLOG, 1..);

    spicelib::CHKIN(b"T_GFRTRM", ctx)?;

    //
    // Make sure we have room for the output.
    //
    if (save.SVNFIN > NMAX) {
        spicelib::SETMSG(b"Number of progress reporting termination calls (to T_GRREPF) since setup is #; room in buffer is #.", ctx);
        spicelib::ERRINT(b"#", save.SVNFIN, ctx);
        spicelib::ERRINT(b"#", NMAX, ctx);
        spicelib::SIGERR(b"SPICE(BUG)", ctx)?;
        spicelib::CHKOUT(b"T_GFRTRM", ctx)?;
        return Ok(());
    }

    //
    // Set the outputs:
    //
    //    - Number of calls to T_GFRFIN
    //
    //    - Sequence numbers of the calls to T_GFRFIN
    //

    *NCALLS = save.SVNFIN;

    spicelib::MOVEI(save.SVFSEQ.as_slice(), save.SVNFIN, SEQLOG.as_slice_mut());

    spicelib::CHKOUT(b"T_GFRTRM", ctx)?;
    Ok(())
}