Skip to content

Commit

Permalink
Version 3.02
Browse files Browse the repository at this point in the history
Improved computation efficiency.

Minor bug fixes.
  • Loading branch information
PaulMBarker committed May 29, 2015
1 parent d276f56 commit 259e142
Show file tree
Hide file tree
Showing 192 changed files with 2,106 additions and 1,704 deletions.
8 changes: 4 additions & 4 deletions Toolbox/Contents.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% GSW Oceanographic Toolbox
% Version 3.01 (R2011a) 15-May-2011
% Version 3.02 (R2011a) 15-May-2011
%
% documentation set
% gsw_front_page - front page to the GSW Oceanographic Toolbox
Expand Down Expand Up @@ -213,10 +213,10 @@
% gsw_gibbs - the TEOS-10 Gibbs function and its derivatives
% gsw_SAAR - Absolute Salinity Anomaly Ratio (excluding the Baltic Sea)
% gsw_Fdelta - ratio of Absolute to Preformed Salinity, minus 1
% gsw_delta_SA_ref - Absolute Salinity Anomaly ref. value (excluding the Baltic Sea)
% gsw_deltaSA_atlas - Absolute Salinity Anomaly atlas value (excluding the Baltic Sea)
% gsw_SA_from_SP_Baltic - Calculates Absolute Salinity in the Baltic Sea
% gsw_SP_from_SA_Baltic - Calculates Practical Salinity in the Baltic Sea
% gsw_infunnel - "oceanographic funnel" check for the 25-term equation
% gsw_infunnel - "oceanographic funnel" check for the 48-term equation
% gsw_entropy_part - entropy minus the terms that are a function of only SA
% gsw_entropy_part_zerop - entropy_part evaluated at 0 dbar
% gsw_interp_ref_cast - linearly interpolates the reference cast
Expand All @@ -229,7 +229,7 @@
% The GSW data set.
% gsw_data_v3_0 - contains
% (1) the global data set of Absolute Salinity Anomaly Ratio,
% (2) the global data set of Absolute Salinity Anomaly Ref.,
% (2) the global data set of Absolute Salinity Anomaly atlas,
% (3) a reference cast (for the isopycnal streamfunction),
% (4) two reference casts that are used by gsw_demo
% (5) three vertical profiles of (SP, t, p) at known long & lat, plus
Expand Down
2 changes: 1 addition & 1 deletion Toolbox/gsw_Abs_Pressure_from_p.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
% AUTHOR:
% Trevor McDougall and Paul Barker [ help@teos-10.org ]
%
% VERSION NUMBER: 3.01 (29th March, 2011)
% VERSION NUMBER: 3.02 (13th November, 2012)
%
% REFERENCES:
% IOC, SCOR and IAPSO, 2010: The international thermodynamic equation of
Expand Down
2 changes: 1 addition & 1 deletion Toolbox/gsw_C3515.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
% AUTHOR:
% Trevor McDougall and Paul Barker [ help@teos-10.org ]
%
% VERSION NUMBER: 3.01 (29th March, 2011)
% VERSION NUMBER: 3.02 (13th November, 2012)
%
% REFERENCES:
% Culkin and Smith, 1980: Determination of the Concentration of Potassium
Expand Down
2 changes: 1 addition & 1 deletion Toolbox/gsw_CT_first_derivatives.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
% AUTHOR:
% Trevor McDougall and Paul Barker [ help@teos-10.org ]
%
% VERSION NUMBER: 3.01 (11th April 2011)
% VERSION NUMBER: 3.02 (15th November, 2012)
%
% REFERENCES:
% IOC, SCOR and IAPSO, 2010: The international thermodynamic equation of
Expand Down
13 changes: 5 additions & 8 deletions Toolbox/gsw_CT_freezing.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
% AUTHOR:
% Trevor McDougall, Paul Barker and Rainer Feistal [ help@teos-10.org ]
%
% VERSION NUMBER: 3.01 (4th November, 2011)
% VERSION NUMBER: 3.02 (13th November, 2012)
%
% REFERENCES:
% IOC, SCOR and IAPSO, 2010: The international thermodynamic equation of
Expand Down Expand Up @@ -108,8 +108,7 @@
%--------------------------------------------------------------------------

% These few lines ensure that SA is non-negative.
[I_neg_SA] = find(SA < 0);
if ~isempty(I_neg_SA)
if any(SA < 0)
error(' gsw_CT_freezing: SA must be non-negative!')
end

Expand Down Expand Up @@ -164,11 +163,9 @@
CT_freezing = CT_freezing ...
- saturation_fraction.*(1e-3).*(2.4 - a.*SA).*(1 + b.*(1 - SA./35.16504));

[Iout_of_range] = find(p > 10000 | SA > 120 | ...
p + SA.*71.428571428571402 > 13571.42857142857);
if ~isempty(Iout_of_range)
CT_freezing(Iout_of_range) = NaN;
end
% set any values that are out of range to be NaN.
CT_freezing(p > 10000 | SA > 120 | ...
p + SA.*71.428571428571402 > 13571.42857142857) = NaN;

if transposed
CT_freezing = CT_freezing.';
Expand Down
9 changes: 3 additions & 6 deletions Toolbox/gsw_CT_from_entropy.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
% AUTHOR:
% Trevor McDougall and Paul Barker. [ help@teos-10.org ]
%
% VERSION NUMBER: 3.01 (3rd March, 2011)
% VERSION NUMBER: 3.02 (13th November, 2012)
%
% REFERENCES:
% IOC, SCOR and IAPSO, 2010: The international thermodynamic equation of
Expand Down Expand Up @@ -62,11 +62,8 @@
% Start of the calculation
%--------------------------------------------------------------------------

% These few lines ensure that SA is non-negative.
[I_neg_SA] = find(SA < 0);
if ~isempty(I_neg_SA)
SA(I_neg_SA) = 0;
end
% This line ensures that SA is non-negative.
SA(SA < 0) = 0;

pt = gsw_pt_from_entropy(SA,entropy);
CT = gsw_CT_from_pt(SA,pt);
Expand Down
10 changes: 3 additions & 7 deletions Toolbox/gsw_CT_from_pt.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
% AUTHOR:
% David Jackett, Trevor McDougall and Paul Barker [ help@teos-10.org ]
%
% VERSION NUMBER: 3.01 (29th March, 2011)
% This function is unchanged from version 2.0 (24th September, 2010).
% VERSION NUMBER: 3.02 (13th November, 2012)
%
% REFERENCES:
% IOC, SCOR and IAPSO, 2010: The international thermodynamic equation of
Expand Down Expand Up @@ -63,11 +62,8 @@
% Start of the calculation
%--------------------------------------------------------------------------

% These few lines ensure that SA is non-negative.
[I_neg_SA] = find(SA < 0);
if ~isempty(I_neg_SA)
SA(I_neg_SA) = 0;
end
% This line ensures that SA is non-negative.
SA(SA < 0) = 0;

cp0 = 3991.86795711963; % defined in Eqn. (3.3.3) of IOC et al. (2010).

Expand Down
75 changes: 30 additions & 45 deletions Toolbox/gsw_CT_from_rho.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@
% AUTHOR:
% Trevor McDougall & Paul Barker [ help@teos-10.org ]
%
% VERSION NUMBER: 3.01 (21th April, 2011)
% VERSION NUMBER: 3.02 (15th November, 2012)
%
% REFERENCES:
% IOC, SCOR and IAPSO, 2010: The international thermodynamic equation of
% seawater - 2010: Calculation and use of thermodynamic properties.
% Intergovernmental Oceanographic Commission, Manuals and Guides No. 56,
% UNESCO (English), 196 pp. Available from http://www.TEOS-10.org
%
% McDougall T.J., P.M. Barker, R. Feistel and D.R. Jackett, 2011: A
% McDougall T.J., P.M. Barker, R. Feistel and D.R. Jackett, 2013: A
% computationally efficient 48-term expression for the density of
% seawater in terms of Conservative Temperature, and related properties
% of seawater. To be submitted to Ocean Science Discussions.
% of seawater. To be submitted to J. Atm. Ocean. Technol., xx, yyy-zzz.
%
% The software is available from http://www.TEOS-10.org
%
Expand Down Expand Up @@ -115,40 +115,35 @@
rec_half_rho_TT = -110.0;

CT = nan(size(SA));
CT_multiple = nan(size(SA));
CT_multiple = CT;

[I_SA_p] = find(SA<0 | SA>42 | p <-1.5 | p>12000);
if ~isempty(I_SA_p)
SA(I_SA_p) = NaN;
end
% SA out of range, set to NaN.
SA(SA<0 | SA>42 | p <-1.5 | p>12000) = NaN;

rho_40 = gsw_rho_CT(SA,40*ones(size(SA)),p);
[I_rho_light] = find((rho - rho_40) < 0);
if ~isempty(I_rho_light)
SA(I_rho_light) = NaN;
end
% rho too light, set to NaN.
SA((rho - rho_40) < 0) = NaN;

CT_max_rho = gsw_CT_maxdensity(SA,p);
rho_max = gsw_rho(SA,CT_max_rho,p);
rho_extreme = rho_max;
CT_freezing = gsw_CT_freezing(SA,p); % this assumes that the seawater is always saturated with air
rho_freezing = gsw_rho(SA,CT_freezing,p);
[I_fr_gr_max] = find((CT_freezing - CT_max_rho) > 0);
rho_extreme(I_fr_gr_max) = rho_freezing(I_fr_gr_max);
[I_rho_dense] = find(rho > rho_extreme);
if ~isempty(I_rho_dense)
SA(I_rho_dense) = NaN;
end
% reset the extreme values
rho_extreme((CT_freezing - CT_max_rho) > 0) = rho_freezing((CT_freezing - CT_max_rho) > 0);

[I_bad] = find(isnan(SA.*p.*rho));
if ~isempty (I_bad)
% set SA values to NaN for the rho's that are too dense.
SA(rho > rho_extreme) = NaN;

if any(isnan(SA + p + rho))
[I_bad] = find(isnan(SA + p + rho));
SA(I_bad) = NaN;
end

alpha_freezing = gsw_alpha(SA,CT_freezing,p);
[I_salty] = find(alpha_freezing > alpha_limit);

if ~isempty(I_salty)
if any(alpha_freezing > alpha_limit)
[I_salty] = find(alpha_freezing > alpha_limit);
CT_diff = 40*ones(size(I_salty)) - CT_freezing(I_salty);

top = rho_40(I_salty) - rho_freezing(I_salty) ...
Expand All @@ -162,20 +157,21 @@
CT(I_salty) = CT_freezing(I_salty) + 0.5*(-b - sqrt_disc)./a;
end

[I_fresh] = find(alpha_freezing <= alpha_limit);
if ~isempty(I_fresh)
if any(alpha_freezing <= alpha_limit)
[I_fresh] = find(alpha_freezing <= alpha_limit);

CT_diff = 40*ones(size(I_fresh)) - CT_max_rho(I_fresh);
factor = (rho_max(I_fresh) - rho(I_fresh))./ ...
(rho_max(I_fresh) - rho_40(I_fresh));
delta_CT = CT_diff.*sqrt(factor);

[I_fresh_NR] = find(delta_CT > 5);
if ~isempty(I_fresh_NR)
if any(delta_CT > 5)
[I_fresh_NR] = find(delta_CT > 5);
CT(I_fresh(I_fresh_NR)) = CT_max_rho(I_fresh(I_fresh_NR)) + delta_CT(I_fresh_NR);
end

[I_quad] = find(delta_CT <= 5);
if ~isempty(I_quad)
if any(delta_CT <= 5)
[I_quad] = find(delta_CT <= 5);
CT_a = nan(size(SA));
% set the initial value of the quadratic solution routes.
CT_a(I_fresh(I_quad)) = CT_max_rho(I_fresh(I_quad)) + ...
Expand All @@ -186,10 +182,8 @@
factorqa = (rho_max - rho)./(rho_max - rho_old);
CT_a = CT_max_rho + (CT_old - CT_max_rho).*sqrt(factorqa);
end
[Ifrozen] = find(CT_freezing - CT_a < 0);
if ~isempty(Ifrozen)
CT_a(Ifrozen) = NaN;
end

CT_a(CT_freezing - CT_a < 0) = NaN;

CT_b = nan(size(SA));
% set the initial value of the quadratic solution roots.
Expand All @@ -203,10 +197,7 @@
end
% After seven iterations of this quadratic iterative procedure,
% the error in rho is no larger than 4.6x10^-13 kg/m^3.
[Ifrozen] = find(CT_freezing - CT_b < 0);
if ~isempty(Ifrozen)
CT_b(Ifrozen) = NaN;
end
CT_b(CT_freezing - CT_b < 0) = NaN;
end
end

Expand All @@ -226,16 +217,10 @@
end

if exist('t_a','var')
[I_quad] = find(~isnan(CT_a));
if ~isempty(I_quad)
CT(I_quad) = CT_a(I_quad);
end
CT(~isnan(CT_a)) = CT_a(~isnan(CT_a));
end
if exist('t_b','var')
[I_quad] = find(~isnan(CT_b));
if ~isempty(I_quad)
CT_multiple(I_quad) = CT_b(I_quad);
end
CT_multiple(~isnan(CT_b)) = CT_b(~isnan(CT_b));
end
% After three iterations of this modified Newton-Raphson iteration,
% the error in rho is no larger than 1.6x10^-12 kg/m^3.
Expand Down
4 changes: 2 additions & 2 deletions Toolbox/gsw_CT_from_rho_exact.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function [CT,CT_multiple] = gsw_CT_from_rho_exact(rho,SA,p)

% gsw_t_from_rho_exact in situ temperature from density
% gsw_t_from_rho_exact in-situ temperature from density
% =========================================================================
%
% USAGE:
Expand Down Expand Up @@ -34,7 +34,7 @@
% AUTHOR:
% Trevor McDougall & Paul Barker [ help@teos-10.org ]
%
% VERSION NUMBER: 3.01 (21th April, 2011)
% VERSION NUMBER: 3.02 (13th November, 2012)
%
% REFERENCES:
% IOC, SCOR and IAPSO, 2010: The international thermodynamic equation of
Expand Down
14 changes: 4 additions & 10 deletions Toolbox/gsw_CT_from_t.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
% AUTHOR:
% David Jackett, Trevor McDougall and Paul Barker [ help@teos-10.org ]
%
% VERSION NUMBER: 3.01 (27th March, 2011)
% This function is unchanged from version 2.0 (24th September, 2010).
% VERSION NUMBER: 3.02 (13th November, 2012)
%
% REFERENCES:
% IOC, SCOR and IAPSO, 2010: The international thermodynamic equation of
Expand Down Expand Up @@ -70,14 +69,9 @@
error('gsw_CT_from_t: Inputs array dimensions arguments do not agree')
end %if

[Iout_of_range] = find(p < 100 & (t > 80 | t < -12));
if (~isempty(Iout_of_range))
t(Iout_of_range) = NaN;
end
[Iout_of_range] = find(p >= 100 & (t > 40 | t < -12));
if (~isempty(Iout_of_range))
t(Iout_of_range) = NaN;
end
%Find values that are out of range, set them to NaN.
t(p < 100 & (t > 80 | t < -12)) = NaN;
t(p >= 100 & (t > 40 | t < -12)) = NaN;

if ms == 1
SA = SA.';
Expand Down
17 changes: 11 additions & 6 deletions Toolbox/gsw_CT_maxdensity.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
% of seawater is a maximum, at given Absolute Salinity, SA, and sea
% pressure, p (in dbar). This function uses the computationally-efficient
% 48-term expression for density in terms of SA, CT and p (McDougall et
% al., 2011).
% al., 2013).
%
% Note that the 48-term equation has been fitted in a restricted range of
% parameter space, and is most accurate inside the "oceanographic funnel"
% described in McDougall et al. (2011). The GSW library function
% described in McDougall et al. (2013). The GSW library function
% "gsw_infunnel(SA,CT,p)" is avaialble to be used if one wants to test if
% some of one's data lies outside this "funnel".
%
Expand Down Expand Up @@ -45,10 +45,14 @@
% UNESCO (English), 196 pp. Available from http://www.TEOS-10.org
% See section 3.42 of this TEOS-10 Manual.
%
% McDougall T.J., P.M. Barker, R. Feistel and D.R. Jackett, 2011: A
% McDougall T.J., P.M. Barker, R. Feistel and D.R. Jackett, 2013: A
% computationally efficient 48-term expression for the density of
% seawater in terms of Conservative Temperature, and related properties
% of seawater. To be submitted to Ocean Science Discussions.
% of seawater. To be submitted to J. Atm. Ocean. Technol., xx, yyy-zzz.
%
% McDougall T.J. and S.J. Wotherspoon, 2012: A simple modification of
% Newton’s method to achieve convergence of order "1 + sqrt(2)".
% Submitted to Applied Mathematics and Computation.
%
% The software is available from http://www.TEOS-10.org
%
Expand Down Expand Up @@ -111,8 +115,9 @@
CT = CT_old - alpha./dalpha_dCT;
end

% After three iterations of this modified Newton-Raphson iteration, the
% error in CT_maxdensity is typically no larger than 1x10^-15 degress C.
% After three iterations of this modified Newton-Raphson (McDougall and
% Wotherspoon, 2012) iteration, the error in CT_maxdensity is typically no
% larger than 1x10^-15 degress C.

CT_maxdensity = CT;

Expand Down
2 changes: 1 addition & 1 deletion Toolbox/gsw_CT_maxdensity_exact.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
% AUTHOR:
% Trevor McDougall & Paul Barker [ help@teos-10.org ]
%
% VERSION NUMBER: 3.01 (3rd April, 2011)
% VERSION NUMBER: 3.02 (15th November, 2012)
%
% REFERENCES:
% IOC, SCOR and IAPSO, 2010: The international thermodynamic equation of
Expand Down

0 comments on commit 259e142

Please sign in to comment.