source: Roms_tools/Preprocessing_tools/vinterp_clm.m @ 2

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

import Roms_Agrif

File size: 2.7 KB
Line 
1function vinterp(clmname,grdname,oaname,vname,tname,zname,tini,...
2                 type,isinitialval);
3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4%
5%  Vertical interpolation from a Z-grid to a sigma-grid in the
6%  case of climatology files.
7%
8%  Further Information: 
9%  http://www.brest.ird.fr/Roms_tools/
10
11%  This file is part of ROMSTOOLS
12%
13%  ROMSTOOLS is free software; you can redistribute it and/or modify
14%  it under the terms of the GNU General Public License as published
15%  by the Free Software Foundation; either version 2 of the License,
16%  or (at your option) any later version.
17%
18%  ROMSTOOLS is distributed in the hope that it will be useful, but
19%  WITHOUT ANY WARRANTY; without even the implied warranty of
20%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21%  GNU General Public License for more details.
22%
23%  You should have received a copy of the GNU General Public License
24%  along with this program; if not, write to the Free Software
25%  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26%  MA  02111-1307  USA
27%
28%  Copyright (c) 2003-2006 by Pierrick Penven
29%  e-mail:Pierrick.Penven@ird.fr 
30%
31%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32
33%
34% open the grid file 
35%
36ng=netcdf(grdname);
37h=ng{'h'}(:);
38close(ng);
39%
40% open the clim file 
41%
42nc=netcdf(clmname,'write');
43theta_s = nc{'theta_s'}(:);
44theta_b =  nc{'theta_b'}(:);
45hc  =  nc{'hc'}(:);
46N =  length(nc('s_rho'));
47%
48% open the oa file 
49%
50noa=netcdf(oaname);
51z=-noa{zname}(:);
52t=noa{tname}(:);
53tlen=length(t);
54%
55% Get the sigma depths
56%
57zroms=zlevs(h,0.*h,theta_s,theta_b,hc,N,'r');
58if type=='u'
59  zroms=rho2u_3d(zroms);
60end
61if type=='v'
62  zroms=rho2v_3d(zroms);
63end
64zmin=min(min(min(zroms)));
65zmax=max(max(max(zroms)));
66%
67% Check if the min z level is below the min sigma level
68%    (if not add a deep layer)
69%
70addsurf=max(z)<zmax;
71addbot=min(z)>zmin;
72if addsurf
73 z=[100;z];
74end
75if addbot
76 z=[z;-100000];
77end
78Nz=min(find(z<zmin));
79z=z(1:Nz);
80%
81% loop on time
82%
83% Are we processing initial file ?
84isinitial = 0;
85if (nargin > 8)
86isinitial = isinitialval;
87end
88
89if (isinitial == 1)  % initial file
90  tlen=1;
91end
92for l=1:tlen
93%for l=1:1
94  if (isinitial == 0)
95    disp([' Time index: ',num2str(l),' of total: ',num2str(tlen)])
96  else
97    ll=find(t<=tini);
98    if (size(ll,1) ~= 0)
99    l=ll(size(ll,1));
100    else
101    l=1;
102    end
103    disp([' Time index: ',num2str(l)])
104  end
105  var=squeeze(noa{vname}(l,:,:,:));
106  if addsurf
107    var=cat(1,var(1,:,:),var);
108  end
109  if addbot
110    var=cat(1,var,var(end,:,:));
111  end
112  var=var(1:Nz,:,:);
113  if (isinitial == 0)
114    nc{vname}(l,:,:,:)=ztosigma(flipdim(var,1),zroms,flipud(z));
115  else
116    nc{vname}(1,:,:,:)=ztosigma(flipdim(var,1),zroms,flipud(z));
117  end
118end
119close(nc);
120close(noa);
121return
Note: See TracBrowser for help on using the repository browser.