source: Roms_tools/Preprocessing_tools/bry_interp.m @ 2

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

import Roms_Agrif

File size: 4.7 KB
Line 
1function 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%
41default=NaN;
42%
43% Read in the datafile
44%
45ncseas=netcdf(seas_datafile);
46X=ncseas{'X'}(:);
47Y=ncseas{'Y'}(:);
48Zseas=-ncseas{'Z'}(:);
49T=ncseas{'T'}(:);
50tlen=length(T);
51Nzseas=length(Zseas);
52%
53% get the boundary position
54%
55if obcndx==1
56%
57% Southern boundary
58%
59  iroms=(1:L);
60  jroms=1;
61elseif obcndx==2
62%
63% Eastern boundary
64%
65  iroms=L;
66  jroms=(1:M);
67elseif obcndx==3
68%
69% Northern boundary
70%
71  iroms=(1:L);
72  jroms=M;
73elseif obcndx==4
74%
75% Western boundary
76%
77  iroms=1;
78  jroms=(1:M);
79end
80%
81lon=lon(jroms,iroms);
82lat=lat(jroms,iroms);
83%
84% get a data subgrid (dependant of the OBC used)
85%
86dl=1.6;
87lonmin=min(min(lon))-dl;
88lonmax=max(max(lon))+dl;
89latmin=min(min(lat))-dl;
90latmax=max(max(lat))+dl;
91%
92j=find(Y>=latmin & Y<=latmax);
93i1=find(X-360>=lonmin & X-360<=lonmax);
94i2=find(X>=lonmin & X<=lonmax);
95i3=find(X+360>=lonmin & X+360<=lonmax);
96x=cat(1,X(i1)-360,X(i2),X(i3)+360);
97y=Y(j);
98%
99% Open the Z-boundary file
100%
101nc=netcdf(zbryname,'write');
102Z=-nc{'Z'}(:);
103Nz=length(Z);
104%
105% Check the time
106%
107tbry=nc{'bry_time'}(:);
108T=T*30; % if time in month in the dataset !!!
109if (tbry~=T)
110  error(['time mismatch  tbry = ',num2str(tbry),...
111         '  t = ',num2str(T)])
112end
113%
114% Read the annual dataset
115%
116if 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);
152end
153%
154% interpole the seasonal dataset on the horizontal roms grid
155%
156disp([' Ext tracers: horizontal interpolation of the seasonal data'])
157%
158% loop on time
159%
160missval=ncseas{dataname}.missing_value(:);
161for 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;
196end
197close(nc);
198close(ncseas);
199return
200
Note: See TracBrowser for help on using the repository browser.