use crate::core::cell::{Cell, CELL_MAXID};
use crate::core::ffi::{UdFunb, UdFuns};
use crate::raw;
use crate::MAX_LEN_OUT;
#[cfg(any(feature = "lock", doc))]
use {crate::SpiceLock, spice_derive::impl_for};
pub const CELL_MAXWIN: usize = 10_000;
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn bodc2n(code: i32) -> (String, bool) {
raw::bodc2n(code, MAX_LEN_OUT as i32)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn bodc2s(code: i32) -> String {
raw::bodc2s(code, MAX_LEN_OUT as i32)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn frmnam(frcode: i32) -> String {
raw::frmnam(frcode, MAX_LEN_OUT as i32)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn et2utc(et: f64, format: &str, prec: i32) -> String {
raw::et2utc(et, format, prec, MAX_LEN_OUT as i32)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn timout(et: f64, pictur: &str) -> String {
raw::timout(et, pictur, MAX_LEN_OUT as i32)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn tparse(string: &str) -> (f64, String) {
raw::tparse(string, MAX_LEN_OUT as i32)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn sce2s(sc: i32, et: f64) -> String {
raw::sce2s(sc, et, MAX_LEN_OUT as i32)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn scdecd(sc: i32, sclkdp: f64) -> String {
raw::scdecd(sc, sclkdp, MAX_LEN_OUT as i32)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn srfc2s(code: i32, bodyid: i32) -> (String, bool) {
raw::srfc2s(code, bodyid, MAX_LEN_OUT as i32)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn srfcss(code: i32, bodstr: &str) -> (String, bool) {
raw::srfcss(code, bodstr, MAX_LEN_OUT as i32)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn kdata(which: i32, kind: &str) -> (String, String, String, i32, bool) {
raw::kdata(
which,
kind,
MAX_LEN_OUT as i32,
MAX_LEN_OUT as i32,
MAX_LEN_OUT as i32,
)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn kinfo(file: &str) -> (String, String, i32, bool) {
raw::kinfo(file, MAX_LEN_OUT as i32, MAX_LEN_OUT as i32)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn gcpool(name: &str, start: usize, room: usize) -> Vec<String> {
raw::gcpool(name, start, room, MAX_LEN_OUT)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn stpool(item: &str, nth: i32, contin: &str) -> (String, i32, bool) {
raw::stpool(item, nth, contin, MAX_LEN_OUT)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn getfat(file: &str) -> (String, String) {
raw::getfat(file, MAX_LEN_OUT, MAX_LEN_OUT)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn getfvn(inst: &str, room: usize) -> (String, String, [f64; 3], Vec<[f64; 3]>) {
raw::getfvn(inst, room, MAX_LEN_OUT, MAX_LEN_OUT)
}
#[allow(clippy::type_complexity)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn et2lst(et: f64, body: i32, lon: f64, kind: &str) -> (i32, i32, i32, String, String) {
raw::et2lst(et, body, lon, kind, MAX_LEN_OUT, MAX_LEN_OUT)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn tpictr(sample: &str) -> (String, bool, String) {
raw::tpictr(sample, MAX_LEN_OUT, MAX_LEN_OUT)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn timdef(action: &str, item: &str, value: &str) -> String {
raw::timdef(action, item, value, MAX_LEN_OUT)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn trcnam(index: i32) -> String {
raw::trcnam(index, MAX_LEN_OUT as i32)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn repmct(input: &str, marker: &str, value: i32, strcase: char) -> String {
raw::repmct(input, marker, value, strcase, MAX_LEN_OUT as i32)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn spksfs(body: i32, et: f64) -> (i32, [f64; raw::SPK_DSCSIZ], String, bool) {
raw::spksfs(body, et, MAX_LEN_OUT)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dafec(handle: i32) -> Vec<String> {
let mut lines = Vec::new();
loop {
let (batch, done) = raw::dafec(handle, 64, MAX_LEN_OUT);
lines.extend(batch);
if done {
return lines;
}
}
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dasec(handle: i32) -> Vec<String> {
let mut lines = Vec::new();
loop {
let (batch, done) = raw::dasec(handle, 64, MAX_LEN_OUT);
lines.extend(batch);
if done {
return lines;
}
}
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn gnpool(name: &str, start: usize, room: usize) -> Vec<String> {
raw::gnpool(name, start, room, MAX_LEN_OUT)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn getfov(instid: i32, room: usize) -> (String, String, [f64; 3], Vec<[f64; 3]>) {
raw::getfov(instid, room, MAX_LEN_OUT, MAX_LEN_OUT)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dskp02(handle: i32, dladsc: raw::DLADSC) -> Vec<[i32; 3]> {
let (_nv, np) = raw::dskz02(handle, dladsc);
raw::dskp02(handle, dladsc, 1, np.max(0) as usize)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dskv02(handle: i32, dladsc: raw::DLADSC) -> Vec<[f64; 3]> {
let (nv, _np) = raw::dskz02(handle, dladsc);
raw::dskv02(handle, dladsc, 1, nv.max(0) as usize)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn lparse(list: &str, delim: &str) -> Vec<String> {
raw::lparse(list, delim, list.len() + 1, list.len() + 1)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn lparsm(list: &str, delims: &str) -> Vec<String> {
raw::lparsm(list, delims, list.len() + 1, list.len() + 1)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn lcase(input: &str) -> String {
raw::lcase(input, input.len() as i32 + 1)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn ucase(input: &str) -> String {
raw::ucase(input, input.len() as i32 + 1)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn cmprss(delim: char, n: i32, input: &str) -> String {
raw::cmprss(delim, n, input, input.len() as i32 + 1)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn nextwd(string: &str) -> (String, String) {
raw::nextwd(string, string.len() + 1, string.len() + 1)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn repmc(input: &str, marker: &str, value: &str) -> String {
raw::repmc(input, marker, value, (input.len() + value.len() + 1) as i32)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn repmd(input: &str, marker: &str, value: f64, sigdig: i32) -> String {
raw::repmd(input, marker, value, sigdig, MAX_LEN_OUT as i32)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn repmi(input: &str, marker: &str, value: i32) -> String {
raw::repmi(input, marker, value, MAX_LEN_OUT as i32)
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dskobj(dsk: &str) -> Cell<i32> {
let mut bodids = Cell::new(CELL_MAXID);
raw::dskobj(dsk, &mut bodids);
bodids
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn dsksrf(dsk: &str, bodyid: i32) -> Cell<i32> {
let mut srfids = Cell::new(CELL_MAXID);
raw::dsksrf(dsk, bodyid, &mut srfids);
srfids
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn spkobj(spk: &str) -> Cell<i32> {
let mut ids = Cell::new(CELL_MAXID);
raw::spkobj(spk, &mut ids);
ids
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn spkcov(spk: &str, idcode: i32) -> Cell<f64> {
let mut cover = Cell::new(CELL_MAXWIN);
raw::spkcov(spk, idcode, &mut cover);
cover
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn ckobj(ck: &str) -> Cell<i32> {
let mut ids = Cell::new(CELL_MAXID);
raw::ckobj(ck, &mut ids);
ids
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn ckcov(
ck: &str,
idcode: i32,
needav: bool,
level: &str,
tol: f64,
timsys: &str,
) -> Cell<f64> {
let mut cover = Cell::new(CELL_MAXWIN);
raw::ckcov(ck, idcode, needav, level, tol, timsys, &mut cover);
cover
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn pckcov(pck: &str, idcode: i32) -> Cell<f64> {
let mut cover = Cell::new(CELL_MAXWIN);
raw::pckcov(pck, idcode, &mut cover);
cover
}
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
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>,
) -> Cell<f64> {
let mut result = Cell::new(CELL_MAXWIN);
raw::gfoclt(
occtyp,
front,
fshape,
fframe,
back,
bshape,
bframe,
abcorr,
obsrvr,
step,
cnfine,
&mut result,
);
result
}
macro_rules! gf_search {
($($name:ident($($arg:ident: $ty:ty),*), $doc:expr);* $(;)?) => {$(
#[doc = $doc]
///
#[doc = concat!("See [`raw::", stringify!($name), "`] for the raw interface.")]
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn $name(
$($arg: $ty,)*
relate: &str,
refval: f64,
adjust: f64,
step: f64,
cnfine: &mut Cell<f64>,
) -> Cell<f64> {
let mut result = Cell::new(CELL_MAXWIN);
raw::$name(
$($arg,)* relate, refval, adjust, step, (CELL_MAXWIN / 2) as i32, cnfine,
&mut result,
);
result
}
)*};
}
gf_search! {
gfdist(target: &str, abcorr: &str, obsrvr: &str),
"Search for times when the distance to a target meets a condition.";
gfrr(target: &str, abcorr: &str, obsrvr: &str),
"Search for times when the range rate of a target meets a condition.";
gfpa(target: &str, illmn: &str, abcorr: &str, obsrvr: &str),
"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
),
"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
),
"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
),
"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
),
"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]
),
"Search for times when an illumination angle at a surface point meets a condition.";
}
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn gfrfov(
inst: &str,
raydir: [f64; 3],
rframe: &str,
abcorr: &str,
obsrvr: &str,
step: f64,
cnfine: &mut Cell<f64>,
) -> Cell<f64> {
let mut result = Cell::new(CELL_MAXWIN);
raw::gfrfov(
inst,
raydir,
rframe,
abcorr,
obsrvr,
step,
cnfine,
&mut result,
);
result
}
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn gftfov(
inst: &str,
target: &str,
tshape: &str,
tframe: &str,
abcorr: &str,
obsrvr: &str,
step: f64,
cnfine: &mut Cell<f64>,
) -> Cell<f64> {
let mut result = Cell::new(CELL_MAXWIN);
raw::gftfov(
inst,
target,
tshape,
tframe,
abcorr,
obsrvr,
step,
cnfine,
&mut result,
);
result
}
#[allow(clippy::too_many_arguments)]
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn gfuds(
udfuns: UdFuns,
udfunb: UdFunb,
relate: &str,
refval: f64,
adjust: f64,
step: f64,
cnfine: &mut Cell<f64>,
) -> Cell<f64> {
let mut result = Cell::new(CELL_MAXWIN);
raw::gfuds(
udfuns,
udfunb,
relate,
refval,
adjust,
step,
(CELL_MAXWIN / 2) as i32,
cnfine,
&mut result,
);
result
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn gfudb(udfuns: UdFuns, udfunb: UdFunb, step: f64, cnfine: &mut Cell<f64>) -> Cell<f64> {
let mut result = Cell::new(CELL_MAXWIN);
raw::gfudb(udfuns, udfunb, step, cnfine, &mut result);
result
}
#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
pub fn pckfrm(pck: &str) -> Cell<i32> {
let mut ids = Cell::new(CELL_MAXID);
raw::pckfrm(pck, &mut ids);
ids
}