1 | function 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 | % |
---|
36 | ng=netcdf(grdname); |
---|
37 | h=ng{'h'}(:); |
---|
38 | close(ng); |
---|
39 | % |
---|
40 | % open the clim file |
---|
41 | % |
---|
42 | nc=netcdf(clmname,'write'); |
---|
43 | theta_s = nc{'theta_s'}(:); |
---|
44 | theta_b = nc{'theta_b'}(:); |
---|
45 | hc = nc{'hc'}(:); |
---|
46 | N = length(nc('s_rho')); |
---|
47 | % |
---|
48 | % open the oa file |
---|
49 | % |
---|
50 | noa=netcdf(oaname); |
---|
51 | z=-noa{zname}(:); |
---|
52 | t=noa{tname}(:); |
---|
53 | tlen=length(t); |
---|
54 | % |
---|
55 | % Get the sigma depths |
---|
56 | % |
---|
57 | zroms=zlevs(h,0.*h,theta_s,theta_b,hc,N,'r'); |
---|
58 | if type=='u' |
---|
59 | zroms=rho2u_3d(zroms); |
---|
60 | end |
---|
61 | if type=='v' |
---|
62 | zroms=rho2v_3d(zroms); |
---|
63 | end |
---|
64 | zmin=min(min(min(zroms))); |
---|
65 | zmax=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 | % |
---|
70 | addsurf=max(z)<zmax; |
---|
71 | addbot=min(z)>zmin; |
---|
72 | if addsurf |
---|
73 | z=[100;z]; |
---|
74 | end |
---|
75 | if addbot |
---|
76 | z=[z;-100000]; |
---|
77 | end |
---|
78 | Nz=min(find(z<zmin)); |
---|
79 | z=z(1:Nz); |
---|
80 | % |
---|
81 | % loop on time |
---|
82 | % |
---|
83 | % Are we processing initial file ? |
---|
84 | isinitial = 0; |
---|
85 | if (nargin > 8) |
---|
86 | isinitial = isinitialval; |
---|
87 | end |
---|
88 | |
---|
89 | if (isinitial == 1) % initial file |
---|
90 | tlen=1; |
---|
91 | end |
---|
92 | for 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 |
---|
118 | end |
---|
119 | close(nc); |
---|
120 | close(noa); |
---|
121 | return |
---|