source: Roms_tools/Preprocessing_tools/bry_interp_pisces.m @ 2

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

import Roms_Agrif

File size: 4.6 KB
Line 
1function bry_interp_pisces(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%
35%
36%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37[M,L]=size(lon);
38%
39% set the value of ro (oa decorrelation scale [m])
40% and default (value if no data) ro=0; %ro=1e8;
41default=NaN;
42%
43% Read in the datafile
44%
45seas_datafile
46ncseas=netcdf(seas_datafile);
47X=ncseas{'X'}(:);
48Y=ncseas{'Y'}(:);
49Zseas=-ncseas{'Z'}(:);
50T=ncseas{'T'}(:);
51tlen=length(T);
52Nzseas=length(Zseas);
53%
54% get the boundary position
55%
56if obcndx==1
57%
58% Southern boundary
59%
60  iroms=(1:L);
61  jroms=1;
62elseif obcndx==2
63%
64% Eastern boundary
65%
66  iroms=L;
67  jroms=(1:M);
68elseif obcndx==3
69%
70% Northern boundary
71%
72  iroms=(1:L);
73  jroms=M;
74elseif obcndx==4
75%
76% Western boundary
77%
78  iroms=1;
79  jroms=(1:M);
80end
81%
82lon=lon(jroms,iroms);
83lat=lat(jroms,iroms);
84%
85% get a data subgrid (dependant of the OBC used)
86%
87dl=1.6;
88lonmin=min(min(lon))-dl;
89lonmax=max(max(lon))+dl;
90latmin=min(min(lat))-dl;
91latmax=max(max(lat))+dl;
92%
93j=find(Y>=latmin & Y<=latmax);
94i1=find(X-360>=lonmin & X-360<=lonmax);
95i2=find(X>=lonmin & X<=lonmax);
96i3=find(X+360>=lonmin & X+360<=lonmax);
97x=cat(1,X(i1)-360,X(i2),X(i3)+360);
98y=Y(j);
99%
100% Open the Z-boundary file
101%
102nc=netcdf(zbryname,'write');
103Z=-nc{'Z'}(:);
104Nz=length(Z);
105%
106% Check the time
107%
108tbry=nc{'bry_time'}(:);
109%Take care if tile in the WOAPISCES data files !!!
110T=(T-1)*30; % if time in month in the dataset !!!
111%tbry
112%T
113
114if (tbry~=T)
115  error(['time mismatch  tbry = ',num2str(tbry),...
116         '  t = ',num2str(T)])
117end
118%
119% Read the annual dataset if Nz > Nzseas
120%
121if Nz > Nzseas
122  ncann=netcdf(ann_datafile);
123  zann=-ncann{'Z'}(1:Nz);
124  if (Z~=zann)
125    error('Vertical levels mismatch')
126  end
127%
128% Interpole the annual dataset on the horizontal ROMS grid
129%
130  disp(' Ext tracers: horizontal interpolation of the annual data')
131  if Zseas~=zann(1:length(Zseas))
132    error('vertical levels dont match')
133  end
134  dims=size(lon);
135  datazgrid=zeros(Nz,length(lon));
136  missval=ncann{dataname}.missing_value(:);
137  for k=Nzseas+1:Nz
138    if ~isempty(i2)
139      data=squeeze(ncann{dataname}(k,j,i2));
140    else
141      data=[];
142    end
143    if ~isempty(i1)
144      data=cat(2,squeeze(ncann{dataname}(k,j,i1)),data);
145    end
146    if ~isempty(i3)
147      data=cat(2,data,squeeze(ncann{dataname}(k,j,i3)));
148    end
149    data=get_missing_val(x,y,data,missval,Roa,default);
150    if dims(1)==1
151      datazgrid(k,:)=interp2(x,y,data,lon,lat,'linear');
152    else
153      datazgrid(k,:)=(interp2(x,y,data,lon,lat,'linear'))';   
154    end
155  end
156  close(ncann);
157end
158
159%Else read seasonal datafile
160%
161% interpole the seasonal dataset on the horizontal roms grid
162%
163disp([' Ext tracers: horizontal interpolation of the seasonal data'])
164%
165% loop on time
166%
167missval=ncseas{dataname}.missing_value(:);
168for l=1:tlen
169%for l=1:1
170  disp(['time index: ',num2str(l),' of total: ',num2str(tlen)])
171  dims=size(lon);
172  if Nz <= Nzseas
173%    datazgrid=zeros(Nz,M,L);
174    datazgrid=zeros(Nz,length(lon));
175  end
176  for k=1:min([Nz Nzseas])
177    if ~isempty(i2)
178      data=squeeze(ncseas{dataname}(l,k,j,i2));
179    else
180      data=[];
181    end
182    if ~isempty(i1)
183      data=cat(2,squeeze(ncseas{dataname}(l,k,j,i1)),data);
184    end
185    if ~isempty(i3)
186      data=cat(2,data,squeeze(ncseas{dataname}(l,k,j,i3)));
187    end
188    data=get_missing_val(x,y,data,missval,Roa,default);
189    if dims(1)==1
190      datazgrid(k,:)=interp2(x,y,data,lon,lat,'linear');
191    else
192      datazgrid(k,:)=(interp2(x,y,data,lon,lat,'linear'))';   
193    end
194  end
195  nc{vname}(l,:,:,:)=datazgrid;
196end
197close(nc);
198close(ncseas);
199return
200
Note: See TracBrowser for help on using the repository browser.