Commit a16b380e authored by Pierre Cazenave's avatar Pierre Cazenave

Add a function description to match the format of the other tools in the...

Add a function description to match the format of the other tools in the toolbox. Also reformat the code to MATLAB standard format (indentation etc.)
parent 5175f32d
function dist = sigma_gen(nlev,dl,du,kl,ku,zkl,zku,h,hmin)
% Generate a generalised sigma coordinate distribution.
%
% Mobj = sigma_gen(nlev, dl, du, kl, ku, zkl, zku, h, hmin)
%
% DESCRIPTION:
% Generate a uniform or hybrid vertical sigma coordinate system.
%
% INPUT:
% nlev: Number of sigma levels (layers + 1)
% dl: The lower depth boundary from the bottom, down to which the
% coordinates are parallel with uniform thickness.
% du: The upper depth boundary from the surface, up to which the
% coordinates are parallel with uniform thickness.
% kl: ?
% ku: ?
% zkl: ?
% zku: ?
% h: Water depth.
% hmin: Minimum water depth.
%
% OUTPUT:
% dist: Generalised vertical sigma coordinate distribution.
%
% EXAMPLE USAGE:
% Mobj = sigma_gen(nlev, dl, du, kl, ku, zkl, zku, h, hmin)
%
% Author(s):
% Geoff Cowles (University of Massachusetts Dartmouth)
% Pierre Cazenave (Plymouth Marine Laboratory)
%
% Revision history
% 2013-04-23 Added help on the function and reformatted the code.
dist = nan(1, nlev);
if(h < hmin)
z(1) = 0.0;
dl2=0.001;
du2=0.001;
for k=1:nlev-1
x1 = dl2+du2;
x1 = x1*double(nlev-1-k)/double(nlev-1);
x1 = x1 - dl2;
x1 = tanh(x1);
x2 = tanh(dl2);
x3 = x2+tanh(du2);
z(k+1) = (x1+x2)/x3-1.0;
end;
else;
if h < hmin
dist(1) = 0.0;
dl2 = 0.001;
du2 = 0.001;
for k = 1:nlev-1
x1 = dl2+du2;
x1 = x1*double(nlev-1-k)/double(nlev-1);
x1 = x1 - dl2;
x1 = tanh(x1);
x2 = tanh(dl2);
x3 = x2+tanh(du2);
dist(k+1) = (x1+x2)/x3-1.0;
end
else
%dr=(h-sum(zku)-sum(zkl))/h/double(nlev-ku-kl-1);
dr=(h-du-dl)/h/double(nlev-ku-kl-1);
z(1) = 0.0;
for k=2:ku+1
z(k) = z(k-1)-zku(k-1)/h;
% fprintf('building z %f %f %f %f \n',z(k),zku(k-1),h,zku(k-1)/h)
end;
dr = (h-du-dl)/h/double(nlev-ku-kl-1);
dist(1) = 0.0;
for k=ku+2:nlev-kl
z(k)=z(k-1)-dr;
% fprintf('building z %f %f \n',z(k),dr)
end;
for k = 2:ku+1
dist(k) = dist(k-1)-zku(k-1)/h;
% fprintf('building z %f %f %f %f \n',z(k),zku(k-1),h,zku(k-1)/h)
end
for k = ku+2:nlev-kl
dist(k) = dist(k-1)-dr;
% fprintf('building z %f %f \n',z(k),dr)
end
kk = 0;
for k=nlev-kl+1:nlev
kk=kk+1;
z(k)=z(k-1)-zkl(kk)/h;
% fprintf('building z %f %f \n',z(k),zkl(kk))
end;
end;
dist = z;
for k = nlev-kl+1:nlev
kk = kk+1;
dist(k) = dist(k-1)-zkl(kk)/h;
% fprintf('building z %f %f \n',z(k),zkl(kk))
end
end
function dist = sigma_tanh(nlev,dl,du)
% Generate a tanh sigma coordinate distribution.
%
% Mobj = sigma_tanh(nlev, dl, du)
%
% DESCRIPTION:
% Generate a tanh vertical sigma coordinate distribution.
%
% INPUT:
% nlev: Number of sigma levels (layers + 1)
% dl: The lower depth boundary from the bottom, down to which the
% coordinates are parallel with uniform thickness.
% du: The upper depth boundary from the surface, up to which the
% coordinates are parallel with uniform thickness.
%
% OUTPUT:
% dist: Tanh vertical sigma coordinate distribution.
%
% EXAMPLE USAGE:
% Mobj = read_sigma(nlev, dl, du)
%
% Author(s):
% Geoff Cowles (University of Massachusetts Dartmouth)
% Pierre Cazenave (Plymouth Marine Laboratory)
%
% Revision history
% 2013-04-23 Added help on the function and reformatted the code.
z=0.0;
for k=1:nlev
x1=dl+du;
x1=x1*(nlev-1-k)/(nlev-1);
x1=x1-dl;
x1=tanh(x1);
x2=tanh(dl);
x3=x2+tanh(du);
z(k+1)=(x1+x2)/x3-1.0;
end;
dist = nan(1, nlev);
for k = 1:nlev
x1 = dl+du;
x1 = x1*(nlev-1-k)/(nlev-1);
x1 = x1-dl;
x1 = tanh(x1);
x2 = tanh(dl);
x3 = x2+tanh(du);
dist(k+1) = (x1+x2)/x3-1.0;
end
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