source: Roms_tools/Preprocessing_tools/ext_data_pathfinder.m @ 1

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

import Roms_Agrif

File size: 2.0 KB
Line 
1function data=ext_data(datafile,dataname,tindex,lon,lat,time)
2%
3% Read a data file and extrapole 1 horizontal
4% slice on a ROMS grid
5%
6disp(['Getting ',dataname,' for time index ',num2str(tindex)])
7%
8%
9%
10ro=1e8;
11default=NaN;
12%
13%
14%
15dl=1;
16lonmin=min(min(lon))-dl;
17lonmax=max(max(lon))+dl;
18latmin=min(min(lat))-dl;
19latmax=max(max(lat))+dl;
20%
21% Open the data file
22%
23ncdat=netcdf(datafile);
24
25%
26% Get attributes
27%
28missval=ncdat{dataname}.missing_value(:);
29if isempty(missval)
30  missval=nan;
31end
32add_offset=ncdat{dataname}.add_offset(:);
33scale_factor=ncdat{dataname}.scale_factor(:);
34ndims=length(dim(ncdat{dataname}));
35%
36% Get lon,lat,t
37%
38X=ncdat{'X'}(:);
39Y=ncdat{'Y'}(:);
40T=30*ncdat{'T'}(tindex)-15;
41if T~=time
42  disp(['Warning incorrect time :',dataname,...
43       ' - ',num2str(tindex),...
44       ' - ',num2str(T),...
45       ' - ',num2str(time)])
46end
47%
48% get a subgrid
49%
50j=find(Y>=latmin & Y<=latmax);
51i1=find(X-360>=lonmin & X-360<=lonmax);
52i2=find(X>=lonmin & X<=lonmax);
53i3=find(X+360>=lonmin & X+360<=lonmax);
54x=cat(1,X(i1)-360,X(i2),X(i3)+360);
55y=Y(j);
56%
57%  Read data
58%
59if ~isempty(i2)
60  if ndims==3
61    data=squeeze(ncdat{dataname}(tindex,j,i2));
62  elseif ndims==4
63    data=squeeze(ncdat{dataname}(tindex,1,j,i2));
64  else
65    error(['Bad dimension number ',num2str(ndims)])
66  end
67else
68  data=[];
69end
70if ~isempty(i1)
71  if ndims==3
72    data=cat(2,squeeze(ncdat{dataname}(tindex,j,i1)),data);
73  elseif ndims==4
74    data=cat(2,squeeze(ncdat{dataname}(tindex,1,j,i1)),data);
75  else
76    error(['Bad dimension number ',num2str(ndims)])
77  end
78end
79if ~isempty(i3)
80  if ndims==3
81    data=cat(2,data,squeeze(ncdat{dataname}(tindex,j,i3)));
82  elseif ndims==4
83    data=cat(2,data,squeeze(ncdat{dataname}(tindex,1,j,i3)));
84  else
85    error(['Bad dimension number ',num2str(ndims)])
86  end
87end
88close(ncdat)
89%
90% Perform the extrapolation
91%
92lon
93  lat
94  x
95y
96stop
97
98data=get_missing_val(x,y,data,missval,ro,default);
99%
100% Interpolation on the ROMS grid
101%
102pcolor(data)
103
104data=interp2(x,y,data,lon,lat,'linear');
105%
106% Apply offset
107%
108if ~isempty(add_offset)
109  data=add_offset+data*scale_factor;
110end
111%
112return
Note: See TracBrowser for help on using the repository browser.