rsspice 0.1.0

Pure Rust port of the SPICE Toolkit for space geometry
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
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
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
//
// GENERATED FILE
//

use super::*;
use crate::SpiceContext;
use f2rust_std::*;

const MAXSRF: i32 = 100;
const INERTL: i32 = 1;
const PCK: i32 = (INERTL + 1);
const CK: i32 = (PCK + 1);
const TK: i32 = (CK + 1);
const DYN: i32 = (TK + 1);
const SWTCH: i32 = (DYN + 1);
const ALL: i32 = -1;
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 CTRSIZ: i32 = 2;
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 RNAME: &[u8] = b"SUBPNT";
const CNVLIM: f64 = 0.00000000000000001;
const MAXITR: i32 = 5;
const MAXL: i32 = 36;
const FRNMLN: i32 = 32;

struct SaveVars {
    PRVCOR: Vec<u8>,
    PRVMTH: Vec<u8>,
    SUBTYP: Vec<u8>,
    NSURF: i32,
    SHAPE: i32,
    SRFLST: StackArray<i32, 100>,
    FIRST: bool,
    NEAR: bool,
    PRI: bool,
    USECN: bool,
    USELT: bool,
    USESTL: bool,
    XMIT: bool,
    SVCTR1: StackArray<i32, 2>,
    SVTARG: Vec<u8>,
    SVTCDE: i32,
    SVFND1: bool,
    SVCTR2: StackArray<i32, 2>,
    SVOBSR: Vec<u8>,
    SVOBSC: i32,
    SVFND2: bool,
    SVCTR3: StackArray<i32, 2>,
    SVFREF: Vec<u8>,
    SVREFC: i32,
    SVCTR4: StackArray<i32, 2>,
}

impl SaveInit for SaveVars {
    fn new() -> Self {
        let mut PRVCOR = vec![b' '; CORLEN as usize];
        let mut PRVMTH = vec![b' '; MTHLEN as usize];
        let mut SUBTYP = vec![b' '; SUBLEN as usize];
        let mut NSURF: i32 = 0;
        let mut SHAPE: i32 = 0;
        let mut SRFLST = StackArray::<i32, 100>::new(1..=MAXSRF);
        let mut FIRST: bool = false;
        let mut NEAR: bool = false;
        let mut PRI: bool = false;
        let mut USECN: bool = false;
        let mut USELT: bool = false;
        let mut USESTL: bool = false;
        let mut XMIT: bool = false;
        let mut SVCTR1 = StackArray::<i32, 2>::new(1..=CTRSIZ);
        let mut SVTARG = vec![b' '; MAXL as usize];
        let mut SVTCDE: i32 = 0;
        let mut SVFND1: bool = false;
        let mut SVCTR2 = StackArray::<i32, 2>::new(1..=CTRSIZ);
        let mut SVOBSR = vec![b' '; MAXL as usize];
        let mut SVOBSC: i32 = 0;
        let mut SVFND2: bool = false;
        let mut SVCTR3 = StackArray::<i32, 2>::new(1..=CTRSIZ);
        let mut SVFREF = vec![b' '; FRNMLN as usize];
        let mut SVREFC: i32 = 0;
        let mut SVCTR4 = StackArray::<i32, 2>::new(1..=CTRSIZ);

        FIRST = true;
        NEAR = true;
        fstr::assign(&mut PRVCOR, b" ");
        fstr::assign(&mut PRVMTH, b" ");
        SHAPE = -1;

        Self {
            PRVCOR,
            PRVMTH,
            SUBTYP,
            NSURF,
            SHAPE,
            SRFLST,
            FIRST,
            NEAR,
            PRI,
            USECN,
            USELT,
            USESTL,
            XMIT,
            SVCTR1,
            SVTARG,
            SVTCDE,
            SVFND1,
            SVCTR2,
            SVOBSR,
            SVOBSC,
            SVFND2,
            SVCTR3,
            SVFREF,
            SVREFC,
            SVCTR4,
        }
    }
}

/// Sub-observer point
///
/// Compute the rectangular coordinates of the sub-observer point on
/// a target body at a specified epoch, optionally corrected for
/// light time and stellar aberration.
///
/// The surface of the target body may be represented by a triaxial
/// ellipsoid or by topographic data provided by DSK files.
///
/// This routine supersedes SUBPT.
///
/// # Required Reading
///
/// * [DSK](crate::required_reading::dsk)
/// * [FRAMES](crate::required_reading::frames)
/// * [NAIF_IDS](crate::required_reading::naif_ids)
/// * [PCK](crate::required_reading::pck)
/// * [SPK](crate::required_reading::spk)
/// * [TIME](crate::required_reading::time)
///
/// # Brief I/O
///
/// ```text
///  VARIABLE  I/O  DESCRIPTION
///  --------  ---  --------------------------------------------------
///  METHOD     I   Computation method.
///  TARGET     I   Name of target body.
///  ET         I   Epoch in ephemeris seconds past J2000 TDB.
///  FIXREF     I   Body-fixed, body-centered target body frame.
///  ABCORR     I   Aberration correction.
///  OBSRVR     I   Name of observing body.
///  SPOINT     O   Sub-observer point on the target body.
///  TRGEPC     O   Sub-observer point epoch.
///  SRFVEC     O   Vector from observer to sub-observer point.
/// ```
///
/// # Detailed Input
///
/// ```text
///  METHOD   is a short string providing parameters defining
///           the computation method to be used. In the syntax
///           descriptions below, items delimited by brackets
///           are optional.
///
///           METHOD may be assigned the following values:
///
///              'NEAR POINT/ELLIPSOID'
///
///                 The sub-observer point computation uses a
///                 triaxial ellipsoid to model the surface of the
///                 target body. The sub-observer point is defined
///                 as the nearest point on the target relative to
///                 the observer.
///
///                 The word "NADIR" may be substituted for the phrase
///                 "NEAR POINT" in the string above.
///
///                 For backwards compatibility, the older syntax
///
///                    'Near point: ellipsoid'
///
///                 is accepted as well.
///
///
///              'INTERCEPT/ELLIPSOID'
///
///                 The sub-observer point computation uses a
///                 triaxial ellipsoid to model the surface of the
///                 target body. The sub-observer point is defined
///                 as the target surface intercept of the line
///                 containing the observer and the target's
///                 center.
///
///                 For backwards compatibility, the older syntax
///
///                    'Intercept: ellipsoid'
///
///                 is accepted as well.
///
///
///              'NADIR/DSK/UNPRIORITIZED[/SURFACES = <surface list>]'
///
///                 The sub-observer point computation uses DSK data
///                 to model the surface of the target body. The
///                 sub-observer point is defined as the intercept, on
///                 the surface represented by the DSK data, of the
///                 line containing the observer and the nearest point
///                 on the target's reference ellipsoid. If multiple
///                 such intercepts exist, the one closest to the
///                 observer is selected.
///
///                 Note that this definition of the sub-observer
///                 point is not equivalent to the "nearest point on
///                 the surface to the observer." The phrase "NEAR
///                 POINT" may NOT be substituted for "NADIR" in the
///                 string above.
///
///                 The surface list specification is optional. The
///                 syntax of the list is
///
///                    <surface 1> [, <surface 2>...]
///
///                 If present, it indicates that data only for the
///                 listed surfaces are to be used; however, data
///                 need not be available for all surfaces in the
///                 list. If absent, loaded DSK data for any surface
///                 associated with the target body are used.
///
///                 The surface list may contain surface names or
///                 surface ID codes. Names containing blanks must
///                 be delimited by double quotes, for example
///
///                    SURFACES = "Mars MEGDR 128 PIXEL/DEG"
///
///                 If multiple surfaces are specified, their names
///                 or IDs must be separated by commas.
///
///                 See the $Particulars section below for details
///                 concerning use of DSK data.
///
///
///              'INTERCEPT/DSK/UNPRIORITIZED[/SURFACES =
///                                           <surface list>]'
///
///                 The sub-observer point computation uses DSK data
///                 to model the surface of the target body. The
///                 sub-observer point is defined as the target
///                 surface intercept of the line containing the
///                 observer and the target's center.
///
///                 If multiple such intercepts exist, the one closest
///                 to the observer is selected.
///
///                 The surface list specification is optional. The
///                 syntax of the list is identical to that for the
///                 NADIR option described above.
///
///
///              Neither case nor white space are significant in
///              METHOD, except within double-quoted strings. For
///              example, the string ' eLLipsoid/nearpoint ' is valid.
///
///              Within double-quoted strings, blank characters are
///              significant, but multiple consecutive blanks are
///              considered equivalent to a single blank. Case is
///              not significant. So
///
///                 "Mars MEGDR 128 PIXEL/DEG"
///
///              is equivalent to
///
///                 " mars megdr  128  pixel/deg "
///
///              but not to
///
///                 "MARS MEGDR128PIXEL/DEG"
///
///
///  TARGET   is the name of the target body. The target body is
///           an ephemeris object (its trajectory is given by
///           SPK data), and is an extended object.
///
///           The string TARGET is case-insensitive, and leading
///           and trailing blanks in TARGET are not significant.
///           Optionally, you may supply a string containing the
///           integer ID code for the object. For example both
///           'MOON' and '301' are legitimate strings that indicate
///           the Moon is the target body.
///
///           When the target body's surface is represented by a
///           tri-axial ellipsoid, this routine assumes that a
///           kernel variable representing the ellipsoid's radii is
///           present in the kernel pool. Normally the kernel
///           variable would be defined by loading a PCK file.
///
///
///  ET       is the epoch of participation of the observer,
///           expressed as ephemeris seconds past J2000 TDB: ET is
///           the epoch at which the observer's state is computed.
///
///           When aberration corrections are not used, ET is also
///           the epoch at which the position and orientation of
///           the target body are computed.
///
///           When aberration corrections are used, the position
///           and orientation of the target body are computed at
///           ET-LT or ET+LT, where LT is the one-way light time
///           between the sub-observer point and the observer, and
///           the sign applied to LT depends on the selected
///           correction. See the description of ABCORR below for
///           details.
///
///
///  FIXREF   is the name of a body-fixed reference frame centered
///           on the target body. FIXREF may be any such frame
///           supported by the SPICE system, including built-in
///           frames (documented in the Frames Required Reading)
///           and frames defined by a loaded frame kernel (FK). The
///           string FIXREF is case-insensitive, and leading and
///           trailing blanks in FIXREF are not significant.
///
///           The output sub-observer point SPOINT and the
///           observer-to-sub-observer point vector SRFVEC will be
///           expressed relative to this reference frame.
///
///  ABCORR   indicates the aberration corrections to be applied
///           when computing the target's position and orientation.
///
///           For remote sensing applications, where the apparent
///           sub-observer point seen by the observer is desired,
///           normally either of the corrections
///
///              'LT+S'
///              'CN+S'
///
///           should be used. These and the other supported options
///           are described below. ABCORR may be any of the
///           following:
///
///              'NONE'     Apply no correction. Return the
///                         geometric sub-observer point on the
///                         target body.
///
///           Let LT represent the one-way light time between the
///           observer and the sub-observer point (note: NOT
///           between the observer and the target body's center).
///           The following values of ABCORR apply to the
///           "reception" case in which photons depart from the
///           sub-observer point's location at the light-time
///           corrected epoch ET-LT and *arrive* at the observer's
///           location at ET:
///
///
///              'LT'       Correct for one-way light time (also
///                         called "planetary aberration") using a
///                         Newtonian formulation. This correction
///                         yields the location of sub-observer
///                         point at the moment it emitted photons
///                         arriving at the observer at ET.
///
///                         The light time correction uses an
///                         iterative solution of the light time
///                         equation. The solution invoked by the
///                         'LT' option uses one iteration.
///
///                         Both the target position as seen by the
///                         observer, and rotation of the target
///                         body, are corrected for light time.
///
///              'LT+S'     Correct for one-way light time and
///                         stellar aberration using a Newtonian
///                         formulation. This option modifies the
///                         sub-observer point obtained with the
///                         'LT' option to account for the
///                         observer's velocity relative to the
///                         solar system barycenter. These
///                         corrections yield the apparent
///                         sub-observer point.
///
///              'CN'       Converged Newtonian light time
///                         correction. In solving the light time
///                         equation, the 'CN' correction iterates
///                         until the solution converges. Both the
///                         position and rotation of the target
///                         body are corrected for light time.
///
///              'CN+S'     Converged Newtonian light time and
///                         stellar aberration corrections. This
///                         option produces a solution that is at
///                         least as accurate at that obtainable
///                         with the `LT+S' option. Whether the
///                         'CN+S' solution is substantially more
///                         accurate depends on the geometry of the
///                         participating objects and on the
///                         accuracy of the input data. In all
///                         cases this routine will execute more
///                         slowly when a converged solution is
///                         computed.
///
///
///           The following values of ABCORR apply to the
///           "transmission" case in which photons *depart* from
///           the observer's location at ET and arrive at the
///           sub-observer point at the light-time corrected epoch
///           ET+LT:
///
///              'XLT'      "Transmission" case: correct for
///                         one-way light time using a Newtonian
///                         formulation. This correction yields the
///                         sub-observer location at the moment it
///                         receives photons emitted from the
///                         observer's location at ET.
///
///                         The light time correction uses an
///                         iterative solution of the light time
///                         equation. The solution invoked by the
///                         'LT' option uses one iteration.
///
///                         Both the target position as seen by the
///                         observer, and rotation of the target
///                         body, are corrected for light time.
///
///              'XLT+S'    "Transmission" case: correct for
///                         one-way light time and stellar
///                         aberration using a Newtonian
///                         formulation  This option modifies the
///                         sub-observer point obtained with the
///                         'XLT' option to account for the
///                         observer's velocity relative to the
///                         solar system barycenter.
///
///              'XCN'      Converged Newtonian light time
///                         correction. This is the same as 'XLT'
///                         correction but with further iterations
///                         to a converged Newtonian light time
///                         solution.
///
///              'XCN+S'    "Transmission" case: converged
///                         Newtonian light time and stellar
///                         aberration corrections.
///
///
///           Neither case nor white space are significant in
///           ABCORR. For example, the string
///
///             'Lt + s'
///
///           is valid.
///
///
///  OBSRVR   is the name of the observing body. The observing body
///           is an ephemeris object: it typically is a spacecraft,
///           the earth, or a surface point on the earth. OBSRVR is
///           case-insensitive, and leading and trailing blanks in
///           OBSRVR are not significant. Optionally, you may
///           supply a string containing the integer ID code for
///           the object. For example both 'MOON' and '301' are
///           legitimate strings that indicate the Moon is the
///           observer.
/// ```
///
/// # Detailed Output
///
/// ```text
///  SPOINT   is the sub-observer point on the target body.
///
///           For target shapes modeled by ellipsoids, the
///           sub-observer point is defined either as the point on
///           the target body that is closest to the observer, or
///           the target surface intercept of the line from the
///           observer to the target's center.
///
///           For target shapes modeled by topographic data
///           provided by DSK files, the sub-observer point is
///           defined as the target surface intercept of the line
///           from the observer to either the nearest point on the
///           reference ellipsoid, or to the target's center. If
///           multiple such intercepts exist, the one closest to
///           the observer is selected.
///
///           The input argument METHOD selects the target shape
///           model and sub-observer point definition to be used.
///
///           SPOINT is expressed in Cartesian coordinates,
///           relative to the body-fixed target frame designated by
///           FIXREF. The body-fixed target frame is evaluated at
///           the sub-observer epoch TRGEPC (see description below).
///
///           When light time correction is used, the duration of
///           light travel between SPOINT to the observer is
///           considered to be the one way light time.
///
///           When aberration corrections are used, SPOINT is
///           computed using target body position and orientation
///           that have been adjusted for the corrections
///           applicable to SPOINT itself rather than to the target
///           body's center. In particular, if the stellar
///           aberration correction applicable to SPOINT is
///           represented by a shift vector S, then the light-time
///           corrected position of the target is shifted by S
///           before the sub-observer point is computed.
///
///           The components of SPOINT have units of km.
///
///
///  TRGEPC   is the "sub-observer point epoch." TRGEPC is defined
///           as follows: letting LT be the one-way light time
///           between the observer and the sub-observer point,
///           TRGEPC is the epoch ET-LT, ET+LT, or ET depending on
///           whether the requested aberration correction is,
///           respectively, for received radiation, transmitted
///           radiation, or omitted. LT is computed using the
///           method indicated by ABCORR.
///
///           TRGEPC is expressed as seconds past J2000 TDB.
///
///
///  SRFVEC   is the vector from the observer's position at ET to
///           the aberration-corrected (or optionally, geometric)
///           position of SPOINT, where the aberration corrections
///           are specified by ABCORR. SRFVEC is expressed in the
///           target body-fixed reference frame designated by
///           FIXREF, evaluated at TRGEPC.
///
///           The components of SRFVEC are given in units of km.
///
///           One can use the SPICELIB function VNORM to obtain the
///           distance between the observer and SPOINT:
///
///              DIST = VNORM ( SRFVEC )
///
///           The observer's position OBSPOS, relative to the
///           target body's center, where the center's position is
///           corrected for aberration effects as indicated by
///           ABCORR, can be computed via the call:
///
///              CALL VSUB ( SPOINT, SRFVEC, OBSPOS )
///
///           To transform the vector SRFVEC from a reference frame
///           FIXREF at time TRGEPC to a time-dependent reference
///           frame REF at time ET, the routine PXFRM2 should be
///           called. Let XFORM be the 3x3 matrix representing the
///           rotation from the reference frame FIXREF at time
///           TRGEPC to the reference frame REF at time ET. Then
///           SRFVEC can be transformed to the result REFVEC as
///           follows:
///
///               CALL PXFRM2 ( FIXREF, REF,    TRGEPC, ET, XFORM )
///               CALL MXV    ( XFORM,  SRFVEC, REFVEC )
///
///           The second example in the $Examples header section
///           below presents a complete program that demonstrates
///           this procedure.
/// ```
///
/// # Exceptions
///
/// ```text
///  1)  If the specified aberration correction is unrecognized, an
///      error is signaled by a routine in the call tree of this
///      routine.
///
///  2)  If either the target or observer input strings cannot be
///      converted to an integer ID code, the error
///      SPICE(IDCODENOTFOUND) is signaled.
///
///  3)  If OBSRVR and TARGET map to the same NAIF integer ID code,
///      the error SPICE(BODIESNOTDISTINCT) is signaled.
///
///  4)  If the input target body-fixed frame FIXREF is not
///      recognized, the error SPICE(NOFRAME) is signaled. A frame
///      name may fail to be recognized because a required frame
///      specification kernel has not been loaded; another cause is a
///      misspelling of the frame name.
///
///  5)  If the input frame FIXREF is not centered at the target body,
///      the error SPICE(INVALIDFRAME) is signaled.
///
///  6)  If the input argument METHOD is not recognized, the error
///      SPICE(INVALIDMETHOD) is signaled by this routine, or, the
///      error is signaled by a routine in the call tree of this
///      routine.
///
///  7)  If the sub-observer point type is not specified or is not
///      recognized, the error SPICE(INVALIDSUBTYPE) is signaled.
///
///  8)  If the target and observer have distinct identities but are
///      at the same location (for example, the target is Mars and the
///      observer is the Mars barycenter), the error
///      SPICE(NOSEPARATION) is signaled.
///
///  9)  If insufficient ephemeris data have been loaded prior to
///      calling SUBPNT, an error is signaled by a
///      routine in the call tree of this routine. Note that when
///      light time correction is used, sufficient ephemeris data must
///      be available to propagate the states of both observer and
///      target to the solar system barycenter.
///
///  10) If the computation method specifies an ellipsoidal target
///      shape and triaxial radii of the target body have not been
///      loaded into the kernel pool prior to calling SUBPNT, an error
///      is signaled by a routine in the call tree of this routine.
///
///  11) The target must be an extended body, and must have a shape
///      for which a sub-observer point can be defined.
///
///      If the target body's shape is modeled by DSK data, the shape
///      must be such that the specified sub-observer point
///      definition is applicable. For example, if the target shape
///      is a torus, both the NADIR and INTERCEPT definitions might
///      be inapplicable, depending on the relative locations of the
///      observer and target.
///
///  12) If PCK data specifying the target body-fixed frame orientation
///      have not been loaded prior to calling SUBPNT, an error is
///      signaled by a routine in the call tree of this routine.
///
///  13) If METHOD specifies that the target surface is represented by
///      DSK data, and no DSK files are loaded for the specified
///      target, an error is signaled by a routine in the call tree
///      of this routine.
///
///  14) If METHOD specifies that the target surface is represented
///      by DSK data, and the ray from the observer to the
///      sub-observer point doesn't intersect the target body's
///      surface, the error SPICE(SUBPOINTNOTFOUND) is signaled.
///
///  15) If the surface intercept on the target body's reference
///      ellipsoid of the observer to target center vector cannot not
///      be computed, the error SPICE(DEGENERATECASE) is signaled. Note
///      that this is a very rare case.
///
///  16) If radii for TARGET are not found in the kernel pool, an error
///      is signaled by a routine in the call tree of this routine.
///
///  17) If the size of the TARGET body radii kernel variable is not
///      three, an error is signaled by a routine in the call tree of
///      this routine.
///
///  18) If any of the three TARGET body radii is less-than or equal to
///      zero, an error is signaled by a routine in the call tree of
///      this routine.
/// ```
///
/// # Files
///
/// ```text
///  Appropriate kernels must be loaded by the calling program before
///  this routine is called.
///
///  The following data are required:
///
///  -  SPK data: ephemeris data for target and observer must be
///     loaded. If aberration corrections are used, the states of
///     target and observer relative to the solar system barycenter
///     must be calculable from the available ephemeris data.
///     Typically ephemeris data are made available by loading one
///     or more SPK files via FURNSH.
///
///  -  PCK data: rotation data for the target body must be
///     loaded. These may be provided in a text or binary PCK file.
///
///  -  Shape data for the target body:
///
///        PCK data:
///
///           If the target body shape is modeled as an ellipsoid,
///           triaxial radii for the target body must be loaded into
///           the kernel pool. Typically this is done by loading a
///           text PCK file via FURNSH.
///
///           Triaxial radii are also needed if the target shape is
///           modeled by DSK data, but the DSK NADIR method is
///           selected.
///
///        DSK data:
///
///           If the target shape is modeled by DSK data, DSK files
///           containing topographic data for the target body must be
///           loaded. If a surface list is specified, data for at
///           least one of the listed surfaces must be loaded.
///
///  The following data may be required:
///
///  -  Frame data: if a frame definition is required to convert the
///     observer and target states to the body-fixed frame of the
///     target, that definition must be available in the kernel
///     pool. Typically the definition is supplied by loading a
///     frame kernel via FURNSH.
///
///  -  Surface name-ID associations: if surface names are specified
///     in METHOD, the association of these names with their
///     corresponding surface ID codes must be established by
///     assignments of the kernel variables
///
///        NAIF_SURFACE_NAME
///        NAIF_SURFACE_CODE
///        NAIF_SURFACE_BODY
///
///     Normally these associations are made by loading a text
///     kernel containing the necessary assignments. An example
///     of such an assignment is
///
///        NAIF_SURFACE_NAME += 'Mars MEGDR 128 PIXEL/DEG'
///        NAIF_SURFACE_CODE += 1
///        NAIF_SURFACE_BODY += 499
///
///  In all cases, kernel data are normally loaded once per program
///  run, NOT every time this routine is called.
/// ```
///
/// # Particulars
///
/// ```text
///  For ellipsoidal target bodies, there are two different popular
///  ways to define the sub-observer point: "nearest point on the
///  target to the observer" or "target surface intercept of the line
///  containing observer and target." These coincide when the target
///  is spherical and generally are distinct otherwise.
///
///  For target body shapes modeled using topographic data provided by
///  DSK files, the "surface intercept" notion is valid, but the
///  "nearest point on the surface" computation is both inefficient to
///  execute and may fail to yield a result that is "under" the
///  observer in an intuitively clear way. The NADIR option for DSK
///  shapes instead finds the surface intercept of a ray that passes
///  through the nearest point on the target reference ellipsoid. For
///  shapes modeled using topography, there may be multiple
///  ray-surface intercepts; the closest one to the observer is
///  selected.
///
///  The NADIR definition makes sense only if the target shape is
///  reasonably close to the target's reference ellipsoid. If the
///  target is very different---the nucleus of comet
///  Churyumov-Gerasimenko is an example---the intercept definition
///  should be used.
///
///  This routine computes light time corrections using light time
///  between the observer and the sub-observer point, as opposed to
///  the center of the target. Similarly, stellar aberration
///  corrections done by this routine are based on the direction of
///  the vector from the observer to the light-time corrected
///  sub-observer point, not to the target center. This technique
///  avoids errors due to the differential between aberration
///  corrections across the target body. Therefore it's valid to use
///  aberration corrections with this routine even when the observer
///  is very close to the sub-observer point, in particular when the
///  observer to sub-observer point distance is much less than the
///  observer to target center distance.
///
///  When comparing sub-observer point computations with results from
///  sources other than SPICE, it's essential to make sure the same
///  geometric definitions are used.
///
///
///  Using DSK data
///  ==============
///
///     DSK loading and unloading
///     -------------------------
///
///     DSK files providing data used by this routine are loaded by
///     calling FURNSH and can be unloaded by calling UNLOAD or
///     KCLEAR. See the documentation of FURNSH for limits on numbers
///     of loaded DSK files.
///
///     For run-time efficiency, it's desirable to avoid frequent
///     loading and unloading of DSK files. When there is a reason to
///     use multiple versions of data for a given target body---for
///     example, if topographic data at varying resolutions are to be
///     used---the surface list can be used to select DSK data to be
///     used for a given computation. It is not necessary to unload
///     the data that are not to be used. This recommendation presumes
///     that DSKs containing different versions of surface data for a
///     given body have different surface ID codes.
///
///
///     DSK data priority
///     -----------------
///
///     A DSK coverage overlap occurs when two segments in loaded DSK
///     files cover part or all of the same domain---for example, a
///     given longitude-latitude rectangle---and when the time
///     intervals of the segments overlap as well.
///
///     When DSK data selection is prioritized, in case of a coverage
///     overlap, if the two competing segments are in different DSK
///     files, the segment in the DSK file loaded last takes
///     precedence. If the two segments are in the same file, the
///     segment located closer to the end of the file takes
///     precedence.
///
///     When DSK data selection is unprioritized, data from competing
///     segments are combined. For example, if two competing segments
///     both represent a surface as sets of triangular plates, the
///     union of those sets of plates is considered to represent the
///     surface.
///
///     Currently only unprioritized data selection is supported.
///     Because prioritized data selection may be the default behavior
///     in a later version of the routine, the UNPRIORITIZED keyword is
///     required in the METHOD argument.
///
///
///     Syntax of the METHOD input argument
///     -----------------------------------
///
///     The keywords and surface list in the METHOD argument
///     are called "clauses." The clauses may appear in any
///     order, for example
///
///        NADIR/DSK/UNPRIORITIZED/<surface list>
///        DSK/NADIR/<surface list>/UNPRIORITIZED
///        UNPRIORITIZED/<surface list>/DSK/NADIR
///
///     The simplest form of the METHOD argument specifying use of
///     DSK data is one that lacks a surface list, for example:
///
///        'NADIR/DSK/UNPRIORITIZED'
///        'INTERCEPT/DSK/UNPRIORITIZED'
///
///     For applications in which all loaded DSK data for the target
///     body are for a single surface, and there are no competing
///     segments, the above strings suffice. This is expected to be
///     the usual case.
///
///     When, for the specified target body, there are loaded DSK
///     files providing data for multiple surfaces for that body, the
///     surfaces to be used by this routine for a given call must be
///     specified in a surface list, unless data from all of the
///     surfaces are to be used together.
///
///     The surface list consists of the string
///
///        SURFACES =
///
///     followed by a comma-separated list of one or more surface
///     identifiers. The identifiers may be names or integer codes in
///     string format. For example, suppose we have the surface
///     names and corresponding ID codes shown below:
///
///        Surface Name                              ID code
///        ------------                              -------
///        'Mars MEGDR 128 PIXEL/DEG'                1
///        'Mars MEGDR 64 PIXEL/DEG'                 2
///        'Mars_MRO_HIRISE'                         3
///
///     If data for all of the above surfaces are loaded, then
///     data for surface 1 can be specified by either
///
///        'SURFACES = 1'
///
///     or
///
///        'SURFACES = "Mars MEGDR 128 PIXEL/DEG"'
///
///     Double quotes are used to delimit the surface name because
///     it contains blank characters.
///
///     To use data for surfaces 2 and 3 together, any
///     of the following surface lists could be used:
///
///        'SURFACES = 2, 3'
///
///        'SURFACES = "Mars MEGDR  64 PIXEL/DEG", 3'
///
///        'SURFACES = 2, Mars_MRO_HIRISE'
///
///        'SURFACES = "Mars MEGDR 64 PIXEL/DEG", Mars_MRO_HIRISE'
///
///     An example of a METHOD argument that could be constructed
///     using one of the surface lists above is
///
///     'NADIR/DSK/UNPRIORITIZED/SURFACES= "Mars MEGDR 64 PIXEL/DEG",3'
///
///
///
///     Aberration corrections
///     ----------------------
///
///     For irregularly shaped target bodies, the distance between the
///     observer and the nearest surface intercept need not be a
///     continuous function of time; hence the one-way light time
///     between the intercept and the observer may be discontinuous as
///     well. In such cases, the computed light time, which is found
///     using an iterative algorithm, may converge slowly or not at
///     all. In all cases, the light time computation will terminate,
///     but the result may be less accurate than expected.
/// ```
///
/// # Examples
///
/// ```text
///  The numerical results shown for these examples may differ across
///  platforms. The results depend on the SPICE kernels used as
///  input, the compiler and supporting libraries, and the machine
///  specific arithmetic implementation.
///
///
///  1) Find the sub-Earth point on Mars for a specified time.
///
///     Compute the sub-Earth points using both triaxial ellipsoid
///     and topographic surface models. Topography data are provided by
///     a DSK file. For the ellipsoid model, use both the "intercept"
///     and "near point" sub-observer point definitions; for the DSK
///     case, use both the "intercept" and "nadir" definitions.
///
///     Display the locations of both the Earth and the sub-Earth
///     point relative to the center of Mars, in the IAU_MARS
///     body-fixed reference frame, using both planetocentric and
///     planetographic coordinates.
///
///     The topographic model is based on data from the MGS MOLA DEM
///     megr90n000cb, which has a resolution of 4 pixels/degree. A
///     triangular plate model was produced by computing a 720 x 1440
///     grid of interpolated heights from this DEM, then tessellating
///     the height grid. The plate model is stored in a type 2 segment
///     in the referenced DSK file.
///
///     Use the meta-kernel shown below to load the required SPICE
///     kernels.
///
///
///        KPL/MK
///
///        File: subpnt_ex1.tm
///
///        This meta-kernel is intended to support operation of SPICE
///        example programs. The kernels shown here should not be
///        assumed to contain adequate or correct versions of data
///        required by SPICE-based user applications.
///
///        In order for an application to use this meta-kernel, the
///        kernels referenced here must be present in the user's
///        current working directory.
///
///        The names and contents of the kernels referenced
///        by this meta-kernel are as follows:
///
///           File name                        Contents
///           ---------                        --------
///           de430.bsp                        Planetary ephemeris
///           mar097.bsp                       Mars satellite ephemeris
///           pck00010.tpc                     Planet orientation and
///                                            radii
///           naif0011.tls                     Leapseconds
///           megr90n000cb_plate.bds           Plate model based on
///                                            MEGDR DEM, resolution
///                                            4 pixels/degree.
///
///        \begindata
///
///           KERNELS_TO_LOAD = ( 'de430.bsp',
///                               'mar097.bsp',
///                               'pck00010.tpc',
///                               'naif0011.tls',
///                               'megr90n000cb_plate.bds' )
///        \begintext
///
///        End of meta-kernel
///
///
///     Example code begins here.
///
///
///           PROGRAM SUBPNT_EX1
///           IMPLICIT NONE
///     C
///     C     SPICELIB functions
///     C
///           DOUBLE PRECISION      DPR
///           DOUBLE PRECISION      VNORM
///     C
///     C     Local parameters
///     C
///           CHARACTER*(*)         META
///           PARAMETER           ( META   = 'subpnt_ex1.tm' )
///
///           CHARACTER*(*)         FM
///           PARAMETER           ( FM     =  '(A,F21.9)' )
///
///           INTEGER               MTHLEN
///           PARAMETER           ( MTHLEN = 50 )
///
///           INTEGER               NMETH
///           PARAMETER           ( NMETH  = 4 )
///
///     C
///     C     Local variables
///     C
///           CHARACTER*(MTHLEN)    METHOD ( NMETH )
///
///           DOUBLE PRECISION      ET
///           DOUBLE PRECISION      F
///           DOUBLE PRECISION      OBSPOS ( 3 )
///           DOUBLE PRECISION      ODIST
///           DOUBLE PRECISION      OPCLAT
///           DOUBLE PRECISION      OPCLON
///           DOUBLE PRECISION      OPCRAD
///           DOUBLE PRECISION      OPGALT
///           DOUBLE PRECISION      OPGLAT
///           DOUBLE PRECISION      OPGLON
///           DOUBLE PRECISION      RADII  ( 3 )
///           DOUBLE PRECISION      RE
///           DOUBLE PRECISION      RP
///           DOUBLE PRECISION      SPCLAT
///           DOUBLE PRECISION      SPCLON
///           DOUBLE PRECISION      SPCRAD
///           DOUBLE PRECISION      SPGALT
///           DOUBLE PRECISION      SPGLAT
///           DOUBLE PRECISION      SPGLON
///           DOUBLE PRECISION      SPOINT ( 3 )
///           DOUBLE PRECISION      SRFVEC ( 3 )
///           DOUBLE PRECISION      TRGEPC
///
///           INTEGER               I
///           INTEGER               N
///     C
///     C     Saved variables
///     C
///           SAVE                  METHOD
///     C
///     C     Initial values
///     C
///           DATA                  METHOD / 'Intercept/ellipsoid',
///          .                               'Near point/ellipsoid',
///          .                      'Intercept/DSK/Unprioritized',
///          .                      'Nadir/DSK/Unprioritized'      /
///
///     C
///     C     Load kernel files via the meta-kernel.
///     C
///           CALL FURNSH ( META )
///
///     C
///     C     Convert the UTC request time string seconds past
///     C     J2000, TDB.
///     C
///           CALL STR2ET ( '2008 AUG 11 00:00:00', ET )
///
///     C
///     C     Look up the target body's radii. We'll use these to
///     C     convert Cartesian to planetographic coordinates. Use
///     C     the radii to compute the flattening coefficient of
///     C     the reference ellipsoid.
///     C
///           CALL BODVRD ( 'MARS', 'RADII', 3, N, RADII )
///
///     C
///     C     Let RE and RP be, respectively, the equatorial and
///     C     polar radii of the target.
///     C
///           RE = RADII( 1 )
///           RP = RADII( 3 )
///
///           F  = ( RE - RP ) / RE
///
///     C
///     C     Compute sub-observer point using light time and
///     C     stellar aberration corrections. Use both ellipsoid
///     C     and DSK shape models, and use all of the
///     C     "near point," "intercept," and "nadir" sub-observer
///     C     point definitions.
///     C
///           DO I = 1, NMETH
///
///              CALL SUBPNT ( METHOD(I),
///          .                'MARS',  ET,     'IAU_MARS', 'CN+S',
///          .                'EARTH', SPOINT, TRGEPC,     SRFVEC )
///     C
///     C        Compute the observer's distance from SPOINT.
///     C
///              ODIST  = VNORM ( SRFVEC )
///
///     C
///     C        Convert the sub-observer point's rectangular
///     C        coordinates to planetographic longitude, latitude
///     C        and altitude. Convert radians to degrees.
///     C
///              CALL RECPGR ( 'MARS', SPOINT, RE,    F,
///          .                 SPGLON, SPGLAT, SPGALT   )
///
///              SPGLON = SPGLON * DPR ()
///              SPGLAT = SPGLAT * DPR ()
///
///     C
///     C        Convert sub-observer point's rectangular coordinates
///     C        to planetocentric radius, longitude, and latitude.
///     C        Convert radians to degrees.
///     C
///              CALL RECLAT ( SPOINT, SPCRAD, SPCLON, SPCLAT )
///
///              SPCLON = SPCLON * DPR ()
///              SPCLAT = SPCLAT * DPR ()
///
///     C
///     C        Compute the observer's position relative to the center
///     C        of the target, where the center's location has been
///     C        adjusted using the aberration corrections applicable
///     C        to the sub-point. Express the observer's location in
///     C        planetographic coordinates.
///     C
///              CALL VSUB ( SPOINT, SRFVEC, OBSPOS )
///
///              CALL RECPGR ( 'MARS', OBSPOS, RE,    F,
///          .                 OPGLON, OPGLAT, OPGALT   )
///
///              OPGLON = OPGLON * DPR ()
///              OPGLAT = OPGLAT * DPR ()
///
///     C
///     C        Convert the observer's rectangular coordinates to
///     C        planetocentric radius, longitude, and latitude.
///     C        Convert radians to degrees.
///     C
///              CALL RECLAT ( OBSPOS, OPCRAD, OPCLON, OPCLAT )
///
///              OPCLON = OPCLON * DPR ()
///              OPCLAT = OPCLAT * DPR ()
///
///     C
///     C        Write the results.
///     C
///              WRITE(*,FM) ' '
///              WRITE(*,* ) 'Computation method = ', METHOD(I)
///              WRITE(*,FM) ' '
///              WRITE(*,FM)
///          .   '  Observer ALT relative to spheroid (km) =', OPGALT
///              WRITE(*,FM)
///          .   '  Length of SRFVEC                  (km) =', ODIST
///              WRITE(*,FM)
///          .   '  Sub-observer point ALT            (km) =', SPGALT
///              WRITE(*,FM)
///          .   '  Sub-observer planetographic LON  (deg) =', SPGLON
///              WRITE(*,FM)
///          .   '  Observer planetographic LON      (deg) =', OPGLON
///              WRITE(*,FM)
///          .   '  Sub-observer planetographic LAT  (deg) =', SPGLAT
///              WRITE(*,FM)
///          .   '  Observer planetographic LAT      (deg) =', OPGLAT
///              WRITE(*,FM)
///          .   '  Sub-observer planetocentric LON  (deg) =', SPCLON
///              WRITE(*,FM)
///          .   '  Observer planetocentric LON      (deg) =', OPCLON
///              WRITE(*,FM)
///          .   '  Sub-observer planetocentric LAT  (deg) =', SPCLAT
///              WRITE(*,FM)
///          .   '  Observer planetocentric LAT      (deg) =', OPCLAT
///              WRITE(*,FM) ' '
///
///           END DO
///
///           END
///
///
///     When this program was executed on a Mac/Intel/gfortran/64-bit
///     platform, the output was:
///
///
///      Computation method = Intercept/ellipsoid
///
///       Observer ALT relative to spheroid (km) =  349199089.540947020
///       Length of SRFVEC                  (km) =  349199089.577642620
///       Sub-observer point ALT            (km) =          0.000000000
///       Sub-observer planetographic LON  (deg) =        199.302305028
///       Observer planetographic LON      (deg) =        199.302305028
///       Sub-observer planetographic LAT  (deg) =         26.262401237
///       Observer planetographic LAT      (deg) =         25.994936751
///       Sub-observer planetocentric LON  (deg) =        160.697694972
///       Observer planetocentric LON      (deg) =        160.697694972
///       Sub-observer planetocentric LAT  (deg) =         25.994934171
///       Observer planetocentric LAT      (deg) =         25.994934171
///
///
///      Computation method = Near point/ellipsoid
///
///       Observer ALT relative to spheroid (km) =  349199089.540938556
///       Length of SRFVEC                  (km) =  349199089.540938556
///       Sub-observer point ALT            (km) =          0.000000000
///       Sub-observer planetographic LON  (deg) =        199.302305029
///       Observer planetographic LON      (deg) =        199.302305029
///       Sub-observer planetographic LAT  (deg) =         25.994936751
///       Observer planetographic LAT      (deg) =         25.994936751
///       Sub-observer planetocentric LON  (deg) =        160.697694971
///       Observer planetocentric LON      (deg) =        160.697694971
///       Sub-observer planetocentric LAT  (deg) =         25.729407227
///       Observer planetocentric LAT      (deg) =         25.994934171
///
///
///      Computation method = Intercept/DSK/Unprioritized
///
///       Observer ALT relative to spheroid (km) =  349199089.541017115
///       Length of SRFVEC                  (km) =  349199091.785406590
///       Sub-observer point ALT            (km) =         -2.207669751
///       Sub-observer planetographic LON  (deg) =        199.302304999
///       Observer planetographic LON      (deg) =        199.302304999
///       Sub-observer planetographic LAT  (deg) =         26.262576677
///       Observer planetographic LAT      (deg) =         25.994936751
///       Sub-observer planetocentric LON  (deg) =        160.697695001
///       Observer planetocentric LON      (deg) =        160.697695001
///       Sub-observer planetocentric LAT  (deg) =         25.994934171
///       Observer planetocentric LAT      (deg) =         25.994934171
///
///
///      Computation method = Nadir/DSK/Unprioritized
///
///       Observer ALT relative to spheroid (km) =  349199089.541007578
///       Length of SRFVEC                  (km) =  349199091.707172215
///       Sub-observer point ALT            (km) =         -2.166164622
///       Sub-observer planetographic LON  (deg) =        199.302305000
///       Observer planetographic LON      (deg) =        199.302305000
///       Sub-observer planetographic LAT  (deg) =         25.994936751
///       Observer planetographic LAT      (deg) =         25.994936751
///       Sub-observer planetocentric LON  (deg) =        160.697695000
///       Observer planetocentric LON      (deg) =        160.697695000
///       Sub-observer planetocentric LAT  (deg) =         25.729237570
///       Observer planetocentric LAT      (deg) =         25.994934171
///
///
///  2) Use SUBPNT to find the sub-spacecraft point on Mars for the
///     Mars Reconnaissance Orbiter spacecraft (MRO) at a specified
///     time, using both the 'Ellipsoid/Near point' computation method
///     and an ellipsoidal target shape, and the
///     'DSK/Unprioritized/Nadir' method and a DSK-based shape model.
///
///     Use both LT+S and CN+S aberration corrections to illustrate
///     the differences.
///
///     Convert the spacecraft to sub-observer point vector obtained
///     from SUBPNT into the MRO_HIRISE_LOOK_DIRECTION reference frame
///     at the observation time. Perform a consistency check with this
///     vector: compare the Mars surface intercept of the ray
///     emanating from the spacecraft and pointed along this vector
///     with the sub-observer point.
///
///     Perform the sub-observer point and surface intercept
///     computations using both triaxial ellipsoid and topographic
///     surface models.
///
///     For this example, the topographic model is based on the MGS
///     MOLA DEM megr90n000eb, which has a resolution of 16
///     pixels/degree. Eight DSKs, each covering longitude and
///     latitude ranges of 90 degrees, were made from this data set.
///     For the region covered by a given DSK, a grid of approximately
///     1500 x 1500 interpolated heights was produced, and this grid
///     was tessellated using approximately 4.5 million triangular
///     plates, giving a total plate count of about 36 million for the
///     entire DSK set.
///
///     All DSKs in the set use the surface ID code 499001, so there
///     is no need to specify the surface ID in the METHOD strings
///     passed to SINCPT and SUBPNT.
///
///     Use the meta-kernel shown below to load the required SPICE
///     kernels.
///
///
///        KPL/MK
///
///        File: subpnt_ex2.tm
///
///        This meta-kernel is intended to support operation of SPICE
///        example programs. The kernels shown here should not be
///        assumed to contain adequate or correct versions of data
///        required by SPICE-based user applications.
///
///        In order for an application to use this meta-kernel, the
///        kernels referenced here must be present in the user's
///        current working directory.
///
///        The names and contents of the kernels referenced
///        by this meta-kernel are as follows:
///
///           File name                        Contents
///           ---------                        --------
///           de430.bsp                        Planetary ephemeris
///           mar097.bsp                       Mars satellite ephemeris
///           pck00010.tpc                     Planet orientation and
///                                            radii
///           naif0011.tls                     Leapseconds
///           mro_psp4_ssd_mro95a.bsp          MRO ephemeris
///           mro_v11.tf                       MRO frame specifications
///           mro_sclkscet_00022_65536.tsc     MRO SCLK coefficients
///                                            parameters
///           mro_sc_psp_070925_071001.bc      MRO attitude
///           megr90n000eb_*_plate.bds         Plate model DSKs based
///                                            on MEGDR DEM, resolution
///                                            16 pixels/degree.
///
///        \begindata
///
///           KERNELS_TO_LOAD = (
///
///              'de430.bsp',
///              'mar097.bsp',
///              'pck00010.tpc',
///              'naif0011.tls',
///              'mro_psp4_ssd_mro95a.bsp',
///              'mro_v11.tf',
///              'mro_sclkscet_00022_65536.tsc',
///              'mro_sc_psp_070925_071001.bc',
///              'megr90n000eb_LL000E00N_UR090E90N_plate.bds'
///              'megr90n000eb_LL000E90S_UR090E00S_plate.bds'
///              'megr90n000eb_LL090E00N_UR180E90N_plate.bds'
///              'megr90n000eb_LL090E90S_UR180E00S_plate.bds'
///              'megr90n000eb_LL180E00N_UR270E90N_plate.bds'
///              'megr90n000eb_LL180E90S_UR270E00S_plate.bds'
///              'megr90n000eb_LL270E00N_UR360E90N_plate.bds'
///              'megr90n000eb_LL270E90S_UR360E00S_plate.bds'  )
///
///        \begintext
///
///        End of meta-kernel
///
///
///     Example code begins here.
///
///
///           PROGRAM SUBPNT_EX2
///           IMPLICIT NONE
///     C
///     C     SPICELIB functions
///     C
///           DOUBLE PRECISION      DPR
///           DOUBLE PRECISION      VDIST
///           DOUBLE PRECISION      VNORM
///
///     C
///     C     Local parameters
///     C
///           CHARACTER*(*)         META
///           PARAMETER           ( META   = 'subpnt_ex2.tm' )
///
///           CHARACTER*(*)         F1
///           PARAMETER           ( F1     = '(A,F21.9)' )
///
///           CHARACTER*(*)         F2
///           PARAMETER           ( F2     = '(A)' )
///
///           INTEGER               FRNMLN
///           PARAMETER           ( FRNMLN = 32 )
///
///           INTEGER               MTHLEN
///           PARAMETER           ( MTHLEN = 50 )
///
///           INTEGER               CORLEN
///           PARAMETER           ( CORLEN = 5 )
///
///           INTEGER               NCORR
///           PARAMETER           ( NCORR  = 2 )
///
///           INTEGER               NMETH
///           PARAMETER           ( NMETH  = 2 )
///
///     C
///     C     Local variables
///     C
///           CHARACTER*(CORLEN)    ABCORR ( NCORR )
///           CHARACTER*(FRNMLN)    FIXREF
///           CHARACTER*(FRNMLN)    HIREF
///           CHARACTER*(MTHLEN)    SINMTH ( NMETH )
///           CHARACTER*(MTHLEN)    SUBMTH ( NMETH )
///
///           DOUBLE PRECISION      ALT
///           DOUBLE PRECISION      ET
///           DOUBLE PRECISION      LAT
///           DOUBLE PRECISION      LON
///           DOUBLE PRECISION      MROVEC ( 3 )
///           DOUBLE PRECISION      RADIUS
///           DOUBLE PRECISION      SPOINT ( 3 )
///           DOUBLE PRECISION      SRFVEC ( 3 )
///           DOUBLE PRECISION      TRGEPC
///           DOUBLE PRECISION      XFORM  ( 3, 3 )
///           DOUBLE PRECISION      XEPOCH
///           DOUBLE PRECISION      XPOINT ( 3 )
///           DOUBLE PRECISION      XVEC   ( 3 )
///
///           INTEGER               I
///           INTEGER               J
///
///           LOGICAL               FOUND
///
///     C
///     C     Initial values
///     C
///           DATA                  ABCORR / 'LT+S', 'CN+S'         /
///           DATA                  FIXREF / 'IAU_MARS'             /
///           DATA                  SINMTH / 'Ellipsoid',
///          .                               'DSK/Unprioritized'    /
///           DATA                  SUBMTH / 'Ellipsoid/Near point',
///          .                            'DSK/Unprioritized/Nadir' /
///
///     C
///     C     Load kernel files via the meta-kernel.
///     C
///           CALL FURNSH ( META )
///
///     C
///     C     Convert the TDB request time string to seconds past
///     C     J2000, TDB.
///     C
///           CALL STR2ET ( '2007 SEP 30 00:00:00 TDB', ET )
///
///     C
///     C     Compute the sub-spacecraft point using the
///     C     "NEAR POINT: ELLIPSOID" definition.
///     C     Compute the results using both LT+S and CN+S
///     C     aberration corrections.
///     C
///     C     Repeat the computation for each method.
///     C
///     C
///           DO I = 1, NMETH
///
///              WRITE(*,F2) ' '
///              WRITE(*,F2) 'Sub-observer point computation method = '
///          .               // SUBMTH(I)
///
///              DO J = 1, NCORR
///
///                 CALL SUBPNT ( SUBMTH(I),
///          .                    'Mars', ET,     FIXREF, ABCORR(J),
///          .                    'MRO',  SPOINT, TRGEPC, SRFVEC    )
///     C
///     C           Compute the observer's altitude above SPOINT.
///     C
///                 ALT = VNORM ( SRFVEC )
///     C
///     C           Express SRFVEC in the MRO_HIRISE_LOOK_DIRECTION
///     C           reference frame at epoch ET. Since SRFVEC is
///     c           expressed relative to the IAU_MARS frame at
///     C           TRGEPC, we must call PXFRM2 to compute the position
///     C           transformation matrix from IAU_MARS at TRGEPC to
///     C           the MRO_HIRISE_LOOK_DIRECTION frame at time ET.
///     C
///     C           To make code formatting a little easier, we'll
///     C           store the long MRO reference frame name in a
///     C           variable:
///     C
///                 HIREF = 'MRO_HIRISE_LOOK_DIRECTION'
///
///                 CALL PXFRM2 ( FIXREF, HIREF,  TRGEPC, ET, XFORM )
///                 CALL MXV    ( XFORM,  SRFVEC, MROVEC )
///
///     C
///     C           Convert rectangular coordinates to planetocentric
///     C           latitude and longitude. Convert radians to degrees.
///     C
///                 CALL RECLAT ( SPOINT, RADIUS, LON, LAT  )
///
///                 LON = LON * DPR ()
///                 LAT = LAT * DPR ()
///     C
///     C           Write the results.
///     C
///                 WRITE(*,F2) ' '
///                 WRITE(*,F2) '   Aberration correction = '
///          .      // ABCORR(J)
///                 WRITE(*,F1) ' '
///                 WRITE(*,F2) '      MRO-to-sub-observer vector in'
///                 WRITE(*,F2) '      MRO HIRISE look direction frame'
///                 WRITE(*,F1) '        X-component             '
///          .      // '(km) = ', MROVEC(1)
///                 WRITE(*,F1) '        Y-component             '
///          .      // '(km) = ', MROVEC(2)
///                 WRITE(*,F1) '        Z-component             '
///          .      // '(km) = ', MROVEC(3)
///                 WRITE(*,F1) '      Sub-observer point radius '
///          .      // '(km) = ', RADIUS
///                 WRITE(*,F1) '      Planetocentric latitude  '
///          .      // '(deg) = ', LAT
///                 WRITE(*,F1) '      Planetocentric longitude '
///          .      // '(deg) = ', LON
///                 WRITE(*,F1) '      Observer altitude         '
///          .      // '(km) = ', ALT
///
///     C
///     C           Consistency check: find the surface intercept on
///     C           Mars of the ray emanating from the spacecraft and
///     C           having direction vector MROVEC in the MRO HIRISE
///     C           reference frame at ET. Call the intercept point
///     C           XPOINT. XPOINT should coincide with SPOINT, up to
///     C           a small round-off error.
///     C
///                 CALL SINCPT ( SINMTH(I), 'Mars', ET,    FIXREF,
///          .                    ABCORR(J), 'MRO',  HIREF, MROVEC,
///          .                    XPOINT,    XEPOCH, XVEC,  FOUND  )
///
///                 IF ( .NOT. FOUND ) THEN
///                    WRITE (*,F1) 'Bug: no intercept'
///                 ELSE
///     C
///     C              Report the distance between XPOINT and SPOINT.
///     C
///                    WRITE (*,* ) ' '
///                    WRITE (*,F1) '   Intercept comparison '
///          .         //           'error (km) = ',
///          .                      VDIST( XPOINT, SPOINT )
///                 END IF
///
///              END DO
///
///           END DO
///
///           END
///
///
///     When this program was executed on a Mac/Intel/gfortran/64-bit
///     platform, the output was:
///
///
///     Sub-observer point computation method = Ellipsoid/Near point
///
///        Aberration correction = LT+S
///
///           MRO-to-sub-observer vector in
///           MRO HIRISE look direction frame
///             X-component             (km) =           0.286933229
///             Y-component             (km) =          -0.260425939
///             Z-component             (km) =         253.816326385
///           Sub-observer point radius (km) =        3388.299078378
///           Planetocentric latitude  (deg) =         -38.799836378
///           Planetocentric longitude (deg) =        -114.995297227
///           Observer altitude         (km) =         253.816622175
///
///        Intercept comparison error (km) =           0.000002144
///
///        Aberration correction = CN+S
///
///           MRO-to-sub-observer vector in
///           MRO HIRISE look direction frame
///             X-component             (km) =           0.286933107
///             Y-component             (km) =          -0.260426683
///             Z-component             (km) =         253.816315915
///           Sub-observer point radius (km) =        3388.299078376
///           Planetocentric latitude  (deg) =         -38.799836382
///           Planetocentric longitude (deg) =        -114.995297449
///           Observer altitude         (km) =         253.816611705
///
///        Intercept comparison error (km) =           0.000000001
///
///     Sub-observer point computation method = DSK/Unprioritized/Nadir
///
///        Aberration correction = LT+S
///
///           MRO-to-sub-observer vector in
///           MRO HIRISE look direction frame
///             X-component             (km) =           0.282372596
///             Y-component             (km) =          -0.256289313
///             Z-component             (km) =         249.784871247
///           Sub-observer point radius (km) =        3392.330239436
///           Planetocentric latitude  (deg) =         -38.800230156
///           Planetocentric longitude (deg) =        -114.995297338
///           Observer altitude         (km) =         249.785162334
///
///        Intercept comparison error (km) =           0.000002412
///
///        Aberration correction = CN+S
///
///           MRO-to-sub-observer vector in
///           MRO HIRISE look direction frame
///             X-component             (km) =           0.282372464
///             Y-component             (km) =          -0.256290075
///             Z-component             (km) =         249.784860121
///           Sub-observer point radius (km) =        3392.330239564
///           Planetocentric latitude  (deg) =         -38.800230162
///           Planetocentric longitude (deg) =        -114.995297569
///           Observer altitude         (km) =         249.785151209
///
///        Intercept comparison error (km) =           0.000000001
/// ```
///
/// # Author and Institution
///
/// ```text
///  N.J. Bachman       (JPL)
///  J. Diaz del Rio    (ODC Space)
///  S.C. Krening       (JPL)
///  B.V. Semenov       (JPL)
///  E.D. Wright        (JPL)
/// ```
///
/// # Version
///
/// ```text
/// -    SPICELIB Version 2.1.0, 01-NOV-2021 (JDR) (EDW) (NJB)
///
///         Bug fix: PRVCOR is no longer set to blank before
///         ABCORR is parsed.
///
///         Body radii accessed from kernel pool using ZZGFTREB.
///
///         Edited the header to comply with NAIF standard.
///         Changed code examples' output to comply with maximum
///         line length for header comments.
///
///         Bug fix: TRGEPC is now initialized prior to first use.
///         Previously the lack of initialization could cause this routine
///         to fail to find DSK data within the time bounds of a DSK
///         segment.
///
/// -    SPICELIB Version 2.0.0, 04-APR-2017 (NJB)
///
///         Added FAILED tests.
///
///         01-JUL-2016 (NJB)
///
///         Now uses surface mapping tracking capability.
///         Updated header. Changed aberration correction
///         in example 1 to CN+S.
///
///         09-FEB-2015 (NJB)
///
///         Updated code to support use of surface list.
///         Updated header to document DSK capabilities.
///         Added check for invalid sub-point type.
///
///         24-DEC-2014 (NJB)
///
///         Updated to support surfaces represented by DSK data.
///
///         Bug fix: set initial value of PRVMTH to a valid
///         value.
///
/// -    SPICELIB Version 1.3.0, 31-MAR-2014 (BVS)
///
///         Updated to save the input body names and ZZBODTRN state
///         counters and to do name-ID conversions only if the counters
///         have changed.
///
///         Updated to save the input frame name and POOL state counter
///         and to do frame name-ID conversion only if the counter has
///         changed.
///
///         Updated to call LJUCRS instead of CMPRSS/UCASE.
///
/// -    SPICELIB Version 1.2.0, 02-APR-2012 (NJB) (SCK)
///
///         Bug fix: FIRST is now set to .FALSE. at the completion
///         of a successful initialization pass. This does not affect
///         the routine's outputs but improves efficiency.
///
///         References to the new PXFRM2 routine were added, which changed
///         the Detailed Output section and the second example.
///
///         Upgrade: this routine now uses ZZVALCOR rather than
///         ZZPRSCOR, simplifying the implementation.
///
/// -    SPICELIB Version 1.1.0, 18-MAY-2010 (NJB)
///
///         Bug fix: calls to FAILED() have been added after
///         SPK calls, target radius lookup, near point
///         and surface intercept computations.
///
/// -    SPICELIB Version 1.0.1, 06-FEB-2009 (NJB)
///
///         Typo correction: changed FIXFRM to FIXREF in header
///         documentation. Meta-kernel name suffix was changed to
///         ".tm" in header code example.
///
/// -    SPICELIB Version 1.0.0, 02-MAR-2008 (NJB)
/// ```
pub fn subpnt(
    ctx: &mut SpiceContext,
    method: &str,
    target: &str,
    et: f64,
    fixref: &str,
    abcorr: &str,
    obsrvr: &str,
    spoint: &mut [f64; 3],
    trgepc: &mut f64,
    srfvec: &mut [f64; 3],
) -> crate::Result<()> {
    SUBPNT(
        method.as_bytes(),
        target.as_bytes(),
        et,
        fixref.as_bytes(),
        abcorr.as_bytes(),
        obsrvr.as_bytes(),
        spoint,
        trgepc,
        srfvec,
        ctx.raw_context(),
    )?;
    ctx.handle_errors()?;
    Ok(())
}

//$Procedure SUBPNT ( Sub-observer point )
pub fn SUBPNT(
    METHOD: &[u8],
    TARGET: &[u8],
    ET: f64,
    FIXREF: &[u8],
    ABCORR: &[u8],
    OBSRVR: &[u8],
    SPOINT: &mut [f64],
    TRGEPC: &mut f64,
    SRFVEC: &mut [f64],
    ctx: &mut Context,
) -> f2rust_std::Result<()> {
    let save = ctx.get_vars::<SaveVars>();
    let save = &mut *save.borrow_mut();

    let mut SPOINT = DummyArrayMut::new(SPOINT, 1..=3);
    let mut SRFVEC = DummyArrayMut::new(SRFVEC, 1..=3);
    let mut PNTDEF = [b' '; CVTLEN as usize];
    let mut SHPSTR = [b' '; SHPLEN as usize];
    let mut TRMSTR = [b' '; TMTLEN as usize];
    let mut ALT: f64 = 0.0;
    let mut CORPOS = StackArray::<f64, 3>::new(1..=3);
    let mut CORVJ2 = StackArray::<f64, 3>::new(1..=3);
    let mut DVEC = StackArray::<f64, 3>::new(1..=3);
    let mut ETDIFF: f64 = 0.0;
    let mut J2POS = StackArray::<f64, 3>::new(1..=3);
    let mut LT: f64 = 0.0;
    let mut LTDIFF: f64 = 0.0;
    let mut OBSPOS = StackArray::<f64, 3>::new(1..=3);
    let mut PREVET: f64 = 0.0;
    let mut PREVLT: f64 = 0.0;
    let mut RADII = StackArray::<f64, 3>::new(1..=3);
    let mut RANGE: f64 = 0.0;
    let mut S: f64 = 0.0;
    let mut SSBOST = StackArray::<f64, 6>::new(1..=6);
    let mut SSBTST = StackArray::<f64, 6>::new(1..=6);
    let mut STLOFF = StackArray::<f64, 3>::new(1..=3);
    let mut SUBVEC = StackArray::<f64, 3>::new(1..=3);
    let mut SUBVJ2 = StackArray::<f64, 3>::new(1..=3);
    let mut TPOS = StackArray::<f64, 3>::new(1..=3);
    let mut VTEMP = StackArray::<f64, 3>::new(1..=3);
    let mut XFORM = StackArray2D::<f64, 9>::new(1..=3, 1..=3);
    let mut FIXCID: i32 = 0;
    let mut FIXCLS: i32 = 0;
    let mut FIXCTR: i32 = 0;
    let mut FIXFID: i32 = 0;
    let mut I: i32 = 0;
    let mut NITR: i32 = 0;
    let mut OBSCDE: i32 = 0;
    let mut TRGCDE: i32 = 0;
    let mut ATTBLK = StackArray::<bool, 15>::new(1..=NABCOR);
    let mut FND: bool = false;
    let mut SURFUP: bool = false;

    //
    // SPICELIB functions
    //

    //
    // Local parameters
    //

    //
    // This value will become system-dependent when systems
    // using 128-bit d.p. numbers are supported by SPICELIB.
    // CNVLIM, when added to 1.0D0, should yield 1.0D0.
    //

    //
    // Saved body name length.
    //

    //
    // Saved frame name length.
    //

    //
    // Local variables
    //

    //
    // Saved name/ID item declarations.
    //

    //
    // Saved frame name/ID item declarations.
    //

    //
    // Saved surface name/ID item declarations.
    //

    //
    // Saved variables
    //

    //
    // Saved name/ID items.
    //

    //
    // Saved frame name/ID items.
    //

    //
    // Saved surface name/ID items.
    //

    //
    // Initial values
    //

    //
    // Standard SPICE error handling.
    //
    if RETURN(ctx) {
        return Ok(());
    }

    CHKIN(RNAME, ctx)?;

    //
    // Counter initialization is done separately.
    //
    if save.FIRST {
        //
        // Initialize counters.
        //
        ZZCTRUIN(save.SVCTR1.as_slice_mut(), ctx);
        ZZCTRUIN(save.SVCTR2.as_slice_mut(), ctx);
        ZZCTRUIN(save.SVCTR3.as_slice_mut(), ctx);
    }

    if (save.FIRST || fstr::ne(ABCORR, &save.PRVCOR)) {
        //
        // The aberration correction flag differs from the value it
        // had on the previous call, if any. Analyze the new flag.
        //
        ZZVALCOR(ABCORR, ATTBLK.as_slice_mut(), ctx)?;

        if FAILED(ctx) {
            CHKOUT(RNAME, ctx)?;
            return Ok(());
        }

        //
        // Set logical flags indicating the attributes of the requested
        // correction:
        //
        //    XMIT is .TRUE. when the correction is for transmitted
        //    radiation.
        //
        //    USELT is .TRUE. when any type of light time correction
        //    (normal or converged Newtonian) is specified.
        //
        //    USECN indicates converged Newtonian light time correction.
        //
        //    USESTL indicates stellar aberration corrections.
        //
        //
        // The above definitions are consistent with those used by
        // ZZVALCOR.
        //
        save.XMIT = ATTBLK[XMTIDX];
        save.USELT = ATTBLK[LTIDX];
        save.USECN = ATTBLK[CNVIDX];
        save.USESTL = ATTBLK[STLIDX];

        //
        // The aberration correction flag is recognized; save it.
        //
        fstr::assign(&mut save.PRVCOR, ABCORR);
    }

    //
    // Obtain integer codes for the target and observer.
    //
    ZZBODS2C(
        save.SVCTR1.as_slice_mut(),
        &mut save.SVTARG,
        &mut save.SVTCDE,
        &mut save.SVFND1,
        TARGET,
        &mut TRGCDE,
        &mut FND,
        ctx,
    )?;

    if !FND {
        SETMSG(b"The target, \'#\', 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, or that you failed to load a kernel containing a name-ID mapping for this body.", ctx);
        ERRCH(b"#", TARGET, ctx);
        SIGERR(b"SPICE(IDCODENOTFOUND)", ctx)?;
        CHKOUT(RNAME, ctx)?;
        return Ok(());
    }

    ZZBODS2C(
        save.SVCTR2.as_slice_mut(),
        &mut save.SVOBSR,
        &mut save.SVOBSC,
        &mut save.SVFND2,
        OBSRVR,
        &mut OBSCDE,
        &mut FND,
        ctx,
    )?;

    if !FND {
        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, or that you failed to load a kernel containing a name-ID mapping for this body.", ctx);
        ERRCH(b"#", OBSRVR, ctx);
        SIGERR(b"SPICE(IDCODENOTFOUND)", ctx)?;
        CHKOUT(RNAME, ctx)?;
        return Ok(());
    }

    //
    // Check the input body codes.  If they are equal, signal
    // an error.
    //
    if (OBSCDE == TRGCDE) {
        SETMSG(b"In computing the sub-observer point, the observing body and target body are the same. Both are #.", ctx);
        ERRCH(b"#", OBSRVR, ctx);
        SIGERR(b"SPICE(BODIESNOTDISTINCT)", ctx)?;
        CHKOUT(RNAME, ctx)?;
        return Ok(());
    }

    //
    // Determine the attributes of the frame designated by FIXREF.
    //
    ZZNAMFRM(
        save.SVCTR3.as_slice_mut(),
        &mut save.SVFREF,
        &mut save.SVREFC,
        FIXREF,
        &mut FIXFID,
        ctx,
    )?;

    FRINFO(FIXFID, &mut FIXCTR, &mut FIXCLS, &mut FIXCID, &mut FND, ctx)?;

    if FAILED(ctx) {
        CHKOUT(RNAME, ctx)?;
        return Ok(());
    }

    if !FND {
        SETMSG(b"Reference frame # is not recognized by the SPICE frame subsystem. Possibly a required frame definition kernel has not been loaded.", ctx);
        ERRCH(b"#", FIXREF, ctx);
        SIGERR(b"SPICE(NOFRAME)", ctx)?;
        CHKOUT(RNAME, ctx)?;
        return Ok(());
    }

    //
    // Make sure that FIXREF is centered at the target body's center.
    //
    if (FIXCTR != TRGCDE) {
        SETMSG(b"Reference frame # is not centered at the the target body #. The ID code of the frame center is #.", ctx);
        ERRCH(b"#", FIXREF, ctx);
        ERRCH(b"#", TARGET, ctx);
        ERRINT(b"#", FIXCTR, ctx);
        SIGERR(b"SPICE(INVALIDFRAME)", ctx)?;
        CHKOUT(RNAME, ctx)?;
        return Ok(());
    }

    //
    // Check whether the surface name/ID mapping has been updated.
    //
    ZZSRFTRK(save.SVCTR4.as_slice_mut(), &mut SURFUP, ctx)?;

    //
    // If necessary, parse the method specification. PRVMTH records the
    // last valid value of METHOD; PRI, NEAR, SHAPE, NSURF, and SRFLST
    // are the corresponding saved variables.
    //
    if ((save.FIRST || SURFUP) || fstr::ne(METHOD, &save.PRVMTH)) {
        //
        // Make sure parsed values from METHOD can't be reused before
        // we've checked them.
        //
        fstr::assign(&mut save.PRVMTH, b" ");

        //
        // Parse the method string. If the string is valid, the
        // outputs SHAPE and SUBTYP will always be be set. However,
        // SUBTYP is not used in this routine.
        //
        // For DSK shapes, the surface list array and count will be set
        // if the method string contains a surface list.
        //
        ZZPRSMET(
            TRGCDE,
            METHOD,
            MAXSRF,
            &mut SHPSTR,
            &mut save.SUBTYP,
            &mut save.PRI,
            &mut save.NSURF,
            save.SRFLST.as_slice_mut(),
            &mut PNTDEF,
            &mut TRMSTR,
            ctx,
        )?;

        if FAILED(ctx) {
            CHKOUT(RNAME, ctx)?;
            return Ok(());
        }

        if fstr::eq(&save.SUBTYP, b" ") {
            SETMSG(
                b"Sub-observer point type was invalid or was not found in the method string #.",
                ctx,
            );
            ERRCH(b"#", METHOD, ctx);
            SIGERR(b"SPICE(INVALIDSUBTYPE)", ctx)?;
            CHKOUT(RNAME, ctx)?;
            return Ok(());
        }

        if EQSTR(&SHPSTR, b"ELLIPSOID") {
            save.SHAPE = ELLSHP;
        } else if EQSTR(&SHPSTR, b"DSK") {
            save.SHAPE = DSKSHP;
        } else {
            //
            // This is a backstop check.
            //
            SETMSG(b"Returned shape value from method string was <#>.", ctx);
            ERRCH(b"#", &SHPSTR, ctx);
            SIGERR(b"SPICE(BUG)", ctx)?;
            CHKOUT(RNAME, ctx)?;
            return Ok(());
        }

        if (save.SHAPE == ELLSHP) {
            //
            // Allow both "near point" and "nadir" expressions the
            // ellipsoid case, since in these case, these are equivalent.
            //
            save.NEAR = (EQSTR(&save.SUBTYP, b"NEAR POINT") || EQSTR(&save.SUBTYP, b"NADIR"));
        } else {
            //
            // "near point" is not supported for DSKs.
            //
            save.NEAR = EQSTR(&save.SUBTYP, b"NADIR");
        }

        if !save.NEAR {
            if !EQSTR(&save.SUBTYP, b"INTERCEPT") {
                SETMSG(
                    b"Invalid sub-observer point type <#> was found in the method string #.",
                    ctx,
                );
                ERRCH(b"#", &save.SUBTYP, ctx);
                ERRCH(b"#", METHOD, ctx);
                SIGERR(b"SPICE(INVALIDSUBTYPE)", ctx)?;
                CHKOUT(RNAME, ctx)?;
                return Ok(());
            }
        }

        //
        // Save the current value of METHOD.
        //
        fstr::assign(&mut save.PRVMTH, METHOD);
    }

    //
    // At this point, the first pass actions were successful.
    //
    save.FIRST = false;

    if (save.SHAPE == DSKSHP) {
        //
        // This is the DSK case.
        //
        // Initialize the intercept algorithm to use a DSK
        // model for the surface of the target body.
        //
        ZZSUDSKI(TRGCDE, save.NSURF, save.SRFLST.as_slice(), FIXFID, ctx)?;
    } else if (save.SHAPE != ELLSHP) {
        SETMSG(b"Computation method argument was <#>; this string must specify a supported shape model and computation type. See the description of METHOD in the header of SUBPNT for details.", ctx);
        ERRCH(b"#", METHOD, ctx);
        SIGERR(b"SPICE(INVALIDMETHOD)", ctx)?;
        CHKOUT(RNAME, ctx)?;
        return Ok(());
    }

    if FAILED(ctx) {
        CHKOUT(RNAME, ctx)?;
        return Ok(());
    }

    //
    // Get the sign S prefixing LT in the expression for TRGEPC.
    // When light time correction is not used, setting S = 0
    // allows us to seamlessly set TRGEPC equal to ET.
    //
    if save.USELT {
        if save.XMIT {
            S = 1.0;
        } else {
            S = -1.0;
        }
    } else {
        S = 0.0;
    }

    //
    // Determine the position of the observer in the target body-fixed
    // frame. This is a first estimate.
    //
    //     -  Call SPKEZP to compute the position of the target body as
    //        seen from the observing body and the light time (LT)
    //        between them. We request that the coordinates of POS be
    //        returned relative to the body fixed reference frame
    //        associated with the target body, using aberration
    //        corrections specified by the input argument ABCORR.
    //
    //     -  Call VMINUS to negate the direction of the vector (OBSPOS)
    //        so it will be the position of the observer as seen from
    //        the target body in target body fixed coordinates.
    //
    //        Note that this result is not the same as the result of
    //        calling SPKEZP with the target and observer switched. We
    //        computed the vector FROM the observer TO the target in
    //        order to get the proper light time and stellar aberration
    //        corrections (if requested). Now we need the inverse of
    //        that corrected vector in order to compute the sub-observer
    //        point.
    //
    SPKEZP(
        TRGCDE,
        ET,
        FIXREF,
        ABCORR,
        OBSCDE,
        TPOS.as_slice_mut(),
        &mut LT,
        ctx,
    )?;

    if FAILED(ctx) {
        CHKOUT(RNAME, ctx)?;
        return Ok(());
    }

    //
    // Negate the target's position to obtain the position of the
    // observer relative to the target.
    //
    VMINUS(TPOS.as_slice(), OBSPOS.as_slice_mut());

    //
    // Make a first estimate of the target epoch.
    //
    *TRGEPC = (ET + (S * LT));

    //
    // Find the sub-observer point given the target epoch,
    // observer-target position, and target body orientation we've
    // already computed. If we're not using light time correction, this
    // is all we need do. Otherwise, our result will give us an initial
    // estimate of the target epoch, which we'll then improve.
    //

    //
    // Get the radii of the target body from the kernel pool.
    //
    ZZGFTREB(TRGCDE, RADII.as_slice_mut(), ctx)?;

    if FAILED(ctx) {
        CHKOUT(RNAME, ctx)?;
        return Ok(());
    }

    RANGE = VNORM(OBSPOS.as_slice());

    if (RANGE == 0.0) {
        //
        // We've already ensured that observer and target are
        // distinct, so this should be a very unusual occurrence.
        //
        SETMSG(
            b"Observer-target distance is zero. Observer is #; target is #.",
            ctx,
        );
        ERRCH(b"#", OBSRVR, ctx);
        ERRCH(b"#", TARGET, ctx);
        SIGERR(b"SPICE(NOSEPARATION)", ctx)?;
        CHKOUT(RNAME, ctx)?;
        return Ok(());
    }

    //
    // Make a first estimate of the sub-observer point. The algorithm
    // we use depends on the sub-observer point definition.
    //
    if save.NEAR {
        //
        // Locate the nearest point to the observer on the target
        // body's reference ellipsoid.
        //
        NEARPT(
            OBSPOS.as_slice(),
            RADII[1],
            RADII[2],
            RADII[3],
            SPOINT.as_slice_mut(),
            &mut ALT,
            ctx,
        )?;

        if FAILED(ctx) {
            CHKOUT(RNAME, ctx)?;
            return Ok(());
        }

        //
        // If the target is an ellipsoid, the NEARPT call above does
        // the trick. For DSKs, we define a ray emanating from the
        // observer and passing through the near point on the
        // reference ellipsoid. The closest ray-DSK surface intercept
        // to the observer is the initial estimate of the sub-point.
        //
        if (save.SHAPE == DSKSHP) {
            //
            // Generate the ray direction; find the DSK intercept.
            //
            VSUB(SPOINT.as_slice(), OBSPOS.as_slice(), DVEC.as_slice_mut());

            ZZSBFXR(
                TRGCDE,
                save.NSURF,
                save.SRFLST.as_slice(),
                *TRGEPC,
                FIXFID,
                OBSPOS.as_slice(),
                DVEC.as_slice(),
                SPOINT.as_slice_mut(),
                &mut FND,
                ctx,
            )?;

            if FAILED(ctx) {
                CHKOUT(RNAME, ctx)?;
                return Ok(());
            }

            if !FND {
                SETMSG(b"No sub-observer point was found on the surface defined by DSK data.Observer is #; target is #. This problem can occur for bodies having shapes not well modeled by ellipsoids. Consider using the \"Intercept: DSK\" computation method.", ctx);
                ERRCH(b"#", OBSRVR, ctx);
                ERRCH(b"#", TARGET, ctx);
                SIGERR(b"SPICE(SUBPOINTNOTFOUND)", ctx)?;
                CHKOUT(RNAME, ctx)?;
                return Ok(());
            }

            //
            // Re-compute the altitude using the intercept on the DSK
            // surface.
            //
            VSUB(SPOINT.as_slice(), OBSPOS.as_slice(), SRFVEC.as_slice_mut());

            ALT = VNORM(SRFVEC.as_slice());
        }
    } else {
        //
        // This is the case for the "intercept" sub-point definition.
        //
        if (save.SHAPE == ELLSHP) {
            //
            // Locate the surface intercept of the ray from the
            // observer to the target center.
            //
            SURFPT(
                OBSPOS.as_slice(),
                TPOS.as_slice(),
                RADII[1],
                RADII[2],
                RADII[3],
                SPOINT.as_slice_mut(),
                &mut FND,
                ctx,
            )?;

            if FAILED(ctx) {
                CHKOUT(RNAME, ctx)?;
                return Ok(());
            }

            if !FND {
                //
                // If there's no intercept, we have a numerical problem.
                //
                SETMSG(b"No intercept of observer-target ray was found.", ctx);
                SIGERR(b"SPICE(DEGENERATECASE)", ctx)?;
                CHKOUT(RNAME, ctx)?;
                return Ok(());
            }

            ALT = VDIST(OBSPOS.as_slice(), SPOINT.as_slice());
        } else {
            //
            // Generate the ray direction; find the DSK intercept.
            //
            VMINUS(OBSPOS.as_slice(), DVEC.as_slice_mut());

            ZZSBFXR(
                TRGCDE,
                save.NSURF,
                save.SRFLST.as_slice(),
                *TRGEPC,
                FIXFID,
                OBSPOS.as_slice(),
                DVEC.as_slice(),
                SPOINT.as_slice_mut(),
                &mut FND,
                ctx,
            )?;

            if FAILED(ctx) {
                CHKOUT(RNAME, ctx)?;
                return Ok(());
            }

            if !FND {
                SETMSG(b"No sub-observer point was found on the surface defined by DSK data.Observer is #; target is #. This problem can occur for a body having an irregular shape such that the origin of the body-fixed reference frame is outside of the body. A torus is an example of such a shape.", ctx);
                ERRCH(b"#", OBSRVR, ctx);
                ERRCH(b"#", TARGET, ctx);
                SIGERR(b"SPICE(SUBPOINTNOTFOUND)", ctx)?;
                CHKOUT(RNAME, ctx)?;
                return Ok(());
            }
            //
            // Re-compute the altitude using the intercept on the DSK
            // surface.
            //
            VSUB(SPOINT.as_slice(), OBSPOS.as_slice(), SRFVEC.as_slice_mut());

            ALT = VNORM(SRFVEC.as_slice());
        }
    }

    if FAILED(ctx) {
        CHKOUT(RNAME, ctx)?;
        return Ok(());
    }

    //
    // If we're not using light time and stellar aberration
    // corrections, we're almost done now. Note that we need only
    // check for use of light time corrections, because use of
    // stellar aberration corrections alone has been prevented by an
    // earlier check.

    if !save.USELT {
        *TRGEPC = ET;
        //
        // The TRGEPC value we'll return is just the input time.
        // The previous call to SPKEZP call yielded
        // the vector OBSPOS. SPOINT was set immediately above. The
        // only output left to compute is SRFVEC.
        //
        VSUB(SPOINT.as_slice(), OBSPOS.as_slice(), SRFVEC.as_slice_mut());

        CHKOUT(RNAME, ctx)?;
        return Ok(());
    }

    //
    // Compute the one-way light time and target epoch based on our
    // first computation of SPOINT. The coefficient S has been
    // set to give us the correct answer for each aberration
    // correction case.
    //
    LT = (ALT / CLIGHT());
    *TRGEPC = (ET + (S * LT));

    //
    // We'll now make an improved sub-observer point estimate using
    // the previous estimate of the sub-observer point. The number of
    // iterations depends on the light time correction type.

    if save.USECN {
        NITR = MAXITR;
    } else {
        NITR = 1;
    }

    //
    // Get the J2000-relative state of the observer relative to
    // the solar system barycenter at ET.
    //
    SPKSSB(OBSCDE, ET, b"J2000", SSBOST.as_slice_mut(), ctx)?;

    if FAILED(ctx) {
        CHKOUT(RNAME, ctx)?;
        return Ok(());
    }

    //
    // Initialize the variables required to evaluate the
    // loop termination condition.
    //
    I = 0;
    LTDIFF = 1.0;
    ETDIFF = 1.0;
    PREVLT = LT;
    PREVET = *TRGEPC;

    while (((I < NITR) && (LTDIFF > (CNVLIM * f64::abs(LT)))) && (ETDIFF > 0.0)) {
        //
        // Get the J2000-relative state of the target relative to
        // the solar system barycenter at the target epoch.
        //
        SPKSSB(TRGCDE, *TRGEPC, b"J2000", SSBTST.as_slice_mut(), ctx)?;

        if FAILED(ctx) {
            CHKOUT(RNAME, ctx)?;
            return Ok(());
        }

        //
        // Find the position of the observer relative to the target.
        // Convert this vector from the J2000 frame to the target
        // frame at TRGEPC.
        //
        VSUB(SSBOST.as_slice(), SSBTST.as_slice(), J2POS.as_slice_mut());
        PXFORM(b"J2000", FIXREF, *TRGEPC, XFORM.as_slice_mut(), ctx)?;

        if FAILED(ctx) {
            CHKOUT(RNAME, ctx)?;
            return Ok(());
        }

        MXV(XFORM.as_slice(), J2POS.as_slice(), OBSPOS.as_slice_mut());

        //
        // If we're using stellar aberration corrections, adjust the
        // observer position to account for the stellar aberration
        // correction applicable to SPOINT.
        //
        if save.USESTL {
            //
            // We want to apply the stellar aberration correction that
            // applies to our current estimate of the sub-observer point
            // location, NOT the correction for the target body's center.
            // In most cases the two corrections will be similar, but they
            // might not be---consider the case of a highly prolate target
            // body where the observer is close to one "end" of the body.
            //
            // Find the vector from the observer to the estimated
            // sub-observer point. Find the stellar aberration offset
            // STLOFF for this vector. Note that all vectors are expressed
            // relative to the target body-fixed frame at TRGEPC. We must
            // perform our corrections in an inertial frame.
            //
            VSUB(SPOINT.as_slice(), OBSPOS.as_slice(), SUBVEC.as_slice_mut());

            MTXV(XFORM.as_slice(), SUBVEC.as_slice(), SUBVJ2.as_slice_mut());

            if save.XMIT {
                STLABX(
                    SUBVJ2.as_slice(),
                    SSBOST.subarray(4),
                    CORVJ2.as_slice_mut(),
                    ctx,
                )?;
            } else {
                STELAB(
                    SUBVJ2.as_slice(),
                    SSBOST.subarray(4),
                    CORVJ2.as_slice_mut(),
                    ctx,
                )?;
            }

            MXV(XFORM.as_slice(), CORVJ2.as_slice(), CORPOS.as_slice_mut());
            VSUB(CORPOS.as_slice(), SUBVEC.as_slice(), STLOFF.as_slice_mut());

            //
            // In principle, we want to shift the target body position
            // relative to the solar system barycenter by STLOFF, but we
            // can skip this step and just re-compute the observer's
            // location relative to the target body's center by
            // subtracting off STLOFF.
            //
            VSUB(OBSPOS.as_slice(), STLOFF.as_slice(), VTEMP.as_slice_mut());
            VEQU(VTEMP.as_slice(), OBSPOS.as_slice_mut());
        }

        //
        // Find the sub-observer point using the current estimated
        // geometry.
        //
        if save.NEAR {
            //
            // Locate the nearest point to the observer on the target's
            // reference ellipsoid.
            //
            NEARPT(
                OBSPOS.as_slice(),
                RADII[1],
                RADII[2],
                RADII[3],
                SPOINT.as_slice_mut(),
                &mut ALT,
                ctx,
            )?;

            if FAILED(ctx) {
                CHKOUT(RNAME, ctx)?;
                return Ok(());
            }

            //
            // If the target is an ellipsoid, the NEARPT call above
            // does the trick. For DSKs, we define a ray emanating from
            // the observer and passing through the near point on the
            // reference ellipsoid. The closest ray-DSK surface
            // intercept to the observer is the initial estimate of the
            // sub-point.

            if (save.SHAPE == DSKSHP) {
                //
                // Generate the ray direction; find the DSK intercept.
                //
                VSUB(SPOINT.as_slice(), OBSPOS.as_slice(), DVEC.as_slice_mut());

                ZZSBFXR(
                    TRGCDE,
                    save.NSURF,
                    save.SRFLST.as_slice(),
                    *TRGEPC,
                    FIXFID,
                    OBSPOS.as_slice(),
                    DVEC.as_slice(),
                    SPOINT.as_slice_mut(),
                    &mut FND,
                    ctx,
                )?;

                if FAILED(ctx) {
                    CHKOUT(RNAME, ctx)?;
                    return Ok(());
                }

                if !FND {
                    SETMSG(b"No sub-observer point was found on the surface defined by DSK data.Observer is #; target is #. This problem can occur for bodies having shapes not well modeled by ellipsoids. Consider using the \"Intercept: DSK\" computation method.", ctx);
                    ERRCH(b"#", OBSRVR, ctx);
                    ERRCH(b"#", TARGET, ctx);
                    SIGERR(b"SPICE(SUBPOINTNOTFOUND)", ctx)?;
                    CHKOUT(RNAME, ctx)?;
                    return Ok(());
                }

                //
                // Re-compute the altitude using the intercept on the
                // DSK surface.
                //
                VSUB(SPOINT.as_slice(), OBSPOS.as_slice(), SRFVEC.as_slice_mut());

                ALT = VNORM(SRFVEC.as_slice());
            }
        } else {
            //
            // This is the "intercept" case.
            //
            // Generate the ray direction.
            //
            VMINUS(OBSPOS.as_slice(), DVEC.as_slice_mut());
            //
            // Locate the surface intercept of the ray from the
            // observer to the target center.
            //
            if (save.SHAPE == ELLSHP) {
                SURFPT(
                    OBSPOS.as_slice(),
                    DVEC.as_slice(),
                    RADII[1],
                    RADII[2],
                    RADII[3],
                    SPOINT.as_slice_mut(),
                    &mut FND,
                    ctx,
                )?;

                if FAILED(ctx) {
                    CHKOUT(RNAME, ctx)?;
                    return Ok(());
                }

                if !FND {
                    //
                    // If there's no intercept, we have a numerical
                    // problem.
                    //
                    SETMSG(b"No intercept of observer-target ray was found.", ctx);
                    SIGERR(b"SPICE(DEGENERATECASE)", ctx)?;
                    CHKOUT(RNAME, ctx)?;
                    return Ok(());
                }

                ALT = VDIST(OBSPOS.as_slice(), SPOINT.as_slice());
            } else {
                //
                // Find the ray-DSK surface intercept.
                //
                ZZSBFXR(
                    TRGCDE,
                    save.NSURF,
                    save.SRFLST.as_slice(),
                    *TRGEPC,
                    FIXFID,
                    OBSPOS.as_slice(),
                    DVEC.as_slice(),
                    SPOINT.as_slice_mut(),
                    &mut FND,
                    ctx,
                )?;

                if FAILED(ctx) {
                    CHKOUT(RNAME, ctx)?;
                    return Ok(());
                }

                if !FND {
                    SETMSG(b"No sub-observer point was found on the surface defined by DSK data.Observer is #; target is #. This problem can occur for a body having an irregular shape such that the origin of the body-fixed reference frame is outside of the body. A torus is an example of such a shape.", ctx);
                    ERRCH(b"#", OBSRVR, ctx);
                    ERRCH(b"#", TARGET, ctx);
                    SIGERR(b"SPICE(SUBPOINTNOTFOUND)", ctx)?;
                    CHKOUT(RNAME, ctx)?;
                    return Ok(());
                }
                //
                // Compute the altitude using the intercept on the DSK
                // surface.
                //
                VSUB(SPOINT.as_slice(), OBSPOS.as_slice(), SRFVEC.as_slice_mut());

                ALT = VNORM(SRFVEC.as_slice());
            }
        }

        if FAILED(ctx) {
            CHKOUT(RNAME, ctx)?;
            return Ok(());
        }

        //
        // Compute a new light time estimate and new target epoch.
        //
        LT = (ALT / CLIGHT());
        *TRGEPC = (ET + (S * LT));

        //
        // At this point, we have new estimates of the sub-observer
        // point SPOINT, the observer altitude ALT, the target epoch
        // TRGEPC, and the position of the observer relative to the
        // target OBSPOS.
        //
        // We use the d.p. identity function TOUCHD to force the compiler
        // to create double precision arguments from the differences
        // LT-PREVLT and TRGEPC-PREVET. Some compilers will perform
        // extended-precision register arithmetic, which can prevent a
        // difference from rounding to zero. Simply storing the result of
        // the subtraction in a double precision variable doesn't solve
        // the problem, because that variable can be optimized out of
        // existence.
        //
        LTDIFF = f64::abs(TOUCHD((LT - PREVLT)));
        ETDIFF = f64::abs(TOUCHD((*TRGEPC - PREVET)));
        PREVLT = LT;
        PREVET = *TRGEPC;
        I = (I + 1);
    }

    //
    // SPOINT, TRGEPC, and OBSPOS have been set at this point. Compute
    // SRFVEC.
    //
    VSUB(SPOINT.as_slice(), OBSPOS.as_slice(), SRFVEC.as_slice_mut());

    CHKOUT(RNAME, ctx)?;
    Ok(())
}