From 2db27fb70872a3dec0a2d0556692f9b22d864263 Mon Sep 17 00:00:00 2001 From: mauzey1 Date: Fri, 9 Aug 2024 16:39:49 -0700 Subject: [PATCH 01/27] Adding gsw_sa_ct_interp --- Makefile | 6 +- gsw_sa_ct_interp.c | 533 +++++++++++++++++++++++++++++++++++++++++++++ gswteos-10.h | 4 + 3 files changed, 541 insertions(+), 2 deletions(-) create mode 100644 gsw_sa_ct_interp.c diff --git a/Makefile b/Makefile index aa0ff06..f3b43f0 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,11 @@ Program = gsw_check PROGRAM_SOURCES = gsw_check_functions.c\ gsw_oceanographic_toolbox.c\ - gsw_saar.c + gsw_saar.c\ + gsw_sa_ct_interp.c LIBRARY_SRCS = gsw_oceanographic_toolbox.c \ - gsw_saar.c + gsw_saar.c \ + gsw_sa_ct_interp.c # \ !ifdef 0 # diff --git a/gsw_sa_ct_interp.c b/gsw_sa_ct_interp.c new file mode 100644 index 0000000..95114fd --- /dev/null +++ b/gsw_sa_ct_interp.c @@ -0,0 +1,533 @@ +#include "gswteos-10.h" +#include "gsw_internal_const.h" + +/* +!========================================================================== +subroutine gsw_util_intersect (x, nx, y, ny, ix, iy) +!========================================================================== +! +! Find unique values common to both x and y arrays. +! +! x : x array of values +! nx : length of x array +! y : y array of values +! ny : length of y array +! xi : indexes of x of values common to y +! yi : indexes of y of values common to x +! +! ni : length of ix and iy +! +*/ +int +gsw_util_intersect(double *x, int nx, double *y, int ny, int *ix, int *iy) +{ + int *sort_ix, *sort_iy, *unique_ix, *unique_iy; + int i, uix, uiy, nxs, nys, itx, ity, ni; + + double xx, yy; + + if (nx <= 0 || ny <= 0) { + return 0; + } + + sort_ix = malloc(nx * sizeof(int)); + sort_iy = malloc(ny * sizeof(int)); + unique_ix = malloc(nx * sizeof(int)); + unique_iy = malloc(ny * sizeof(int)); + + gsw_util_sort_real(x, nx, sort_ix); + gsw_util_sort_real(y, ny, sort_iy); + + nxs = 0; + uix = sort_ix[0]; + for (i=1; i yy) { + ++ity; + } else { + ix[ni] = unique_ix[itx]; + iy[ni] = unique_iy[ity]; + ++itx; + ++ity; + ++ni; + } + } + + free(sort_ix); + free(sort_iy); + free(unique_ix); + free(unique_iy); + + return ni; +} + +/* +!========================================================================== +subroutine gsw_SA_CT_interp (sa,ct,p,p_i) +!========================================================================== +! +! SA and CT interpolation to p_i on a cast +! +! SA = Absolute Salinity [ g/kg ] +! CT = Conservative Temperature (ITS-90) [ deg C ] +! p = sea pressure [ dbar ] +! ( i.e. absolute pressure - 10.1325 dbar ) +! p_i = specific query points at which the interpolated SA_i and CT_i +! are required [ dbar ] +! +! SA & CT need to have the same dimensions. +! p may have dimensions Mx1 or 1xN or MxN, where SA & CT are MxN. +! p_i needs to be either a vector or a matrix and have dimensions M_ix1 +! or M_ixN. +! +! SA_i = interpolated SA values at pressures p_i [ g/kg ] +! CT_i = interpolated CT values at pressures p_i [ deg C ] +! +!-------------------------------------------------------------------------- +*/ +void +gsw_sa_ct_interp(double *sa, double *ct, int m, int n, double *p, int mp, + int np, double *p_i, int mp_i, int np_i, double *sa_i, double *ct_i) +{ + double factor = 9., + rec_factor = 1./factor, + + sin_kpi_on_16[] = { + 1.950903220161283e-1, + 3.826834323650898e-1, + 5.555702330196022e-1, + 7.071067811865475e-1, + 8.314696123025452e-1, + 9.238795325112867e-1, + 9.807852804032304e-1 + }, + cos_kpi_on_16[] = { + 9.807852804032304e-1, + 9.238795325112867e-1, + 8.314696123025452e-1, + 7.071067811865476e-1, + 5.555702330196023e-1, + 3.826834323650898e-1, + 1.950903220161283e-1 + }; + + int i, j, k, i_prof, prof_len, interp_profile_length, + num_interp_profiles, not_monotonic, unique_count, new_len, p_all_len, + i_min_p_obs, i_obs_plus_interp_len, i_surf_and_obs_plus_interp_len, + i_out_len, i_2_len, i_frozen, i_shallower, i_above, i_above_i, i_below_i; + int *p_idx, *p_all_idx, *i_obs_plus_interp, *i_surf_and_obs_plus_interp, + *i_out, *i_1, *i_2, *i_3; + double d, ct_f, unique_p, ct_sum, sa_sum, min_p_obs, max_p_obs; + double *p_mat, *p_i_mat, *sa_obs, *ct_obs, *p_obs, *p_i_tmp, + *p_sort, *sa_sort, *ct_sort, *p_all, *p_all_sort, + *p_obs_plus_interp, *p_surf_and_obs_plus_interp, + *independent_variable, *independent_variable_obs_plus_interp, + *scaled_sa_obs, *v_tmp, *q_tmp, *v_i, *q_i, + *sa_i_obs_plus_interp, *ct_i_obs_plus_interp, + *sa_i_limiting_obs_plus_interp, *ct_i_limiting_obs_plus_interp, + *ctf_i_tointerp, *sa_i_tooutput, *ct_i_tooutput; + + p_mat = (double *) malloc(m*n*sizeof (double)); + p_i_mat = (double *) malloc(mp_i*np_i*sizeof (double)); + sa_obs = (double *) malloc(m*sizeof (double)); + ct_obs = (double *) malloc(m*sizeof (double)); + p_obs = (double *) malloc(m*sizeof (double)); + p_i_tmp = (double *) malloc(m*sizeof (double)); + p_idx = (int *) malloc(m*sizeof (int)); + p_sort = (double *) malloc(m*sizeof (double)); + sa_sort = (double *) malloc(m*sizeof (double)); + ct_sort = (double *) malloc(m*sizeof (double)); + p_all = (double *) malloc((m + mp_i)*sizeof (double)); + p_all_sort = (double *) malloc((m + mp_i)*sizeof (double)); + p_all_idx = (int *) malloc((m + mp_i)*sizeof (int)); + i_obs_plus_interp = (int *) malloc((m + mp_i)*sizeof (int)); + i_surf_and_obs_plus_interp = (int *) malloc((m + mp_i)*sizeof (int)); + p_obs_plus_interp = (double *) malloc((m + mp_i)*sizeof (double)); + p_surf_and_obs_plus_interp = (double *) malloc((m + mp_i)*sizeof (double)); + i_out = (int *) malloc((m + mp_i)*sizeof (int)); + i_1 = (int *) malloc((m + mp_i)*sizeof (int)); + i_2 = (int *) malloc((m + mp_i)*sizeof (int)); + i_3 = (int *) malloc((m + mp_i)*sizeof (int)); + + if (m < 4 && np == 1) + return; // There must be at least 4 bottles' + else if ((n == np && mp == 1) || (n == mp && np == 1)){ + for (j=0; j 1) || (mp_i == n && np_i != n)) { + interp_profile_length = np_i; + num_interp_profiles = mp_i; + for (j=0; j 0) { + gsw_util_sort_real(p_obs, prof_len, p_idx); + for (i=0; i= min_p_obs && p_all[i] <= max_p_obs) { + i_obs_plus_interp[i_obs_plus_interp_len] = i; + p_obs_plus_interp[i_obs_plus_interp_len] = p_all[i]; + i_obs_plus_interp_len++; + } + if (p_all[i] <= max_p_obs) { + i_surf_and_obs_plus_interp[i_surf_and_obs_plus_interp_len] = i; + p_surf_and_obs_plus_interp[i_surf_and_obs_plus_interp_len] = p_all[i]; + i_surf_and_obs_plus_interp_len++; + } + } + i_out_len = gsw_util_intersect(p_i_tmp, interp_profile_length, p_surf_and_obs_plus_interp, i_surf_and_obs_plus_interp_len, i_out, i_1); + i_2_len = gsw_util_intersect(p_obs, prof_len, p_obs_plus_interp, i_obs_plus_interp_len, i_2, i_3); + + independent_variable = (double *) malloc(prof_len*sizeof (double)); + independent_variable_obs_plus_interp = (double *) malloc(i_obs_plus_interp_len*sizeof (double)); + + for(i=0; i i_3[i_shallower]) { + i_below_i = i_3[i_shallower]; + } else { + i_below_i = i_3[i_above + 1]; + } + + for (i=i_above_i; i<=i_below_i; ++i) { + sa_i_obs_plus_interp[i] = sa_i_limiting_obs_plus_interp[i]; + ct_i_obs_plus_interp[i] = ct_i_limiting_obs_plus_interp[i]; + ctf_i_tointerp[i] = gsw_ct_freezing_poly(sa_i_obs_plus_interp[i], p_all[i], 0.); + } + } + + sa_i_tooutput = (double *)malloc(i_surf_and_obs_plus_interp_len*sizeof (double)); + ct_i_tooutput = (double *)malloc(i_surf_and_obs_plus_interp_len*sizeof (double)); + + if (min_p_obs != 0.) { + for (i=0; i Date: Fri, 9 Aug 2024 18:36:27 -0700 Subject: [PATCH 02/27] Fix several mistakes in gsw_sa_ct_interp code --- gsw_sa_ct_interp.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/gsw_sa_ct_interp.c b/gsw_sa_ct_interp.c index 95114fd..4d45314 100644 --- a/gsw_sa_ct_interp.c +++ b/gsw_sa_ct_interp.c @@ -342,7 +342,7 @@ gsw_sa_ct_interp(double *sa, double *ct, int m, int n, double *p, int mp, min_p_obs = p_obs[0]; max_p_obs = p_obs[0]; for (i=1; i Date: Fri, 9 Aug 2024 19:10:04 -0700 Subject: [PATCH 03/27] Add DECLSPEC to gsw_sa_ct_interp function --- gswteos-10.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gswteos-10.h b/gswteos-10.h index e712b30..5f732ac 100644 --- a/gswteos-10.h +++ b/gswteos-10.h @@ -228,7 +228,7 @@ DECLSPEC extern double gsw_rho_t_exact(double sa, double t, double p); DECLSPEC extern void gsw_rr68_interp_sa_ct(double *sa, double *ct, double *p, int mp, double *p_i, int mp_i, double *sa_i, double *ct_i); DECLSPEC extern double gsw_saar(double p, double lon, double lat); -extern void gsw_sa_ct_interp(double *sa, double *ct, int m, int n, double *p, +DECLSPEC extern void gsw_sa_ct_interp(double *sa, double *ct, int m, int n, double *p, int mp, int np, double *p_i, int mp_i, int np_i, double *sa_i, double *ct_i); DECLSPEC extern double gsw_sa_freezing_estimate(double p, double saturation_fraction, @@ -305,7 +305,7 @@ DECLSPEC extern void gsw_turner_rsubrho(double *sa, double *ct, double *p, int DECLSPEC extern int gsw_util_indx(double *x, int n, double z); DECLSPEC extern double *gsw_util_interp1q_int(int nx, double *x, int *iy, int nxi, double *x_i, double *y_i); -extern int gsw_util_intersect(double *x, int nx, double *y, int ny, int *ix, int *iy); +DECLSPEC extern int gsw_util_intersect(double *x, int nx, double *y, int ny, int *ix, int *iy); DECLSPEC extern double *gsw_util_linear_interp(int nx, double *x, int ny, double *y, int nxi, double *x_i, double *y_i); DECLSPEC extern void gsw_util_sort_real(double *rarray, int nx, int *iarray); From 99d141951f9474cff1714054605a79ba249be663 Mon Sep 17 00:00:00 2001 From: mauzey1 Date: Fri, 30 Aug 2024 11:09:33 -0700 Subject: [PATCH 04/27] Rework gsw_sa_ct_interp to process one profile at a time --- gsw_sa_ct_interp.c | 552 ++++++++++++++++++++------------------------- gswteos-10.h | 5 +- 2 files changed, 252 insertions(+), 305 deletions(-) diff --git a/gsw_sa_ct_interp.c b/gsw_sa_ct_interp.c index 4d45314..bbbfe16 100644 --- a/gsw_sa_ct_interp.c +++ b/gsw_sa_ct_interp.c @@ -104,11 +104,7 @@ subroutine gsw_SA_CT_interp (sa,ct,p,p_i) ! ( i.e. absolute pressure - 10.1325 dbar ) ! p_i = specific query points at which the interpolated SA_i and CT_i ! are required [ dbar ] -! -! SA & CT need to have the same dimensions. -! p may have dimensions Mx1 or 1xN or MxN, where SA & CT are MxN. -! p_i needs to be either a vector or a matrix and have dimensions M_ix1 -! or M_ixN. + ! ! SA_i = interpolated SA values at pressures p_i [ g/kg ] ! CT_i = interpolated CT values at pressures p_i [ deg C ] @@ -116,8 +112,8 @@ subroutine gsw_SA_CT_interp (sa,ct,p,p_i) !-------------------------------------------------------------------------- */ void -gsw_sa_ct_interp(double *sa, double *ct, int m, int n, double *p, int mp, - int np, double *p_i, int mp_i, int np_i, double *sa_i, double *ct_i) +gsw_sa_ct_interp(double *sa, double *ct, double *p, int m, + double *p_i, int m_i, double *sa_i, double *ct_i) { double factor = 9., rec_factor = 1./factor, @@ -141,14 +137,14 @@ gsw_sa_ct_interp(double *sa, double *ct, int m, int n, double *p, int mp, 1.950903220161283e-1 }; - int i, j, k, i_prof, prof_len, interp_profile_length, - num_interp_profiles, not_monotonic, unique_count, new_len, p_all_len, + int i, j, k, prof_len, + not_monotonic, unique_count, new_len, p_all_len, i_min_p_obs, i_obs_plus_interp_len, i_surf_and_obs_plus_interp_len, i_out_len, i_2_len, i_frozen, i_shallower, i_above, i_above_i, i_below_i; int *p_idx, *p_all_idx, *i_obs_plus_interp, *i_surf_and_obs_plus_interp, *i_out, *i_1, *i_2, *i_3; double d, ct_f, unique_p, ct_sum, sa_sum, min_p_obs, max_p_obs; - double *p_mat, *p_i_mat, *sa_obs, *ct_obs, *p_obs, *p_i_tmp, + double *sa_obs, *ct_obs, *p_obs, *p_i_tmp, *p_sort, *sa_sort, *ct_sort, *p_all, *p_all_sort, *p_obs_plus_interp, *p_surf_and_obs_plus_interp, *independent_variable, *independent_variable_obs_plus_interp, @@ -157,358 +153,310 @@ gsw_sa_ct_interp(double *sa, double *ct, int m, int n, double *p, int mp, *sa_i_limiting_obs_plus_interp, *ct_i_limiting_obs_plus_interp, *ctf_i_tointerp, *sa_i_tooutput, *ct_i_tooutput; - p_mat = (double *) malloc(m*n*sizeof (double)); - p_i_mat = (double *) malloc(mp_i*np_i*sizeof (double)); sa_obs = (double *) malloc(m*sizeof (double)); ct_obs = (double *) malloc(m*sizeof (double)); p_obs = (double *) malloc(m*sizeof (double)); - p_i_tmp = (double *) malloc(m*sizeof (double)); p_idx = (int *) malloc(m*sizeof (int)); p_sort = (double *) malloc(m*sizeof (double)); sa_sort = (double *) malloc(m*sizeof (double)); ct_sort = (double *) malloc(m*sizeof (double)); - p_all = (double *) malloc((m + mp_i)*sizeof (double)); - p_all_sort = (double *) malloc((m + mp_i)*sizeof (double)); - p_all_idx = (int *) malloc((m + mp_i)*sizeof (int)); - i_obs_plus_interp = (int *) malloc((m + mp_i)*sizeof (int)); - i_surf_and_obs_plus_interp = (int *) malloc((m + mp_i)*sizeof (int)); - p_obs_plus_interp = (double *) malloc((m + mp_i)*sizeof (double)); - p_surf_and_obs_plus_interp = (double *) malloc((m + mp_i)*sizeof (double)); - i_out = (int *) malloc((m + mp_i)*sizeof (int)); - i_1 = (int *) malloc((m + mp_i)*sizeof (int)); - i_2 = (int *) malloc((m + mp_i)*sizeof (int)); - i_3 = (int *) malloc((m + mp_i)*sizeof (int)); - - if (m < 4 && np == 1) + + if (m < 4) return; // There must be at least 4 bottles' - else if ((n == np && mp == 1) || (n == mp && np == 1)){ - for (j=0; j 1) || (mp_i == n && np_i != n)) { - interp_profile_length = np_i; - num_interp_profiles = mp_i; - for (j=0; j 0) { + gsw_util_sort_real(p_obs, prof_len, p_idx); + for (i=0; i 0) { - gsw_util_sort_real(p_obs, prof_len, p_idx); - for (i=0; i= min_p_obs && p_all[i] <= max_p_obs) { + i_obs_plus_interp[i_obs_plus_interp_len] = i; + p_obs_plus_interp[i_obs_plus_interp_len] = p_all[i]; + i_obs_plus_interp_len++; } - - i_obs_plus_interp_len = 0; - i_surf_and_obs_plus_interp_len = 0; - for (i=0; i= min_p_obs && p_all[i] <= max_p_obs) { - i_obs_plus_interp[i_obs_plus_interp_len] = i; - p_obs_plus_interp[i_obs_plus_interp_len] = p_all[i]; - i_obs_plus_interp_len++; - } - if (p_all[i] <= max_p_obs) { - i_surf_and_obs_plus_interp[i_surf_and_obs_plus_interp_len] = i; - p_surf_and_obs_plus_interp[i_surf_and_obs_plus_interp_len] = p_all[i]; - i_surf_and_obs_plus_interp_len++; - } + if (p_all[i] <= max_p_obs) { + i_surf_and_obs_plus_interp[i_surf_and_obs_plus_interp_len] = i; + p_surf_and_obs_plus_interp[i_surf_and_obs_plus_interp_len] = p_all[i]; + i_surf_and_obs_plus_interp_len++; } - i_out_len = gsw_util_intersect(p_i_tmp, interp_profile_length, p_surf_and_obs_plus_interp, i_surf_and_obs_plus_interp_len, i_out, i_1); - i_2_len = gsw_util_intersect(p_obs, prof_len, p_obs_plus_interp, i_obs_plus_interp_len, i_2, i_3); + } + i_out_len = gsw_util_intersect(p_i_tmp, m_i, p_surf_and_obs_plus_interp, i_surf_and_obs_plus_interp_len, i_out, i_1); + i_2_len = gsw_util_intersect(p_obs, prof_len, p_obs_plus_interp, i_obs_plus_interp_len, i_2, i_3); - independent_variable = (double *) malloc(prof_len*sizeof (double)); - independent_variable_obs_plus_interp = (double *) malloc(i_obs_plus_interp_len*sizeof (double)); + independent_variable = (double *) malloc(prof_len*sizeof (double)); + independent_variable_obs_plus_interp = (double *) malloc(i_obs_plus_interp_len*sizeof (double)); - for(i=0; i i_3[i_shallower]) { - i_below_i = i_3[i_shallower]; - } else { - i_below_i = i_3[i_above + 1]; - } - - for (i=i_above_i; i<=i_below_i; ++i) { - sa_i_obs_plus_interp[i] = sa_i_limiting_obs_plus_interp[i]; - ct_i_obs_plus_interp[i] = ct_i_limiting_obs_plus_interp[i]; - ctf_i_tointerp[i] = gsw_ct_freezing_poly(sa_i_obs_plus_interp[i], p_all[i], 0.); - } + if (i_frozen == i_obs_plus_interp_len) { + break; } - sa_i_tooutput = (double *)malloc(i_surf_and_obs_plus_interp_len*sizeof (double)); - ct_i_tooutput = (double *)malloc(i_surf_and_obs_plus_interp_len*sizeof (double)); - - if (min_p_obs != 0.) { - for (i=0; i i_3[i_shallower]) { + i_below_i = i_3[i_shallower]; } else { - for (i=0; i Date: Fri, 30 Aug 2024 11:43:08 -0700 Subject: [PATCH 05/27] Initialize interpolated SA and CT arrays with NaNs --- gsw_sa_ct_interp.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gsw_sa_ct_interp.c b/gsw_sa_ct_interp.c index bbbfe16..dbfc7eb 100644 --- a/gsw_sa_ct_interp.c +++ b/gsw_sa_ct_interp.c @@ -171,6 +171,11 @@ gsw_sa_ct_interp(double *sa, double *ct, double *p, int m, return; } } + + for (i=0; i Date: Fri, 30 Aug 2024 13:29:46 -0700 Subject: [PATCH 06/27] Move gsw_util_intersect to gsw_oceanographic_toolbox.c --- gsw_oceanographic_toolbox.c | 90 +++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/gsw_oceanographic_toolbox.c b/gsw_oceanographic_toolbox.c index 371bce2..e783077 100644 --- a/gsw_oceanographic_toolbox.c +++ b/gsw_oceanographic_toolbox.c @@ -11489,6 +11489,96 @@ gsw_z_from_p(double p, double lat, double geo_strf_dyn_height, return (-2.0*c/(b + sqrt(b*b - 4.0*a*c))); } +/* +!========================================================================== +subroutine gsw_util_intersect (x, nx, y, ny, ix, iy) +!========================================================================== +! +! Find unique values common to both x and y arrays. +! +! x : x array of values +! nx : length of x array +! y : y array of values +! ny : length of y array +! xi : indexes of x of values common to y +! yi : indexes of y of values common to x +! +! ni : length of ix and iy +! +*/ +int +gsw_util_intersect(double *x, int nx, double *y, int ny, int *ix, int *iy) +{ + int *sort_ix, *sort_iy, *unique_ix, *unique_iy; + int i, uix, uiy, nxs, nys, itx, ity, ni; + + double xx, yy; + + if (nx <= 0 || ny <= 0) { + return 0; + } + + sort_ix = malloc(nx * sizeof(int)); + sort_iy = malloc(ny * sizeof(int)); + unique_ix = malloc(nx * sizeof(int)); + unique_iy = malloc(ny * sizeof(int)); + + gsw_util_sort_real(x, nx, sort_ix); + gsw_util_sort_real(y, ny, sort_iy); + + nxs = 0; + uix = sort_ix[0]; + for (i=1; i yy) { + ++ity; + } else { + ix[ni] = unique_ix[itx]; + iy[ni] = unique_iy[ity]; + ++itx; + ++ity; + ++ni; + } + } + + free(sort_ix); + free(sort_iy); + free(unique_ix); + free(unique_iy); + + return ni; +} + /* ** The End **!========================================================================== From b16962367d16db2bca7c7c9e7ee5070d06dddb65 Mon Sep 17 00:00:00 2001 From: mauzey1 Date: Fri, 30 Aug 2024 13:40:41 -0700 Subject: [PATCH 07/27] Remove gsw_util_intersect from gsw_sa_ct_interp.c --- gsw_sa_ct_interp.c | 90 ---------------------------------------------- 1 file changed, 90 deletions(-) diff --git a/gsw_sa_ct_interp.c b/gsw_sa_ct_interp.c index dbfc7eb..7972ed3 100644 --- a/gsw_sa_ct_interp.c +++ b/gsw_sa_ct_interp.c @@ -1,96 +1,6 @@ #include "gswteos-10.h" #include "gsw_internal_const.h" -/* -!========================================================================== -subroutine gsw_util_intersect (x, nx, y, ny, ix, iy) -!========================================================================== -! -! Find unique values common to both x and y arrays. -! -! x : x array of values -! nx : length of x array -! y : y array of values -! ny : length of y array -! xi : indexes of x of values common to y -! yi : indexes of y of values common to x -! -! ni : length of ix and iy -! -*/ -int -gsw_util_intersect(double *x, int nx, double *y, int ny, int *ix, int *iy) -{ - int *sort_ix, *sort_iy, *unique_ix, *unique_iy; - int i, uix, uiy, nxs, nys, itx, ity, ni; - - double xx, yy; - - if (nx <= 0 || ny <= 0) { - return 0; - } - - sort_ix = malloc(nx * sizeof(int)); - sort_iy = malloc(ny * sizeof(int)); - unique_ix = malloc(nx * sizeof(int)); - unique_iy = malloc(ny * sizeof(int)); - - gsw_util_sort_real(x, nx, sort_ix); - gsw_util_sort_real(y, ny, sort_iy); - - nxs = 0; - uix = sort_ix[0]; - for (i=1; i yy) { - ++ity; - } else { - ix[ni] = unique_ix[itx]; - iy[ni] = unique_iy[ity]; - ++itx; - ++ity; - ++ni; - } - } - - free(sort_ix); - free(sort_iy); - free(unique_ix); - free(unique_iy); - - return ni; -} - /* !========================================================================== subroutine gsw_SA_CT_interp (sa,ct,p,p_i) From fe0cc28d5d9df44b49294208291aaad21ba2a4f0 Mon Sep 17 00:00:00 2001 From: mauzey1 Date: Fri, 30 Aug 2024 14:03:30 -0700 Subject: [PATCH 08/27] Add gsw_tracer_ct_interp --- gsw_tracer_ct_interp.c | 334 +++++++++++++++++++++++++++++++++++++++++ gswteos-10.h | 2 + 2 files changed, 336 insertions(+) create mode 100644 gsw_tracer_ct_interp.c diff --git a/gsw_tracer_ct_interp.c b/gsw_tracer_ct_interp.c new file mode 100644 index 0000000..3cf4350 --- /dev/null +++ b/gsw_tracer_ct_interp.c @@ -0,0 +1,334 @@ +#include "gswteos-10.h" +#include "gsw_internal_const.h" + +/* +!========================================================================== +subroutine gsw_tracer_CT_interp (sa,ct,p,p_i) +!========================================================================== +! +! SA and CT interpolation to p_i on a cast +! +! tracer = tracer [ ? ] +! CT = Conservative Temperature (ITS-90) [ deg C ] +! p = sea pressure [ dbar ] +! ( i.e. absolute pressure - 10.1325 dbar ) +! p_i = specific query points at which the interpolated tracer_i and CT_i +! are required [ dbar ] + +! +! tracer_i = interpolated SA values at pressures p_i [ g/kg ] +! CT_i = interpolated CT values at pressures p_i [ deg C ] +! +!-------------------------------------------------------------------------- +*/ +void +gsw_tracer_ct_interp(double *sa, double *ct, double *p, int m, + double *p_i, int m_i, double factor, double *tracer_i, double *ct_i) +{ + double rec_factor = 1./factor, + + sin_kpi_on_16[] = { + 1.950903220161283e-1, + 3.826834323650898e-1, + 5.555702330196022e-1, + 7.071067811865475e-1, + 8.314696123025452e-1, + 9.238795325112867e-1, + 9.807852804032304e-1 + }, + cos_kpi_on_16[] = { + 9.807852804032304e-1, + 9.238795325112867e-1, + 8.314696123025452e-1, + 7.071067811865476e-1, + 5.555702330196023e-1, + 3.826834323650898e-1, + 1.950903220161283e-1 + }; + + int i, j, k, prof_len, + not_monotonic, unique_count, new_len, p_all_len, + i_min_p_obs, i_obs_plus_interp_len, i_surf_and_obs_plus_interp_len, + i_out_len, i_2_len, i_frozen, i_shallower, i_above, i_above_i, i_below_i; + int *p_idx, *p_all_idx, *i_obs_plus_interp, *i_surf_and_obs_plus_interp, + *i_out, *i_1, *i_2, *i_3; + double d, ct_f, unique_p, ct_sum, tracer_sum, min_p_obs, max_p_obs; + double *tracer_obs, *ct_obs, *p_obs, *p_i_tmp, + *p_sort, *tracer_sort, *ct_sort, *p_all, *p_all_sort, + *p_obs_plus_interp, *p_surf_and_obs_plus_interp, + *independent_variable, *independent_variable_obs_plus_interp, + *scaled_tracer_obs, *v_tmp, *q_tmp, *v_i, *q_i, + *tracer_i_obs_plus_interp, *ct_i_obs_plus_interp, + *tracer_i_tooutput, *ct_i_tooutput; + + tracer_obs = (double *) malloc(m*sizeof (double)); + ct_obs = (double *) malloc(m*sizeof (double)); + p_obs = (double *) malloc(m*sizeof (double)); + p_idx = (int *) malloc(m*sizeof (int)); + p_sort = (double *) malloc(m*sizeof (double)); + tracer_sort = (double *) malloc(m*sizeof (double)); + ct_sort = (double *) malloc(m*sizeof (double)); + + if (m < 4) + return; // There must be at least 4 bottles' + + // Check if interpolating pressure is monotonic + for (i=0; i 0) { + gsw_util_sort_real(p_obs, prof_len, p_idx); + for (i=0; i= min_p_obs && p_all[i] <= max_p_obs) { + i_obs_plus_interp[i_obs_plus_interp_len] = i; + p_obs_plus_interp[i_obs_plus_interp_len] = p_all[i]; + i_obs_plus_interp_len++; + } + if (p_all[i] <= max_p_obs) { + i_surf_and_obs_plus_interp[i_surf_and_obs_plus_interp_len] = i; + p_surf_and_obs_plus_interp[i_surf_and_obs_plus_interp_len] = p_all[i]; + i_surf_and_obs_plus_interp_len++; + } + } + i_out_len = gsw_util_intersect(p_i_tmp, m_i, p_surf_and_obs_plus_interp, i_surf_and_obs_plus_interp_len, i_out, i_1); + i_2_len = gsw_util_intersect(p_obs, prof_len, p_obs_plus_interp, i_obs_plus_interp_len, i_2, i_3); + + independent_variable = (double *) malloc(prof_len*sizeof (double)); + independent_variable_obs_plus_interp = (double *) malloc(i_obs_plus_interp_len*sizeof (double)); + + for(i=0; i Date: Fri, 30 Aug 2024 14:06:53 -0700 Subject: [PATCH 09/27] gsw_tracer_ct_interp changes --- Makefile | 6 ++++-- gsw_tracer_ct_interp.c | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index f3b43f0..2a2a2fb 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,12 @@ Program = gsw_check PROGRAM_SOURCES = gsw_check_functions.c\ gsw_oceanographic_toolbox.c\ gsw_saar.c\ - gsw_sa_ct_interp.c + gsw_sa_ct_interp.c\ + gsw_tracer_ct_interp.c LIBRARY_SRCS = gsw_oceanographic_toolbox.c \ gsw_saar.c \ - gsw_sa_ct_interp.c + gsw_sa_ct_interp.c\ + gsw_tracer_ct_interp.c # \ !ifdef 0 # diff --git a/gsw_tracer_ct_interp.c b/gsw_tracer_ct_interp.c index 3cf4350..d230a88 100644 --- a/gsw_tracer_ct_interp.c +++ b/gsw_tracer_ct_interp.c @@ -3,26 +3,26 @@ /* !========================================================================== -subroutine gsw_tracer_CT_interp (sa,ct,p,p_i) +subroutine gsw_tracer_CT_interp (tracer,ct,p,p_i) !========================================================================== ! -! SA and CT interpolation to p_i on a cast +! Tracer and CT interpolation to p_i on a cast ! ! tracer = tracer [ ? ] ! CT = Conservative Temperature (ITS-90) [ deg C ] ! p = sea pressure [ dbar ] ! ( i.e. absolute pressure - 10.1325 dbar ) -! p_i = specific query points at which the interpolated tracer_i and CT_i -! are required [ dbar ] +! p_i = specific query points at which the interpolated tracer_i +! and CT_i are required [ dbar ] ! -! tracer_i = interpolated SA values at pressures p_i [ g/kg ] +! tracer_i = interpolated tracer values at pressures p_i [ g/kg ] ! CT_i = interpolated CT values at pressures p_i [ deg C ] ! !-------------------------------------------------------------------------- */ void -gsw_tracer_ct_interp(double *sa, double *ct, double *p, int m, +gsw_tracer_ct_interp(double *tracer, double *ct, double *p, int m, double *p_i, int m_i, double factor, double *tracer_i, double *ct_i) { double rec_factor = 1./factor, @@ -88,9 +88,9 @@ gsw_tracer_ct_interp(double *sa, double *ct, double *p, int m, // Find NaNs in profile prof_len = 0; for (i=0; i Date: Fri, 30 Aug 2024 14:11:56 -0700 Subject: [PATCH 10/27] Remove unused variables --- gsw_tracer_ct_interp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gsw_tracer_ct_interp.c b/gsw_tracer_ct_interp.c index d230a88..6cdb9b5 100644 --- a/gsw_tracer_ct_interp.c +++ b/gsw_tracer_ct_interp.c @@ -49,7 +49,7 @@ gsw_tracer_ct_interp(double *tracer, double *ct, double *p, int m, int i, j, k, prof_len, not_monotonic, unique_count, new_len, p_all_len, i_min_p_obs, i_obs_plus_interp_len, i_surf_and_obs_plus_interp_len, - i_out_len, i_2_len, i_frozen, i_shallower, i_above, i_above_i, i_below_i; + i_out_len, i_2_len; int *p_idx, *p_all_idx, *i_obs_plus_interp, *i_surf_and_obs_plus_interp, *i_out, *i_1, *i_2, *i_3; double d, ct_f, unique_p, ct_sum, tracer_sum, min_p_obs, max_p_obs; From 93dc45828fbdbfe3e30cc20ee00c716bde313a32 Mon Sep 17 00:00:00 2001 From: mauzey1 Date: Fri, 30 Aug 2024 18:04:57 -0700 Subject: [PATCH 11/27] Update comment for gsw_tracer_ct_interp with note on factor parameter --- gsw_tracer_ct_interp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gsw_tracer_ct_interp.c b/gsw_tracer_ct_interp.c index 6cdb9b5..2d9cd03 100644 --- a/gsw_tracer_ct_interp.c +++ b/gsw_tracer_ct_interp.c @@ -3,7 +3,7 @@ /* !========================================================================== -subroutine gsw_tracer_CT_interp (tracer,ct,p,p_i) +subroutine gsw_tracer_CT_interp (tracer,ct,p,p_i,factor) !========================================================================== ! ! Tracer and CT interpolation to p_i on a cast @@ -14,6 +14,8 @@ subroutine gsw_tracer_CT_interp (tracer,ct,p,p_i) ! ( i.e. absolute pressure - 10.1325 dbar ) ! p_i = specific query points at which the interpolated tracer_i ! and CT_i are required [ dbar ] +! factor = ratio between the ranges of Conservative Temperature +! and tracer in the world ocean. [ ? ] ! ! tracer_i = interpolated tracer values at pressures p_i [ g/kg ] From 33e18540392852d983b1860c5b4dfbf114155f3d Mon Sep 17 00:00:00 2001 From: mauzey1 Date: Fri, 6 Sep 2024 12:24:47 -0700 Subject: [PATCH 12/27] Fix finding of index --- gsw_sa_ct_interp.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gsw_sa_ct_interp.c b/gsw_sa_ct_interp.c index 7972ed3..14713d9 100644 --- a/gsw_sa_ct_interp.c +++ b/gsw_sa_ct_interp.c @@ -307,13 +307,15 @@ gsw_sa_ct_interp(double *sa, double *ct, double *p, int m, break; } - for (i=0; i < i_obs_plus_interp_len && (i_3[i] - i_frozen) <= 0; ++i) { - i_shallower = i; + for (i=0; i < i_2_len; ++i) { + if ((i_3[i] - i_frozen) <= 0) { + i_shallower = i; + } } i_above = i_2[i_shallower]; i_above_i = i_3[i_shallower]; - if ((i_above + 1) > i_3[i_shallower]) { - i_below_i = i_3[i_shallower]; + if ((i_above + 1) > i_3[i_2_len - 1]) { + i_below_i = i_3[i_2_len - 1]; } else { i_below_i = i_3[i_above + 1]; } From cd589c2e755fbc1d9f8f539d23280cbaba4000d0 Mon Sep 17 00:00:00 2001 From: mauzey1 Date: Fri, 6 Sep 2024 12:36:46 -0700 Subject: [PATCH 13/27] Clean up indentations and add newlines --- Makefile | 6 +++--- gsw_sa_ct_interp.c | 2 +- gsw_tracer_ct_interp.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 2a2a2fb..bd76dd0 100644 --- a/Makefile +++ b/Makefile @@ -4,12 +4,12 @@ Program = gsw_check PROGRAM_SOURCES = gsw_check_functions.c\ gsw_oceanographic_toolbox.c\ gsw_saar.c\ - gsw_sa_ct_interp.c\ - gsw_tracer_ct_interp.c + gsw_sa_ct_interp.c\ + gsw_tracer_ct_interp.c LIBRARY_SRCS = gsw_oceanographic_toolbox.c \ gsw_saar.c \ gsw_sa_ct_interp.c\ - gsw_tracer_ct_interp.c + gsw_tracer_ct_interp.c # \ !ifdef 0 # diff --git a/gsw_sa_ct_interp.c b/gsw_sa_ct_interp.c index 14713d9..dc94dd6 100644 --- a/gsw_sa_ct_interp.c +++ b/gsw_sa_ct_interp.c @@ -391,4 +391,4 @@ gsw_sa_ct_interp(double *sa, double *ct, double *p, int m, free(i_3); return; -} \ No newline at end of file +} diff --git a/gsw_tracer_ct_interp.c b/gsw_tracer_ct_interp.c index 2d9cd03..9e79b54 100644 --- a/gsw_tracer_ct_interp.c +++ b/gsw_tracer_ct_interp.c @@ -333,4 +333,4 @@ gsw_tracer_ct_interp(double *tracer, double *ct, double *p, int m, free(i_3); return; -} \ No newline at end of file +} From 5fdd25e4b227c144a0f53cec2284705cc15ad1e7 Mon Sep 17 00:00:00 2001 From: mauzey1 Date: Fri, 6 Sep 2024 14:29:36 -0700 Subject: [PATCH 14/27] Place gsw_tracer_ct_interp in alphabetical order in header file --- gswteos-10.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gswteos-10.h b/gswteos-10.h index d2c8155..fbfa16f 100644 --- a/gswteos-10.h +++ b/gswteos-10.h @@ -230,8 +230,6 @@ DECLSPEC extern void gsw_rr68_interp_sa_ct(double *sa, double *ct, double *p, DECLSPEC extern double gsw_saar(double p, double lon, double lat); DECLSPEC extern void gsw_sa_ct_interp(double *sa, double *ct, double *p, int m, double *p_i, int m_i, double *sa_i, double *ct_i); -DECLSPEC extern void gsw_tracer_ct_interp(double *sa, double *ct, double *p, - int m, double *p_i, int m_i, double factor, double *sa_i, double *ct_i); DECLSPEC extern double gsw_sa_freezing_estimate(double p, double saturation_fraction, double *ct, double *t); DECLSPEC extern double gsw_sa_freezing_from_ct(double ct, double p, @@ -301,6 +299,8 @@ DECLSPEC extern double gsw_t_freezing_poly(double sa, double p, DECLSPEC extern double gsw_t_from_ct(double sa, double ct, double p); DECLSPEC extern double gsw_t_from_pt0_ice(double pt0_ice, double p); DECLSPEC extern double gsw_thermobaric(double sa, double ct, double p); +DECLSPEC extern void gsw_tracer_ct_interp(double *sa, double *ct, double *p, + int m, double *p_i, int m_i, double factor, double *sa_i, double *ct_i); DECLSPEC extern void gsw_turner_rsubrho(double *sa, double *ct, double *p, int nz, double *tu, double *rsubrho, double *p_mid); DECLSPEC extern int gsw_util_indx(double *x, int n, double z); From 9c083e4482a59098de106c556847b37f782bc231 Mon Sep 17 00:00:00 2001 From: mauzey1 Date: Fri, 6 Sep 2024 14:35:13 -0700 Subject: [PATCH 15/27] Move gsw_tracer_ct_interp into main toolbox code --- gsw_oceanographic_toolbox.c | 333 +++++++++++++++++++++++++++++++++++ gsw_tracer_ct_interp.c | 336 ------------------------------------ 2 files changed, 333 insertions(+), 336 deletions(-) delete mode 100644 gsw_tracer_ct_interp.c diff --git a/gsw_oceanographic_toolbox.c b/gsw_oceanographic_toolbox.c index e783077..d479aec 100644 --- a/gsw_oceanographic_toolbox.c +++ b/gsw_oceanographic_toolbox.c @@ -10918,6 +10918,339 @@ gsw_thermobaric(double sa, double ct, double p) } /* !========================================================================== +subroutine gsw_tracer_CT_interp (tracer,ct,p,p_i,factor) +!========================================================================== +! +! Tracer and CT interpolation to p_i on a cast +! +! tracer = tracer [ ? ] +! CT = Conservative Temperature (ITS-90) [ deg C ] +! p = sea pressure [ dbar ] +! ( i.e. absolute pressure - 10.1325 dbar ) +! p_i = specific query points at which the interpolated tracer_i +! and CT_i are required [ dbar ] +! factor = ratio between the ranges of Conservative Temperature +! and tracer in the world ocean. [ ? ] + +! +! tracer_i = interpolated tracer values at pressures p_i [ g/kg ] +! CT_i = interpolated CT values at pressures p_i [ deg C ] +! +!-------------------------------------------------------------------------- +*/ +void +gsw_tracer_ct_interp(double *tracer, double *ct, double *p, int m, + double *p_i, int m_i, double factor, double *tracer_i, double *ct_i) +{ + double rec_factor = 1./factor, + + sin_kpi_on_16[] = { + 1.950903220161283e-1, + 3.826834323650898e-1, + 5.555702330196022e-1, + 7.071067811865475e-1, + 8.314696123025452e-1, + 9.238795325112867e-1, + 9.807852804032304e-1 + }, + cos_kpi_on_16[] = { + 9.807852804032304e-1, + 9.238795325112867e-1, + 8.314696123025452e-1, + 7.071067811865476e-1, + 5.555702330196023e-1, + 3.826834323650898e-1, + 1.950903220161283e-1 + }; + + int i, j, k, prof_len, + not_monotonic, unique_count, new_len, p_all_len, + i_min_p_obs, i_obs_plus_interp_len, i_surf_and_obs_plus_interp_len, + i_out_len, i_2_len; + int *p_idx, *p_all_idx, *i_obs_plus_interp, *i_surf_and_obs_plus_interp, + *i_out, *i_1, *i_2, *i_3; + double d, ct_f, unique_p, ct_sum, tracer_sum, min_p_obs, max_p_obs; + double *tracer_obs, *ct_obs, *p_obs, *p_i_tmp, + *p_sort, *tracer_sort, *ct_sort, *p_all, *p_all_sort, + *p_obs_plus_interp, *p_surf_and_obs_plus_interp, + *independent_variable, *independent_variable_obs_plus_interp, + *scaled_tracer_obs, *v_tmp, *q_tmp, *v_i, *q_i, + *tracer_i_obs_plus_interp, *ct_i_obs_plus_interp, + *tracer_i_tooutput, *ct_i_tooutput; + + tracer_obs = (double *) malloc(m*sizeof (double)); + ct_obs = (double *) malloc(m*sizeof (double)); + p_obs = (double *) malloc(m*sizeof (double)); + p_idx = (int *) malloc(m*sizeof (int)); + p_sort = (double *) malloc(m*sizeof (double)); + tracer_sort = (double *) malloc(m*sizeof (double)); + ct_sort = (double *) malloc(m*sizeof (double)); + + if (m < 4) + return; // There must be at least 4 bottles' + + // Check if interpolating pressure is monotonic + for (i=0; i 0) { + gsw_util_sort_real(p_obs, prof_len, p_idx); + for (i=0; i= min_p_obs && p_all[i] <= max_p_obs) { + i_obs_plus_interp[i_obs_plus_interp_len] = i; + p_obs_plus_interp[i_obs_plus_interp_len] = p_all[i]; + i_obs_plus_interp_len++; + } + if (p_all[i] <= max_p_obs) { + i_surf_and_obs_plus_interp[i_surf_and_obs_plus_interp_len] = i; + p_surf_and_obs_plus_interp[i_surf_and_obs_plus_interp_len] = p_all[i]; + i_surf_and_obs_plus_interp_len++; + } + } + i_out_len = gsw_util_intersect(p_i_tmp, m_i, p_surf_and_obs_plus_interp, i_surf_and_obs_plus_interp_len, i_out, i_1); + i_2_len = gsw_util_intersect(p_obs, prof_len, p_obs_plus_interp, i_obs_plus_interp_len, i_2, i_3); + + independent_variable = (double *) malloc(prof_len*sizeof (double)); + independent_variable_obs_plus_interp = (double *) malloc(i_obs_plus_interp_len*sizeof (double)); + + for(i=0; i 0) { - gsw_util_sort_real(p_obs, prof_len, p_idx); - for (i=0; i= min_p_obs && p_all[i] <= max_p_obs) { - i_obs_plus_interp[i_obs_plus_interp_len] = i; - p_obs_plus_interp[i_obs_plus_interp_len] = p_all[i]; - i_obs_plus_interp_len++; - } - if (p_all[i] <= max_p_obs) { - i_surf_and_obs_plus_interp[i_surf_and_obs_plus_interp_len] = i; - p_surf_and_obs_plus_interp[i_surf_and_obs_plus_interp_len] = p_all[i]; - i_surf_and_obs_plus_interp_len++; - } - } - i_out_len = gsw_util_intersect(p_i_tmp, m_i, p_surf_and_obs_plus_interp, i_surf_and_obs_plus_interp_len, i_out, i_1); - i_2_len = gsw_util_intersect(p_obs, prof_len, p_obs_plus_interp, i_obs_plus_interp_len, i_2, i_3); - - independent_variable = (double *) malloc(prof_len*sizeof (double)); - independent_variable_obs_plus_interp = (double *) malloc(i_obs_plus_interp_len*sizeof (double)); - - for(i=0; i Date: Fri, 6 Sep 2024 14:38:38 -0700 Subject: [PATCH 16/27] Move gsw_sa_ct_interp into main toolbox code --- Makefile | 8 +- gsw_oceanographic_toolbox.c | 391 +++++++++++++++++++++++++++++++++++ gsw_sa_ct_interp.c | 394 ------------------------------------ 3 files changed, 393 insertions(+), 400 deletions(-) delete mode 100644 gsw_sa_ct_interp.c diff --git a/Makefile b/Makefile index bd76dd0..d6740a6 100644 --- a/Makefile +++ b/Makefile @@ -3,13 +3,9 @@ Program = gsw_check PROGRAM_SOURCES = gsw_check_functions.c\ gsw_oceanographic_toolbox.c\ - gsw_saar.c\ - gsw_sa_ct_interp.c\ - gsw_tracer_ct_interp.c + gsw_saar.c LIBRARY_SRCS = gsw_oceanographic_toolbox.c \ - gsw_saar.c \ - gsw_sa_ct_interp.c\ - gsw_tracer_ct_interp.c + gsw_saar.c # \ !ifdef 0 # diff --git a/gsw_oceanographic_toolbox.c b/gsw_oceanographic_toolbox.c index d479aec..829306e 100644 --- a/gsw_oceanographic_toolbox.c +++ b/gsw_oceanographic_toolbox.c @@ -8589,6 +8589,397 @@ rr68_interp_section(int sectnum, double *sa, double *ct, double *p, int mp, } /* !========================================================================== +subroutine gsw_SA_CT_interp (sa,ct,p,p_i) +!========================================================================== +! +! SA and CT interpolation to p_i on a cast +! +! SA = Absolute Salinity [ g/kg ] +! CT = Conservative Temperature (ITS-90) [ deg C ] +! p = sea pressure [ dbar ] +! ( i.e. absolute pressure - 10.1325 dbar ) +! p_i = specific query points at which the interpolated SA_i and CT_i +! are required [ dbar ] + +! +! SA_i = interpolated SA values at pressures p_i [ g/kg ] +! CT_i = interpolated CT values at pressures p_i [ deg C ] +! +!-------------------------------------------------------------------------- +*/ +void +gsw_sa_ct_interp(double *sa, double *ct, double *p, int m, + double *p_i, int m_i, double *sa_i, double *ct_i) +{ + double factor = 9., + rec_factor = 1./factor, + + sin_kpi_on_16[] = { + 1.950903220161283e-1, + 3.826834323650898e-1, + 5.555702330196022e-1, + 7.071067811865475e-1, + 8.314696123025452e-1, + 9.238795325112867e-1, + 9.807852804032304e-1 + }, + cos_kpi_on_16[] = { + 9.807852804032304e-1, + 9.238795325112867e-1, + 8.314696123025452e-1, + 7.071067811865476e-1, + 5.555702330196023e-1, + 3.826834323650898e-1, + 1.950903220161283e-1 + }; + + int i, j, k, prof_len, + not_monotonic, unique_count, new_len, p_all_len, + i_min_p_obs, i_obs_plus_interp_len, i_surf_and_obs_plus_interp_len, + i_out_len, i_2_len, i_frozen, i_shallower, i_above, i_above_i, i_below_i; + int *p_idx, *p_all_idx, *i_obs_plus_interp, *i_surf_and_obs_plus_interp, + *i_out, *i_1, *i_2, *i_3; + double d, ct_f, unique_p, ct_sum, sa_sum, min_p_obs, max_p_obs; + double *sa_obs, *ct_obs, *p_obs, *p_i_tmp, + *p_sort, *sa_sort, *ct_sort, *p_all, *p_all_sort, + *p_obs_plus_interp, *p_surf_and_obs_plus_interp, + *independent_variable, *independent_variable_obs_plus_interp, + *scaled_sa_obs, *v_tmp, *q_tmp, *v_i, *q_i, + *sa_i_obs_plus_interp, *ct_i_obs_plus_interp, + *sa_i_limiting_obs_plus_interp, *ct_i_limiting_obs_plus_interp, + *ctf_i_tointerp, *sa_i_tooutput, *ct_i_tooutput; + + sa_obs = (double *) malloc(m*sizeof (double)); + ct_obs = (double *) malloc(m*sizeof (double)); + p_obs = (double *) malloc(m*sizeof (double)); + p_idx = (int *) malloc(m*sizeof (int)); + p_sort = (double *) malloc(m*sizeof (double)); + sa_sort = (double *) malloc(m*sizeof (double)); + ct_sort = (double *) malloc(m*sizeof (double)); + + if (m < 4) + return; // There must be at least 4 bottles' + + // Check if interpolating pressure is monotonic + for (i=0; i 0) { + gsw_util_sort_real(p_obs, prof_len, p_idx); + for (i=0; i= min_p_obs && p_all[i] <= max_p_obs) { + i_obs_plus_interp[i_obs_plus_interp_len] = i; + p_obs_plus_interp[i_obs_plus_interp_len] = p_all[i]; + i_obs_plus_interp_len++; + } + if (p_all[i] <= max_p_obs) { + i_surf_and_obs_plus_interp[i_surf_and_obs_plus_interp_len] = i; + p_surf_and_obs_plus_interp[i_surf_and_obs_plus_interp_len] = p_all[i]; + i_surf_and_obs_plus_interp_len++; + } + } + i_out_len = gsw_util_intersect(p_i_tmp, m_i, p_surf_and_obs_plus_interp, i_surf_and_obs_plus_interp_len, i_out, i_1); + i_2_len = gsw_util_intersect(p_obs, prof_len, p_obs_plus_interp, i_obs_plus_interp_len, i_2, i_3); + + independent_variable = (double *) malloc(prof_len*sizeof (double)); + independent_variable_obs_plus_interp = (double *) malloc(i_obs_plus_interp_len*sizeof (double)); + + for(i=0; i i_3[i_2_len - 1]) { + i_below_i = i_3[i_2_len - 1]; + } else { + i_below_i = i_3[i_above + 1]; + } + + for (i=i_above_i; i<=i_below_i; ++i) { + sa_i_obs_plus_interp[i] = sa_i_limiting_obs_plus_interp[i]; + ct_i_obs_plus_interp[i] = ct_i_limiting_obs_plus_interp[i]; + ctf_i_tointerp[i] = gsw_ct_freezing_poly(sa_i_obs_plus_interp[i], p_all[i], 0.); + } + } + + sa_i_tooutput = (double *)malloc(i_surf_and_obs_plus_interp_len*sizeof (double)); + ct_i_tooutput = (double *)malloc(i_surf_and_obs_plus_interp_len*sizeof (double)); + + if (min_p_obs != 0.) { + for (i=0; i 0) { - gsw_util_sort_real(p_obs, prof_len, p_idx); - for (i=0; i= min_p_obs && p_all[i] <= max_p_obs) { - i_obs_plus_interp[i_obs_plus_interp_len] = i; - p_obs_plus_interp[i_obs_plus_interp_len] = p_all[i]; - i_obs_plus_interp_len++; - } - if (p_all[i] <= max_p_obs) { - i_surf_and_obs_plus_interp[i_surf_and_obs_plus_interp_len] = i; - p_surf_and_obs_plus_interp[i_surf_and_obs_plus_interp_len] = p_all[i]; - i_surf_and_obs_plus_interp_len++; - } - } - i_out_len = gsw_util_intersect(p_i_tmp, m_i, p_surf_and_obs_plus_interp, i_surf_and_obs_plus_interp_len, i_out, i_1); - i_2_len = gsw_util_intersect(p_obs, prof_len, p_obs_plus_interp, i_obs_plus_interp_len, i_2, i_3); - - independent_variable = (double *) malloc(prof_len*sizeof (double)); - independent_variable_obs_plus_interp = (double *) malloc(i_obs_plus_interp_len*sizeof (double)); - - for(i=0; i i_3[i_2_len - 1]) { - i_below_i = i_3[i_2_len - 1]; - } else { - i_below_i = i_3[i_above + 1]; - } - - for (i=i_above_i; i<=i_below_i; ++i) { - sa_i_obs_plus_interp[i] = sa_i_limiting_obs_plus_interp[i]; - ct_i_obs_plus_interp[i] = ct_i_limiting_obs_plus_interp[i]; - ctf_i_tointerp[i] = gsw_ct_freezing_poly(sa_i_obs_plus_interp[i], p_all[i], 0.); - } - } - - sa_i_tooutput = (double *)malloc(i_surf_and_obs_plus_interp_len*sizeof (double)); - ct_i_tooutput = (double *)malloc(i_surf_and_obs_plus_interp_len*sizeof (double)); - - if (min_p_obs != 0.) { - for (i=0; i Date: Fri, 6 Sep 2024 17:45:22 -0700 Subject: [PATCH 17/27] Make SA-CT interp functions return error code --- gsw_oceanographic_toolbox.c | 20 ++++++++++---------- gswteos-10.h | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gsw_oceanographic_toolbox.c b/gsw_oceanographic_toolbox.c index 829306e..45590c4 100644 --- a/gsw_oceanographic_toolbox.c +++ b/gsw_oceanographic_toolbox.c @@ -8607,7 +8607,7 @@ subroutine gsw_SA_CT_interp (sa,ct,p,p_i) ! !-------------------------------------------------------------------------- */ -void +int gsw_sa_ct_interp(double *sa, double *ct, double *p, int m, double *p_i, int m_i, double *sa_i, double *ct_i) { @@ -8658,13 +8658,13 @@ gsw_sa_ct_interp(double *sa, double *ct, double *p, int m, ct_sort = (double *) malloc(m*sizeof (double)); if (m < 4) - return; // There must be at least 4 bottles' + return 1; // There must be at least 4 bottles' // Check if interpolating pressure is monotonic for (i=0; i Date: Thu, 12 Sep 2024 12:45:03 -0700 Subject: [PATCH 18/27] Update check data with interpolation test values --- gsw_check_data.h | 205 +++++++++++++++++++++++++++++++++++++++++- gsw_check_data.nc | Bin 268800 -> 274652 bytes gsw_data_ncdump.txt | 11 +++ make_data_from_mat.py | 8 ++ 4 files changed, 223 insertions(+), 1 deletion(-) diff --git a/gsw_check_data.h b/gsw_check_data.h index 8a288c7..07b6b81 100644 --- a/gsw_check_data.h +++ b/gsw_check_data.h @@ -5,7 +5,7 @@ ** version_date: 15th_May_2011 ** version_number: 3.06.16 ** mat_zip_version: 3_06_16 -** This file created on: 2024-02-12 11:26:21.045021 +** This file created on: 2024-09-12 12:38:26.783150 */ /* @@ -24,6 +24,8 @@ #define cast_ice_n 3 #define cast_mpres_m 44 #define cast_mpres_n 3 +#define interp_m 51 +#define interp_n 3 static UNUSED double ct[135] = { 27.996436412058213, 27.993857176639086, 27.944017615967979, 27.948372399994319, @@ -296,6 +298,13 @@ static UNUSED double p[135] = { 8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90 }; +static UNUSED double p_i[51] = { +0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, +1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, +2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, +4100, 4200, 4300, 4400, 4500, 4600, 4700, 4800, 4900, 5000 +}; + static UNUSED double delta_p[135] = { 0, 10, 10, 10, 10, 10, 26, 25, 25, 25, 25, 26, 50, 51, 50, 51, 101, 101, 101, 101, 101, 101, 101, 102, 101, 102, 101, 254, 254, 254, 255, 255, 256, 255, 256, @@ -7933,6 +7942,200 @@ static UNUSED double rsubrho[132] = { #define rsubrho_ca 1.690921180852456e-08 +static UNUSED double sai_sactinterp[153] = { +34.468236430490606, 34.981684011594275, 34.845532135029757, 34.594880552563986, +34.646910055942165, 34.658726028373025, 34.667610684451823, 34.681241443337626, +34.693152815925814, 34.704242814066355, 34.715310018759446, 34.727191420710305, +34.737970181514079, 34.749908756622247, 34.75865652413632, 34.767977853907084, +34.776667058040957, 34.784334257348284, 34.79178015056219, 34.799429517990411, +34.806552614204548, 34.812691689382405, 34.818169026804789, 34.822997593767191, +34.827267561289105, 34.83107566345695, 34.834475961281619, 34.837525533487018, +34.840341326091348, 34.843005908156698, 34.845452404272699, 34.847569222979239, +34.849391445147802, 34.851249802860892, 34.853492505612103, 34.855706803475442, +34.857247772994597, 34.858497276933569, 34.859092057229148, 34.858381605762077, +34.856823030966915, 34.855679183654935, 34.854739459543588, 34.854308742400669, +34.855299304684273, 34.857513577115284, 34.85900682590129, 34.859483671997552, +34.859866852752297, 34.860716166459341, 34.862075375111715, 34.556977983037378, +35.143552028278961, 34.743955515099316, 34.823482547808247, 34.804942319288521, +34.760842876649718, 34.73197711758587, 34.714860568930348, 34.713553992644862, +34.718238136890584, 34.723558346430032, 34.732932331364822, 34.741835167338756, +34.751656516251295, 34.760987253055077, 34.770634831831927, 34.779831462444207, +34.787896487807899, 34.795973697286236, 34.804846003583471, 34.812671598162424, +34.817995350850836, 34.822145849128248, 34.826452359442619, 34.831415297815248, +34.836065183487634, 34.839513990464418, 34.842264529794129, 34.845044087445629, +34.848173560330608, 34.851227079351254, 34.853788960522365, 34.856002592079761, +34.858008149143096, 34.859816041891456, 34.861511533268335, 34.863314423422317, +34.865265218099864, 34.86708175309419, 34.868590932972623, 34.869910820929661, +34.871133587707021, 34.872546396459661, 34.873351690456062, 34.872775691608311, +34.871547239164059, 34.870721688384769, 34.870383374148055, 34.870265396867914, +34.870338679141682, 34.870546744141642, 6.6699043409245728, 10.346695553446363, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90 +}; + +#define sai_sactinterp_ca 1.3001510978938313e-10 + +static UNUSED double cti_sactinterp[153] = { +27.996436412058227, 25.533144569030263, 16.019861520340768, 10.341891502382861, +8.4456966374532545, 7.2721994214211767, 6.5074004434211012, 5.8840829086292556, +5.3600631828344829, 4.8832999981632534, 4.4343297157729946, 4.0194186111174233, +3.6464959786663744, 3.3302175416713258, 3.0360389453491519, 2.7908185312784872, +2.5904631148025259, 2.423166010494068, 2.2715684781542738, 2.1281996714820086, +2.0038859800808941, 1.9057066559935123, 1.8235890129026773, 1.7482666532235847, +1.6762447258413102, 1.6115589460702915, 1.5572356514838051, 1.5101427761616257, +1.4678690688374059, 1.4291052039518444, 1.3940324397786752, 1.3631384058258678, +1.3360645039300703, 1.3092326083968704, 1.2796554533485569, 1.2504454968981085, +1.2262396689330433, 1.2054680503482365, 1.187164480536496, 1.1684829755830797, +1.1477518433658003, 1.1286972420975527, 1.1093760918020004, 1.0943939612593574, +1.0873483431052355, 1.0817477224915897, 1.0745478755635225, 1.0634152009122975, +1.0515515736003886, 1.0426620383447947, 1.0351918856149576, 27.322890736362599, +22.011254836061603, 11.560227514375722, 9.8757443413275237, 9.0022892545844027, +8.05506023421108, 7.1412969334874559, 6.2985045169753038, 5.6689611002002005, +5.1619651842686372, 4.6499362388415042, 4.3058993935480157, 3.9759763533444907, +3.6420020781766036, 3.3196655649536524, 2.9994634344611657, 2.7820843247989426, +2.6147405296234192, 2.4435788959532885, 2.2471193199195505, 2.0822572605932823, +1.9899103600091417, 1.9259139687763396, 1.8589909978970756, 1.7804728271451022, +1.705937917028272, 1.6475130925660368, 1.5987301233149647, 1.5517208830746407, +1.5039888179174263, 1.4579677965960154, 1.4151089811281323, 1.3749691776165345, +1.3359607264588433, 1.2978547591325253, 1.2603848521798859, 1.2218814621548661, +1.1820088935554813, 1.1431502947536156, 1.1066031829996259, 1.0714954834787538, +1.0377190422510292, 1.0030329830608418, 0.97360861725787962, +0.9534590677768886, 0.93592175165578984, 0.92023524972450943, +0.90565719701788883, 0.8921688460133359, 0.8795567615391916, +0.86702210345731012, 10.502767735302228, 4.5888811896604285, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90 +}; + +#define cti_sactinterp_ca 6.2611249518340628e-10 + +static UNUSED double traceri_tracerctinterp[153] = { +34.468236430490606, 34.981684011594275, 34.845532135029757, 34.594880552563986, +34.646910055942165, 34.658726028373025, 34.667610684451823, 34.681241443337626, +34.693152815925814, 34.704242814066355, 34.715310018759446, 34.727191420710305, +34.737970181514079, 34.749908756622247, 34.75865652413632, 34.767977853907084, +34.776667058040957, 34.784334257348284, 34.79178015056219, 34.799429517990411, +34.806552614204548, 34.812691689382405, 34.818169026804789, 34.822997593767191, +34.827267561289105, 34.83107566345695, 34.834475961281619, 34.837525533487018, +34.840341326091348, 34.843005908156698, 34.845452404272699, 34.847569222979239, +34.849391445147802, 34.851249802860892, 34.853492505612103, 34.855706803475442, +34.857247772994597, 34.858497276933569, 34.859092057229148, 34.858381605762077, +34.856823030966915, 34.855679183654935, 34.854739459543588, 34.854308742400669, +34.855299304684273, 34.857513577115284, 34.85900682590129, 34.859483671997552, +34.859866852752297, 34.860716166459341, 34.862075375111715, 34.556977983037378, +35.143552028278961, 34.743955515099316, 34.823482547808247, 34.804942319288521, +34.760842876649718, 34.73197711758587, 34.714860568930348, 34.713553992644862, +34.718238136890584, 34.723558346430032, 34.732932331364822, 34.741835167338756, +34.751656516251295, 34.760987253055077, 34.770634831831927, 34.779831462444207, +34.787896487807899, 34.795973697286236, 34.804846003583471, 34.812671598162424, +34.817995350850836, 34.822145849128248, 34.826452359442619, 34.831415297815248, +34.836065183487634, 34.839513990464418, 34.842264529794129, 34.845044087445629, +34.848173560330608, 34.851227079351254, 34.853788960522365, 34.856002592079761, +34.858008149143096, 34.859816041891456, 34.861511533268335, 34.863314423422317, +34.865265218099864, 34.86708175309419, 34.868590932972623, 34.869910820929661, +34.871133587707021, 34.872546396459661, 34.873351690456062, 34.872775691608311, +34.871547239164059, 34.870721688384769, 34.870383374148055, 34.870265396867914, +34.870338679141682, 34.870546744141642, 6.6699043409245728, 10.346695553446363, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90 +}; + +#define traceri_tracerctinterp_ca 1.3001510978938313e-10 + +static UNUSED double cti_tracerctinterp[153] = { +27.996436412058227, 25.533144569030263, 16.019861520340768, 10.341891502382861, +8.4456966374532545, 7.2721994214211767, 6.5074004434211012, 5.8840829086292556, +5.3600631828344829, 4.8832999981632534, 4.4343297157729946, 4.0194186111174233, +3.6464959786663744, 3.3302175416713258, 3.0360389453491519, 2.7908185312784872, +2.5904631148025259, 2.423166010494068, 2.2715684781542738, 2.1281996714820086, +2.0038859800808941, 1.9057066559935123, 1.8235890129026773, 1.7482666532235847, +1.6762447258413102, 1.6115589460702915, 1.5572356514838051, 1.5101427761616257, +1.4678690688374059, 1.4291052039518444, 1.3940324397786752, 1.3631384058258678, +1.3360645039300703, 1.3092326083968704, 1.2796554533485569, 1.2504454968981085, +1.2262396689330433, 1.2054680503482365, 1.187164480536496, 1.1684829755830797, +1.1477518433658003, 1.1286972420975527, 1.1093760918020004, 1.0943939612593574, +1.0873483431052355, 1.0817477224915897, 1.0745478755635225, 1.0634152009122975, +1.0515515736003886, 1.0426620383447947, 1.0351918856149576, 27.322890736362599, +22.011254836061603, 11.560227514375722, 9.8757443413275237, 9.0022892545844027, +8.05506023421108, 7.1412969334874559, 6.2985045169753038, 5.6689611002002005, +5.1619651842686372, 4.6499362388415042, 4.3058993935480157, 3.9759763533444907, +3.6420020781766036, 3.3196655649536524, 2.9994634344611657, 2.7820843247989426, +2.6147405296234192, 2.4435788959532885, 2.2471193199195505, 2.0822572605932823, +1.9899103600091417, 1.9259139687763396, 1.8589909978970756, 1.7804728271451022, +1.705937917028272, 1.6475130925660368, 1.5987301233149647, 1.5517208830746407, +1.5039888179174263, 1.4579677965960154, 1.4151089811281323, 1.3749691776165345, +1.3359607264588433, 1.2978547591325253, 1.2603848521798859, 1.2218814621548661, +1.1820088935554813, 1.1431502947536156, 1.1066031829996259, 1.0714954834787538, +1.0377190422510292, 1.0030329830608418, 0.97360861725787962, +0.9534590677768886, 0.93592175165578984, 0.92023524972450943, +0.90565719701788883, 0.8921688460133359, 0.8795567615391916, +0.86702210345731012, 10.502767735302228, 4.5888811896604285, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90, 8.9999999999999998e+90, 8.9999999999999998e+90, +8.9999999999999998e+90 +}; + +#define cti_tracerctinterp_ca 6.2611249518340628e-10 + static UNUSED double p_mid_tursr[132] = { 5, 15, 25, 35, 45, 63, 88.5, 113.5, 138.5, 163.5, 189, 227, 277.5, 328, 378.5, 454.5, 555.5, 656.5, 757.5, 858.5, 959.5, 1060.5, 1162, 1263.5, 1365, 1466.5, diff --git a/gsw_check_data.nc b/gsw_check_data.nc index 75b54eb47fc5992d7a669402296c3f88605e51f8..e019372aaad1bd94d7e9f8537e21c71b9a996e6a 100644 GIT binary patch delta 8478 zcmeHLZCq64wwE=-yz%}j?+&mTU^8xEzzGrAdlV5A5djsH4xmGVj!HP1c1Tds)I5qT z&dG|Baw@CQFsanY=;SG1$SBE^MTt43*_fzkl&E*@8Bh0~d+&#PK6O7Fen0r{|61!= z&-1MHJZtSuLx*?Yd2jDYnOQC)oIff8xBcFsE@OSomCMa#)l1ElwKZj?%B2gGa$KsmV!W6LG%Fvo5{Oz`=udOeC1k zU^&4Z05apyI+#-#a+r;NW1J0Gk!Jjg*L&`#v1^WqF zr0DL-!IMTzcV*>IA0RbCy0ECaQGMXGf!o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G@X|&OBy>0RgWjh}% zo{g3C;|W+BBlP2oNN+UgXFl9z`dI)C4;pkiiTHyN@dY-jj&rTxw2=ixSxco>fIp#sx(nSuw%4}In zQk>RU~LUAQwesvoX%{Q@Lhw6EtS~QS1Gx~%4-?yGz*1^BRi)N*ZMSf zP74po8;t$p+if9#R7#HQ1qV>KRi_0>^ljB>(M6=T8nkE%ldLS7J$GyC@zQgLk9 Date: Fri, 13 Sep 2024 12:28:56 -0700 Subject: [PATCH 19/27] Make sure memory is freed after returning from an error --- gsw_oceanographic_toolbox.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gsw_oceanographic_toolbox.c b/gsw_oceanographic_toolbox.c index 45590c4..ce81871 100644 --- a/gsw_oceanographic_toolbox.c +++ b/gsw_oceanographic_toolbox.c @@ -8649,14 +8649,6 @@ gsw_sa_ct_interp(double *sa, double *ct, double *p, int m, *sa_i_limiting_obs_plus_interp, *ct_i_limiting_obs_plus_interp, *ctf_i_tointerp, *sa_i_tooutput, *ct_i_tooutput; - sa_obs = (double *) malloc(m*sizeof (double)); - ct_obs = (double *) malloc(m*sizeof (double)); - p_obs = (double *) malloc(m*sizeof (double)); - p_idx = (int *) malloc(m*sizeof (int)); - p_sort = (double *) malloc(m*sizeof (double)); - sa_sort = (double *) malloc(m*sizeof (double)); - ct_sort = (double *) malloc(m*sizeof (double)); - if (m < 4) return 1; // There must be at least 4 bottles' @@ -8672,7 +8664,11 @@ gsw_sa_ct_interp(double *sa, double *ct, double *p, int m, sa_i[i] = NAN; ct_i[i] = NAN; } - + + sa_obs = (double *) malloc(m*sizeof (double)); + ct_obs = (double *) malloc(m*sizeof (double)); + p_obs = (double *) malloc(m*sizeof (double)); + // Find NaNs in profile prof_len = 0; for (i=0; i 0) { gsw_util_sort_real(p_obs, prof_len, p_idx); for (i=0; i Date: Fri, 13 Sep 2024 12:40:53 -0700 Subject: [PATCH 20/27] Allocate arrays after NaN check --- gsw_oceanographic_toolbox.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/gsw_oceanographic_toolbox.c b/gsw_oceanographic_toolbox.c index ce81871..c0d355a 100644 --- a/gsw_oceanographic_toolbox.c +++ b/gsw_oceanographic_toolbox.c @@ -8665,11 +8665,23 @@ gsw_sa_ct_interp(double *sa, double *ct, double *p, int m, ct_i[i] = NAN; } - sa_obs = (double *) malloc(m*sizeof (double)); - ct_obs = (double *) malloc(m*sizeof (double)); - p_obs = (double *) malloc(m*sizeof (double)); - // Find NaNs in profile + prof_len = 0; + for (i=0; i Date: Mon, 23 Sep 2024 11:27:48 -0700 Subject: [PATCH 21/27] Apply the same memory allocation change from gsw_sa_ct_interp to gsw_tracer_ct_interp --- gsw_oceanographic_toolbox.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/gsw_oceanographic_toolbox.c b/gsw_oceanographic_toolbox.c index c0d355a..3f51c75 100644 --- a/gsw_oceanographic_toolbox.c +++ b/gsw_oceanographic_toolbox.c @@ -11378,14 +11378,6 @@ gsw_tracer_ct_interp(double *tracer, double *ct, double *p, int m, *tracer_i_obs_plus_interp, *ct_i_obs_plus_interp, *tracer_i_tooutput, *ct_i_tooutput; - tracer_obs = (double *) malloc(m*sizeof (double)); - ct_obs = (double *) malloc(m*sizeof (double)); - p_obs = (double *) malloc(m*sizeof (double)); - p_idx = (int *) malloc(m*sizeof (int)); - p_sort = (double *) malloc(m*sizeof (double)); - tracer_sort = (double *) malloc(m*sizeof (double)); - ct_sort = (double *) malloc(m*sizeof (double)); - if (m < 4) return 1; // There must be at least 4 bottles' @@ -11403,6 +11395,22 @@ gsw_tracer_ct_interp(double *tracer, double *ct, double *p, int m, } // Find NaNs in profile + prof_len = 0; + for (i=0; i 0) { gsw_util_sort_real(p_obs, prof_len, p_idx); for (i=0; i Date: Mon, 23 Sep 2024 13:31:31 -0700 Subject: [PATCH 22/27] Add tests for vertical interpolation functions --- gsw_check_functions.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/gsw_check_functions.c b/gsw_check_functions.c index a396a4e..06fc48c 100644 --- a/gsw_check_functions.c +++ b/gsw_check_functions.c @@ -130,7 +130,8 @@ main(int argc, char **argv) int count = cast_m*cast_n, i, j, k, l, n; double saturation_fraction, value[cast_m*cast_n], lat[cast_m*cast_n], lon[cast_m*cast_n], val1[cast_m*cast_n], val2[cast_m*cast_n], val3[cast_m*cast_n], - val4[cast_m*cast_n], val5[cast_m*cast_n]; + val4[cast_m*cast_n], val5[cast_m*cast_n], val6[interp_m*interp_n], + val7[interp_m*interp_n]; if (argc==2 && !strcmp(argv[1],"-debug")) debug = 1; @@ -583,6 +584,38 @@ 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); + section_title("Vertical Interpolation"); + + for (j = 0; j= GSW_ERROR_LIMIT) + break; + if (gsw_sa_ct_interp(&sa[k],&ct[k],&p[k],n, + p_i,interp_m,&val6[l],&val7[l]) == 1) + printf("gsw_sa_ct_interp returned error.\n"); + } + check_accuracy("gsw_sa_ct_interp",sai_sactinterp_ca, + "sai_sactinterp",interp_n*interp_m, val6, sai_sactinterp); + check_accuracy("gsw_sa_ct_interp",cti_sactinterp_ca, + "cti_sactinterp",interp_n*interp_m, val7, cti_sactinterp); + + for (j = 0; j= GSW_ERROR_LIMIT) + break; + if (gsw_tracer_ct_interp(&sa[k],&ct[k],&p[k],n, + p_i,interp_m,9.,&val6[l],&val7[l]) == 1) + printf("gsw_sa_ct_interp returned error.\n"); + } + check_accuracy("gsw_tracer_ct_interp",traceri_tracerctinterp_ca, + "traceri_tracerctinterp",interp_n*interp_m, val6, traceri_tracerctinterp); + check_accuracy("gsw_tracer_ct_interp",cti_tracerctinterp_ca, + "cti_tracerctinterp",interp_n*interp_m, val7, cti_tracerctinterp); + test_infunnel(); if (gsw_error_flag) From d5cad06ecec1ff1d43098089f596b7c8cecec04d Mon Sep 17 00:00:00 2001 From: mauzey1 Date: Mon, 23 Sep 2024 13:54:16 -0700 Subject: [PATCH 23/27] clean up --- Makefile | 2 +- gsw_data_ncdump.txt | 4 ++-- gswteos-10.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 75cb1cb..1fe0b19 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ PROGRAM_SOURCES = gsw_check_functions.c\ gsw_oceanographic_toolbox.c\ gsw_saar.c LIBRARY_SRCS = gsw_oceanographic_toolbox.c \ - gsw_saar.c + gsw_saar.c # This includes TOOLS.gcc if make (unix) is used # The #\ logic causes the include to be ignored by nmake (windows) diff --git a/gsw_data_ncdump.txt b/gsw_data_ncdump.txt index 20397be..4b6b4b2 100644 --- a/gsw_data_ncdump.txt +++ b/gsw_data_ncdump.txt @@ -15,8 +15,8 @@ dimensions: test_cast_midpressure_number = 3 ; test_cast_midlocation_length = 45 ; test_cast_midlocation_number = 2 ; - test_interp_length = 51 ; - test_interp_number = 3 ; + test_interp_length = 51 ; + test_interp_number = 3 ; variables: double p_ref(nz) ; p_ref:standard_name = "pressure_reference_atlas" ; diff --git a/gswteos-10.h b/gswteos-10.h index 74be239..e273cad 100644 --- a/gswteos-10.h +++ b/gswteos-10.h @@ -299,7 +299,7 @@ DECLSPEC extern double gsw_t_freezing_poly(double sa, double p, DECLSPEC extern double gsw_t_from_ct(double sa, double ct, double p); DECLSPEC extern double gsw_t_from_pt0_ice(double pt0_ice, double p); DECLSPEC extern double gsw_thermobaric(double sa, double ct, double p); -DECLSPEC extern int gsw_tracer_ct_interp(double *sa, double *ct, double *p, +DECLSPEC extern int gsw_tracer_ct_interp(double *tracer, double *ct, double *p, int m, double *p_i, int m_i, double factor, double *sa_i, double *ct_i); DECLSPEC extern void gsw_turner_rsubrho(double *sa, double *ct, double *p, int nz, double *tu, double *rsubrho, double *p_mid); From e18e4c3ac70470ed8ee70976a800e8689ba78a9e Mon Sep 17 00:00:00 2001 From: mauzey1 Date: Mon, 23 Sep 2024 13:56:42 -0700 Subject: [PATCH 24/27] Use correct function name in error message in test --- gsw_check_functions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gsw_check_functions.c b/gsw_check_functions.c index 06fc48c..b8bab4b 100644 --- a/gsw_check_functions.c +++ b/gsw_check_functions.c @@ -609,7 +609,7 @@ main(int argc, char **argv) break; if (gsw_tracer_ct_interp(&sa[k],&ct[k],&p[k],n, p_i,interp_m,9.,&val6[l],&val7[l]) == 1) - printf("gsw_sa_ct_interp returned error.\n"); + printf("gsw_tracer_ct_interp returned error.\n"); } check_accuracy("gsw_tracer_ct_interp",traceri_tracerctinterp_ca, "traceri_tracerctinterp",interp_n*interp_m, val6, traceri_tracerctinterp); From 3999a39c068fe6b05d668c157eda71a368a90938 Mon Sep 17 00:00:00 2001 From: mauzey1 Date: Mon, 23 Sep 2024 14:21:19 -0700 Subject: [PATCH 25/27] Fix pointer type issue with malloc in gsw_util_intersect --- gsw_oceanographic_toolbox.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gsw_oceanographic_toolbox.c b/gsw_oceanographic_toolbox.c index 3f51c75..e8bb04c 100644 --- a/gsw_oceanographic_toolbox.c +++ b/gsw_oceanographic_toolbox.c @@ -12260,10 +12260,10 @@ gsw_util_intersect(double *x, int nx, double *y, int ny, int *ix, int *iy) return 0; } - sort_ix = malloc(nx * sizeof(int)); - sort_iy = malloc(ny * sizeof(int)); - unique_ix = malloc(nx * sizeof(int)); - unique_iy = malloc(ny * sizeof(int)); + sort_ix = (int *) malloc(nx * sizeof(int)); + sort_iy = (int *) malloc(ny * sizeof(int)); + unique_ix = (int *) malloc(nx * sizeof(int)); + unique_iy = (int *) malloc(ny * sizeof(int)); gsw_util_sort_real(x, nx, sort_ix); gsw_util_sort_real(y, ny, sort_iy); From 5e6015b24cadc51b41905cc5ba672a7972395263 Mon Sep 17 00:00:00 2001 From: mauzey1 Date: Mon, 23 Sep 2024 14:37:19 -0700 Subject: [PATCH 26/27] Trim trailing whitespace --- gsw_oceanographic_toolbox.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gsw_oceanographic_toolbox.c b/gsw_oceanographic_toolbox.c index e8bb04c..806d998 100644 --- a/gsw_oceanographic_toolbox.c +++ b/gsw_oceanographic_toolbox.c @@ -8633,7 +8633,7 @@ gsw_sa_ct_interp(double *sa, double *ct, double *p, int m, 1.950903220161283e-1 }; - int i, j, k, prof_len, + int i, j, k, prof_len, not_monotonic, unique_count, new_len, p_all_len, i_min_p_obs, i_obs_plus_interp_len, i_surf_and_obs_plus_interp_len, i_out_len, i_2_len, i_frozen, i_shallower, i_above, i_above_i, i_below_i; @@ -8692,7 +8692,7 @@ gsw_sa_ct_interp(double *sa, double *ct, double *p, int m, p_obs[prof_len] = 1e-3 * round(1e3 * p[i]); ct_f = gsw_ct_freezing_poly(sa_obs[prof_len], - p_obs[prof_len], + p_obs[prof_len], 0.); if (ct_obs[prof_len] < (ct_f - 0.1)) { ct_obs[prof_len] = ct_f; @@ -11329,7 +11329,7 @@ subroutine gsw_tracer_CT_interp (tracer,ct,p,p_i,factor) ! ( i.e. absolute pressure - 10.1325 dbar ) ! p_i = specific query points at which the interpolated tracer_i ! and CT_i are required [ dbar ] -! factor = ratio between the ranges of Conservative Temperature +! factor = ratio between the ranges of Conservative Temperature ! and tracer in the world ocean. [ ? ] ! @@ -11363,7 +11363,7 @@ gsw_tracer_ct_interp(double *tracer, double *ct, double *p, int m, 1.950903220161283e-1 }; - int i, j, k, prof_len, + int i, j, k, prof_len, not_monotonic, unique_count, new_len, p_all_len, i_min_p_obs, i_obs_plus_interp_len, i_surf_and_obs_plus_interp_len, i_out_len, i_2_len; @@ -11393,7 +11393,7 @@ gsw_tracer_ct_interp(double *tracer, double *ct, double *p, int m, tracer_i[i] = NAN; ct_i[i] = NAN; } - + // Find NaNs in profile prof_len = 0; for (i=0; i Date: Mon, 23 Sep 2024 16:46:51 -0700 Subject: [PATCH 27/27] Remove more trailing whitespace --- gsw_oceanographic_toolbox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gsw_oceanographic_toolbox.c b/gsw_oceanographic_toolbox.c index 806d998..1bda1f3 100644 --- a/gsw_oceanographic_toolbox.c +++ b/gsw_oceanographic_toolbox.c @@ -8832,7 +8832,7 @@ gsw_sa_ct_interp(double *sa, double *ct, double *p, int m, } gsw_util_pchip_interp(p_obs, independent_variable, prof_len, p_obs_plus_interp, independent_variable_obs_plus_interp, i_obs_plus_interp_len); - + scaled_sa_obs = (double *) malloc(prof_len*sizeof (double)); v_tmp = (double *) malloc(prof_len*sizeof (double)); q_tmp = (double *) malloc(prof_len*sizeof (double));