source: trunk/src/interp_erai_t2m_1989_2009.pro @ 29

Last change on this file since 29 was 27, checked in by pinsard, 13 years ago

progress on interpolation tools (to be cont.)

File size: 9.7 KB
Line 
1;+
2;
3; .. _interp_erai_t2m_1989_2009.pro:
4;
5; ==================================================================================
6; interp_erai_t2m_1989_2009.pro - Interpolation of t2 from ERA-I grid to OAFLUX grid
7; ==================================================================================
8;
9; Interpolation of t2 from ERA-I grid to OAFLUX grid
10;
11; :file:`${TROPFLUX_ID}/20c3m_erai_t2_TROP_1989_2009.nc` containing t2 from ERA-I have been produced
12; by :ref:`compute_erai_daily_region_2d.sh`.
13;
14; :file:`${TROPFLUX_ID}/mask_oaflux_30N30S.nc` containing OAFLUX grid have been produced by :ref:`oaflux_mask_30N30S.pro`.
15;
16; Interpolated t2 is written in
17; :file:`${TROPFLUX_OD}/erai_t2m_19890101_20091231_oafluxgrid.nc` if this file not already exists.
18;
19; This output file :file:`${TROPFLUX_OD}/erai_t2m_19890101_20091231_oafluxgrid.nc` must be processed after by :ref:`t2m_correction_ncdf.pro`.
20;
21;
22;     .. graphviz::
23;
24;        digraph interp_erai_t2m_1989_2009 {
25;           graph [
26;           rankdir="TB",
27;           ]
28;           file_in [shape=ellipse,fontname=Courier,label="${TROPFLUX_ID}/20c3m_erai_t2_TROP_1989_2009.nc"];
29;           mask [shape=ellipse,fontname=Courier,label="${TROPFLUX_ID}/mask_oaflux_30N30S.nc"];
30;
31;           ncfile [shape=ellipse,fontname=Courier,label="${TROPFLUX_OD}/erai_t2m_19890101_20091231_oafluxgrid.nc"];
32;
33;           interp_erai_t2m_1989_2009 [shape=box,
34;           fontname=Courier,
35;           color=blue,
36;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_erai_t2m_1989_2009.pro"",
37;           label="${TROPFLUX}/src/interp_erai_t2m_1989_2009.pro"];
38;
39;           {file_in mask} -> {interp_erai_t2m_1989_2009} -> {ncfile}
40;
41;          }
42;
43;
44; SEE ALSO
45; ========
46;
47; :ref:`interpolate_data`
48;
49; :ref:`tropflux_profile.sh`
50;
51; :ref:`compute_erai_daily_region_2d.sh`
52;
53; :ref:`oaflux_mask_30N30S.pro`
54;
55; :func:`report <saxo:report>`
56; :func:`isadirectory <saxo:isadirectory>`
57; :func:`isafile <saxo:isafile>`
58; :func:`initncdf <saxo:initncdf>`
59; :func:`read_ncdf <saxo:read_ncdf>`
60; :func:`ncdf_lec <saxo:ncdf_lec>`
61; :func:`domdef <saxo:domdef>`
62; :func:`call_interp2d <saxo:call_interp2d>`
63; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
64; :func:`ncdf_getatt <saxo:ncdf_getatt>`
65;
66; :ref:`t2m_correction_ncdf.pro`
67;
68; EXAMPLES
69; ========
70;
71; ::
72;
73;  IDL> .compile file_interp
74;  IDL> interp_erai_t2m_1989_2009
75;
76;
77; TODO
78; ====
79;
80; strange view (lat and lon shift with ncview) : check grid init
81;
82; remove useless netcdf_read
83;
84; check time values
85;
86; why use :func:`call_interp2d <saxo:call_interp2d>` : this is an hidden function of SAXO
87; see :func:`file_interp <saxo:file_interp>`
88;
89; use as input a file produced by compute_erai_daily_region_2d.sh
90;
91; coding rules
92;
93; hard coded time in module name and in output filename
94;
95; why two "initncdf, fullfilename_msk"
96;
97; hard coded attributes for t2m (missing value, short name, axis) and time (origin) : use ncdf_getatt
98;
99; CF conventions
100;
101; KNOWN ISSUES
102; ============
103;
104; test of existence of fullfilename_msk not very efficient because
105; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
106;
107; EVOLUTIONS
108; ==========
109;
110; - fplod 20110103T153734Z aedon.locean-ipsl.upmc.fr (Darwin)
111;
112;   * computed first and last dates
113;   * start using ncdf_getatt instead of hard coded attributes
114;
115; - fplod 20101223T130406Z aedon.locean-ipsl.upmc.fr (Darwin)
116;
117;   * replace /Volumes/PRAVEEN/TropFlux/input_uncor/ by ${TROPFLUX_OD}
118;   * complete documentation
119;   * get time dimension in data file
120;   * replace read_ncdf by ncdf_lec
121;
122;     usage of timestep keyword in read_ncdf was not efficient because of  memory problem :
123;     can not read the whole time range (ok with 7580, not ok with 7591 while need is 7670
124;     ::
125;
126;       % Unable to allocate memory: to make array.
127;       Cannot allocate memory
128;
129;
130;     When timestep keyword is not used we can see these messages::
131;
132;        /usr/work/incas/fplod/tropflux_d/20c3m_erai_t2_TROP_1989_2009.nc as no time axis variable
133;        given by Praveen
134;
135;        Value of Julian date is out of allowed range
136;
137;        % Array used to subscript array contains out of range subscript: DATAIN
138;
139;
140; - fplod 20101222T163216Z aedon.locean-ipsl.upmc.fr (Darwin)
141;
142;   * replace /Volumes/PRAVEEN/ERAI_global by ${TROPFLUX_ID}
143;
144; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
145;
146;   * remove hard coded directory for mask_oaflux_30N30S.nc
147;
148; - fplod 20101215T112140Z aedon.locean-ipsl.upmc.fr (Darwin)
149;
150;   * add graph in header
151;
152; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
153;
154;   * minimal header
155;
156; - pbk 2008
157;
158;   * creation
159;
160;-
161pro interp_erai_t2m_1989_2009
162;
163@common
164;
165; check for input directory
166;
167; test if ${TROPFLUX_ID} defined
168tropflux_id_env=GETENV('TROPFLUX_ID')
169CASE tropflux_id_env OF
170    ''  :  BEGIN
171     msg = 'eee : ${TROPFLUX_ID} is not defined'
172     ras = report(msg)
173     STOP
174           END
175 ELSE: BEGIN
176     msg = 'iii : ${TROPFLUX_ID} is ' + tropflux_id_env
177     ras = report(msg)
178       END
179ENDCASE
180;
181iodirin = isadirectory(tropflux_id_env)
182;
183; existence and protection of ${TROPFLUX_ID}
184IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
185   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
186   ras = report(msg)
187   STOP
188ENDIF
189;
190; build mask filename
191filename_msk='mask_oaflux_30N30S.nc'
192;
193; check if this file exists
194fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
195IF fullfilename_msk[0] EQ '' THEN BEGIN
196   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
197   ras = report(msg)
198   STOP
199ENDIF
200;
201; build t2 filename
202filename_t2='20c3m_erai_t2_TROP_1989_2009.nc'
203;
204; check if this file exists
205fullfilename_t2 = isafile(iodirin + filename_t2, NEW=0, /MUST_EXIST)
206IF fullfilename_t2[0] EQ '' THEN BEGIN
207   msg = 'eee : the file ' + fullfilename_t2 + ' was not found.'
208   ras = report(msg)
209   STOP
210ENDIF
211;
212; test if ${TROPFLUX_OD} defined
213tropflux_od_env=GETENV('TROPFLUX_OD')
214CASE tropflux_od_env OF
215  '' : BEGIN
216         msg = 'eee : ${TROPFLUX_OD} is not defined'
217         ras = report(msg)
218       STOP
219       END
220  ELSE: BEGIN
221          msg = 'iii : ${TROPFLUX_OD} is ' + tropflux_od_env
222          ras = report(msg)
223        END
224 ENDCASE
225;
226; check if output data will be possible
227iodirout = isadirectory(tropflux_od_env)
228;
229; existence and protection
230IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
231    msg = 'eee : the directory' + iodirout  + ' was not found.'
232    ras = report(msg)
233    STOP
234ENDIF
235;
236; build output filename
237filename_out = 'erai_t2m_19890101_20091231_oafluxgrid.nc'
238fullfilename_out = iodirout + filename_out
239; in order to avoid unexpected overwritten
240IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
241   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
242   ras = report(msg)
243   STOP
244ENDIF
245;
246; define grid parameters with t2 file
247initncdf, fullfilename_t2
248domdef
249latin=reform(gphit(0,*))
250lonin=reform(glamt(*,0))
251print, 'lat grid from data',min(latin),max(latin),latin(1)-latin(0)
252print, 'lon grid from data',min(lonin),max(lonin),lonin(1)-lonin(0)
253;
254; get time in t2 file
255timein=ncdf_lec(fullfilename_t2,var='time')
256jptin=n_elements(timein)
257print, 'time steps from data ', jptin
258print, 'The first 10 time values (variable timein) = ', timein[0:9]
259;
260; find first and last dates yyyymmdd
261; they will be written in global attributes of output file
262da=jul2date(julday(01, 01, 1957,timein[0]))
263cda0=string(da,format='(i8.8)')
264da=jul2date(julday(01, 01, 1957,timein[jptin-1]))
265cda1=string(da,format='(i8.8)')
266print, 'first date ', cda0
267print, 'last date ' , cda1
268
269; read t2 data
270;++ pb memory t2min=read_ncdf("t2",0,jptin-1,/timestep,file=fullfilename_t2,/nostr)
271; the following line is here just to prepare replacement of read_ncdf by ncdf_lec
272t2min_read_ncdf=read_ncdf("t2",0,10,/timestep,file=fullfilename_t2,/nostr)
273help, t2min_read_ncdf
274;++print, 'The first 10 time values (variable time) = ', time[0:9]
275;++print, 'time steps after read_ncdf (variable jpt) ', jpt
276t2min=ncdf_lec(fullfilename_t2,var='t2')
277;
278mskin=glamt*0.+1.
279
280; define grid parameters with mask file
281initncdf, fullfilename_msk
282domdef
283latout=reform(gphit(0,*))
284lonout=reform(glamt(*,0))
285print, 'lat grid from mask ',min(latout),max(latout),latout(1)-latout(0)
286print, 'lon grid from mask ',min(lonout),max(lonout),lonout(1)-lonout(0)
287mskout=read_ncdf("msk", file=fullfilename_msk,/nostr)
288;
289help, t2min,lonin,latin,mskin,lonout,latout,mskout
290;
291; interpolation and mask
292t2mout=fltarr(jpi,jpj,jptin)
293for jt=0,jptin-1 do begin
294  tab=reform(t2min(*,*,jt))
295  t2mout(*,*,jt)=call_interp2d(tab,lonin,latin,mskin,lonout,latout,method='bilinear')
296  t2mout(*,*,jt)=t2mout(*,*,jt)*mskout+(1.-mskout)*1.e20
297endfor
298
299initncdf, fullfilename_msk
300
301lat=latout
302lon=lonout
303ncfile='!' + fullfilename_out
304print, 'ncfile ', ncfile
305ncdf_getatt, fullfilename_msk, 'longitude', units=units
306ncdf_getatt, fullfilename_msk, 'longitude', long_name=long_name
307lon_attr={units:units, long_name:long_name}
308ncdf_getatt, fullfilename_msk, 'latitude', units=units
309ncdf_getatt, fullfilename_msk, 'latitude', long_name=long_name
310lat_attr={units:units, long_name:long_name}
311ncdf_getatt, fullfilename_t2, 'time', units=units
312ncdf_getatt, fullfilename_t2, 'time', long_name=long_name
313time_attr={units:units, long_name:long_name, time_origin:' 1957-JAN-01 00:00:00'}
314ncdf_getatt, fullfilename_t2, 't2', units=units
315ncdf_getatt, fullfilename_t2, 't2', long_name=long_name
316t2m_attr={units:units, long_name:long_name, missing_value:1e20, short_name:'t2m',axis:'TYX'}
317globattr={source:'Data are from ECMWF ERA-Interim reanalysis', timerange:cda0+' - '+cda1}
318
319
320ncfields = 't2m[longitude,latitude,time]=t2mout:t2m_attr; ' $
321                      + 'longitude[]=lon:lon_attr; ' $
322                      + 'latitude[]=lat:lat_attr; ' $
323                      + 'time[*time]=timein:time_attr ' $
324                      + ' @ globattr'
325
326@ncdf_quickwrite
327
328
329end
Note: See TracBrowser for help on using the repository browser.