-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsw_CT_freezing.m
executable file
·137 lines (122 loc) · 5.53 KB
/
gsw_CT_freezing.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
function CT_freezing = gsw_CT_freezing(SA,p,saturation_fraction)
% gsw_CT_freezing Conservative Temperature at
% which seawater freezes
%==========================================================================
%
% USAGE:
% CT_freezing = gsw_CT_freezing(SA,p,saturation_fraction)
%
% DESCRIPTION:
% Calculates the Conservative Temperature at which seawater freezes. The
% Conservative Temperature freezing point is calculated from the exact
% in-situ freezing temperature which is found by a modified Newton-Raphson
% iteration (McDougall and Wotherspoon, 2014) of the equality of the
% chemical potentials of water in seawater and in ice.
%
% An alternative GSW function, gsw_CT_freezing_poly, it is based on a
% computationally-efficient polynomial, and is accurate to within -5e-4 K
% and 6e-4 K, when compared with this function.
%
% INPUT:
% SA = Absolute Salinity [ g/kg ]
% p = sea pressure [ dbar ]
% ( i.e. absolute pressure - 10.1325 dbar )
%
% OPTIONAL:
% saturation_fraction = the saturation fraction of dissolved air in
% seawater
% (i.e., saturation_fraction must be between 0 and 1, and the default
% is 0, air free)
%
% p & saturation_fraction (if provided) may have dimensions 1x1 or Mx1 or
% 1xN or MxN, where SA is MxN.
%
% OUTPUT:
% CT_freezing = Conservative Temperature at freezing of seawater [ deg C ]
% That is, the freezing temperature expressed in terms of
% Conservative Temperature (ITS-90).
%
% AUTHOR:
% Trevor McDougall and Paul Barker [ [email protected] ]
%
% VERSION NUMBER: 3.05 (27th January 2015)
%
% 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.
% See sections 3.33 and 3.34 of this TEOS-10 Manual.
%
% McDougall, T.J., and S.J. Wotherspoon, 2014: A simple modification of
% Newton's method to achieve convergence of order 1 + sqrt(2). Applied
% Mathematics Letters, 29, 20-25.
%
% The software is available from http://www.TEOS-10.org
%
%==========================================================================
%--------------------------------------------------------------------------
% Check variables and resize if necessary
%--------------------------------------------------------------------------
if ~(nargin == 2 | nargin == 3)
error('gsw_CT_freezing: Requires either two or three inputs')
end
if ~exist('saturation_fraction','var')
saturation_fraction = 0;
end
if (saturation_fraction < 0 | saturation_fraction > 1)
error('gsw_CT_freezing: saturation fraction MUST be between zero and one.')
end
[ms,ns] = size(SA);
[mp,np] = size(p);
[msf,nsf] = size(saturation_fraction);
if (mp == 1) & (np == 1) % p scalar - fill to size of SA
p = p*ones(size(SA));
elseif (ns == np) & (mp == 1) % p is row vector,
p = p(ones(1,ms), :); % copy down each column.
elseif (ms == mp) & (np == 1) % p is column vector,
p = p(:,ones(1,ns)); % copy across each row.
elseif (ns == mp) & (np == 1) % p is a transposed row vector,
p = p.'; % transposed then
p = p(ones(1,ms), :); % copy down each column.
elseif (ms == mp) & (ns == np)
% ok
else
error('gsw_CT_freezing: Inputs array dimensions arguments do not agree')
end %if
if (msf == 1) & (nsf == 1) % saturation_fraction scalar
saturation_fraction = saturation_fraction*ones(size(SA)); % fill to size of SA
elseif (ns == nsf) & (msf == 1) % saturation_fraction is row vector,
saturation_fraction = saturation_fraction(ones(1,ms), :); % copy down each column.
elseif (ms == msf) & (nsf == 1) % saturation_fraction is column vector,
saturation_fraction = saturation_fraction(:,ones(1,ns)); % copy across each row.
elseif (ns == msf) & (nsf == 1) % saturation_fraction is a transposed row vector,
saturation_fraction = saturation_fraction.'; % transposed then
saturation_fraction = saturation_fraction(ones(1,ms), :); % copy down each column.
elseif (ms == msf) & (ns == nsf)
% ok
else
error('gsw_CT_freezing: Inputs array dimensions arguments do not agree')
end %if
if ms == 1
SA = SA.';
p = p.';
saturation_fraction = saturation_fraction.';
transposed = 1;
else
transposed = 0;
end
%--------------------------------------------------------------------------
% Start of the calculation
%--------------------------------------------------------------------------
% This line ensures that SA is non-negative.
SA(SA < 0) = 0;
t_freezing = gsw_t_freezing(SA,p,saturation_fraction);
CT_freezing = gsw_CT_from_t(SA,t_freezing,p);
% set any values that are out of the valid TEOS-10 range to be NaN.
CT_freezing(p > 10000 | SA > 120 | ...
p + SA.*71.428571428571402 > 13571.42857142857) = NaN;
if transposed
CT_freezing = CT_freezing.';
end
end