1 | function bry_interp(zbryname,lon,lat,seas_datafile,ann_datafile,... |
---|
2 | dataname,vname,obcndx,Roa); |
---|
3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
4 | % |
---|
5 | % function bry_interp(zbryname,lon,lat,seas_datafile,ann_datafile,... |
---|
6 | % dataname,vname,obcndx,Roa); |
---|
7 | % |
---|
8 | % Interpole data for the lateral boundaries (bry_file) along |
---|
9 | % horizontal z levels. |
---|
10 | % |
---|
11 | % Further Information: |
---|
12 | % http://www.brest.ird.fr/Roms_tools/ |
---|
13 | % |
---|
14 | % This file is part of ROMSTOOLS |
---|
15 | % |
---|
16 | % ROMSTOOLS is free software; you can redistribute it and/or modify |
---|
17 | % it under the terms of the GNU General Public License as published |
---|
18 | % by the Free Software Foundation; either version 2 of the License, |
---|
19 | % or (at your option) any later version. |
---|
20 | % |
---|
21 | % ROMSTOOLS is distributed in the hope that it will be useful, but |
---|
22 | % WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
23 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
24 | % GNU General Public License for more details. |
---|
25 | % |
---|
26 | % You should have received a copy of the GNU General Public License |
---|
27 | % along with this program; if not, write to the Free Software |
---|
28 | % Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
---|
29 | % MA 02111-1307 USA |
---|
30 | % |
---|
31 | % Copyright (c) 2001-2006 by Pierrick Penven |
---|
32 | % e-mail:Pierrick.Penven@ird.fr |
---|
33 | % |
---|
34 | % Updated 5-Oct-2006 by Pierrick Penven (test for negative salinity) |
---|
35 | % |
---|
36 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
37 | [M,L]=size(lon); |
---|
38 | % |
---|
39 | % set the default value if no data |
---|
40 | % |
---|
41 | default=NaN; |
---|
42 | % |
---|
43 | % Read in the datafile |
---|
44 | % |
---|
45 | ncseas=netcdf(seas_datafile); |
---|
46 | X=ncseas{'X'}(:); |
---|
47 | Y=ncseas{'Y'}(:); |
---|
48 | Zseas=-ncseas{'Z'}(:); |
---|
49 | T=ncseas{'T'}(:); |
---|
50 | tlen=length(T); |
---|
51 | Nzseas=length(Zseas); |
---|
52 | % |
---|
53 | % get the boundary position |
---|
54 | % |
---|
55 | if obcndx==1 |
---|
56 | % |
---|
57 | % Southern boundary |
---|
58 | % |
---|
59 | iroms=(1:L); |
---|
60 | jroms=1; |
---|
61 | elseif obcndx==2 |
---|
62 | % |
---|
63 | % Eastern boundary |
---|
64 | % |
---|
65 | iroms=L; |
---|
66 | jroms=(1:M); |
---|
67 | elseif obcndx==3 |
---|
68 | % |
---|
69 | % Northern boundary |
---|
70 | % |
---|
71 | iroms=(1:L); |
---|
72 | jroms=M; |
---|
73 | elseif obcndx==4 |
---|
74 | % |
---|
75 | % Western boundary |
---|
76 | % |
---|
77 | iroms=1; |
---|
78 | jroms=(1:M); |
---|
79 | end |
---|
80 | % |
---|
81 | lon=lon(jroms,iroms); |
---|
82 | lat=lat(jroms,iroms); |
---|
83 | % |
---|
84 | % get a data subgrid (dependant of the OBC used) |
---|
85 | % |
---|
86 | dl=1.6; |
---|
87 | lonmin=min(min(lon))-dl; |
---|
88 | lonmax=max(max(lon))+dl; |
---|
89 | latmin=min(min(lat))-dl; |
---|
90 | latmax=max(max(lat))+dl; |
---|
91 | % |
---|
92 | j=find(Y>=latmin & Y<=latmax); |
---|
93 | i1=find(X-360>=lonmin & X-360<=lonmax); |
---|
94 | i2=find(X>=lonmin & X<=lonmax); |
---|
95 | i3=find(X+360>=lonmin & X+360<=lonmax); |
---|
96 | x=cat(1,X(i1)-360,X(i2),X(i3)+360); |
---|
97 | y=Y(j); |
---|
98 | % |
---|
99 | % Open the Z-boundary file |
---|
100 | % |
---|
101 | nc=netcdf(zbryname,'write'); |
---|
102 | Z=-nc{'Z'}(:); |
---|
103 | Nz=length(Z); |
---|
104 | % |
---|
105 | % Check the time |
---|
106 | % |
---|
107 | tbry=nc{'bry_time'}(:); |
---|
108 | T=T*30; % if time in month in the dataset !!! |
---|
109 | if (tbry~=T) |
---|
110 | error(['time mismatch tbry = ',num2str(tbry),... |
---|
111 | ' t = ',num2str(T)]) |
---|
112 | end |
---|
113 | % |
---|
114 | % Read the annual dataset |
---|
115 | % |
---|
116 | if Nz > Nzseas |
---|
117 | ncann=netcdf(ann_datafile); |
---|
118 | zann=-ncann{'Z'}(1:Nz); |
---|
119 | if (Z~=zann) |
---|
120 | error('Vertical levels mismatch') |
---|
121 | end |
---|
122 | % |
---|
123 | % Interpole the annual dataset on the horizontal ROMS grid |
---|
124 | % |
---|
125 | disp(' Ext tracers: horizontal interpolation of the annual data') |
---|
126 | if Zseas~=zann(1:length(Zseas)) |
---|
127 | error('vertical levels dont match') |
---|
128 | end |
---|
129 | dims=size(lon); |
---|
130 | datazgrid=zeros(Nz,length(lon)); |
---|
131 | missval=ncann{dataname}.missing_value(:); |
---|
132 | for k=Nzseas+1:Nz |
---|
133 | if ~isempty(i2) |
---|
134 | data=squeeze(ncann{dataname}(k,j,i2)); |
---|
135 | else |
---|
136 | data=[]; |
---|
137 | end |
---|
138 | if ~isempty(i1) |
---|
139 | data=cat(2,squeeze(ncann{dataname}(k,j,i1)),data); |
---|
140 | end |
---|
141 | if ~isempty(i3) |
---|
142 | data=cat(2,data,squeeze(ncann{dataname}(k,j,i3))); |
---|
143 | end |
---|
144 | data=get_missing_val(x,y,data,missval,Roa,default); |
---|
145 | if dims(1)==1 |
---|
146 | datazgrid(k,:)=interp2(x,y,data,lon,lat,'cubic'); |
---|
147 | else |
---|
148 | datazgrid(k,:)=(interp2(x,y,data,lon,lat,'cubic'))'; |
---|
149 | end |
---|
150 | end |
---|
151 | close(ncann); |
---|
152 | end |
---|
153 | % |
---|
154 | % interpole the seasonal dataset on the horizontal roms grid |
---|
155 | % |
---|
156 | disp([' Ext tracers: horizontal interpolation of the seasonal data']) |
---|
157 | % |
---|
158 | % loop on time |
---|
159 | % |
---|
160 | missval=ncseas{dataname}.missing_value(:); |
---|
161 | for l=1:tlen |
---|
162 | %for l=1:1 |
---|
163 | disp(['time index: ',num2str(l),' of total: ',num2str(tlen)]) |
---|
164 | if Nz <= Nzseas |
---|
165 | datazgrid=zeros(Nz,M,L); |
---|
166 | end |
---|
167 | for k=1:min([Nz Nzseas]) |
---|
168 | if ~isempty(i2) |
---|
169 | data=squeeze(ncseas{dataname}(l,k,j,i2)); |
---|
170 | else |
---|
171 | data=[]; |
---|
172 | end |
---|
173 | if ~isempty(i1) |
---|
174 | data=cat(2,squeeze(ncseas{dataname}(l,k,j,i1)),data); |
---|
175 | end |
---|
176 | if ~isempty(i3) |
---|
177 | data=cat(2,data,squeeze(ncseas{dataname}(l,k,j,i3))); |
---|
178 | end |
---|
179 | data=get_missing_val(x,y,data,missval,Roa,default); |
---|
180 | if dims(1)==1 |
---|
181 | datazgrid(k,:)=interp2(x,y,data,lon,lat,'cubic'); |
---|
182 | else |
---|
183 | datazgrid(k,:)=(interp2(x,y,data,lon,lat,'cubic'))'; |
---|
184 | end |
---|
185 | end |
---|
186 | % |
---|
187 | % Test for salinity (no negative salinity !) |
---|
188 | % |
---|
189 | if strcmp(vname,'salt_south') | strcmp(vname,'salt_north') | ... |
---|
190 | strcmp(vname,'salt_east') | strcmp(vname,'salt_west') |
---|
191 | disp('salinity test') |
---|
192 | datazgrid(datazgrid<2)=2; |
---|
193 | end |
---|
194 | % |
---|
195 | nc{vname}(l,:,:,:)=datazgrid; |
---|
196 | end |
---|
197 | close(nc); |
---|
198 | close(ncseas); |
---|
199 | return |
---|
200 | |
---|