Skip to content

Commit

Permalink
Implement existing internal funcs in C FFI (#78)
Browse files Browse the repository at this point in the history
Co-authored-by: Jacob Wood <[email protected]>
  • Loading branch information
JMdoubleU and Jacob Wood authored Apr 26, 2024
1 parent e5d6da8 commit 380be15
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 37 deletions.
69 changes: 33 additions & 36 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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!()
Expand Down Expand Up @@ -762,17 +789,6 @@ pub unsafe extern "C" fn gsw_geo_strf_dyn_height_pc(
std::ptr::null_mut::<f64>()
}

#[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!()
Expand All @@ -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!()
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/gsw_internal_funcs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f64> {
pub(crate) fn gibbs_ice(nt: u8, np: u8, t: f64, p: f64) -> Result<f64> {
// use a complex number crate. eventually replaced by calculations by hand
use num_complex::Complex;

Expand Down

0 comments on commit 380be15

Please sign in to comment.