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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
//
// GENERATED FILE
//

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

const PCK: &[u8] = b"test.tpc";
const SPK: &[u8] = b"test.bsp";
const UTC: &[u8] = b"1999 JAN 1";
const LOOSE: f64 = 0.0000001;
const MED: f64 = 0.00000000001;
const TIGHT: f64 = 0.000000000001;
const VTIGHT: f64 = 0.00000000000001;
const MSGLEN: i32 = 240;

//$Procedure F_GE01 ( SPICE higher-level geometry routine tests )
pub fn F_GE01(OK: &mut bool, ctx: &mut Context) -> f2rust_std::Result<()> {
    let mut TITLE = [b' '; MSGLEN as usize];
    let mut ALT: f64 = 0.0;
    let mut EMISSN: f64 = 0.0;
    let mut ET: f64 = 0.0;
    let mut EXPPNT = StackArray::<f64, 3>::new(1..=3);
    let mut F: f64 = 0.0;
    let mut LAT: f64 = 0.0;
    let mut LON: f64 = 0.0;
    let mut LT: f64 = 0.0;
    let mut PHASE: f64 = 0.0;
    let mut RAD: f64 = 0.0;
    let mut RADII = StackArray::<f64, 3>::new(1..=3);
    let mut RE: f64 = 0.0;
    let mut RP: f64 = 0.0;
    let mut SOLAR: f64 = 0.0;
    let mut SPOINT = StackArray::<f64, 3>::new(1..=3);
    let mut SUNALT: f64 = 0.0;
    let mut SUNLAT: f64 = 0.0;
    let mut SUNLON: f64 = 0.0;
    let mut SUNRAD: f64 = 0.0;
    let mut SUNSTA = StackArray::<f64, 6>::new(1..=6);
    let mut DIM: i32 = 0;
    let mut HANDLE: i32 = 0;

    //
    // SPICELIB functions
    //

    //
    // Local Parameters
    //

    //
    // Local Variables
    //

    //
    // Initial values
    //

    //
    // Open the test family.
    //
    testutil::TOPEN(b"F_GE01", ctx)?;

    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"Setup:  load kernels.", ctx)?;

    //
    // Leapseconds:  Note that the LSK is deleted after loading, so we
    // don't have to clean it up later.
    //
    testutil::TSTLSK(ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Create and load a PCK file. Delete the file afterwards.
    //
    testutil::TSTPCK(PCK, true, false, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Load an SPK file as well.
    //
    testutil::TSTSPK(SPK, true, &mut HANDLE, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // --- Case: ------------------------------------------------------
    //
    fstr::assign(&mut TITLE, b"Test SUBPT.  Find the sub-solar point of the sun on the Earth using the INTERCEPT definition.");

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

    spicelib::STR2ET(UTC, &mut ET, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::SUBPT(
        b"INTERCEPT",
        b"EARTH",
        ET,
        b"NONE",
        b"SUN",
        SPOINT.as_slice_mut(),
        &mut ALT,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::RECLAT(SPOINT.as_slice(), &mut RAD, &mut LON, &mut LAT);

    //
    // Get the state of the sun in Earth bodyfixed coordinates at ET.
    //
    spicelib::SPKGEO(
        10,
        ET,
        b"IAU_EARTH",
        399,
        SUNSTA.as_slice_mut(),
        &mut LT,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::RECLAT(SUNSTA.as_slice(), &mut SUNRAD, &mut SUNLON, &mut SUNLAT);

    //
    // Make sure the directional coordinates match up.
    //
    testutil::CHCKSD(b"Sub point lon", LON, b"~", SUNLON, TIGHT, OK, ctx)?;
    testutil::CHCKSD(b"Sub point lat", LAT, b"~", SUNLAT, TIGHT, OK, ctx)?;

    //
    // --- Case: ------------------------------------------------------
    //
    fstr::assign(&mut TITLE, b"Test SUBPT.  Find the sub-solar point of the sun on the Earth using the NEAR POINT definition.");

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

    spicelib::STR2ET(UTC, &mut ET, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Make sure that strings representing integers are parsed correctly.
    //
    spicelib::SUBPT(
        b"NEAR POINT",
        b"399",
        ET,
        b"NONE",
        b"10",
        SPOINT.as_slice_mut(),
        &mut ALT,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // We'll need the radii of the earth.
    //
    spicelib::BODVRD(b"EARTH", b"RADII", 3, &mut DIM, RADII.as_slice_mut(), ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    RE = RADII[1];
    RP = RADII[3];

    F = ((RE - RP) / RE);

    spicelib::RECGEO(SPOINT.as_slice(), RE, F, &mut LON, &mut LAT, &mut ALT, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Get the state of the sun in Earth bodyfixed coordinates at ET.
    //
    spicelib::SPKGEO(
        10,
        ET,
        b"IAU_EARTH",
        399,
        SUNSTA.as_slice_mut(),
        &mut LT,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::RECGEO(
        SUNSTA.as_slice(),
        RE,
        F,
        &mut SUNLON,
        &mut SUNLAT,
        &mut SUNALT,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Make sure the directional coordinates match up.
    //
    testutil::CHCKSD(b"Sub point lon", LON, b"~", SUNLON, TIGHT, OK, ctx)?;
    testutil::CHCKSD(b"Sub point lat", LAT, b"~", SUNLAT, TIGHT, OK, ctx)?;

    //
    // SUBPT error cases:
    //

    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"Invalid method.", ctx)?;

    spicelib::SUBPT(
        b"NARPOINT",
        b"399",
        ET,
        b"NONE",
        b"10",
        SPOINT.as_slice_mut(),
        &mut ALT,
        ctx,
    )?;
    testutil::CHCKXC(true, b"SPICE(DUBIOUSMETHOD)", OK, ctx)?;

    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"Invalid observer name.", ctx)?;

    spicelib::SUBPT(
        b"Nearpoint",
        b"earth",
        ET,
        b"NONE",
        b"sn",
        SPOINT.as_slice_mut(),
        &mut ALT,
        ctx,
    )?;
    testutil::CHCKXC(true, b"SPICE(IDCODENOTFOUND)", OK, ctx)?;

    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"Invalid target name.", ctx)?;

    spicelib::SUBPT(
        b"Nearpoint",
        b"erth",
        ET,
        b"NONE",
        b"sun",
        SPOINT.as_slice_mut(),
        &mut ALT,
        ctx,
    )?;
    testutil::CHCKXC(true, b"SPICE(IDCODENOTFOUND)", OK, ctx)?;

    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"Observer is target.", ctx)?;

    spicelib::SUBPT(
        b"Nearpoint",
        b"earth",
        ET,
        b"NONE",
        b"earth",
        SPOINT.as_slice_mut(),
        &mut ALT,
        ctx,
    )?;
    testutil::CHCKXC(true, b"SPICE(BODIESNOTDISTINCT)", OK, ctx)?;

    //
    //     ILLUM tests follow.
    //
    //
    // --- Case: ------------------------------------------------------
    //
    fstr::assign(&mut TITLE, b"Test ILLUM.  Find the illumination angles on the earth as seen from the moon, evaluated at the sub-moon point (NEARPOINT method).");

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

    spicelib::SUBPT(
        b"Nearpoint",
        b"earth",
        ET,
        b"NONE",
        b"moon",
        SPOINT.as_slice_mut(),
        &mut ALT,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::ILLUM(
        b"EARTH",
        ET,
        b"NONE",
        b"MOON",
        SPOINT.as_slice(),
        &mut PHASE,
        &mut SOLAR,
        &mut EMISSN,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // We should have an emission angle of zero.
    //
    testutil::CHCKSD(b"Emission angle", EMISSN, b"~", 0.0, TIGHT, OK, ctx)?;

    //
    // The phase angle should match the solar incidence angle.
    //
    testutil::CHCKSD(b"Phase angle", PHASE, b"~", SOLAR, TIGHT, OK, ctx)?;

    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"Repeat tests with integer codes.", ctx)?;

    spicelib::SUBPT(
        b"Nearpoint",
        b"399",
        ET,
        b"NONE",
        b"301",
        SPOINT.as_slice_mut(),
        &mut ALT,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::ILLUM(
        b"399",
        ET,
        b"NONE",
        b"301",
        SPOINT.as_slice(),
        &mut PHASE,
        &mut SOLAR,
        &mut EMISSN,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // We should have an emission angle of zero.
    //
    testutil::CHCKSD(b"Emission angle", EMISSN, b"~", 0.0, TIGHT, OK, ctx)?;

    //
    // The phase angle should match the solar incidence angle.
    //
    testutil::CHCKSD(b"Phase angle", PHASE, b"~", SOLAR, TIGHT, OK, ctx)?;

    //
    //     Now make the sun the observer:  test the solar incidence
    //     angle.
    //
    //
    // --- Case: ------------------------------------------------------
    //
    fstr::assign(&mut TITLE, b"Test ILLUM.  Find the illumination angles on the earth as seen from the sun, evaluated at the sub-sun point (NEARPOINT method).");

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

    spicelib::SUBPT(
        b"Nearpoint",
        b"earth",
        ET,
        b"NONE",
        b"sun",
        SPOINT.as_slice_mut(),
        &mut ALT,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::ILLUM(
        b"EARTH",
        ET,
        b"NONE",
        b"sun",
        SPOINT.as_slice(),
        &mut PHASE,
        &mut SOLAR,
        &mut EMISSN,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // We should have an solar incidence angle of zero.
    //
    testutil::CHCKSD(b"Solar inc. angle", SOLAR, b"~", 0.0, TIGHT, OK, ctx)?;

    //
    // The phase angle should match the solar incidence angle.
    //
    testutil::CHCKSD(b"Phase angle", PHASE, b"~", SOLAR, TIGHT, OK, ctx)?;

    //
    //     ILLUM error cases:
    //
    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"Invalid observer name.", ctx)?;

    spicelib::ILLUM(
        b"earth",
        ET,
        b"NONE",
        b"son",
        SPOINT.as_slice(),
        &mut PHASE,
        &mut SOLAR,
        &mut EMISSN,
        ctx,
    )?;
    testutil::CHCKXC(true, b"SPICE(IDCODENOTFOUND)", OK, ctx)?;

    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"Invalid target name.", ctx)?;

    spicelib::ILLUM(
        b"erth",
        ET,
        b"NONE",
        b"sun",
        SPOINT.as_slice(),
        &mut PHASE,
        &mut SOLAR,
        &mut EMISSN,
        ctx,
    )?;
    testutil::CHCKXC(true, b"SPICE(IDCODENOTFOUND)", OK, ctx)?;

    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"Observer is target.", ctx)?;

    spicelib::ILLUM(
        b"SUN",
        ET,
        b"NONE",
        b"sun",
        SPOINT.as_slice(),
        &mut PHASE,
        &mut SOLAR,
        &mut EMISSN,
        ctx,
    )?;
    testutil::CHCKXC(true, b"SPICE(BODIESNOTDISTINCT)", OK, ctx)?;

    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"No body-fixed frame associated with target.", ctx)?;

    spicelib::ILLUM(
        b"mars express",
        ET,
        b"NONE",
        b"sun",
        SPOINT.as_slice(),
        &mut PHASE,
        &mut SOLAR,
        &mut EMISSN,
        ctx,
    )?;
    testutil::CHCKXC(true, b"SPICE(NOFRAME)", OK, ctx)?;

    //
    //     SUBSOL tests follow.
    //
    //
    // --- Case: ------------------------------------------------------
    //
    fstr::assign(&mut TITLE, b"Test SUBSOL.  Find the sub-solar point of the sun on the Earth using the NEARPOINT definition.");

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

    spicelib::STR2ET(UTC, &mut ET, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::SUBSOL(
        b"NEARPOINT",
        b"EARTH",
        ET,
        b"NONE",
        b"SUN",
        SPOINT.as_slice_mut(),
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::SUBPT(
        b"NEARPOINT",
        b"EARTH",
        ET,
        b"NONE",
        b"SUN",
        EXPPNT.as_slice_mut(),
        &mut ALT,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::RECLAT(SPOINT.as_slice(), &mut RAD, &mut LON, &mut LAT);

    //
    // Make sure the surface points match up.
    //
    testutil::CHCKAD(
        b"Geometric sub solar point",
        SPOINT.as_slice(),
        b"~~/",
        EXPPNT.as_slice(),
        3,
        TIGHT,
        OK,
        ctx,
    )?;

    //
    // --- Case: ------------------------------------------------------
    //
    fstr::assign(
        &mut TITLE,
        b"Test SUBSOL.  Repeat test using integer codes.",
    );

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

    spicelib::STR2ET(UTC, &mut ET, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::SUBSOL(
        b"NEARPOINT",
        b"399",
        ET,
        b"NONE",
        b"10",
        SPOINT.as_slice_mut(),
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::SUBPT(
        b"NEARPOINT",
        b"EARTH",
        ET,
        b"NONE",
        b"SUN",
        EXPPNT.as_slice_mut(),
        &mut ALT,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::RECLAT(SPOINT.as_slice(), &mut RAD, &mut LON, &mut LAT);

    //
    // Make sure the surface points match up.
    //
    testutil::CHCKAD(
        b"Geometric sub solar point",
        SPOINT.as_slice(),
        b"~~/",
        EXPPNT.as_slice(),
        3,
        TIGHT,
        OK,
        ctx,
    )?;

    //
    // --- Case: ------------------------------------------------------
    //
    fstr::assign(&mut TITLE, b"Test SUBSOL.  Find the sub-solar point of the sun on the Earth using the INTERCEPT definition.");

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

    spicelib::STR2ET(UTC, &mut ET, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::SUBSOL(
        b"INTERCEPT",
        b"EARTH",
        ET,
        b"NONE",
        b"SUN",
        SPOINT.as_slice_mut(),
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::SUBPT(
        b"INTERCEPT",
        b"EARTH",
        ET,
        b"NONE",
        b"SUN",
        EXPPNT.as_slice_mut(),
        &mut ALT,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::RECLAT(SPOINT.as_slice(), &mut RAD, &mut LON, &mut LAT);

    //
    // Make sure the surface points match up.
    //
    testutil::CHCKAD(
        b"Geometric sub solar point",
        SPOINT.as_slice(),
        b"~~/",
        EXPPNT.as_slice(),
        3,
        TIGHT,
        OK,
        ctx,
    )?;

    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"Invalid method.", ctx)?;

    spicelib::SUBSOL(
        b"NARPOINT",
        b"399",
        ET,
        b"NONE",
        b"10",
        SPOINT.as_slice_mut(),
        ctx,
    )?;
    testutil::CHCKXC(true, b"SPICE(DUBIOUSMETHOD)", OK, ctx)?;

    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"Invalid observer name.", ctx)?;

    spicelib::SUBSOL(
        b"Nearpoint",
        b"earth",
        ET,
        b"NONE",
        b"sn",
        SPOINT.as_slice_mut(),
        ctx,
    )?;
    testutil::CHCKXC(true, b"SPICE(IDCODENOTFOUND)", OK, ctx)?;

    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"Invalid target name.", ctx)?;

    spicelib::SUBSOL(
        b"Nearpoint",
        b"erth",
        ET,
        b"NONE",
        b"sun",
        SPOINT.as_slice_mut(),
        ctx,
    )?;
    testutil::CHCKXC(true, b"SPICE(IDCODENOTFOUND)", OK, ctx)?;

    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"Observer is target.", ctx)?;

    spicelib::SUBSOL(
        b"Nearpoint",
        b"earth",
        ET,
        b"NONE",
        b"earth",
        SPOINT.as_slice_mut(),
        ctx,
    )?;
    testutil::CHCKXC(true, b"SPICE(BODIESNOTDISTINCT)", OK, ctx)?;

    //
    //

    //
    // --- Case: ------------------------------------------------------
    //
    testutil::TCASE(b"Clean up:  delete kernels.", ctx)?;

    spicelib::SPKUEF(HANDLE, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::DELFIL(SPK, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    // Close out the test family.
    //
    testutil::T_SUCCESS(OK, ctx);
    Ok(())
}