spice/core/
mod.rs

1/*!
2An idiomatic interface in Rust to CSPICE.
3
4## Description
5
6Below you will find the index of the CSPICE functions that are wrapped with an idiomatic Rust interface.
7
8It takes a long time to correctly wrap all functions of the API. Raise an issue to ask a specific
9function to be implemented and we will do it immediately. Pull requests are warmly welcomed to help
10speed up this process (do not forget to include a proper documentation and a test).
11
12In the meantime, if you are in a rush and need quickly to use a function not implemented with the
13Rust interface, use the unsafe C functions [here][crate::c#functions]. You can find some inspiration in
14the source of this lib to deal with the FFI types and unsafe code.
15
16## Bindings
17
18CSPICE | **rust-spice** | Description
19-------|--------------|------------
20[bodc2n_c][bodc2n_c link] | [`neat::bodc2n`] | Body ID code to name translation
21[bodfnd_c][bodfnd_c link] | [`raw::bodfnd`] | Find values from the kernel pool
22[bodn2c_c][bodn2c_c link] | [`raw::bodn2c`] | Body name to ID code translation
23[bodvrd_c][bodvrd_c link] | [`raw::bodvrd`] | Return d.p. values from the kernel pool
24[ckcov_c][ckcov_c link] | *TODO*
25[ckgp_c][ckgp_c link] | *TODO*
26[ckgpav_c][ckgpav_c link] | *TODO*
27[ckobj_c][ckobj_c link] | *TODO*
28[dascls_c][dascls_c link] | [`raw::dascls`] | DAS, close file
29[dasopr_c][dasopr_c link] | [`raw::dasopr`] | DAS, open for read
30[deltet_c][deltet_c link] | [`raw::udeltet`] | Delta ET, ET - UTC
31[dlabfs_c][dlabfs_c link] | [`raw::dlabfs`] | DLA, begin forward search
32[dskgd_c][dskgd_c link] | [`raw::dskgd`] | DSK, return DSK segment descriptor
33[dskn02_c][dskn02_c link] | [`raw::dskn02`] | DSK, type 2, compute normal vector for plate
34[dskobj_c][dskobj_c link] | [`raw::dskobj`] | DSK, get object IDs
35[dskp02_c][dskp02_c link] | [`neat::dskp02`] | DSK, fetch type 2 plate data
36[dsksrf_c][dsksrf_c link] | *TODO*
37[dskv02_c][dskv02_c link] | [`neat::dskv02`] | DSK, fetch type 2 vertex data
38[dskx02_c][dskx02_c link] | [`raw::dskx02`] | DSK, ray-surface intercept, type 2
39[dskz02_c][dskz02_c link] | [`raw::dskz02`] | DSK, fetch type 2 model size parameters
40[furnsh_c][furnsh_c link] | [`raw::furnsh`] | Furnish a program with SPICE kernels
41[gcpool_c][gcpool_c link] | *TODO*
42[gdpool_c][gdpool_c link] | [`raw::gdpool`] | Get d.p. values from the kernel pool
43[georec_c][georec_c link] | [`raw::georec`] | Geodetic to rectangular coordinates
44[getfov_c][getfov_c link] | [`raw::getfov`] | Get instrument FOV parameters
45[gipool_c][gipool_c link] | *TODO*
46[illumf_c][illumf_c link] | [`raw::illumf`] | Illumination angles, general source, return flags
47[kclear_c][kclear_c link] | [`raw::kclear`] | Keeper clear
48[kdata_c][kdata_c link] | [`neat::kdata`] | Kernel Data
49[ktotal_c][ktotal_c link] | [`raw::ktotal`] | Kernel Totals
50[latrec_c][latrec_c link] | [`raw::latrec`] | Latitudinal to rectangular coordinates
51[latsrf_c][latsrf_c link] | *TODO*
52[mxv_c][mxv_c link] | [`raw::mxv`] |  Matrix times vector, 3x3
53[occult_c][occult_c link] | [`raw::occult`] | Find occultation type at time
54[pckcov_c][pckcov_c link] | *TODO*
55[pxform_c][pxform_c link] | [`raw::pxform`] | Position Transformation Matrix
56[pxfrm2_c][pxfrm2_c link] | [`raw::pxfrm2`] | Position Transform Matrix, Different Epochs
57[sce2c_c][sce2c_c link] | *TODO*
58[sce2s_c][sce2s_c link] | *TODO*
59[scencd_c][scencd_c link] | *TODO*
60[scdecd_c][scdecd_c link] | *TODO*
61[scs2e_c][scs2e_c link] | *TODO*
62[sct2e_c][sct2e_c link] | *TODO*
63[sincpt_c][sincpt_c link] | [`raw::sincpt`] | Surface intercept
64[spkcls_c][spkcov_c link] | [`raw::spkcls`] | SPK, Close file
65[spkcov_c][spkcov_c link] | *TODO*
66[spkcpo_c][spkcpo_c link] | *TODO*
67[spkcpt_c][spkcpt_c link] | *TODO*
68[spkcvo_c][spkcvo_c link] | *TODO*
69[spkcvt_c][spkcvt_c link] | *TODO*
70[spkezr_c][spkezr_c link] | [`raw::spkezr`] | S/P Kernel, easier reader
71[spkobj_c][spkobj_c link] | *TODO*
72[spkopn_c][spkopn_c link] | [`raw::spkopn`] | SPK, open new file.
73[spkpos_c][spkpos_c link] | [`raw::spkpos`] | S/P Kernel, position
74[spkw09_c][spkopn_c link] | [`raw::spkw09`] | Write SPK segment, type 9
75[srfc2s_c][srfc2s_c link] | *TODO*
76[srfcss_c][srfcss_c link] | *TODO*
77[srfnrm_c][srfnrm_c link] | *TODO*
78[srfs2c_c][srfs2c_c link] | *TODO*
79[srfscc_c][srfscc_c link] | *TODO*
80[str2et_c][str2et_c link] | [`raw::str2et`] | String to ET
81[sunpnt_c][sxform_c link] | [`raw::subpnt`] | Sub-observer point
82[surfpt_c][surfpt_c link] | [`raw::surfpt`] | Surface point on an ellipsoid
83[sxform_c][sxform_c link] | *TODO*
84[radrec_c][radrec_c link] | [`raw::radrec`] |  RA and DEC to rectangular coordinates
85[recrad_c][recrad_c link] | [`raw::recrad`] | Rectangular coordinates to RA and DEC
86[recpgr_c][recpgr_c link] | [`raw::recpgr`] | Rectangular to planetographic
87[timout_c][timout_c link] | [`neat::timout`] | Time Output
88[unitim_c][unitim_c link] | [`raw::unitime`] | Uniform time scale transformation
89[unload_c][unload_c link] | [`raw::unload`] | Unload a kernel
90[vcrss_c][vcrss_c link] | [`raw::vcrss`] | Vector cross product, 3 dimensions
91[vdot_c][vdot_c link] | [`raw::vdot`] |  Vector dot product, 3 dimensions
92[vsep_c][vsep_c link] | [`raw::vsep`] | Angular separation of vectors, 3 dimensions
93[xpose_c][xpose_c link] | [`raw::xpose`] | Transpose a matrix, 3x3
94
95[bodc2n_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/bodc2n_c.html
96[bodfnd_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/bodfnd_c.html
97[bodn2c_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/bodn2c_c.html
98[bodvrd_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/bodvrd_c.html
99[ckcov_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ckcov_c.html
100[ckgp_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ckgp_c.html
101[ckgpav_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ckgpav_c.html
102[ckobj_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ckobj_c.html
103[dascls_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/dascls_c.html
104[dasopr_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/dasopr_c.html
105[deltet_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/deltet_c.html
106[dlabfs_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/dasopr_c.html
107[dskgd_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/dskgd_c.html
108[dskn02_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/dskn02_c.html
109[dskobj_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/dskobj_c.html
110[dskp02_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/dskp02_c.html
111[dsksrf_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/dsksrf_c.html
112[dskv02_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/dskv02_c.html
113[dskx02_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/dskx02_c.html
114[dskz02_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/dskz02_c.html
115[furnsh_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/furnsh_c.html
116[gcpool_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/gcpool_c.html
117[gdpool_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/gdpool_c.html
118[getfov_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/getfov_c.html
119[georec_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/georec_c.html
120[gipool_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/gipool_c.html
121[illumf_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/illumf_c.html
122[kclear_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/kclear_c.html
123[kdata_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/kdata_c.html
124[ktotal_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ktotal_c.html
125[latrec_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/latrec_c.html
126[latsrf_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/latsrf_c.html
127[mxv_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/mxv_c.html
128[occult_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/occult_c.html
129[pxform_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/pxform_c.html
130[pckcov_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/pckcov_c.html
131[pckfrm_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/pckfrm_c.html
132[pxfrm2_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/pxfrm2_c.html
133[scdecd_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/scdecd_c.html
134[sce2c_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/sce2c_c.html
135[sce2s_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/sce2s_c.html
136[scencd_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/scencd_c.html
137[scs2e_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/scs2e_c.html
138[sct2e_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/sct2e_c.html
139[sincpt_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/sincpt_c.html
140[spkcls_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkcls_c.html
141[spkcpo_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkcpo_c.html
142[spkcov_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkcov_c.html
143[spkcpt_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkcpt_c.html
144[spkcvo_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkcvo_c.html
145[spkcvt_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkcvt_c.html
146[spkezr_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkezr_c.html
147[spkobj_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkobj_c.html
148[spkopn_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkopn_c.html
149[spkpos_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkpos_c.html
150[spkw09_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkw09_c.html
151[srfc2s_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/srfc2s_c.html
152[srfcss_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/srfcss_c.html
153[srfnrm_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/srfnrm_c.html
154[srfs2c_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/srfs2c_c.html
155[srfscc_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/srfscc_c.html
156[str2et_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/str2et_c.html
157[subpnt_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/subpnt_c.html
158[surfpt_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/surfpt_c.html
159[sxform_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/sxform_c.html
160[radrec_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/radrec_c.html
161[recrad_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/recrad_c.html
162[recpgr_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/recpgr_c.html
163[timout_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/timout_c.html
164[unitim_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/unitim_c.html
165[unload_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/unload_c.html
166[vcrss_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vcrss_c.html
167[vdot_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vdot_c.html
168[vsep_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsep_c.html
169[xpose_c link]: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xpose_c.html
170*/
171
172#[cfg(any(feature = "lock", doc))]
173#[cfg_attr(docsrs, doc(cfg(feature = "lock")))]
174pub mod lock;
175
176pub mod neat;
177pub mod raw;
178
179pub use self::neat::{bodc2n, dskp02, dskv02, kdata, timout};
180pub use self::raw::{
181    bodfnd, bodn2c, bodvrd, dascls, dasopr, deltet, dlabfs, dskgd, dskn02, dskobj, dskx02, dskz02,
182    furnsh, gdpool, georec, getfov, illumf, kclear, ktotal, latrec, mxv, occult, pxform, pxfrm2,
183    radrec, recpgr, recrad, sincpt, spkcls, spkezr, spkopn, spkpos, spkw09, str2et, subpnt, surfpt,
184    unitim, unload, vcrss, vdot, vsep, xpose, DLADSC, DSKDSC,
185};
186
187/**
188Default date format.
189*/
190pub const TIME_FORMAT: &str = "YYYY-MON-DD HR:MN:SC ::RND";
191
192/**
193Size of the default date format.
194*/
195pub const TIME_FORMAT_SIZE: usize = TIME_FORMAT.len();
196
197/**
198Maximum size of string outputs.
199*/
200pub const MAX_LEN_OUT: usize = 256;
201
202/**
203Allocate for a given type and number of elements.
204*/
205#[macro_export]
206macro_rules! malloc {
207    ($a:ty, $n:expr) => {
208        unsafe { libc::malloc(std::mem::size_of::<$a>() * $n as usize) as *mut $a }
209    };
210}
211
212/**
213Allocate [`*mut i8`][`std::os::raw::c_char`] to be sent as a pointer to a string.
214*/
215#[macro_export]
216macro_rules! mallocstr {
217    ($s:expr) => {
218        $crate::malloc!(i8, $s + 1)
219    };
220}
221
222/**
223Convert [`String`] to [`*mut i8`][`std::os::raw::c_char`].
224*/
225#[macro_export]
226macro_rules! cstr {
227    ($s:expr) => {{
228        std::ffi::CString::new($s).unwrap().into_raw()
229    }};
230    () => {{
231        std::ffi::CString::new(String::new()).unwrap().into_raw()
232    }};
233}
234
235/**
236Get [`String`] from [`*mut i8`][`std::os::raw::c_char`].
237*/
238#[macro_export]
239macro_rules! fcstr {
240    ($s:expr) => {{
241        unsafe { std::ffi::CStr::from_ptr($s).to_str().unwrap().to_string() }
242    }};
243}
244
245/**
246Pointer to expression.
247*/
248#[macro_export]
249macro_rules! mptr {
250    ($e:expr) => {
251        $e.as_mut_ptr()
252    };
253}
254
255/**
256Allocate a scalar to be sent as a pointer.
257*/
258#[macro_export]
259macro_rules! init_scalar {
260    () => {
261        std::mem::MaybeUninit::uninit()
262    };
263}
264
265/**
266Retrieve a value from a pointer to a scalar created using [`init_scalar`].
267*/
268#[macro_export]
269macro_rules! get_scalar {
270    ($e:expr) => {
271        $e.assume_init()
272    };
273}
274
275/**
276Get a vector of array from the pointer to the array.
277*/
278#[macro_export]
279macro_rules! get_varr {
280    ($e:expr, $n:expr) => {
281        std::slice::from_raw_parts($e, $n as usize).to_vec()
282    };
283}