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 75b54eb..e019372 100644 Binary files a/gsw_check_data.nc and b/gsw_check_data.nc differ diff --git a/gsw_check_functions.c b/gsw_check_functions.c index a396a4e..b8bab4b 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_tracer_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) diff --git a/gsw_data_ncdump.txt b/gsw_data_ncdump.txt index f840ab1..4b6b4b2 100644 --- a/gsw_data_ncdump.txt +++ b/gsw_data_ncdump.txt @@ -15,6 +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 ; variables: double p_ref(nz) ; p_ref:standard_name = "pressure_reference_atlas" ; @@ -85,6 +87,7 @@ variables: double SP_chck_cast(test_cast_number, test_cast_length) ; double t_chck_cast(test_cast_number, test_cast_length) ; double p_chck_cast(test_cast_number, test_cast_length) ; + double p_i(test_interp_length) ; double lat_chck_cast(test_cast_number) ; double long_chck_cast(test_cast_number) ; double pr(value_test_cast) ; @@ -320,6 +323,14 @@ variables: Tu:computation_accuracy = 2.19097096021414e-08 ; double Rsubrho(test_cast_number, test_cast_midpressure_length) ; Rsubrho:computation_accuracy = 1.70965819279445e-08 ; + double SAi_SACTinterp(test_interp_number, test_interp_length) ; + SAi_SACTinterp:computation_accuracy = 1.300151097893831e-10 ; + double CTi_SACTinterp(test_interp_number, test_interp_length) ; + CTi_SACTinterp:computation_accuracy = 6.261124951834063e-10 ; + double traceri_tracerCTinterp(test_interp_number, test_interp_length) ; + traceri_tracerCTinterp:computation_accuracy = 1.300151097893831e-10 ; + double CTi_tracerCTinterp(test_interp_number, test_interp_length) ; + CTi_tracerCTinterp:computation_accuracy = 6.261124951834063e-10 ; double p_mid_TuRsr(test_cast_number, test_cast_midpressure_length) ; p_mid_TuRsr:computation_accuracy = 2.30002115131356e-08 ; double n2(test_cast_number, test_cast_midpressure_length) ; diff --git a/gsw_oceanographic_toolbox.c b/gsw_oceanographic_toolbox.c index 371bce2..1bda1f3 100644 --- a/gsw_oceanographic_toolbox.c +++ b/gsw_oceanographic_toolbox.c @@ -8589,6 +8589,406 @@ 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 ] +! +!-------------------------------------------------------------------------- +*/ +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) +{ + 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; + + if (m < 4) + return 1; // 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 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 **!========================================================================== diff --git a/gswteos-10.h b/gswteos-10.h index 0d43caa..e273cad 100644 --- a/gswteos-10.h +++ b/gswteos-10.h @@ -228,6 +228,8 @@ 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); +DECLSPEC extern 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); 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, @@ -297,11 +299,14 @@ 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 *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); 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); +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); diff --git a/make_data_from_mat.py b/make_data_from_mat.py index dede788..6dc8b7a 100644 --- a/make_data_from_mat.py +++ b/make_data_from_mat.py @@ -97,6 +97,7 @@ def get_arraydims(): ["sp", "SP_chck_cast"], ["t", "t_chck_cast"], ["p", "p_chck_cast"], + ["p_i", "p_i"], ["delta_p", "delta_p_chck_cast"], ["p_shallow", "p_chck_cast_shallow"], ["p_deep", "p_chck_cast_deep"], @@ -271,6 +272,10 @@ def get_arraydims(): ['p_mid_n2', ""], ['Tu', ""], ['Rsubrho', ""], + ['SAi_SACTinterp', ""], + ['CTi_SACTinterp', ""], + ['traceri_tracerCTinterp', ""], + ['CTi_tracerCTinterp', ""], ['p_mid_TuRsr', ""], ['IPVfN2', ""], ['p_mid_IPVfN2', ""], @@ -380,6 +385,7 @@ def get_arraydims(): work_dims["cast_m"], work_dims["cast_n"] = cv['p_chck_cast'].shape work_dims["cast_ice_m"], work_dims["cast_ice_n"] = cv["p_Arctic"].shape work_dims["cast_mpres_m"], work_dims["cast_mpres_n"] = cv["p_mid_n2"].shape +work_dims["interp_m"], work_dims["interp_n"] = cv['SAi_SACTinterp'].shape for key, val in work_dims.items(): out.write("#define\t%s\t%d\n" % (key, val)) @@ -410,6 +416,8 @@ def get_arraydims(): test_cast_midpressure_number = 3, test_cast_midlocation_length = 45, test_cast_midlocation_number = 2, + test_interp_length = 51, + test_interp_number = 3 ) arraydims = get_arraydims()