source: trunk/src/interp_erai_t2m_1989_2009.pro @ 26

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

progess on interpolation tools (to be cont.)

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