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