source: Roms_tools/Preprocessing_tools/ztosigma.m @ 2

Last change on this file since 2 was 1, checked in by cholod, 13 years ago

import Roms_Agrif

File size: 2.2 KB
Line 
1function vnew = ztosigma(var,z,depth)
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3%
4% function  vnew = ztosigma(var,z,depth)
5%
6% This function transform a variable from z to sigma coordinates
7%    warning: the variable must be in the form: var(k,j,i)
8%
9% On Input:
10%
11%    var     Variable z (3D matrix).
12%    z       Sigma depths (m) of RHO- or W-points (3D matrix).
13%    depth   z depth (vector; meters, negative).
14%
15% On Output:
16%
17%    vnew    Variable sigma (3D matrix).
18%
19%  Further Information: 
20%  http://www.brest.ird.fr/Roms_tools/
21
22%  This file is part of ROMSTOOLS
23%
24%  ROMSTOOLS is free software; you can redistribute it and/or modify
25%  it under the terms of the GNU General Public License as published
26%  by the Free Software Foundation; either version 2 of the License,
27%  or (at your option) any later version.
28%
29%  ROMSTOOLS is distributed in the hope that it will be useful, but
30%  WITHOUT ANY WARRANTY; without even the implied warranty of
31%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32%  GNU General Public License for more details.
33%
34%  You should have received a copy of the GNU General Public License
35%  along with this program; if not, write to the Free Software
36%  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
37%  MA  02111-1307  USA
38%
39%  Copyright (c) 2001-2006 by Pierrick Penven
40%  e-mail:Pierrick.Penven@ird.fr 
41%
42%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43[Ns,Mp,Lp]=size(z);
44[Nz]=length(depth);
45%
46% Find the grid position of the nearest vertical levels
47%
48for ks=1:Ns
49  sigmalev=squeeze(z(ks,:,:,:));
50  thezlevs=0.*sigmalev;
51  for kz=1:Nz
52    thezlevs(sigmalev>depth(kz))=thezlevs(sigmalev>depth(kz))+1;
53  end
54  if max(max(thezlevs))>=Nz | min(min(thezlevs))<=0
55    disp(['min sigma level = ',num2str(min(min(min(z)))),...
56           ' - min z level = ',num2str(min(depth))])
57    disp(['max sigma level = ',num2str(max(max(max(z)))),...
58           ' - max z level = ',num2str(max(depth))])
59  end
60  [imat,jmat]=meshgrid((1:Lp),(1:Mp));
61  pos=Nz*Mp*(imat-1)+Nz*(jmat-1)+thezlevs;
62  z1=depth(thezlevs);
63  z2=depth(thezlevs+1);
64  v1=var(pos);
65  v2=var(pos+1);
66  vnew(ks,:,:)=(((v1-v2).*sigmalev+v2.*z1-v1.*z2)./(z1-z2));
67end
68return
Note: See TracBrowser for help on using the repository browser.