source: Roms_tools/Forecast_tools/download_GFS.m @ 8

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

patch_romstools_15_04_2011.tar : UPDATES of Nesting_tools, Diagnostics_tools, Oforc_OGCM, Preprocessing_tools and Forecast_tools

File size: 8.0 KB
Line 
1function download_GFS(today,lonmin,lonmax,latmin,latmax,FRCST_dir,Yorig,it)
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3%
4%  download_GFS(today,lonmin,lonmax,latmin,latmax,FRCST_dir,Yorig)
5%
6%
7%  Extract a subgrid from GFS to get a ROMS forcing
8%  Store that into monthly files (to limit the problems
9%  of bandwith...).
10%  Take care of the Greenwitch Meridian.
11%  Transform variables in the ROMS format.
12%
13%
14%  Further Information: 
15%  http://www.brest.ird.fr/Roms_tools/
16
17%  This file is part of ROMSTOOLS
18%
19%  ROMSTOOLS is free software; you can redistribute it and/or modify
20%  it under the terms of the GNU General Public License as published
21%  by the Free Software Foundation; either version 2 of the License,
22%  or (at your option) any later version.
23%
24%  ROMSTOOLS is distributed in the hope that it will be useful, but
25%  WITHOUT ANY WARRANTY; without even the implied warranty of
26%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27%  GNU General Public License for more details.
28%
29%  You should have received a copy of the GNU General Public License
30%  along with this program; if not, write to the Free Software
31%  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32%  MA  02111-1307  USA
33%
34%  Copyright (c) 2006 by Pierrick Penven
35%  e-mail:Pierrick.Penven@ird.fr 
36%
37%  Updated    9-Sep-2006 by Pierrick Penven
38%  Updated    20-Aug-2008 by Matthieu Caillaud & P. Marchesiello
39%
40%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41romstools_param
42
43%
44% Put the date in 'Yorig' time
45%
46rundate=datenum(today)-datenum(Yorig,1,1);
47%
48% GFS output name
49%
50gfs_name=[FRCST_dir,'GFS_',num2str(rundate),'.nc'];
51%
52% start
53%
54disp([' '])
55disp(['Get GFS data for ',datestr(today)])
56disp(['Minimum Longitude: ',num2str(lonmin)])
57disp(['Maximum Longitude: ',num2str(lonmax)])
58disp(['Minimum Latitude: ',num2str(latmin)])
59disp(['Maximum Latitude: ',num2str(latmax)])
60disp([' '])
61%
62% Create the directory
63%
64disp(['Making output data directory ',FRCST_dir])
65eval(['!mkdir ',FRCST_dir])
66%
67% Get the GFS file name (first check if there is an available forecast)
68%
69gfs_run_time0=0;
70gfs_date0=today-0.5;
71gfs_run_time=gfs_run_time0;
72gfs_date=gfs_date0;
73foundfile=0;
74while foundfile==0
75  fname=get_GFS_fname(gfs_date,gfs_run_time,1);
76  warning off
77  try
78    x=loaddap('-A -e +v ', fname);
79    foundfile=1;
80  catch
81    foundfile=0;
82  end
83  if foundfile==1 & ~isempty(x)
84    disp('  File found')
85  else
86    foundfile=0;
87    disp(['  GFS : did not found ',fname])
88    gfs_run_time=gfs_run_time-6;
89    if gfs_run_time<0
90      gfs_date=gfs_date-1;
91      gfs_run_time=18;
92      if gfs_date<gfs_date0-8;
93        error(['  GFS: did not found anything'])
94      end
95    end
96  end
97  warning on
98end
99%
100% Get the grid and the indices of the subgrid for GFS
101%
102gfs_run_time_GFS=gfs_run_time;
103gfs_date_GFS=gfs_date; 
104fname=get_GFS_fname(gfs_date_GFS,gfs_run_time_GFS,1);
105[i1min,i1max,i2min,i2max,i3min,i3max,jrange,lon,lat]=...
106         get_GFS_subgrid(fname,lonmin,lonmax,latmin,latmax);
107mask=getdap('',fname,'landsfc','[1:1]','',jrange,...
108             i1min,i1max,i2min,i2max,i3min,i3max);
109mask(mask==1)=NaN;
110mask(isfinite(mask))=1;
111%
112% Initialisation
113N=70;
114[M,L]=size(mask);
115tx=zeros(N,M,L);
116ty=tx;
117tair=tx;
118rhum=tx;
119prate=tx;
120wspd=tx;
121radlw=tx;
122radsw=tx;
123radlw_in=tx;
124uwnd=tx;
125vwnd=tx;
126%
127n=0;
128gfstime=0*(1:N);
129LON=lon;
130LAT=lat;
131%
132%==================================================
133% Get the variables for hindcast
134%==================================================
135%
136% Get GDAS 1 deg grid
137%
138gfs_run_time=12;
139gfs_date=today-(hdays+1);
140fname=get_GFS_fname(gfs_date,gfs_run_time,0);
141[i1min,i1max,i2min,i2max,i3min,i3max,jrange,lon,lat]=...
142         get_GFS_subgrid(fname,lonmin,lonmax,latmin,latmax);
143mask=getdap('',fname,'landsfc','[1:1]','',jrange,...
144             i1min,i1max,i2min,i2max,i3min,i3max);
145mask(mask==1)=NaN;
146mask(isfinite(mask))=1;
147%
148% Loop on GDAS analyses
149% (starts hdays day ago 18Z, 1 analysis every 6h
150%  ends before yesterday 18Z).
151%
152gfs_run_time0=12;
153gfs_date0=today-(hdays+1);
154for frcst=1:4*hdays-3             % number of files until before yesterday 18Z
155  gfs_run_time0=gfs_run_time0+6; 
156  if gfs_run_time0>18
157    gfs_date0=gfs_date0+1;
158    gfs_run_time0=0;
159  end
160%
161% 1.1: check if the GDAS is available.
162%
163  gfs_run_time=gfs_run_time0;
164  gfs_date=gfs_date0;
165  t1=1;
166  t1dap=t1-1;
167  fname=get_GFS_fname(gfs_date,gfs_run_time,0);
168  warning off
169  try
170    x=loaddap('-A -e +v ', fname);
171    foundfile=1;
172  catch
173    foundfile=0;
174  end
175  if foundfile==1 & ~isempty(x)
176    disp('  File found')
177    gfs_run_time1=gfs_run_time0;  % Increment Forecast
178    gfs_date1=gfs_date0;          %           start time
179  else
180    foundfile=0;
181    disp(['  GDAS: file not found, try next file'])
182%    error(['  GDAS: file not found'])
183  end
184  warning on
185%
186% 1.2: read file
187%
188  if foundfile,
189   missvalue=x.ugrd10m.missing_value;
190%
191   n=n+1;
192   [gfstime(n),tx0,ty0,tair0,rhum0,...
193         prate0,wspd0,uwnd0,vwnd0,radlw0,radlw_in0,radsw0]=...
194   get_GDAS(fname,mask,t1dap,jrange,i1min,i1max,i2min,i2max,i3min,i3max,missvalue);
195   TX=interp2(lon,lat',tx0,LON,LAT');
196   TY=interp2(lon,lat',ty0,LON,LAT');
197   TAIR=interp2(lon,lat',tair0,LON,LAT');
198   RHUM=interp2(lon,lat',rhum0,LON,LAT');
199   PRATE=interp2(lon,lat',prate0,LON,LAT');
200   WSPD=interp2(lon,lat',wspd0,LON,LAT');
201   UWND=interp2(lon,lat',uwnd0,LON,LAT');
202   VWND=interp2(lon,lat',vwnd0,LON,LAT');
203   RADLW=interp2(lon,lat',radlw0,LON,LAT');
204   RADLW_IN=interp2(lon,lat',radlw_in0,LON,LAT');
205   RADSW=interp2(lon,lat',radsw0,LON,LAT');
206   tx(n,:,:)=TX;
207   ty(n,:,:)=TY;
208   tair(n,:,:)=TAIR;
209   rhum(n,:,:)=RHUM;
210   prate(n,:,:)=PRATE;
211   wspd(n,:,:)=WSPD;
212   uwnd(n,:,:)=UWND;
213   vwnd(n,:,:)=VWND;
214   radlw(n,:,:)=RADLW;
215   radlw_in(n,:,:)=RADLW_IN;
216   radsw(n,:,:)=RADSW;
217%
218  end
219end
220%
221%==================================================================
222% 2: Get the variables for Forecast starting  yesterday 00Z
223%==================================================================
224gfs_run_time0=gfs_run_time1+6;
225gfs_date0=gfs_date1;
226  if gfs_run_time0>18
227    gfs_date0=gfs_date0+1;
228    gfs_run_time0=0;
229  end
230gfs_run_time=gfs_run_time0;
231gfs_date=gfs_date0;
232
233% Get the grid and the indices of the subgrid for GFS
234fname=get_GFS_fname(gfs_date,gfs_run_time,1);
235[i1min,i1max,i2min,i2max,i3min,i3max,jrange,lon,lat]=...
236         get_GFS_subgrid(fname,lonmin,lonmax,latmin,latmax);
237
238mask=getdap('',fname,'landsfc','[0:0]','',jrange,...
239             i1min,i1max,i2min,i2max,i3min,i3max);
240mask(mask==1)=NaN;
241mask(isfinite(mask))=1;
242[M,L]=size(mask);
243%
244% 2.1: check if the GFS forecast has been done for this time.
245% if not: take the previous one (but increment time index)
246%
247t1=1;
248foundfile=0;
249while foundfile==0
250  fname=get_GFS_fname(gfs_date,gfs_run_time,1);
251  warning off
252  try
253    x=loaddap('-A -e +v ', fname);
254    foundfile=1;
255  catch
256    foundfile=0;
257  end
258  if foundfile==1 & ~isempty(x)
259    disp('  File found')
260  else
261    foundfile=0;
262    disp(['  GFS : did not found ',fname])
263    t1=t1+it; % increment time index
264    gfs_run_time=gfs_run_time-6;
265    if gfs_run_time<0
266      gfs_date=gfs_date-1;
267      gfs_run_time=18;
268      if gfs_date<gfs_date0-8;
269        error(['  GFS: did not found anything'])
270      end
271    end
272  end
273  warning on
274end
275%
276% 2.2: read 60 time steps (dt = 3h)
277%
278for tndx=t1:it:60
279  tndxdap=tndx-1;
280  n=n+1;
281  [gfstime(n),tx(n,:,:),ty(n,:,:),tair(n,:,:),rhum(n,:,:),...
282   prate(n,:,:),wspd(n,:,:),uwnd(n,:,:),vwnd(n,:,:),...
283   radlw(n,:,:),radlw_in(n,:,:),...
284   radsw(n,:,:)]=...
285   get_GFS(fname,mask,tndxdap,jrange,i1min,i1max,i2min,i2max,...
286           i3min,i3max,missvalue);
287end
288%
289% Reduce the matrices
290%
291gfstime=gfstime(1:n);
292tx=tx(1:n,:,:);
293ty=ty(1:n,:,:);
294tair=tair(1:n,:,:);
295rhum=rhum(1:n,:,:);
296prate=prate(1:n,:,:);
297wspd=wspd(1:n,:,:);
298uwnd=uwnd(1:n,:,:);
299vwnd=vwnd(1:n,:,:);
300radlw=radlw(1:n,:,:);
301radlw_in=radlw_in(1:n,:,:);
302radsw=radsw(1:n,:,:);
303%
304% Put the time in Yorig time
305%
306gfstime=gfstime-datenum(Yorig,1,1);
307%
308% Create the GFS output file and write everything down
309%
310mask(isnan(mask))=0;
311write_GFS(gfs_name,Yorig,lon,lat,mask,gfstime,tx,ty,tair,rhum,prate,wspd,uwnd,vwnd,radlw,radlw_in,radsw)
312%
313disp('Download GFS: done')
314%
315return
316
317
318
319
Note: See TracBrowser for help on using the repository browser.