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

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

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 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 KVNMLN: i32 = 32;
const KVLEN: i32 = 80;
const FRNMLN: i32 = 32;
const BDNMLN: i32 = 36;
const MAXCOF: i32 = 20;
const MXNFAC: i32 = 10;
const LBSEP: f64 = 0.001;
const QEXP: i32 = -27;
const KWBFRM: &[u8] = b"RELATIVE";
const KWSTYL: &[u8] = b"DEF_STYLE";
const KVPARM: &[u8] = b"PARAMETERIZED";
const KWFREZ: &[u8] = b"FREEZE_EPOCH";
const KWRSTA: &[u8] = b"ROTATION_STATE";
const KVROTG: &[u8] = b"ROTATING";
const KVINRT: &[u8] = b"INERTIAL";
const KWFFAM: &[u8] = b"FAMILY";
const KVMEQT: &[u8] = b"MEAN_EQUATOR_AND_EQUINOX_OF_DATE";
const KVMECL: &[u8] = b"MEAN_ECLIPTIC_AND_EQUINOX_OF_DATE";
const KVTEQT: &[u8] = b"TRUE_EQUATOR_AND_EQUINOX_OF_DATE";
const KV2VEC: &[u8] = b"TWO-VECTOR";
const KVEULR: &[u8] = b"EULER";
const KVPROD: &[u8] = b"PRODUCT";
const KWPRCM: &[u8] = b"PREC_MODEL";
const KWNUTM: &[u8] = b"NUT_MODEL";
const KWOBQM: &[u8] = b"OBLIQ_MODEL";
const KVM001: &[u8] = b"EARTH_IAU_1976";
const KVM002: &[u8] = b"EARTH_IAU_1980";
const KVM003: &[u8] = b"EARTH_IAU_1980";
const KWVAXI: &[u8] = b"AXIS";
const KVX: &[u8] = b"X";
const KVY: &[u8] = b"Y";
const KVZ: &[u8] = b"Z";
const KWPRI: &[u8] = b"PRI_";
const KWSEC: &[u8] = b"SEC_";
const KWVCDF: &[u8] = b"VECTOR_DEF";
const KVPOSV: &[u8] = b"OBSERVER_TARGET_POSITION";
const KVVELV: &[u8] = b"OBSERVER_TARGET_VELOCITY";
const KVNEAR: &[u8] = b"TARGET_NEAR_POINT";
const KVCONS: &[u8] = b"CONSTANT";
const KWVOBS: &[u8] = b"OBSERVER";
const KWVTRG: &[u8] = b"TARGET";
const KWVFRM: &[u8] = b"FRAME";
const KWVABC: &[u8] = b"ABCORR";
const KWVSPC: &[u8] = b"SPEC";
const KVRECC: &[u8] = b"RECTANGULAR";
const KVLATC: &[u8] = b"LATITUDINAL";
const KVRADC: &[u8] = b"RA/DEC";
const KWVECT: &[u8] = b"VECTOR";
const KWLAT: &[u8] = b"LATITUDE";
const KWLON: &[u8] = b"LONGITUDE";
const KWRA: &[u8] = b"RA";
const KWDEC: &[u8] = b"DEC";
const KWATOL: &[u8] = b"ANGLE_SEP_TOL";
const KWEPOC: &[u8] = b"EPOCH";
const KWEUAX: &[u8] = b"AXES";
const KWEAC1: &[u8] = b"ANGLE_1_COEFFS";
const KWEAC2: &[u8] = b"ANGLE_2_COEFFS";
const KWEAC3: &[u8] = b"ANGLE_3_COEFFS";
const KWFFRM: &[u8] = b"FROM_FRAMES";
const KWTFRM: &[u8] = b"TO_FRAMES";
const KWUNIT: &[u8] = b"UNITS";
const KVRADN: &[u8] = b"RADIANS";
const KVDEGR: &[u8] = b"DEGREES";
const RNAME: &[u8] = b"ZZDYNFRM";
const TIMLEN: i32 = 50;
const VNAMLN: i32 = 4;

struct SaveVars {
    AXES: ActualCharArray,
    ITMABC: ActualCharArray,
    ITMAXE: ActualCharArray,
    ITMCOF: ActualCharArray,
    ITMDEC: ActualCharArray,
    ITMFRM: ActualCharArray,
    ITMLAT: ActualCharArray,
    ITMLON: ActualCharArray,
    ITMOBS: ActualCharArray,
    ITMRA: ActualCharArray,
    ITMSEP: Vec<u8>,
    ITMSPC: ActualCharArray,
    ITMTRG: ActualCharArray,
    ITMUNT: ActualCharArray,
    ITMVDF: ActualCharArray,
    ITMVEC: ActualCharArray,
    VNAME: ActualCharArray,
    EARTH: i32,
    J2000: i32,
    FIRST: bool,
}

impl SaveInit for SaveVars {
    fn new() -> Self {
        let mut AXES = ActualCharArray::new(1, 1..=3);
        let mut ITMABC = ActualCharArray::new(KVNMLN, 1..=2);
        let mut ITMAXE = ActualCharArray::new(KVNMLN, 1..=2);
        let mut ITMCOF = ActualCharArray::new(KVNMLN, 1..=3);
        let mut ITMDEC = ActualCharArray::new(KVNMLN, 1..=2);
        let mut ITMFRM = ActualCharArray::new(KVNMLN, 1..=2);
        let mut ITMLAT = ActualCharArray::new(KVNMLN, 1..=2);
        let mut ITMLON = ActualCharArray::new(KVNMLN, 1..=2);
        let mut ITMOBS = ActualCharArray::new(KVNMLN, 1..=2);
        let mut ITMRA = ActualCharArray::new(KVNMLN, 1..=2);
        let mut ITMSEP = vec![b' '; KVNMLN as usize];
        let mut ITMSPC = ActualCharArray::new(KVNMLN, 1..=2);
        let mut ITMTRG = ActualCharArray::new(KVNMLN, 1..=2);
        let mut ITMUNT = ActualCharArray::new(KVNMLN, 1..=2);
        let mut ITMVDF = ActualCharArray::new(KVNMLN, 1..=2);
        let mut ITMVEC = ActualCharArray::new(KVNMLN, 1..=2);
        let mut VNAME = ActualCharArray::new(VNAMLN, 1..=2);
        let mut EARTH: i32 = 0;
        let mut J2000: i32 = 0;
        let mut FIRST: bool = false;

        {
            use f2rust_std::data::Val;

            let mut clist = [Val::C(KVX), Val::C(KVY), Val::C(KVZ)].into_iter();
            AXES.iter_mut()
                .for_each(|n| fstr::assign(n, clist.next().unwrap().into_str()));

            debug_assert!(clist.next().is_none(), "DATA not fully initialised");
        }
        FIRST = true;
        {
            use f2rust_std::data::Val;

            let mut clist = [Val::C(KWEAC1), Val::C(KWEAC2), Val::C(KWEAC3)].into_iter();
            ITMCOF
                .iter_mut()
                .for_each(|n| fstr::assign(n, clist.next().unwrap().into_str()));

            debug_assert!(clist.next().is_none(), "DATA not fully initialised");
        }
        fstr::assign(&mut ITMSEP, KWATOL);
        {
            use f2rust_std::data::Val;

            let mut clist = [Val::C(KWPRI), Val::C(KWSEC)].into_iter();
            VNAME
                .iter_mut()
                .for_each(|n| fstr::assign(n, clist.next().unwrap().into_str()));

            debug_assert!(clist.next().is_none(), "DATA not fully initialised");
        }

        Self {
            AXES,
            ITMABC,
            ITMAXE,
            ITMCOF,
            ITMDEC,
            ITMFRM,
            ITMLAT,
            ITMLON,
            ITMOBS,
            ITMRA,
            ITMSEP,
            ITMSPC,
            ITMTRG,
            ITMUNT,
            ITMVDF,
            ITMVEC,
            VNAME,
            EARTH,
            J2000,
            FIRST,
        }
    }
}

//$Procedure ZZDYNFRM ( Dynamic state transformation evaluation )
pub fn ZZDYNFRM(
    INFRAM: i32,
    CENTER: i32,
    ET: f64,
    XFORM: &mut [f64],
    BASFRM: &mut i32,
    ctx: &mut Context,
) -> f2rust_std::Result<()> {
    let save = ctx.get_vars::<SaveVars>();
    let save = &mut *save.borrow_mut();

    let mut XFORM = DummyArrayMut2D::new(XFORM, 1..=6, 1..=6);
    let mut ABCORR = [b' '; CORLEN as usize];
    let mut AXNAME = [b' '; KVLEN as usize];
    let mut BASNAM = [b' '; FRNMLN as usize];
    let mut CFRMNM = [b' '; FRNMLN as usize];
    let mut CTRNAM = [b' '; BDNMLN as usize];
    let mut CVCORR = [b' '; CORLEN as usize];
    let mut DYNSTL = [b' '; KVLEN as usize];
    let mut DYNFAM = [b' '; KVLEN as usize];
    let mut FFRAMS = ActualCharArray::new(FRNMLN, 1..=MXNFAC);
    let mut INNAME = [b' '; FRNMLN as usize];
    let mut NUTMOD = [b' '; KVLEN as usize];
    let mut OBLMOD = [b' '; KVLEN as usize];
    let mut PRCMOD = [b' '; KVLEN as usize];
    let mut ROTSTA = [b' '; KVLEN as usize];
    let mut SPEC = [b' '; KVLEN as usize];
    let mut TFRAMS = ActualCharArray::new(FRNMLN, 1..=MXNFAC);
    let mut TIMSTR = [b' '; TIMLEN as usize];
    let mut TMPFAM = [b' '; KVLEN as usize];
    let mut UNITS = [b' '; KVLEN as usize];
    let mut VECDEF = ActualCharArray::new(KVLEN, 1..=2);
    let mut VELFRM = [b' '; FRNMLN as usize];
    let mut ACC = StackArray::<f64, 3>::new(1..=3);
    let mut ANGLES = StackArray::<f64, 2>::new(1..=2);
    let mut COEFFS = StackArray2D::<f64, 60>::new(1..=MAXCOF, 1..=3);
    let mut CTRPOS = StackArray::<f64, 3>::new(1..=3);
    let mut DEC: f64 = 0.0;
    let mut DELTA: f64 = 0.0;
    let mut DIRVEC = StackArray::<f64, 3>::new(1..=3);
    let mut DMOB: f64 = 0.0;
    let mut EPOCH: f64 = 0.0;
    let mut EULANG = StackArray::<f64, 6>::new(1..=6);
    let mut FET: f64 = 0.0;
    let mut LAT: f64 = 0.0;
    let mut LON: f64 = 0.0;
    let mut LT: f64 = 0.0;
    let mut MINSEP: f64 = 0.0;
    let mut MOB: f64 = 0.0;
    let mut NUTXF = StackArray2D::<f64, 36>::new(1..=6, 1..=6);
    let mut OBLXF = StackArray2D::<f64, 36>::new(1..=6, 1..=6);
    let mut POLY = StackArray::<f64, 2>::new(0..=1);
    let mut PRECXF = StackArray2D::<f64, 36>::new(1..=6, 1..=6);
    let mut RA: f64 = 0.0;
    let mut RADII = StackArray::<f64, 3>::new(1..=3);
    let mut S2 = StackArray2D::<f64, 12>::new(1..=6, 1..=2);
    let mut SEP: f64 = 0.0;
    let mut STALT = StackArray::<f64, 2>::new(1..=2);
    let mut STEMP = StackArray::<f64, 6>::new(1..=6);
    let mut STNEAR = StackArray::<f64, 6>::new(1..=6);
    let mut STOBS = StackArray::<f64, 6>::new(1..=6);
    let mut TARRAY = StackArray::<f64, 3>::new(1..=3);
    let mut T0: f64 = 0.0;
    let mut VARRAY = StackArray2D::<f64, 9>::new(1..=3, 1..=3);
    let mut VET: f64 = 0.0;
    let mut VFLT: f64 = 0.0;
    let mut XF2000 = StackArray2D::<f64, 36>::new(1..=6, 1..=6);
    let mut XFINV = StackArray2D::<f64, 36>::new(1..=6, 1..=6);
    let mut XFTEMP = StackArray2D::<f64, 36>::new(1..=6, 1..=6);
    let mut XIPM = StackArray2D::<f64, 36>::new(1..=6, 1..=6);
    let mut XOUT = StackArray2D::<f64, 36>::new(1..=6, 1..=6);
    let mut AXIS = StackArray::<i32, 2>::new(1..=2);
    let mut CFRMID: i32 = 0;
    let mut CVOBS: i32 = 0;
    let mut DEGS = StackArray::<i32, 3>::new(1..=3);
    let mut FRCID: i32 = 0;
    let mut FRCLS: i32 = 0;
    let mut FRCTR: i32 = 0;
    let mut FRID: i32 = 0;
    let mut FROMID: i32 = 0;
    let mut IAXES = StackArray::<i32, 3>::new(1..=3);
    let mut J: i32 = 0;
    let mut M: i32 = 0;
    let mut N: i32 = 0;
    let mut OBS: i32 = 0;
    let mut TARG: i32 = 0;
    let mut TOID: i32 = 0;
    let mut CORBLK = StackArray::<bool, 15>::new(1..=NABCOR);
    let mut FND: bool = false;
    let mut FROZEN: bool = false;
    let mut INERT: bool = false;
    let mut MEANEC: bool = false;
    let mut MEANEQ: bool = false;
    let mut NEGATE: bool = false;
    let mut OFDATE: bool = false;
    let mut TRUEEQ: bool = false;

    //
    // SPICELIB functions
    //

    //
    // Local parameters
    //

    //
    // Local variables
    //

    //
    // Saved variables
    //

    //
    // Initial values
    //

    if RETURN(ctx) {
        return Ok(());
    }

    CHKIN(RNAME, ctx)?;

    if save.FIRST {
        //
        // Get the ID code for the J2000 frame.
        //
        IRFNUM(b"J2000", &mut save.J2000, ctx);

        //
        // Get the ID code for the earth (we needn't check the found
        // flag).
        //
        BODN2C(b"EARTH", &mut save.EARTH, &mut FND, ctx)?;

        //
        // Initialize "item" strings used to create kernel variable
        // names.
        //
        for I in 1..=2 {
            //
            // Vector axis:
            //
            fstr::assign(
                save.ITMAXE.get_mut(I),
                &fstr::concat(save.VNAME.get(I), KWVAXI),
            );
            //
            // Vector definition:
            //
            fstr::assign(
                save.ITMVDF.get_mut(I),
                &fstr::concat(save.VNAME.get(I), KWVCDF),
            );
            //
            // Vector aberration correction:
            //
            fstr::assign(
                save.ITMABC.get_mut(I),
                &fstr::concat(save.VNAME.get(I), KWVABC),
            );
            //
            // Vector frame:
            //
            fstr::assign(
                save.ITMFRM.get_mut(I),
                &fstr::concat(save.VNAME.get(I), KWVFRM),
            );
            //
            // Vector observer:
            //
            fstr::assign(
                save.ITMOBS.get_mut(I),
                &fstr::concat(save.VNAME.get(I), KWVOBS),
            );
            //
            // Vector target:
            //
            fstr::assign(
                save.ITMTRG.get_mut(I),
                &fstr::concat(save.VNAME.get(I), KWVTRG),
            );
            //
            // Vector longitude:
            //
            fstr::assign(
                save.ITMLON.get_mut(I),
                &fstr::concat(save.VNAME.get(I), KWLON),
            );
            //
            // Vector latitude:
            //
            fstr::assign(
                save.ITMLAT.get_mut(I),
                &fstr::concat(save.VNAME.get(I), KWLAT),
            );
            //
            // Vector right ascension:
            //
            fstr::assign(
                save.ITMRA.get_mut(I),
                &fstr::concat(save.VNAME.get(I), KWRA),
            );
            //
            // Vector declination:
            //
            fstr::assign(
                save.ITMDEC.get_mut(I),
                &fstr::concat(save.VNAME.get(I), KWDEC),
            );
            //
            // Vector units:
            //
            fstr::assign(
                save.ITMUNT.get_mut(I),
                &fstr::concat(save.VNAME.get(I), KWUNIT),
            );
            //
            // Constant vector coordinate specification:
            //
            fstr::assign(
                save.ITMSPC.get_mut(I),
                &fstr::concat(save.VNAME.get(I), KWVSPC),
            );
            //
            // Constant vector in Cartesian coordinates, literal value:
            //
            fstr::assign(
                save.ITMVEC.get_mut(I),
                &fstr::concat(save.VNAME.get(I), KWVECT),
            );
        }

        save.FIRST = false;
    }

    //
    // Initialize the output arguments.
    //
    CLEARD(36, XFORM.as_slice_mut());

    *BASFRM = 0;

    //
    // Initialize certain variables to ensure that we don't do
    // arithmetic operations using bogus, possibly large,
    // undefined values.
    //
    CLEARD(36, NUTXF.as_slice_mut());
    CLEARD(36, OBLXF.as_slice_mut());
    CLEARD(36, PRECXF.as_slice_mut());
    CLEARD(36, XF2000.as_slice_mut());
    CLEARD(36, XFINV.as_slice_mut());
    CLEARD(36, XIPM.as_slice_mut());

    MOB = 0.0;
    DMOB = 0.0;
    T0 = 0.0;
    FROZEN = false;

    //
    // Get the input frame name.
    //
    FRMNAM(INFRAM, &mut INNAME, ctx)?;

    //
    // We need the name of the base frame.
    //
    ZZDYNFID(&INNAME, INFRAM, KWBFRM, BASFRM, ctx)?;

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

    FRMNAM(*BASFRM, &mut BASNAM, ctx)?;

    //
    // The output frame code and name are set.
    //
    // Look up the dynamic frame definition style from the kernel pool.
    // The kernel variable's name might be specified by name or ID.
    //
    ZZDYNVAC(
        &INNAME,
        INFRAM,
        KWSTYL,
        1,
        &mut N,
        CharArrayMut::from_mut(&mut DYNSTL),
        ctx,
    )?;

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

    //
    // At this time, the only supported dynamic frame definition style is
    // PARAMETERIZED.
    //
    if EQSTR(&DYNSTL, KVPARM) {
        //
        // Parameterized dynamic frames belong to families.  Look up
        // the family for this frame.
        //
        ZZDYNVAC(
            &INNAME,
            INFRAM,
            KWFFAM,
            1,
            &mut N,
            CharArrayMut::from_mut(&mut DYNFAM),
            ctx,
        )?;

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

        CMPRSS(b" ", 0, &DYNFAM, &mut TMPFAM);
        UCASE(&TMPFAM, &mut DYNFAM, ctx);

        //
        // Determine whether we have an "of-date" frame family.
        // The logical flags used here and respective meanings are:
        //
        //    MEANEQ   Mean equator and equinox of date
        //    TRUEEQ   True equator and equinox of date
        //    MEANEC   Mean ecliptic and equinox of date
        //
        MEANEQ = fstr::eq(&DYNFAM, KVMEQT);
        TRUEEQ = fstr::eq(&DYNFAM, KVTEQT);
        MEANEC = fstr::eq(&DYNFAM, KVMECL);

        OFDATE = ((MEANEQ || MEANEC) || TRUEEQ);

        //
        // Set the evaluation epoch T0.  Normally this epoch is ET,
        // but if the frame is frozen, the freeze epoch from the
        // frame definition is used.
        //
        // Read the freeze epoch into T0 if a freeze epoch was
        // specified; let FROZEN receive the FOUND flag value
        // returned by ZZDYNOAD.
        //
        ZZDYNOAD(
            &INNAME,
            INFRAM,
            KWFREZ,
            1,
            &mut N,
            std::slice::from_mut(&mut T0),
            &mut FROZEN,
            ctx,
        )?;

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

        if !FROZEN {
            //
            // Normal case:  just use the input epoch.
            //
            T0 = ET;
        }

        //
        // Look up the rotation state keyword.  Rather than checking
        // FAILED() after every call, we'll do it after we're
        // done with processing the rotation state.
        //
        ZZDYNOAC(
            &INNAME,
            INFRAM,
            KWRSTA,
            1,
            &mut N,
            CharArrayMut::from_mut(&mut ROTSTA),
            &mut FND,
            ctx,
        )?;

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

        //
        // If the frame is frozen, the rotation state keyword *must be
        // absent*.
        //
        if (FROZEN && FND) {
            SETMSG(b"Definition of frame # contains both # and # keywords; at most one of these must be present in the frame definition. This situation is usually caused by an error in a frame kernel in which the frame is defined.", ctx);
            ERRCH(b"#", &INNAME, ctx);
            ERRCH(b"#", KWFREZ, ctx);
            ERRCH(b"#", KWRSTA, ctx);
            SIGERR(b"SPICE(FRAMEDEFERROR)", ctx)?;
            CHKOUT(RNAME, ctx)?;
            return Ok(());
        }

        //
        // If the frame belongs to an "of date" family, either the
        // rotation state must be specified or the frame must be
        // frozen.
        //
        if ((OFDATE && !FROZEN) && !FND) {
            SETMSG(b"Definition of frame #, which belongs to parameterized dynamic frame family #, contains neither # nor # keywords; frames in this family require exactly one of these in their frame definitions. This situation is usually caused by an error in a frame kernel in which the frame is defined.", ctx);
            ERRCH(b"#", &INNAME, ctx);
            ERRCH(b"#", &DYNFAM, ctx);
            ERRCH(b"#", KWFREZ, ctx);
            ERRCH(b"#", KWRSTA, ctx);
            SIGERR(b"SPICE(FRAMEDEFERROR)", ctx)?;
            CHKOUT(RNAME, ctx)?;
            return Ok(());
        }

        //
        // Set the rotation state logical flag indicating whether
        // the state is 'INERTIAL'.
        //
        if FND {
            //
            // A rotation state keyword was found.
            //
            // We know the state is not frozen if we arrive here.
            //
            INERT = EQSTR(&ROTSTA, KVINRT);

            if !INERT {
                //
                // Catch invalid rotation states here.
                //
                if !EQSTR(&ROTSTA, KVROTG) {
                    SETMSG(b"Definition of frame # contains # specification #. The only valid rotation states are # or #. This situation is usually caused by an error in a frame kernel in which the frame is defined.", ctx);
                    ERRCH(b"#", &INNAME, ctx);
                    ERRCH(b"#", KWRSTA, ctx);
                    ERRCH(b"#", &ROTSTA, ctx);
                    ERRCH(b"#", KVROTG, ctx);
                    ERRCH(b"#", KVINRT, ctx);
                    SIGERR(b"SPICE(NOTSUPPORTED)", ctx)?;
                    CHKOUT(RNAME, ctx)?;
                    return Ok(());
                }
            }
        } else {
            //
            // The state is not inertial unless there's a ROTATION_STATE
            // keyword assignment telling us it is.
            //
            INERT = false;
        }

        //
        // INERT and FROZEN are both set. The evaluation epoch T0 is also
        // set.
        //
        // The following code block performs actions specific to
        // the various dynamic frame families.
        //
        if OFDATE {
            //
            // Fetch the name of the true equator and equinox of date
            // precession model.
            //
            ZZDYNVAC(
                &INNAME,
                INFRAM,
                KWPRCM,
                1,
                &mut N,
                CharArrayMut::from_mut(&mut PRCMOD),
                ctx,
            )?;

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

            //
            // Get the precession transformation.
            //
            if EQSTR(&PRCMOD, KVM001) {
                //
                // This is the 1976 IAU earth precession model.
                //
                // Make sure the center of the input frame is the earth.
                //
                if (CENTER != save.EARTH) {
                    BODC2N(CENTER, &mut CTRNAM, &mut FND, ctx)?;

                    if !FND {
                        INTSTR(CENTER, &mut CTRNAM, ctx);
                    }

                    SETMSG(b"Definition of frame # specifies frame center # and precession model #. This precession model is not applicable to body #. This situation is usually caused by an error in a frame kernel in which the frame is defined.", ctx);
                    ERRCH(b"#", &INNAME, ctx);
                    ERRCH(b"#", &CTRNAM, ctx);
                    ERRCH(b"#", KVM001, ctx);
                    ERRCH(b"#", &CTRNAM, ctx);
                    SIGERR(b"SPICE(INVALIDSELECTION)", ctx)?;
                    CHKOUT(RNAME, ctx)?;
                    return Ok(());
                }
                //
                // Look up the precession transformation.
                //
                ZZEPRC76(T0, PRECXF.as_slice_mut(), ctx)?;

                //
                // If we're in the mean-of-date case, invert this
                // transformation to obtain the mapping from the
                // mean-of-date frame to J2000.
                //
                if MEANEQ {
                    INVSTM(PRECXF.as_slice(), XFTEMP.as_slice_mut(), ctx)?;
                }
            } else {
                SETMSG(b"Definition of frame # specifies precession model #, which is not recognized. This situation is usually caused by an error in a frame kernel in which the frame is defined.", ctx);
                ERRCH(b"#", &INNAME, ctx);
                ERRCH(b"#", &PRCMOD, ctx);
                SIGERR(b"SPICE(NOTSUPPORTED)", ctx)?;
                CHKOUT(RNAME, ctx)?;
                return Ok(());
            }

            //
            // At this point the precession transformation PRECXF is set.
            // If INFRAM is a mean equator and equinox of date frame, the
            // inverse of PRECXF is currently stored in XFTEMP.

            if TRUEEQ {
                //
                // We need a nutation transformation as well. Get the name
                // of the nutation model.
                //
                ZZDYNVAC(
                    &INNAME,
                    INFRAM,
                    KWNUTM,
                    1,
                    &mut N,
                    CharArrayMut::from_mut(&mut NUTMOD),
                    ctx,
                )?;

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

                //
                // Get the nutation transformation.
                //
                if EQSTR(&NUTMOD, KVM002) {
                    //
                    // This is the 1980 IAU earth nutation model.
                    //
                    // Make sure the center is the earth.
                    //
                    if (CENTER != save.EARTH) {
                        BODC2N(CENTER, &mut CTRNAM, &mut FND, ctx)?;

                        if !FND {
                            INTSTR(CENTER, &mut CTRNAM, ctx);
                        }

                        SETMSG(b"Definition of frame # specifies frame center # and nutation model #. This nutation model is not applicable to body #.  This situation is usually caused by an error in a frame kernel in which the frame is defined.", ctx);
                        ERRCH(b"#", &INNAME, ctx);
                        ERRCH(b"#", &CTRNAM, ctx);
                        ERRCH(b"#", KVM002, ctx);
                        ERRCH(b"#", &CTRNAM, ctx);
                        SIGERR(b"SPICE(INVALIDSELECTION)", ctx)?;
                        CHKOUT(RNAME, ctx)?;
                        return Ok(());
                    }

                    //
                    // Look up the nutation transformation.
                    //
                    ZZENUT80(T0, NUTXF.as_slice_mut(), ctx)?;

                    //
                    // Find the transformation from the J2000 frame to the
                    // earth true of date frame.  Invert.
                    //
                    MXMG(
                        NUTXF.as_slice(),
                        PRECXF.as_slice(),
                        6,
                        6,
                        6,
                        XFINV.as_slice_mut(),
                    );
                    INVSTM(XFINV.as_slice(), XFTEMP.as_slice_mut(), ctx)?;
                } else {
                    SETMSG(b"Definition of frame # specifies nutation model #, which is not recognized. This situation is usually caused by an error in a frame kernel in which the frame is defined.", ctx);
                    ERRCH(b"#", &INNAME, ctx);
                    ERRCH(b"#", &NUTMOD, ctx);
                    SIGERR(b"SPICE(NOTSUPPORTED)", ctx)?;
                    CHKOUT(RNAME, ctx)?;
                    return Ok(());
                }
            } else if MEANEC {
                //
                // We need a mean obliquity transformation as well.
                // Get the name of the obliquity model.
                //
                ZZDYNVAC(
                    &INNAME,
                    INFRAM,
                    KWOBQM,
                    1,
                    &mut N,
                    CharArrayMut::from_mut(&mut OBLMOD),
                    ctx,
                )?;

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

                //
                // Get the obliquity transformation.
                //
                if EQSTR(&OBLMOD, KVM003) {
                    //
                    // This is the 1980 IAU earth mean obliquity of
                    // date model.
                    //
                    // Make sure the center is the earth.
                    //
                    if (CENTER != save.EARTH) {
                        BODC2N(CENTER, &mut CTRNAM, &mut FND, ctx)?;

                        if !FND {
                            INTSTR(CENTER, &mut CTRNAM, ctx);
                        }

                        SETMSG(b"Definition of frame # specifies frame center # and obliquity model #.  This obliquity model is not applicable to body #. This situation is usually caused by an error in a frame kernel in which the frame is defined.", ctx);
                        ERRCH(b"#", &INNAME, ctx);
                        ERRCH(b"#", &CTRNAM, ctx);
                        ERRCH(b"#", KVM003, ctx);
                        ERRCH(b"#", &CTRNAM, ctx);
                        SIGERR(b"SPICE(INVALIDSELECTION)", ctx)?;
                        CHKOUT(RNAME, ctx)?;
                        return Ok(());
                    }

                    //
                    // Create the obliquity transformation. First look up
                    // the obliquity state (angle and angular rate).
                    //
                    ZZMOBLIQ(T0, &mut MOB, &mut DMOB, ctx);

                    //
                    // The obliquity rotation is about the mean-of-date
                    // x-axis.  The other Euler angles are identically
                    // zero; the axes are arbitrary, as long as the
                    // middle axis is distinct from the other two.
                    //
                    CLEARD(6, EULANG.as_slice_mut());
                    EULANG[3] = MOB;
                    EULANG[6] = DMOB;

                    EUL2XF(EULANG.as_slice(), 1, 3, 1, OBLXF.as_slice_mut(), ctx)?;

                    //
                    // Find the transformation from the J2000 to the
                    // earth mean ecliptic of date frame.  Invert.
                    //
                    MXMG(
                        OBLXF.as_slice(),
                        PRECXF.as_slice(),
                        6,
                        6,
                        6,
                        XFINV.as_slice_mut(),
                    );
                    INVSTM(XFINV.as_slice(), XFTEMP.as_slice_mut(), ctx)?;
                } else {
                    SETMSG(b"Definition of frame # specifies obliquity model #, which is not recognized. This situation is usually caused by an error in a frame kernel in which the frame is defined.", ctx);
                    ERRCH(b"#", &INNAME, ctx);
                    ERRCH(b"#", &OBLMOD, ctx);
                    SIGERR(b"SPICE(NOTSUPPORTED)", ctx)?;
                    CHKOUT(RNAME, ctx)?;
                    return Ok(());
                }
            }

            //
            // At this point, XFTEMP contains the mapping from the
            // specified mean of date or true of date frame to J2000.
            //
            // If the base frame is not J2000, we must find the
            // transformation from J2000 to the base frame.
            //
            if (*BASFRM != save.J2000) {
                ZZFRMCH0(save.J2000, *BASFRM, T0, XF2000.as_slice_mut(), ctx)?;
                MXMG(
                    XF2000.as_slice(),
                    XFTEMP.as_slice(),
                    6,
                    6,
                    6,
                    XFORM.as_slice_mut(),
                );
            } else {
                //
                // Otherwise, XFTEMP is the matrix we want.
                //
                MOVED(XFTEMP.as_slice(), 36, XFORM.as_slice_mut());
            }

        //
        // Now XFORM is the state transformation mapping from
        // the input frame INFRAM to the base frame BASFRM.
        //
        // This is the end of the work specific to "of-date" frames.
        // From here we drop out of the IF block.  At the end of this
        // routine, the derivative block of XFORM will be zeroed out
        // if the frame is frozen.  If the rotation state is
        // 'INERTIAL', we will make sure the transformation between
        // the defined frame and the J2000 frame has time derivative
        // zero.
        //
        } else if fstr::eq(&DYNFAM, KV2VEC) {
            //
            // The frame belongs to the TWO-VECTOR family.
            //
            // Initialize the array S2.
            //
            CLEARD(12, S2.as_slice_mut());

            //
            // Fetch the specifications of the primary and secondary
            // axes.
            //
            for I in 1..=2 {
                //
                // Get the name of the axis associated with the Ith
                // defining vector.
                //
                ZZDYNVAC(
                    &INNAME,
                    INFRAM,
                    &save.ITMAXE[I],
                    1,
                    &mut N,
                    CharArrayMut::from_mut(&mut AXNAME),
                    ctx,
                )?;

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

                CMPRSS(b" ", 0, &AXNAME.clone(), &mut AXNAME);
                UCASE(&AXNAME.clone(), &mut AXNAME, ctx);

                //
                // Set the sign flag associated with the axis.
                //
                NEGATE = fstr::eq(fstr::substr(&AXNAME, 1..=1), b"-");

                CMPRSS(b"-", 0, &AXNAME.clone(), &mut AXNAME);
                CMPRSS(b"+", 0, &AXNAME.clone(), &mut AXNAME);

                AXIS[I] = ISRCHC(&AXNAME, 3, save.AXES.as_arg());

                if (AXIS[I] == 0) {
                    SETMSG(b"Definition of frame # associates vector # with axis #.  The only valid axis values are { X, -X, Y, -Y, Z, -Z }. This situation is usually caused by an error in a frame kernel in which the frame is defined.", ctx);
                    ERRCH(b"#", &INNAME, ctx);
                    ERRINT(b"#", I, ctx);
                    ERRCH(b"#", &AXNAME, ctx);
                    SIGERR(b"SPICE(INVALIDAXIS)", ctx)?;
                    CHKOUT(RNAME, ctx)?;
                    return Ok(());
                }

                //
                // Find out how the vector is defined:
                //
                //    - Observer-target position vector
                //    - Observer-target velocity vector
                //    - Observer-target near point vector
                //    - Constant vector
                //
                // VECDEF(I) indicates the vector definition method
                // for the Ith vector.
                //
                ZZDYNVAC(
                    &INNAME,
                    INFRAM,
                    &save.ITMVDF[I],
                    1,
                    &mut N,
                    VECDEF.subarray_mut(I),
                    ctx,
                )?;

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

                CMPRSS(b" ", 0, &VECDEF[I].to_vec(), &mut VECDEF[I]);
                UCASE(&VECDEF[I].to_vec(), &mut VECDEF[I], ctx);

                if fstr::eq(VECDEF.get(I), KVPOSV) {
                    //
                    // The vector is the position of a target relative
                    // to an observer.
                    //
                    // We need a target, observer, and aberration correction.
                    //
                    ZZDYNBID(&INNAME, INFRAM, &save.ITMTRG[I], &mut TARG, ctx)?;

                    ZZDYNBID(&INNAME, INFRAM, &save.ITMOBS[I], &mut OBS, ctx)?;

                    ZZDYNVAC(
                        &INNAME,
                        INFRAM,
                        &save.ITMABC[I],
                        1,
                        &mut N,
                        CharArrayMut::from_mut(&mut ABCORR),
                        ctx,
                    )?;

                    //
                    // Look up the Ith state vector in the J2000 frame.
                    //
                    ZZSPKEZ0(
                        TARG,
                        T0,
                        b"J2000",
                        &ABCORR,
                        OBS,
                        S2.subarray_mut([1, I]),
                        &mut LT,
                        ctx,
                    )?;

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

                //
                // At this point, S2(*,I) contains position and
                // velocity relative to frame J2000.
                //
                } else if fstr::eq(VECDEF.get(I), KVVELV) {
                    //
                    // The vector is the velocity of a target relative
                    // to an observer.
                    //
                    // We need a target, observer, and aberration correction.
                    //
                    ZZDYNBID(&INNAME, INFRAM, &save.ITMTRG[I], &mut TARG, ctx)?;

                    ZZDYNBID(&INNAME, INFRAM, &save.ITMOBS[I], &mut OBS, ctx)?;

                    ZZDYNVAC(
                        &INNAME,
                        INFRAM,
                        &save.ITMABC[I],
                        1,
                        &mut N,
                        CharArrayMut::from_mut(&mut ABCORR),
                        ctx,
                    )?;

                    //
                    // We need to know the frame in which the velocity is
                    // defined.
                    //
                    ZZDYNFID(&INNAME, INFRAM, &save.ITMFRM[I], &mut FRID, ctx)?;
                    FRMNAM(FRID, &mut VELFRM, ctx)?;

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

                    //
                    // Obtain the velocity vector in the specified velocity
                    // frame.  Also obtain bracketing vectors to support
                    // discrete differentiation.  (See notes in zzdyn.inc
                    // regarding definition of DELTA.)
                    //
                    DELTA = intrinsics::DMAX1(&[1.0, (f64::powi(2.0, QEXP) * T0)]);

                    VPACK((T0 - DELTA), T0, (T0 + DELTA), TARRAY.as_slice_mut());

                    {
                        let m1__: i32 = 1;
                        let m2__: i32 = 3;
                        let m3__: i32 = 1;
                        J = m1__;
                        for _ in 0..((m2__ - m1__ + m3__) / m3__) as i32 {
                            ZZSPKEZ0(
                                TARG,
                                TARRAY[J],
                                &VELFRM,
                                &ABCORR,
                                OBS,
                                STEMP.as_slice_mut(),
                                &mut LT,
                                ctx,
                            )?;
                            //
                            // We compute the derivative using unit
                            // velocity vectors.
                            //
                            if FAILED(ctx) {
                                CHKOUT(RNAME, ctx)?;
                                return Ok(());
                            }

                            VHAT(STEMP.subarray(4), VARRAY.subarray_mut([1, J]));

                            J += m3__;
                        }
                    }

                    //
                    // Compute acceleration and fill in the velocity state
                    // vector S2(*,I).
                    //
                    QDERIV(
                        3,
                        VARRAY.subarray([1, 1]),
                        VARRAY.subarray([1, 3]),
                        DELTA,
                        ACC.as_slice_mut(),
                        ctx,
                    )?;

                    VEQU(VARRAY.subarray([1, 2]), S2.subarray_mut([1, I]));
                    VEQU(ACC.as_slice(), S2.subarray_mut([4, I]));

                    //
                    // We need the epoch VET at which VELFRM is evaluated.
                    // This epoch will be used to transform the velocity's
                    // "state" vector from VELFRM to J2000.
                    //
                    // Set the default value of VET here.
                    //
                    VET = T0;

                    //
                    // Parse the aberration correction.  Find the epoch used
                    // to evaluate the velocity vector's frame.
                    //
                    ZZVALCOR(&ABCORR, CORBLK.as_slice_mut(), ctx)?;

                    if CORBLK[LTIDX] {
                        //
                        // Light time correction is used.  The epoch used
                        // to evaluate the velocity vector's frame depends
                        // on the frame's observer and center.
                        //
                        // Look up the velocity frame's center.
                        //
                        FRINFO(FRID, &mut FRCTR, &mut FRCLS, &mut FRCID, &mut FND, ctx)?;

                        if !FND {
                            SETMSG(b"In definition of frame #, the frame associated with a velocity vector has frame ID code #, but no frame center, frame class, or frame class ID was found by FRINFO.  This situation MAY be caused by an error in a frame kernel in which the frame is defined. The problem also could be indicative of a SPICELIB bug.", ctx);
                            ERRCH(b"#", &INNAME, ctx);
                            ERRINT(b"#", FRID, ctx);
                            SIGERR(b"SPICE(FRAMEDATANOTFOUND)", ctx)?;
                            CHKOUT(RNAME, ctx)?;
                            return Ok(());
                        }

                        //
                        // If the velocity frame is non-inertial, we'll need
                        // to compute the evaluation epoch for this frame.
                        //
                        if (FRCLS != INERTL) {
                            //
                            // Obtain light time from the observer to the
                            // frame's center; find the evaluation epoch VET
                            // for the frame.

                            ZZSPKZP0(
                                FRCTR,
                                T0,
                                b"J2000",
                                &ABCORR,
                                OBS,
                                CTRPOS.as_slice_mut(),
                                &mut VFLT,
                                ctx,
                            )?;
                            ZZCOREPC(&ABCORR, T0, VFLT, &mut VET, ctx)?;

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

                    //
                    // The velocity frame's evaluation epoch VET is now set.
                    //
                    // We must rotate the velocity vector and transform the
                    // acceleration from the velocity frame (evaluated at
                    // VET) to the output frame at T0.  We'll do this in two
                    // stages, first mapping velocity and acceleration into
                    // the J2000 frame.
                    //
                    if (FRID != save.J2000) {
                        ZZFRMCH0(FRID, save.J2000, VET, XF2000.as_slice_mut(), ctx)?;

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

                        MXVG(
                            XF2000.as_slice(),
                            S2.subarray([1, I]),
                            6,
                            6,
                            STEMP.as_slice_mut(),
                        );
                        MOVED(STEMP.as_slice(), 6, S2.subarray_mut([1, I]));
                    }

                //
                // At this point, S2(*,I) contains velocity and
                // acceleration relative to frame J2000.
                //
                } else if fstr::eq(VECDEF.get(I), KVNEAR) {
                    //
                    // The vector points from an observer to the
                    // sub-observer point (nearest point to the observer) on
                    // the target body.
                    //
                    // We need a target, observer, and aberration correction.
                    //
                    ZZDYNBID(&INNAME, INFRAM, &save.ITMTRG[I], &mut TARG, ctx)?;

                    ZZDYNBID(&INNAME, INFRAM, &save.ITMOBS[I], &mut OBS, ctx)?;

                    ZZDYNVAC(
                        &INNAME,
                        INFRAM,
                        &save.ITMABC[I],
                        1,
                        &mut N,
                        CharArrayMut::from_mut(&mut ABCORR),
                        ctx,
                    )?;

                    //
                    // The vector points from the observer to the nearest
                    // point on the target. We need the state of the near
                    // point relative to the observer.
                    //
                    // We'll look up the state of the target center relative
                    // to the observer and the state of the near point
                    // relative to the target center, both in the body-fixed
                    // frame associated with the target.
                    //
                    // Look up the body-fixed frame associated with the
                    // target body.
                    //
                    CIDFRM(TARG, &mut CFRMID, &mut CFRMNM, &mut FND, ctx)?;

                    if !FND {
                        SETMSG(b"Definition of frame # requires definition of body-fixed frame associated with target body #. A call to CIDFRM indicated no body-fixed frame is associated with the target body.  This situation can arise when a frame kernel defining the target\'s body-fixed frame  lacks the OBJECT_<ID>_FRAME or OBJECT_<name>_FRAME keywords.  The problem also could be caused by an error in a frame kernel in which the parameterized two-vector dynamic frame # is defined.", ctx);
                        ERRCH(b"#", &INNAME, ctx);
                        ERRINT(b"#", TARG, ctx);
                        ERRCH(b"#", &INNAME, ctx);
                        SIGERR(b"SPICE(FRAMEDATANOTFOUND)", ctx)?;
                        CHKOUT(RNAME, ctx)?;
                        return Ok(());
                    }

                    //
                    // Get the radii of the target body.
                    //
                    ZZGFTREB(TARG, RADII.as_slice_mut(), ctx)?;

                    //
                    // Look up the Ith state vector in the target-fixed
                    // frame.  Negate the vector to obtain the target-to-
                    // observer vector.
                    //
                    ZZSPKEZ0(
                        TARG,
                        T0,
                        &CFRMNM,
                        &ABCORR,
                        OBS,
                        STEMP.as_slice_mut(),
                        &mut LT,
                        ctx,
                    )?;

                    //
                    // We check FAILED() here because VMINUG is a simple
                    // arithmetic routine that doesn't return on entry.
                    //
                    if FAILED(ctx) {
                        CHKOUT(RNAME, ctx)?;
                        return Ok(());
                    }

                    VMINUG(STEMP.as_slice(), 6, STOBS.as_slice_mut());

                    DNEARP(
                        STOBS.as_slice(),
                        RADII[1],
                        RADII[2],
                        RADII[3],
                        STNEAR.as_slice_mut(),
                        STALT.as_slice_mut(),
                        &mut FND,
                        ctx,
                    )?;

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

                    if !FND {
                        SETMSG(b"In definition of frame #, vector # is defined by the near point on body # as seen from body #.  The state of this near point was not found. See the routine DNEARP for an explanation.  This situation MAY be caused by an error in a frame kernel in which the frame is defined. The problem also could be indicative of a SPICELIB bug.", ctx);
                        ERRCH(b"#", &INNAME, ctx);
                        ERRINT(b"#", I, ctx);
                        ERRINT(b"#", TARG, ctx);
                        ERRINT(b"#", OBS, ctx);
                        SIGERR(b"SPICE(DEGENERATECASE)", ctx)?;
                        CHKOUT(RNAME, ctx)?;
                        return Ok(());
                    }

                    //
                    // Find the observer-near point state in the target
                    // body-fixed frame.
                    //
                    VSUBG(STNEAR.as_slice(), STOBS.as_slice(), 6, STEMP.as_slice_mut());

                    //
                    // Transform the state to frame J2000.  To get the
                    // required transformation matrix, we'll need to obtain
                    // the epoch associated with CNMFRM.  Parse the
                    // aberration correction and adjust the frame evaluation
                    // epoch as needed.
                    //
                    ZZCOREPC(&ABCORR, T0, LT, &mut FET, ctx)?;

                    //
                    // Obtain the matrix for transforming state vectors
                    // from the target center frame to the J2000 frame and
                    // apply it to the observer-to-near point state vector.
                    //
                    ZZFRMCH0(CFRMID, save.J2000, FET, XIPM.as_slice_mut(), ctx)?;

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

                    MXVG(
                        XIPM.as_slice(),
                        STEMP.as_slice(),
                        6,
                        6,
                        S2.subarray_mut([1, I]),
                    );

                //
                // At this point, S2(*,I) contains position and
                // velocity of the near point on the target as
                // seen by the observer, relative to frame J2000.
                //
                } else if fstr::eq(VECDEF.get(I), KVCONS) {
                    //
                    // The vector is constant in a specified frame.
                    //
                    //
                    // We need a 3-vector and an associated reference
                    // frame relative to which the vector is specified.
                    //
                    // Look up the ID of the frame first.
                    //
                    ZZDYNFID(&INNAME, INFRAM, &save.ITMFRM[I], &mut FRID, ctx)?;

                    //
                    // Let FET ("frame ET") be the evaluation epoch for
                    // the constant vector's frame.  By default, this
                    // frame is just T0, but if we're using light time
                    // corrections, FET must be adjusted for one-way
                    // light time between the frame's center and the
                    // observer.
                    //
                    // Set the default value of FET here.
                    //
                    FET = T0;

                    //
                    // Optionally, there is an aberration correction
                    // associated with the constant vector's frame.
                    // If so, an observer must be associated with the
                    // frame.  Look up the correction first.
                    //
                    ZZDYNOAC(
                        &INNAME,
                        INFRAM,
                        &save.ITMABC[I],
                        1,
                        &mut N,
                        CharArrayMut::from_mut(&mut CVCORR),
                        &mut FND,
                        ctx,
                    )?;

                    if !FND {
                        fstr::assign(&mut CVCORR, b"NONE");
                    }

                    ZZPRSCOR(&CVCORR, CORBLK.as_slice_mut(), ctx)?;

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

                    if !CORBLK[GEOIDX] {
                        //
                        // We need to apply an aberration correction to
                        // the constant vector.
                        //
                        // Check for errors in the aberration correction
                        // specification.
                        //
                        //    - Light time and stellar aberration corrections
                        //      are mutually exclusive.
                        //
                        if (CORBLK[LTIDX] && CORBLK[STLIDX]) {
                            SETMSG(b"Definition of frame # specifies aberration correction # for constant vector.  Light time and stellar aberration corrections are mutually exclusive for constant vectors used in two-vector parameterized dynamic frame definitions.  This situation is usually caused by an error in a frame kernel in which the frame is defined.", ctx);
                            ERRCH(b"#", &INNAME, ctx);
                            ERRCH(b"#", &CVCORR, ctx);
                            SIGERR(b"SPICE(INVALIDOPTION)", ctx)?;
                            CHKOUT(RNAME, ctx)?;
                            return Ok(());
                        }

                        if CORBLK[LTIDX] {
                            //
                            // Light time correction is used.  The epoch used
                            // to evaluate the constant vector's frame depends
                            // on the frame's observer and center.
                            //
                            // Look up the constant vector frame's center.
                            //
                            FRINFO(FRID, &mut FRCTR, &mut FRCLS, &mut FRCID, &mut FND, ctx)?;

                            if !FND {
                                SETMSG(b"In definition of frame #, the frame associated with a constant vector has frame ID code #, but no frame center, frame class, or frame class ID was found by FRINFO.  This situation MAY be caused by an error in a frame kernel in which the frame is defined. The problem also could be indicative of a SPICELIB bug.", ctx);
                                ERRCH(b"#", &INNAME, ctx);
                                ERRINT(b"#", FRID, ctx);
                                SIGERR(b"SPICE(FRAMEDATANOTFOUND)", ctx)?;
                                CHKOUT(RNAME, ctx)?;
                                return Ok(());
                            }
                            //
                            // If the constant vector frame is non-inertial,
                            // we'll need to compute the evaluation epoch for
                            // this frame.
                            //
                            if (FRCLS != INERTL) {
                                //
                                // Look up the observer associated with the
                                // constant vector's frame.  This observer,
                                // together with the frame's center, determines
                                // the evaluation epoch for the frame.
                                //
                                ZZDYNBID(&INNAME, INFRAM, &save.ITMOBS[I], &mut CVOBS, ctx)?;

                                //
                                // Obtain light time from the observer to the
                                // frame's center.
                                //
                                ZZSPKZP0(
                                    FRCTR,
                                    T0,
                                    b"J2000",
                                    &CVCORR,
                                    CVOBS,
                                    CTRPOS.as_slice_mut(),
                                    &mut LT,
                                    ctx,
                                )?;

                                //
                                // Re-set the evaluation epoch for the frame.
                                //
                                ZZCOREPC(&CVCORR, T0, LT, &mut FET, ctx)?;

                                if FAILED(ctx) {
                                    CHKOUT(RNAME, ctx)?;
                                    return Ok(());
                                }
                            }
                        //
                        // The constant vector frame's evaluation epoch
                        // FET has been set.
                        //
                        } else if CORBLK[STLIDX] {
                            //
                            // Stellar aberration case.
                            //
                            // The constant vector must be corrected for
                            // stellar aberration induced by the observer's
                            // velocity relative to the solar system
                            // barycenter.  First, find this velocity in
                            // the J2000 frame.  We'll apply the correction
                            // later, when the constant vector has been
                            // transformed to the J2000 frame.
                            //
                            ZZDYNBID(&INNAME, INFRAM, &save.ITMOBS[I], &mut CVOBS, ctx)?;

                            ZZSPKSB0(CVOBS, T0, b"J2000", STOBS.as_slice_mut(), ctx)?;

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

                    //
                    // At this point FET is the frame evaluation epoch
                    // for the frame associated with the constant vector.
                    //
                    // If stellar aberration correction has been specified,
                    // STOBS is the state of the observer relative to the
                    // solar system barycenter, expressed in the J2000
                    // frame.
                    //
                    // Get the constant vector specification.
                    //
                    ZZDYNVAC(
                        &INNAME,
                        INFRAM,
                        &save.ITMSPC[I],
                        1,
                        &mut N,
                        CharArrayMut::from_mut(&mut SPEC),
                        ctx,
                    )?;

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

                    CMPRSS(b" ", 0, &SPEC.clone(), &mut SPEC);
                    UCASE(&SPEC.clone(), &mut SPEC, ctx);

                    if fstr::eq(&SPEC, KVRECC) {
                        //
                        // The coordinate system is rectangular.
                        //
                        // Look up the constant vector.
                        //
                        ZZDYNVAD(
                            &INNAME,
                            INFRAM,
                            &save.ITMVEC[I],
                            3,
                            &mut N,
                            DIRVEC.as_slice_mut(),
                            ctx,
                        )?;
                    } else if (fstr::eq(&SPEC, KVLATC) || fstr::eq(&SPEC, KVRADC)) {
                        //
                        // The coordinate system is latitudinal or RA/DEC.
                        //
                        // Look up the units associated with the angles.
                        //
                        ZZDYNVAC(
                            &INNAME,
                            INFRAM,
                            &save.ITMUNT[I],
                            1,
                            &mut N,
                            CharArrayMut::from_mut(&mut UNITS),
                            ctx,
                        )?;

                        if fstr::eq(&SPEC, KVLATC) {
                            //
                            // Look up longitude and latitude.
                            //
                            ZZDYNVAD(
                                &INNAME,
                                INFRAM,
                                &save.ITMLON[I],
                                1,
                                &mut N,
                                std::slice::from_mut(&mut LON),
                                ctx,
                            )?;

                            ZZDYNVAD(
                                &INNAME,
                                INFRAM,
                                &save.ITMLAT[I],
                                1,
                                &mut N,
                                std::slice::from_mut(&mut LAT),
                                ctx,
                            )?;

                            //
                            // Convert angles from input units to radians.
                            //
                            CONVRT(LON, &UNITS, KVRADN, &mut ANGLES[1], ctx)?;
                            CONVRT(LAT, &UNITS, KVRADN, &mut ANGLES[2], ctx)?;
                        } else {
                            //
                            // Look up RA and DEC.
                            //
                            ZZDYNVAD(
                                &INNAME,
                                INFRAM,
                                &save.ITMRA[I],
                                1,
                                &mut N,
                                std::slice::from_mut(&mut RA),
                                ctx,
                            )?;

                            ZZDYNVAD(
                                &INNAME,
                                INFRAM,
                                &save.ITMDEC[I],
                                1,
                                &mut N,
                                std::slice::from_mut(&mut DEC),
                                ctx,
                            )?;

                            //
                            // Convert angles from input units to radians.
                            //
                            CONVRT(RA, &UNITS, KVRADN, &mut ANGLES[1], ctx)?;
                            CONVRT(DEC, &UNITS, KVRADN, &mut ANGLES[2], ctx)?;
                        }

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

                        //
                        // Now  produce a direction vector.
                        //
                        LATREC(1.0, ANGLES[1], ANGLES[2], DIRVEC.as_slice_mut());
                    } else {
                        SETMSG(b"Definition of two-vector parameterized dynamic frame # includes constant vector specification #, which is not supported.  This situation is usually caused by an error in a frame kernel in which the frame is defined.", ctx);
                        ERRCH(b"#", &INNAME, ctx);
                        ERRCH(b"#", &SPEC, ctx);
                        SIGERR(b"SPICE(NOTSUPPORTED)", ctx)?;
                        CHKOUT(RNAME, ctx)?;
                        return Ok(());
                    }

                    //
                    // At this point, the Cartesian coordinates of the
                    // vector relative to the constant vector frame
                    // are stored in DIRVEC.
                    //
                    // Convert the direction vector to the J2000 frame.
                    // Fill in the state vector.  The velocity in the
                    // constant vector's frame is zero.
                    //
                    VEQU(DIRVEC.as_slice(), S2.subarray_mut([1, I]));
                    CLEARD(3, S2.subarray_mut([4, I]));

                    if (FRID != save.J2000) {
                        ZZFRMCH0(FRID, save.J2000, FET, XIPM.as_slice_mut(), ctx)?;

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

                        MXVG(
                            XIPM.as_slice(),
                            S2.subarray([1, I]),
                            6,
                            6,
                            STEMP.as_slice_mut(),
                        );
                        MOVED(STEMP.as_slice(), 6, S2.subarray_mut([1, I]));
                    }

                    //
                    // The state of the constant vector is now represented
                    // in the J2000 frame, but we may still need to
                    // apply a stellar aberration correction.
                    //
                    if CORBLK[STLIDX] {
                        //
                        // Perform the stellar aberration correction
                        // appropriate to the radiation travel sense.

                        if CORBLK[XMTIDX] {
                            //
                            // The correction is for transmission.
                            //
                            STLABX(
                                S2.subarray([1, I]),
                                STOBS.subarray(4),
                                STEMP.as_slice_mut(),
                                ctx,
                            )?;
                        } else {
                            //
                            // The correction is for reception.
                            //
                            STELAB(
                                S2.subarray([1, I]),
                                STOBS.subarray(4),
                                STEMP.as_slice_mut(),
                                ctx,
                            )?;
                        }

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

                        //
                        // Update the position portion of S2(*,I).
                        //
                        VEQU(STEMP.as_slice(), S2.subarray_mut([1, I]));
                    }

                //
                // At this point, S2(*,I) contains position and velocity
                // of the constant (constant relative to its associated
                // frame, that is) vector as seen by the observer,
                // relative to frame J2000.
                //
                } else {
                    SETMSG(b"Definition of two-vector parameterized dynamic frame # includes vector definition #, which is not supported.  This situation is usually caused by an error in a frame kernel in which the frame is defined.", ctx);
                    ERRCH(b"#", &INNAME, ctx);
                    ERRCH(b"#", &VECDEF[I], ctx);
                    SIGERR(b"SPICE(NOTSUPPORTED)", ctx)?;
                    CHKOUT(RNAME, ctx)?;
                    return Ok(());
                }

                //
                // Negate the state vector if the axis has negative sign.
                //
                if NEGATE {
                    VMINUG(S2.subarray([1, I]), 6, STEMP.as_slice_mut());
                    MOVED(STEMP.as_slice(), 6, S2.subarray_mut([1, I]));
                }
            }

            //
            // Look up the lower bound for the angular separation of
            // the defining vectors.  Use the default value if none
            // was supplied.
            //
            ZZDYNOAD(
                &INNAME,
                INFRAM,
                &save.ITMSEP,
                1,
                &mut N,
                std::slice::from_mut(&mut MINSEP),
                &mut FND,
                ctx,
            )?;

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

            if !FND {
                MINSEP = LBSEP;
            }

            //
            // Now use our states to compute our state transformation
            // matrix.
            //
            // Check the angular separation of the defining vectors. We
            // want to ensure that the vectors are not too close to being
            // linearly dependent.  We can handle both cases---separation
            // close to 0 or separation close to Pi---by comparing the
            // sine of the separation to the sine of the separation limit.
            //
            SEP = VSEP(S2.subarray([1, 1]), S2.subarray([1, 2]), ctx);

            if (f64::sin(SEP) < f64::sin(MINSEP)) {
                ETCAL(T0, &mut TIMSTR, ctx);

                SETMSG(b"Angular separation of vectors defining two-vector parameterized dynamic frame # is # (radians); minimum allowed difference of separation from 0 or Pi is # radians.  Evaluation epoch is #.  Extreme loss of precision can occur when defining vectors are nearly linearly dependent.  This type of error can be due to using a dynamic frame outside of the time range for which it is meant. It also can be due to a conceptual error pertaining to the frame\'s definition, or to an implementation error in the frame kernel containing the frame definition. However, if you wish to proceed with this computation, the # keyword can be used in the frame definition to adjust the separation limit.", ctx);
                ERRCH(b"#", &INNAME, ctx);
                ERRDP(b"#", SEP, ctx);
                ERRDP(b"#", MINSEP, ctx);
                ERRCH(b"#", &TIMSTR, ctx);
                ERRCH(b"#", KWATOL, ctx);
                SIGERR(b"SPICE(DEGENERATECASE)", ctx)?;
                CHKOUT(RNAME, ctx)?;
                return Ok(());
            }

            //
            // We have both states expressed relative to frame J2000
            // at this point.  Find the transformation from INNAME to
            // the frame J2000, then from J2000 to frame BASNAM.
            //
            ZZTWOVXF(
                S2.subarray([1, 1]),
                AXIS[1],
                S2.subarray([1, 2]),
                AXIS[2],
                XFORM.as_slice_mut(),
                ctx,
            )?;

            if (*BASFRM != save.J2000) {
                MOVED(XFORM.as_slice(), 36, XFTEMP.as_slice_mut());

                ZZFRMCH0(save.J2000, *BASFRM, T0, XF2000.as_slice_mut(), ctx)?;

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

                MXMG(
                    XF2000.as_slice(),
                    XFTEMP.as_slice(),
                    6,
                    6,
                    6,
                    XFORM.as_slice_mut(),
                );
            }

        //
        // This is the end of the work specific to two-vector frames.
        // From here we drop out of the IF block.  At the end of this
        // routine, the derivative block of XFORM will be zeroed out
        // if the frame is frozen.  If the rotation state is
        // 'INERTIAL', we will make sure the transformation between
        // the defined frame and the J2000 frame has time derivative
        // zero.
        //
        } else if fstr::eq(&DYNFAM, KVEULR) {
            //
            // The frame belongs to the Euler family.
            //
            // We expect to see specifications of an axis sequence, units,
            // and angles via polynomial coefficients.  We also expect
            // to see an ET epoch.
            //
            // Look up the epoch first.  Let DELTA represent the offset
            // of T0 relative to the epoch.
            //
            // Initialize EPOCH so subtraction doesn't overflow if EPOCH
            // is invalid due to a lookup error.
            //
            EPOCH = 0.0;

            ZZDYNVAD(
                &INNAME,
                INFRAM,
                KWEPOC,
                1,
                &mut N,
                std::slice::from_mut(&mut EPOCH),
                ctx,
            )?;

            DELTA = (T0 - EPOCH);

            //
            // Now the axis sequence.
            //
            ZZDYNVAI(
                &INNAME,
                INFRAM,
                KWEUAX,
                3,
                &mut N,
                IAXES.as_slice_mut(),
                ctx,
            )?;

            //
            // Now the coefficients for the angles.
            //
            for I in 1..=3 {
                //
                // Initialize N so subtraction doesn't overflow if N
                // is invalid due to a lookup error.
                //
                N = 0;

                ZZDYNVAD(
                    &INNAME,
                    INFRAM,
                    &save.ITMCOF[I],
                    MAXCOF,
                    &mut N,
                    COEFFS.subarray_mut([1, I]),
                    ctx,
                )?;

                //
                // Set the polynomial degree for the Ith angle.
                //
                DEGS[I] = (N - 1);
            }

            //
            // Look up the units associated with the angles.
            //
            ZZDYNVAC(
                &INNAME,
                INFRAM,
                KWUNIT,
                1,
                &mut N,
                CharArrayMut::from_mut(&mut UNITS),
                ctx,
            )?;

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

            //
            // Evaluate the angles and their derivatives at DELTA.  Convert
            // angles from input units to radians and radians/sec.
            //
            for I in 1..=3 {
                POLYDS(
                    COEFFS.subarray([1, I]),
                    DEGS[I],
                    1,
                    DELTA,
                    POLY.as_slice_mut(),
                );
                //
                // Convert units.  Fill in the Euler angle state vector.
                //
                CONVRT(POLY[0], &UNITS, KVRADN, &mut EULANG[I], ctx)?;
                CONVRT(POLY[1], &UNITS, KVRADN, &mut EULANG[(I + 3)], ctx)?;
            }

            //
            // Produce a state transformation matrix that maps from
            // the defined frame to the base frame.
            //
            EUL2XF(
                EULANG.as_slice(),
                IAXES[1],
                IAXES[2],
                IAXES[3],
                XFORM.as_slice_mut(),
                ctx,
            )?;

        //
        // This is the end of the work specific to Euler frames.
        // From here we drop out of the IF block.  At the end of this
        // routine, the derivative block of XFORM will be zeroed out
        // if the frame is frozen.  If the rotation state is
        // 'INERTIAL', we will make sure the transformation between
        // the defined frame and the J2000 frame has time derivative
        // zero.
        //
        } else if fstr::eq(&DYNFAM, KVPROD) {
            //
            // The frame belongs to the product family.
            //
            // We expect to see specifications of "from" and "to" frames
            // that make up the product.
            //
            // Look up the "from" and "to" frames that define the product.
            //
            ZZDYNVAC(
                &INNAME,
                INFRAM,
                KWFFRM,
                MXNFAC,
                &mut M,
                FFRAMS.as_arg_mut(),
                ctx,
            )?;
            ZZDYNVAC(
                &INNAME,
                INFRAM,
                KWTFRM,
                MXNFAC,
                &mut N,
                TFRAMS.as_arg_mut(),
                ctx,
            )?;

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

            if (N != M) {
                SETMSG(b"Definition of product parameterized dynamic frame # has # \"from\" frames and # \"to\" frames. These counts must match.", ctx);
                ERRCH(b"#", &INNAME, ctx);
                ERRINT(b"#", M, ctx);
                ERRINT(b"#", N, ctx);
                SIGERR(b"SPICE(BADFRAMECOUNT)", ctx)?;
                CHKOUT(RNAME, ctx)?;
                return Ok(());
            }

            //
            // The product of the factors is the transformation from the
            // base frame to the output frame. We need the inverse of
            // this transformation.
            //
            // Compute the inverse of the product of the factors; place
            // the result in XFORM.
            //
            NAMFRM(&FFRAMS[1], &mut FROMID, ctx)?;
            NAMFRM(&TFRAMS[1], &mut TOID, ctx)?;

            ZZFRMCH0(TOID, FROMID, T0, XFORM.as_slice_mut(), ctx)?;

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

            for I in 2..=N {
                MOVED(XFORM.as_slice(), 36, XFTEMP.as_slice_mut());

                NAMFRM(&FFRAMS[I], &mut FROMID, ctx)?;
                NAMFRM(&TFRAMS[I], &mut TOID, ctx)?;

                ZZFRMCH0(TOID, FROMID, T0, XFORM.as_slice_mut(), ctx)?;

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

                MXMG(
                    XFORM.as_slice(),
                    XFTEMP.as_slice(),
                    6,
                    6,
                    6,
                    XOUT.as_slice_mut(),
                );
                MOVED(XOUT.as_slice(), 36, XFORM.as_slice_mut());
            }
        } else {
            SETMSG(b"Dynamic frame family # (in definition of frame #) is not supported. This situation is usually caused by an error in a frame kernel in which the frame is defined.", ctx);
            ERRCH(b"#", &DYNFAM, ctx);
            ERRCH(b"#", &INNAME, ctx);
            SIGERR(b"SPICE(NOTSUPPORTED)", ctx)?;
            CHKOUT(RNAME, ctx)?;
            return Ok(());
        }
    //
    // This is the end of the IF block that processes the
    // parameterized dynamic frame families.
    //
    } else {
        SETMSG(b"Dynamic frame style # (in definition of frame #) is not supported. This situation is usually caused by an error in a frame kernel in which the frame is defined.", ctx);
        ERRCH(b"#", &DYNSTL, ctx);
        ERRCH(b"#", &INNAME, ctx);
        SIGERR(b"SPICE(NOTSUPPORTED)", ctx)?;
        CHKOUT(RNAME, ctx)?;
        return Ok(());
    }

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

    //
    // At this point XFORM is the state transformation matrix mapping
    // from the input frame INFRAM to the base frame BASFRM.
    //
    // If the frame has rotation state 'INERTIAL', the frame must have
    // zero derivative with respect to any inertial frame. Set the
    // derivative block accordingly.
    //
    if INERT {
        //
        // See whether the base frame is inertial.
        //
        IRFNUM(&BASNAM, &mut J, ctx);

        if (J > 0) {
            //
            // The base frame is  a recognized inertial frame.  Zero
            // out the derivative block.
            //
            for I in 1..=3 {
                CLEARD(3, XFORM.subarray_mut([4, I]));
            }
        } else {
            //
            // The base frame is *not* a recognized inertial frame.
            //
            // Create the state transformation matrix that maps from the
            // defined frame to J2000.  Zero out the derivative block of
            // this matrix.  Convert the resulting matrix to the state
            // transformation from the defined frame to the output frame.
            //
            ZZFRMCH0(*BASFRM, save.J2000, T0, XF2000.as_slice_mut(), ctx)?;

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

            MXMG(
                XF2000.as_slice(),
                XFORM.as_slice(),
                6,
                6,
                6,
                XFTEMP.as_slice_mut(),
            );

            for I in 1..=3 {
                CLEARD(3, XFTEMP.subarray_mut([4, I]));
            }

            //
            // XFTEMP now represents the transformation from a
            // constant frame matching the defined frame at T0 to the
            // J2000 frame. Produce the transformation from this constant
            // frame to the output frame.
            //
            // To avoid introducing additional round-off error into
            // the rotation blocks of XFORM, we overwrite only the
            // derivative block of XFORM with the derivative block
            // of the "inertial" transformation.
            //
            INVSTM(XF2000.as_slice(), XFINV.as_slice_mut(), ctx)?;
            MXMG(
                XFINV.as_slice(),
                XFTEMP.as_slice(),
                6,
                6,
                6,
                XOUT.as_slice_mut(),
            );

            for I in 1..=3 {
                VEQU(XOUT.subarray([4, I]), XFORM.subarray_mut([4, I]));
            }
        }
    }

    //
    // If the frame is frozen, zero out the derivative block of the
    // transformation matrix.
    //
    if FROZEN {
        for I in 1..=3 {
            CLEARD(3, XFORM.subarray_mut([4, I]));
        }
    }

    //
    // XFORM and BASFRM are set.
    //

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