NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/seawater/sw_cp.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1
2 function cp = sw_cp(S,T,P)
3
4 % SW_CP      Heat Capacity (Cp) of sea water
5 %=========================================================================
6 % SW_CP  $Id: sw_cp.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $
7 %         Copyright (C) CSIRO, Phil Morgan 1993.
8 %
9 % USAGE: cp = sw_cp(S,T,P)
10 %
11 % DESCRIPTION:
12 %    Heat Capacity of Sea Water using UNESCO 1983 polynomial.
13 %
14 % INPUT:  (all must have same dimensions)
15 %   S = salinity    [psu      (PSS-78)]
16 %   T = temperature [degree C (ITS-90)]
17 %   P = pressure    [db]
18 %       (P may have dims 1x1, mx1, 1xn or mxn for S(mxn) )
19 %
20 % OUTPUT:
21 %   cp = Specific Heat Capacity  [J kg^-1 C^-1]
22 %
23 % AUTHOR:  Phil Morgan, Lindsay Pender (Lindsay.Pender@csiro.au)
24 %
25 % DISCLAIMER:
26 %   This software is provided "as is" without warranty of any kind.
27 %   See the file sw_copy.m for conditions of use and licence.
28 %
29 % REFERENCES:
30 %    Fofonff, P. and Millard, R.C. Jr
31 %    Unesco 1983. Algorithms for computation of fundamental properties of
32 %    seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp.
33 %=========================================================================
34
35 % Modifications
36 % 99-06-25. Lindsay Pender, Fixed transpose of row vectors.
37 % 03-12-12. Lindsay Pender, Converted to ITS-90.
38
39 % CALLER: general purpose
40 % CALLEE: none
41
42 %----------------------
43 % CHECK INPUT ARGUMENTS
44 %----------------------
45 if nargin ~=3
46    error('Must pass 3 parameters')
47 end %if
48
49 % CHECK S,T,P dimensions and verify consistent
50 [ms,ns] = size(S);
51 [mt,nt] = size(T);
52 [mp,np] = size(P);
53
54
55 % CHECK THAT S & T HAVE SAME SHAPE
56 if (ms~=mt) | (ns~=nt)
57    error('S & T must have same dimensions')
58 end %if
59
60 % CHECK OPTIONAL SHAPES FOR P
61 if     mp==1  & np==1      % P is a scalar.  Fill to size of S
62    P = P(1)*ones(ms,ns);
63 elseif np==ns & mp==1      % P is row vector with same cols as S
64    P = P( ones(1,ms), : ); %   Copy down each column.
65 elseif mp==ms & np==1      % P is column vector
66    P = P( :, ones(1,ns) ); %   Copy across each row
67 elseif mp==ms & np==ns     % PR is a matrix size(S)
68    % shape ok
69 else
70    error('P has wrong dimensions')
71 end %if
72
73 %***check_stp
74
75 %------
76 % BEGIN
77 %------
78 P = P/10; % to convert db to Bar as used in Unesco routines
79 T68 = T * 1.00024;
80
81 %------------
82 % eqn 26 p.32
83 %------------
84 c0 = 4217.4;
85 c1 =   -3.720283;
86 c2 =    0.1412855;
87 c3 =   -2.654387e-3;
88 c4 =    2.093236e-5;
89
90 a0 = -7.64357;
91 a1 =  0.1072763;
92 a2 = -1.38385e-3;
93
94 b0 =  0.1770383;
95 b1 = -4.07718e-3;
96 b2 =  5.148e-5;
97
98 Cpst0 = (((c4.*T68 + c3).*T68 + c2).*T68 + c1).*T68 + c0 + ...
99         (a0 + a1.*T68 + a2.*T68.^2).*S + ...
100     (b0 + b1.*T68 + b2.*T68.^2).*S.*sqrt(S);
101
102 %------------
103 % eqn 28 p.33
104 %------------
105 a0 = -4.9592e-1;
106 a1 =  1.45747e-2;
107 a2 = -3.13885e-4;
108 a3 =  2.0357e-6;
109 a4 =  1.7168e-8;
110
111 b0 =  2.4931e-4;
112 b1 = -1.08645e-5;
113 b2 =  2.87533e-7;
114 b3 = -4.0027e-9;
115 b4 =  2.2956e-11;
116
117 c0 = -5.422e-8;
118 c1 =  2.6380e-9;
119 c2 = -6.5637e-11;
120 c3 =  6.136e-13;
121
122 del_Cp0t0 =  (((((c3.*T68 + c2).*T68 + c1).*T68 + c0).*P + ...
123              ((((b4.*T68 + b3).*T68 + b2).*T68 + b1).*T68 + b0)).*P + ...
124              ((((a4.*T68 + a3).*T68 + a2).*T68 + a1).*T68 + a0)).*P;
125
126 %------------
127 % eqn 29 p.34
128 %------------
129 d0 =  4.9247e-3;
130 d1 = -1.28315e-4;
131 d2 =  9.802e-7;
132 d3 =  2.5941e-8;
133 d4 = -2.9179e-10;
134
135 e0 = -1.2331e-4;
136 e1 = -1.517e-6;
137 e2 =  3.122e-8;
138
139 f0 = -2.9558e-6;
140 f1 =  1.17054e-7;
141 f2 = -2.3905e-9;
142 f3 =  1.8448e-11;
143
144 g0 =  9.971e-8;
145
146 h0 =  5.540e-10;
147 h1 = -1.7682e-11;
148 h2 =  3.513e-13;
149
150 j1 = -1.4300e-12;
151 S3_2  = S.*sqrt(S);
152
153 del_Cpstp = [((((d4.*T68 + d3).*T68 + d2).*T68 + d1).*T68 + d0).*S + ...
154              ((e2.*T68 + e1).*T68 + e0).*S3_2].*P                + ...
155         [(((f3.*T68 + f2).*T68 + f1).*T68 + f0).*S            + ...
156          g0.*S3_2].*P.^2                                  + ...
157          [((h2.*T68 + h1).*T68 + h0).*S                      + ...
158          j1.*T68.*S3_2].*P.^3;
159
160
161 cp = Cpst0 + del_Cp0t0 + del_Cpstp;
162
Note: See TracBrowser for help on using the browser.