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
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
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 RECSYS: &[u8] = b"RECTANGULAR";
const LATSYS: &[u8] = b"LATITUDINAL";
const SPHSYS: &[u8] = b"SPHERICAL";
const RADSYS: &[u8] = b"RA/DEC";
const CYLSYS: &[u8] = b"CYLINDRICAL";
const GEOSYS: &[u8] = b"GEODETIC";
const PGRSYS: &[u8] = b"PLANETOGRAPHIC";
const XCRD: &[u8] = b"X";
const YCRD: &[u8] = b"Y";
const ZCRD: &[u8] = b"Z";
const RADCRD: &[u8] = b"RADIUS";
const LONCRD: &[u8] = b"LONGITUDE";
const LATCRD: &[u8] = b"LATITUDE";
const RACRD: &[u8] = b"RIGHT ASCENSION";
const DECCRD: &[u8] = b"DECLINATION";
const RNGCRD: &[u8] = b"RANGE";
const CLTCRD: &[u8] = b"COLATITUDE";
const ALTCRD: &[u8] = b"ALTITUDE";
const POSDEF: &[u8] = b"POSITION";
const SOBDEF: &[u8] = b"SUB-OBSERVER POINT";
const SINDEF: &[u8] = b"SURFACE INTERCEPT POINT";
const NWREL: i32 = 5;
const NWLONG: i32 = 7;
const EXWIDX: i32 = ((NWREL + NWLONG) + 1);
const MXBEGM: i32 = 55;
const MXENDM: i32 = 13;
const MXMSG: i32 = ((MXBEGM + MXENDM) + 10);
const LBCELL: i32 = -5;
const BCAMRG: f64 = 0.00000000001;
const LCXMRG: f64 = 0.000000000001;
const LB: i32 = LBCELL;
const LBPOOL: i32 = LBCELL;
const NC: i32 = 7;
const BDNMLN: i32 = 36;
const NAMLEN: i32 = 32;
const OPLEN: i32 = 6;
const FUNLEN: i32 = 50;
const CRDLEN: i32 = 32;
const SYSLEN: i32 = 32;
const RPTLEN: i32 = 80;
struct SaveVars {
OPS: ActualCharArray,
Y: StackArray<f64, 3>,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut OPS = ActualCharArray::new(OPLEN, 1..=NC);
let mut Y = StackArray::<f64, 3>::new(1..=3);
{
use f2rust_std::data::Val;
let mut clist = [
Val::C(b"<"),
Val::C(b"="),
Val::C(b">"),
Val::C(b"LOCMIN"),
Val::C(b"ABSMIN"),
Val::C(b"LOCMAX"),
Val::C(b"ABSMAX"),
]
.into_iter();
OPS.iter_mut()
.for_each(|n| fstr::assign(n, clist.next().unwrap().into_str()));
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
{
use f2rust_std::data::Val;
let mut clist = [Val::D(0.0), Val::D(1.0), Val::D(0.0)].into_iter();
Y.iter_mut()
.for_each(|n| *n = clist.next().unwrap().into_f64());
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
Self { OPS, Y }
}
}
//$Procedure ZZGFLONG ( GF, longitude solver )
pub fn ZZGFLONG(
VECDEF: &[u8],
METHOD: &[u8],
TARGET: &[u8],
REF: &[u8],
ABCORR: &[u8],
OBSRVR: &[u8],
DREF: &[u8],
DVEC: &[f64],
CRDSYS: &[u8],
CRDNAM: &[u8],
RELATE: &[u8],
REFVAL: f64,
TOL: f64,
ADJUST: f64,
UDSTEP: fn(&mut f64, &mut f64, &mut Context) -> f2rust_std::Result<()>,
UDREFN: fn(f64, f64, bool, bool, &mut f64) -> (),
RPT: bool,
UDREPI: fn(&[f64], &[u8], &[u8], &mut Context) -> f2rust_std::Result<()>,
UDREPU: fn(f64, f64, f64, &mut Context) -> f2rust_std::Result<()>,
UDREPF: fn(&mut Context) -> f2rust_std::Result<()>,
BAIL: bool,
UDBAIL: fn() -> bool,
MW: i32,
NW: i32,
WORK: &mut [f64],
CNFINE: &[f64],
RESULT: &mut [f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let DVEC = DummyArray::new(DVEC, 1..=3);
let mut WORK = DummyArrayMut2D::new(WORK, LBCELL..=MW, 1..=NW);
let CNFINE = DummyArray::new(CNFINE, LBCELL..);
let mut RESULT = DummyArrayMut::new(RESULT, LBCELL..);
let mut NRMCRD = [b' '; CRDLEN as usize];
let mut NRMSYS = [b' '; SYSLEN as usize];
let mut PRXCRD = [b' '; CRDLEN as usize];
let mut PRXFUN = [b' '; FUNLEN as usize];
let mut PRXSYS = [b' '; SYSLEN as usize];
let mut RCTRNM = [b' '; BDNMLN as usize];
let mut RPTPRE = ActualCharArray::new(RPTLEN, 1..=2);
let mut RPTSUF = ActualCharArray::new(RPTLEN, 1..=2);
let mut TMPLAT = [b' '; RPTLEN as usize];
let mut RLIST = ActualCharArray::new(NAMLEN, 1..=NWLONG);
let mut UOP = [b' '; OPLEN as usize];
let mut PRXREL = [b' '; OPLEN as usize];
let mut ALT: f64 = 0.0;
let mut CMPVAL: f64 = 0.0;
let mut CV: f64 = 0.0;
let mut ET: f64 = 0.0;
let mut EXTVAL: f64 = 0.0;
let mut LAT: f64 = 0.0;
let mut LOCREF: f64 = 0.0;
let mut LOCTOL: f64 = 0.0;
let mut LON: f64 = 0.0;
let mut PRXVAL: f64 = 0.0;
let mut R2OVR2: f64 = 0.0;
let mut START: f64 = 0.0;
let mut SV: f64 = 0.0;
let mut VALUE: f64 = 0.0;
let mut XRFVAL: f64 = 0.0;
let mut BOT: i32 = 0;
let mut CLASS: i32 = 0;
let mut CLSSID: i32 = 0;
let mut COMPL: i32 = 0;
let mut F1: i32 = 0;
let mut F2: i32 = 0;
let mut FRCODE: i32 = 0;
let mut HEAD: i32 = 0;
let mut I: i32 = 0;
let mut LEFT: i32 = 0;
let mut N: i32 = 0;
let mut NEEDWN = StackArray::<i32, 13>::new(LBCELL..=NWLONG);
let mut NEXT: i32 = 0;
let mut NL: i32 = 0;
let mut NODE: i32 = 0;
let mut Q1: i32 = 0;
let mut Q2: i32 = 0;
let mut Q3: i32 = 0;
let mut Q4: i32 = 0;
let mut QUAD: i32 = 0;
let mut REFCTR: i32 = 0;
let mut REGION = StackArray::<i32, 3>::new(1..=3);
let mut RES: i32 = 0;
let mut RES1: i32 = 0;
let mut RES2: i32 = 0;
let mut RIGHT: i32 = 0;
let mut S: i32 = 0;
let mut TOP: i32 = 0;
let mut TOTAL: i32 = 0;
let mut WH: i32 = 0;
let mut WIX = StackArray::<i32, 7>::new(1..=NWLONG);
let mut WWPOOL = StackArray2D::<i32, 26>::new(1..=2, LBPOOL..=NWLONG);
let mut FLIP: bool = false;
let mut FOUND: bool = false;
//
// SPICELIB functions
//
//
// Entry points in the coordinate utility package.
// We have the usual GF entry points for the coordinate, plus
// utilities for the cosine and sine of the coordinate.
//
// Names and meanings:
//
// ZZGFCODC Is coordinate decreasing?
// ZZGFCOG Get coordinate value.
// ZZGFCOCD Is cosine of the coordinate decreasing?
// ZZGFCOCG Get cosine of the coordinate value.
// ZZGFCOSD Is sine of the coordinate decreasing?
// ZZGFCOSG Get sine of the coordinate value.
//
//
// The routine to test UDFUNC < REFVAL.
//
//
// Local parameters
//
//
//
// Margin for branch cut avoidance. Units are radians:
//
//
// Margin for local extrema search. Units are radians:
//
//
// Short alias for LBCELL:
//
//
// Number of supported comparison operators:
//
//
// Assorted string lengths:
//
// Maximum body name length:
//
//
// NAMLEN is the maximum length of both a frame name and of
// any kernel pool variable name.
//
//
// OPLEN is the maximum string length for comparison operators.
// OPLEN may grow if new comparisons are added.
//
//
// FUNLEN is the length of the function name string.
//
//
// CRDLEN is the maximum length of a coordinate name.
//
//
// SYSLEN is the maximum length of a coordinate system name.
//
//
// RPTLEN is the maximum length of a progress reporter message.
//
//
// Local variables
//
//
// Saved variables
//
//
// Initial values
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"ZZGFLONG", ctx)?;
}
//
// Overview
// ========
//
//
// Terminology
// -----------
//
// - Proxy function
//
// In many cases, instead of finding a time window
// where the coordinate of interest satisfies a specified
// condition, we'll find a time window where a second, related
// function satisfies a related condition. We'll call this
// second function the "proxy function."
//
// The proxy function will be one that is "better behaved"
// than the original in the domain of interest. For
// example, when searching for times when longitude is
// equal to pi radians, we may instead intersect the
// confinement window with a window on which cosine of
// longitude is negative, and then within that more
// restricted intersection, find the times when the sine
// of longitude is zero. In this example sine(longitude)
// is a proxy function for longitude.
//
// - Resolution of a function
//
// Below we'll refer to the "resolution" of a proxy function.
// In order to find roots accurately, it's necessary for
// a proxy function to change a by a reasonable amount
// when the function it represents changes. Mathematically,
// the magnitude of the derivative of the proxy function
// with respect to the function it represents should not
// be too much less than 1. An example of a *bad* choice
// of a proxy function would be to use cosine of longitude
// as a proxy function for longitude in a confinement
// window in which longitude is close to zero. This
// choice would lead to considerable loss of accuracy. On
// the other hand, sine of longitude would be a reasonable
// proxy function for this case.
//
// - The unit circle
//
// In the discussion below, we'll freely associate angular
// coordinates with locations on the unit circle. For example,
// we might say "longitude is in the upper half of the unit
// circle."
//
// - Window aliases
//
// We're going to make extensive use workspace windows.
// In many cases, we'll need to reuse various windows for
// different purposes at different times. So instead
// of using mnemonic parameter names for window indices,
// we'll use variables we call window aliases. For example,
// when we want to use the 8th workspace window to hold
// the window of times when longitude is in the upper half
// of the unit circle, we'll set the alias UPPER equal to
// 8, so we can refer to the window by
//
// WORK( LB, UPPER )
//
// and keep track of what we're using the window for.
//
// Some of the aliases aren't wonderful names: we use
// F1, F2, etc. to represent "free" window 1, 2, etc.
//
//
// Algorithm
// ---------
//
// - Equality
//
// We use sine or cosine of the coordinate as proxy functions.
// The proxy function having the better resolution is
// selected. For example, to find times when right ascension
// is 2*pi/3, we search for the times when cosine of right
// ascension is equal to -1/2. Since these searches can produce
// spurious roots, we cast out any such roots after completing
// the search.
//
//
// - Local extrema
//
// We first find local extrema in the right and left half
// circles, using longitude as a proxy function on the right
// half and right ascension on the left.
//
//
// - Absolute extrema
//
// We deal with absolute extrema before inequalities because
// this allows us to use the code (later in this routine) for
// inequality relations when the user specifies a non-zero
// ADJUST value. When ADJUST is non-zero, having the actual
// extreme value in hand, we can easily solve for the window
// in which the coordinate is greater than
//
// <absolute maximum> - ADJUST
//
// or less than
//
// <absolute minimum> + ADJUST
//
// Below, "Searching in a region" means that we find the
// window when the coordinate is in the region (and of course
// in the confinement window), then use this window as the
// confinement window.
//
// Finding absolute extrema is a matter of successively
// searching for extrema in different parts of the unit
// circle. For example, when we search for an absolute
// maximum of longitude, we first search in the second
// quadrant, then if we find nothing, the right half circle,
// then if we find nothing, the fourth quadrant.
//
// We always use longitude as a proxy function on the right
// half circle and right ascension as a proxy function on
// the left half circle.
//
//
// - Inequality
//
// In general, we use proxy functions and break up the unit
// circle into regions where the proxy functions are single
// valued. The exact solution approach depends on where the
// reference value is. For example, to find the window on
// which longitude is less than 3*pi/4, we first search
// for the solution in the second quadrant. We then
// combine this result window with the window of times
// when longitude is in the right half circle, and with
// the window of times when longitude is in the third
// quadrant.
//
//
// Code layout
// -----------
//
// We've tried to arrange the code to minimize calls to
// ZZGFREL, primarily because these expensive in terms of
// run time. They also take up a lot of space.
//
// The code starts out by re-formulating the constraint,
// if necessary, as one applying to planetocentric longitude
// or right ascension. This simplifies the subsequent logic.
//
// Equality searches are handled before the rest. The routine
// exits after processing a search having an equality constraint.
//
// Searches for local extrema are handled next. Again, the
// routine exits after processing these types of searches.
//
// The next portion of the code is devoted to dealing with
// absolute extrema. If the search is for absolute extrema and
// AJDUST is non-zero, we use the results from this portion of
// the code to set up an inequality search, which is done below.
//
// After the portion of the code dealing with absolute extrema
// with ADJUST equal to zero, we perform setup functions to
// prepare to call ZZGFREL. In general, what's happening here is
// that we're deciding what regions of the unit circle we're
// going to use in our solution, and we prepare to find windows
// when the coordinate is in the various regions of interest.
// This setup code includes assignment of window aliases,
// selection of proxy functions, and setting flags indicating
// which windows corresponding to search regions must be
// computed.
//
// Next, the windows corresponding to times when the coordinate
// is in the selected regions are found using ZZGFREL.
//
//
// Check the workspace window count.
//
if (NW < NWMAX) {
SETMSG(b"Workspace window count was # but must be at least #.", ctx);
ERRINT(b"#", NW, ctx);
ERRINT(b"#", NWMAX, ctx);
SIGERR(b"SPICE(TOOFEWWINDOWS)", ctx)?;
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
//
// We can't initialize the whole workspace, but we can initialize
// the windows we actually own. Do so.
//
{
let m1__: i32 = 1;
let m2__: i32 = NWLONG;
let m3__: i32 = 1;
I = m1__;
for _ in 0..((m2__ - m1__ + m3__) / m3__) as i32 {
SSIZED(MW, WORK.subarray_mut([LB, (NWREL + I)]), ctx)?;
I += m3__;
}
}
//
// Initialize the workspace window pool. Set up the parallel
// array of window indices.
//
LNKINI(NWLONG, WWPOOL.as_slice_mut(), ctx)?;
{
let m1__: i32 = 1;
let m2__: i32 = NWLONG;
let m3__: i32 = 1;
I = m1__;
for _ in 0..((m2__ - m1__ + m3__) / m3__) as i32 {
WIX[I] = (NWREL + I);
I += m3__;
}
}
//
// Get an upper case, left-justified version of the
// requested comparison operation.
//
LJUST(RELATE, &mut UOP);
UCASE(&UOP.clone(), &mut UOP, ctx);
//
// Reject bad operators.
//
// Use the original operator string in the error message.
//
I = ISRCHC(&UOP, NC, save.OPS.as_arg());
if (I == 0) {
SETMSG(b"The comparison operator, # is not recognized. Supported quantities are: <, =, >, LOCMIN, ABSMIN, LOCMAX, ABSMAX.", ctx);
ERRCH(b"#", RELATE, ctx);
SIGERR(b"SPICE(NOTRECOGNIZED)", ctx)?;
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
//
// Make sure TOL is positive.
//
if (TOL <= 0.0) {
SETMSG(b"TOL was #; must be positive.", ctx);
ERRDP(b"#", TOL, ctx);
SIGERR(b"SPICE(VALUEOUTOFRANGE)", ctx)?;
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
//
// We'll use a local tolerance equal to 1/5 of the input value.
// This will allow us to keep the total round-off error within
// the desired tolerance.
//
LOCTOL = intrinsics::DMAX1(&[0.0000001, (TOL / 10.0)]);
//
// Make sure ADJUST is non-negative.
//
if (ADJUST < 0.0) {
SETMSG(b"ADJUST was #; must be non-negative.", ctx);
ERRDP(b"#", ADJUST, ctx);
SIGERR(b"SPICE(VALUEOUTOFRANGE)", ctx)?;
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
//
// Confirm ADJUST equals zero unless UOP (RELATE) has value
// "ABSMAX" or "ABSMIN."
//
if (fstr::ne(&UOP, b"ABSMIN") && fstr::ne(&UOP, b"ABSMAX")) {
if (ADJUST != 0.0) {
SETMSG(b"ADJUST should have value zero for all comparison operators except ABSMAX and ABSMIN", ctx);
SIGERR(b"SPICE(INVALIDVALUE)", ctx)?;
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
}
//
// Get an upper case, left-justified, compressed versions of the
// coordinate system and coordinate names.
//
LJUST(CRDSYS, &mut NRMSYS);
CMPRSS(b" ", 0, &NRMSYS.clone(), &mut NRMSYS);
UCASE(&NRMSYS.clone(), &mut NRMSYS, ctx);
LJUST(CRDNAM, &mut NRMCRD);
CMPRSS(b" ", 1, &NRMCRD.clone(), &mut NRMCRD);
UCASE(&NRMCRD.clone(), &mut NRMCRD, ctx);
//
// Make an initial call to the coordinate utility initialization
// routine to invoke error checking. We don't want to have
// to duplicate the checking here. Later, when necessary, we'll
// re-initialize the utilities.
//
ZZGFCOIN(
VECDEF,
METHOD,
TARGET,
REF,
ABCORR,
OBSRVR,
DREF,
DVEC.as_slice(),
&NRMSYS,
&NRMCRD,
ctx,
)?;
if FAILED(ctx) {
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
//
// We've done the basic error checking. Empty the result window and
// return now if the confinement window is empty.
//
if (WNCARD(CNFINE.as_slice(), ctx)? == 0) {
SCARDD(0, RESULT.as_slice_mut(), ctx)?;
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
//
// Initialize the total number of search passes performed.
//
TOTAL = 0;
//
// To eliminate special cases, we'll check for inequality
// constraints that are always met or can't be met.
//
if ((fstr::eq(&NRMSYS, CYLSYS) || fstr::eq(&NRMSYS, PGRSYS)) || fstr::eq(&NRMSYS, RADSYS)) {
if (f64::cos(REFVAL) == 1.0) {
//
// The reference value lies on the branch cut at 0.
//
if fstr::eq(&UOP, b"<") {
//
// These coordinates can never be less than zero.
//
SCARDD(0, RESULT.as_slice_mut(), ctx)?;
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
} else if fstr::eq(&UOP, b">") {
//
// The solution is the whole confinement window. This
// is because the inequality operators really act like
// '>=' and '<=' operators, and because we assume the
// quantity is increasing or decreasing except on a
// set of measure zero.
//
COPYD(CNFINE.as_slice(), RESULT.as_slice_mut(), ctx)?;
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
}
} else if ((fstr::eq(&NRMSYS, GEOSYS) || fstr::eq(&NRMSYS, LATSYS))
|| fstr::eq(&NRMSYS, SPHSYS))
{
if (f64::cos(REFVAL) == -1.0) {
//
// The reference value lies on the branch cut at pi.
//
if fstr::eq(&UOP, b"<") {
//
// The solution is the whole confinement window.
//
COPYD(CNFINE.as_slice(), RESULT.as_slice_mut(), ctx)?;
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
} else if fstr::eq(&UOP, b">") {
//
// These coordinates can never be greater
// than pi.
//
SCARDD(0, RESULT.as_slice_mut(), ctx)?;
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
}
}
//
// At this point, we make some adjustments to simplify the
// remaining code. We map the input coordinate system to
// either "latitudinal" or "RA/DEC" and modify the
// constraint if the original system is "planetographic."
// The longitude coordinate is renamed accordingly, if necessary.
// The mapping is as follows:
//
// Spherical ( longitude range is (-pi, pi] ) -> Latitudinal
//
// Cylindrical ( longitude range is [0, 2*pi] ) -> RA/Dec
// Longitude -> RA
//
// Planetographic ( longitude range is [0, 2*pi] ) -> RA/Dec
// Longitude -> RA
//
//
// For planetographic coordinates, if the longitude is positive
// west, and since REFVAL does not lie on the branch cut, we can
// make the following additional adjustments:
//
// Input relational operator Transformed operator
// ------------------------- --------------------
// ABSMAX ABSMIN
// ABSMAX - ADJUST ABSMIN + ADJUST
// ABSMIN ABSMAX
// ABSMIN + AJDUST ABSMAX - ADJUST
// LOCMAX LOCMIN
// LOCMIN LOCMAX
// < REFVAL > 2*pi - REFVAL
// > REFVAL < 2*pi - REFVAL
// = REFVAL = 2*pi - REFVAL
//
//
XRFVAL = REFVAL;
if fstr::eq(&NRMSYS, SPHSYS) {
fstr::assign(&mut NRMSYS, LATSYS);
XRFVAL = REFVAL;
} else if fstr::eq(&NRMSYS, CYLSYS) {
fstr::assign(&mut NRMSYS, RADSYS);
fstr::assign(&mut NRMCRD, RACRD);
XRFVAL = REFVAL;
} else if fstr::eq(&NRMSYS, PGRSYS) {
fstr::assign(&mut NRMSYS, RADSYS);
fstr::assign(&mut NRMCRD, RACRD);
//
// If the planetographic coordinates are positive West, we'll
// need to transform the constraint and reference value.
//
// Get the name of the central body of frame REF.
//
// NOTE: We omit error checking here because ZZGFCOIN has done
// it already.
//
NAMFRM(REF, &mut FRCODE, ctx)?;
FRINFO(
FRCODE,
&mut REFCTR,
&mut CLASS,
&mut CLSSID,
&mut FOUND,
ctx,
)?;
if FAILED(ctx) {
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
if !FOUND {
SETMSG(b"FRINFO didn\'t find data for frame # which has frame ID code #. This frame should have been validated by ZZGFCOIN.", ctx);
ERRCH(b"#", REF, ctx);
ERRINT(b"#", FRCODE, ctx);
SIGERR(b"SPICE(BUG)", ctx)?;
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
BODC2S(REFCTR, &mut RCTRNM, ctx)?;
//
// Find the longitude of the +Y axis. If this longitude
// is greater than pi, the sense is positive West. Note
// that we don't need to use realistic values of the
// equatorial radius and flattening factor: 1 and 0,
// respectively, are just fine.
//
RECPGR(
&RCTRNM,
save.Y.as_slice(),
1.0,
0.0,
&mut LON,
&mut LAT,
&mut ALT,
ctx,
)?;
//
// Planetographic longitude ranges from 0 to 2*pi, so
// longitudes corresponding to positive Y values are
// in the range pi to 2*pi.
//
if (LON > PI(ctx)) {
//
// Planetographic longitude for the frame center is positive
// West.
//
// Note that no action is required to modify non-zero
// extremum adjustment values.
//
if fstr::eq(&UOP, b"ABSMAX") {
fstr::assign(&mut UOP, b"ABSMIN");
} else if fstr::eq(&UOP, b"ABSMIN") {
fstr::assign(&mut UOP, b"ABSMAX");
} else if fstr::eq(&UOP, b"LOCMAX") {
fstr::assign(&mut UOP, b"LOCMIN");
} else if fstr::eq(&UOP, b"LOCMIN") {
fstr::assign(&mut UOP, b"LOCMAX");
} else if fstr::eq(&UOP, b"=") {
XRFVAL = (TWOPI(ctx) - REFVAL);
} else if fstr::eq(&UOP, b"<") {
fstr::assign(&mut UOP, b">");
XRFVAL = (TWOPI(ctx) - REFVAL);
} else if fstr::eq(&UOP, b">") {
fstr::assign(&mut UOP, b"<");
XRFVAL = (TWOPI(ctx) - REFVAL);
} else {
//
// We shouldn't get here.
//
SETMSG(b"Unexpected UOP value: #", ctx);
ERRCH(b"#", &UOP, ctx);
SIGERR(b"SPICE(BUG)", ctx)?;
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
} else {
//
// Longitude is positive East, so we treat
// the constraint as though the coordinate were RA.
//
XRFVAL = REFVAL;
}
}
//
// From this point on, we use:
//
// Coordinate system: NRMSYS
// Coordinate: NRMCRD
// Operator: UOP
// Reference value: XRFVAL
//
//
// The result window must be initialized by the caller of the GF
// system (usually a user application). We simply empty the result
// window here.
//
SCARDD(0, RESULT.as_slice_mut(), ctx)?;
//
// We use the constant 0.5 * 2**0.5 quite a bit. Create a
// "macro" variable for it.
//
R2OVR2 = (f64::sqrt(2.0) / 2.0);
//
// Set the progress report suffix strings.
//
fstr::assign(RPTSUF.get_mut(1), b"done.");
fstr::assign(RPTSUF.get_mut(2), b"done.");
//
// Case: '='
//
if fstr::eq(&UOP, b"=") {
//
// Equality constraints are the simplest to handle, so we'll get
// them out of the way now. Our approach is to use sine or cosine
// as proxy functions; we'll select the proxy function with the
// highest resolution at the reference value. For the proxy
// function f, our proxy constraint is
//
// f(x) = f(XRFVAL)
//
// This may yield spurious roots; we'll delete these after we've
// done our search.
//
// Find the sine and cosine of the reference value. We'll use
// these both to locate the quadrant of the reference value and
// to have continuously differentiable functions to work with.
// Note that if the original reference value is not in the
// standard range, this presents no problem.
//
CV = f64::cos(XRFVAL);
SV = f64::sin(XRFVAL);
//
// Decide which proxy function to use.
//
if (f64::abs(SV) >= R2OVR2) {
//
// The reference value lies in the top or bottom quarter of
// the unit circle. The "comparison value" CMPVAL will be
// used later to delete solutions with matching sines but
// non-matching cosines.
//
fstr::assign(&mut PRXFUN, b"COS");
PRXVAL = CV;
CMPVAL = SV;
} else {
fstr::assign(&mut PRXFUN, b"SIN");
PRXVAL = SV;
CMPVAL = CV;
}
//
// Set up the progress reporting prefix strings. We have one
// ZZGFREL call which performs two passes.
//
fstr::assign(RPTPRE.get_mut(1), b"Coordinate pass 1 of 2");
fstr::assign(RPTPRE.get_mut(2), b"Coordinate pass 2 of 2");
//
// Allocate a workspace window.
//
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
F1 = WIX[NODE];
//
// Make sure the coordinate utilities have been initialized
// with the actual values we'll use for our search.
//
ZZGFCOIN(
VECDEF,
METHOD,
TARGET,
REF,
ABCORR,
OBSRVR,
DREF,
DVEC.as_slice(),
&NRMSYS,
&NRMCRD,
ctx,
)?;
//
// Now we're ready to compute the window in which our proxy
// function satisfies the proxy constraint.
//
if fstr::eq(&PRXFUN, b"SIN") {
//
// Find the window where the sine of the coordinate satisfies
// the proxy constraint.
//
ZZGFRELX(
UDSTEP,
UDREFN,
ZZGFCOSD,
ZZGFUDLT,
ZZGFCOSG,
b"=",
PRXVAL,
LOCTOL,
0.0,
CNFINE.as_slice(),
MW,
NW,
&mut WORK.data().to_vec(),
RPT,
UDREPI,
UDREPU,
UDREPF,
RPTPRE.as_arg(),
RPTSUF.as_arg(),
BAIL,
UDBAIL,
WORK.subarray_mut([LB, F1]),
ctx,
)?;
} else {
//
// Find the window where the cosine of the coordinate
// satisfies the proxy constraint.
//
ZZGFRELX(
UDSTEP,
UDREFN,
ZZGFCOCD,
ZZGFUDLT,
ZZGFCOCG,
b"=",
PRXVAL,
LOCTOL,
0.0,
CNFINE.as_slice(),
MW,
NW,
&mut WORK.data().to_vec(),
RPT,
UDREPI,
UDREPU,
UDREPF,
RPTPRE.as_arg(),
RPTSUF.as_arg(),
BAIL,
UDBAIL,
WORK.subarray_mut([LB, F1]),
ctx,
)?;
}
if FAILED(ctx) {
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
//
// Handle interrupts if necessary.
//
if BAIL {
if UDBAIL() {
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
}
//
// Remove any spurious results.
//
N = CARDD(WORK.subarray([LB, F1]), ctx)?;
{
let m1__: i32 = 1;
let m2__: i32 = N;
let m3__: i32 = 2;
I = m1__;
for _ in 0..((m2__ - m1__ + m3__) / m3__) as i32 {
START = WORK[[I, F1]];
if fstr::eq(&PRXFUN, b"SIN") {
//
// Get the cosine of the coordinate at the interval start
// time. If this cosine has the same sign as the cosine of
// the reference value, we have a winner. Note that the
// cosines of spurious values won't ever be close to the
// correct values, so round-off isn't an issue.
//
ZZGFCOCG(&mut START, &mut VALUE, ctx)?;
} else {
//
// Same deal, but here we're using sines.
//
ZZGFCOSG(&mut START, &mut VALUE, ctx)?;
}
if SMSGND(CMPVAL, VALUE) {
//
// This is a winner.
//
WNINSD(START, START, RESULT.as_slice_mut(), ctx)?;
}
I += m3__;
}
}
//
// All done.
//
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
//
// Case: local minimum or local maximum
//
if (fstr::eq(&UOP, b"LOCMAX") || fstr::eq(&UOP, b"LOCMIN")) {
//
// This algorithm uses 4 ZZGFREL calls, 2 of which perform
// 2 passes and 2 of which perform 1 pass.
//
fstr::assign(RPTSUF.get_mut(1), b"done.");
fstr::assign(RPTSUF.get_mut(2), b"done.");
//
// Empty the result window.
//
SCARDD(0, RESULT.as_slice_mut(), ctx)?;
//
// We'll first find two windows covering the left and right
// halves of the unit circle, with both halves extended
// slightly to ensure no roots are missed. We start by
// finding the window on which the cosine of the coordinate
// is less than cos(LCXMRG) (which is a small, positive number).
//
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
LEFT = WIX[NODE];
fstr::assign(RPTPRE.get_mut(1), b"Coordinate pass 1 of 6");
fstr::assign(RPTPRE.get_mut(2), b"Coordinate pass 2 of 6");
fstr::assign(&mut PRXREL, b"<");
PRXVAL = f64::cos(LCXMRG);
ZZGFCOIN(
VECDEF,
METHOD,
TARGET,
REF,
ABCORR,
OBSRVR,
DREF,
DVEC.as_slice(),
&NRMSYS,
&NRMCRD,
ctx,
)?;
ZZGFRELX(
UDSTEP,
UDREFN,
ZZGFCOCD,
ZZGFUDLT,
ZZGFCOCG,
&PRXREL,
PRXVAL,
LOCTOL,
0.0,
CNFINE.as_slice(),
MW,
NW,
&mut WORK.data().to_vec(),
RPT,
UDREPI,
UDREPU,
UDREPF,
RPTPRE.as_arg(),
RPTSUF.as_arg(),
BAIL,
UDBAIL,
WORK.subarray_mut([LB, LEFT]),
ctx,
)?;
//
// Handle interrupts if necessary.
//
if BAIL {
if UDBAIL() {
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
}
//
// Now search for the time period when the cosine of the
// coordinate is greater than -cos(LCXMRG). We can save some time
// by searching within the window designated by LEFT for the
// complement of this window and then complementing the result of
// that search.
//
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
COMPL = WIX[NODE];
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
RIGHT = WIX[NODE];
fstr::assign(RPTPRE.get_mut(1), b"Coordinate pass 3 of 6");
fstr::assign(RPTPRE.get_mut(2), b"Coordinate pass 4 of 6");
fstr::assign(&mut PRXREL, b"<");
PRXVAL = -f64::cos(LCXMRG);
ZZGFCOIN(
VECDEF,
METHOD,
TARGET,
REF,
ABCORR,
OBSRVR,
DREF,
DVEC.as_slice(),
&NRMSYS,
&NRMCRD,
ctx,
)?;
ZZGFRELX(
UDSTEP,
UDREFN,
ZZGFCOCD,
ZZGFUDLT,
ZZGFCOCG,
&PRXREL,
PRXVAL,
LOCTOL,
0.0,
&WORK.subarray([LB, LEFT]).to_vec(),
MW,
NW,
&mut WORK.data().to_vec(),
RPT,
UDREPI,
UDREPU,
UDREPF,
RPTPRE.as_arg(),
RPTSUF.as_arg(),
BAIL,
UDBAIL,
WORK.subarray_mut([LB, COMPL]),
ctx,
)?;
//
// Handle interrupts if necessary.
//
if BAIL {
if UDBAIL() {
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
}
//
// WORK(LB,COMPL) contains the complement of the window
// we want.
//
WNDIFD(
CNFINE.as_slice(),
&WORK.subarray([LB, COMPL]).to_vec(),
WORK.subarray_mut([LB, RIGHT]),
ctx,
)?;
//
// We're now going to find local extrema of the coordinate in the
// windows indexed by LEFT and RIGHT.
//
{
let m1__: i32 = 1;
let m2__: i32 = 2;
let m3__: i32 = 1;
I = m1__;
for _ in 0..((m2__ - m1__ + m3__) / m3__) as i32 {
if (I == 1) {
//
// The sector we're searching is indexed by LEFT.
// We'll use RA as a proxy function, since RA has no
// singularity on the left half circle.
//
S = LEFT;
fstr::assign(&mut PRXSYS, RADSYS);
fstr::assign(&mut PRXCRD, RACRD);
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
RES1 = WIX[NODE];
RES = RES1;
fstr::assign(RPTPRE.get_mut(1), b"Coordinate pass 5 of 6");
fstr::assign(RPTPRE.get_mut(2), b" ");
} else {
S = RIGHT;
fstr::assign(&mut PRXSYS, LATSYS);
fstr::assign(&mut PRXCRD, LONCRD);
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
RES2 = WIX[NODE];
RES = RES2;
fstr::assign(RPTPRE.get_mut(1), b"Coordinate pass 6 of 6");
fstr::assign(RPTPRE.get_mut(2), b" ");
}
ZZGFCOIN(
VECDEF,
METHOD,
TARGET,
REF,
ABCORR,
OBSRVR,
DREF,
DVEC.as_slice(),
&PRXSYS,
&PRXCRD,
ctx,
)?;
ZZGFRELX(
UDSTEP,
UDREFN,
ZZGFCODC,
ZZGFUDLT,
ZZGFCOG,
&UOP,
0.0,
LOCTOL,
0.0,
&WORK.subarray([LB, S]).to_vec(),
MW,
NW,
&mut WORK.data().to_vec(),
RPT,
UDREPI,
UDREPU,
UDREPF,
RPTPRE.as_arg(),
RPTSUF.as_arg(),
BAIL,
UDBAIL,
WORK.subarray_mut([LB, RES]),
ctx,
)?;
//
// Handle interrupts if necessary.
//
if BAIL {
if UDBAIL() {
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
}
I += m3__;
}
}
//
// Combine the contributions of both searches in RESULT.
//
WNUNID(
WORK.subarray([LB, RES1]),
WORK.subarray([LB, RES2]),
RESULT.as_slice_mut(),
ctx,
)?;
//
// End of the LOCMIN and LOCMAX cases. RESULT is set.
//
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
//
// The remaining operators are: ABSMAX, ABSMIN, '<', '>'.
//
// Initialize the window aliases. A value of zero indicates the
// corresponding region hasn't been computed.
//
TOP = 0;
BOT = 0;
RIGHT = 0;
LEFT = 0;
Q1 = 0;
Q2 = 0;
Q3 = 0;
Q4 = 0;
S = 0;
WH = 0;
F1 = 0;
F2 = 0;
//
// If we have an absolute extremum or inequality relation,
// we'll need to find times when the coordinate is in the
// various quadrants. We'll start out by setting up windows
// for the times when the coordinate is in the top and right
// halves of the unit circle.
//
// The ZZGFREL call below involves two passes.
//
if (fstr::eq(&UOP, b"ABSMAX") || fstr::eq(&UOP, b"ABSMIN")) {
if (ADJUST == 0 as f64) {
fstr::assign(&mut TMPLAT, b"Coordinate pass # of 7");
} else {
fstr::assign(&mut TMPLAT, b"Coordinate pass # of 7-9");
}
} else {
//
// Ordinary inequality searches use 8 passes.
//
fstr::assign(&mut TMPLAT, b"Coordinate pass # of 8");
}
{
let m1__: i32 = 1;
let m2__: i32 = 2;
let m3__: i32 = 1;
I = m1__;
for _ in 0..((m2__ - m1__ + m3__) / m3__) as i32 {
REPMI(&TMPLAT, b"#", I, &mut RPTPRE[I], ctx);
I += m3__;
}
}
//
// Find the window where the sine of the coordinate is greater than
// the sine of the branch cut avoidance tolerance.
//
// Make sure the coordinate utilities have been initialized
// with the actual values we'll use for our search.
//
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
HEAD = NODE;
TOP = WIX[NODE];
PRXVAL = f64::sin(BCAMRG);
ZZGFCOIN(
VECDEF,
METHOD,
TARGET,
REF,
ABCORR,
OBSRVR,
DREF,
DVEC.as_slice(),
&NRMSYS,
&NRMCRD,
ctx,
)?;
ZZGFRELX(
UDSTEP,
UDREFN,
ZZGFCOSD,
ZZGFUDLT,
ZZGFCOSG,
b">",
PRXVAL,
LOCTOL,
0.0,
CNFINE.as_slice(),
MW,
NW,
&mut WORK.data().to_vec(),
RPT,
UDREPI,
UDREPU,
UDREPF,
RPTPRE.as_arg(),
RPTSUF.as_arg(),
BAIL,
UDBAIL,
WORK.subarray_mut([LB, TOP]),
ctx,
)?;
//
// 2 passes done.
//
TOTAL = 2;
if BAIL {
if UDBAIL() {
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
}
//
// Find the window where the sine of the coordinate is less than
// the negative of the sine of the branch cut avoidance tolerance.
//
// Make sure the coordinate utilities have been initialized
// with the actual values we'll use for our search.
//
// The ZZGFREL call below involves two passes.
//
{
let m1__: i32 = 1;
let m2__: i32 = 2;
let m3__: i32 = 1;
I = m1__;
for _ in 0..((m2__ - m1__ + m3__) / m3__) as i32 {
REPMI(&TMPLAT, b"#", (TOTAL + I), &mut RPTPRE[I], ctx);
I += m3__;
}
}
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
LNKILA(HEAD, NODE, WWPOOL.as_slice_mut(), ctx)?;
BOT = WIX[NODE];
PRXVAL = -f64::sin(BCAMRG);
ZZGFCOIN(
VECDEF,
METHOD,
TARGET,
REF,
ABCORR,
OBSRVR,
DREF,
DVEC.as_slice(),
&NRMSYS,
&NRMCRD,
ctx,
)?;
ZZGFRELX(
UDSTEP,
UDREFN,
ZZGFCOSD,
ZZGFUDLT,
ZZGFCOSG,
b"<",
PRXVAL,
LOCTOL,
0.0,
CNFINE.as_slice(),
MW,
NW,
&mut WORK.data().to_vec(),
RPT,
UDREPI,
UDREPU,
UDREPF,
RPTPRE.as_arg(),
RPTSUF.as_arg(),
BAIL,
UDBAIL,
WORK.subarray_mut([LB, BOT]),
ctx,
)?;
//
// 4 passes done.
//
TOTAL = (TOTAL + 2);
if BAIL {
if UDBAIL() {
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
}
//
// Find the window where the cosine of the coordinate is
// greater than zero.
//
//
// The ZZGFREL call below involves two passes.
//
{
let m1__: i32 = 1;
let m2__: i32 = 2;
let m3__: i32 = 1;
I = m1__;
for _ in 0..((m2__ - m1__ + m3__) / m3__) as i32 {
REPMI(&TMPLAT, b"#", (TOTAL + I), &mut RPTPRE[I], ctx);
I += m3__;
}
}
//
// We'll keep all of the allocated nodes linked together.
// Since the order of the nodes is unimportant, we insert
// each new node following the head node; this is non-standard
// but ensures the list head doesn't change until we delete
// nodes from the list.
//
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
LNKILA(HEAD, NODE, WWPOOL.as_slice_mut(), ctx)?;
RIGHT = WIX[NODE];
ZZGFCOIN(
VECDEF,
METHOD,
TARGET,
REF,
ABCORR,
OBSRVR,
DREF,
DVEC.as_slice(),
&NRMSYS,
&NRMCRD,
ctx,
)?;
ZZGFRELX(
UDSTEP,
UDREFN,
ZZGFCOCD,
ZZGFUDLT,
ZZGFCOCG,
b">",
0.0,
LOCTOL,
0.0,
CNFINE.as_slice(),
MW,
NW,
&mut WORK.data().to_vec(),
RPT,
UDREPI,
UDREPU,
UDREPF,
RPTPRE.as_arg(),
RPTSUF.as_arg(),
BAIL,
UDBAIL,
WORK.subarray_mut([LB, RIGHT]),
ctx,
)?;
//
// 6 passes done.
//
TOTAL = (TOTAL + 2);
if BAIL {
if UDBAIL() {
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
}
if FAILED(ctx) {
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
//
// Now find the absolute extremum, if this was requested.
//
if (fstr::eq(&UOP, b"ABSMAX") || fstr::eq(&UOP, b"ABSMIN")) {
//
// If we're looking for an absolute extremum and the
// adjustment value is 0, each ZZGFREL call executes
// on search pass; otherwise these calls execute two
// search passes.
//
if fstr::eq(&NRMCRD, LONCRD) {
//
// We need windows when the coordinate is in quadrants 2 and
// 3. We can derive these from the windows TOP and RIGHT
// without additional searches.
//
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
LNKILA(HEAD, NODE, WWPOOL.as_slice_mut(), ctx)?;
Q2 = WIX[NODE];
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
LNKILA(HEAD, NODE, WWPOOL.as_slice_mut(), ctx)?;
Q3 = WIX[NODE];
//
// Compute windows for the second and third quadrants. Note
// that these windows are bounded away from the branch cut
// at pi radians, since windows TOP and BOT have been
// trimmed.
//
WNDIFD(
&WORK.subarray([LB, TOP]).to_vec(),
&WORK.subarray([LB, RIGHT]).to_vec(),
WORK.subarray_mut([LB, Q2]),
ctx,
)?;
WNDIFD(
&WORK.subarray([LB, BOT]).to_vec(),
&WORK.subarray([LB, RIGHT]).to_vec(),
WORK.subarray_mut([LB, Q3]),
ctx,
)?;
if fstr::eq(&UOP, b"ABSMAX") {
REGION[1] = Q2;
REGION[2] = RIGHT;
REGION[3] = Q3;
} else {
REGION[1] = Q3;
REGION[2] = RIGHT;
REGION[3] = Q2;
}
} else if fstr::eq(&NRMCRD, RACRD) {
//
// We need windows when the coordinate is in quadrants 1 and
// 4, and the window when the coordinate is in the left half
// of the unit circle. We can derive these from the windows
// TOP and RIGHT without additional searches.
//
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
LNKILA(HEAD, NODE, WWPOOL.as_slice_mut(), ctx)?;
Q1 = WIX[NODE];
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
LNKILA(HEAD, NODE, WWPOOL.as_slice_mut(), ctx)?;
LEFT = WIX[NODE];
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
LNKILA(HEAD, NODE, WWPOOL.as_slice_mut(), ctx)?;
Q4 = WIX[NODE];
//
// Compute windows for the first and fourth quadrants. Note
// that these windows are bounded away from the branch cut
// at pi radians, since windows TOP and BOT have been
// trimmed. Also compute the window LEFT, which is the
// complement of window RIGHT.
//
WNINTD(
&WORK.subarray([LB, RIGHT]).to_vec(),
&WORK.subarray([LB, TOP]).to_vec(),
WORK.subarray_mut([LB, Q1]),
ctx,
)?;
WNINTD(
&WORK.subarray([LB, RIGHT]).to_vec(),
&WORK.subarray([LB, BOT]).to_vec(),
WORK.subarray_mut([LB, Q4]),
ctx,
)?;
WNDIFD(
CNFINE.as_slice(),
&WORK.subarray([LB, RIGHT]).to_vec(),
WORK.subarray_mut([LB, LEFT]),
ctx,
)?;
if fstr::eq(&UOP, b"ABSMAX") {
REGION[1] = Q4;
REGION[2] = LEFT;
REGION[3] = Q1;
} else {
REGION[1] = Q1;
REGION[2] = LEFT;
REGION[3] = Q4;
}
} else {
//
// We're not expecting to see a coordinate other than
// longitude or RA here.
//
SETMSG(b"Unexpected coordinate # (0)", ctx);
ERRCH(b"#", &NRMCRD, ctx);
SIGERR(b"SPICE(BUG)", ctx)?;
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
//
// Now search the list of regions for the specified
// extremum.
//
FOUND = false;
I = 1;
while ((I <= 3) && !FOUND) {
//
// Search region I. Set the reference and adjustment
// values to 0 for this search.
//
// The ZZGFREL call below executes 1 pass, since it's
// doing an absolute extremum search with 0 adjustment
// value (even if ADJUST is non-zero).
//
REPMI(&TMPLAT, b"#", (TOTAL + 1), &mut RPTPRE[1], ctx);
fstr::assign(RPTPRE.get_mut(2), b" ");
SCARDD(0, RESULT.as_slice_mut(), ctx)?;
//
// Perform our searches with functions that have no branch
// cuts near the region boundaries.
//
if (((REGION[I] == Q1) || (REGION[I] == Q4)) || (REGION[I] == RIGHT)) {
fstr::assign(&mut PRXSYS, LATSYS);
fstr::assign(&mut PRXCRD, LONCRD);
} else {
fstr::assign(&mut PRXSYS, RADSYS);
fstr::assign(&mut PRXCRD, RACRD);
}
ZZGFCOIN(
VECDEF,
METHOD,
TARGET,
REF,
ABCORR,
OBSRVR,
DREF,
DVEC.as_slice(),
&PRXSYS,
&PRXCRD,
ctx,
)?;
ZZGFRELX(
UDSTEP,
UDREFN,
ZZGFCODC,
ZZGFUDLT,
ZZGFCOCG,
&UOP,
0.0,
LOCTOL,
0.0,
WORK.subarray([LB, REGION[I]]),
MW,
NW,
&mut WORK.data().to_vec(),
RPT,
UDREPI,
UDREPU,
UDREPF,
RPTPRE.as_arg(),
RPTSUF.as_arg(),
BAIL,
UDBAIL,
RESULT.as_slice_mut(),
ctx,
)?;
//
// ZZGFREL will have performed a pass only if the confinement
// window was non-empty.
//
if (CARDD(WORK.subarray([LB, REGION[I]]), ctx)? > 0) {
//
// Another pass has been completed.
//
TOTAL = (TOTAL + 1);
}
if BAIL {
if UDBAIL() {
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
}
if (WNCARD(RESULT.as_slice(), ctx)? > 0) {
//
// We found an extremum. We don't have to search further.
//
FOUND = true;
} else {
I = (I + 1);
}
}
if (ADJUST == 0.0) {
//
// The result we have is the final result.
//
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
//
// This is the case of an absolute extremum search with
// non-zero adjustment value.
//
// We'll need to obtain the extreme value.
//
ET = RESULT[1];
ZZGFCOIN(
VECDEF,
METHOD,
TARGET,
REF,
ABCORR,
OBSRVR,
DREF,
DVEC.as_slice(),
&NRMSYS,
&NRMCRD,
ctx,
)?;
ZZGFCOG(&mut ET, &mut EXTVAL, ctx)?;
//
// Re-set the operator and reference value to enable
// us to conduct an inequality search.
//
if fstr::eq(&UOP, b"ABSMAX") {
if fstr::eq(&NRMCRD, LONCRD) {
XRFVAL = intrinsics::DMAX1(&[(EXTVAL - ADJUST), -PI(ctx)]);
} else {
XRFVAL = intrinsics::DMAX1(&[(EXTVAL - ADJUST), 0.0]);
}
fstr::assign(&mut UOP, b">");
} else {
if fstr::eq(&NRMCRD, LONCRD) {
XRFVAL = intrinsics::DMIN1(&[(EXTVAL + ADJUST), PI(ctx)]);
} else {
XRFVAL = intrinsics::DMIN1(&[(EXTVAL + ADJUST), TWOPI(ctx)]);
}
fstr::assign(&mut UOP, b"<");
}
}
//
// Case: inequality
//
// Searches for absolute extrema with non-zero adjustment values
// also use this code block.
//
if (fstr::eq(&UOP, b"<") || fstr::eq(&UOP, b">")) {
//
// We'll find the window when the coordinate is less than
// the reference value. If the relation is '>', we'll
// complement the result. Let FLIP indicate whether
// we need to take the complement of our result at the
// end of the search.
//
if fstr::eq(&UOP, b">") {
fstr::assign(&mut UOP, b"<");
FLIP = true;
} else {
FLIP = false;
}
//
// We'll need the sine and cosine of the reference value.
//
CV = f64::cos(XRFVAL);
SV = f64::sin(XRFVAL);
//
// Determine the quadrant QUAD of the reference value.
//
LOCREF = f64::atan2(SV, CV);
if (LOCREF < -(PI(ctx) / 2 as f64)) {
QUAD = 3;
} else if (LOCREF < 0.0) {
QUAD = 4;
} else if (LOCREF < (PI(ctx) / 2 as f64)) {
QUAD = 1;
} else {
QUAD = 2;
}
//
// Create a list of region windows to compute. The order
// of list items is significant: the regions will
// be computed in the order in which they're listed.
//
if fstr::eq(&NRMCRD, LONCRD) {
NL = 2;
fstr::assign(RLIST.get_mut(1), b"Q2");
fstr::assign(RLIST.get_mut(2), b"Q3");
} else {
NL = 3;
fstr::assign(RLIST.get_mut(1), b"LEFT");
fstr::assign(RLIST.get_mut(2), b"Q1");
fstr::assign(RLIST.get_mut(3), b"Q4");
}
//
// Compute all of the region windows.
//
// We make use of the fact that windows TOP and RIGHT
// have already been computed.
//
{
let m1__: i32 = 1;
let m2__: i32 = NL;
let m3__: i32 = 1;
I = m1__;
for _ in 0..((m2__ - m1__ + m3__) / m3__) as i32 {
if (fstr::eq(RLIST.get(I), b"LEFT") && (LEFT == 0)) {
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
LNKILA(HEAD, NODE, WWPOOL.as_slice_mut(), ctx)?;
LEFT = WIX[NODE];
WNDIFD(
CNFINE.as_slice(),
&WORK.subarray([LB, RIGHT]).to_vec(),
WORK.subarray_mut([LB, LEFT]),
ctx,
)?;
} else if (fstr::eq(RLIST.get(I), b"Q1") && (Q1 == 0)) {
if (Q1 == 0) {
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
LNKILA(HEAD, NODE, WWPOOL.as_slice_mut(), ctx)?;
Q1 = WIX[NODE];
}
WNINTD(
&WORK.subarray([LB, RIGHT]).to_vec(),
&WORK.subarray([LB, TOP]).to_vec(),
WORK.subarray_mut([LB, Q1]),
ctx,
)?;
} else if (fstr::eq(RLIST.get(I), b"Q2") && (Q2 == 0)) {
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
LNKILA(HEAD, NODE, WWPOOL.as_slice_mut(), ctx)?;
Q2 = WIX[NODE];
WNDIFD(
&WORK.subarray([LB, TOP]).to_vec(),
&WORK.subarray([LB, RIGHT]).to_vec(),
WORK.subarray_mut([LB, Q2]),
ctx,
)?;
} else if (fstr::eq(RLIST.get(I), b"Q3") && (Q3 == 0)) {
//
// Note: we need the bottom window in order to compute Q3!
//
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
LNKILA(HEAD, NODE, WWPOOL.as_slice_mut(), ctx)?;
Q3 = WIX[NODE];
WNDIFD(
&WORK.subarray([LB, BOT]).to_vec(),
&WORK.subarray([LB, RIGHT]).to_vec(),
WORK.subarray_mut([LB, Q3]),
ctx,
)?;
} else if (fstr::eq(RLIST.get(I), b"Q4") && (Q4 == 0)) {
//
// NOTE: We need the bottom window in order to compute Q4!
//
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
LNKILA(HEAD, NODE, WWPOOL.as_slice_mut(), ctx)?;
Q4 = WIX[NODE];
WNINTD(
&WORK.subarray([LB, RIGHT]).to_vec(),
&WORK.subarray([LB, BOT]).to_vec(),
WORK.subarray_mut([LB, Q4]),
ctx,
)?;
}
I += m3__;
}
}
if FAILED(ctx) {
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
//
// Now decide the sector and proxy function we'll use to
// search for the time when the reference value is hit.
//
if fstr::eq(&NRMCRD, LONCRD) {
if (QUAD == 1) {
S = RIGHT;
fstr::assign(&mut PRXFUN, LONCRD);
} else if (QUAD == 2) {
S = Q2;
fstr::assign(&mut PRXFUN, RACRD);
} else if (QUAD == 3) {
S = Q3;
fstr::assign(&mut PRXFUN, RACRD);
} else {
S = RIGHT;
fstr::assign(&mut PRXFUN, LONCRD);
}
} else {
if (QUAD == 1) {
S = Q1;
fstr::assign(&mut PRXFUN, LONCRD);
} else if (QUAD == 2) {
S = LEFT;
fstr::assign(&mut PRXFUN, RACRD);
} else if (QUAD == 3) {
S = LEFT;
fstr::assign(&mut PRXFUN, RACRD);
} else {
S = Q4;
fstr::assign(&mut PRXFUN, LONCRD);
}
}
//
// Set the proxy reference value based on the input
// reference value and the choice of proxy function.
//
if fstr::eq(&PRXFUN, LONCRD) {
PRXVAL = f64::atan2(SV, CV);
} else {
PRXVAL = f64::atan2(SV, CV);
if (PRXVAL < 0.0) {
PRXVAL = (PRXVAL + TWOPI(ctx));
}
}
//
// We're going to need additional windows in order to search
// quadrant Q. At this point, we're going to de-allocate all
// windows except those needed for the upcoming searches.
//
// Create the set NEEDWN of the windows we need to retain.
//
SSIZEI(NWLONG, NEEDWN.as_slice_mut(), ctx)?;
if fstr::eq(&NRMCRD, LONCRD) {
INSRTI(Q2, NEEDWN.as_slice_mut(), ctx)?;
INSRTI(Q3, NEEDWN.as_slice_mut(), ctx)?;
INSRTI(RIGHT, NEEDWN.as_slice_mut(), ctx)?;
} else {
INSRTI(Q1, NEEDWN.as_slice_mut(), ctx)?;
INSRTI(Q4, NEEDWN.as_slice_mut(), ctx)?;
INSRTI(LEFT, NEEDWN.as_slice_mut(), ctx)?;
}
//
// Now delete all windows not referenced by NEEDWN.
//
NODE = HEAD;
while (NODE > 0) {
//
// Find the next node in the list.
//
NEXT = LNKNXT(NODE, WWPOOL.as_slice(), ctx)?;
if !ELEMI(WIX[NODE], NEEDWN.as_slice(), ctx)? {
//
// Delete NODE; update HEAD if we deleted the head node.
//
LNKFSL(NODE, NODE, WWPOOL.as_slice_mut(), ctx)?;
if (HEAD == NODE) {
HEAD = NEXT;
}
}
//
// Prepare to look at the next node.
//
NODE = NEXT;
}
if fstr::eq(&NRMCRD, LONCRD) {
//
// This is a longitude search.
//
// For each quadrant, identify or compute the window on which
// the constraint is automatically satisfied. Store the result
// in workspace window F1. If this window is empty, set F1 to
// 0.
//
if (QUAD == 1) {
F1 = Q3;
} else if (QUAD == 2) {
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
LNKILA(HEAD, NODE, WWPOOL.as_slice_mut(), ctx)?;
F1 = WIX[NODE];
WNUNID(
&WORK.subarray([LB, Q3]).to_vec(),
&WORK.subarray([LB, RIGHT]).to_vec(),
WORK.subarray_mut([LB, F1]),
ctx,
)?;
} else if (QUAD == 3) {
F1 = 0;
} else {
//
// QUAD is 4.
//
F1 = Q3;
}
} else {
//
// We're working with RA.
//
if (QUAD == 1) {
F1 = 0;
} else if (QUAD == 2) {
F1 = Q1;
} else if (QUAD == 3) {
F1 = Q1;
} else {
//
// QUAD is 4.
//
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
LNKILA(HEAD, NODE, WWPOOL.as_slice_mut(), ctx)?;
F1 = WIX[NODE];
WNUNID(
&WORK.subarray([LB, LEFT]).to_vec(),
&WORK.subarray([LB, Q1]).to_vec(),
WORK.subarray_mut([LB, F1]),
ctx,
)?;
}
}
if FAILED(ctx) {
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
//
// Search sector S to find times when the relation
//
// PRXFUN PRXREL PRXVAL
//
// holds.
//
// Allocate window F2 to hold the result of the search.
//
//
{
let m1__: i32 = 1;
let m2__: i32 = 2;
let m3__: i32 = 1;
I = m1__;
for _ in 0..((m2__ - m1__ + m3__) / m3__) as i32 {
REPMI(&TMPLAT, b"#", (TOTAL + I), &mut RPTPRE[I], ctx);
I += m3__;
}
}
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
LNKILA(HEAD, NODE, WWPOOL.as_slice_mut(), ctx)?;
F2 = WIX[NODE];
SCARDD(0, WORK.subarray_mut([LB, F2]), ctx)?;
if fstr::eq(&PRXFUN, LONCRD) {
//
// Initialize the proxy search in sector S, then perform the
// search.
//
ZZGFCOIN(
VECDEF,
METHOD,
TARGET,
REF,
ABCORR,
OBSRVR,
DREF,
DVEC.as_slice(),
LATSYS,
LONCRD,
ctx,
)?;
ZZGFRELX(
UDSTEP,
UDREFN,
ZZGFCODC,
ZZGFUDLT,
ZZGFCOG,
b"<",
PRXVAL,
LOCTOL,
0.0,
&WORK.subarray([LB, S]).to_vec(),
MW,
NW,
&mut WORK.data().to_vec(),
RPT,
UDREPI,
UDREPU,
UDREPF,
RPTPRE.as_arg(),
RPTSUF.as_arg(),
BAIL,
UDBAIL,
WORK.subarray_mut([LB, F2]),
ctx,
)?;
} else {
//
// Initialize the proxy search in sector S, then perform the
// search.
//
ZZGFCOIN(
VECDEF,
METHOD,
TARGET,
REF,
ABCORR,
OBSRVR,
DREF,
DVEC.as_slice(),
RADSYS,
RACRD,
ctx,
)?;
ZZGFRELX(
UDSTEP,
UDREFN,
ZZGFCODC,
ZZGFUDLT,
ZZGFCOG,
b"<",
PRXVAL,
LOCTOL,
0.0,
&WORK.subarray([LB, S]).to_vec(),
MW,
NW,
&mut WORK.data().to_vec(),
RPT,
UDREPI,
UDREPU,
UDREPF,
RPTPRE.as_arg(),
RPTSUF.as_arg(),
BAIL,
UDBAIL,
WORK.subarray_mut([LB, F2]),
ctx,
)?;
}
//
// 7 + 0:2 passes done for adjusted extrema.
//
if BAIL {
if UDBAIL() {
CHKOUT(b"ZZGFLONG", ctx)?;
return Ok(());
}
}
//
// Combine the contents of windows F1 and F2 to obtain
// the result.
//
if (F1 != 0) {
WNUNID(
WORK.subarray([LB, F1]),
WORK.subarray([LB, F2]),
RESULT.as_slice_mut(),
ctx,
)?;
} else {
COPYD(WORK.subarray([LB, F2]), RESULT.as_slice_mut(), ctx)?;
}
//
// Last step: complement the result if necessary.
//
if FLIP {
//
// Create the window relative to which we'll find
// the complement of RESULT. The window we seek
// is not CNFINE, but rather a union of windows
// that avoids the branch cut.
//
LNKAN(WWPOOL.as_slice_mut(), &mut NODE, ctx)?;
WH = WIX[NODE];
if fstr::eq(&NRMCRD, LONCRD) {
WNUNID(
&WORK.subarray([LB, Q2]).to_vec(),
&WORK.subarray([LB, RIGHT]).to_vec(),
WORK.subarray_mut([LB, F2]),
ctx,
)?;
WNUNID(
&WORK.subarray([LB, Q3]).to_vec(),
&WORK.subarray([LB, F2]).to_vec(),
WORK.subarray_mut([LB, WH]),
ctx,
)?;
} else {
WNUNID(
&WORK.subarray([LB, Q1]).to_vec(),
&WORK.subarray([LB, LEFT]).to_vec(),
WORK.subarray_mut([LB, F2]),
ctx,
)?;
WNUNID(
&WORK.subarray([LB, Q4]).to_vec(),
&WORK.subarray([LB, F2]).to_vec(),
WORK.subarray_mut([LB, WH]),
ctx,
)?;
}
//
// We use F2 as a temporary window index, since F2 is
// guaranteed to exist at this point and is distinct from WH.
//
WNDIFD(
&WORK.subarray([LB, WH]).to_vec(),
RESULT.as_slice(),
WORK.subarray_mut([LB, F2]),
ctx,
)?;
COPYD(WORK.subarray([LB, F2]), RESULT.as_slice_mut(), ctx)?;
}
}
CHKOUT(b"ZZGFLONG", ctx)?;
Ok(())
}