


SW_Density Density of sea water ========================================================================= USAGE: rho = SW_Density(T,S) DESCRIPTION: Density of seawater at atmospheric pressure (0.1 MPa) using Eq. (8) given by [1] which best fit the data of [2] and [3]. The pure water density equation is a best fit to the data of [4]. Values at temperature higher than the normal boiling temperature are calculated at the saturation pressure. INPUT: (all must have same dimensions) T = temperature [degree C] (ITS-90) S = salinity [g/kg] (reference-composition salinity) OUTPUT: rho = density [kg/m^3] AUTHOR: Mostafa H. Sharqawy 12-18-2009, MIT (mhamed@mit.edu) Pierre Cazenave (Plymouth Marine Laboratory) DISCLAIMER: This software is provided "as is" without warranty of any kind. See the file sw_copy.m for conditions of use and licence. VALIDITY: 0 < T < 180 C; 0 < S < 160 g/kg; ACCURACY: 0.1% REFERENCES: [1] Sharqawy M. H., Lienhard J. H., and Zubair, S. M., Desalination and Water Treatment, 2009. [2] Isdale, and Morris, Desalination, 10(4), 329, 1972. [3] Millero and Poisson, Deep-Sea Research, 28A (6), 625, 1981 [4] IAPWS release on the Thermodynamic properties of ordinary water substance, 1996. UPDATED 09-23-2010 modified to now handle matrices and commented out range checking. Revision history 2017-03-31 Tidy up the code a bit. =========================================================================


0001 function rho = SW_Density(T,S) 0002 % SW_Density Density of sea water 0003 %========================================================================= 0004 % USAGE: rho = SW_Density(T,S) 0005 % 0006 % DESCRIPTION: 0007 % Density of seawater at atmospheric pressure (0.1 MPa) using Eq. (8) 0008 % given by [1] which best fit the data of [2] and [3]. The pure water 0009 % density equation is a best fit to the data of [4]. 0010 % Values at temperature higher than the normal boiling temperature are 0011 % calculated at the saturation pressure. 0012 % 0013 % INPUT: (all must have same dimensions) 0014 % T = temperature [degree C] (ITS-90) 0015 % S = salinity [g/kg] (reference-composition salinity) 0016 % 0017 % OUTPUT: 0018 % rho = density [kg/m^3] 0019 % 0020 % AUTHOR: 0021 % Mostafa H. Sharqawy 12-18-2009, MIT (mhamed@mit.edu) 0022 % Pierre Cazenave (Plymouth Marine Laboratory) 0023 % 0024 % DISCLAIMER: 0025 % This software is provided "as is" without warranty of any kind. 0026 % See the file sw_copy.m for conditions of use and licence. 0027 % 0028 % VALIDITY: 0 < T < 180 C; 0 < S < 160 g/kg; 0029 % 0030 % ACCURACY: 0.1% 0031 % 0032 % REFERENCES: 0033 % [1] Sharqawy M. H., Lienhard J. H., and Zubair, S. M., Desalination and Water Treatment, 2009. 0034 % [2] Isdale, and Morris, Desalination, 10(4), 329, 1972. 0035 % [3] Millero and Poisson, Deep-Sea Research, 28A (6), 625, 1981 0036 % [4] IAPWS release on the Thermodynamic properties of ordinary water 0037 % substance, 1996. 0038 % UPDATED 09-23-2010 modified to now handle matrices and commented out 0039 % range checking. 0040 % 0041 % Revision history 0042 % 2017-03-31 Tidy up the code a bit. 0043 %========================================================================= 0044 0045 global ftbverbose 0046 [~, subname] = fileparts(mfilename('fullpath')); 0047 if ftbverbose 0048 fprintf('\nbegin : %s\n', subname) 0049 end 0050 0051 %---------------------- 0052 % CHECK INPUT ARGUMENTS 0053 %---------------------- 0054 if nargin ~=2 0055 error('SW_Density.m: Must pass 2 parameters') 0056 end 0057 0058 % CHECK S,T dimensions and verify consistent 0059 [ms,ns] = size(S); 0060 [mt,nt] = size(T); 0061 0062 % CHECK THAT S & T HAVE SAME SHAPE 0063 if (ms~=mt) || (ns~=nt) 0064 error('check_stp: S & T must have same dimensions') 0065 end 0066 0067 % CHECK THAT S & T ARE WITHIN THE FUNCTION RANGE 0068 vectorsize=size(S); 0069 s = nan(vectorsize); 0070 rho_w = nan(vectorsize); 0071 D_rho = nan(vectorsize); 0072 rho = nan(vectorsize); 0073 for i = 1:vectorsize(1,1) 0074 for j = 1:vectorsize(1,2) 0075 % if T(i,j)>180 | T(i,j)<0 0076 % disp('Temperature is out of range for density function 0 < T < 180 C'); 0077 % end 0078 % if S(i,j)<0 | S(i,j)>160 0079 % disp('Salinity is out of range for density function 0 < S < 160 g/kg'); 0080 % end 0081 0082 %------ 0083 % BEGIN 0084 %------ 0085 s(i,j)=S(i,j)/1000; 0086 a1=9.9992293295E+02;a2=2.0341179217E-02;a3=-6.1624591598E-03;a4=2.2614664708E-05;a5=-4.6570659168E-08; 0087 b1=8.0200240891E+02;b2=-2.0005183488E+00;b3=1.6771024982E-02;b4=-3.0600536746E-05;b5=-1.6132224742E-05; 0088 rho_w(i,j) = a1 + a2*T(i,j) + a3*T(i,j)^2 + a4*T(i,j)^3 + a5*T(i,j)^4; 0089 D_rho(i,j) = b1*s(i,j) + b2*s(i,j)*T(i,j) + b3*s(i,j)*T(i,j)^2 + b4*s(i,j)*T(i,j)^3 + b5*s(i,j)^2*T(i,j)^2; 0090 rho(i,j) = rho_w(i,j) + D_rho(i,j); 0091 end 0092 end 0093 0094 if ftbverbose 0095 fprintf('end : %s\n', subname) 0096 end