source: Roms_tools/Preprocessing_tools/ext_tracers2.m @ 2

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

import Roms_Agrif

File size: 3.0 KB
Line 
1function ext_tracers2(oaname,month_datafile,seas_datafile,...
2                      dataname,vname,tname);
3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4%
5%
6%  pierrick 2002
7%
8%  Ext tracers in a ROMS climatology file
9%  take monthly data for the upper levels and
10%  seasonnal data for the
11%  lower levels
12%
13%  input:
14%   
15%    oaname      : roms oa file to process (netcdf)
16%    month_datafile : regular longitude - latitude - z seasonal data
17%                    file used for the upper levels  (netcdf)
18%    seas_datafile  : regular longitude - latitude - z annual data
19%                    file used for the lower levels  (netcdf)
20%
21%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22disp(' ')
23%
24% set the value of ro (oa decorrelation scale [m])
25% and default (value if no data)
26%
27ro=1e8;
28default=NaN;
29disp([' Ext tracers: ro = ',num2str(ro/1000),...
30      ' km - default value = ',num2str(default)])
31%
32% Read in the datafile
33%
34ncmonth=netcdf(month_datafile);
35x=ncmonth{'X'}(:);
36y=ncmonth{'Y'}(:);
37zmonth=-ncmonth{'Z'}(:);
38t=ncmonth{'T'}(:);
39tlen=length(t);
40Nzmonth=length(zmonth);
41%
42% Open the grid file 
43%
44ng=netcdf(oaname);
45lon=ng{'lon_rho'}(:);
46lon(lon<0)=lon(lon<0)+360;
47lat=ng{'lat_rho'}(:);
48close(ng);
49[M,L]=size(lon);
50dl=0.5;
51minlon=min(min(lon))-dl;
52maxlon=max(max(lon))+dl;
53minlat=min(min(lat))-dl;
54maxlat=max(max(lat))+dl;
55imin=max(find(x<=minlon));
56imax=min(find(x>=maxlon));
57jmin=max(find(y<=minlat));
58jmax=min(find(y>=maxlat));
59x=x(imin:imax);
60y=y(jmin:jmax);
61%
62% Open the OA file 
63%
64nc=netcdf(oaname,'write');
65Z=-nc{'Z'}(:);
66Nz=length(Z);
67%
68% Check the time
69%
70tclim=nc{tname}(:);
71t=t*30; % if time in month in the dataset !!!
72if (tclim~=t)
73  disp('Warning !! time mismatch')
74  disp('  tclim = ')
75  tclim
76  disp('  t = ')
77  t
78end
79%
80% Read the seasonal dataset
81%
82if Nz > Nzmonth
83  ncseas=netcdf(seas_datafile);
84  zseas=-ncseas{'Z'}(1:Nz);
85  if (Z~=zseas)
86    error('Vertical levels mismatch')
87  end
88%
89% Interpole the seasonal dataset on the horizontal ROMS grid
90%
91  disp(' Ext tracers: horizontal interpolation of the annual data')
92  if zmonth~=zseas(1:length(zmonth))
93    error('vertical levels dont match')
94  end
95  datazgrid=zeros(Nz,M,L);
96  missval=ncseas{dataname}.missing_value(:);
97  for k=Nzmonth+1:Nz
98    data=squeeze(ncseas{dataname}(k,jmin:jmax,imin:imax));
99    data=get_missing_val(x,y,data,missval,ro,default);
100    datazgrid(k,:,:)=interp2(x,y,data,lon,lat,'cubic');
101  end
102  close(ncseas);
103end
104%
105% interpole the seasonal dataset on the horizontal roms grid
106%
107disp([' Ext tracers: horizontal interpolation of the seasonal data'])
108%
109% loop on time
110%
111missval=ncmonth{dataname}.missing_value(:);
112for l=1:tlen
113%for l=1:1
114  disp(['time index: ',num2str(l),' of total: ',num2str(tlen)])
115  if Nz <= Nzmonth
116    datazgrid=zeros(Nz,M,L);
117  end
118  for k=1:min([Nz Nzmonth])
119    data=squeeze(ncmonth{dataname}(l,k,jmin:jmax,imin:imax));
120    data=get_missing_val(x,y,data,missval,ro,default);
121    datazgrid(k,:,:)=interp2(x,y,data,lon,lat,'cubic');
122  end
123  nc{vname}(l,:,:,:)=datazgrid;
124end
125close(nc);
126close(ncmonth);
127return
Note: See TracBrowser for help on using the repository browser.