Commit b5089c7d authored by Pierre Cazenave's avatar Pierre Cazenave
Browse files

Support for arrays of data and minor performance improvements (preallocation).

parent bc17c6d8
......@@ -72,7 +72,11 @@ dens = SW_Density(T,S);
dstar = ST_Dstar(d,'temp',T,'sal',S,'sdens',sdens);
% calculate wset
wset = (nu/d)*( sqrt(10.36^2 + 1.049*(dstar^3)) - 10.36);
if ismatrix(d)
wset = (nu./d).*( sqrt(10.36^2 + 1.049*(dstar.^3)) - 10.36);
else
wset = (nu/d)*( sqrt(10.36^2 + 1.049*(dstar^3)) - 10.36);
end
if ftbverbose
fprintf('end : %s\n', subname)
......
......@@ -19,6 +19,7 @@ function rho = SW_Density(T,S)
%
% 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.
......@@ -36,6 +37,9 @@ function rho = SW_Density(T,S)
% 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.
%=========================================================================
global ftbverbose
......@@ -56,12 +60,16 @@ end
[mt,nt] = size(T);
% CHECK THAT S & T HAVE SAME SHAPE
if (ms~=mt) | (ns~=nt)
if (ms~=mt) || (ns~=nt)
error('check_stp: S & T must have same dimensions')
end
% CHECK THAT S & T ARE WITHIN THE FUNCTION RANGE
vectorsize=size(S);
s = nan(vectorsize);
rho_w = nan(vectorsize);
D_rho = nan(vectorsize);
rho = nan(vectorsize);
for i = 1:vectorsize(1,1)
for j = 1:vectorsize(1,2)
% if T(i,j)>180 | T(i,j)<0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment