Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gsw infunnel #60

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

repos:
- repo: https://github.com/codespell-project/codespell
rev: v2.2.1
rev: v2.2.6
hooks:
- id: codespell
args:
- --ignore-words-list=preformed

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand Down
31 changes: 30 additions & 1 deletion gsw_check_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "gswteos-10.h"
#include "gsw_check_data.h"

#include <stdio.h>
ocefpaf marked this conversation as resolved.
Show resolved Hide resolved

#define test_func(name, arglist, value, var) \
for (i=0; i<count; i++) { \
value[i] = gsw_ ## name arglist; \
Expand Down Expand Up @@ -96,6 +98,32 @@ double tf_poly[cast_m*cast_n];
double h[cast_m*cast_n];
double z[cast_m*cast_n];

int assert_equal(int actual, int expected, const char *test_name) {
if (actual == expected) {
printf("%s: ............................... passed\n", test_name);
} else {
printf("%s: Failed (Expected: %d, Actual: %d)\n", test_name, expected, actual);
return gsw_error_flag=1;
}
}


void test_infunnel() {
// Inside the funnel.
int result1 = gsw_infunnel(35.0, 5.0, 400);
ocefpaf marked this conversation as resolved.
Show resolved Hide resolved
assert_equal(result1, 1, "gsw_infunnel -> inside funnel");

int result2 = gsw_infunnel(20.0, 7.0, 2000);
assert_equal(result2, 1, "gsw_infunnel -> inside funnel");

// Outside the funnel
int result3 = gsw_infunnel(10.0, 0.0, 9000);
assert_equal(result3, 0, "gsw_infunnel -> invalid pressure");

int result4 = gsw_infunnel(45.0, 10.0, 400);
assert_equal(result4, 0, "gsw_infunnel -> invalid salinity");
}

int
main(int argc, char **argv)
{
Expand Down Expand Up @@ -124,7 +152,6 @@ main(int argc, char **argv)
" of TEOS-10 (version 3.05).\n");

check_count = 1;

section_title("Practical Salinity, PSS-78");

test_func(c_from_sp, (sp[i],t[i],p[i]), c,c_from_sp);
Expand Down Expand Up @@ -556,6 +583,8 @@ main(int argc, char **argv)
test_func(o2sol, (sa[i],ct[i],p[i],lon[i],lat[i]), value, o2sol);
test_func(o2sol_sp_pt, (sp[i],pt[i]), value, o2sol_sp_pt);

test_infunnel();

if (gsw_error_flag)
{
printf("\nYour installation of the Gibbs SeaWater (GSW) "
Expand Down
51 changes: 42 additions & 9 deletions gsw_oceanographic_toolbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,39 @@ gsw_add_mean(double *data_in, double *data_out)
}
/*
!==========================================================================
function gsw_infunnel(sa,ct,p)
!==========================================================================

! "oceanographic funnel" check for the 75-term equation
!
! sa : Absolute Salinity [g/kg]
! ct : Conservative Temperature [deg C]
! p : sea pressure [dbar]
!
! gsw_infunnel : 0, if SA, CT and p are outside the "funnel"
! 1, if SA, CT and p are inside the "funnel"
!
! Note. The term "funnel" (McDougall et al., 2003) describes the range of
! SA, CT and p over which the error in the fit of the computationally
! efficient 75-term expression for specific volume in terms of SA, CT
! and p was calculated (Roquet et al., 2015).
*/
int
gsw_infunnel(double sa, double ct, double p)
{
return !(p > 8000 ||
sa < 0 ||
sa > 42 ||
(p < 500 && ct < gsw_ct_freezing(sa, p, 0)) ||
(p >= 500 && p < 6500 && sa < p * 5e-3 - 2.5) ||
(p > 500 && p < 6500 && ct > (31.66666666666667 - p * 3.333333333333334e-3)) ||
ocefpaf marked this conversation as resolved.
Show resolved Hide resolved
(p >= 500 && ct < gsw_ct_freezing(sa, 500, 0)) ||
(p >= 6500 && sa < 30) ||
(p >= 6500 && ct > 10.0)
);
}
/*
!==========================================================================
function gsw_adiabatic_lapse_rate_from_ct(sa,ct,p)
!==========================================================================

Expand Down Expand Up @@ -215,7 +248,7 @@ elemental function gsw_adiabatic_lapse_rate_ice (t, p)
! ( i.e. absolute pressure - 10.1325 dbar )
!
! Note. The output is in unit of degrees Celsius per Pa,
! (or equivilently K/Pa) not in units of K/dbar.
! (or equivalently K/Pa) not in units of K/dbar.
!--------------------------------------------------------------------------
*/
double
Expand Down Expand Up @@ -2781,12 +2814,12 @@ elemental subroutine gsw_frazil_properties (sa_bulk, h_bulk, p, &
! throughout the code).
!
! When the mass fraction w_Ih_final is calculated as being a positive
! value, the seawater-ice mixture is at thermodynamic equlibrium.
! value, the seawater-ice mixture is at thermodynamic equilibrium.
!
! This code returns w_Ih_final = 0 when the input bulk enthalpy, h_bulk,
! is sufficiently large (i.e. sufficiently "warm") so that there is no ice
! present in the final state. In this case the final state consists of
! only seawater rather than being an equlibrium mixture of seawater and
! only seawater rather than being an equilibrium mixture of seawater and
! ice which occurs when w_Ih_final is positive. Note that when
! w_Ih_final = 0, the final seawater is not at the freezing temperature.
!
Expand Down Expand Up @@ -2978,12 +3011,12 @@ elemental subroutine gsw_frazil_properties_potential (sa_bulk, h_pot_bulk,&
! is assumed to be zero throughout the code).
!
! When the mass fraction w_Ih_final is calculated as being a positive
! value, the seawater-ice mixture is at thermodynamic equlibrium.
! value, the seawater-ice mixture is at thermodynamic equilibrium.
!
! This code returns w_Ih_final = 0 when the input bulk enthalpy, h_bulk,
! is sufficiently large (i.e. sufficiently "warm") so that there is no ice
! present in the final state. In this case the final state consists of
! only seawater rather than being an equlibrium mixture of seawater and
! only seawater rather than being an equilibrium mixture of seawater and
! ice which occurs when w_Ih_final is positive. Note that when
! w_Ih_final = 0, the final seawater is not at the freezing temperature.
!
Expand Down Expand Up @@ -3249,12 +3282,12 @@ elemental subroutine gsw_frazil_properties_potential_poly (sa_bulk, &
! is assumed to be zero throughout the code).
!
! When the mass fraction w_Ih_final is calculated as being a positive
! value, the seawater-ice mixture is at thermodynamic equlibrium.
! value, the seawater-ice mixture is at thermodynamic equilibrium.
!
! This code returns w_Ih_final = 0 when the input bulk enthalpy, h_bulk,
! is sufficiently large (i.e. sufficiently "warm") so that there is no ice
! present in the final state. In this case the final state consists of
! only seawater rather than being an equlibrium mixture of seawater and
! only seawater rather than being an equilibrium mixture of seawater and
! ice which occurs when w_Ih_final is positive. Note that when
! w_Ih_final = 0, the final seawater is not at the freezing temperature.
!
Expand Down Expand Up @@ -5803,12 +5836,12 @@ elemental subroutine gsw_melting_ice_into_seawater (sa, ct, p, w_ih, t_ih,&
! This code takes the seawater to contain no dissolved air.
!
! When the mass fraction w_Ih_final is calculated as being a positive
! value, the seawater-ice mixture is at thermodynamic equlibrium.
! value, the seawater-ice mixture is at thermodynamic equilibrium.
!
! This code returns w_Ih_final = 0 when the input bulk enthalpy, h_bulk,
! is sufficiently large (i.e. sufficiently "warm") so that there is no ice
! present in the final state. In this case the final state consists of
! only seawater rather than being an equlibrium mixture of seawater and
! only seawater rather than being an equilibrium mixture of seawater and
! ice which occurs when w_Ih_final is positive. Note that when
! w_Ih_final = 0, the final seawater is not at the freezing temperature.
!
Expand Down
1 change: 1 addition & 0 deletions gswteos-10.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern void gsw_add_barrier(double *input_data, double lon, double lat,
double long_grid, double lat_grid, double dlong_grid,
double dlat_grid, double *output_data);
extern void gsw_add_mean(double *data_in, double *data_out);
extern int gsw_infunnel(double sa, double ct, double p);
extern double gsw_adiabatic_lapse_rate_from_ct(double sa, double ct, double p);
extern double gsw_adiabatic_lapse_rate_ice(double t, double p);
extern double gsw_alpha(double sa, double ct, double p);
Expand Down