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

Bring lons outside of [0, 360) into range #47

Merged
merged 1 commit into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions gsw_check_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ main(int argc, char **argv)
test_func(sstar_from_sp,(sp[i],p[i],lon[i],lat[i]),value,sstar_from_sp);
test_func(ct_from_t, (sa[i],t[i],p[i]), value,ct_from_t);

// the baltic sea calculations have a lon range assumption in them
for (i = 0; i<count; i++) {
value[i] = gsw_sa_from_sp(sp[i],p[i],lon[i]+360.,lat[i]);
}
check_accuracy("sa_from_sp_lon_wrapped_high",sa_from_sp_ca,"sa_from_sp",count,value,sa_from_sp);
for (i = 0; i<count; i++) {
value[i] = gsw_sa_from_sp(sp[i],p[i],lon[i]-720.,lat[i]);
}
check_accuracy("sa_from_sp_lon_wrapped_low",sa_from_sp_ca,"sa_from_sp",count,value,sa_from_sp);

section_title(
"Other conversions between Temperatures, Salinities, Entropy, "
"Pressure and Height");
Expand All @@ -146,6 +156,17 @@ main(int argc, char **argv)
test_func(sr_from_sp, (sp[i]), sr,sr_from_sp);
test_func(sp_from_sr, (sr[i]), value,sp_from_sr);
test_func(sp_from_sa, (sa[i],p[i],lon[i],lat[i]), value,sp_from_sa);

// the baltic sea calculations have a lon range assumption in them
for (i = 0; i<count; i++) {
value[i] = gsw_sp_from_sa(sa[i],p[i],lon[i]+360.,lat[i]);
}
check_accuracy("ssp_from_sa_lon_wrapped_high",sp_from_sa_ca,"sp_from_sa",count,value,sp_from_sa);
for (i = 0; i<count; i++) {
value[i] = gsw_sp_from_sa(sa[i],p[i],lon[i]-720.,lat[i]);
}
check_accuracy("sa_from_sp_lon_wrapped_low",sp_from_sa_ca,"sp_from_sa",count,value,sp_from_sa);

test_func(sstar_from_sa,(sa[i],p[i],lon[i],lat[i]),sstar,sstar_from_sa);
test_func(sa_from_sstar, (sstar[i],p[i],lon[i],lat[i]), value,
sa_from_sstar);
Expand Down Expand Up @@ -333,6 +354,25 @@ main(int argc, char **argv)
test_func(deltasa_atlas, (p[i],lon[i],lat[i]),value,deltasa_atlas);
test_func(fdelta, (p[i],lon[i],lat[i]),value,fdelta);

// wrap the lons a bit to check wrapping
for (i = 0; i<count; i++) {
value[i] = gsw_deltasa_atlas(p[i],lon[i]+360.,lat[i]);
}
check_accuracy("deltasa_atlas_lon_wrapped_high",deltasa_atlas_ca,"deltasa_atlas",count,value,deltasa_atlas);
for (i = 0; i<count; i++) {
value[i] = gsw_deltasa_atlas(p[i],lon[i]-720.,lat[i]);
}
check_accuracy("deltasa_atlas_lon_wrapped_low",deltasa_atlas_ca,"deltasa_atlas",count,value,deltasa_atlas);

for (i = 0; i<count; i++) {
value[i] = gsw_fdelta(p[i],lon[i]+360.,lat[i]);
}
check_accuracy("fdelta_lon_wrapped_high",fdelta_ca,"fdelta",count,value,fdelta);
for (i = 0; i<count; i++) {
value[i] = gsw_fdelta(p[i],lon[i]-720.,lat[i]);
}
check_accuracy("fdelta_lon_wrapped_low",fdelta_ca,"fdelta",count,value,fdelta);

section_title(
"Water column properties, based on the 75-term polynomial "
"for specific volume");
Expand Down
8 changes: 8 additions & 0 deletions gsw_oceanographic_toolbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -9024,6 +9024,10 @@ gsw_sa_from_sp_baltic(double sp, double lon, double lat)
GSW_BALTIC_DATA;
double xx_left, xx_right, return_value;

lon = fmod(lon, 360.0);
if (lon < 0.0)
lon += 360.0;

if (xb_left[1] < lon && lon < xb_right[0] && yb_left[0] < lat &&
lat < yb_left[2]) {

Expand Down Expand Up @@ -9567,6 +9571,10 @@ gsw_sp_from_sa_baltic(double sa, double lon, double lat)
GSW_BALTIC_DATA;
double xx_left, xx_right, return_value;

lon = fmod(lon, 360.0);
if (lon < 0.0)
lon += 360.0;

if (xb_left[1] < lon && lon < xb_right[0] && yb_left[0] < lat &&
lat < yb_left[2]) {

Expand Down
2 changes: 2 additions & 0 deletions gsw_saar.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ gsw_saar(double p, double lon, double lat)
if (lat < -86.0 || lat > 90.0)
return (return_value);

lon = fmod(lon, 360.0);
if (lon < 0.0)
lon += 360.0;

Expand Down Expand Up @@ -184,6 +185,7 @@ gsw_deltasa_atlas(double p, double lon, double lat)
if (lat < -86.0 || lat > 90.0)
return (return_value);

lon = fmod(lon, 360.0);
if (lon < 0.0)
lon += 360.0;

Expand Down