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
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const MAXSRF: i32 = 100;
const CNVTOL: f64 = 0.000001;
const NWMAX: i32 = 15;
const NWDIST: i32 = 5;
const NWSEP: i32 = 5;
const NWRR: i32 = 5;
const NWUDS: i32 = 5;
const NWPA: i32 = 5;
const NWILUM: i32 = 5;
const ADDWIN: f64 = 0.5;
const FRMNLN: i32 = 32;
const FOVTLN: i32 = 40;
const FTCIRC: &[u8] = b"CIRCLE";
const FTELLI: &[u8] = b"ELLIPSE";
const FTPOLY: &[u8] = b"POLYGON";
const FTRECT: &[u8] = b"RECTANGLE";
const ANNULR: &[u8] = b"ANNULAR";
const ANY: &[u8] = b"ANY";
const PARTL: &[u8] = b"PARTIAL";
const FULL: &[u8] = b"FULL";
const DSSHAP: &[u8] = b"DSK";
const EDSHAP: &[u8] = b"ELLIPSOID";
const PTSHAP: &[u8] = b"POINT";
const RYSHAP: &[u8] = b"RAY";
const SPSHAP: &[u8] = b"SPHERE";
const NOCTYP: i32 = 4;
const OCLLN: i32 = 7;
const SHPLEN: i32 = 9;
const MAXVRT: i32 = 10000;
const CIRFOV: &[u8] = b"CIRCLE";
const ELLFOV: &[u8] = b"ELLIPSE";
const POLFOV: &[u8] = b"POLYGON";
const RECFOV: &[u8] = b"RECTANGLE";
const NABCOR: i32 = 15;
const ABATSZ: i32 = 6;
const GEOIDX: i32 = 1;
const LTIDX: i32 = (GEOIDX + 1);
const STLIDX: i32 = (LTIDX + 1);
const CNVIDX: i32 = (STLIDX + 1);
const XMTIDX: i32 = (CNVIDX + 1);
const RELIDX: i32 = (XMTIDX + 1);
const CORLEN: i32 = 5;
const DSKSHP: i32 = 2;
const ELLSHP: i32 = 1;
const MTHLEN: i32 = 500;
const SUBLEN: i32 = 20;
const CVTLEN: i32 = 20;
const TANGNT: i32 = 1;
const GUIDED: i32 = 2;
const TMTLEN: i32 = 20;
const LMBCRV: i32 = 0;
const UMBRAL: i32 = 1;
const PNMBRL: i32 = 2;
const ACLLEN: i32 = 25;
const CTRCOR: i32 = 1;
const ELLCOR: i32 = 2;
const TOTAL1: i32 = -3;
const ANNLR1: i32 = -2;
const PARTL1: i32 = -1;
const NOOCC: i32 = 0;
const PARTL2: i32 = 1;
const ANNLR2: i32 = 2;
const TOTAL2: i32 = 3;
const ALPHA: f64 = 0.01;
const ATOL: f64 = 0.000000000001;
const BDNMLN: i32 = 36;
const FRNMLN: i32 = 32;
const POSLEN: i32 = 10;
struct SaveVars {
SVBFRM: Vec<u8>,
SVBMTH: Vec<u8>,
SVBNAM: Vec<u8>,
SVBSHP: Vec<u8>,
SVCORR: Vec<u8>,
SVFFRM: Vec<u8>,
SVFMTH: Vec<u8>,
SVFNAM: Vec<u8>,
SVFSHP: Vec<u8>,
SVONAM: Vec<u8>,
SVTYPE: Vec<u8>,
SVTYPS: ActualCharArray,
SVORIG: StackArray<f64, 3>,
SVBRAD: StackArray<f64, 3>,
SVFRAD: StackArray<f64, 3>,
SVMNBR: f64,
SVMNFR: f64,
SVMXBR: f64,
SVMXFR: f64,
SVBACK: i32,
SVFRNT: i32,
SVOBS: i32,
NCALLS: i32,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut SVBFRM = vec![b' '; FRNMLN as usize];
let mut SVBMTH = vec![b' '; MTHLEN as usize];
let mut SVBNAM = vec![b' '; BDNMLN as usize];
let mut SVBSHP = vec![b' '; SHPLEN as usize];
let mut SVCORR = vec![b' '; CORLEN as usize];
let mut SVFFRM = vec![b' '; FRNMLN as usize];
let mut SVFMTH = vec![b' '; MTHLEN as usize];
let mut SVFNAM = vec![b' '; BDNMLN as usize];
let mut SVFSHP = vec![b' '; SHPLEN as usize];
let mut SVONAM = vec![b' '; BDNMLN as usize];
let mut SVTYPE = vec![b' '; OCLLN as usize];
let mut SVTYPS = ActualCharArray::new(OCLLN, 1..=NOCTYP);
let mut SVORIG = StackArray::<f64, 3>::new(1..=3);
let mut SVBRAD = StackArray::<f64, 3>::new(1..=3);
let mut SVFRAD = StackArray::<f64, 3>::new(1..=3);
let mut SVMNBR: f64 = 0.0;
let mut SVMNFR: f64 = 0.0;
let mut SVMXBR: f64 = 0.0;
let mut SVMXFR: f64 = 0.0;
let mut SVBACK: i32 = 0;
let mut SVFRNT: i32 = 0;
let mut SVOBS: i32 = 0;
let mut NCALLS: i32 = 0;
NCALLS = 0;
{
use f2rust_std::data::Val;
let mut clist = []
.into_iter()
.chain(std::iter::repeat_n(Val::D(0.0), 3 as usize))
.chain([]);
SVORIG
.iter_mut()
.for_each(|n| *n = clist.next().unwrap().into_f64());
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
{
use f2rust_std::data::Val;
let mut clist = [Val::C(ANNULR), Val::C(ANY), Val::C(PARTL), Val::C(FULL)].into_iter();
SVTYPS
.iter_mut()
.for_each(|n| fstr::assign(n, clist.next().unwrap().into_str()));
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
Self {
SVBFRM,
SVBMTH,
SVBNAM,
SVBSHP,
SVCORR,
SVFFRM,
SVFMTH,
SVFNAM,
SVFSHP,
SVONAM,
SVTYPE,
SVTYPS,
SVORIG,
SVBRAD,
SVFRAD,
SVMNBR,
SVMNFR,
SVMXBR,
SVMXFR,
SVBACK,
SVFRNT,
SVOBS,
NCALLS,
}
}
}
//$Procedure ZZGFOCU ( GF, occultation utilities )
pub fn ZZGFOCU(
OCCTYP: &[u8],
FRONT: &[u8],
FSHAPE: &[u8],
FFRAME: &[u8],
BACK: &[u8],
BSHAPE: &[u8],
BFRAME: &[u8],
OBSRVR: &[u8],
ABCORR: &[u8],
TIME: f64,
OCSTAT: bool,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
//
// SPICELIB functions
//
//
// Local parameters
//
//
// ALPHA is a bound for the fraction of the speed of light
// at which target body may move, relative to the solar
// system barycenter.
//
//
// ATOL is a tolerance value for computing arc sine.
//
//
// Local variables
//
//
// Saved variables
//
//
// Initial values
//
//
// Below we initialize the list of occultation types.
//
//
// This routine should never be called directly.
//
CHKIN(b"ZZGFOCU", ctx)?;
SIGERR(b"SPICE(BOGUSENTRY)", ctx)?;
CHKOUT(b"ZZGFOCU", ctx)?;
Ok(())
}
//$Procedure ZZGFOCIN ( GF, occultation initialization )
pub fn ZZGFOCIN(
OCCTYP: &[u8],
FRONT: &[u8],
FSHAPE: &[u8],
FFRAME: &[u8],
BACK: &[u8],
BSHAPE: &[u8],
BFRAME: &[u8],
OBSRVR: &[u8],
ABCORR: &[u8],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let mut FIXFRM = [b' '; FRNMLN as usize];
let mut PNTDEF = [b' '; CVTLEN as usize];
let mut POSNAM = [b' '; POSLEN as usize];
let mut SHAPE = [b' '; SHPLEN as usize];
let mut SHPSTR = [b' '; SHPLEN as usize];
let mut SUBTYP = [b' '; SUBLEN as usize];
let mut TRMTYP = [b' '; TMTLEN as usize];
let mut RADII = StackArray::<f64, 3>::new(1..=3);
let mut CENTER: i32 = 0;
let mut CLSSID: i32 = 0;
let mut FFRMID: i32 = 0;
let mut FRCLSS: i32 = 0;
let mut IDBACK: i32 = 0;
let mut IDFRNT: i32 = 0;
let mut IDOBS: i32 = 0;
let mut LOC: i32 = 0;
let mut NSURF: i32 = 0;
let mut OCCNUM: i32 = 0;
let mut SRFLST = StackArray::<i32, 100>::new(1..=MAXSRF);
let mut TRGID: i32 = 0;
let mut ATTBLK = StackArray::<bool, 15>::new(1..=NABCOR);
let mut FOUND: bool = false;
let mut PRI: bool = false;
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"ZZGFOCIN", ctx)?;
//
// Find NAIF IDs for FRONT, BACK, and OBSRVR.
//
BODS2C(FRONT, &mut IDFRNT, &mut FOUND, ctx)?;
if !FOUND {
SETMSG(b"The front target object, \'#\', is not a recognized name for an ephemeris object. The cause of this problem may be that you need an updated version of the SPICE toolkit. ", ctx);
ERRCH(b"#", FRONT, ctx);
SIGERR(b"SPICE(IDCODENOTFOUND)", ctx)?;
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
BODS2C(BACK, &mut IDBACK, &mut FOUND, ctx)?;
if !FOUND {
SETMSG(b"The back target object, \'#\', is not a recognized name for an ephemeris object. The cause of this problem may be that you need an updated version of the SPICE toolkit. ", ctx);
ERRCH(b"#", BACK, ctx);
SIGERR(b"SPICE(IDCODENOTFOUND)", ctx)?;
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
BODS2C(OBSRVR, &mut IDOBS, &mut FOUND, ctx)?;
if !FOUND {
SETMSG(b"The observer, \'#\', is not a recognized name for an ephemeris object. The cause of this problem may be that you need an updated version of the SPICE toolkit. ", ctx);
ERRCH(b"#", OBSRVR, ctx);
SIGERR(b"SPICE(IDCODENOTFOUND)", ctx)?;
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
//
// Make sure the observer and both targets are distinct.
//
if (((IDFRNT == IDBACK) || (IDFRNT == IDOBS)) || (IDBACK == IDOBS)) {
SETMSG(b"The observer and both targets must be distinct objects, but are not: OBSRVR = #; FRONT = #; BACK = #.", ctx);
ERRCH(b"#", OBSRVR, ctx);
ERRCH(b"#", FRONT, ctx);
ERRCH(b"#", BACK, ctx);
SIGERR(b"SPICE(BODIESNOTDISTINCT)", ctx)?;
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
//
// Save the objects' names. We'll need these if
// we need to call SINCPT.
//
fstr::assign(&mut save.SVFNAM, FRONT);
fstr::assign(&mut save.SVBNAM, BACK);
fstr::assign(&mut save.SVONAM, OBSRVR);
//
// Store the ID codes, shape specifications, and body-fixed,
// body-centered frame names of the objects involved in this event.
// The shape arguments must be parsed in case they contain
// DSK specifications.
//
save.SVFRNT = IDFRNT;
fstr::assign(&mut save.SVFFRM, FFRAME);
save.SVBACK = IDBACK;
fstr::assign(&mut save.SVBFRM, BFRAME);
save.SVOBS = IDOBS;
//
// Save the input shape strings. These will be examined later,
// but we need them in their original form for computations
// involving DSK data. In the variable names below, "MTH"
// stands for "method"---the name used in SPICE geometry
// APIs for this type of input string.
//
fstr::assign(&mut save.SVFMTH, FSHAPE);
fstr::assign(&mut save.SVBMTH, BSHAPE);
//
// Parse the front body shape string.
//
if EQSTR(FSHAPE, b"POINT") {
fstr::assign(&mut save.SVFSHP, PTSHAP);
} else if EQSTR(FSHAPE, b"ELLIPSOID") {
fstr::assign(&mut save.SVFSHP, EDSHAP);
} else {
ZZPRSMET(
IDFRNT,
&save.SVFMTH,
MAXSRF,
&mut SHPSTR,
&mut SUBTYP,
&mut PRI,
&mut NSURF,
SRFLST.as_slice_mut(),
&mut PNTDEF,
&mut TRMTYP,
ctx,
)?;
if FAILED(ctx) {
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
if EQSTR(&SHPSTR, b"DSK") {
fstr::assign(&mut save.SVFSHP, DSSHAP);
} else {
SETMSG(b"Front target shape from FSHAPE string was <#>. Valid shapes are ELLIPSOID, POINT, and DSK.", ctx);
ERRCH(b"#", FSHAPE, ctx);
SIGERR(b"SPICE(INVALIDSHAPE)", ctx)?;
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
}
//
// Parse the back body shape string.
//
if EQSTR(BSHAPE, b"POINT") {
fstr::assign(&mut save.SVBSHP, PTSHAP);
} else if EQSTR(BSHAPE, b"ELLIPSOID") {
fstr::assign(&mut save.SVBSHP, EDSHAP);
} else {
ZZPRSMET(
IDFRNT,
&save.SVBMTH,
MAXSRF,
&mut SHPSTR,
&mut SUBTYP,
&mut PRI,
&mut NSURF,
SRFLST.as_slice_mut(),
&mut PNTDEF,
&mut TRMTYP,
ctx,
)?;
if FAILED(ctx) {
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
if EQSTR(&SHPSTR, b"DSK") {
fstr::assign(&mut save.SVBSHP, DSSHAP);
} else {
SETMSG(b"Back target shape from BSHAPE string was <#>. Valid shapes are ELLIPSOID, POINT, and DSK.", ctx);
ERRCH(b"#", BSHAPE, ctx);
SIGERR(b"SPICE(INVALIDSHAPE)", ctx)?;
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
}
//
// Check for invalid shape combinations.
//
if (fstr::eq(&save.SVFSHP, PTSHAP) && fstr::eq(&save.SVBSHP, PTSHAP)) {
SETMSG(b"Both front and back objects have POINT shape specifications; only one point shape is allowed. The other shape must be ELLIPSOID or DSK.", ctx);
SIGERR(b"SPICE(INVALIDSHAPECOMBO)", ctx)?;
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
} else if ((fstr::eq(&save.SVFSHP, DSSHAP) && fstr::ne(&save.SVBSHP, PTSHAP))
|| (fstr::eq(&save.SVBSHP, DSSHAP) && fstr::ne(&save.SVFSHP, PTSHAP)))
{
SETMSG(b"Front target shape from FSHAPE string was <#>; back target shape from BSHAPE was <#>. When one shape is DSK, the other must be POINT.", ctx);
ERRCH(b"#", &save.SVFSHP, ctx);
ERRCH(b"#", &save.SVBSHP, ctx);
SIGERR(b"SPICE(INVALIDSHAPECOMBO)", ctx)?;
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
//
// Save a single upper-case character representing the occultation
// type string.
//
LJUST(OCCTYP, &mut save.SVTYPE);
UCASE(&save.SVTYPE.to_vec(), &mut save.SVTYPE, ctx);
//
// Check the occultation type.
//
OCCNUM = ISRCHC(&save.SVTYPE, NOCTYP, save.SVTYPS.as_arg());
if (OCCNUM == 0) {
SETMSG(
b"The occultation type # is not recognized. Supported types are: #, #, #, #.",
ctx,
);
ERRCH(b"#", OCCTYP, ctx);
for I in 1..=NOCTYP {
ERRCH(b"#", &save.SVTYPS[I], ctx);
}
SIGERR(b"SPICE(INVALIDOCCTYPE)", ctx)?;
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
//
// If we have a point target, the occultation type must
// be 'ANY'.
//
if (fstr::eq(&save.SVFSHP, PTSHAP) || fstr::eq(&save.SVBSHP, PTSHAP)) {
if fstr::ne(&save.SVTYPE, ANY) {
SETMSG(b"Occultation type # is not allowed when either target body is modeled as a point. Set OCCTYP to ANY for use with point targets.", ctx);
ERRCH(b"#", OCCTYP, ctx);
SIGERR(b"SPICE(BADTYPESHAPECOMBO)", ctx)?;
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
}
//
// Check the aberration correction. If SPKEZR can't handle it,
// neither can we.
//
ZZVALCOR(ABCORR, ATTBLK.as_slice_mut(), ctx)?;
if FAILED(ctx) {
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
//
// Create a local aberration correction string without
// a stellar aberration correction specifier.
//
if ATTBLK[GEOIDX] {
fstr::assign(&mut save.SVCORR, b"NONE");
} else {
//
// The correction string specified either Newtonian or converged
// light time correction.
//
if ATTBLK[XMTIDX] {
fstr::assign(&mut save.SVCORR, b"X");
} else {
fstr::assign(&mut save.SVCORR, b" ");
}
if ATTBLK[CNVIDX] {
SUFFIX(b"CN", 0, &mut save.SVCORR);
} else {
SUFFIX(b"LT", 0, &mut save.SVCORR);
}
}
//
// Check the front and back targets' shapes, frames
// and radii.
//
for I in 1..=2 {
if (I == 1) {
fstr::assign(&mut POSNAM, b"front");
fstr::assign(&mut FIXFRM, FFRAME);
TRGID = IDFRNT;
fstr::assign(&mut SHAPE, &save.SVFSHP);
} else {
fstr::assign(&mut POSNAM, b"back");
fstr::assign(&mut FIXFRM, BFRAME);
TRGID = IDBACK;
fstr::assign(&mut SHAPE, &save.SVBSHP);
}
if fstr::eq(&SHAPE, EDSHAP) {
//
// Fetch and check the radii.
//
ZZGFTREB(TRGID, RADII.as_slice_mut(), ctx)?;
if FAILED(ctx) {
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
//
// Checks of radii have been completed.
//
if (I == 1) {
MOVED(RADII.as_slice(), 3, save.SVFRAD.as_slice_mut());
//
// Select smallest and largest semi-axis lengths of body
// for later tests.
//
MINAD(save.SVFRAD.as_slice(), 3, &mut save.SVMNFR, &mut LOC);
MAXAD(save.SVFRAD.as_slice(), 3, &mut save.SVMXFR, &mut LOC);
} else {
MOVED(RADII.as_slice(), 3, save.SVBRAD.as_slice_mut());
MINAD(save.SVBRAD.as_slice(), 3, &mut save.SVMNBR, &mut LOC);
MAXAD(save.SVBRAD.as_slice(), 3, &mut save.SVMXBR, &mut LOC);
}
if FAILED(ctx) {
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
}
//
// We've performed radii checks for an ellipsoidal target.
// Minimum and maximum bounding radii are set, if the target
// shape is modeled as an ellipsoid.
//
//
// Check body-fixed frame for extended targets.
//
if (fstr::eq(&SHAPE, EDSHAP) || fstr::eq(&SHAPE, DSSHAP)) {
//
// The target is ellipsoidal or is modeled using DSK data;
// there must be a target body-fixed frame associated with
// this body.
//
if fstr::eq(&FIXFRM, b" ") {
SETMSG(b"The # target shape is represented by an ellipsoid or by DSK data, but the associated body-fixed frame name is blank.", ctx);
ERRCH(b"#", &POSNAM, ctx);
SIGERR(b"SPICE(INVALIDFRAME)", ctx)?;
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
} else {
//
// Look up the target's body-fixed frame ID code.
//
NAMFRM(&FIXFRM, &mut FFRMID, ctx)?;
if FAILED(ctx) {
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
if (FFRMID == 0) {
SETMSG(
b"The # target\'s body-fixed frame name # is not recognized.",
ctx,
);
ERRCH(b"#", &POSNAM, ctx);
ERRCH(b"#", &FIXFRM, ctx);
SIGERR(b"SPICE(INVALIDFRAME)", ctx)?;
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
//
// Obtain the center of the frame and verify it's the
// Ith target.
//
FRINFO(
FFRMID,
&mut CENTER,
&mut FRCLSS,
&mut CLSSID,
&mut FOUND,
ctx,
)?;
if FAILED(ctx) {
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
if !FOUND {
//
// Since we mapped the frame name to an ID code, we
// expect to find the frame info. So control should
// never reach this point.
//
SETMSG(b"Frame ID found for # body-fixed frame # but FRINFO couldn\'t find frame info.", ctx);
ERRCH(b"#", &POSNAM, ctx);
ERRCH(b"#", &FIXFRM, ctx);
SIGERR(b"SPICE(BUG)", ctx)?;
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
if (CENTER != TRGID) {
//
// The body-fixed frame for the current target
// isn't actually centered on the body.
//
SETMSG(b"Supposed body-fixed frame # for # target # is actually centered on body #.", ctx);
ERRCH(b"#", &FIXFRM, ctx);
ERRCH(b"#", &POSNAM, ctx);
ERRINT(b"#", TRGID, ctx);
ERRINT(b"#", CENTER, ctx);
SIGERR(b"SPICE(INVALIDFRAME)", ctx)?;
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
}
}
//
// We've performed frame checks for an extended target.
//
//
// Obtain radii of inner and outer bounding spheres for
// DSK targets.
//
if fstr::eq(&SHAPE, DSSHAP) {
//
// Note that TRGID and FFRMID refer to the current
// target (out of two); "FFRMID" means "fixed frame ID."
//
ZZSUDSKI(TRGID, NSURF, SRFLST.as_slice(), FFRMID, ctx)?;
if FAILED(ctx) {
CHKOUT(b"ZZGFOCIN", ctx)?;
return Ok(());
}
if (I == 1) {
ZZMINRAD(&mut save.SVMNFR, ctx);
ZZMAXRAD(&mut save.SVMXFR, ctx);
} else {
ZZMINRAD(&mut save.SVMNBR, ctx);
ZZMAXRAD(&mut save.SVMXBR, ctx);
}
}
//
// Initialize bounding radii and body-fixed frame
// names for point targets.
//
if fstr::eq(&SHAPE, PTSHAP) {
//
// Zero out radius values for this target; set the
// frame to blank.
//
if (I == 1) {
CLEARD(3, save.SVFRAD.as_slice_mut());
save.SVMNFR = 0.0;
save.SVMXFR = 0.0;
fstr::assign(&mut save.SVFFRM, b" ");
} else {
CLEARD(3, save.SVBRAD.as_slice_mut());
save.SVMNBR = 0.0;
save.SVMXBR = 0.0;
fstr::assign(&mut save.SVBFRM, b" ");
}
}
//
// We've performed shape, and if applicable, frame and radii
// checks for the Ith target. Bounding radii have been obtained
// for extended targets.
//
}
//
// We've performed shape, and if applicable, frame and radii
// checks for both targets.
//
CHKOUT(b"ZZGFOCIN", ctx)?;
Ok(())
}
//$Procedure ZZGFOCST ( GF, "in occultation?" )
pub fn ZZGFOCST(TIME: f64, OCSTAT: &mut bool, ctx: &mut Context) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let mut BCKFRT = StackArray::<f64, 3>::new(1..=3);
let mut BCKOBS = StackArray::<f64, 3>::new(1..=3);
let mut BCKPOS = StackArray::<f64, 3>::new(1..=3);
let mut BDIST: f64 = 0.0;
let mut BSMAXS = StackArray2D::<f64, 9>::new(1..=3, 1..=3);
let mut ETBCOR: f64 = 0.0;
let mut ETFCOR: f64 = 0.0;
let mut FDIST: f64 = 0.0;
let mut FRTBCK = StackArray::<f64, 3>::new(1..=3);
let mut FRTOBS = StackArray::<f64, 3>::new(1..=3);
let mut FRTPOS = StackArray::<f64, 3>::new(1..=3);
let mut FSMAXS = StackArray2D::<f64, 9>::new(1..=3, 1..=3);
let mut LTBACK: f64 = 0.0;
let mut LTFRNT: f64 = 0.0;
let mut MAXANG: f64 = 0.0;
let mut MINANG: f64 = 0.0;
let mut MTEMP = StackArray2D::<f64, 9>::new(1..=3, 1..=3);
let mut SPOINT = StackArray::<f64, 3>::new(1..=3);
let mut SRFVEC = StackArray::<f64, 3>::new(1..=3);
let mut SRAD: f64 = 0.0;
let mut T2SEP: f64 = 0.0;
let mut TDIST: f64 = 0.0;
let mut TRGEPC: f64 = 0.0;
let mut TRGSEP: f64 = 0.0;
let mut OCCODE: i32 = 0;
let mut FOUND: bool = false;
let mut PNTOCC: bool = false;
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"ZZGFOCST", ctx)?;
//
// Initialize the state output.
//
*OCSTAT = false;
//
// Get the apparent positions of FRONT and BACK as seen from the
// observer.
//
SPKEZP(
save.SVFRNT,
TIME,
b"J2000",
&save.SVCORR,
save.SVOBS,
FRTPOS.as_slice_mut(),
&mut LTFRNT,
ctx,
)?;
SPKEZP(
save.SVBACK,
TIME,
b"J2000",
&save.SVCORR,
save.SVOBS,
BCKPOS.as_slice_mut(),
&mut LTBACK,
ctx,
)?;
if FAILED(ctx) {
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
}
//
// Handle the cases of one and two extended targets
// separately.
//
if (fstr::eq(&save.SVBSHP, EDSHAP) && fstr::eq(&save.SVFSHP, EDSHAP)) {
//
// The caller has selected a test for a partial, annular or full
// occultation using ellipsoidal shape models.
//
// Look up the axes of each target body in the J2000 frame at the
// light time corrected epoch for that body.
//
ZZCOREPC(&save.SVCORR, TIME, LTBACK, &mut ETBCOR, ctx)?;
PXFORM(&save.SVBFRM, b"J2000", ETBCOR, MTEMP.as_slice_mut(), ctx)?;
if FAILED(ctx) {
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
}
//
// Scale the columns of MTEMP by the axis lengths of the back
// target.
//
for I in 1..=3 {
VSCL(
save.SVBRAD[I],
MTEMP.subarray([1, I]),
BSMAXS.subarray_mut([1, I]),
);
}
ZZCOREPC(&save.SVCORR, TIME, LTFRNT, &mut ETFCOR, ctx)?;
PXFORM(&save.SVFFRM, b"J2000", ETFCOR, MTEMP.as_slice_mut(), ctx)?;
if FAILED(ctx) {
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
}
//
// Scale the columns of MTEMP by the axis lengths of the second
// target.
//
for I in 1..=3 {
VSCL(
save.SVFRAD[I],
MTEMP.subarray([1, I]),
FSMAXS.subarray_mut([1, I]),
);
}
//
// Classify the occultation state of BACK by FRONT as seen from
// the observer.
//
OCCODE = ZZOCCED(
save.SVORIG.as_slice(),
BCKPOS.as_slice(),
BSMAXS.as_slice(),
FRTPOS.as_slice(),
FSMAXS.as_slice(),
ctx,
)?;
if FAILED(ctx) {
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
}
if (OCCODE == NOOCC) {
//
// Neither body occults the other.
//
*OCSTAT = false;
} else if (fstr::eq(&save.SVTYPE, ANY) && (OCCODE < 0)) {
//
// The "of" body (target 1) is at least partially occulted by
// the BY object.
//
*OCSTAT = true;
} else if (fstr::eq(&save.SVTYPE, FULL) && (OCCODE == TOTAL1)) {
//
// The BACK body is in total occultation.
//
*OCSTAT = true;
} else if (fstr::eq(&save.SVTYPE, ANNULR) && (OCCODE == ANNLR1)) {
//
// The BACK body is in annular occultation.
//
*OCSTAT = true;
} else if (fstr::eq(&save.SVTYPE, PARTL) && (OCCODE == PARTL1)) {
//
// The BACK body is partially occulted.
//
*OCSTAT = true;
} else {
//
// The occultation state doesn't match the requested state.
//
*OCSTAT = false;
}
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
} else if ((((fstr::eq(&save.SVFSHP, EDSHAP) && fstr::eq(&save.SVBSHP, PTSHAP))
|| (fstr::eq(&save.SVFSHP, DSSHAP) && fstr::eq(&save.SVBSHP, PTSHAP)))
|| (fstr::eq(&save.SVFSHP, PTSHAP) && fstr::eq(&save.SVBSHP, EDSHAP)))
|| (fstr::eq(&save.SVFSHP, PTSHAP) && fstr::eq(&save.SVBSHP, DSSHAP)))
{
//
// One of the targets is modeled as a point; the other is
// modeled as an ellipsoid or a DSK shape.
//
// If the front target is an ellipsoid or a DSK shape and the
// back target is a point, we'll classify the geometry as a
// "point occultation." Otherwise we have a "point transit" case.
// We'll set the logical flag PNTOCC to .TRUE. to indicate a
// point occultation.
//
PNTOCC = fstr::eq(&save.SVBSHP, PTSHAP);
//
// We're going to start out by doing some error checking.
// We're looking for intersections of the participating
// objects: these should never occur.
//
// Let BDIST, FDIST be the distances from the observer
// to the back and front targets, respectively.
//
BDIST = VNORM(BCKPOS.as_slice());
FDIST = VNORM(FRTPOS.as_slice());
//
// Find the vector from BACK to FRONT. We'll use this later,
// but we want it now in order to make sure that BACK doesn't
// intersect FRONT.
//
VSUB(FRTPOS.as_slice(), BCKPOS.as_slice(), BCKFRT.as_slice_mut());
if PNTOCC {
//
// The front target is an extended shape.
//
if (FDIST <= save.SVMNFR) {
//
// The observer is INSIDE the front target. We
// treat this as an error.
//
SETMSG(b"Observer is inside front target body.", ctx);
SIGERR(b"SPICE(NOTDISJOINT)", ctx)?;
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
} else if (BDIST == 0.0) {
SETMSG(b"Back target coincides with observer.", ctx);
SIGERR(b"SPICE(NOTDISJOINT)", ctx)?;
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
} else if (VNORM(BCKFRT.as_slice()) <= save.SVMNFR) {
SETMSG(b"BACK target is inside FRONT target.", ctx);
SIGERR(b"SPICE(NOTDISJOINT)", ctx)?;
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
}
} else {
//
// The back target is an extended shape.
//
if (BDIST <= save.SVMNBR) {
//
// The observer is INSIDE the back target. We
// treat this as an error.
//
SETMSG(b"Observer is inside back target body.", ctx);
SIGERR(b"SPICE(NOTDISJOINT)", ctx)?;
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
} else if (FDIST == 0.0) {
SETMSG(b"Front target coincides with observer.", ctx);
SIGERR(b"SPICE(NOTDISJOINT)", ctx)?;
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
} else if (VNORM(BCKFRT.as_slice()) <= save.SVMNBR) {
SETMSG(b"FRONT target is inside BACK target.", ctx);
SIGERR(b"SPICE(NOTDISJOINT)", ctx)?;
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
}
}
//
// Find angular separation of the target centers as
// seen by the observer.
//
TRGSEP = VSEP(BCKPOS.as_slice(), FRTPOS.as_slice(), ctx);
//
// Find angular radius of the outer bounding sphere of the
// extended target, as seen by the observer.
//
// In computing this angular radius, scale up the bounding
// sphere to compensate for the light time error we've made
// by computing light time to the target's center. The
// correct value to use is light time to the limb point having
// minimum angular separation from the point target.
//
// Presuming the extended target can move no faster than
// alpha*c (where c represents the speed of light in a vacuum),
// and considering the fact that the light time error cannot
// exceed r/c, where r is the radius of the outer bounding sphere
// of the ellipsoid, we find that the magnitude of the position
// error of the extended target cannot exceed alpha*r. Then the
// correctly positioned target---that is, located at
// the position corresponding to the correct light time
// correction---must be contained in the outer bounding
// sphere we've found, if we scale the sphere up by 1+alpha.
//
// Perform the test only if the observer is outside the
// outer bounding sphere of the extended target.
//
if PNTOCC {
SRAD = (((1 as f64) + ALPHA) * save.SVMXFR);
TDIST = FDIST;
} else {
SRAD = (((1 as f64) + ALPHA) * save.SVMXBR);
TDIST = BDIST;
}
if (SRAD < TDIST) {
MAXANG = DASINE((SRAD / TDIST), ATOL, ctx)?;
if FAILED(ctx) {
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
}
if (TRGSEP > MAXANG) {
//
// No occultation is possible.
//
*OCSTAT = false;
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
}
}
//
// We'll need the negatives of the observer-target vectors in
// several places later, so compute them now.
//
VMINUS(FRTPOS.as_slice(), FRTOBS.as_slice_mut());
VMINUS(BCKPOS.as_slice(), BCKOBS.as_slice_mut());
//
// Now check for an occulted state assuming a spherical extended
// body with radius equal to the minimum semi-axis. Again,
// adjust the sphere for our light time error.
//
if PNTOCC {
MINANG = DASINE(((((1 as f64) - ALPHA) * save.SVMNFR) / FDIST), ATOL, ctx)?;
} else {
MINANG = DASINE(((((1 as f64) - ALPHA) * save.SVMNBR) / BDIST), ATOL, ctx)?;
}
if FAILED(ctx) {
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
}
if (TRGSEP < MINANG) {
//
// The targets must overlap as seen from the observer.
//
if PNTOCC {
//
// Examine the angle between the vector from FRONT to the
// observer and the vector from FRONT to BACK. If that
// angle is greater than or equal to the complement of the
// angular radius of FRONT, then FRONT occults BACK. First
// find the position of FRONT and BACK relative to each
// other.
//
VMINUS(BCKFRT.as_slice(), FRTBCK.as_slice_mut());
T2SEP = VSEP(FRTOBS.as_slice(), FRTBCK.as_slice(), ctx);
if (T2SEP > (HALFPI(ctx) - MINANG)) {
//
// There must be an occultation.
//
*OCSTAT = true;
} else {
//
// There can't be an occultation: the "back" object
// is actually in transit across the "front" object.
//
*OCSTAT = false;
}
} else {
//
// We're looking for a point transit condition.
//
T2SEP = VSEP(BCKOBS.as_slice(), BCKFRT.as_slice(), ctx);
if (T2SEP < (HALFPI(ctx) - MINANG)) {
//
// There must be a transit.
//
*OCSTAT = true;
} else {
//
// There can't be a transit: the "back" object
// actually occults the "front" object.
//
*OCSTAT = false;
}
}
//
// OCSTAT has been set.
//
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
}
//
// If we've reached this point, we have a situation where we
// can't classify the geometry using bounding spheres. Instead,
// we'll see whether the observer-point target vector intersects
// the extended body.
//
if PNTOCC {
//
// The front body is the extended one.
//
save.NCALLS = (save.NCALLS + 1);
SINCPT(
&save.SVFMTH,
&save.SVFNAM,
TIME,
&save.SVFFRM,
&save.SVCORR,
&save.SVONAM,
b"J2000",
BCKPOS.as_slice(),
SPOINT.as_slice_mut(),
&mut TRGEPC,
SRFVEC.as_slice_mut(),
&mut FOUND,
ctx,
)?;
if FAILED(ctx) {
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
}
if FOUND {
//
// There's an intercept. If the distance from the observer
// to the intercept is less than the distance from the
// observer to the back target, then the back target is
// occulted; otherwise there's a point transit, which is
// not considered an occultation in this case.
//
*OCSTAT = (VNORM(SRFVEC.as_slice()) < BDIST);
} else {
//
// There's no overlap and hence no occultation.
//
*OCSTAT = false;
}
} else {
//
// The back body is the extended one.
//
SINCPT(
&save.SVBMTH,
&save.SVBNAM,
TIME,
&save.SVBFRM,
&save.SVCORR,
&save.SVONAM,
b"J2000",
FRTPOS.as_slice(),
SPOINT.as_slice_mut(),
&mut TRGEPC,
SRFVEC.as_slice_mut(),
&mut FOUND,
ctx,
)?;
if FAILED(ctx) {
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
}
if FOUND {
//
// There's an intercept. If the distance from the observer
// to the intercept is greater than the distance from the
// observer to the front target, then the front target is
// in transit across the back target; otherwise there's a
// point occultation, which is not considered a transit in
// this case.
//
*OCSTAT = (VNORM(SRFVEC.as_slice()) > FDIST);
} else {
//
// There's no overlap and hence no occultation.
//
*OCSTAT = false;
}
}
} else {
//
// Bad combination of shapes. We expect this situation to have
// been caught at initialization time, but make this check for
// safety.
//
SETMSG(b"The combination of shapes of front and back targets is not supported: front shape = #; back shape = #.", ctx);
ERRCH(b"#", &save.SVFSHP, ctx);
ERRCH(b"#", &save.SVBSHP, ctx);
SIGERR(b"SPICE(INVALIDSHAPECOMBO)", ctx)?;
CHKOUT(b"ZZGFOCST", ctx)?;
return Ok(());
}
CHKOUT(b"ZZGFOCST", ctx)?;
Ok(())
}