From 380be1540fec07d57d32d9a6e088608614b98385 Mon Sep 17 00:00:00 2001 From: Jacob Wood <7240625+JMdoubleU@users.noreply.github.com> Date: Fri, 26 Apr 2024 00:53:34 -0400 Subject: [PATCH] Implement existing internal funcs in C FFI (#78) Co-authored-by: Jacob Wood --- src/ffi.rs | 69 +++++++++++++++++------------------ src/gsw_internal_funcs/mod.rs | 2 +- 2 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/ffi.rs b/src/ffi.rs index 23b816ee..91d051a4 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -199,6 +199,11 @@ pub unsafe extern "C" fn gsw_enthalpy_second_derivatives( *h_ct_ct = ct_ct; } +#[no_mangle] +pub unsafe extern "C" fn gsw_enthalpy_sso_0(p: f64) -> f64 { + crate::gsw_internal_funcs::enthalpy_sso_0(p) +} + #[no_mangle] pub unsafe extern "C" fn gsw_sa_from_rho(rho: f64, ct: f64, p: f64) -> f64 { crate::volume::sa_from_rho(rho, ct, p).unwrap_or(GSW_INVALID_VALUE) @@ -308,6 +313,34 @@ pub unsafe extern "C" fn gsw_enthalpy_diff(sa: f64, ct: f64, p_shallow: f64, p_d crate::volume::enthalpy_diff(sa, ct, p_shallow, p_deep).unwrap_or(GSW_INVALID_VALUE) } +#[no_mangle] +pub unsafe extern "C" fn gsw_gibbs_ice( + nt: ::libc::c_int, + np: ::libc::c_int, + t: f64, + p: f64, +) -> f64 { + crate::gsw_internal_funcs::gibbs_ice(nt as u8, np as u8, t, p).unwrap_or(GSW_INVALID_VALUE) +} + +#[no_mangle] +pub unsafe extern "C" fn gsw_gibbs( + ns: ::libc::c_int, + nt: ::libc::c_int, + np: ::libc::c_int, + sa: f64, + t: f64, + p: f64, +) -> f64 { + crate::gsw_internal_funcs::gibbs(ns as u8, nt as u8, np as u8, sa, t, p) + .unwrap_or(GSW_INVALID_VALUE) +} + +#[no_mangle] +pub unsafe extern "C" fn gsw_hill_ratio_at_sp2(t: f64) -> f64 { + crate::gsw_internal_funcs::hill_ratio_at_sp2(t) +} + #[no_mangle] pub unsafe extern "C" fn gsw_kappa(sa: f64, ct: f64, p: f64) -> f64 { crate::volume::kappa(sa, ct, p).unwrap_or(GSW_INVALID_VALUE) @@ -586,12 +619,6 @@ pub unsafe extern "C" fn gsw_enthalpy_second_derivatives_ct_exact( //unimplemented!() } -#[no_mangle] -pub unsafe extern "C" fn gsw_enthalpy_sso_0(p: f64) -> f64 { - //unimplemented!() - f64::NAN -} - #[no_mangle] pub unsafe extern "C" fn gsw_enthalpy_t_exact(sa: f64, t: f64, p: f64) -> f64 { //unimplemented!() @@ -762,17 +789,6 @@ pub unsafe extern "C" fn gsw_geo_strf_dyn_height_pc( std::ptr::null_mut::() } -#[no_mangle] -pub unsafe extern "C" fn gsw_gibbs_ice( - nt: ::libc::c_int, - np: ::libc::c_int, - t: f64, - p: f64, -) -> f64 { - //unimplemented!() - f64::NAN -} - #[no_mangle] pub unsafe extern "C" fn gsw_gibbs_ice_part_t(t: f64, p: f64) -> f64 { //unimplemented!() @@ -791,19 +807,6 @@ pub unsafe extern "C" fn gsw_gibbs_ice_pt0_pt0(pt0: f64) -> f64 { f64::NAN } -#[no_mangle] -pub unsafe extern "C" fn gsw_gibbs( - ns: ::libc::c_int, - nt: ::libc::c_int, - np: ::libc::c_int, - sa: f64, - t: f64, - p: f64, -) -> f64 { - //unimplemented!() - f64::NAN -} - #[no_mangle] pub unsafe extern "C" fn gsw_gibbs_pt0_pt0(sa: f64, pt0: f64) -> f64 { //unimplemented!() @@ -822,12 +825,6 @@ pub unsafe extern "C" fn gsw_helmholtz_energy_ice(t: f64, p: f64) -> f64 { f64::NAN } -#[no_mangle] -pub unsafe extern "C" fn gsw_hill_ratio_at_sp2(t: f64) -> f64 { - //unimplemented!() - f64::NAN -} - #[no_mangle] pub unsafe extern "C" fn gsw_ice_fraction_to_freeze_seawater( sa: f64, diff --git a/src/gsw_internal_funcs/mod.rs b/src/gsw_internal_funcs/mod.rs index eb7dfb11..75cc3d3a 100644 --- a/src/gsw_internal_funcs/mod.rs +++ b/src/gsw_internal_funcs/mod.rs @@ -1068,7 +1068,7 @@ mod test_gibbs { /// - pressure derivatives in: \[(J/kg) (Pa)^(-np)\] /// - mixed derivatives in \[(J/kg) (K)^(-nt) (Pa)^(-np)\] #[allow(dead_code)] -fn gibbs_ice(nt: u8, np: u8, t: f64, p: f64) -> Result { +pub(crate) fn gibbs_ice(nt: u8, np: u8, t: f64, p: f64) -> Result { // use a complex number crate. eventually replaced by calculations by hand use num_complex::Complex;