rust-spice 1.0.1

WOW! The complete NASA/NAIF Spice toolkit is actually usable on Rust.
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
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
/*!
A Rust idiomatic CSPICE wrapper built with [procedural macros][`spice_derive`].

## Description

Every routine here mirrors its CSPICE counterpart one for one: the C inputs stay inputs, and the
values the C routine writes through pointers become the Rust return value, in the order CSPICE
declares them. Wrappers that need an explicit buffer size, or a caller allocated
[cell][crate::core::cell::Cell], have a friendlier counterpart in [`neat`][crate::core::neat].
*/

use crate::c::{SpiceChar, SpiceDouble, SpiceInt};
use crate::core::cell::{Cell, CellItem};
use crate::core::ffi::{from_cbuf, from_strided, to_cstring, to_strided};
use crate::core::ffi::{UdBail, UdFunb, UdFunc, UdFuns, UdRefn, UdRepf, UdRepi, UdRepu, UdStep};
use spice_derive::cspice_proc;

#[cfg(any(feature = "lock", doc))]
use {crate::core::lock::SpiceLock, spice_derive::impl_for};

/// A DLA segment descriptor.
#[allow(clippy::upper_case_acronyms)]
pub type DLADSC = crate::c::SpiceDLADescr;

/// A DSK segment descriptor.
#[allow(clippy::upper_case_acronyms)]
pub type DSKDSC = crate::c::SpiceDSKDescr;

/// A plane, as a unit normal and the constant of the plane equation.
#[allow(clippy::upper_case_acronyms)]
pub type PLANE = crate::c::SpicePlane;

/// An ellipse, as a centre and two generating vectors.
#[allow(clippy::upper_case_acronyms)]
pub type ELLIPSE = crate::c::SpiceEllipse;

/// The raw CSPICE cell descriptor; see [`Cell`] for the owning Rust type.
#[allow(clippy::upper_case_acronyms, dead_code)]
pub type CELL = crate::c::SpiceCell;

/* -------------------------------------------------------------------------------------------- */
/* Bodies, names and identifiers                                                                  */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Translate the SPICE integer code of a body into a common name for that body.

    This function has a [neat version][crate::neat::bodc2n].
    */
    pub fn bodc2n(code: i32, #[lenout] lenout: i32) -> (String, bool) {}
}

cspice_proc! {
    /**
    Translate a body ID code to either the corresponding name or, if no name exists, the string
    representation of the code.

    This function has a [neat version][crate::neat::bodc2s].
    */
    pub fn bodc2s(code: i32, #[lenout] lenout: i32) -> String {}
}

cspice_proc! {
    /**
    Determine whether values exist for some item for any body in the kernel pool.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn bodfnd(body: i32, item: &str) -> bool {}
}

cspice_proc! {
    /**
    Translate the name of a body or object to the corresponding SPICE integer ID code.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn bodn2c(name: &str) -> (i32, bool) {}
}

cspice_proc! {
    /**
    Translate a string containing a body name or ID code to an integer code.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn bods2c(name: &str) -> (i32, bool) {}
}

/**
Fetch from the kernel pool the double precision values of an item associated with a body.

At most `maxn` values are returned; the vector is truncated to the number actually found, and is
empty when the item is not in the pool.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn bodvrd(bodynm: &str, item: &str, maxn: usize) -> Vec<f64> {
    let bodynm = to_cstring(bodynm);
    let item = to_cstring(item);
    let mut dim = 0;
    let mut values = vec![0.0; maxn];
    unsafe {
        crate::c::bodvrd_c(
            bodynm.as_ptr() as *mut SpiceChar,
            item.as_ptr() as *mut SpiceChar,
            maxn as SpiceInt,
            &mut dim,
            values.as_mut_ptr(),
        )
    };
    values.truncate(dim.max(0) as usize);
    values
}

/**
Fetch from the kernel pool the double precision values of an item associated with a body.

Deprecated by CSPICE in favour of [`bodvcd`] and [`bodvrd`]: it takes no bound on how much it may
write, so the caller has to know how many values to make room for.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn bodvar(body: i32, item: &str, maxn: usize) -> Vec<f64> {
    let item = to_cstring(item);
    let mut dim = 0;
    let mut values = vec![0.0; maxn];
    unsafe {
        crate::c::bodvar_c(
            body,
            item.as_ptr() as *mut SpiceChar,
            &mut dim,
            values.as_mut_ptr(),
        )
    };
    values.truncate(dim.max(0) as usize);
    values
}

/**
Fetch from the kernel pool the double precision values of an item associated with a body, using the
body's integer ID code.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn bodvcd(bodyid: i32, item: &str, maxn: usize) -> Vec<f64> {
    let item = to_cstring(item);
    let mut dim = 0;
    let mut values = vec![0.0; maxn];
    unsafe {
        crate::c::bodvcd_c(
            bodyid,
            item.as_ptr() as *mut SpiceChar,
            maxn as SpiceInt,
            &mut dim,
            values.as_mut_ptr(),
        )
    };
    values.truncate(dim.max(0) as usize);
    values
}

/* -------------------------------------------------------------------------------------------- */
/* C-kernels                                                                                      */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Find the coverage window for a specified object in a specified CK file.

    This function has a [neat version][crate::neat::ckcov].
    */
    #[allow(clippy::too_many_arguments)]
    pub fn ckcov(
        ck: &str,
        idcode: i32,
        needav: bool,
        level: &str,
        tol: f64,
        timsys: &str,
        cover: &mut Cell<f64>
    ) {}
}

cspice_proc! {
    /**
    Get pointing (attitude) for a specified spacecraft clock time.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ckgp(inst: i32, sclkdp: f64, tol: f64, frame: &str) -> ([[f64; 3]; 3], f64, bool) {}
}

cspice_proc! {
    /**
    Get pointing (attitude) and angular velocity for a spacecraft clock time.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ckgpav(
        inst: i32,
        sclkdp: f64,
        tol: f64,
        frame: &str
    ) -> ([[f64; 3]; 3], [f64; 3], f64, bool) {
    }
}

cspice_proc! {
    /**
    Find the set of ID codes of all objects in a specified CK file.

    This function has a [neat version][crate::neat::ckobj].
    */
    pub fn ckobj(ck: &str, ids: &mut Cell<i32>) {}
}

cspice_proc! {
    /**
    Open a new CK file, returning the handle of the opened file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ckopn(fname: &str, ifname: &str, ncomch: i32) -> i32 {}
}

cspice_proc! {
    /**
    Close an open CK file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ckcls(handle: i32) {}
}

/**
Add a type 3 segment to a CK file.

# Panics

Panics if `nrec` or `nints` is negative, or larger than the arrays it counts: CSPICE reads exactly
that many records and has no way of knowing how long they are.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn ckw03(
    handle: i32,
    begtim: f64,
    endtim: f64,
    inst: i32,
    frame: &str,
    avflag: bool,
    segid: &str,
    nrec: i32,
    sclkdp: &[f64],
    quats: &[[f64; 4]],
    avvs: &[[f64; 3]],
    nints: i32,
    starts: &[f64],
) {
    let records = usize::try_from(nrec).expect("the number of records cannot be negative");
    let intervals = usize::try_from(nints).expect("the number of intervals cannot be negative");
    assert!(
        records <= sclkdp.len() && records <= quats.len(),
        "ckw03 was asked for {records} records but got {} clock times and {} quaternions",
        sclkdp.len(),
        quats.len()
    );
    assert!(
        !avflag || records <= avvs.len(),
        "ckw03 was asked for {records} angular velocities but got {}",
        avvs.len()
    );
    assert!(
        intervals <= starts.len(),
        "ckw03 was asked for {intervals} intervals but got {} start times",
        starts.len()
    );

    let frame = to_cstring(frame);
    let segid = to_cstring(segid);

    unsafe {
        crate::c::ckw03_c(
            handle,
            begtim,
            endtim,
            inst,
            frame.as_ptr() as *mut SpiceChar,
            avflag as crate::c::SpiceBoolean,
            segid.as_ptr() as *mut SpiceChar,
            nrec,
            sclkdp.as_ptr() as *mut SpiceDouble,
            quats.as_ptr() as *mut [SpiceDouble; 4],
            avvs.as_ptr() as *mut [SpiceDouble; 3],
            nints,
            starts.as_ptr() as *mut SpiceDouble,
        );
    }
}

/* -------------------------------------------------------------------------------------------- */
/* DAS, DLA and DSK                                                                               */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Close a DAS file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dascls(handle: i32) {}
}

cspice_proc! {
    /**
    Open a DAS file for reading.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dasopr(fname: &str) -> i32 {}
}

cspice_proc! {
    /**
    Begin a forward segment search in a DLA file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dlabfs(handle: i32) -> (DLADSC, bool) {}
}

cspice_proc! {
    /**
    Begin a backward segment search in a DLA file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dlabbs(handle: i32) -> (DLADSC, bool) {}
}

cspice_proc! {
    /**
    Find the segment following a specified segment in a DLA file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dlafns(handle: i32, dladsc: DLADSC) -> (DLADSC, bool) {}
}

cspice_proc! {
    /**
    Return the DSK descriptor from a DSK segment identified by a DAS handle and DLA descriptor.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dskgd(handle: i32, dladsc: DLADSC) -> DSKDSC {}
}

cspice_proc! {
    /**
    Compute the unit normal vector for a specified plate from a type 2 DSK segment.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dskn02(handle: i32, dladsc: DLADSC, plid: i32) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Find the set of body ID codes of all objects for which topographic data are provided in a
    specified DSK file.

    This function has a [neat version][crate::neat::dskobj].
    */
    pub fn dskobj(dsk: &str, bodids: &mut Cell<i32>) {}
}

cspice_proc! {
    /**
    Find the set of surface ID codes for all surfaces associated with a given body in a specified
    DSK file.

    This function has a [neat version][crate::neat::dsksrf].
    */
    pub fn dsksrf(dsk: &str, bodyid: i32, srfids: &mut Cell<i32>) {}
}

/**
Fetch triangular plates from a type 2 DSK segment.

This function has a [neat version][crate::neat::dskp02].
*/
pub fn dskp02(handle: i32, dladsc: DLADSC, start: usize, room: usize) -> Vec<[i32; 3]> {
    let mut dladsc = dladsc;
    let mut n = 0;
    let mut plates = vec![[0; 3]; room];

    unsafe {
        crate::c::dskp02_c(
            handle,
            &mut dladsc,
            start as SpiceInt,
            room as SpiceInt,
            &mut n,
            plates.as_mut_ptr(),
        );
    }

    plates.truncate(n.max(0) as usize);
    plates
}

/**
Fetch vertices from a type 2 DSK segment.

This function has a [neat version][crate::neat::dskv02].
*/
pub fn dskv02(handle: i32, dladsc: DLADSC, start: usize, room: usize) -> Vec<[f64; 3]> {
    let mut dladsc = dladsc;
    let mut n = 0;
    let mut vrtces = vec![[0.0; 3]; room];

    unsafe {
        crate::c::dskv02_c(
            handle,
            &mut dladsc,
            start as SpiceInt,
            room as SpiceInt,
            &mut n,
            vrtces.as_mut_ptr(),
        );
    }

    vrtces.truncate(n.max(0) as usize);
    vrtces
}

cspice_proc! {
    /**
    Determine the plate ID and body-fixed coordinates of the intersection of a specified ray with
    the surface defined by a type 2 DSK plate model.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dskx02(
        handle: i32,
        dladsc: DLADSC,
        vertex: [f64; 3],
        raydir: [f64; 3]
    ) -> (i32, [f64; 3], bool) {
    }
}

cspice_proc! {
    /**
    Return plate model size parameters---vertex count and plate count---for a type 2 DSK segment.

    Vertices first, plates second.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dskz02(handle: i32, dladsc: DLADSC) -> (i32, i32) {}
}

/// Size of the `dc` output of [`dskxsi`].
pub const DSKXSI_DCSIZE: usize = 1;
/// Size of the `ic` output of [`dskxsi`]; for a type 2 segment `ic[0]` is the plate ID.
pub const DSKXSI_ICSIZE: usize = 1;

/**
Compute a ray-surface intercept using data provided by multiple loaded DSK segments, and return
information about the source of the data defining the surface on which the intercept was found.

`srflst` is the list of surface IDs to consider; leave it empty to let CSPICE choose.
*/
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dskxsi(
    pri: bool,
    target: &str,
    srflst: &[i32],
    et: f64,
    fixref: &str,
    vertex: [f64; 3],
    raydir: [f64; 3],
) -> (
    [f64; 3],
    i32,
    DLADSC,
    DSKDSC,
    [f64; DSKXSI_DCSIZE],
    [i32; DSKXSI_ICSIZE],
    bool,
) {
    let target = to_cstring(target);
    let fixref = to_cstring(fixref);

    let mut xpt = [0.0; 3];
    let mut handle = 0;
    // SAFETY: both descriptors are plain old data, for which all-zero is a valid value.
    let mut dladsc: DLADSC = unsafe { std::mem::zeroed() };
    let mut dskdsc: DSKDSC = unsafe { std::mem::zeroed() };
    let mut dc = [0.0; DSKXSI_DCSIZE];
    let mut ic = [0; DSKXSI_ICSIZE];
    let mut found = 0;

    unsafe {
        crate::c::dskxsi_c(
            pri as crate::c::SpiceBoolean,
            target.as_ptr() as *mut SpiceChar,
            srflst.len() as SpiceInt,
            srflst.as_ptr() as *mut SpiceInt,
            et,
            fixref.as_ptr() as *mut SpiceChar,
            vertex.as_ptr() as *mut SpiceDouble,
            raydir.as_ptr() as *mut SpiceDouble,
            DSKXSI_DCSIZE as SpiceInt,
            DSKXSI_ICSIZE as SpiceInt,
            xpt.as_mut_ptr(),
            &mut handle,
            &mut dladsc,
            &mut dskdsc,
            dc.as_mut_ptr(),
            ic.as_mut_ptr(),
            &mut found,
        );
    }

    (xpt, handle, dladsc, dskdsc, dc, ic, found != 0)
}

/**
Compute ray-surface intercepts for a set of rays, using data provided by multiple loaded DSK
segments.

Returns one intercept and one flag per ray.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dskxv(
    pri: bool,
    target: &str,
    srflst: &[i32],
    et: f64,
    fixref: &str,
    vtxarr: &[[f64; 3]],
    dirarr: &[[f64; 3]],
) -> (Vec<[f64; 3]>, Vec<bool>) {
    let rays = vtxarr.len().min(dirarr.len());
    let target = to_cstring(target);
    let fixref = to_cstring(fixref);

    let mut xptarr = vec![[0.0; 3]; rays];
    let mut fndarr = vec![0 as crate::c::SpiceBoolean; rays];

    unsafe {
        crate::c::dskxv_c(
            pri as crate::c::SpiceBoolean,
            target.as_ptr() as *mut SpiceChar,
            srflst.len() as SpiceInt,
            srflst.as_ptr() as *mut SpiceInt,
            et,
            fixref.as_ptr() as *mut SpiceChar,
            rays as SpiceInt,
            vtxarr.as_ptr() as *mut [f64; 3],
            dirarr.as_ptr() as *mut [f64; 3],
            xptarr.as_mut_ptr(),
            fndarr.as_mut_ptr(),
        );
    }

    (xptarr, fndarr.into_iter().map(|flag| flag != 0).collect())
}

cspice_proc! {
    /**
    Open a new DSK file for subsequent write operations.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dskopn(fname: &str, ifname: &str, ncomch: i32) -> i32 {}
}

cspice_proc! {
    /**
    Close a DSK file, optionally segregating it for faster access.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dskcls(handle: i32, optmiz: bool) {}
}

/// Keyword of the plate expansion fraction, for [`dskgtl`] and [`dskstl`].
pub const DSK_KEYXFR: i32 = 1;
/// Keyword of the greedy segment selection factor.
pub const DSK_KEYSGR: i32 = 2;
/// Keyword of the segment pad margin.
pub const DSK_KEYSPM: i32 = 3;
/// Keyword of the surface point membership margin.
pub const DSK_KEYPTM: i32 = 4;
/// Keyword of the angular rounding margin.
pub const DSK_KEYAMG: i32 = 5;
/// Keyword of the longitude alias margin.
pub const DSK_KEYLAL: i32 = 6;

cspice_proc! {
    /**
    Retrieve the value of a specified DSK tolerance or margin parameter.

    The keyword is one of the `DSK_KEY*` constants of this module.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dskgtl(keywrd: i32) -> f64 {}
}

cspice_proc! {
    /**
    Set the value of a specified DSK tolerance or margin parameter.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dskstl(keywrd: i32, dpval: f64) {}
}

/// Type 2 DSK keywords for [`dskd02`] and [`dski02`]; each belongs to one of the two.
pub mod dsk02 {
    /// Number of vertices in the model, an integer item.
    pub const KWNV: i32 = 1;
    /// Number of plates in the model, an integer item.
    pub const KWNP: i32 = 2;
    /// Total number of voxels in the fine grid, an integer item.
    pub const KWNVXT: i32 = 3;
    /// Voxel grid extent, an integer item.
    pub const KWVGRX: i32 = 4;
    /// Coarse voxel grid scale, an integer item.
    pub const KWCGSC: i32 = 5;
    /// Size of the voxel to plate pointer array, an integer item.
    pub const KWVXPS: i32 = 6;
    /// Voxel-plate correspondence list size, an integer item.
    pub const KWVXLS: i32 = 7;
    /// Vertex-plate correspondence list size, an integer item.
    pub const KWVTLS: i32 = 8;
    /// Plate array, an integer item.
    pub const KWPLAT: i32 = 9;
    /// Voxel-plate pointer list, an integer item.
    pub const KWVXPT: i32 = 10;
    /// Voxel-plate correspondence list, an integer item.
    pub const KWVXPL: i32 = 11;
    /// Vertex-plate pointer list, an integer item.
    pub const KWVTPT: i32 = 12;
    /// Vertex-plate correspondence list, an integer item.
    pub const KWVTPL: i32 = 13;
    /// Coarse voxel grid pointers, an integer item.
    pub const KWCGPT: i32 = 14;
    /// The segment descriptor, a double precision item.
    pub const KWDSC: i32 = 15;
    /// Vertex bounds, a double precision item.
    pub const KWVTBD: i32 = 16;
    /// Voxel grid origin, a double precision item.
    pub const KWVXOR: i32 = 17;
    /// Voxel size, a double precision item.
    pub const KWVXSZ: i32 = 18;
    /// Vertex coordinates, a double precision item.
    pub const KWVERT: i32 = 19;
}

/// Size of the double precision component of a type 2 DSK spatial index.
pub const DSK02_SPADSZ: usize = 10;

/**
Make a spatial index for a DSK type 2 segment, returning its double precision and integer
components.

`spxisz` is the size to allocate for the integer component; see the
[C documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/dskmi2_c.html) for how to
size it and the work array.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dskmi2(
    vrtces: &[[f64; 3]],
    plates: &[[i32; 3]],
    finscl: f64,
    corscl: i32,
    worksz: usize,
    voxpsz: usize,
    voxlsz: usize,
    makvtl: bool,
    spxisz: usize,
) -> (Vec<f64>, Vec<i32>) {
    let mut work = vec![[0; 2]; worksz.max(1)];
    let mut spaixd = vec![0.0; DSK02_SPADSZ];
    let mut spaixi = vec![0; spxisz.max(1)];

    unsafe {
        crate::c::dskmi2_c(
            vrtces.len() as SpiceInt,
            vrtces.as_ptr() as *mut [f64; 3],
            plates.len() as SpiceInt,
            plates.as_ptr() as *mut [SpiceInt; 3],
            finscl,
            corscl,
            worksz as SpiceInt,
            voxpsz as SpiceInt,
            voxlsz as SpiceInt,
            makvtl as SpiceInt,
            spxisz as SpiceInt,
            work.as_mut_ptr(),
            spaixd.as_mut_ptr(),
            spaixi.as_mut_ptr(),
        );
    }

    (spaixd, spaixi)
}

/// Number of coordinate system parameters a DSK descriptor holds.
pub const DSK_NSYPAR: usize = 10;

/**
Write a type 2 segment to a DSK file.

# Panics

Panics if `corpar` holds fewer than [`DSK_NSYPAR`] values: CSPICE reads that many whatever the
coordinate system.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dskw02(
    handle: i32,
    center: i32,
    surfce: i32,
    dclass: i32,
    frame: &str,
    corsys: i32,
    corpar: &[f64],
    mncor1: f64,
    mxcor1: f64,
    mncor2: f64,
    mxcor2: f64,
    mncor3: f64,
    mxcor3: f64,
    first: f64,
    last: f64,
    vrtces: &[[f64; 3]],
    plates: &[[i32; 3]],
    spaixd: &[f64],
    spaixi: &[i32],
) {
    assert!(
        corpar.len() >= DSK_NSYPAR,
        "dskw02 needs {DSK_NSYPAR} coordinate parameters but got {}",
        corpar.len()
    );

    let frame = to_cstring(frame);

    unsafe {
        crate::c::dskw02_c(
            handle,
            center,
            surfce,
            dclass,
            frame.as_ptr() as *mut SpiceChar,
            corsys,
            corpar.as_ptr() as *mut SpiceDouble,
            mncor1,
            mxcor1,
            mncor2,
            mxcor2,
            mncor3,
            mxcor3,
            first,
            last,
            vrtces.len() as SpiceInt,
            vrtces.as_ptr() as *mut [f64; 3],
            plates.len() as SpiceInt,
            plates.as_ptr() as *mut [SpiceInt; 3],
            spaixd.as_ptr() as *mut SpiceDouble,
            spaixi.as_ptr() as *mut SpiceInt,
        );
    }
}

/* -------------------------------------------------------------------------------------------- */
/* Kernel pool                                                                                    */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Load one or more SPICE kernels into a program.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn furnsh(name: &str) {}
}

cspice_proc! {
    /**
    Unload a SPICE kernel.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn unload(name: &str) {}
}

cspice_proc! {
    /**
    Clear the KEEPER subsystem: unload all kernels, clear the kernel pool, and re-initialize the
    subsystem. Existing watches on kernel variables are retained.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn kclear() {}
}

cspice_proc! {
    /**
    Return the current number of kernels that have been loaded via the KEEPER interface that are of
    a specified type.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ktotal(kind: &str) -> i32 {}
}

cspice_proc! {
    /**
    Load the variables contained in a text kernel into the kernel pool.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ldpool(filename: &str) {}
}

cspice_proc! {
    /**
    Remove all variables from the kernel pool.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn clpool() {}
}

cspice_proc! {
    /**
    Confirm the existence of a kernel variable in the kernel pool.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn expool(name: &str) -> bool {}
}

cspice_proc! {
    /**
    Return the data about a kernel pool variable: whether it exists, how many components it has,
    and whether it is numeric (`"N"`) or character (`"C"`).
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dtpool(name: &str) -> (bool, i32, String) {}
}

/**
Return the file name, type, source and handle of a loaded kernel.

This function has a [neat version][crate::neat::kdata].
*/
#[allow(clippy::too_many_arguments)]
pub fn kdata(
    which: i32,
    kind: &str,
    fillen: i32,
    typlen: i32,
    srclen: i32,
) -> (String, String, String, i32, bool) {
    let kind = to_cstring(kind);
    let mut file = vec![0 as SpiceChar; fillen.max(1) as usize];
    let mut filtyp = vec![0 as SpiceChar; typlen.max(1) as usize];
    let mut source = vec![0 as SpiceChar; srclen.max(1) as usize];
    let mut handle = 0;
    let mut found = 0;

    unsafe {
        crate::c::kdata_c(
            which,
            kind.as_ptr() as *mut SpiceChar,
            fillen,
            typlen,
            srclen,
            file.as_mut_ptr(),
            filtyp.as_mut_ptr(),
            source.as_mut_ptr(),
            &mut handle,
            &mut found,
        );
    }

    (
        from_cbuf(&file),
        from_cbuf(&filtyp),
        from_cbuf(&source),
        handle,
        found != 0,
    )
}

/**
Return the type, source and handle of a loaded kernel, given its name.

This function has a [neat version][crate::neat::kinfo].
*/
pub fn kinfo(file: &str, typlen: i32, srclen: i32) -> (String, String, i32, bool) {
    let file = to_cstring(file);
    let mut filtyp = vec![0 as SpiceChar; typlen.max(1) as usize];
    let mut source = vec![0 as SpiceChar; srclen.max(1) as usize];
    let mut handle = 0;
    let mut found = 0;

    unsafe {
        crate::c::kinfo_c(
            file.as_ptr() as *mut SpiceChar,
            typlen,
            srclen,
            filtyp.as_mut_ptr(),
            source.as_mut_ptr(),
            &mut handle,
            &mut found,
        );
    }

    (from_cbuf(&filtyp), from_cbuf(&source), handle, found != 0)
}

/**
Return the double precision values of a kernel pool variable.

The vector is empty when the variable is absent from the pool.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn gdpool(name: &str, start: usize, room: usize) -> Vec<f64> {
    let name = to_cstring(name);
    let mut n = 0;
    let mut values = vec![0.0; room];
    let mut found = 0;

    unsafe {
        crate::c::gdpool_c(
            name.as_ptr() as *mut SpiceChar,
            start as SpiceInt,
            room as SpiceInt,
            &mut n,
            values.as_mut_ptr(),
            &mut found,
        )
    }

    values.truncate(if found != 0 { n.max(0) as usize } else { 0 });
    values
}

/**
Return the integer values of a kernel pool variable.

The vector is empty when the variable is absent from the pool.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn gipool(name: &str, start: usize, room: usize) -> Vec<i32> {
    let name = to_cstring(name);
    let mut n = 0;
    let mut values = vec![0; room];
    let mut found = 0;

    unsafe {
        crate::c::gipool_c(
            name.as_ptr() as *mut SpiceChar,
            start as SpiceInt,
            room as SpiceInt,
            &mut n,
            values.as_mut_ptr(),
            &mut found,
        )
    }

    values.truncate(if found != 0 { n.max(0) as usize } else { 0 });
    values
}

/**
Return the character values of a kernel pool variable.

The vector is empty when the variable is absent from the pool.

This function has a [neat version][crate::neat::gcpool].
*/
pub fn gcpool(name: &str, start: usize, room: usize, lenout: usize) -> Vec<String> {
    let name = to_cstring(name);
    let lenout = lenout.max(1);
    let mut n = 0;
    let mut values = vec![0 as SpiceChar; room * lenout];
    let mut found = 0;

    unsafe {
        crate::c::gcpool_c(
            name.as_ptr() as *mut SpiceChar,
            start as SpiceInt,
            room as SpiceInt,
            lenout as SpiceInt,
            &mut n,
            values.as_mut_ptr().cast(),
            &mut found,
        )
    }

    let count = if found != 0 { n.max(0) as usize } else { 0 };
    (0..count)
        .map(|index| from_cbuf(&values[index * lenout..(index + 1) * lenout]))
        .collect()
}

/**
Set a watch on a set of kernel pool variables for a named agent.

[`cvpool`] then reports whether any of them have been updated since the agent last asked.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn swpool<S: AsRef<str>>(agent: &str, names: &[S]) {
    let agent = to_cstring(agent);
    let (buffer, lenvals) = to_strided(names);
    unsafe {
        crate::c::swpool_c(
            agent.as_ptr() as *mut SpiceChar,
            names.len() as SpiceInt,
            lenvals as SpiceInt,
            buffer.as_ptr().cast(),
        )
    }
}

/**
Return the names of the kernel pool variables matching a template.

The vector is empty when nothing matches.

This function has a [neat version][crate::neat::gnpool].
*/
pub fn gnpool(name: &str, start: usize, room: usize, lenout: usize) -> Vec<String> {
    let name = to_cstring(name);
    let lenout = lenout.max(1);
    let mut buffer = vec![0 as SpiceChar; room.max(1) * lenout];
    let mut n = 0;
    let mut found = 0;

    unsafe {
        crate::c::gnpool_c(
            name.as_ptr() as *mut SpiceChar,
            start as SpiceInt,
            room as SpiceInt,
            lenout as SpiceInt,
            &mut n,
            buffer.as_mut_ptr().cast(),
            &mut found,
        )
    };

    let count = if found != 0 { n.max(0) as usize } else { 0 };
    from_strided(&buffer, lenout, count)
}

/**
Insert double precision values into the kernel pool.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn pdpool(name: &str, values: &[f64]) {
    let name = to_cstring(name);
    unsafe {
        crate::c::pdpool_c(
            name.as_ptr() as *mut SpiceChar,
            values.len() as SpiceInt,
            values.as_ptr() as *mut SpiceDouble,
        )
    }
}

/**
Insert integer values into the kernel pool.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn pipool(name: &str, values: &[i32]) {
    let name = to_cstring(name);
    unsafe {
        crate::c::pipool_c(
            name.as_ptr() as *mut SpiceChar,
            values.len() as SpiceInt,
            values.as_ptr() as *mut SpiceInt,
        )
    }
}

/**
Insert character values into the kernel pool.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn pcpool<S: AsRef<str>>(name: &str, values: &[S]) {
    let name = to_cstring(name);
    let (buffer, lenvals) = to_strided(values);

    unsafe {
        crate::c::pcpool_c(
            name.as_ptr() as *mut SpiceChar,
            values.len() as SpiceInt,
            lenvals as SpiceInt,
            buffer.as_ptr().cast(),
        )
    }
}

/* -------------------------------------------------------------------------------------------- */
/* Time                                                                                           */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Convert a string representing an epoch to a double precision value representing the number of
    TDB seconds past the J2000 epoch corresponding to the input epoch.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn str2et(targ: &str) -> f64 {}
}

cspice_proc! {
    /**
    Convert an input time from UTC seconds past the J2000 epoch to ephemeris seconds past J2000.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn utc2et(utcstr: &str) -> f64 {}
}

cspice_proc! {
    /**
    Convert an input epoch, in ephemeris seconds past J2000, to a UTC string.

    This function has a [neat version][crate::neat::et2utc].
    */
    pub fn et2utc(et: f64, format: &str, prec: i32, #[lenout] lenout: i32) -> String {}
}

cspice_proc! {
    /**
    Convert an input epoch represented in TDB seconds past the TDB epoch of J2000 to a character
    string formatted to the specifications of a user's format picture.

    This function has a [neat version][crate::neat::timout].
    */
    pub fn timout(et: f64, pictur: &str, #[lenout] lenout: i32) -> String {}
}

cspice_proc! {
    /**
    Parse a time string and return the number of seconds past the J2000 epoch on a formal calendar,
    together with the error message CSPICE produced, empty when the parse succeeded.

    This function has a [neat version][crate::neat::tparse].
    */
    pub fn tparse(string: &str, #[lenout] lenout: i32) -> (f64, String) {}
}

cspice_proc! {
    /**
    Return the value of Delta ET (ET-UTC) for an input epoch.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn deltet(epoch: f64, eptype: &str) -> f64 {}
}

cspice_proc! {
    /**
    Transform time from one uniform scale to another. The uniform time scales are TAI, GPS, TT, TDT,
    TDB, ET, JED, JDTDB, JDTDT.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn unitim(epoch: f64, insys: &str, outsys: &str) -> f64 {}
}

cspice_proc! {
    /**
    Convert ephemeris seconds past J2000 to continuous encoded spacecraft clock ticks.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn sce2c(sc: i32, et: f64) -> f64 {}
}

cspice_proc! {
    /**
    Convert ephemeris seconds past J2000 to a spacecraft clock string.

    This function has a [neat version][crate::neat::sce2s].
    */
    pub fn sce2s(sc: i32, et: f64, #[lenout] sclklen: i32) -> String {}
}

cspice_proc! {
    /**
    Encode a character representation of spacecraft clock time into a double precision number.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn scencd(sc: i32, sclkch: &str) -> f64 {}
}

cspice_proc! {
    /**
    Convert a double precision encoding of spacecraft clock time into a character representation.

    This function has a [neat version][crate::neat::scdecd].
    */
    pub fn scdecd(sc: i32, sclkdp: f64, #[lenout] sclklen: i32) -> String {}
}

cspice_proc! {
    /**
    Convert a spacecraft clock string to ephemeris seconds past J2000.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn scs2e(sc: i32, sclkch: &str) -> f64 {}
}

cspice_proc! {
    /**
    Convert encoded spacecraft clock ticks to ephemeris seconds past J2000.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn sct2e(sc: i32, sclkdp: f64) -> f64 {}
}

cspice_proc! {
    /**
    Compute L_s, the planetocentric longitude of the sun, as seen from a specified body.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn lspcn(body: &str, et: f64, abcorr: &str) -> f64 {}
}

/* -------------------------------------------------------------------------------------------- */
/* Frames                                                                                         */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Return the matrix that transforms position vectors from one specified frame to another at a
    specified epoch.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn pxform(from: &str, to: &str, et: f64) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Return the 3x3 matrix that transforms position vectors from one specified frame at a specified
    epoch to another specified frame at another specified epoch.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn pxfrm2(from: &str, to: &str, etfrom: f64, etto: f64) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Return the 6x6 state transformation matrix from one frame to another at a specified epoch.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn sxform(from: &str, to: &str, et: f64) -> [[f64; 6]; 6] {}
}

cspice_proc! {
    /**
    Look up the frame ID code associated with a frame name; zero when the name is not recognised.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn namfrm(frname: &str) -> i32 {}
}

cspice_proc! {
    /**
    Look up the name of a reference frame associated with an ID code.

    This function has a [neat version][crate::neat::frmnam].
    */
    pub fn frmnam(frcode: i32, #[lenout] lenout: i32) -> String {}
}

/* -------------------------------------------------------------------------------------------- */
/* Coordinates                                                                                    */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Convert geodetic coordinates to rectangular coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn georec(lon: f64, lat: f64, alt: f64, re: f64, f: f64) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Convert rectangular coordinates to geodetic coordinates, as longitude, latitude and altitude.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn recgeo(rectan: [f64; 3], re: f64, f: f64) -> (f64, f64, f64) {}
}

cspice_proc! {
    /**
    Convert from latitudinal coordinates to rectangular coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn latrec(radius: f64, longitude: f64, latitude: f64) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Convert from rectangular coordinates to latitudinal coordinates, as radius, longitude and
    latitude.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn reclat(rectan: [f64; 3]) -> (f64, f64, f64) {}
}

cspice_proc! {
    /**
    Convert from spherical coordinates to rectangular coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn sphrec(r: f64, colat: f64, lon: f64) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Convert from rectangular coordinates to spherical coordinates, as radius, colatitude and
    longitude.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn recsph(rectan: [f64; 3]) -> (f64, f64, f64) {}
}

cspice_proc! {
    /**
    Convert from cylindrical coordinates to rectangular coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn cylrec(r: f64, lon: f64, z: f64) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Convert from rectangular coordinates to cylindrical coordinates, as radius, longitude and `z`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn reccyl(rectan: [f64; 3]) -> (f64, f64, f64) {}
}

cspice_proc! {
    /**
    Convert planetographic coordinates to rectangular coordinates.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn pgrrec(body: &str, lon: f64, lat: f64, alt: f64, re: f64, f: f64) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Convert rectangular coordinates to planetographic coordinates, as longitude, latitude and
    altitude.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn recpgr(body: &str, rectan: [f64; 3], re: f64, f: f64) -> (f64, f64, f64) {}
}

cspice_proc! {
    /**
    Convert range, right ascension, and declination to rectangular coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn radrec(range: f64, ra: f64, dec: f64) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Convert rectangular coordinates to range, right ascension, and declination.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn recrad(rectan: [f64; 3]) -> (f64, f64, f64) {}
}

cspice_proc! {
    /**
    Convert planetocentric latitude and longitude of a surface point on a specified body to
    rectangular coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn srfrec(body: i32, lon: f64, lat: f64) -> [f64; 3] {}
}

/* -------------------------------------------------------------------------------------------- */
/* Vectors and matrices                                                                           */

cspice_proc! {
    /**
    Pack three scalars into a vector.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vpack(x: f64, y: f64, z: f64) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Unpack a vector into three scalars.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vupack(v: [f64; 3]) -> (f64, f64, f64) {}
}

cspice_proc! {
    /**
    Whether a vector is the zero vector.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vzero(v: [f64; 3]) -> bool {}
}

cspice_proc! {
    /**
    The component of `a` perpendicular to `b`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vperp(a: [f64; 3], b: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    The projection of `a` onto `b`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vproj(a: [f64; 3], b: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Rotate a vector about an axis by a given angle.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vrotv(v: [f64; 3], axis: [f64; 3], theta: f64) -> [f64; 3] {}
}

cspice_proc! {
    /**
    The linear combination `a * v1 + b * v2`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vlcom(a: f64, v1: [f64; 3], b: f64, v2: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    The linear combination `a * v1 + b * v2 + c * v3`.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vlcom3(
        a: f64,
        v1: [f64; 3],
        b: f64,
        v2: [f64; 3],
        c: f64,
        v3: [f64; 3]
    ) -> [f64; 3] {
    }
}

cspice_proc! {
    /**
    The quadratic form `v1 * matrix * v2`.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vtmv(v1: [f64; 3], matrix: [[f64; 3]; 3], v2: [f64; 3]) -> f64 {}
}

cspice_proc! {
    /**
    The 3x3 identity matrix.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ident() -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Copy a 3x3 matrix.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn mequ(m1: [[f64; 3]; 3]) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Transpose a 6x6 matrix.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn xpose6(m1: [[f64; 6]; 6]) -> [[f64; 6]; 6] {}
}

/* -------------------------------------------------------------------------------------------- */
/* Vectors and matrices of arbitrary dimension                                                    */
/* -------------------------------------------------------------------------------------------- */

/*
CSPICE takes the dimensions as separate arguments and writes the result through a bare pointer, so
these cannot go through the macro: the length of the output is only known at run time. Each wrapper
takes the dimensions from the slices it is given and sizes the result itself.
*/

/// Generate the wrappers of the `v*g` routines that map one or two vectors to another.
macro_rules! vector_g {
    ($($name:ident($($arg:ident),*) => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// # Panics
        ///
        /// Panics if the vectors have different lengths.
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name($($arg: &[f64]),*) -> Vec<f64> {
            let ndim = same_length(&[$($arg),*]);
            let mut vout = vec![0.0; ndim];
            unsafe {
                crate::c::$cname(
                    $($arg.as_ptr() as *mut SpiceDouble,)*
                    ndim as SpiceInt,
                    vout.as_mut_ptr(),
                );
            }
            vout
        }
    )*};
}

/// Generate the wrappers of the `v*g` routines that reduce one or two vectors to a scalar.
macro_rules! scalar_g {
    ($($name:ident($($arg:ident),*) -> $ret:ty => $cname:ident, $conv:expr, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// # Panics
        ///
        /// Panics if the vectors have different lengths.
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name($($arg: &[f64]),*) -> $ret {
            let ndim = same_length(&[$($arg),*]);
            let returned = unsafe {
                crate::c::$cname($($arg.as_ptr() as *mut SpiceDouble,)* ndim as SpiceInt)
            };
            #[allow(clippy::redundant_closure_call)]
            ($conv)(returned)
        }
    )*};
}

/// The common length of a set of slices.
fn same_length(slices: &[&[f64]]) -> usize {
    let ndim = slices[0].len();
    assert!(
        slices.iter().all(|slice| slice.len() == ndim),
        "the vectors must all have the same length, got {:?}",
        slices.iter().map(|slice| slice.len()).collect::<Vec<_>>()
    );
    ndim
}

vector_g! {
    vaddg(v1, v2) => vaddg_c, "Add two vectors of arbitrary dimension.";
    vsubg(v1, v2) => vsubg_c, "Subtract one vector of arbitrary dimension from another.";
    vhatg(v1) => vhatg_c, "The unit vector along a vector of arbitrary dimension.";
    vequg(vin) => vequg_c, "Copy a vector of arbitrary dimension.";
    vminug(vin) => vminug_c, "Negate a vector of arbitrary dimension.";
    vprojg(a, b) => vprojg_c, "The projection of one vector onto another, in arbitrary dimension.";
}

scalar_g! {
    vdotg(v1, v2) -> f64 => vdotg_c, |value| value,
        "The dot product of two vectors of arbitrary dimension.";
    vnormg(v1) -> f64 => vnormg_c, |value| value,
        "The magnitude of a vector of arbitrary dimension.";
    vdistg(v1, v2) -> f64 => vdistg_c, |value| value,
        "The distance between two vectors of arbitrary dimension.";
    vrelg(v1, v2) -> f64 => vrelg_c, |value| value,
        "The relative difference between two vectors of arbitrary dimension.";
    vsepg(v1, v2) -> f64 => vsepg_c, |value| value,
        "The angular separation of two vectors of arbitrary dimension.";
    vzerog(v) -> bool => vzerog_c, |value: crate::c::SpiceBoolean| value != 0,
        "Whether a vector of arbitrary dimension is the zero vector.";
}

/**
Scale a vector of arbitrary dimension.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn vsclg(s: f64, v1: &[f64]) -> Vec<f64> {
    let mut vout = vec![0.0; v1.len()];
    unsafe {
        crate::c::vsclg_c(
            s,
            v1.as_ptr() as *mut SpiceDouble,
            v1.len() as SpiceInt,
            vout.as_mut_ptr(),
        )
    };
    vout
}

/**
Normalize a vector of arbitrary dimension, returning the unit vector and the original magnitude.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn unormg(v1: &[f64]) -> (Vec<f64>, f64) {
    let mut vout = vec![0.0; v1.len()];
    let mut vmag = 0.0;
    unsafe {
        crate::c::unormg_c(
            v1.as_ptr() as *mut SpiceDouble,
            v1.len() as SpiceInt,
            vout.as_mut_ptr(),
            &mut vmag,
        )
    };
    (vout, vmag)
}

/**
The linear combination `a * v1 + b * v2`, in arbitrary dimension.

# Panics

Panics if the vectors have different lengths.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn vlcomg(a: f64, v1: &[f64], b: f64, v2: &[f64]) -> Vec<f64> {
    let ndim = same_length(&[v1, v2]);
    let mut sum = vec![0.0; ndim];
    unsafe {
        crate::c::vlcomg_c(
            ndim as SpiceInt,
            a,
            v1.as_ptr() as *mut SpiceDouble,
            b,
            v2.as_ptr() as *mut SpiceDouble,
            sum.as_mut_ptr(),
        )
    };
    sum
}

/**
Copy `ndim` elements of an array.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn moved(arrfrm: &[f64]) -> Vec<f64> {
    let mut arrto = vec![0.0; arrfrm.len()];
    unsafe {
        crate::c::moved_c(
            arrfrm.as_ptr() as *mut SpiceDouble,
            arrfrm.len() as SpiceInt,
            arrto.as_mut_ptr(),
        )
    };
    arrto
}

/**
The quadratic form `v1 * matrix * v2`, in arbitrary dimension.

`matrix` is `nrow` by `ncol`, stored row by row.

# Panics

Panics if the lengths do not match the dimensions.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn vtmvg(v1: &[f64], matrix: &[f64], v2: &[f64], nrow: usize, ncol: usize) -> f64 {
    assert_matrix(matrix, nrow, ncol);
    assert!(
        v1.len() == nrow && v2.len() == ncol,
        "vtmvg needs a vector of {nrow} and one of {ncol}, got {} and {}",
        v1.len(),
        v2.len()
    );

    unsafe {
        crate::c::vtmvg_c(
            v1.as_ptr().cast(),
            matrix.as_ptr().cast(),
            v2.as_ptr().cast(),
            nrow as SpiceInt,
            ncol as SpiceInt,
        )
    }
}

/// Check that a slice holds a `rows` by `cols` matrix, stored row by row.
fn assert_matrix(matrix: &[f64], rows: usize, cols: usize) {
    assert!(
        matrix.len() == rows * cols,
        "a {rows}x{cols} matrix needs {} elements, got {}",
        rows * cols,
        matrix.len()
    );
}

/*
CSPICE names the dimensions of these after what they mean rather than after their position, and
the meaning differs between the three. Spelling them out, and asserting the shapes, is the only way
a caller can tell what to pass: getting `mtxmg` wrong the other way round produces a plausible
looking matrix rather than an error.
*/

/**
Multiply a `nr1` by `nc1r2` matrix with a `nc1r2` by `nc2` one, giving `nr1` by `nc2`.

The matrices are stored row by row.

# Panics

Panics if the slice lengths do not match the dimensions.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn mxmg(m1: &[f64], m2: &[f64], nr1: usize, nc1r2: usize, nc2: usize) -> Vec<f64> {
    assert_matrix(m1, nr1, nc1r2);
    assert_matrix(m2, nc1r2, nc2);
    let mut mout = vec![0.0; nr1 * nc2];
    unsafe {
        crate::c::mxmg_c(
            m1.as_ptr().cast(),
            m2.as_ptr().cast(),
            nr1 as SpiceInt,
            nc1r2 as SpiceInt,
            nc2 as SpiceInt,
            mout.as_mut_ptr().cast(),
        )
    };
    mout
}

/**
Multiply the transpose of a `nr1r2` by `nc1` matrix with a `nr1r2` by `nc2` one, giving `nc1` by
`nc2`.

The matrices are stored row by row.

# Panics

Panics if the slice lengths do not match the dimensions.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn mtxmg(m1: &[f64], m2: &[f64], nc1: usize, nr1r2: usize, nc2: usize) -> Vec<f64> {
    assert_matrix(m1, nr1r2, nc1);
    assert_matrix(m2, nr1r2, nc2);
    let mut mout = vec![0.0; nc1 * nc2];
    unsafe {
        crate::c::mtxmg_c(
            m1.as_ptr().cast(),
            m2.as_ptr().cast(),
            nc1 as SpiceInt,
            nr1r2 as SpiceInt,
            nc2 as SpiceInt,
            mout.as_mut_ptr().cast(),
        )
    };
    mout
}

/**
Multiply a `nr1` by `nc1c2` matrix with the transpose of a `nr2` by `nc1c2` one, giving `nr1` by
`nr2`.

The matrices are stored row by row.

# Panics

Panics if the slice lengths do not match the dimensions.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn mxmtg(m1: &[f64], m2: &[f64], nr1: usize, nc1c2: usize, nr2: usize) -> Vec<f64> {
    assert_matrix(m1, nr1, nc1c2);
    assert_matrix(m2, nr2, nc1c2);
    let mut mout = vec![0.0; nr1 * nr2];
    unsafe {
        crate::c::mxmtg_c(
            m1.as_ptr().cast(),
            m2.as_ptr().cast(),
            nr1 as SpiceInt,
            nc1c2 as SpiceInt,
            nr2 as SpiceInt,
            mout.as_mut_ptr().cast(),
        )
    };
    mout
}

/**
Multiply a matrix by a vector, in arbitrary dimension.

`m1` is `nrow1` by `nc1r2`, stored row by row.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn mxvg(m1: &[f64], v2: &[f64], nrow1: usize, nc1r2: usize) -> Vec<f64> {
    assert_matrix(m1, nrow1, nc1r2);
    assert_matrix(v2, nc1r2, 1);
    let mut vout = vec![0.0; nrow1];
    unsafe {
        crate::c::mxvg_c(
            m1.as_ptr().cast(),
            v2.as_ptr().cast(),
            nrow1 as SpiceInt,
            nc1r2 as SpiceInt,
            vout.as_mut_ptr().cast(),
        )
    };
    vout
}

/**
Multiply the transpose of a matrix by a vector, in arbitrary dimension.

`m1` is `nr1r2` by `ncol1`, stored row by row.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn mtxvg(m1: &[f64], v2: &[f64], ncol1: usize, nr1r2: usize) -> Vec<f64> {
    assert_matrix(m1, nr1r2, ncol1);
    assert_matrix(v2, nr1r2, 1);
    let mut vout = vec![0.0; ncol1];
    unsafe {
        crate::c::mtxvg_c(
            m1.as_ptr().cast(),
            v2.as_ptr().cast(),
            ncol1 as SpiceInt,
            nr1r2 as SpiceInt,
            vout.as_mut_ptr().cast(),
        )
    };
    vout
}

/**
Transpose a matrix of arbitrary dimension, stored row by row.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn xposeg(matrix: &[f64], nrow: usize, ncol: usize) -> Vec<f64> {
    assert_matrix(matrix, nrow, ncol);
    let mut xposem = vec![0.0; nrow * ncol];
    unsafe {
        crate::c::xposeg_c(
            matrix.as_ptr().cast(),
            nrow as SpiceInt,
            ncol as SpiceInt,
            xposem.as_mut_ptr().cast(),
        )
    };
    xposem
}

/**
Copy a matrix of arbitrary dimension, stored row by row.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn mequg(m1: &[f64], nr: usize, nc: usize) -> Vec<f64> {
    assert_matrix(m1, nr, nc);
    let mut mout = vec![0.0; nr * nc];
    unsafe {
        crate::c::mequg_c(
            m1.as_ptr().cast(),
            nr as SpiceInt,
            nc as SpiceInt,
            mout.as_mut_ptr().cast(),
        )
    };
    mout
}

/* -------------------------------------------------------------------------------------------- */
/* Coordinate conversions between non-rectangular systems                                         */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Convert from latitudinal to cylindrical coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn latcyl(radius: f64, lon: f64, lat: f64) -> (f64, f64, f64) {}
}

cspice_proc! {
    /**
    Convert from cylindrical to latitudinal coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn cyllat(r: f64, lonc: f64, z: f64) -> (f64, f64, f64) {}
}

cspice_proc! {
    /**
    Convert from latitudinal to spherical coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn latsph(radius: f64, lon: f64, lat: f64) -> (f64, f64, f64) {}
}

cspice_proc! {
    /**
    Convert from spherical to latitudinal coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn sphlat(r: f64, colat: f64, lons: f64) -> (f64, f64, f64) {}
}

cspice_proc! {
    /**
    Convert from cylindrical to spherical coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn cylsph(r: f64, lonc: f64, z: f64) -> (f64, f64, f64) {}
}

cspice_proc! {
    /**
    Convert from spherical to cylindrical coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn sphcyl(radius: f64, colat: f64, slon: f64) -> (f64, f64, f64) {}
}

cspice_proc! {
    /**
    Convert from range, azimuth and elevation to rectangular coordinates.

    `azccw` says whether azimuth increases counterclockwise, `elplsz` whether elevation is positive
    toward `+z`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn azlrec(range: f64, az: f64, el: f64, azccw: bool, elplsz: bool) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Convert from rectangular coordinates to range, azimuth and elevation.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn recazl(rectan: [f64; 3], azccw: bool, elplsz: bool) -> (f64, f64, f64) {}
}

/* -------------------------------------------------------------------------------------------- */
/* Jacobians of the coordinate conversions                                                        */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Jacobian of the transformation from rectangular to latitudinal coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dlatdr(x: f64, y: f64, z: f64) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Jacobian of the transformation from latitudinal to rectangular coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn drdlat(r: f64, lon: f64, lat: f64) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Jacobian of the transformation from rectangular to spherical coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dsphdr(x: f64, y: f64, z: f64) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Jacobian of the transformation from spherical to rectangular coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn drdsph(r: f64, colat: f64, lon: f64) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Jacobian of the transformation from rectangular to cylindrical coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dcyldr(x: f64, y: f64, z: f64) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Jacobian of the transformation from cylindrical to rectangular coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn drdcyl(r: f64, lon: f64, z: f64) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Jacobian of the transformation from rectangular to geodetic coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dgeodr(x: f64, y: f64, z: f64, re: f64, f: f64) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Jacobian of the transformation from geodetic to rectangular coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn drdgeo(lon: f64, lat: f64, alt: f64, re: f64, f: f64) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Jacobian of the transformation from rectangular to planetographic coordinates.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dpgrdr(body: &str, x: f64, y: f64, z: f64, re: f64, f: f64) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Jacobian of the transformation from planetographic to rectangular coordinates.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn drdpgr(body: &str, lon: f64, lat: f64, alt: f64, re: f64, f: f64) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Jacobian of the transformation from rectangular to azimuth/elevation coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dazldr(x: f64, y: f64, z: f64, azccw: bool, elplsz: bool) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Jacobian of the transformation from azimuth/elevation to rectangular coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn drdazl(range: f64, az: f64, el: f64, azccw: bool, elplsz: bool) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Transform a state between two coordinate systems.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn xfmsta(
        input_state: [f64; 6],
        input_coord_sys: &str,
        output_coord_sys: &str,
        body: &str
    ) -> [f64; 6] {
    }
}

/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Add two 3-dimensional vectors.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vadd(v1: [f64; 3], v2: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Subtract one 3-dimensional vector from another.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vsub(v1: [f64; 3], v2: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Multiply a 3-dimensional vector by a scalar.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vscl(s: f64, v1: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Copy a 3-dimensional vector.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vequ(vin: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Negate a 3-dimensional vector.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vminus(v1: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Find the unit vector along a 3-dimensional vector.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vhat(v1: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Normalize a 3-dimensional vector, returning the unit vector and the original magnitude.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn unorm(v1: [f64; 3]) -> ([f64; 3], f64) {}
}

cspice_proc! {
    /**
    Compute the magnitude of a 3-dimensional vector.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vnorm(v1: [f64; 3]) -> f64 {}
}

cspice_proc! {
    /**
    Compute the distance between two 3-dimensional vectors.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vdist(v1: [f64; 3], v2: [f64; 3]) -> f64 {}
}

cspice_proc! {
    /**
    Compute the relative difference between two 3-dimensional vectors.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vrel(v1: [f64; 3], v2: [f64; 3]) -> f64 {}
}

cspice_proc! {
    /**
    Compute the dot product of two double precision, 3-dimensional vectors.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vdot(v1: [f64; 3], v2: [f64; 3]) -> f64 {}
}

cspice_proc! {
    /**
    Compute the cross product of two 3-dimensional vectors.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vcrss(v1: [f64; 3], v2: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Find the separation angle in radians between two double precision, 3-dimensional vectors. This
    angle is defined as zero if either vector is zero.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vsep(v1: [f64; 3], v2: [f64; 3]) -> f64 {}
}

cspice_proc! {
    /**
    Multiply a 3x3 double precision matrix with a 3-dimensional double precision vector.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn mxv(m1: [[f64; 3]; 3], vin: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Multiply the transpose of a 3x3 matrix with a 3-dimensional vector.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn mtxv(m1: [[f64; 3]; 3], vin: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Multiply two 3x3 matrices.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn mxm(m1: [[f64; 3]; 3], m2: [[f64; 3]; 3]) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Multiply a 3x3 matrix by the transpose of another.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn mxmt(m1: [[f64; 3]; 3], m2: [[f64; 3]; 3]) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Multiply the transpose of a 3x3 matrix by another 3x3 matrix.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn mtxm(m1: [[f64; 3]; 3], m2: [[f64; 3]; 3]) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Transpose a 3x3 matrix.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn xpose(m1: [[f64; 3]; 3]) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Invert a 3x3 matrix.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn invert(m1: [[f64; 3]; 3]) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Compute the determinant of a 3x3 matrix.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn det(m1: [[f64; 3]; 3]) -> f64 {}
}

cspice_proc! {
    /**
    Compute the trace of a 3x3 matrix.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn trace(matrix: [[f64; 3]; 3]) -> f64 {}
}

cspice_proc! {
    /**
    Find the transformation to the right-handed frame having a given vector as a specified axis and
    a second given vector lying in a specified coordinate plane.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn twovec(axdef: [f64; 3], indexa: i32, plndef: [f64; 3], indexp: i32) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Calculate the 3x3 rotation matrix generated by a rotation of a specified angle about a specified
    axis. This rotation is thought of as rotating the coordinate system.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn rotate(angle: f64, iaxis: i32) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Apply a rotation of `angle` radians about axis `iaxis` to a matrix.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn rotmat(m1: [[f64; 3]; 3], angle: f64, iaxis: i32) -> [[f64; 3]; 3] {}
}

/* -------------------------------------------------------------------------------------------- */
/* Rotations                                                                                      */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Find the unit quaternion corresponding to a specified rotation matrix.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn m2q(r: [[f64; 3]; 3]) -> [f64; 4] {}
}

cspice_proc! {
    /**
    Find the rotation matrix corresponding to a specified unit quaternion.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn q2m(q: [f64; 4]) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Multiply two quaternions.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn qxq(q1: [f64; 4], q2: [f64; 4]) -> [f64; 4] {}
}

cspice_proc! {
    /**
    Construct a rotation matrix that rotates vectors by a specified angle about a specified axis.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn axisar(axis: [f64; 3], angle: f64) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Compute the axis of the rotation a matrix represents, and the angle about that axis.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn raxisa(matrix: [[f64; 3]; 3]) -> ([f64; 3], f64) {}
}

cspice_proc! {
    /**
    Construct a rotation matrix from a set of Euler angles.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn eul2m(
        angle3: f64,
        angle2: f64,
        angle1: f64,
        axis3: i32,
        axis2: i32,
        axis1: i32
    ) -> [[f64; 3]; 3] {
    }
}

cspice_proc! {
    /**
    Factor a rotation matrix as a product of three rotations about specified coordinate axes,
    returning the three angles in the order `angle3, angle2, angle1`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn m2eul(r: [[f64; 3]; 3], axis3: i32, axis2: i32, axis1: i32) -> (f64, f64, f64) {}
}

cspice_proc! {
    /**
    Construct a state transformation matrix from a set of Euler angles and their derivatives.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn eul2xf(eulang: [f64; 6], axisa: i32, axisb: i32, axisc: i32) -> [[f64; 6]; 6] {}
}

cspice_proc! {
    /**
    Factor a state transformation matrix into Euler angles and their derivatives.

    The boolean says whether the factorisation is unique.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn xf2eul(xform: [[f64; 6]; 6], axisa: i32, axisb: i32, axisc: i32) -> ([f64; 6], bool) {}
}

cspice_proc! {
    /**
    Split a state transformation matrix into a rotation and the angular velocity of that rotation.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn xf2rav(xform: [[f64; 6]; 6]) -> ([[f64; 3]; 3], [f64; 3]) {}
}

cspice_proc! {
    /**
    Build a state transformation matrix from a rotation and an angular velocity.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn rav2xf(rot: [[f64; 3]; 3], av: [f64; 3]) -> [[f64; 6]; 6] {}
}

cspice_proc! {
    /**
    Compute the inverse of a 3x3 matrix whose rows are orthogonal but not necessarily unit length.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn invort(m: [[f64; 3]; 3]) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Decide whether a matrix is a rotation matrix, to within the given norm and determinant
    tolerances.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn isrot(m: [[f64; 3]; 3], ntol: f64, dtol: f64) -> bool {}
}

/* -------------------------------------------------------------------------------------------- */
/* SPK                                                                                            */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Return the position of a target body relative to an observing body, optionally corrected for
    light time (planetary aberration) and stellar aberration.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkpos(targ: &str, et: f64, frame: &str, abcorr: &str, obs: &str) -> ([f64; 3], f64) {}
}

cspice_proc! {
    /**
    Return the state (position and velocity) of a target body relative to an observing body,
    optionally corrected for light time (planetary aberration) and stellar aberration.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkezr(targ: &str, et: f64, frame: &str, abcorr: &str, obs: &str) -> ([f64; 6], f64) {}
}

cspice_proc! {
    /**
    Return the state of a target body relative to an observing body, both given by their ID codes.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkez(targ: i32, et: f64, frame: &str, abcorr: &str, obs: i32) -> ([f64; 6], f64) {}
}

cspice_proc! {
    /**
    Return the position of a target body relative to an observing body, both given by their ID
    codes.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkezp(targ: i32, et: f64, frame: &str, abcorr: &str, obs: i32) -> ([f64; 3], f64) {}
}

cspice_proc! {
    /**
    Compute the geometric state of a target body relative to an observing body.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkgeo(targ: i32, et: f64, frame: &str, obs: i32) -> ([f64; 6], f64) {}
}

cspice_proc! {
    /**
    Return the state of a specified target relative to an observer that is described by a constant
    position in a specified reference frame.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkcpo(
        target: &str,
        et: f64,
        outref: &str,
        refloc: &str,
        abcorr: &str,
        obssta: [f64; 6],
        obsctr: &str,
        obsref: &str
    ) -> ([f64; 6], f64) {
    }
}

cspice_proc! {
    /**
    Return the state of a target that is described by a constant position in a specified reference
    frame, relative to a specified observer.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkcpt(
        trgpos: [f64; 3],
        trgctr: &str,
        trgref: &str,
        et: f64,
        outref: &str,
        refloc: &str,
        abcorr: &str,
        obsrvr: &str
    ) -> ([f64; 6], f64) {
    }
}

cspice_proc! {
    /**
    Return the state of a specified target relative to an observer that is described by a constant
    velocity in a specified reference frame.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkcvo(
        target: &str,
        et: f64,
        outref: &str,
        refloc: &str,
        abcorr: &str,
        obssta: [f64; 6],
        obsepc: f64,
        obsctr: &str,
        obsref: &str
    ) -> ([f64; 6], f64) {
    }
}

cspice_proc! {
    /**
    Return the state of a target that is described by a constant velocity in a specified reference
    frame, relative to a specified observer.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkcvt(
        trgsta: [f64; 6],
        trgepc: f64,
        trgctr: &str,
        trgref: &str,
        et: f64,
        outref: &str,
        refloc: &str,
        abcorr: &str,
        obsrvr: &str
    ) -> ([f64; 6], f64) {
    }
}

cspice_proc! {
    /**
    Find the set of ID codes of all objects in a specified SPK file.

    This function has a [neat version][crate::neat::spkobj].
    */
    pub fn spkobj(spk: &str, ids: &mut Cell<i32>) {}
}

cspice_proc! {
    /**
    Find the coverage window for a specified ephemeris object in a specified SPK file.

    This function has a [neat version][crate::neat::spkcov].
    */
    pub fn spkcov(spk: &str, idcode: i32, cover: &mut Cell<f64>) {}
}

cspice_proc! {
    /**
    Create a new SPK file, returning the handle of the opened file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkopn(fname: &str, ifname: &str, ncomch: i32) -> i32 {}
}

cspice_proc! {
    /**
    Open an existing SPK file for subsequent write, returning its handle.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkopa(fname: &str) -> i32 {}
}

cspice_proc! {
    /**
    Close a SPK file opened for read or write.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkcls(handle: i32) {}
}

/**
Write a type 9 segment to an SPK file.

# Panics

Panics if `n` is negative, or larger than `states` or `epochs`: CSPICE reads exactly `n` records
from each and has no way of knowing how long they are.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn spkw09(
    handle: i32,
    body: i32,
    center: i32,
    frame: &str,
    first: f64,
    last: f64,
    segid: &str,
    degree: i32,
    n: i32,
    states: &[[f64; 6]],
    epochs: &[f64],
) {
    let count = usize::try_from(n).expect("the number of states cannot be negative");
    assert!(
        count <= states.len() && count <= epochs.len(),
        "spkw09 was asked for {count} records but got {} states and {} epochs",
        states.len(),
        epochs.len()
    );

    let frame = to_cstring(frame);
    let segid = to_cstring(segid);

    unsafe {
        crate::c::spkw09_c(
            handle,
            body,
            center,
            frame.as_ptr() as *mut SpiceChar,
            first,
            last,
            segid.as_ptr() as *mut SpiceChar,
            degree,
            n,
            states.as_ptr() as *mut [SpiceDouble; 6],
            epochs.as_ptr() as *mut SpiceDouble,
        );
    }
}

/* -------------------------------------------------------------------------------------------- */
/* Surface geometry                                                                               */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Compute, for a given observer and a ray emanating from the observer, the surface intercept of
    the ray 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 `srfxpt`.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn sincpt(
        method: &str,
        target: &str,
        et: f64,
        fixref: &str,
        abcorr: &str,
        obsrvr: &str,
        dref: &str,
        dvec: [f64; 3]
    ) -> ([f64; 3], f64, [f64; 3], bool) {
    }
}

cspice_proc! {
    /**
    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.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn subpnt(
        method: &str,
        target: &str,
        et: f64,
        fixref: &str,
        abcorr: &str,
        obsrvr: &str
    ) -> ([f64; 3], f64, [f64; 3]) {
    }
}

cspice_proc! {
    /**
    Compute the rectangular coordinates of the sub-solar point on a target body at a specified
    epoch, optionally corrected for light time and stellar aberration.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn subslr(
        method: &str,
        target: &str,
        et: f64,
        fixref: &str,
        abcorr: &str,
        obsrvr: &str
    ) -> ([f64; 3], f64, [f64; 3]) {
    }
}

cspice_proc! {
    /**
    Find the illumination angles---phase, solar incidence, and emission---at a specified surface
    point of a target body.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ilumin(
        method: &str,
        target: &str,
        et: f64,
        fixref: &str,
        abcorr: &str,
        obsrvr: &str,
        spoint: [f64; 3]
    ) -> (f64, [f64; 3], f64, f64, f64) {
    }
}

cspice_proc! {
    /**
    Compute the illumination angles---phase, incidence, and emission---at a specified point on a
    target body. Return logical flags indicating whether the surface point is visible from the
    observer's position and whether the surface point is illuminated.

    The target body's surface is represented using topographic data provided by DSK files, or by a
    reference ellipsoid.

    The illumination source is a specified ephemeris object.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn illumf(
        method: &str,
        target: &str,
        ilusrc: &str,
        et: f64,
        fixref: &str,
        abcorr: &str,
        obsrvr: &str,
        spoint: [f64; 3]
    ) -> (f64, [f64; 3], f64, f64, f64, bool, bool) {
    }
}

cspice_proc! {
    /**
    Determine the intersection of a line-of-sight vector with the surface of an ellipsoid.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn surfpt(positn: [f64; 3], u: [f64; 3], a: f64, b: f64, c: f64) -> ([f64; 3], bool) {}
}

cspice_proc! {
    /**
    Locate the point on the surface of an ellipsoid that is nearest to a specified position, and
    the altitude of that position above the ellipsoid.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn nearpt(positn: [f64; 3], a: f64, b: f64, c: f64) -> ([f64; 3], f64) {}
}

cspice_proc! {
    /**
    Determine the occultation condition (not occulted, partially, etc.) of one target relative to
    another target as seen by an observer at a given time, with targets modeled as points,
    ellipsoids, or digital shapes (DSK).
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn occult(
        targ1: &str,
        shape1: &str,
        frame1: &str,
        targ2: &str,
        shape2: &str,
        frame2: &str,
        abcorr: &str,
        obsrvr: &str,
        et: f64
    ) -> i32 {
    }
}

cspice_proc! {
    /**
    Compute the apparent phase angle for a target, observer, illuminator set of ephemeris objects.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn phaseq(et: f64, target: &str, illumn: &str, obsrvr: &str, abcorr: &str) -> f64 {}
}

/**
Map an array of surface points on a target body to the corresponding unit length outward surface
normal vectors.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn srfnrm(
    method: &str,
    target: &str,
    et: f64,
    fixref: &str,
    srfpts: &[[f64; 3]],
) -> Vec<[f64; 3]> {
    let method = to_cstring(method);
    let target = to_cstring(target);
    let fixref = to_cstring(fixref);
    let mut normls = vec![[0.0; 3]; srfpts.len()];

    unsafe {
        crate::c::srfnrm_c(
            method.as_ptr() as *mut SpiceChar,
            target.as_ptr() as *mut SpiceChar,
            et,
            fixref.as_ptr() as *mut SpiceChar,
            srfpts.len() as SpiceInt,
            srfpts.as_ptr() as *mut [f64; 3],
            normls.as_mut_ptr(),
        );
    }

    normls
}

/**
Map an array of planetocentric longitude/latitude pairs to the corresponding surface points on a
target body.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn latsrf(
    method: &str,
    target: &str,
    et: f64,
    fixref: &str,
    lonlat: &[[f64; 2]],
) -> Vec<[f64; 3]> {
    let method = to_cstring(method);
    let target = to_cstring(target);
    let fixref = to_cstring(fixref);
    let mut srfpts = vec![[0.0; 3]; lonlat.len()];

    unsafe {
        crate::c::latsrf_c(
            method.as_ptr() as *mut SpiceChar,
            target.as_ptr() as *mut SpiceChar,
            et,
            fixref.as_ptr() as *mut SpiceChar,
            lonlat.len() as SpiceInt,
            lonlat.as_ptr() as *mut [f64; 2],
            srfpts.as_mut_ptr(),
        );
    }

    srfpts
}

/**
Compute a set of points on the umbral or penumbral terminator of a specified target body, where the
target shape is modelled as an ellipsoid.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn edterm(
    trmtyp: &str,
    source: &str,
    target: &str,
    et: f64,
    fixfrm: &str,
    abcorr: &str,
    obsrvr: &str,
    npts: usize,
) -> (f64, [f64; 3], Vec<[f64; 3]>) {
    let trmtyp = to_cstring(trmtyp);
    let source = to_cstring(source);
    let target = to_cstring(target);
    let fixfrm = to_cstring(fixfrm);
    let abcorr = to_cstring(abcorr);
    let obsrvr = to_cstring(obsrvr);

    let mut trgepc = 0.0;
    let mut obspos = [0.0; 3];
    let mut termpts = vec![[0.0; 3]; npts];

    unsafe {
        crate::c::edterm_c(
            trmtyp.as_ptr() as *mut SpiceChar,
            source.as_ptr() as *mut SpiceChar,
            target.as_ptr() as *mut SpiceChar,
            et,
            fixfrm.as_ptr() as *mut SpiceChar,
            abcorr.as_ptr() as *mut SpiceChar,
            obsrvr.as_ptr() as *mut SpiceChar,
            npts as SpiceInt,
            &mut trgepc,
            obspos.as_mut_ptr(),
            termpts.as_mut_ptr(),
        );
    }

    (trgepc, obspos, termpts)
}

/**
Find limb points on a target body, on cuts of a half-plane pencil rotating about the observer-target
vector.

Returns, per cut, the number of points found, then the points themselves, the epoch associated with
each, and the tangent vector from the observer to each.
*/
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn limbpt(
    method: &str,
    target: &str,
    et: f64,
    fixref: &str,
    abcorr: &str,
    corloc: &str,
    obsrvr: &str,
    refvec: [f64; 3],
    rolstp: f64,
    ncuts: usize,
    schstp: f64,
    soltol: f64,
    maxn: usize,
) -> (Vec<i32>, Vec<[f64; 3]>, Vec<f64>, Vec<[f64; 3]>) {
    let method = to_cstring(method);
    let target = to_cstring(target);
    let fixref = to_cstring(fixref);
    let abcorr = to_cstring(abcorr);
    let corloc = to_cstring(corloc);
    let obsrvr = to_cstring(obsrvr);

    let mut npts = vec![0; ncuts.max(1)];
    let mut points = vec![[0.0; 3]; maxn];
    let mut epochs = vec![0.0; maxn];
    let mut tangts = vec![[0.0; 3]; maxn];

    unsafe {
        crate::c::limbpt_c(
            method.as_ptr() as *mut SpiceChar,
            target.as_ptr() as *mut SpiceChar,
            et,
            fixref.as_ptr() as *mut SpiceChar,
            abcorr.as_ptr() as *mut SpiceChar,
            corloc.as_ptr() as *mut SpiceChar,
            obsrvr.as_ptr() as *mut SpiceChar,
            refvec.as_ptr() as *mut SpiceDouble,
            rolstp,
            ncuts as SpiceInt,
            schstp,
            soltol,
            maxn as SpiceInt,
            npts.as_mut_ptr(),
            points.as_mut_ptr(),
            epochs.as_mut_ptr(),
            tangts.as_mut_ptr(),
        );
    }

    truncate_cuts(npts, points, epochs, tangts)
}

/**
Find terminator points on a target body, on cuts of a half-plane pencil rotating about the
observer-target vector.

Shaped like [`limbpt`], with the illumination source named separately.
*/
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn termpt(
    method: &str,
    ilusrc: &str,
    target: &str,
    et: f64,
    fixref: &str,
    abcorr: &str,
    corloc: &str,
    obsrvr: &str,
    refvec: [f64; 3],
    rolstp: f64,
    ncuts: usize,
    schstp: f64,
    soltol: f64,
    maxn: usize,
) -> (Vec<i32>, Vec<[f64; 3]>, Vec<f64>, Vec<[f64; 3]>) {
    let method = to_cstring(method);
    let ilusrc = to_cstring(ilusrc);
    let target = to_cstring(target);
    let fixref = to_cstring(fixref);
    let abcorr = to_cstring(abcorr);
    let corloc = to_cstring(corloc);
    let obsrvr = to_cstring(obsrvr);

    let mut npts = vec![0; ncuts.max(1)];
    let mut points = vec![[0.0; 3]; maxn];
    let mut epochs = vec![0.0; maxn];
    let mut tangts = vec![[0.0; 3]; maxn];

    unsafe {
        crate::c::termpt_c(
            method.as_ptr() as *mut SpiceChar,
            ilusrc.as_ptr() as *mut SpiceChar,
            target.as_ptr() as *mut SpiceChar,
            et,
            fixref.as_ptr() as *mut SpiceChar,
            abcorr.as_ptr() as *mut SpiceChar,
            corloc.as_ptr() as *mut SpiceChar,
            obsrvr.as_ptr() as *mut SpiceChar,
            refvec.as_ptr() as *mut SpiceDouble,
            rolstp,
            ncuts as SpiceInt,
            schstp,
            soltol,
            maxn as SpiceInt,
            npts.as_mut_ptr(),
            points.as_mut_ptr(),
            epochs.as_mut_ptr(),
            tangts.as_mut_ptr(),
        );
    }

    truncate_cuts(npts, points, epochs, tangts)
}

/// Cut the per-cut output arrays down to the number of points CSPICE actually wrote.
#[allow(clippy::type_complexity)]
fn truncate_cuts(
    npts: Vec<SpiceInt>,
    mut points: Vec<[f64; 3]>,
    mut epochs: Vec<f64>,
    mut tangts: Vec<[f64; 3]>,
) -> (Vec<i32>, Vec<[f64; 3]>, Vec<f64>, Vec<[f64; 3]>) {
    let found = npts.iter().map(|count| count.max(&0)).sum::<SpiceInt>() as usize;
    points.truncate(found);
    epochs.truncate(found);
    tangts.truncate(found);
    (npts, points, epochs, tangts)
}

/**
Return the field-of-view (FOV) parameters for a specified instrument. The instrument is specified by
its NAIF ID code.

This function has a [neat version][crate::neat::getfov].
*/
pub fn getfov(
    instid: i32,
    room: usize,
    shapelen: usize,
    framelen: usize,
) -> (String, String, [f64; 3], Vec<[f64; 3]>) {
    let mut shape = vec![0 as SpiceChar; shapelen.max(1)];
    let mut frame = vec![0 as SpiceChar; framelen.max(1)];
    let mut bsight = [0.0; 3];
    let mut n = 0;
    let mut bounds = vec![[0.0; 3]; room];

    unsafe {
        crate::c::getfov_c(
            instid,
            room as SpiceInt,
            shapelen as SpiceInt,
            framelen as SpiceInt,
            shape.as_mut_ptr(),
            frame.as_mut_ptr(),
            bsight.as_mut_ptr(),
            &mut n,
            bounds.as_mut_ptr(),
        )
    };

    bounds.truncate(n.max(0) as usize);
    (from_cbuf(&shape), from_cbuf(&frame), bsight, bounds)
}

/* -------------------------------------------------------------------------------------------- */
/* Planes and ellipses                                                                            */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Build a plane from a normal vector and a constant.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn nvc2pl(normal: [f64; 3], constant: f64) -> PLANE {}
}

cspice_proc! {
    /**
    Build a plane from a normal vector and a point.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn nvp2pl(normal: [f64; 3], point: [f64; 3]) -> PLANE {}
}

cspice_proc! {
    /**
    Build a plane from a point and two spanning vectors.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn psv2pl(point: [f64; 3], span1: [f64; 3], span2: [f64; 3]) -> PLANE {}
}

cspice_proc! {
    /**
    Take a plane apart into a unit normal vector and a constant.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn pl2nvc(plane: PLANE) -> ([f64; 3], f64) {}
}

cspice_proc! {
    /**
    Take a plane apart into a unit normal vector and a point.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn pl2nvp(plane: PLANE) -> ([f64; 3], [f64; 3]) {}
}

cspice_proc! {
    /**
    Take a plane apart into a point and two spanning vectors.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn pl2psv(plane: PLANE) -> ([f64; 3], [f64; 3], [f64; 3]) {}
}

cspice_proc! {
    /**
    Build an ellipse from a centre and two generating vectors.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn cgv2el(center: [f64; 3], vec1: [f64; 3], vec2: [f64; 3]) -> ELLIPSE {}
}

cspice_proc! {
    /**
    Take an ellipse apart into its centre and its semi-major and semi-minor axes.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn el2cgv(ellipse: ELLIPSE) -> ([f64; 3], [f64; 3], [f64; 3]) {}
}

cspice_proc! {
    /**
    Find the semi-axes of the ellipse two vectors generate.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn saelgv(vec1: [f64; 3], vec2: [f64; 3]) -> ([f64; 3], [f64; 3]) {}
}

cspice_proc! {
    /**
    Find the intersection of an ellipsoid and a plane, when there is one.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn inedpl(a: f64, b: f64, c: f64, plane: PLANE) -> (ELLIPSE, bool) {}
}

cspice_proc! {
    /**
    Find the intersection of an ellipse and a plane: how many points there are, and the points.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn inelpl(ellips: ELLIPSE, plane: PLANE) -> (i32, [f64; 3], [f64; 3]) {}
}

cspice_proc! {
    /**
    Find the intersection of a ray and a plane: how many points there are, and the point.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn inrypl(vertex: [f64; 3], dir: [f64; 3], plane: PLANE) -> (i32, [f64; 3]) {}
}

cspice_proc! {
    /**
    Find the limb of an ellipsoid as seen from a viewing point.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn edlimb(a: f64, b: f64, c: f64, viewpt: [f64; 3]) -> ELLIPSE {}
}

cspice_proc! {
    /**
    Project an ellipse orthogonally onto a plane.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn pjelpl(elin: ELLIPSE, plane: PLANE) -> ELLIPSE {}
}

cspice_proc! {
    /**
    Project a vector orthogonally onto a plane.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vprjp(vin: [f64; 3], plane: PLANE) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Invert an orthogonal projection: find the vector of `invpl` that projects onto `vin`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn vprjpi(vin: [f64; 3], projpl: PLANE, invpl: PLANE) -> ([f64; 3], bool) {}
}

cspice_proc! {
    /**
    Find the point of an ellipse nearest a specified point, and the distance between them.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn npelpt(point: [f64; 3], ellips: ELLIPSE) -> ([f64; 3], f64) {}
}

cspice_proc! {
    /**
    Find the point of an ellipsoid nearest a line, and the distance between them.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn npedln(
        a: f64,
        b: f64,
        c: f64,
        linept: [f64; 3],
        linedr: [f64; 3]
    ) -> ([f64; 3], f64) {
    }
}

cspice_proc! {
    /**
    Find the point of a line nearest a specified point, and the distance between them.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn nplnpt(linpt: [f64; 3], lindir: [f64; 3], point: [f64; 3]) -> ([f64; 3], f64) {}
}

cspice_proc! {
    /**
    The outward normal of an ellipsoid at a point on its surface.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn surfnm(a: f64, b: f64, c: f64, point: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Find the state of the intersection of a ray with an ellipsoid, given the state of the ray.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn surfpv(
        stvrtx: [f64; 6],
        stdir: [f64; 6],
        a: f64,
        b: f64,
        c: f64
    ) -> ([f64; 6], bool) {
    }
}

/* -------------------------------------------------------------------------------------------- */
/* Surfaces                                                                                       */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Translate a surface ID code, together with a body ID code, to the corresponding surface name.

    The boolean tells whether the returned string is a name rather than the string representation of
    the code.

    This function has a [neat version][crate::neat::srfc2s].
    */
    pub fn srfc2s(code: i32, bodyid: i32, #[lenout] srflen: i32) -> (String, bool) {}
}

cspice_proc! {
    /**
    Translate a surface ID code, together with a body string, to the corresponding surface name.

    This function has a [neat version][crate::neat::srfcss].
    */
    pub fn srfcss(code: i32, bodstr: &str, #[lenout] srflen: i32) -> (String, bool) {}
}

cspice_proc! {
    /**
    Translate a surface string, together with a body string, to the corresponding surface ID code.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn srfs2c(srfstr: &str, bodstr: &str) -> (i32, bool) {}
}

cspice_proc! {
    /**
    Translate a surface string, together with a body ID code, to the corresponding surface ID code.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn srfscc(surfce: &str, bodyid: i32) -> (i32, bool) {}
}

/* -------------------------------------------------------------------------------------------- */
/* PCK                                                                                            */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Find the coverage window for a specified reference frame in a specified binary PCK file.

    This function has a [neat version][crate::neat::pckcov].
    */
    pub fn pckcov(pck: &str, idcode: i32, cover: &mut Cell<f64>) {}
}

cspice_proc! {
    /**
    Find the set of reference frame class ID codes of all frames in a specified binary PCK file.

    This function has a [neat version][crate::neat::pckfrm].
    */
    pub fn pckfrm(pck: &str, ids: &mut Cell<i32>) {}
}

/* -------------------------------------------------------------------------------------------- */
/* Two-body orbits                                                                                */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Determine the state of a body from a set of elliptic, hyperbolic, or parabolic orbital elements.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn conics(elts: [f64; 8], et: f64) -> [f64; 6] {}
}

cspice_proc! {
    /**
    Determine the set of osculating conic orbital elements that corresponds to the state of a body
    at some epoch.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn oscelt(state: [f64; 6], et: f64, mu: f64) -> [f64; 8] {}
}

cspice_proc! {
    /**
    Like [`oscelt`], with the true anomaly, semi-major axis and orbital period appended.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn oscltx(state: [f64; 6], et: f64, mu: f64) -> [f64; 20] {}
}

cspice_proc! {
    /**
    Propagate a two body solution from one epoch to another.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn prop2b(gm: f64, pvinit: [f64; 6], dt: f64) -> [f64; 6] {}
}

/* -------------------------------------------------------------------------------------------- */
/* Windows                                                                                        */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Insert the interval `[left, right]` into a double precision window.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn wninsd(left: f64, right: f64, window: &mut Cell<f64>) {}
}

cspice_proc! {
    /**
    Fetch the endpoints of the `n`th interval of a double precision window, counting from zero.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn wnfetd(window: &mut Cell<f64>, n: i32) -> (f64, f64) {}
}

cspice_proc! {
    /**
    Return the number of intervals in a double precision window.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn wncard(window: &mut Cell<f64>) -> i32 {}
}

cspice_proc! {
    /**
    Place the complement of a window, relative to the interval `[left, right]`, into `result`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn wncomd(left: f64, right: f64, window: &mut Cell<f64>, result: &mut Cell<f64>) {}
}

cspice_proc! {
    /**
    Contract each interval of a window by `left` at its start and `right` at its end.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn wncond(left: f64, right: f64, window: &mut Cell<f64>) {}
}

cspice_proc! {
    /**
    Expand each interval of a window by `left` at its start and `right` at its end.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn wnexpd(left: f64, right: f64, window: &mut Cell<f64>) {}
}

cspice_proc! {
    /**
    Place the difference of two windows into `c`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn wndifd(a: &mut Cell<f64>, b: &mut Cell<f64>, c: &mut Cell<f64>) {}
}

cspice_proc! {
    /**
    Place the intersection of two windows into `c`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn wnintd(a: &mut Cell<f64>, b: &mut Cell<f64>, c: &mut Cell<f64>) {}
}

cspice_proc! {
    /**
    Place the union of two windows into `c`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn wnunid(a: &mut Cell<f64>, b: &mut Cell<f64>, c: &mut Cell<f64>) {}
}

cspice_proc! {
    /**
    Whether a point belongs to a window.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn wnelmd(point: f64, window: &mut Cell<f64>) -> bool {}
}

cspice_proc! {
    /**
    Whether an interval is included in a window.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn wnincd(left: f64, right: f64, window: &mut Cell<f64>) -> bool {}
}

cspice_proc! {
    /**
    Compare two windows; `op` is one of `"="`, `"<>"`, `"<="`, `"<"`, `">="` or `">"`.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn wnreld(a: &mut Cell<f64>, op: &str, b: &mut Cell<f64>) -> bool {}
}

cspice_proc! {
    /**
    Replace each interval of a window by one of its endpoints; `side` is `'L'` or `'R'`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn wnextd(side: char, window: &mut Cell<f64>) {}
}

cspice_proc! {
    /**
    Fill the gaps shorter than `sml` between adjacent intervals of a window.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn wnfild(sml: f64, window: &mut Cell<f64>) {}
}

cspice_proc! {
    /**
    Drop the intervals of a window shorter than `sml`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn wnfltd(sml: f64, window: &mut Cell<f64>) {}
}

cspice_proc! {
    /**
    Summarize a window: total measure, average and standard deviation of the interval lengths, and
    the indices of the shortest and longest intervals.

    The two indices point at the *left endpoints* in the flat endpoint array, so they run
    `0, 2, 4, ...` rather than `0, 1, 2, ...`; the `n`th interval is reported as `2 * n`. Ties go
    to the first interval of that length.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    #[allow(clippy::type_complexity)]
    pub fn wnsumd(window: &mut Cell<f64>) -> (f64, f64, f64, i32, i32) {}
}

cspice_proc! {
    /**
    Validate a double precision window built by writing into a cell directly.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn wnvald(size: i32, n: i32, window: &mut Cell<f64>) {}
}

/* -------------------------------------------------------------------------------------------- */
/* Sets and cells                                                                                 */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Place the union of two sets into `c`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn union<T: CellItem>(a: &mut Cell<T>, b: &mut Cell<T>, c: &mut Cell<T>) {}
}

cspice_proc! {
    /**
    Place the intersection of two sets into `c`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn inter<T: CellItem>(a: &mut Cell<T>, b: &mut Cell<T>, c: &mut Cell<T>) {}
}

cspice_proc! {
    /**
    Place the difference of two sets into `c`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn diff<T: CellItem>(a: &mut Cell<T>, b: &mut Cell<T>, c: &mut Cell<T>) {}
}

cspice_proc! {
    /**
    Copy the contents of one cell into another.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn copy<T: CellItem>(a: &mut Cell<T>, b: &mut Cell<T>) {}
}

cspice_proc! {
    /**
    The cardinality of a cell; [`Cell::len`] reports the same number without a CSPICE call.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn card<T: CellItem>(cell: &mut Cell<T>) -> i32 {}
}

cspice_proc! {
    /**
    Set the cardinality of a cell.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn scard<T: CellItem>(card: i32, cell: &mut Cell<T>) {}
}

cspice_proc! {
    /**
    The size of a cell; [`Cell::capacity`] reports the same number without a CSPICE call.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn size<T: CellItem>(cell: &mut Cell<T>) -> i32 {}
}

cspice_proc! {
    /**
    Set the size of a cell.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ssize<T: CellItem>(size: i32, cell: &mut Cell<T>) {}
}

cspice_proc! {
    /**
    Turn a cell holding `n` items into a set, by sorting it and removing the duplicates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn valid<T: CellItem>(size: i32, n: i32, a: &mut Cell<T>) {}
}

cspice_proc! {
    /**
    Whether an integer belongs to a set.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn elemi(item: i32, set: &mut Cell<i32>) -> bool {}
}

cspice_proc! {
    /**
    Whether a double precision number belongs to a set.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn elemd(item: f64, set: &mut Cell<f64>) -> bool {}
}

cspice_proc! {
    /**
    Whether a string belongs to a set.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn elemc(item: &str, set: &mut Cell<String>) -> bool {}
}

cspice_proc! {
    /**
    Insert an integer into a set.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn insrti(item: i32, set: &mut Cell<i32>) {}
}

cspice_proc! {
    /**
    Insert a double precision number into a set.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn insrtd(item: f64, set: &mut Cell<f64>) {}
}

cspice_proc! {
    /**
    Insert a string into a set.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn insrtc(item: &str, set: &mut Cell<String>) {}
}

cspice_proc! {
    /**
    Remove an integer from a set.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn removi(item: i32, set: &mut Cell<i32>) {}
}

cspice_proc! {
    /**
    Remove a double precision number from a set.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn removd(item: f64, set: &mut Cell<f64>) {}
}

cspice_proc! {
    /**
    Remove a string from a set.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn removc(item: &str, set: &mut Cell<String>) {}
}

cspice_proc! {
    /**
    Append an integer to a cell; [`Cell::push`] is the idiomatic form.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn appndi(item: i32, cell: &mut Cell<i32>) {}
}

cspice_proc! {
    /**
    Append a double precision number to a cell; [`Cell::push`] is the idiomatic form.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn appndd(item: f64, cell: &mut Cell<f64>) {}
}

cspice_proc! {
    /**
    Append a string to a cell; [`Cell::push`] is the idiomatic form.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn appndc(item: &str, cell: &mut Cell<String>) {}
}

/* -------------------------------------------------------------------------------------------- */
/* Geometry finder                                                                                */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Determine the time windows, within a confinement window, when one body is occulted by or in
    transit across another, as seen from an observer.

    This function has a [neat version][crate::neat::gfoclt].
    */
    #[allow(clippy::too_many_arguments)]
    pub fn gfoclt(
        occtyp: &str,
        front: &str,
        fshape: &str,
        fframe: &str,
        back: &str,
        bshape: &str,
        bframe: &str,
        abcorr: &str,
        obsrvr: &str,
        step: f64,
        cnfine: &mut Cell<f64>,
        result: &mut Cell<f64>
    ) {
    }
}

/* -------------------------------------------------------------------------------------------- */
/* Two-line elements                                                                              */
/* -------------------------------------------------------------------------------------------- */

/// Number of elements a two-line element set is parsed into.
pub const TLE_NELTS: usize = 10;

/// Number of geophysical constants the SGP4 propagator needs.
pub const TLE_NGEOPHS: usize = 8;

/**
Parse the two lines of a NORAD two-line element set into the epoch and the element set CSPICE uses.

`frstyr` is the first year of the century the two digit years in the set belong to; 1957, the start
of the space age, is the usual choice.

# Panics

Panics if `lines` does not hold exactly two lines.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn getelm<S: AsRef<str>>(frstyr: i32, lines: &[S]) -> (f64, [f64; TLE_NELTS]) {
    assert!(
        lines.len() == 2,
        "a two-line element set has two lines, got {}",
        lines.len()
    );

    // CSPICE reads the pair out of one contiguous, fixed stride, char array.
    let lineln = lines
        .iter()
        .map(|line| line.as_ref().len())
        .max()
        .unwrap_or(0)
        + 1;
    let mut buffer = vec![0 as SpiceChar; 2 * lineln];
    for (index, line) in lines.iter().enumerate() {
        let slot = &mut buffer[index * lineln..(index + 1) * lineln];
        for (target, byte) in slot.iter_mut().zip(line.as_ref().as_bytes()) {
            *target = *byte as SpiceChar;
        }
    }

    let mut epoch = 0.0;
    let mut elems = [0.0; TLE_NELTS];

    unsafe {
        crate::c::getelm_c(
            frstyr,
            lineln as SpiceInt,
            buffer.as_ptr().cast(),
            &mut epoch,
            elems.as_mut_ptr(),
        );
    }

    (epoch, elems)
}

cspice_proc! {
    /**
    Evaluate a two-line element set with the SGP4 propagator.

    `geophs` holds the eight geophysical constants the propagator needs, in the order
    `J2, J3, J4, KE, QO, SO, ER, AE`; they normally come from a geophysical constants kernel.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn evsgp4(et: f64, geophs: [f64; 8], elems: [f64; 10]) -> [f64; 6] {}
}

/* -------------------------------------------------------------------------------------------- */
/* Searching, sorting and ordering                                                                */
/* -------------------------------------------------------------------------------------------- */

/// Generate the wrappers that search a slice for a value.
macro_rules! search {
    ($($name:ident($ty:ty) => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// Returns the index found, or `-1`.
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(value: $ty, array: &[$ty]) -> i32 {
            unsafe { crate::c::$cname(value, array.len() as SpiceInt, array.as_ptr() as *mut _) }
        }
    )*};
}

search! {
    bsrchd(f64) => bsrchd_c, "Binary search a sorted array of doubles.";
    bsrchi(i32) => bsrchi_c, "Binary search a sorted array of integers.";
    lstled(f64) => lstled_c, "Last index of the doubles less than or equal to a value.";
    lstlei(i32) => lstlei_c, "Last index of the integers less than or equal to a value.";
    lstltd(f64) => lstltd_c, "Last index of the doubles strictly less than a value.";
    lstlti(i32) => lstlti_c, "Last index of the integers strictly less than a value.";
}

/// Generate the wrappers that sort a slice in place.
macro_rules! sort_in_place {
    ($($name:ident($ty:ty) => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(array: &mut [$ty]) {
            unsafe { crate::c::$cname(array.len() as SpiceInt, array.as_mut_ptr()) }
        }
    )*};
}

sort_in_place! {
    shelld(f64) => shelld_c, "Sort an array of doubles in place.";
    shelli(i32) => shelli_c, "Sort an array of integers in place.";
}

/// Generate the wrappers that report the order of a slice without moving it.
macro_rules! order_of {
    ($($name:ident($ty:ty) => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(array: &[$ty]) -> Vec<i32> {
            let mut iorder = vec![0; array.len()];
            unsafe {
                crate::c::$cname(
                    array.as_ptr() as *mut _,
                    array.len() as SpiceInt,
                    iorder.as_mut_ptr(),
                )
            };
            iorder
        }
    )*};
}

order_of! {
    orderd(f64) => orderd_c, "The order vector that sorts an array of doubles.";
    orderi(i32) => orderi_c, "The order vector that sorts an array of integers.";
}

/// Generate the wrappers that apply an order vector to a slice in place.
macro_rules! reorder {
    ($($name:ident($ty:ty) => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// # Panics
        ///
        /// Panics if the order vector is not as long as the array.
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(iorder: &[i32], array: &mut [$ty]) {
            assert!(
                iorder.len() == array.len(),
                "the order vector has {} entries for an array of {}",
                iorder.len(),
                array.len()
            );
            unsafe {
                crate::c::$cname(
                    iorder.as_ptr() as *mut SpiceInt,
                    array.len() as SpiceInt,
                    array.as_mut_ptr(),
                )
            };
        }
    )*};
}

reorder! {
    reordd(f64) => reordd_c, "Reorder an array of doubles in place.";
    reordi(i32) => reordi_c, "Reorder an array of integers in place.";
    reordl(crate::c::SpiceBoolean) => reordl_c, "Reorder an array of logical flags in place.";
}

cspice_proc! {
    /**
    Bracket a double precision number between two endpoints.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn brcktd(number: f64, end1: f64, end2: f64) -> f64 {}
}

cspice_proc! {
    /**
    Bracket an integer between two endpoints.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn brckti(number: i32, end1: i32, end2: i32) -> i32 {}
}

/**
The sum of an array of doubles.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn sumad(array: &[f64]) -> f64 {
    unsafe { crate::c::sumad_c(array.as_ptr() as *mut SpiceDouble, array.len() as SpiceInt) }
}

/**
The sum of an array of integers.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn sumai(array: &[i32]) -> i32 {
    unsafe { crate::c::sumai_c(array.as_ptr() as *mut SpiceInt, array.len() as SpiceInt) }
}

/**
Whether an array is an order vector: a permutation of `0 .. n`.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn isordv(array: &[i32]) -> bool {
    unsafe { crate::c::isordv_c(array.as_ptr() as *mut SpiceInt, array.len() as SpiceInt) != 0 }
}

/// Generate the wrappers that search a strided array of strings.
macro_rules! search_strings {
    ($($name:ident => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// Returns the index found, or `-1`.
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name<S: AsRef<str>>(value: &str, array: &[S]) -> i32 {
            let value = to_cstring(value);
            let (buffer, stride) = to_strided(array);
            unsafe {
                crate::c::$cname(
                    value.as_ptr() as *mut SpiceChar,
                    array.len() as SpiceInt,
                    stride as SpiceInt,
                    buffer.as_ptr().cast(),
                )
            }
        }
    )*};
}

search_strings! {
    bsrchc => bsrchc_c, "Binary search a sorted array of strings.";
    esrchc => esrchc_c, "Search an array of strings, ignoring case and trailing blanks.";
    lstlec => lstlec_c, "Last index of the strings less than or equal to a value.";
    lstltc => lstltc_c, "Last index of the strings strictly less than a value.";
}

/**
Binary search an array of integers ordered by an order vector.

Returns the index found, or `-1`.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn bschoi(value: i32, array: &[i32], order: &[i32]) -> i32 {
    unsafe {
        crate::c::bschoi_c(
            value,
            array.len() as SpiceInt,
            array.as_ptr() as *mut SpiceInt,
            order.as_ptr() as *mut SpiceInt,
        )
    }
}

/**
Binary search an array of strings ordered by an order vector.

Returns the index found, or `-1`.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn bschoc<S: AsRef<str>>(value: &str, array: &[S], order: &[i32]) -> i32 {
    let value = to_cstring(value);
    let (buffer, stride) = to_strided(array);
    unsafe {
        crate::c::bschoc_c(
            value.as_ptr() as *mut SpiceChar,
            array.len() as SpiceInt,
            stride as SpiceInt,
            buffer.as_ptr().cast(),
            order.as_ptr() as *mut SpiceInt,
        )
    }
}

/**
The order vector that sorts an array of strings.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn orderc<S: AsRef<str>>(array: &[S]) -> Vec<i32> {
    let (buffer, stride) = to_strided(array);
    let mut iorder = vec![0; array.len()];
    unsafe {
        crate::c::orderc_c(
            stride as SpiceInt,
            buffer.as_ptr().cast(),
            array.len() as SpiceInt,
            iorder.as_mut_ptr(),
        )
    };
    iorder
}

/**
Apply an order vector to an array of strings.

# Panics

Panics if the order vector is not as long as the array.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn reordc<S: AsRef<str>>(iorder: &[i32], array: &[S]) -> Vec<String> {
    assert!(
        iorder.len() == array.len(),
        "the order vector has {} entries for an array of {}",
        iorder.len(),
        array.len()
    );
    let (mut buffer, stride) = to_strided(array);
    unsafe {
        crate::c::reordc_c(
            iorder.as_ptr() as *mut SpiceInt,
            array.len() as SpiceInt,
            stride as SpiceInt,
            buffer.as_mut_ptr().cast(),
        )
    };
    from_strided(&buffer, stride, array.len())
}

/**
Sort an array of strings.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn shellc<S: AsRef<str>>(array: &[S]) -> Vec<String> {
    let (mut buffer, stride) = to_strided(array);
    unsafe {
        crate::c::shellc_c(
            array.len() as SpiceInt,
            stride as SpiceInt,
            buffer.as_mut_ptr().cast(),
        )
    };
    from_strided(&buffer, stride, array.len())
}

/* -------------------------------------------------------------------------------------------- */
/* Strings                                                                                        */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Convert a string to lower case.
    */
    pub fn lcase(input: &str, #[lenout] lenout: i32) -> String {}
}

cspice_proc! {
    /**
    Convert a string to upper case.
    */
    pub fn ucase(input: &str, #[lenout] lenout: i32) -> String {}
}

cspice_proc! {
    /**
    Compress runs of a delimiter down to `n` of them.
    */
    pub fn cmprss(delim: char, n: i32, input: &str, #[lenout] lenout: i32) -> String {}
}

cspice_proc! {
    /**
    Whether two strings are equivalent, ignoring case and leading and trailing blanks.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn eqstr(a: &str, b: &str) -> bool {}
}

cspice_proc! {
    /**
    Match a string against a template, ignoring case; `wstr` matches any run of characters and
    `wchr` any single one.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn matchi(string: &str, templ: &str, wstr: char, wchr: char) -> bool {}
}

cspice_proc! {
    /**
    Match a string against a template, respecting case.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn matchw(string: &str, templ: &str, wstr: char, wchr: char) -> bool {}
}

cspice_proc! {
    /**
    Replace a marker in a string with a string.
    */
    pub fn repmc(input: &str, marker: &str, value: &str, #[lenout] lenout: i32) -> String {}
}

cspice_proc! {
    /**
    Replace a marker in a string with a double precision number.
    */
    pub fn repmd(
        input: &str,
        marker: &str,
        value: f64,
        sigdig: i32,
        #[lenout] lenout: i32
    ) -> String {
    }
}

cspice_proc! {
    /**
    Replace a marker in a string with a formatted double precision number; `format` is `'E'` or
    `'F'`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    #[allow(clippy::too_many_arguments)]
    pub fn repmf(
        input: &str,
        marker: &str,
        value: f64,
        sigdig: i32,
        format: char,
        #[lenout] lenout: i32
    ) -> String {
    }
}

cspice_proc! {
    /**
    Replace a marker in a string with an integer.
    */
    pub fn repmi(input: &str, marker: &str, value: i32, #[lenout] lenout: i32) -> String {}
}

cspice_proc! {
    /**
    Replace a marker in a string with the text of a boolean; `rtcase` picks the capitalisation.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn repml(
        input: &str,
        marker: &str,
        value: bool,
        rtcase: char,
        #[lenout] outlen: i32
    ) -> String {
    }
}

cspice_proc! {
    /**
    Replace a marker in a string with an ordinal number; `strcase` picks the capitalisation.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    #[cname(repmot_c)]
    pub fn repmot(
        input: &str,
        marker: &str,
        value: i32,
        strcase: char,
        #[lenout] lenout: i32
    ) -> String {
    }
}

/**
Split a string at the first run of blanks, into the first word and the rest.
*/
pub fn nextwd(string: &str, nexlen: usize, reslen: usize) -> (String, String) {
    let string = to_cstring(string);
    let mut next = vec![0 as SpiceChar; nexlen.max(1)];
    let mut rest = vec![0 as SpiceChar; reslen.max(1)];

    unsafe {
        crate::c::nextwd_c(
            string.as_ptr() as *mut SpiceChar,
            nexlen as SpiceInt,
            reslen as SpiceInt,
            next.as_mut_ptr(),
            rest.as_mut_ptr(),
        )
    };

    (from_cbuf(&next), from_cbuf(&rest))
}

/**
Split a list on a single delimiter.

This function has a [neat version][crate::neat::lparse].
*/
pub fn lparse(list: &str, delim: &str, nmax: usize, lenout: usize) -> Vec<String> {
    let list = to_cstring(list);
    let delim = to_cstring(delim);
    let lenout = lenout.max(1);
    let mut buffer = vec![0 as SpiceChar; nmax.max(1) * lenout];
    let mut n = 0;

    unsafe {
        crate::c::lparse_c(
            list.as_ptr() as *mut SpiceChar,
            delim.as_ptr() as *mut SpiceChar,
            nmax as SpiceInt,
            lenout as SpiceInt,
            &mut n,
            buffer.as_mut_ptr().cast(),
        )
    };

    from_strided(&buffer, lenout, n.max(0) as usize)
}

/**
Split a list on any of a set of delimiters, treating runs of them as one.

This function has a [neat version][crate::neat::lparsm].
*/
pub fn lparsm(list: &str, delims: &str, nmax: usize, lenout: usize) -> Vec<String> {
    let list = to_cstring(list);
    let delims = to_cstring(delims);
    let lenout = lenout.max(1);
    let mut buffer = vec![0 as SpiceChar; nmax.max(1) * lenout];
    let mut n = 0;

    unsafe {
        crate::c::lparsm_c(
            list.as_ptr() as *mut SpiceChar,
            delims.as_ptr() as *mut SpiceChar,
            nmax as SpiceInt,
            lenout as SpiceInt,
            &mut n,
            buffer.as_mut_ptr().cast(),
        )
    };

    from_strided(&buffer, lenout, n.max(0) as usize)
}

/* ---------------------------------------------------------------------------------------------- */
/* Units, numbers and text                                                                        */
/* ---------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Take a measurement X, the units associated with X, and units to which X should be converted; return Y --- the value of the measurement in the output units.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn convrt(x: f64, input: &str, output: &str) -> f64 {}
}

cspice_proc! {
    /**
    Return the value of the largest (positive) number representable in a double precision variable.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dpmax() -> f64 {}
}

cspice_proc! {
    /**
    Return the value of the smallest (negative) number representable in a double precision variable.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dpmin() -> f64 {}
}

cspice_proc! {
    /**
    Convert a double precision number to an equivalent character string using a base 16 "scientific notation."
    */
    pub fn dp2hx(number: f64, #[lenout] lenout: i32) -> (String, i32) {}
}

cspice_proc! {
    /**
    Convert a string representing a double precision number in a base 16 "scientific notation" into its equivalent double precision number.
    */
    pub fn hx2dp(string: &str, #[lenout] lenout: i32) -> (f64, bool, String) {}
}

cspice_proc! {
    /**
    Find the first occurrence in a string of a character belonging to a collection of characters, starting at a specified location, searching forward.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn cpos(string: &str, chars: &str, start: i32) -> i32 {}
}

cspice_proc! {
    /**
    Find the first occurrence in a string of a character belonging to a collection of characters, starting at a specified location, searching in reverse.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn cposr(string: &str, chars: &str, start: i32) -> i32 {}
}

cspice_proc! {
    /**
    Find the first occurrence in a string of a substring, starting at a specified location, searching forward.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn pos(string: &str, substr: &str, start: i32) -> i32 {}
}

cspice_proc! {
    /**
    Find the first occurrence in a string of a substring, starting at a specified location, searching backward.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn posr(string: &str, substr: &str, start: i32) -> i32 {}
}

cspice_proc! {
    /**
    Convert from an ephemeris epoch measured in seconds past the epoch of J2000 to a calendar string format using a formal calendar free of leapseconds.
    */
    pub fn etcal(et: f64, #[lenout] lenout: i32) -> String {}
}

cspice_proc! {
    /**
    Restrict the set of strings that are recognized by SPICE time parsing routines to those that have standard values for all time components.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn tparch(kind: &str) {}
}

cspice_proc! {
    /**
    Determine if a kernel pool variable is present and if so that it has the correct size and type.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn badkpv(caller: &str, name: &str, comp: &str, size: i32, divby: i32, kind: char) -> bool {}
}

/* ---------------------------------------------------------------------------------------------- */
/* Bodies, frames and the kernel pool                                                             */
/* ---------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Return the frame name, frame ID, and center associated with a given frame class and class ID.
    */
    pub fn ccifrm(frclss: i32, clssid: i32, #[lenout] lenout: i32) -> (i32, String, i32, bool) {}
}

cspice_proc! {
    /**
    Retrieve frame ID code and name to associate with a frame center.
    */
    pub fn cidfrm(cent: i32, #[lenout] lenout: i32) -> (i32, String, bool) {}
}

cspice_proc! {
    /**
    Retrieve frame ID code and name to associate with an object.
    */
    pub fn cnmfrm(cname: &str, #[lenout] lenout: i32) -> (i32, String, bool) {}
}

cspice_proc! {
    /**
    Return a SPICE set containing the frame IDs of all built-in frames of a specified class.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn bltfrm(frmcls: i32, idset: &mut Cell<i32>) {}
}

cspice_proc! {
    /**
    Indicate whether or not any watched kernel variables that have a specified agent on their notification list have been updated.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn cvpool(agent: &str) -> bool {}
}

/* ---------------------------------------------------------------------------------------------- */
/* Assorted routines                                                                              */
/* ---------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Return the azimuth/elevation coordinates of a specified target relative to an "observer," where the observer has constant position in a specified reference frame. The observer's position is provided by the calling program rather than by loaded SPK files.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn azlcpo(method: &str, target: &str, et: f64, abcorr: &str, azccw: bool, elplsz: bool, obspos: [f64; 3], obsctr: &str, obsref: &str) -> ([f64; 6], f64) {}
}

cspice_proc! {
    /**
    Define a body name/ID code pair for later translation via bodn2c_c or bodc2n_c.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn boddef(name: &str, code: i32) {}
}

cspice_proc! {
    /**
    Inform the CSPICE error handling mechanism of entry into a routine.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn chkin(module: &str) {}
}

cspice_proc! {
    /**
    Inform the CSPICE error handling mechanism of exit from a routine.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn chkout(module: &str) {}
}

cspice_proc! {
    /**
    Compute the state (position and velocity) of an ellipsoid surface point nearest to the position component of a specified state.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dnearp(state: [f64; 6], a: f64, b: f64, c: f64) -> ([f64; 6], [f64; 2], bool) {}
}

cspice_proc! {
    /**
    Compute the unit vector parallel to the cross product of two 3-dimensional vectors and the derivative of this unit vector.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ducrss(s1: [f64; 6], s2: [f64; 6]) -> [f64; 6] {}
}

cspice_proc! {
    /**
    Compute the cross product of two 3-dimensional vectors and the derivative of this cross product.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dvcrss(s1: [f64; 6], s2: [f64; 6]) -> [f64; 6] {}
}

cspice_proc! {
    /**
    Compute the derivative of the dot product of two double precision position vectors.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dvdot(s1: [f64; 6], s2: [f64; 6]) -> f64 {}
}

cspice_proc! {
    /**
    Find the unit vector corresponding to a state vector and the derivative of the unit vector.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dvhat(s1: [f64; 6]) -> [f64; 6] {}
}

cspice_proc! {
    /**
    Calculate the derivative of the norm of a 3-vector.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dvnorm(state: [f64; 6]) -> f64 {}
}

cspice_proc! {
    /**
    Delete a variable from the kernel pool.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dvpool(name: &str) {}
}

cspice_proc! {
    /**
    Calculate the time derivative of the separation angle between two input states, S1 and S2.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dvsep(s1: [f64; 6], s2: [f64; 6]) -> f64 {}
}

cspice_proc! {
    /**
    Return the unique point on an ellipsoid's surface where the outward normal direction is a given vector.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ednmpt(a: f64, b: f64, c: f64, normal: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Scale a point so that it lies on the surface of a specified triaxial ellipsoid that is centered at the origin and aligned with the Cartesian coordinate axes.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn edpnt(p: [f64; 3], a: f64, b: f64, c: f64) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Compute the state (position and velocity) of an object whose trajectory is described via equinoctial elements relative to some fixed plane (usually the equatorial plane of some planet).
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn eqncpv(et: f64, epoch: f64, eqel: [f64; 9], rapol: f64, decpol: f64) -> [f64; 6] {}
}

cspice_proc! {
    /**
    Whether a routine should return immediately because the toolkit is in an error state.

    Named `return_c` rather than `return`, which is a keyword in Rust. It is the only routine in
    the toolkit whose name has to change, and SpiceyPy renames it the same way for the same reason.
    */
    #[return_output]
    #[cname(return_c)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn return_c() -> bool {}
}

cspice_proc! {
    /**
    Signal an error, with the short message given.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn sigerr(message: &str) {}
}

cspice_proc! {
    /**
    Substitute a double precision number for the first occurrence of a marker in the long error
    message being built.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn errdp(marker: &str, number: f64) {}
}

cspice_proc! {
    /**
    Substitute an integer for the first occurrence of a marker in the long error message being
    built.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn errint(marker: &str, number: i32) {}
}

cspice_proc! {
    /**
    Substitute a character string for the first occurrence of a marker in the current long error message.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn errch(marker: &str, string: &str) {}
}

cspice_proc! {
    /**
    Close a file designated by a Fortran-style integer logical unit.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ftncls(unit: i32) {}
}

cspice_proc! {
    /**
    Deprecated: This routine has been superseded by the CSPICE routine ilumin_c. This routine is supported for purposes of backward compatibility only.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn illum(target: &str, et: f64, abcorr: &str, obsrvr: &str, spoint: [f64; 3]) -> (f64, f64, f64) {}
}

cspice_proc! {
    /**
    Return the inverse of a state transformation matrix.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn invstm(mat: [[f64; 6]; 6]) -> [[f64; 6]; 6] {}
}

cspice_proc! {
    /**
    Return a boolean value indicating whether a string contains only white space characters.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn iswhsp(string: &str) -> bool {}
}

cspice_proc! {
    /**
    Return the zero based index of the last non-blank character in a character string.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn lastnb(string: &str) -> i32 {}
}

cspice_proc! {
    /**
    Compute the transmission (or reception) time of a signal at a specified target, given the reception (or transmission) time at a specified observer. Also return the elapsed time between transmission and reception.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ltime(etobs: f64, obs: i32, dir: &str, targ: i32) -> (f64, f64) {}
}

cspice_proc! {
    /**
    Scan a string from a specified starting position for the end of a decimal number.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn lx4dec(string: &str, first: i32) -> (i32, i32) {}
}

cspice_proc! {
    /**
    Scan a string from a specified starting position for the end of a number.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn lx4num(string: &str, first: i32) -> (i32, i32) {}
}

cspice_proc! {
    /**
    Scan a string from a specified starting position for the end of a signed integer.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn lx4sgn(string: &str, first: i32) -> (i32, i32) {}
}

cspice_proc! {
    /**
    Scan a string from a specified starting position for the end of an unsigned integer.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn lx4uns(string: &str, first: i32) -> (i32, i32) {}
}

cspice_proc! {
    /**
    Scan (lex) a quoted string.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn lxqstr(string: &str, qchar: char, first: i32) -> (i32, i32) {}
}

cspice_proc! {
    /**
    Find the first occurrence in a string of a character NOT belonging to a collection of characters, starting at a specified location, searching forward.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ncpos(string: &str, chars: &str, start: i32) -> i32 {}
}

cspice_proc! {
    /**
    Find the first occurrence in a string of a character NOT belonging to a collection of characters, starting at a specified location, searching in reverse.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ncposr(string: &str, chars: &str, start: i32) -> i32 {}
}

cspice_proc! {
    /**
    Expand a triangular plate by a specified amount. The expanded plate is co-planar with, and has the same orientation as, the original. The centroids of the two plates coincide.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn pltexp(iverts: [[f64; 3]; 3], delta: f64) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Parse a string as a double precision number, encapsulating error handling.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn prsdp(string: &str) -> f64 {}
}

cspice_proc! {
    /**
    Parse a string as an integer, encapsulating error handling.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn prsint(string: &str) -> i32 {}
}

cspice_proc! {
    /**
    Derive angular velocity from a unit quaternion and its derivative with respect to time.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn qdq2av(q: [f64; 4], dq: [f64; 4]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Transform a vector to a new coordinate system rotated by `angle' radians about axis `iaxis'. This transformation rotates `v1' by -angle radians about the specified axis.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn rotvec(v1: [f64; 3], angle: f64, iaxis: i32) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Find the roots of a quadratic equation.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn rquad(a: f64, b: f64, c: f64) -> ([f64; 2], [f64; 2]) {}
}

cspice_proc! {
    /**
    Convert ephemeris seconds past J2000 (ET) to integral encoded spacecraft clock (`ticks'). For conversion to fractional ticks, (required for C-kernel production), see the routine sce2c_c.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn sce2t(sc: i32, et: f64) -> f64 {}
}

cspice_proc! {
    /**
    Convert a spacecraft clock format string to number of "ticks".
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn sctiks(sc: i32, clkstr: &str) -> f64 {}
}

cspice_proc! {
    /**
    Set the value of the current long error message.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn setmsg(msg: &str) {}
}

cspice_proc! {
    /**
    Deprecated: This routine has been superseded by the CSPICE routine sincpt_c. This routine is supported for purposes of backward compatibility only.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    #[allow(clippy::type_complexity)]
    pub fn srfxpt(method: &str, target: &str, et: f64, abcorr: &str, obsrvr: &str, dref: &str, dvec: [f64; 3]) -> ([f64; 3], f64, f64, [f64; 3], bool) {}
}

cspice_proc! {
    /**
    Correct the apparent position of an object for stellar aberration.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn stelab(pobj: [f64; 3], vobs: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Correct the position of a target for the stellar aberration effect on radiation transmitted from a specified observer to the target.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn stlabx(pobj: [f64; 3], vobs: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Deprecated: This routine has been superseded by the CSPICE routine subpnt_c. This routine is supported for purposes of backward compatibility only.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn subpt(method: &str, target: &str, et: f64, abcorr: &str, obsrvr: &str) -> ([f64; 3], f64) {}
}

cspice_proc! {
    /**
    Deprecated: This routine has been superseded by the CSPICE routine subslr_c. This routine is supported for purposes of backward compatibility only.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn subsol(method: &str, target: &str, et: f64, abcorr: &str, obsrvr: &str) -> [f64; 3] {}
}

cspice_proc! {
    /**
    Compute, for a given observer, ray emanating from the observer, and target, the "tangent point": the point on the ray nearest to the target's surface. Also compute the point on the target's surface nearest to the tangent point.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    #[allow(clippy::type_complexity)]
    pub fn tangpt(method: &str, target: &str, et: f64, fixref: &str, abcorr: &str, corloc: &str, obsrvr: &str, dref: &str, dvec: [f64; 3]) -> ([f64; 3], f64, f64, [f64; 3], f64, [f64; 3]) {}
}

cspice_proc! {
    /**
    Return a 3x3 matrix that transforms positions in inertial coordinates to positions in body-equator-and-prime-meridian coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn tipbod(frame: &str, body: i32, et: f64) -> [[f64; 3]; 3] {}
}

cspice_proc! {
    /**
    Return a 6x6 matrix that transforms states in inertial coordinates to states in body-equator-and-prime-meridian coordinates.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn tisbod(frame: &str, body: i32, et: f64) -> [[f64; 6]; 6] {}
}

cspice_proc! {
    /**
    Find the position rotation matrix from a Text Kernel (TK) frame with the specified frame class ID to its base frame.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn tkfram(frcode: i32) -> ([[f64; 3]; 3], i32, bool) {}
}

cspice_proc! {
    /**
    Return the number of modules in the traceback representation.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn trcdep() -> i32 {}
}

cspice_proc! {
    /**
    Compute the angular separation in radians between two spherical or point objects.
    */
    #[allow(clippy::too_many_arguments)]
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn trgsep(et: f64, targ1: &str, shape1: &str, frame1: &str, targ2: &str, shape2: &str, frame2: &str, obsrvr: &str, abcorr: &str) -> f64 {}
}

cspice_proc! {
    /**
    Set the lower bound on the 100 year range
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn tsetyr(year: i32) {}
}

cspice_proc! {
    /**
    Find the state transformation from a base frame to the right-handed frame defined by two state vectors: one state vector defining a specified axis and a second state vector defining a specified coordinate plane.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn twovxf(axdef: [f64; 6], indexa: i32, plndef: [f64; 6], indexp: i32) -> [[f64; 6]; 6] {}
}

cspice_proc! {
    /**
    Compute the normalized cross product of two 3-vectors.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ucrss(v1: [f64; 3], v2: [f64; 3]) -> [f64; 3] {}
}

/* ---------------------------------------------------------------------------------------------- */
/* DAF, DAS and the kernel file layers                                                            */
/* ---------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Find the position rotation matrix from a C-kernel (CK) frame with the specified frame class ID (CK ID) to the base frame of the highest priority CK segment containing orientation data for this CK frame at the time requested.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ckfrot(inst: i32, et: f64) -> ([[f64; 3]; 3], i32, bool) {}
}

cspice_proc! {
    /**
    Find the state transformation matrix from a C-kernel (CK) frame with the specified frame class ID (CK ID) to the base frame of the highest priority CK segment containing orientation and angular velocity data for this CK frame at the time requested.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ckfxfm(inst: i32, et: f64) -> ([[f64; 6]; 6], i32, bool) {}
}

cspice_proc! {
    /**
    Load a CK pointing file for use by the CK readers. Return that file's handle, to be used by other CK routines to refer to the file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn cklpf(fname: &str) -> i32 {}
}

cspice_proc! {
    /**
    Return (depending upon the user's request) the ID code of either the spacecraft or spacecraft clock associated with a C-Kernel ID code.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ckmeta(ckid: i32, meta: &str) -> i32 {}
}

cspice_proc! {
    /**
    Unload a CK pointing file so that it will no longer be searched by the readers.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ckupf(handle: i32) {}
}

cspice_proc! {
    /**
    Begin a backward search for arrays in a DAF.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dafbbs(handle: i32) {}
}

cspice_proc! {
    /**
    Begin a forward search for arrays in a DAF.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dafbfs(handle: i32) {}
}

cspice_proc! {
    /**
    Close the DAF associated with a given handle.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dafcls(handle: i32) {}
}

cspice_proc! {
    /**
    Select a DAF that already has a search in progress as the one to continue searching.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dafcs(handle: i32) {}
}

cspice_proc! {
    /**
    Delete the entire comment area of a specified DAF file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dafdc(handle: i32) {}
}

cspice_proc! {
    /**
    Find the next (forward) array in the current DAF.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn daffna() -> bool {}
}

cspice_proc! {
    /**
    Find the previous (backward) array in the current DAF.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn daffpa() -> bool {}
}

cspice_proc! {
    /**
    Return (get) the handle of the DAF currently being searched.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dafgh() -> i32 {}
}

/**
Read a contiguous run of double precision words from a DAF record.

Returns the `end - begin + 1` words, and whether the record was found.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dafgsr(handle: i32, recno: i32, begin: i32, end: i32) -> (Vec<f64>, bool) {
    let words = (end - begin + 1).max(0) as usize;
    let mut data = vec![0.0; words.max(1)];
    let mut found = 0;
    unsafe { crate::c::dafgsr_c(handle, recno, begin, end, data.as_mut_ptr(), &mut found) };
    data.truncate(words);
    (data, found != 0)
}

cspice_proc! {
    /**
    Return the summary format associated with a handle.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dafhsf(handle: i32) -> (i32, i32) {}
}

cspice_proc! {
    /**
    Open a DAF for subsequent read requests.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dafopr(fname: &str) -> i32 {}
}

cspice_proc! {
    /**
    Open a DAF for subsequent write requests.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dafopw(fname: &str) -> i32 {}
}

cspice_proc! {
    /**
    Delete the entire comment area of a previously opened binary DAS file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dasdc(handle: i32) {}
}

cspice_proc! {
    /**
    Return a file summary for a specified DAS file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    #[allow(clippy::type_complexity)]
    pub fn dashfs(handle: i32) -> (i32, i32, i32, i32, i32, [i32; 3], [i32; 3], [i32; 3]) {}
}

cspice_proc! {
    /**
    Return last DAS logical addresses of character, double precision and integer type that are currently in use in a specified DAS file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn daslla(handle: i32) -> (i32, i32, i32) {}
}

cspice_proc! {
    /**
    Close the DAS file associated with a given handle, without flushing buffered data or segregating the file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dasllc(handle: i32) {}
}

cspice_proc! {
    /**
    Open a new DAS file and set the file type.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dasonw(fname: &str, ftype: &str, ifname: &str, ncomr: i32) -> i32 {}
}

cspice_proc! {
    /**
    Open a scratch DAS file for writing.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dasops() -> i32 {}
}

cspice_proc! {
    /**
    Open a DAS file for writing.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dasopw(fname: &str) -> i32 {}
}

cspice_proc! {
    /**
    Write out all buffered records of a specified DAS file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn daswbr(handle: i32) {}
}

cspice_proc! {
    /**
    Begin a new segment in a DLA file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dlabns(handle: i32) {}
}

cspice_proc! {
    /**
    End a new segment in a DLA file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dlaens(handle: i32) {}
}

cspice_proc! {
    /**
    Open a new DLA file and set the file type.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dlaopn(fname: &str, ftype: &str, ifname: &str, ncomch: i32) -> i32 {}
}

cspice_proc! {
    /**
    Close an open PCK file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn pckcls(handle: i32) {}
}

cspice_proc! {
    /**
    Load a binary PCK file for use by the readers. Return the handle of the loaded file which is used by other PCK routines to refer to the file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn pcklof(fname: &str) -> i32 {}
}

cspice_proc! {
    /**
    Create a new PCK file, returning the handle of the opened file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn pckopn(name: &str, ifname: &str, ncomch: i32) -> i32 {}
}

cspice_proc! {
    /**
    Unload a binary PCK file so that it will no longer be searched by the readers.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn pckuof(handle: i32) {}
}

/* -------------------------------------------------------------------------------------------- */
/* DAF and DAS, the array files underneath the kernels                                            */
/* -------------------------------------------------------------------------------------------- */

/// Largest DAF summary, in double precision words.
pub const DAF_MAXSUM: usize = 125;

/// Read a run of double precision words from a DAF, for the two routines that do it.
macro_rules! daf_read {
    ($($name:ident => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// Returns the `end - begin + 1` words, addressed from one.
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(handle: i32, begin: i32, end: i32) -> Vec<f64> {
            let words = (end - begin + 1).max(0) as usize;
            let mut data = vec![0.0; words.max(1)];
            unsafe { crate::c::$cname(handle, begin, end, data.as_mut_ptr()) };
            data.truncate(words);
            data
        }
    )*};
}

daf_read! {
    dafgda => dafgda_c, "Read double precision data from the current array of a DAF.";
    dafrda => dafrda_c, "Read double precision data from a DAF; superseded by `dafgda`.";
}

cspice_proc! {
    /**
    Return the name of the current array in the current DAF.
    */
    pub fn dafgn(#[lenout] lenout: i32) -> String {}
}

/**
Return the summary of the current array in the current DAF.

At most [`DAF_MAXSUM`] words are returned, which is the largest a DAF summary can be.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dafgs() -> Vec<f64> {
    let mut summary = vec![0.0; DAF_MAXSUM];
    unsafe { crate::c::dafgs_c(summary.as_mut_ptr()) };
    summary
}

/**
Pack the double precision and integer components of a DAF summary into one array.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dafps(dc: &[f64], ic: &[i32]) -> Vec<f64> {
    let words = dc.len() + (ic.len() + 1) / 2 + 1;
    let mut summary = vec![0.0; words.max(1)];
    unsafe {
        crate::c::dafps_c(
            dc.len() as SpiceInt,
            ic.len() as SpiceInt,
            dc.as_ptr() as *mut SpiceDouble,
            ic.as_ptr() as *mut SpiceInt,
            summary.as_mut_ptr(),
        )
    };
    summary
}

/**
Unpack a DAF summary into its `nd` double precision and `ni` integer components.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dafus(summary: &[f64], nd: usize, ni: usize) -> (Vec<f64>, Vec<i32>) {
    let mut dc = vec![0.0; nd.max(1)];
    let mut ic = vec![0; ni.max(1)];
    unsafe {
        crate::c::dafus_c(
            summary.as_ptr() as *mut SpiceDouble,
            nd as SpiceInt,
            ni as SpiceInt,
            dc.as_mut_ptr(),
            ic.as_mut_ptr(),
        )
    };
    dc.truncate(nd);
    ic.truncate(ni);
    (dc, ic)
}

/**
Replace the summary of the current array in the current DAF.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dafrs(summary: &[f64]) {
    unsafe { crate::c::dafrs_c(summary.as_ptr() as *mut SpiceDouble) }
}

/**
Read the file record of a DAF: the summary sizes, the internal file name, and the pointers to the
first and last summary records and the first free address.
*/
#[allow(clippy::type_complexity)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dafrfr(handle: i32, lenout: usize) -> (i32, i32, String, i32, i32, i32) {
    let mut ifname = vec![0 as SpiceChar; lenout.max(1)];
    let (mut nd, mut ni, mut fward, mut bward, mut free) = (0, 0, 0, 0, 0);
    unsafe {
        crate::c::dafrfr_c(
            handle,
            lenout as SpiceInt,
            &mut nd,
            &mut ni,
            ifname.as_mut_ptr(),
            &mut fward,
            &mut bward,
            &mut free,
        )
    };
    (nd, ni, from_cbuf(&ifname), fward, bward, free)
}

/**
Add comment lines to the comment area of a DAF.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dafac<S: AsRef<str>>(handle: i32, buffer: &[S]) {
    let (packed, lenvals) = to_strided(buffer);
    unsafe {
        crate::c::dafac_c(
            handle,
            buffer.len() as SpiceInt,
            lenvals as SpiceInt,
            packed.as_ptr().cast(),
        )
    }
}

/**
Read comment lines from the comment area of a DAF.

Returns at most `bufsiz` lines, and whether the comment area has been read to the end.

This function has a [neat version][crate::neat::dafec].
*/
pub fn dafec(handle: i32, bufsiz: usize, lenout: usize) -> (Vec<String>, bool) {
    let lenout = lenout.max(1);
    let mut buffer = vec![0 as SpiceChar; bufsiz.max(1) * lenout];
    let (mut n, mut done) = (0, 0);
    unsafe {
        crate::c::dafec_c(
            handle,
            bufsiz as SpiceInt,
            lenout as SpiceInt,
            &mut n,
            buffer.as_mut_ptr().cast(),
            &mut done,
        )
    };
    (from_strided(&buffer, lenout, n.max(0) as usize), done != 0)
}

/// Read a run of words from a DAS, for the double precision and integer cases.
macro_rules! das_read {
    ($($name:ident($ty:ty) => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// Returns the `last - first + 1` words, addressed from one.
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(handle: i32, first: i32, last: i32) -> Vec<$ty> {
            let words = (last - first + 1).max(0) as usize;
            let mut data = vec![<$ty>::default(); words.max(1)];
            unsafe { crate::c::$cname(handle, first, last, data.as_mut_ptr()) };
            data.truncate(words);
            data
        }
    )*};
}

das_read! {
    dasrdd(f64) => dasrdd_c, "Read double precision data from a DAS.";
    dasrdi(i32) => dasrdi_c, "Read integer data from a DAS.";
}

/// Update a run of words in a DAS, for the double precision and integer cases.
macro_rules! das_update {
    ($($name:ident($ty:ty) => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(handle: i32, first: i32, last: i32, data: &[$ty]) {
            unsafe { crate::c::$cname(handle, first, last, data.as_ptr() as *mut _) }
        }
    )*};
}

das_update! {
    dasudd(f64) => dasudd_c, "Update double precision data in a DAS.";
    dasudi(i32) => dasudi_c, "Update integer data in a DAS.";
}

/// Append data to a DAS, for the double precision and integer cases.
macro_rules! das_add {
    ($($name:ident($ty:ty) => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(handle: i32, data: &[$ty]) {
            unsafe {
                crate::c::$cname(handle, data.len() as SpiceInt, data.as_ptr() as *mut _)
            }
        }
    )*};
}

das_add! {
    dasadd(f64) => dasadd_c, "Append double precision data to a DAS.";
    dasadi(i32) => dasadi_c, "Append integer data to a DAS.";
}

/**
Append characters to a DAS, taking the substring `bpos ..= epos` of each line.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dasadc<S: AsRef<str>>(handle: i32, bpos: i32, epos: i32, data: &[S]) {
    let (packed, datlen) = to_strided(data);
    // The count CSPICE wants is of characters, not of lines.
    let sublen = (epos - bpos + 1).max(0) as usize;
    unsafe {
        crate::c::dasadc_c(
            handle,
            (data.len() * sublen) as SpiceInt,
            bpos,
            epos,
            datlen as SpiceInt,
            packed.as_ptr().cast(),
        )
    }
}

/**
Read characters from a DAS, into the substring `bpos ..= epos` of each line.

Returns one line per substring the range covers, each `epos + 1` characters long, of which only
`bpos ..= epos` come from the file.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dasrdc(handle: i32, first: i32, last: i32, bpos: i32, epos: i32) -> Vec<String> {
    let sublen = (epos - bpos + 1).max(1) as usize;
    let datlen = (epos + 1).max(1) as usize;
    let lines = ((last - first + 1).max(0) as usize + sublen - 1) / sublen;
    // The routine reads the file as a stream of characters and leaves the rest of each line alone,
    // so the lines start out blank rather than empty.
    let mut data = vec![b' ' as SpiceChar; lines.max(1) * datlen];
    unsafe {
        crate::c::dasrdc_c(
            handle,
            first,
            last,
            bpos,
            epos,
            datlen as SpiceInt,
            data.as_mut_ptr().cast(),
        )
    };
    (0..lines)
        .map(|line| {
            data[line * datlen..(line + 1) * datlen]
                .iter()
                .map(|&byte| byte as u8 as char)
                .collect()
        })
        .collect()
}

/**
Update characters in a DAS, taking the substring `bpos ..= epos` of each line.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dasudc<S: AsRef<str>>(handle: i32, first: i32, last: i32, bpos: i32, epos: i32, data: &[S]) {
    // Only `bpos ..= epos` of each line is read, so every line has to reach at least that far.
    let datlen = (epos + 1).max(1) as usize;
    let mut packed = vec![b' ' as SpiceChar; data.len().max(1) * datlen];
    for (line, value) in data.iter().enumerate() {
        let slot = &mut packed[line * datlen..(line + 1) * datlen];
        for (target, byte) in slot.iter_mut().zip(value.as_ref().as_bytes()) {
            *target = *byte as SpiceChar;
        }
    }
    unsafe {
        crate::c::dasudc_c(
            handle,
            first,
            last,
            bpos,
            epos,
            datlen as SpiceInt,
            packed.as_ptr().cast(),
        )
    }
}

/**
Add comment lines to the comment area of a DAS.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dasac<S: AsRef<str>>(handle: i32, buffer: &[S]) {
    let (packed, buflen) = to_strided(buffer);
    unsafe {
        crate::c::dasac_c(
            handle,
            buffer.len() as SpiceInt,
            buflen as SpiceInt,
            packed.as_ptr().cast(),
        )
    }
}

/**
Read comment lines from the comment area of a DAS.

This function has a [neat version][crate::neat::dasec].
*/
pub fn dasec(handle: i32, bufsiz: usize, buflen: usize) -> (Vec<String>, bool) {
    let buflen = buflen.max(1);
    let mut buffer = vec![0 as SpiceChar; bufsiz.max(1) * buflen];
    let (mut n, mut done) = (0, 0);
    unsafe {
        crate::c::dasec_c(
            handle,
            bufsiz as SpiceInt,
            buflen as SpiceInt,
            &mut n,
            buffer.as_mut_ptr().cast(),
            &mut done,
        )
    };
    (from_strided(&buffer, buflen, n.max(0) as usize), done != 0)
}

cspice_proc! {
    /**
    Return the name of the file a DAS handle refers to.
    */
    pub fn dashfn(handle: i32, #[lenout] namlen: i32) -> String {}
}

/**
Read the file record of a DAS: the ID word, the internal file name, and the reserved and comment
area sizes.
*/
#[allow(clippy::type_complexity)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dasrfr(handle: i32, idwlen: usize, ifnlen: usize) -> (String, String, i32, i32, i32, i32) {
    let mut idword = vec![0 as SpiceChar; idwlen.max(1)];
    let mut ifname = vec![0 as SpiceChar; ifnlen.max(1)];
    let (mut nresvr, mut nresvc, mut ncomr, mut ncomc) = (0, 0, 0, 0);
    unsafe {
        crate::c::dasrfr_c(
            handle,
            idwlen as SpiceInt,
            ifnlen as SpiceInt,
            idword.as_mut_ptr(),
            ifname.as_mut_ptr(),
            &mut nresvr,
            &mut nresvc,
            &mut ncomr,
            &mut ncomc,
        )
    };
    (
        from_cbuf(&idword),
        from_cbuf(&ifname),
        nresvr,
        nresvc,
        ncomr,
        ncomc,
    )
}

cspice_proc! {
    /**
    Find the segment preceding a specified segment in a DLA file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn dlafps(handle: i32, descr: DLADSC) -> (DLADSC, bool) {}
}

/* ---------------------------------------------------------------------------------------------- */
/* Kernel readers and writers                                                                     */
/* ---------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Begin a type 14 SPK segment in the SPK file associated with `handle'.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spk14b(handle: i32, segid: &str, body: i32, center: i32, frame: &str, first: f64, last: f64, chbdeg: i32) {}
}

cspice_proc! {
    /**
    End the type 14 SPK segment currently being written to the SPK file associated with `handle'.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spk14e(handle: i32) {}
}

cspice_proc! {
    /**
    Return the state (position and velocity) of a target body relative to an observer, optionally corrected for light time and stellar aberration, expressed relative to an inertial reference frame.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkacs(targ: i32, et: f64, frame: &str, abcorr: &str, obs: i32) -> ([f64; 6], f64, f64) {}
}

cspice_proc! {
    /**
    Return the position of a target body relative to an observer, optionally corrected for light time and stellar aberration.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkapo(targ: i32, et: f64, frame: &str, sobs: [f64; 6], abcorr: &str) -> ([f64; 3], f64) {}
}

cspice_proc! {
    /**
    Deprecated: This routine has been superseded by the CSPICE routine spkaps_c. This routine is supported for purposes of backward compatibility only.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkapp(targ: i32, et: f64, frame: &str, sobs: [f64; 6], abcorr: &str) -> ([f64; 6], f64) {}
}

cspice_proc! {
    /**
    Return the state (position and velocity) of a target body relative to an observer specified by its state and acceleration relative to the solar system barycenter. The returned state may be optionally corrected for light time and stellar aberration. All input and output vectors are expressed relative to an inertial reference frame.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkaps(targ: i32, et: f64, frame: &str, abcorr: &str, stobs: [f64; 6], accobs: [f64; 3]) -> ([f64; 6], f64, f64) {}
}

cspice_proc! {
    /**
    Compute the geometric position of a target body relative to an observing body.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkgps(targ: i32, et: f64, frame: &str, obs: i32) -> ([f64; 3], f64) {}
}

cspice_proc! {
    /**
    Return the state (position and velocity) of a target body relative to an observer, optionally corrected for light time, expressed relative to an inertial reference frame.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkltc(targ: i32, et: f64, frame: &str, abcorr: &str, stobs: [f64; 6]) -> ([f64; 6], f64, f64) {}
}

cspice_proc! {
    /**
    Perform routine error checks and if all check pass, pack the descriptor for an SPK segment
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkpds(body: i32, center: i32, frame: &str, kind: i32, first: f64, last: f64) -> [f64; 5] {}
}

cspice_proc! {
    /**
    Return, for a specified SPK segment and time, the state (position and velocity) of the segment's target body relative to its center of motion.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkpvn(handle: i32, descr: [f64; 5], et: f64) -> (i32, [f64; 6], i32) {}
}

cspice_proc! {
    /**
    Return the state (position and velocity) of a target body relative to the solar system barycenter.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkssb(targ: i32, et: f64, frame: &str) -> [f64; 6] {}
}

cspice_proc! {
    /**
    Unload an ephemeris file so that it will no longer be searched by the readers.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkuef(handle: i32) {}
}

cspice_proc! {
    /**
    Write an SPK segment of type 15 given a type 15 data record.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkw15(handle: i32, body: i32, center: i32, frame: &str, first: f64, last: f64, segid: &str, epoch: f64, tp: [f64; 3], pa: [f64; 3], p: f64, ecc: f64, j2flg: f64, pv: [f64; 3], gm: f64, j2: f64, radius: f64) {}
}

cspice_proc! {
    /**
    Write an SPK segment of type 17 given a type 17 data record.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spkw17(handle: i32, body: i32, center: i32, frame: &str, first: f64, last: f64, segid: &str, epoch: f64, eqel: [f64; 9], rapol: f64, decpol: f64) {}
}

/* -------------------------------------------------------------------------------------------- */
/* Kernel writers and low level readers                                                           */
/* -------------------------------------------------------------------------------------------- */

/// Largest SPK or PCK segment descriptor, in double precision words.
pub const SPK_DSCSIZ: usize = 5;

/// Write a segment whose data is one flat run of Chebyshev coefficients.
macro_rules! spk_chebyshev {
    ($($name:ident => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        #[allow(clippy::too_many_arguments)]
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(
            handle: i32,
            body: i32,
            center: i32,
            frame: &str,
            first: f64,
            last: f64,
            segid: &str,
            intlen: f64,
            n: i32,
            polydg: i32,
            cdata: &[f64],
            btime: f64,
        ) {
            let frame = to_cstring(frame);
            let segid = to_cstring(segid);
            unsafe {
                crate::c::$cname(
                    handle, body, center,
                    frame.as_ptr() as *mut SpiceChar,
                    first, last,
                    segid.as_ptr() as *mut SpiceChar,
                    intlen, n, polydg,
                    cdata.as_ptr() as *mut SpiceDouble,
                    btime,
                );
            }
        }
    )*};
}

spk_chebyshev! {
    spkw02 => spkw02_c, "Write a type 2 segment: Chebyshev polynomials for position.";
    spkw03 => spkw03_c, "Write a type 3 segment: Chebyshev polynomials for position and velocity.";
}

/// Write a segment whose data is a run of states at given epochs.
macro_rules! spk_states_at_epochs {
    ($($name:ident($mid:ident: $midty:ty) => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// # Panics
        ///
        /// Panics if `n` is larger than `states` or `epochs`.
        #[allow(clippy::too_many_arguments)]
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(
            handle: i32,
            body: i32,
            center: i32,
            frame: &str,
            first: f64,
            last: f64,
            segid: &str,
            $mid: $midty,
            n: i32,
            states: &[[f64; 6]],
            epochs: &[f64],
        ) {
            let count = usize::try_from(n).expect("the record count cannot be negative");
            assert!(
                count <= states.len() && count <= epochs.len(),
                "asked for {count} records but got {} states and {} epochs",
                states.len(),
                epochs.len()
            );
            let frame = to_cstring(frame);
            let segid = to_cstring(segid);
            unsafe {
                crate::c::$cname(
                    handle, body, center,
                    frame.as_ptr() as *mut SpiceChar,
                    first, last,
                    segid.as_ptr() as *mut SpiceChar,
                    $mid, n,
                    states.as_ptr() as *mut [SpiceDouble; 6],
                    epochs.as_ptr() as *mut SpiceDouble,
                );
            }
        }
    )*};
}

spk_states_at_epochs! {
    spkw05(gm: f64) => spkw05_c,
        "Write a type 5 segment: discrete states propagated with two body dynamics.";
    spkw13(degree: i32) => spkw13_c,
        "Write a type 13 segment: Hermite interpolation of unequally spaced states.";
}

/// Write a segment whose states are evenly spaced in time.
macro_rules! spk_states_evenly_spaced {
    ($($name:ident => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// # Panics
        ///
        /// Panics if `n` is larger than `states`.
        #[allow(clippy::too_many_arguments)]
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(
            handle: i32,
            body: i32,
            center: i32,
            frame: &str,
            first: f64,
            last: f64,
            segid: &str,
            degree: i32,
            n: i32,
            states: &[[f64; 6]],
            epoch0: f64,
            step: f64,
        ) {
            let count = usize::try_from(n).expect("the record count cannot be negative");
            assert!(count <= states.len(), "asked for {count} states but got {}", states.len());
            let frame = to_cstring(frame);
            let segid = to_cstring(segid);
            unsafe {
                crate::c::$cname(
                    handle, body, center,
                    frame.as_ptr() as *mut SpiceChar,
                    first, last,
                    segid.as_ptr() as *mut SpiceChar,
                    degree, n,
                    states.as_ptr() as *mut [SpiceDouble; 6],
                    epoch0, step,
                );
            }
        }
    )*};
}

spk_states_evenly_spaced! {
    spkw08 => spkw08_c, "Write a type 8 segment: Lagrange interpolation of evenly spaced states.";
    spkw12 => spkw12_c, "Write a type 12 segment: Hermite interpolation of evenly spaced states.";
}

/**
Write a type 10 segment: two-line element sets.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn spkw10(
    handle: i32,
    body: i32,
    center: i32,
    frame: &str,
    first: f64,
    last: f64,
    segid: &str,
    consts: &[f64],
    n: i32,
    elems: &[f64],
    epochs: &[f64],
) {
    let frame = to_cstring(frame);
    let segid = to_cstring(segid);
    unsafe {
        crate::c::spkw10_c(
            handle,
            body,
            center,
            frame.as_ptr() as *mut SpiceChar,
            first,
            last,
            segid.as_ptr() as *mut SpiceChar,
            consts.as_ptr() as *mut SpiceDouble,
            n,
            elems.as_ptr() as *mut SpiceDouble,
            epochs.as_ptr() as *mut SpiceDouble,
        );
    }
}

/**
Write a type 18 segment: Hermite or Lagrange interpolation of packets of state data.

`packts` holds one packet per epoch, laid out row by row.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn spkw18(
    handle: i32,
    subtyp: i32,
    body: i32,
    center: i32,
    frame: &str,
    first: f64,
    last: f64,
    segid: &str,
    degree: i32,
    n: i32,
    packts: &[f64],
    epochs: &[f64],
) {
    let frame = to_cstring(frame);
    let segid = to_cstring(segid);
    unsafe {
        crate::c::spkw18_c(
            handle,
            subtyp as crate::c::SpiceSPK18Subtype,
            body,
            center,
            frame.as_ptr() as *mut SpiceChar,
            first,
            last,
            segid.as_ptr() as *mut SpiceChar,
            degree,
            n,
            packts.as_ptr().cast(),
            epochs.as_ptr() as *mut SpiceDouble,
        );
    }
}

/**
Write a type 20 segment: Chebyshev polynomials for velocity, with the position at the interval
start.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn spkw20(
    handle: i32,
    body: i32,
    center: i32,
    frame: &str,
    first: f64,
    last: f64,
    segid: &str,
    intlen: f64,
    n: i32,
    polydg: i32,
    cdata: &[f64],
    dscale: f64,
    tscale: f64,
    initjd: f64,
    initfr: f64,
) {
    let frame = to_cstring(frame);
    let segid = to_cstring(segid);
    unsafe {
        crate::c::spkw20_c(
            handle,
            body,
            center,
            frame.as_ptr() as *mut SpiceChar,
            first,
            last,
            segid.as_ptr() as *mut SpiceChar,
            intlen,
            n,
            polydg,
            cdata.as_ptr() as *mut SpiceDouble,
            dscale,
            tscale,
            initjd,
            initfr,
        );
    }
}

/**
Add Chebyshev coefficient sets to a type 14 segment opened with [`spk14b`].
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn spk14a(handle: i32, ncsets: i32, coeffs: &[f64], epochs: &[f64]) {
    unsafe {
        crate::c::spk14a_c(
            handle,
            ncsets,
            coeffs.as_ptr() as *mut SpiceDouble,
            epochs.as_ptr() as *mut SpiceDouble,
        )
    }
}

/**
Search for the segment of an SPK that covers a body at an epoch.

This function has a [neat version][crate::neat::spksfs].
*/
pub fn spksfs(body: i32, et: f64, idlen: usize) -> (i32, [f64; SPK_DSCSIZ], String, bool) {
    let mut descr = [0.0; SPK_DSCSIZ];
    let mut ident = vec![0 as SpiceChar; idlen.max(1)];
    let (mut handle, mut found) = (0, 0);
    unsafe {
        crate::c::spksfs_c(
            body,
            et,
            idlen as SpiceInt,
            &mut handle,
            descr.as_mut_ptr(),
            ident.as_mut_ptr(),
            &mut found,
        )
    };
    (handle, descr, from_cbuf(&ident), found != 0)
}

cspice_proc! {
    /**
    Load an SPK for use by the low level readers, outside the KEEPER subsystem.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn spklef(filename: &str) -> i32 {}
}

/**
Unpack an SPK segment descriptor.
*/
#[allow(clippy::type_complexity)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn spkuds(descr: &[f64]) -> (i32, i32, i32, i32, f64, f64, i32, i32) {
    let (mut body, mut center, mut frame, mut kind) = (0, 0, 0, 0);
    let (mut first, mut last) = (0.0, 0.0);
    let (mut begin, mut end) = (0, 0);
    unsafe {
        crate::c::spkuds_c(
            descr.as_ptr() as *mut SpiceDouble,
            &mut body,
            &mut center,
            &mut frame,
            &mut kind,
            &mut first,
            &mut last,
            &mut begin,
            &mut end,
        )
    };
    (body, center, frame, kind, first, last, begin, end)
}

/**
Copy a subset of the data in an SPK segment into another file.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn spksub(handle: i32, descr: &mut [f64], ident: &str, begin: f64, end: f64, newh: i32) {
    let ident = to_cstring(ident);
    unsafe {
        crate::c::spksub_c(
            handle,
            descr.as_mut_ptr(),
            ident.as_ptr() as *mut SpiceChar,
            begin,
            end,
            newh,
        )
    }
}

/**
Write a type 1 segment to a CK file: discrete pointing with angular velocity.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn ckw01(
    handle: i32,
    begtime: f64,
    endtime: f64,
    inst: i32,
    frame: &str,
    avflag: bool,
    segid: &str,
    nrec: i32,
    sclkdp: &[f64],
    quats: &[[f64; 4]],
    avvs: &[[f64; 3]],
) {
    let frame = to_cstring(frame);
    let segid = to_cstring(segid);
    unsafe {
        crate::c::ckw01_c(
            handle,
            begtime,
            endtime,
            inst,
            frame.as_ptr() as *mut SpiceChar,
            avflag as crate::c::SpiceBoolean,
            segid.as_ptr() as *mut SpiceChar,
            nrec,
            sclkdp.as_ptr() as *mut SpiceDouble,
            quats.as_ptr() as *mut [SpiceDouble; 4],
            avvs.as_ptr() as *mut [SpiceDouble; 3],
        );
    }
}

/**
Write a type 2 segment to a CK file: constant angular velocity over each interval.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn ckw02(
    handle: i32,
    begtim: f64,
    endtim: f64,
    inst: i32,
    frame: &str,
    segid: &str,
    nrec: i32,
    start: &[f64],
    stop: &[f64],
    quats: &[[f64; 4]],
    avvs: &[[f64; 3]],
    rates: &[f64],
) {
    let frame = to_cstring(frame);
    let segid = to_cstring(segid);
    unsafe {
        crate::c::ckw02_c(
            handle,
            begtim,
            endtim,
            inst,
            frame.as_ptr() as *mut SpiceChar,
            segid.as_ptr() as *mut SpiceChar,
            nrec,
            start.as_ptr() as *mut SpiceDouble,
            stop.as_ptr() as *mut SpiceDouble,
            quats.as_ptr() as *mut [SpiceDouble; 4],
            avvs.as_ptr() as *mut [SpiceDouble; 3],
            rates.as_ptr() as *mut SpiceDouble,
        );
    }
}

/**
Write a type 5 segment to a CK file: interpolated quaternion packets.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn ckw05(
    handle: i32,
    subtyp: i32,
    degree: i32,
    begtim: f64,
    endtim: f64,
    inst: i32,
    frame: &str,
    avflag: bool,
    segid: &str,
    n: i32,
    sclkdp: &[f64],
    packets: &[f64],
    rate: f64,
    nints: i32,
    starts: &[f64],
) {
    let frame = to_cstring(frame);
    let segid = to_cstring(segid);
    unsafe {
        crate::c::ckw05_c(
            handle,
            subtyp as crate::c::SpiceCK05Subtype,
            degree,
            begtim,
            endtim,
            inst,
            frame.as_ptr() as *mut SpiceChar,
            avflag as crate::c::SpiceBoolean,
            segid.as_ptr() as *mut SpiceChar,
            n,
            sclkdp.as_ptr() as *mut SpiceDouble,
            packets.as_ptr().cast(),
            rate,
            nints,
            starts.as_ptr() as *mut SpiceDouble,
        );
    }
}

/// Read a pointing record from a CK segment, for the two segment types that have them.
macro_rules! ck_record {
    ($($name:ident => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// `room` is how many double precision words to make space for.
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(handle: i32, descr: &[f64], recno: i32, room: usize) -> Vec<f64> {
            let mut record = vec![0.0; room.max(1)];
            unsafe {
                crate::c::$cname(
                    handle,
                    descr.as_ptr() as *mut SpiceDouble,
                    recno,
                    record.as_mut_ptr(),
                )
            };
            record
        }
    )*};
}

ck_record! {
    ckgr02 => ckgr02_c, "Read a pointing record from a type 2 CK segment.";
    ckgr03 => ckgr03_c, "Read a pointing record from a type 3 CK segment.";
}

/// Count the pointing records of a CK segment, for the two segment types that have them.
macro_rules! ck_record_count {
    ($($name:ident => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(handle: i32, descr: &[f64]) -> i32 {
            let mut nrec = 0;
            unsafe {
                crate::c::$cname(handle, descr.as_ptr() as *mut SpiceDouble, &mut nrec)
            };
            nrec
        }
    )*};
}

ck_record_count! {
    cknr02 => cknr02_c, "Number of pointing records in a type 2 CK segment.";
    cknr03 => cknr03_c, "Number of pointing records in a type 3 CK segment.";
}

/**
Write a type 2 segment to a binary PCK file: Chebyshev polynomials for the Euler angles.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn pckw02(
    handle: i32,
    clssid: i32,
    frame: &str,
    first: f64,
    last: f64,
    segid: &str,
    intlen: f64,
    n: i32,
    polydg: i32,
    cdata: &[f64],
    btime: f64,
) {
    let frame = to_cstring(frame);
    let segid = to_cstring(segid);
    unsafe {
        crate::c::pckw02_c(
            handle,
            clssid,
            frame.as_ptr() as *mut SpiceChar,
            first,
            last,
            segid.as_ptr() as *mut SpiceChar,
            intlen,
            n,
            polydg,
            cdata.as_ptr() as *mut SpiceDouble,
            btime,
        );
    }
}

/**
Return the bookkeeping parameters of a type 2 DSK segment.
*/
#[allow(clippy::type_complexity)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dskb02(
    handle: i32,
    dladsc: DLADSC,
) -> (
    i32,
    i32,
    i32,
    [[f64; 2]; 3],
    f64,
    [f64; 3],
    [i32; 3],
    i32,
    i32,
    i32,
    i32,
) {
    let mut dladsc = dladsc;
    let (mut nv, mut np, mut nvxtot) = (0, 0, 0);
    let mut vtxbds = [[0.0; 2]; 3];
    let mut voxsiz = 0.0;
    let mut voxori = [0.0; 3];
    let mut vgrext = [0; 3];
    let (mut cgscal, mut vtxnpl, mut voxnpt, mut voxnpl) = (0, 0, 0, 0);
    unsafe {
        crate::c::dskb02_c(
            handle,
            &mut dladsc,
            &mut nv,
            &mut np,
            &mut nvxtot,
            vtxbds.as_mut_ptr(),
            &mut voxsiz,
            voxori.as_mut_ptr(),
            vgrext.as_mut_ptr(),
            &mut cgscal,
            &mut vtxnpl,
            &mut voxnpt,
            &mut voxnpl,
        )
    };
    (
        nv, np, nvxtot, vtxbds, voxsiz, voxori, vgrext, cgscal, vtxnpl, voxnpt, voxnpl,
    )
}

/// Fetch a run of items from a type 2 DSK segment, for the double precision and integer cases.
macro_rules! dsk_fetch {
    ($($name:ident($ty:ty) => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// `item` is one of the [`dsk02`] keywords and at most `room` values are returned.
        ///
        /// `start` counts from **zero**, unlike most of the toolkit: the vertex indices of the
        /// first plate are at `start` 0, even though plate IDs themselves start at 1.
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(
            handle: i32,
            dladsc: DLADSC,
            item: i32,
            start: i32,
            room: usize,
        ) -> Vec<$ty> {
            let mut dladsc = dladsc;
            let mut values = vec![<$ty>::default(); room.max(1)];
            let mut n = 0;
            unsafe {
                crate::c::$cname(
                    handle,
                    &mut dladsc,
                    item,
                    start,
                    room as SpiceInt,
                    &mut n,
                    values.as_mut_ptr(),
                )
            };
            values.truncate(n.max(0) as usize);
            values
        }
    )*};
}

dsk_fetch! {
    dskd02(f64) => dskd02_c, "Fetch double precision data from a type 2 DSK segment.";
    dski02(i32) => dski02_c, "Fetch integer data from a type 2 DSK segment.";
}

/**
Determine the vertical extent of a plate set in a given coordinate system.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dskrb2(vrtces: &[[f64; 3]], plates: &[[i32; 3]], corsys: i32, corpar: &[f64]) -> (f64, f64) {
    assert!(
        corpar.len() >= DSK_NSYPAR,
        "dskrb2 needs {DSK_NSYPAR} coordinate parameters but got {}",
        corpar.len()
    );
    let (mut mncor3, mut mxcor3) = (0.0, 0.0);
    unsafe {
        crate::c::dskrb2_c(
            vrtces.len() as SpiceInt,
            vrtces.as_ptr() as *mut [f64; 3],
            plates.len() as SpiceInt,
            plates.as_ptr() as *mut [SpiceInt; 3],
            corsys,
            corpar.as_ptr() as *mut SpiceDouble,
            &mut mncor3,
            &mut mxcor3,
        )
    };
    (mncor3, mxcor3)
}

cspice_proc! {
    /**
    Convert encoded spacecraft clock ticks to a clock string.
    */
    pub fn scfmt(sc: i32, ticks: f64, #[lenout] clkstrlen: i32) -> String {}
}

/**
Return the partition start and stop times of a spacecraft clock.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn scpart(sc: i32, maxparts: usize) -> (Vec<f64>, Vec<f64>) {
    let mut pstart = vec![0.0; maxparts.max(1)];
    let mut pstop = vec![0.0; maxparts.max(1)];
    let mut nparts = 0;
    unsafe { crate::c::scpart_c(sc, &mut nparts, pstart.as_mut_ptr(), pstop.as_mut_ptr()) };
    let count = nparts.max(0) as usize;
    pstart.truncate(count);
    pstop.truncate(count);
    (pstart, pstop)
}

/* -------------------------------------------------------------------------------------------- */
/* Interpolation and polynomials                                                                  */
/* -------------------------------------------------------------------------------------------- */

/**
Evaluate a Chebyshev expansion at `x`, returning the value and its derivative.

`x2s` holds the midpoint and radius of the interval the expansion is defined on.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn chbint(cp: &[f64], degp: i32, x2s: [f64; 2], x: f64) -> (f64, f64) {
    let (mut p, mut dpdx) = (0.0, 0.0);
    unsafe {
        crate::c::chbint_c(
            cp.as_ptr() as *mut SpiceDouble,
            degp,
            x2s.as_ptr() as *mut SpiceDouble,
            x,
            &mut p,
            &mut dpdx,
        )
    };
    (p, dpdx)
}

/**
Evaluate a Chebyshev expansion at `x`.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn chbval(cp: &[f64], degp: i32, x2s: [f64; 2], x: f64) -> f64 {
    let mut p = 0.0;
    unsafe {
        crate::c::chbval_c(
            cp.as_ptr() as *mut SpiceDouble,
            degp,
            x2s.as_ptr() as *mut SpiceDouble,
            x,
            &mut p,
        )
    };
    p
}

/**
Evaluate a Chebyshev expansion at `x`, returning the value and its indefinite integral.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn chbigr(degp: i32, cp: &[f64], x2s: [f64; 2], x: f64) -> (f64, f64) {
    let (mut p, mut itgrlp) = (0.0, 0.0);
    unsafe {
        crate::c::chbigr_c(
            degp,
            cp.as_ptr() as *mut SpiceDouble,
            x2s.as_ptr() as *mut SpiceDouble,
            x,
            &mut p,
            &mut itgrlp,
        )
    };
    (p, itgrlp)
}

/**
Evaluate a Chebyshev expansion and its first `nderiv` derivatives at `x`.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn chbder(cp: &[f64], degp: i32, x2s: [f64; 2], x: f64, nderiv: i32) -> Vec<f64> {
    let count = nderiv.max(0) as usize + 1;
    let mut partdp = vec![0.0; 3 * count.max(1)];
    let mut dpdxs = vec![0.0; count.max(1)];
    let mut x2s = x2s;
    unsafe {
        crate::c::chbder_c(
            cp.as_ptr() as *mut SpiceDouble,
            degp,
            x2s.as_mut_ptr(),
            x,
            nderiv,
            partdp.as_mut_ptr(),
            dpdxs.as_mut_ptr(),
        )
    };
    dpdxs
}

/**
Evaluate a polynomial and its first `nderiv` derivatives at `t`.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn polyds(coeffs: &[f64], deg: i32, nderiv: i32, t: f64) -> Vec<f64> {
    let mut p = vec![0.0; nderiv.max(0) as usize + 1];
    unsafe {
        crate::c::polyds_c(
            coeffs.as_ptr() as *mut SpiceDouble,
            deg,
            nderiv,
            t,
            p.as_mut_ptr(),
        )
    };
    p
}

/**
Hermite interpolate a function and its derivative at evenly spaced points.

`yvals` holds the value and derivative at each point, in pairs.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn hrmesp(first: f64, step: f64, yvals: &[f64], x: f64) -> (f64, f64) {
    let n = (yvals.len() / 2) as SpiceInt;
    let (mut f, mut df) = (0.0, 0.0);
    unsafe {
        crate::c::hrmesp_c(
            n,
            first,
            step,
            yvals.as_ptr() as *mut SpiceDouble,
            x,
            &mut f,
            &mut df,
        )
    };
    (f, df)
}

/**
Hermite interpolate a function and its derivative at unevenly spaced points.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn hrmint(xvals: &[f64], yvals: &[f64], x: f64) -> (f64, f64) {
    let n = xvals.len() as SpiceInt;
    let mut work = vec![0.0; (4 * xvals.len() + 4).max(1)];
    let (mut f, mut df) = (0.0, 0.0);
    unsafe {
        crate::c::hrmint_c(
            n,
            xvals.as_ptr() as *mut SpiceDouble,
            yvals.as_ptr() as *mut SpiceDouble,
            x,
            work.as_mut_ptr(),
            &mut f,
            &mut df,
        )
    };
    (f, df)
}

/**
Lagrange interpolate a function at evenly spaced points.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn lgresp(first: f64, step: f64, yvals: &[f64], x: f64) -> f64 {
    unsafe {
        crate::c::lgresp_c(
            yvals.len() as SpiceInt,
            first,
            step,
            yvals.as_ptr() as *mut SpiceDouble,
            x,
        )
    }
}

/**
Lagrange interpolate a function at unevenly spaced points.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn lgrint(xvals: &[f64], yvals: &[f64], x: f64) -> f64 {
    unsafe {
        crate::c::lgrint_c(
            xvals.len() as SpiceInt,
            xvals.as_ptr() as *mut SpiceDouble,
            yvals.as_ptr() as *mut SpiceDouble,
            x,
        )
    }
}

/**
Lagrange interpolate a function and its derivative at unevenly spaced points.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn lgrind(xvals: &[f64], yvals: &[f64], x: f64) -> (f64, f64) {
    let mut work = vec![0.0; (2 * xvals.len() + 2).max(1)];
    let (mut p, mut dp) = (0.0, 0.0);
    unsafe {
        crate::c::lgrind_c(
            xvals.len() as SpiceInt,
            xvals.as_ptr() as *mut SpiceDouble,
            yvals.as_ptr() as *mut SpiceDouble,
            work.as_mut_ptr(),
            x,
            &mut p,
            &mut dp,
        )
    };
    (p, dp)
}

/**
Estimate a derivative by the central difference of a function sampled either side of a point.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn qderiv(f0: &[f64], f2: &[f64], delta: f64) -> Vec<f64> {
    let ndim = f0.len().min(f2.len());
    let mut dfdt = vec![0.0; ndim.max(1)];
    unsafe {
        crate::c::qderiv_c(
            ndim as SpiceInt,
            f0.as_ptr() as *mut SpiceDouble,
            f2.as_ptr() as *mut SpiceDouble,
            delta,
            dfdt.as_mut_ptr(),
        )
    };
    dfdt.truncate(ndim);
    dfdt
}

/* -------------------------------------------------------------------------------------------- */
/* Plates                                                                                         */
/* -------------------------------------------------------------------------------------------- */

/**
The total area of a set of triangular plates.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn pltar(vrtces: &[[f64; 3]], plates: &[[i32; 3]]) -> f64 {
    unsafe {
        crate::c::pltar_c(
            vrtces.len() as SpiceInt,
            vrtces.as_ptr() as *mut [f64; 3],
            plates.len() as SpiceInt,
            plates.as_ptr() as *mut [SpiceInt; 3],
        )
    }
}

/**
The volume enclosed by a set of triangular plates.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn pltvol(vrtces: &[[f64; 3]], plates: &[[i32; 3]]) -> f64 {
    unsafe {
        crate::c::pltvol_c(
            vrtces.len() as SpiceInt,
            vrtces.as_ptr() as *mut [f64; 3],
            plates.len() as SpiceInt,
            plates.as_ptr() as *mut [SpiceInt; 3],
        )
    }
}

cspice_proc! {
    /**
    The outward normal of a triangular plate, scaled by twice its area.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn pltnrm(v1: [f64; 3], v2: [f64; 3], v3: [f64; 3]) -> [f64; 3] {}
}

cspice_proc! {
    /**
    The point of a triangular plate nearest a given point, and the distance between them.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn pltnp(
        point: [f64; 3],
        v1: [f64; 3],
        v2: [f64; 3],
        v3: [f64; 3]
    ) -> ([f64; 3], f64) {
    }
}

cspice_proc! {
    /**
    Diagonalize a symmetric 2x2 matrix, returning the diagonal and the rotation that produces it.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn diags2(symmat: [[f64; 2]; 2]) -> ([[f64; 2]; 2], [[f64; 2]; 2]) {}
}

/* -------------------------------------------------------------------------------------------- */
/* More searches, sets and the kernel pool                                                        */
/* -------------------------------------------------------------------------------------------- */

/// Linear search of an unordered array, for the three element types.
macro_rules! linear_search {
    ($($name:ident($ty:ty) => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// Returns the index found, or `-1`.
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(value: $ty, array: &[$ty]) -> i32 {
            unsafe { crate::c::$cname(value, array.len() as SpiceInt, array.as_ptr() as *mut _) }
        }
    )*};
}

linear_search! {
    isrchd(f64) => isrchd_c, "Search an unordered array of doubles.";
    isrchi(i32) => isrchi_c, "Search an unordered array of integers.";
}

/**
Search an unordered array of strings.

Returns the index found, or `-1`.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn isrchc<S: AsRef<str>>(value: &str, array: &[S]) -> i32 {
    let value = to_cstring(value);
    let (buffer, stride) = to_strided(array);
    unsafe {
        crate::c::isrchc_c(
            value.as_ptr() as *mut SpiceChar,
            array.len() as SpiceInt,
            stride as SpiceInt,
            buffer.as_ptr().cast(),
        )
    }
}

/// The ordinal position of an item within a set, for the three element types.
macro_rules! ordinal {
    ($($name:ident($ty:ty, $cell:ty) => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// Positions run from zero; the result is `-1` when the item is not in the set.
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(item: $ty, set: &mut Cell<$cell>) -> i32 {
            let raw = set.as_mut_ptr();
            unsafe { crate::c::$cname(item, raw) }
        }
    )*};
}

ordinal! {
    ordd(f64, f64) => ordd_c, "The ordinal position of a double precision number in a set.";
    ordi(i32, i32) => ordi_c, "The ordinal position of an integer in a set.";
}

/**
The ordinal position of a string in a set, counting from zero, or `-1` when it is absent.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn ordc(item: &str, set: &mut Cell<String>) -> i32 {
    let item = to_cstring(item);
    let raw = set.as_mut_ptr();
    unsafe { crate::c::ordc_c(item.as_ptr() as *mut SpiceChar, raw) }
}

cspice_proc! {
    /**
    Place the symmetric difference of two sets into `c`.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn sdiff<T: CellItem>(a: &mut Cell<T>, b: &mut Cell<T>, c: &mut Cell<T>) {}
}

cspice_proc! {
    /**
    Compare two sets; `op` is one of `"="`, `"<>"`, `"<="`, `"<"`, `">="` or `">"`.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn set<T: CellItem>(a: &mut Cell<T>, op: &str, b: &mut Cell<T>) -> bool {}
}

cspice_proc! {
    /**
    Parse a list on any of a set of delimiters, into a set of unique items.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn lparss(list: &str, delims: &str, set: &mut Cell<String>) {}
}

cspice_proc! {
    /**
    Find the frame ID codes of all reference frames of a given class in the kernel pool.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn kplfrm(frmcls: i32, idset: &mut Cell<i32>) {}
}

/**
Load the variables of a text kernel held in memory, rather than in a file.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn lmpool<S: AsRef<str>>(cvals: &[S]) {
    let (buffer, lenvals) = to_strided(cvals);
    unsafe {
        crate::c::lmpool_c(
            buffer.as_ptr().cast(),
            lenvals as SpiceInt,
            cvals.len() as SpiceInt,
        )
    }
}

cspice_proc! {
    /**
    The value of a kernel pool parameter, such as `"MAXVAR"`, `"MAXLEN"` or `"MAXVAL"`.

    This is about the pool's own limits, not about any variable in it; [`dtpool`] reports how many
    values a variable holds.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn szpool(name: &str) -> (i32, bool) {}
}

/**
Fetch the `nth` string of a kernel pool variable, re-joining any continuation lines.

Returns the string, its length, and whether it was found.

This function has a [neat version][crate::neat::stpool].
*/
pub fn stpool(item: &str, nth: i32, contin: &str, lenout: usize) -> (String, i32, bool) {
    let item = to_cstring(item);
    let contin = to_cstring(contin);
    let mut string = vec![0 as SpiceChar; lenout.max(1)];
    let (mut size, mut found) = (0, 0);
    unsafe {
        crate::c::stpool_c(
            item.as_ptr() as *mut SpiceChar,
            nth,
            contin.as_ptr() as *mut SpiceChar,
            lenout as SpiceInt,
            string.as_mut_ptr(),
            &mut size,
            &mut found,
        )
    };
    (from_cbuf(&string), size, found != 0)
}

/* -------------------------------------------------------------------------------------------- */
/* Files, frames and time, the remainder                                                          */
/* -------------------------------------------------------------------------------------------- */

cspice_proc! {
    /**
    Whether a file exists.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn exists(name: &str) -> bool {}
}

/**
Determine the architecture and type of a SPICE kernel file.

This function has a [neat version][crate::neat::getfat].
*/
pub fn getfat(file: &str, arclen: usize, typlen: usize) -> (String, String) {
    let file = to_cstring(file);
    let mut arch = vec![0 as SpiceChar; arclen.max(1)];
    let mut kind = vec![0 as SpiceChar; typlen.max(1)];
    unsafe {
        crate::c::getfat_c(
            file.as_ptr() as *mut SpiceChar,
            arclen as SpiceInt,
            typlen as SpiceInt,
            arch.as_mut_ptr(),
            kind.as_mut_ptr(),
        )
    };
    (from_cbuf(&arch), from_cbuf(&kind))
}

/**
Read the next line of a text file, opening it if it is not already open.

Returns the line and whether the end of the file has been reached.

The file stays open until it has been read to the end, and CSPICE refuses to load a file it already
has open, so an abandoned partial read makes that file unloadable. The C API has no counterpart to
Fortran's `CLTEXT` to close one early.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn rdtext(file: &str, lenout: usize) -> (String, bool) {
    let file = to_cstring(file);
    let mut line = vec![0 as SpiceChar; lenout.max(1)];
    let mut eof = 0;
    unsafe {
        crate::c::rdtext_c(
            file.as_ptr() as *mut SpiceChar,
            lenout as SpiceInt,
            line.as_mut_ptr(),
            &mut eof,
        )
    };
    (from_cbuf(&line), eof != 0)
}

cspice_proc! {
    /**
    The centre, class and class ID of a reference frame.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn frinfo(frcode: i32) -> (i32, i32, i32, bool) {}
}

/**
Build a right handed orthonormal frame from a vector, which is normalised in place.

Returns the normalised input and the two vectors completing the frame.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn frame(x: [f64; 3]) -> ([f64; 3], [f64; 3], [f64; 3]) {
    let mut x = x;
    let (mut y, mut z) = ([0.0; 3], [0.0; 3]);
    unsafe { crate::c::frame_c(x.as_mut_ptr(), y.as_mut_ptr(), z.as_mut_ptr()) };
    (x, y, z)
}

/*
These two take their epoch through a `SpiceDouble *` rather than by value, so they cannot go
through the macro.
*/

/**
Whether a ray is in the field of view of an instrument at a given epoch.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn fovray(
    inst: &str,
    raydir: [f64; 3],
    rframe: &str,
    abcorr: &str,
    obsrvr: &str,
    et: f64,
) -> bool {
    let inst = to_cstring(inst);
    let rframe = to_cstring(rframe);
    let abcorr = to_cstring(abcorr);
    let obsrvr = to_cstring(obsrvr);
    let mut raydir = raydir;
    let mut et = et;
    let mut visible = 0;
    unsafe {
        crate::c::fovray_c(
            inst.as_ptr() as *mut SpiceChar,
            raydir.as_mut_ptr(),
            rframe.as_ptr() as *mut SpiceChar,
            abcorr.as_ptr() as *mut SpiceChar,
            obsrvr.as_ptr() as *mut SpiceChar,
            &mut et,
            &mut visible,
        )
    };
    visible != 0
}

/**
Whether a target is in the field of view of an instrument at a given epoch.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn fovtrg(
    inst: &str,
    target: &str,
    tshape: &str,
    tframe: &str,
    abcorr: &str,
    obsrvr: &str,
    et: f64,
) -> bool {
    let inst = to_cstring(inst);
    let target = to_cstring(target);
    let tshape = to_cstring(tshape);
    let tframe = to_cstring(tframe);
    let abcorr = to_cstring(abcorr);
    let obsrvr = to_cstring(obsrvr);
    let mut et = et;
    let mut visible = 0;
    unsafe {
        crate::c::fovtrg_c(
            inst.as_ptr() as *mut SpiceChar,
            target.as_ptr() as *mut SpiceChar,
            tshape.as_ptr() as *mut SpiceChar,
            tframe.as_ptr() as *mut SpiceChar,
            abcorr.as_ptr() as *mut SpiceChar,
            obsrvr.as_ptr() as *mut SpiceChar,
            &mut et,
            &mut visible,
        )
    };
    visible != 0
}

cspice_proc! {
    /**
    Find the illumination angles at a surface point, with the illumination source named separately.
    */
    #[allow(clippy::too_many_arguments)]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn illumg(
        method: &str,
        target: &str,
        ilusrc: &str,
        et: f64,
        fixref: &str,
        abcorr: &str,
        obsrvr: &str,
        spoint: [f64; 3]
    ) -> (f64, [f64; 3], f64, f64, f64) {
    }
}

/**
Return the field of view of an instrument, given its name, with the boundary vectors in the
instrument frame.

This function has a [neat version][crate::neat::getfvn].
*/
pub fn getfvn(
    inst: &str,
    room: usize,
    shalen: usize,
    fralen: usize,
) -> (String, String, [f64; 3], Vec<[f64; 3]>) {
    let inst = to_cstring(inst);
    let mut shape = vec![0 as SpiceChar; shalen.max(1)];
    let mut frame = vec![0 as SpiceChar; fralen.max(1)];
    let mut bsight = [0.0; 3];
    let mut n = 0;
    let mut bounds = vec![[0.0; 3]; room.max(1)];
    unsafe {
        crate::c::getfvn_c(
            inst.as_ptr() as *mut SpiceChar,
            room as SpiceInt,
            shalen as SpiceInt,
            fralen as SpiceInt,
            shape.as_mut_ptr(),
            frame.as_mut_ptr(),
            bsight.as_mut_ptr(),
            &mut n,
            bounds.as_mut_ptr(),
        )
    };
    bounds.truncate(n.max(0) as usize);
    (from_cbuf(&shape), from_cbuf(&frame), bsight, bounds)
}

/**
The local solar time at a longitude on a body.

Returns the hour, minute and second, then the time string and the AM/PM form.
*/
#[allow(clippy::type_complexity)]
pub fn et2lst(
    et: f64,
    body: i32,
    lon: f64,
    kind: &str,
    timlen: usize,
    ampmlen: usize,
) -> (i32, i32, i32, String, String) {
    let kind = to_cstring(kind);
    let mut time = vec![0 as SpiceChar; timlen.max(1)];
    let mut ampm = vec![0 as SpiceChar; ampmlen.max(1)];
    let (mut hr, mut mn, mut sc) = (0, 0, 0);
    unsafe {
        crate::c::et2lst_c(
            et,
            body,
            lon,
            kind.as_ptr() as *mut SpiceChar,
            timlen as SpiceInt,
            ampmlen as SpiceInt,
            &mut hr,
            &mut mn,
            &mut sc,
            time.as_mut_ptr(),
            ampm.as_mut_ptr(),
        )
    };
    (hr, mn, sc, from_cbuf(&time), from_cbuf(&ampm))
}

/**
Build a time format picture from a sample time string.

Returns the picture, whether the sample was understood, and the error if it was not.
*/
pub fn tpictr(sample: &str, lenpictur: usize, lenerror: usize) -> (String, bool, String) {
    let sample = to_cstring(sample);
    let mut pictur = vec![0 as SpiceChar; lenpictur.max(1)];
    let mut errmsg = vec![0 as SpiceChar; lenerror.max(1)];
    let mut ok = 0;
    unsafe {
        crate::c::tpictr_c(
            sample.as_ptr() as *mut SpiceChar,
            lenpictur as SpiceInt,
            lenerror as SpiceInt,
            pictur.as_mut_ptr(),
            &mut ok,
            errmsg.as_mut_ptr(),
        )
    };
    (from_cbuf(&pictur), ok != 0, from_cbuf(&errmsg))
}

/**
Set or retrieve a default used by the time routines.

`action` is `"SET"` or `"GET"`; the current value is returned either way.
*/
pub fn timdef(action: &str, item: &str, value: &str, lenout: usize) -> String {
    let action = to_cstring(action);
    let item = to_cstring(item);
    let mut buffer = vec![0 as SpiceChar; lenout.max(value.len() + 1)];
    for (target, byte) in buffer.iter_mut().zip(value.as_bytes()) {
        *target = *byte as SpiceChar;
    }
    unsafe {
        crate::c::timdef_c(
            action.as_ptr() as *mut SpiceChar,
            item.as_ptr() as *mut SpiceChar,
            buffer.len() as SpiceInt,
            buffer.as_mut_ptr(),
        )
    };
    from_cbuf(&buffer)
}

cspice_proc! {
    /**
    The name of the routine at a given depth in the traceback.
    */
    pub fn trcnam(index: i32, #[lenout] namelen: i32) -> String {}
}

cspice_proc! {
    /**
    Disable the traceback, which cannot be turned back on.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn trcoff() {}
}

cspice_proc! {
    /**
    Replace a marker in a string with the cardinal text of an integer.
    */
    pub fn repmct(
        input: &str,
        marker: &str,
        value: i32,
        strcase: char,
        #[lenout] lenout: i32
    ) -> String {
    }
}

/**
Extract the substring of a word that follows a keyword, from a list of terminating keywords.

Returns the remaining string, whether the keyword was found, and the substring.
*/
#[allow(clippy::type_complexity)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn kxtrct<S: AsRef<str>>(
    keywd: &str,
    terms: &[S],
    string: &str,
    stringlen: usize,
    substrlen: usize,
) -> (String, bool, String) {
    let keywd = to_cstring(keywd);
    let (packed, termlen) = to_strided(terms);
    let mut buffer = vec![0 as SpiceChar; stringlen.max(string.len() + 1)];
    for (target, byte) in buffer.iter_mut().zip(string.as_bytes()) {
        *target = *byte as SpiceChar;
    }
    let mut substr = vec![0 as SpiceChar; substrlen.max(1)];
    let mut found = 0;
    unsafe {
        crate::c::kxtrct_c(
            keywd.as_ptr() as *mut SpiceChar,
            termlen as SpiceInt,
            packed.as_ptr().cast(),
            terms.len() as SpiceInt,
            buffer.len() as SpiceInt,
            substrlen as SpiceInt,
            buffer.as_mut_ptr(),
            &mut found,
            substr.as_mut_ptr(),
        )
    };
    (from_cbuf(&buffer), found != 0, from_cbuf(&substr))
}

/* -------------------------------------------------------------------------------------------- */
/* Geometry finder                                                                                */
/* -------------------------------------------------------------------------------------------- */

/*
Every search takes a confinement window to search within and a window to report the answer in. The
confinement window is an input that CSPICE also reads back, so it is taken by `&mut`; the result is
cleared and filled. Each has a neat version that allocates the result for you.
*/

/// Generate the searches that compare a scalar quantity against a reference value.
macro_rules! gf_search {
    ($($name:ident($($arg:ident: $ty:ty),*) => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// `relate` is one of `"="`, `"<"`, `">"`, `"LOCMIN"`, `"ABSMIN"`, `"LOCMAX"` or
        /// `"ABSMAX"`; `nintvls` is the room to make in `result`, in intervals.
        #[allow(clippy::too_many_arguments)]
        pub fn $name(
            $($arg: $ty,)*
            relate: &str,
            refval: f64,
            adjust: f64,
            step: f64,
            nintvls: i32,
            cnfine: &mut Cell<f64>,
            result: &mut Cell<f64>,
        ) {
            $(let $arg = crate::core::ffi::In::new($arg);)*
            let relate = to_cstring(relate);
            #[allow(unused_mut)]
            let ($(mut $arg,)*) = ($($arg,)*);
            let cnfine = cnfine.as_mut_ptr();
            let result = result.as_mut_ptr();
            unsafe {
                crate::c::$cname(
                    $($arg.raw() as _,)*
                    relate.as_ptr() as *mut SpiceChar,
                    refval,
                    adjust,
                    step,
                    nintvls,
                    cnfine,
                    result,
                );
            }
        }
    )*};
}

gf_search! {
    gfdist(target: &str, abcorr: &str, obsrvr: &str) => gfdist_c,
        "Search for times when the distance to a target meets a condition.";
    gfrr(target: &str, abcorr: &str, obsrvr: &str) => gfrr_c,
        "Search for times when the range rate of a target meets a condition.";
    gfpa(target: &str, illmn: &str, abcorr: &str, obsrvr: &str) => gfpa_c,
        "Search for times when the phase angle of a target meets a condition.";
    gfposc(
        target: &str, frame: &str, abcorr: &str, obsrvr: &str, crdsys: &str, coord: &str
    ) => gfposc_c,
        "Search for times when a coordinate of a target's position meets a condition.";
    gfsubc(
        target: &str, fixref: &str, method: &str, abcorr: &str, obsrvr: &str, crdsys: &str,
        coord: &str
    ) => gfsubc_c,
        "Search for times when a coordinate of the sub-observer point meets a condition.";
    gfsntc(
        target: &str, fixref: &str, method: &str, abcorr: &str, obsrvr: &str, dref: &str,
        dvec: [f64; 3], crdsys: &str, coord: &str
    ) => gfsntc_c,
        "Search for times when a coordinate of a ray-surface intercept meets a condition.";
    gfsep(
        targ1: &str, shape1: &str, frame1: &str, targ2: &str, shape2: &str, frame2: &str,
        abcorr: &str, obsrvr: &str
    ) => gfsep_c,
        "Search for times when the angular separation of two targets meets a condition.";
    gfilum(
        method: &str, angtyp: &str, target: &str, illmn: &str, fixref: &str, abcorr: &str,
        obsrvr: &str, spoint: [f64; 3]
    ) => gfilum_c,
        "Search for times when an illumination angle at a surface point meets a condition.";
}

cspice_proc! {
    /**
    Search for times when a ray is in the field of view of an instrument.
    */
    #[allow(clippy::too_many_arguments)]
    pub fn gfrfov(
        inst: &str,
        raydir: [f64; 3],
        rframe: &str,
        abcorr: &str,
        obsrvr: &str,
        step: f64,
        cnfine: &mut Cell<f64>,
        result: &mut Cell<f64>
    ) {
    }
}

cspice_proc! {
    /**
    Search for times when a target is in the field of view of an instrument.
    */
    #[allow(clippy::too_many_arguments)]
    pub fn gftfov(
        inst: &str,
        target: &str,
        tshape: &str,
        tframe: &str,
        abcorr: &str,
        obsrvr: &str,
        step: f64,
        cnfine: &mut Cell<f64>,
        result: &mut Cell<f64>
    ) {
    }
}

cspice_proc! {
    /**
    Set the step size the geometry finder takes between samples.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn gfsstp(step: f64) {}
}

cspice_proc! {
    /**
    The step to take from an epoch, as set by [`gfsstp`].
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn gfstep(time: f64) -> f64 {}
}

cspice_proc! {
    /**
    Set the convergence tolerance the geometry finder uses, in seconds.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn gfstol(value: f64) {}
}

cspice_proc! {
    /**
    Refine a bracketing interval by bisection.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn gfrefn(t1: f64, t2: f64, s1: bool, s2: bool) -> f64 {}
}

cspice_proc! {
    /**
    Whether an interrupt has been requested; see [`gfinth`].
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn gfbail() -> bool {}
}

cspice_proc! {
    /**
    Clear the interrupt handler installed by [`gfinth`].
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn gfclrh() {}
}

cspice_proc! {
    /**
    Install an interrupt handler for the signal `sigcode`, so a search can be stopped.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn gfinth(sigcode: i32) {}
}

cspice_proc! {
    /**
    Begin the default progress report over a confinement window.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn gfrepi(window: &mut Cell<f64>, begmss: &str, endmss: &str) {}
}

cspice_proc! {
    /**
    Update the default progress report.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn gfrepu(ivbeg: f64, ivend: f64, time: f64) {}
}

cspice_proc! {
    /**
    Finish the default progress report.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn gfrepf() {}
}

cspice_proc! {
    /**
    A placeholder scalar function, for the searches that want one but do not use it.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn udf(x: f64) -> f64 {}
}

/**
Whether a scalar function is decreasing at `x`, by a central difference over `dx`.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn uddc(udfunc: UdFunc, x: f64, dx: f64) -> bool {
    let mut isdecr = 0;
    unsafe { crate::c::uddc_c(Some(udfunc), x, dx, &mut isdecr) };
    isdecr != 0
}

/**
The derivative of a scalar function at `x`, by a central difference over `dx`.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn uddf(udfunc: UdFunc, x: f64, dx: f64) -> f64 {
    let mut deriv = 0.0;
    unsafe { crate::c::uddf_c(Some(udfunc), x, dx, &mut deriv) };
    deriv
}

/**
Search for times when a scalar function the caller supplies meets a condition.

`udfuns` computes the quantity and `udfunb` says whether it is decreasing; [`uddc`] can be used to
build the second from the first.
*/
#[allow(clippy::too_many_arguments)]
pub fn gfuds(
    udfuns: UdFuns,
    udfunb: UdFunb,
    relate: &str,
    refval: f64,
    adjust: f64,
    step: f64,
    nintvls: i32,
    cnfine: &mut Cell<f64>,
    result: &mut Cell<f64>,
) {
    let relate = to_cstring(relate);
    let cnfine = cnfine.as_mut_ptr();
    let result = result.as_mut_ptr();
    unsafe {
        crate::c::gfuds_c(
            Some(udfuns),
            Some(udfunb),
            relate.as_ptr() as *mut SpiceChar,
            refval,
            adjust,
            step,
            nintvls,
            cnfine,
            result,
        );
    }
}

/**
Search for times when a boolean function the caller supplies is true.
*/
pub fn gfudb(
    udfuns: UdFuns,
    udfunb: UdFunb,
    step: f64,
    cnfine: &mut Cell<f64>,
    result: &mut Cell<f64>,
) {
    let cnfine = cnfine.as_mut_ptr();
    let result = result.as_mut_ptr();
    unsafe { crate::c::gfudb_c(Some(udfuns), Some(udfunb), step, cnfine, result) };
}

/**
Search for times when an occultation occurs, with the search progress and stepping under the
caller's control.

[`crate::neat::gfoclt`] is the form to reach for unless the stepping needs to be customised.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn gfocce(
    occtyp: &str,
    front: &str,
    fshape: &str,
    fframe: &str,
    back: &str,
    bshape: &str,
    bframe: &str,
    abcorr: &str,
    obsrvr: &str,
    tol: f64,
    udstep: UdStep,
    udrefn: UdRefn,
    rpt: bool,
    udrepi: UdRepi,
    udrepu: UdRepu,
    udrepf: UdRepf,
    bail: bool,
    udbail: UdBail,
    cnfine: &mut Cell<f64>,
    result: &mut Cell<f64>,
) {
    let occtyp = to_cstring(occtyp);
    let front = to_cstring(front);
    let fshape = to_cstring(fshape);
    let fframe = to_cstring(fframe);
    let back = to_cstring(back);
    let bshape = to_cstring(bshape);
    let bframe = to_cstring(bframe);
    let abcorr = to_cstring(abcorr);
    let obsrvr = to_cstring(obsrvr);
    let cnfine = cnfine.as_mut_ptr();
    let result = result.as_mut_ptr();
    unsafe {
        crate::c::gfocce_c(
            occtyp.as_ptr() as *mut SpiceChar,
            front.as_ptr() as *mut SpiceChar,
            fshape.as_ptr() as *mut SpiceChar,
            fframe.as_ptr() as *mut SpiceChar,
            back.as_ptr() as *mut SpiceChar,
            bshape.as_ptr() as *mut SpiceChar,
            bframe.as_ptr() as *mut SpiceChar,
            abcorr.as_ptr() as *mut SpiceChar,
            obsrvr.as_ptr() as *mut SpiceChar,
            tol,
            Some(udstep),
            Some(udrefn),
            rpt as crate::c::SpiceBoolean,
            Some(udrepi),
            Some(udrepu),
            Some(udrepf),
            bail as crate::c::SpiceBoolean,
            Some(udbail),
            cnfine,
            result,
        );
    }
}

/**
Search for times when a target or ray is in the field of view of an instrument, with the search
progress and stepping under the caller's control.

[`gftfov`] and [`gfrfov`] are the forms to reach for unless the stepping needs to be customised.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn gffove(
    inst: &str,
    tshape: &str,
    raydir: [f64; 3],
    target: &str,
    tframe: &str,
    abcorr: &str,
    obsrvr: &str,
    tol: f64,
    udstep: UdStep,
    udrefn: UdRefn,
    rpt: bool,
    udrepi: UdRepi,
    udrepu: UdRepu,
    udrepf: UdRepf,
    bail: bool,
    udbail: UdBail,
    cnfine: &mut Cell<f64>,
    result: &mut Cell<f64>,
) {
    let inst = to_cstring(inst);
    let tshape = to_cstring(tshape);
    let target = to_cstring(target);
    let tframe = to_cstring(tframe);
    let abcorr = to_cstring(abcorr);
    let obsrvr = to_cstring(obsrvr);
    let mut raydir = raydir;
    let cnfine = cnfine.as_mut_ptr();
    let result = result.as_mut_ptr();
    unsafe {
        crate::c::gffove_c(
            inst.as_ptr() as *mut SpiceChar,
            tshape.as_ptr() as *mut SpiceChar,
            raydir.as_mut_ptr(),
            target.as_ptr() as *mut SpiceChar,
            tframe.as_ptr() as *mut SpiceChar,
            abcorr.as_ptr() as *mut SpiceChar,
            obsrvr.as_ptr() as *mut SpiceChar,
            tol,
            Some(udstep),
            Some(udrefn),
            rpt as crate::c::SpiceBoolean,
            Some(udrepi),
            Some(udrepu),
            Some(udrepf),
            bail as crate::c::SpiceBoolean,
            Some(udbail),
            cnfine,
            result,
        );
    }
}

/**
Search for times when a geometric quantity named by a string meets a condition.

The quantity and its parameters are given by name, which is what makes this the most general of the
searches and the most awkward to call; the specific searches above are easier where they apply.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn gfevnt<S: AsRef<str>, T: AsRef<str>>(
    udstep: UdStep,
    udrefn: UdRefn,
    gquant: &str,
    qpnams: &[S],
    qcpars: &[T],
    qdpars: &[f64],
    qipars: &[i32],
    qlpars: &[bool],
    op: &str,
    refval: f64,
    tol: f64,
    adjust: f64,
    rpt: bool,
    udrepi: UdRepi,
    udrepu: UdRepu,
    udrepf: UdRepf,
    nintvls: i32,
    bail: bool,
    udbail: UdBail,
    cnfine: &mut Cell<f64>,
    result: &mut Cell<f64>,
) {
    let gquant = to_cstring(gquant);
    let op = to_cstring(op);
    let (names, namelen) = to_strided(qpnams);
    let (values, valuelen) = to_strided(qcpars);
    let lenvals = namelen.max(valuelen);
    // Both string arrays are read with the same stride, so they have to be packed with it.
    let (names, _) = if namelen == lenvals {
        (names, namelen)
    } else {
        repack(qpnams, lenvals)
    };
    let (values, _) = if valuelen == lenvals {
        (values, valuelen)
    } else {
        repack(qcpars, lenvals)
    };
    // CSPICE reads one element of each of the three numeric arrays per parameter name, whether or
    // not the quantity uses it, so they are padded rather than passed at the length given.
    let count = qpnams.len().max(1);
    let mut reals = qdpars.to_vec();
    let mut ints = qipars.to_vec();
    let mut flags = qlpars
        .iter()
        .map(|&flag| flag as crate::c::SpiceBoolean)
        .collect::<Vec<_>>();
    reals.resize(count, 0.0);
    ints.resize(count, 0);
    flags.resize(count, 0);
    let cnfine = cnfine.as_mut_ptr();
    let result = result.as_mut_ptr();

    unsafe {
        crate::c::gfevnt_c(
            Some(udstep),
            Some(udrefn),
            gquant.as_ptr() as *mut SpiceChar,
            qpnams.len() as SpiceInt,
            lenvals as SpiceInt,
            names.as_ptr().cast(),
            values.as_ptr().cast(),
            reals.as_ptr() as *mut SpiceDouble,
            ints.as_ptr() as *mut SpiceInt,
            flags.as_ptr() as *mut crate::c::SpiceBoolean,
            op.as_ptr() as *mut SpiceChar,
            refval,
            tol,
            adjust,
            rpt as crate::c::SpiceBoolean,
            Some(udrepi),
            Some(udrepu),
            Some(udrepf),
            nintvls,
            bail as crate::c::SpiceBoolean,
            Some(udbail),
            cnfine,
            result,
        );
    }
}

/// Pack strings at a stride the caller chooses, rather than at the natural one.
fn repack<S: AsRef<str>>(values: &[S], stride: usize) -> (Vec<SpiceChar>, usize) {
    let mut buffer = vec![0 as SpiceChar; values.len().max(1) * stride];
    for (index, value) in values.iter().enumerate() {
        let slot = &mut buffer[index * stride..(index + 1) * stride];
        for (target, byte) in slot.iter_mut().zip(value.as_ref().as_bytes()) {
            *target = *byte as SpiceChar;
        }
    }
    (buffer, stride)
}

cspice_proc! {
    /**
    The largest integer CSPICE represents.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn intmax() -> i32 {}
}

cspice_proc! {
    /**
    The smallest integer CSPICE represents.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn intmin() -> i32 {}
}

/* -------------------------------------------------------------------------------------------- */
/* Constants                                                                                      */
/* -------------------------------------------------------------------------------------------- */

/// Generate the wrappers of the CSPICE routines that just return a constant.
macro_rules! constants {
    ($($name:ident => $doc:expr),* $(,)?) => {$(
        cspice_proc! {
            #[doc = $doc]
            #[return_output]
            #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
            pub fn $name() -> f64 {}
        }
    )*};
}

constants! {
    b1900 => "Julian Date of the epoch B1900.",
    b1950 => "Julian Date of the epoch B1950.",
    clight => "Speed of light in a vacuum, in km/s.",
    dpr => "Number of degrees per radian.",
    halfpi => "Half the value of pi.",
    j1900 => "Julian Date of 1899 DEC 31 12:00:00 (1900 JAN 0.5).",
    j1950 => "Julian Date of 1950 JAN 01 00:00:00 (1950 JAN 1.0).",
    j2000 => "Julian Date of 2000 JAN 01 12:00:00 (2000 JAN 1.5).",
    j2100 => "Julian Date of 2100 JAN 01 12:00:00 (2100 JAN 1.5).",
    jyear => "Number of seconds in a Julian year.",
    pi => "Value of pi.",
    rpd => "Number of radians per degree.",
    spd => "Number of seconds in a day.",
    twopi => "Twice the value of pi.",
    tyear => "Number of seconds in a tropical year.",
}

cspice_proc! {
    /**
    Return the version of the CSPICE toolkit; pass `"TOOLKIT"` as the item.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn tkvrsn(item: &str) -> String {}
}

/* -------------------------------------------------------------------------------------------- */
/* Events kernels                                                                                 */
/* -------------------------------------------------------------------------------------------- */

/// Attributes of one column of a table of an events kernel.
#[allow(clippy::upper_case_acronyms)]
pub type EKATTDSC = crate::c::SpiceEKAttDsc;

/// Summary of one segment of an events kernel: its table, its shape and its columns.
#[allow(clippy::upper_case_acronyms)]
pub type EKSEGSUM = crate::c::SpiceEKSegSum;

/// Greatest number of columns a segment of an events kernel may have.
pub const EK_MXCLSG: usize = 100;

/// Greatest number of items the `SELECT` clause of a query may name.
pub const EK_MAXQSEL: usize = 50;

/// Length of the name of a column, with room for the terminator.
pub const EK_CSTRLN: usize = 33;

/// Length of the name of a table, with room for the terminator.
pub const EK_TSTRLN: usize = 65;

/// The size a column declares when the number of values in its entries varies from row to row.
pub const EK_VARSIZ: i32 = -1;

/// The data type of a column of character strings.
pub const EK_CHR: crate::c::SpiceEKDataType = crate::c::_SpiceDataType_SPICE_CHR;

/// The data type of a column of double precision numbers.
pub const EK_DP: crate::c::SpiceEKDataType = crate::c::_SpiceDataType_SPICE_DP;

/// The data type of a column of integers.
pub const EK_INT: crate::c::SpiceEKDataType = crate::c::_SpiceDataType_SPICE_INT;

/// The data type of a column of epochs, which are read as double precision numbers.
pub const EK_TIME: crate::c::SpiceEKDataType = crate::c::_SpiceDataType_SPICE_TIME;

/// A selected item that is a column.
pub const EK_EXP_COL: crate::c::SpiceEKExprClass = crate::c::_SpiceEKExprClass_SPICE_EK_EXP_COL;

/// A selected item that is a function applied to a column.
pub const EK_EXP_FUNC: crate::c::SpiceEKExprClass = crate::c::_SpiceEKExprClass_SPICE_EK_EXP_FUNC;

/// A selected item that is neither a column nor a function of one.
pub const EK_EXP_EXPR: crate::c::SpiceEKExprClass = crate::c::_SpiceEKExprClass_SPICE_EK_EXP_EXPR;

cspice_proc! {
    /**
    Open a new events kernel and prepare it for writing, returning the handle of the open file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekopn(fname: &str, ifname: &str, ncomch: i32) -> i32 {}
}

cspice_proc! {
    /**
    Open an existing events kernel for reading, returning the handle of the open file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekopr(fname: &str) -> i32 {}
}

cspice_proc! {
    /**
    Open an existing events kernel for writing, returning the handle of the open file.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekopw(fname: &str) -> i32 {}
}

cspice_proc! {
    /**
    Open a scratch events kernel and prepare it for writing, returning the handle of the open file.

    The file is deleted when it is closed.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekops() -> i32 {}
}

cspice_proc! {
    /**
    Close an open events kernel.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekcls(handle: i32) {}
}

cspice_proc! {
    /**
    Load an events kernel, making it readable by the query routines, and return its handle.

    [`furnsh`] loads one too; this is the form that hands back the handle.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn eklef(fname: &str) -> i32 {}
}

cspice_proc! {
    /**
    Unload an events kernel, making its contents unreadable and its room available again.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekuef(handle: i32) {}
}

cspice_proc! {
    /**
    Return the number of tables the loaded events kernels hold between them.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekntab() -> i32 {}
}

cspice_proc! {
    /**
    Return the name of the `n`th loaded table, counting from zero.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ektnam(n: i32, #[lenout] lenout: i32) -> String {}
}

cspice_proc! {
    /**
    Return the number of distinct columns of a loaded table.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekccnt(table: &str) -> i32 {}
}

cspice_proc! {
    /**
    Return the name and the attributes of the `cindex`th column of a loaded table, counting from
    zero.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekcii(table: &str, cindex: i32, #[lenout] lenout: i32) -> (String, EKATTDSC) {}
}

cspice_proc! {
    /**
    Return the number of segments of an open events kernel.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn eknseg(handle: i32) -> i32 {}
}

cspice_proc! {
    /**
    Return the summary of a segment of an open events kernel, counting segments from zero.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekssum(handle: i32, segno: i32) -> EKSEGSUM {}
}

cspice_proc! {
    /**
    Run a query, returning the number of rows it matched, whether it could not be parsed, and the
    message saying why it could not.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekfind(query: &str, #[lenout] lenout: i32) -> (i32, bool, String) {}
}

cspice_proc! {
    /**
    Return the number of values in the entry of the `selidx`th selected item in a row of the result
    of the last [`ekfind`], counting both from zero.
    */
    #[return_output]
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn eknelt(selidx: i32, row: i32) -> i32 {}
}

cspice_proc! {
    /**
    Return one value of a character entry from the result of the last [`ekfind`], and whether it is
    null and whether it was found.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekgc(
        selidx: i32,
        row: i32,
        elment: i32,
        #[lenout] lenout: i32
    ) -> (String, bool, bool) {
    }
}

cspice_proc! {
    /**
    Return one value of a double precision entry from the result of the last [`ekfind`], and
    whether it is null and whether it was found.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekgd(selidx: i32, row: i32, elment: i32) -> (f64, bool, bool) {}
}

cspice_proc! {
    /**
    Return one value of an integer entry from the result of the last [`ekfind`], and whether it is
    null and whether it was found.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekgi(selidx: i32, row: i32, elment: i32) -> (i32, bool, bool) {}
}

cspice_proc! {
    /**
    Append an empty record to a segment of an open events kernel, returning its number.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekappr(handle: i32, segno: i32) -> i32 {}
}

cspice_proc! {
    /**
    Insert an empty record into a segment of an open events kernel, at the given index.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekinsr(handle: i32, segno: i32, recno: i32) {}
}

cspice_proc! {
    /**
    Delete a record from a segment of an open events kernel.
    */
    #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
    pub fn ekdelr(handle: i32, segno: i32, recno: i32) {}
}

/**
Start a segment of an open events kernel, returning its number.

`cnames` names the columns and `decls` declares them, so the two have the same length.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn ekbseg<S: AsRef<str>, T: AsRef<str>>(
    handle: i32,
    tabnam: &str,
    cnames: &[S],
    decls: &[T],
) -> i32 {
    let tabnam = to_cstring(tabnam);
    let (names, cnmlen) = to_strided(cnames);
    let (declarations, declen) = to_strided(decls);
    let mut segno = 0;
    unsafe {
        crate::c::ekbseg_c(
            handle,
            tabnam.as_ptr() as *mut SpiceChar,
            cnames.len() as SpiceInt,
            cnmlen as SpiceInt,
            names.as_ptr().cast(),
            declen as SpiceInt,
            declarations.as_ptr().cast(),
            &mut segno,
        );
    }
    segno
}

/**
Start a segment of an open events kernel that is to be written a column at a time.

Returns the number of the segment and the record pointers, which every later call writing the
segment is handed in turn: the column additions [`ekaclc`], [`ekacld`] and [`ekacli`], and finally
[`ekffld`].
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn ekifld<S: AsRef<str>, T: AsRef<str>>(
    handle: i32,
    tabnam: &str,
    nrows: i32,
    cnames: &[S],
    decls: &[T],
) -> (i32, Vec<i32>) {
    let tabnam = to_cstring(tabnam);
    let (names, cnmlen) = to_strided(cnames);
    let (declarations, declen) = to_strided(decls);
    let mut segno = 0;
    let mut rcptrs = vec![0; (nrows.max(0) as usize).max(1)];
    unsafe {
        crate::c::ekifld_c(
            handle,
            tabnam.as_ptr() as *mut SpiceChar,
            cnames.len() as SpiceInt,
            nrows,
            cnmlen as SpiceInt,
            names.as_ptr().cast(),
            declen as SpiceInt,
            declarations.as_ptr().cast(),
            &mut segno,
            rcptrs.as_mut_ptr(),
        );
    }
    rcptrs.truncate(nrows.max(0) as usize);
    (segno, rcptrs)
}

/**
Finish writing a segment started by [`ekifld`], given the record pointers it returned.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn ekffld(handle: i32, segno: i32, rcptrs: &mut [i32]) {
    unsafe { crate::c::ekffld_c(handle, segno, rcptrs.as_mut_ptr()) };
}

/// The three column additions differ only in the type of the values they are handed.
macro_rules! ek_add_column {
    ($name:ident, $cname:ident, $ty:ty, $values:ident, $doc:expr) => {
        #[doc = $doc]
        ///
        /// `entszs` gives the number of values in each row's entry and `nlflgs` says which entries
        /// are null, so both have one element per row. `rcptrs` is what [`ekifld`] returned.
        #[allow(clippy::too_many_arguments)]
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(
            handle: i32,
            segno: i32,
            column: &str,
            $values: &[$ty],
            entszs: &[i32],
            nlflgs: &[bool],
            rcptrs: &[i32],
        ) {
            let column = to_cstring(column);
            let flags = nlflgs
                .iter()
                .map(|&flag| flag as crate::c::SpiceBoolean)
                .collect::<Vec<_>>();
            // The index is only read when the column is indexed, and then it needs one slot a row.
            let mut wkindx = vec![0 as SpiceInt; rcptrs.len().max(1)];
            unsafe {
                crate::c::$cname(
                    handle,
                    segno,
                    column.as_ptr() as *mut SpiceChar,
                    $values.as_ptr() as *mut _,
                    entszs.as_ptr() as *mut SpiceInt,
                    flags.as_ptr() as *mut crate::c::SpiceBoolean,
                    rcptrs.as_ptr() as *mut SpiceInt,
                    wkindx.as_mut_ptr(),
                );
            }
        }
    };
}

ek_add_column!(
    ekacld,
    ekacld_c,
    f64,
    dvals,
    "Write a whole double precision column of a segment started by [`ekifld`]."
);
ek_add_column!(
    ekacli,
    ekacli_c,
    i32,
    ivals,
    "Write a whole integer column of a segment started by [`ekifld`]."
);

/**
Write a whole character column of a segment started by [`ekifld`].

`entszs` gives the number of values in each row's entry and `nlflgs` says which entries are null,
so both have one element per row. `rcptrs` is what [`ekifld`] returned.
*/
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn ekaclc<S: AsRef<str>>(
    handle: i32,
    segno: i32,
    column: &str,
    cvals: &[S],
    entszs: &[i32],
    nlflgs: &[bool],
    rcptrs: &[i32],
) {
    let column = to_cstring(column);
    let (values, vallen) = to_strided(cvals);
    let flags = nlflgs
        .iter()
        .map(|&flag| flag as crate::c::SpiceBoolean)
        .collect::<Vec<_>>();
    let mut wkindx = vec![0 as SpiceInt; rcptrs.len().max(1)];
    unsafe {
        crate::c::ekaclc_c(
            handle,
            segno,
            column.as_ptr() as *mut SpiceChar,
            vallen as SpiceInt,
            values.as_ptr().cast(),
            entszs.as_ptr() as *mut SpiceInt,
            flags.as_ptr() as *mut crate::c::SpiceBoolean,
            rcptrs.as_ptr() as *mut SpiceInt,
            wkindx.as_mut_ptr(),
        );
    }
}

/// Adding an entry to a record and updating one take the same arguments.
macro_rules! ek_record_write {
    ($name:ident, $cname:ident, $ty:ty, $values:ident, $doc:expr) => {
        #[doc = $doc]
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(
            handle: i32,
            segno: i32,
            recno: i32,
            column: &str,
            $values: &[$ty],
            isnull: bool,
        ) {
            let column = to_cstring(column);
            unsafe {
                crate::c::$cname(
                    handle,
                    segno,
                    recno,
                    column.as_ptr() as *mut SpiceChar,
                    $values.len() as SpiceInt,
                    $values.as_ptr() as *mut _,
                    isnull as crate::c::SpiceBoolean,
                );
            }
        }
    };
}

ek_record_write!(
    ekaced,
    ekaced_c,
    f64,
    dvals,
    "Write a double precision entry into a record of a segment of an open events kernel."
);
ek_record_write!(
    ekacei,
    ekacei_c,
    i32,
    ivals,
    "Write an integer entry into a record of a segment of an open events kernel."
);
ek_record_write!(
    ekuced,
    ekuced_c,
    f64,
    dvals,
    "Replace a double precision entry of a record of a segment of an open events kernel."
);
ek_record_write!(
    ekucei,
    ekucei_c,
    i32,
    ivals,
    "Replace an integer entry of a record of a segment of an open events kernel."
);

/// The two character record writers differ only in the routine they call.
macro_rules! ek_record_write_c {
    ($name:ident, $cname:ident, $doc:expr) => {
        #[doc = $doc]
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name<S: AsRef<str>>(
            handle: i32,
            segno: i32,
            recno: i32,
            column: &str,
            cvals: &[S],
            isnull: bool,
        ) {
            let column = to_cstring(column);
            let (values, vallen) = to_strided(cvals);
            unsafe {
                crate::c::$cname(
                    handle,
                    segno,
                    recno,
                    column.as_ptr() as *mut SpiceChar,
                    cvals.len() as SpiceInt,
                    vallen as SpiceInt,
                    values.as_ptr().cast(),
                    isnull as crate::c::SpiceBoolean,
                );
            }
        }
    };
}

ek_record_write_c!(
    ekacec,
    ekacec_c,
    "Write a character entry into a record of a segment of an open events kernel."
);
ek_record_write_c!(
    ekucec,
    ekucec_c,
    "Replace a character entry of a record of a segment of an open events kernel."
);

/// The two numeric record readers differ only in the type of the values they report.
macro_rules! ek_record_read {
    ($name:ident, $cname:ident, $ty:ty, $zero:expr, $doc:expr) => {
        #[doc = $doc]
        ///
        /// `maxvals` is the room to make for the entry, in values; CSPICE writes as many as the
        /// entry holds, which is at most the size the column declares.
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(
            handle: i32,
            segno: i32,
            recno: i32,
            column: &str,
            maxvals: usize,
        ) -> (Vec<$ty>, bool) {
            let column = to_cstring(column);
            let mut values = vec![$zero; maxvals.max(1)];
            let (mut nvals, mut isnull) = (0, 0);
            unsafe {
                crate::c::$cname(
                    handle,
                    segno,
                    recno,
                    column.as_ptr() as *mut SpiceChar,
                    &mut nvals,
                    values.as_mut_ptr(),
                    &mut isnull,
                );
            }
            values.truncate((nvals.max(0) as usize).min(maxvals));
            (values, isnull != 0)
        }
    };
}

ek_record_read!(
    ekrced,
    ekrced_c,
    f64,
    0.0,
    "Read a double precision entry of a record of a segment of an open events kernel."
);
ek_record_read!(
    ekrcei,
    ekrcei_c,
    i32,
    0,
    "Read an integer entry of a record of a segment of an open events kernel."
);

/**
Read a character entry of a record of a segment of an open events kernel.

`maxvals` is the room to make for the entry, in values, and `lenout` the room for each of them.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn ekrcec(
    handle: i32,
    segno: i32,
    recno: i32,
    column: &str,
    maxvals: usize,
    lenout: usize,
) -> (Vec<String>, bool) {
    let column = to_cstring(column);
    let stride = lenout.max(1);
    let mut buffer = vec![0 as SpiceChar; maxvals.max(1) * stride];
    let (mut nvals, mut isnull) = (0, 0);
    unsafe {
        crate::c::ekrcec_c(
            handle,
            segno,
            recno,
            column.as_ptr() as *mut SpiceChar,
            stride as SpiceInt,
            &mut nvals,
            buffer.as_mut_ptr().cast(),
            &mut isnull,
        );
    }
    let count = (nvals.max(0) as usize).min(maxvals);
    (from_strided(&buffer, stride, count), isnull != 0)
}

/**
Parse the `SELECT` clause of a query, reporting in full on each item it selects.

Returns, for each selected item, where its expression begins and ends in `query`, its data type,
its class, the table it is taken from and the column it names; then whether the query could not be
parsed, and the message saying why.
*/
#[allow(clippy::type_complexity)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn ekpsel(
    query: &str,
    msglen: usize,
    tablen: usize,
    collen: usize,
) -> (
    Vec<i32>,
    Vec<i32>,
    Vec<crate::c::SpiceEKDataType>,
    Vec<crate::c::SpiceEKExprClass>,
    Vec<String>,
    Vec<String>,
    bool,
    String,
) {
    let query = to_cstring(query);
    let (tablen, collen) = (tablen.max(1), collen.max(1));
    let mut xbegs = vec![0 as SpiceInt; EK_MAXQSEL];
    let mut xends = vec![0 as SpiceInt; EK_MAXQSEL];
    let mut xtypes = vec![EK_CHR; EK_MAXQSEL];
    let mut xclass = vec![EK_EXP_COL; EK_MAXQSEL];
    let mut tabs = vec![0 as SpiceChar; EK_MAXQSEL * tablen];
    let mut cols = vec![0 as SpiceChar; EK_MAXQSEL * collen];
    let mut errmsg = vec![0 as SpiceChar; msglen.max(1)];
    let (mut n, mut error) = (0, 0);
    unsafe {
        crate::c::ekpsel_c(
            query.as_ptr() as *mut SpiceChar,
            errmsg.len() as SpiceInt,
            tablen as SpiceInt,
            collen as SpiceInt,
            &mut n,
            xbegs.as_mut_ptr(),
            xends.as_mut_ptr(),
            xtypes.as_mut_ptr(),
            xclass.as_mut_ptr(),
            tabs.as_mut_ptr().cast(),
            cols.as_mut_ptr().cast(),
            &mut error,
            errmsg.as_mut_ptr(),
        );
    }
    let count = (n.max(0) as usize).min(EK_MAXQSEL);
    xbegs.truncate(count);
    xends.truncate(count);
    xtypes.truncate(count);
    xclass.truncate(count);
    (
        xbegs,
        xends,
        xtypes,
        xclass,
        from_strided(&tabs, tablen, count),
        from_strided(&cols, collen, count),
        error != 0,
        from_cbuf(&errmsg),
    )
}

/* -------------------------------------------------------------------------------------------- */
/* The rest of the toolkit                                                                        */
/* -------------------------------------------------------------------------------------------- */

/// Building an array of a repeated value, for the cases CSPICE provides a routine for.
macro_rules! fill_array {
    ($($name:ident($ty:ty, $value:expr) => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// `vec![]` does the same thing without leaving Rust; this is here for completeness.
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(value: $ty, ndim: usize) -> Vec<$ty> {
            let mut array = vec![$value; ndim.max(1)];
            unsafe { crate::c::$cname(value, ndim as SpiceInt, array.as_mut_ptr()) };
            array.truncate(ndim);
            array
        }
    )*};
}

fill_array! {
    filld(f64, 0.0) => filld_c, "Fill a double precision array with a value.";
    filli(i32, 0) => filli_c, "Fill an integer array with a value.";
}

/// Building an array of zeros, for the cases CSPICE provides a routine for.
macro_rules! clear_array {
    ($($name:ident($ty:ty, $value:expr) => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// `vec![]` does the same thing without leaving Rust; this is here for completeness.
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(ndim: usize) -> Vec<$ty> {
            let mut array = vec![$value; ndim.max(1)];
            unsafe { crate::c::$cname(ndim as SpiceInt, array.as_mut_ptr()) };
            array.truncate(ndim);
            array
        }
    )*};
}

clear_array! {
    cleard(f64, 1.0) => cleard_c, "Set every element of a double precision array to zero.";
    cleari(i32, 1) => cleari_c, "Set every element of an integer array to zero.";
}

/**
Set every string of an array to blank, returning `ndim` of them, each `arrlen` characters long.

`vec![]` does the same thing without leaving Rust; this is here for completeness.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn clearc(ndim: usize, arrlen: usize) -> Vec<String> {
    let arrlen = arrlen.max(1);
    let mut array = vec![b'x' as SpiceChar; ndim.max(1) * arrlen];
    unsafe {
        crate::c::clearc_c(
            ndim as SpiceInt,
            arrlen as SpiceInt,
            array.as_mut_ptr().cast(),
        )
    };
    from_strided(&array, arrlen, ndim)
}

/// The extremes, which CSPICE takes as variadic arguments.
macro_rules! extremum {
    ($($name:ident($ty:ty) => $cname:ident, $doc:expr);* $(;)?) => {$(
        #[doc = $doc]
        ///
        /// The C routine is variadic, which Rust cannot hand a list whose length is only known
        /// while it runs; folding the two argument form over the slice gives the same answer for
        /// any length. An empty slice gives zero, as the C routine does for a count of none.
        #[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
        pub fn $name(values: &[$ty]) -> $ty {
            values
                .iter()
                .copied()
                .reduce(|left, right| unsafe { crate::c::$cname(2, left, right) })
                .unwrap_or_else(|| unsafe { crate::c::$cname(0) })
        }
    )*};
}

extremum! {
    maxd(f64) => maxd_c, "The largest of a set of double precision numbers.";
    maxi(i32) => maxi_c, "The largest of a set of integers.";
    mind(f64) => mind_c, "The smallest of a set of double precision numbers.";
    mini(i32) => mini_c, "The smallest of a set of integers.";
}

cspice_proc! {
    /**
    Return the `nth` word of a string, counting from zero, and where in the string it starts.

    The location counts from zero too, and is -1 when the string has no such word.
    */
    pub fn nthwd(string: &str, nth: i32, #[lenout] worlen: i32) -> (String, i32) {}
}

/**
Display a prompt and return the line the user types in reply.

Reads from the standard input, so it blocks until there is a line to read.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn prompt(dspmsg: &str, buflen: usize) -> String {
    let dspmsg = to_cstring(dspmsg);
    let mut buffer = vec![0 as SpiceChar; buflen.max(1)];
    unsafe {
        crate::c::prompt_c(
            dspmsg.as_ptr() as *mut SpiceChar,
            buffer.len() as SpiceInt,
            buffer.as_mut_ptr(),
        )
    };
    from_cbuf(&buffer)
}

/**
Store the command line arguments, so that [`getcml`] can hand them back.

CSPICE keeps the pointers rather than the strings, so the copy this makes is leaked on purpose: it
has to outlive every later call. The toolkit refuses a second call, for the same reason.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn putcml<S: AsRef<str>>(argv: &[S]) {
    let pointers = argv
        .iter()
        .map(|value| to_cstring(value).into_raw())
        .collect::<Vec<_>>();
    let pointers = Box::leak(pointers.into_boxed_slice());
    unsafe { crate::c::putcml_c(argv.len() as SpiceInt, pointers.as_mut_ptr()) }
}

/**
Return the command line arguments [`putcml`] was given.
*/
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn getcml() -> Vec<String> {
    let (mut argc, mut argv) = (0, std::ptr::null_mut());
    unsafe { crate::c::getcml_c(&mut argc, &mut argv) };
    if argv.is_null() {
        return Vec::new();
    }
    (0..argc.max(0) as usize)
        .map(|index| unsafe {
            std::ffi::CStr::from_ptr(*argv.add(index))
                .to_string_lossy()
                .into_owned()
        })
        .collect()
}