source: trunk/src/interp_erai_t2m_1989_2009.pro @ 46

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

improve IDL startup

File size: 11.6 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> @tropflux_init
74;  IDL> .compile file_interp
75;  IDL> interp_erai_t2m_1989_2009
76;
77;
78; TODO
79; ====
80;
81; strange view (lat and lon shift with ncview) : check grid init
82;
83; remove useless netcdf_read
84;
85; check time values
86;
87; why use :func:`call_interp2d <saxo:call_interp2d>` : this is an hidden function of SAXO
88; see :func:`file_interp <saxo:file_interp>`
89;
90; use as input a file produced by compute_erai_daily_region_2d.sh
91;
92; coding rules
93;
94; hard coded time in module name and in output filename
95;
96; why two "initncdf, fullfilename_msk"
97;
98; hard coded attributes for t2m (missing value, short name, axis) and time (origin) : use ncdf_getatt
99;
100; CF conventions
101;
102; KNOWN ISSUES
103; ============
104;
105; test of existence of fullfilename_msk not very efficient because
106; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
107;
108; EVOLUTIONS
109; ==========
110;
111; - fplod 20110103T153734Z aedon.locean-ipsl.upmc.fr (Darwin)
112;
113;   * computed first and last dates
114;   * start using ncdf_getatt instead of hard coded attributes
115;
116; - fplod 20101223T130406Z aedon.locean-ipsl.upmc.fr (Darwin)
117;
118;   * replace /Volumes/PRAVEEN/TropFlux/input_uncor/ by ${TROPFLUX_OD}
119;   * complete documentation
120;   * get time dimension in data file
121;   * replace read_ncdf by ncdf_lec
122;
123;     usage of timestep keyword in read_ncdf was not efficient because of  memory problem :
124;     can not read the whole time range (ok with 7580, not ok with 7591 while need is 7670
125;     ::
126;
127;       % Unable to allocate memory: to make array.
128;       Cannot allocate memory
129;
130;
131;     When timestep keyword is not used we can see these messages::
132;
133;        /usr/work/incas/fplod/tropflux_d/20c3m_erai_t2_TROP_1989_2009.nc as no time axis variable
134;        given by Praveen
135;
136;        Value of Julian date is out of allowed range
137;
138;        % Array used to subscript array contains out of range subscript: DATAIN
139;
140;
141; - fplod 20101222T163216Z aedon.locean-ipsl.upmc.fr (Darwin)
142;
143;   * replace /Volumes/PRAVEEN/ERAI_global by ${TROPFLUX_ID}
144;
145; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
146;
147;   * remove hard coded directory for mask_oaflux_30N30S.nc
148;
149; - fplod 20101215T112140Z aedon.locean-ipsl.upmc.fr (Darwin)
150;
151;   * add graph in header
152;
153; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
154;
155;   * minimal header
156;
157; - pbk 2008
158;
159;   * creation
160;
161;-
162pro interp_erai_t2m_1989_2009
163;
164@cm_4cal
165@cm_4data
166@cm_4mesh
167@cm_4data
168@cm_tropflux
169;
170; check for input directory
171;
172; test if ${TROPFLUX_ID} defined
173CASE tropflux_id_env OF
174    ''  :  BEGIN
175     msg = 'eee : ${TROPFLUX_ID} is not defined'
176     ras = report(msg)
177     STOP
178           END
179 ELSE: BEGIN
180     msg = 'iii : ${TROPFLUX_ID} is ' + tropflux_id_env
181     ras = report(msg)
182       END
183ENDCASE
184;
185iodirin = isadirectory(tropflux_id_env)
186;
187; existence and protection of ${TROPFLUX_ID}
188IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
189   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
190   ras = report(msg)
191   STOP
192ENDIF
193;
194; build mask filename
195filename_msk='mask_oaflux_30N30S.nc'
196;
197; check if this file exists
198fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
199IF fullfilename_msk[0] EQ '' THEN BEGIN
200   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
201   ras = report(msg)
202   STOP
203ENDIF
204;
205; build t2 filename
206filename_t2='20c3m_erai_t2_TROP_1989_2009.nc'
207;
208; check if this file exists
209fullfilename_t2 = isafile(iodirin + filename_t2, NEW=0, /MUST_EXIST)
210IF fullfilename_t2[0] EQ '' THEN BEGIN
211   msg = 'eee : the file ' + fullfilename_t2 + ' was not found.'
212   ras = report(msg)
213   STOP
214ENDIF
215;
216; test if ${TROPFLUX_OD} defined
217CASE tropflux_od_env OF
218  '' : BEGIN
219         msg = 'eee : ${TROPFLUX_OD} is not defined'
220         ras = report(msg)
221       STOP
222       END
223  ELSE: BEGIN
224          msg = 'iii : ${TROPFLUX_OD} is ' + tropflux_od_env
225          ras = report(msg)
226        END
227 ENDCASE
228;
229; check if output data will be possible
230iodirout = isadirectory(tropflux_od_env)
231;
232; existence and protection
233IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
234    msg = 'eee : the directory' + iodirout  + ' was not found.'
235    ras = report(msg)
236    STOP
237ENDIF
238;
239; build output filename
240filename_out = 'erai_t2m_19890101_20091231_oafluxgrid.nc'
241fullfilename_out = iodirout + filename_out
242; in order to avoid unexpected overwritten
243IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
244   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
245   ras = report(msg)
246   STOP
247ENDIF
248;
249; define grid parameters with t2 file
250initncdf, fullfilename_t2
251domdef
252latin=reform(gphit(0,*))
253lonin=reform(glamt(*,0))
254print, 'lat grid from data',min(latin),max(latin),latin(1)-latin(0)
255print, 'lon grid from data',min(lonin),max(lonin),lonin(1)-lonin(0)
256;
257; get time in t2 file
258timein=ncdf_lec(fullfilename_t2,var='time')
259jptin=n_elements(timein)
260print, 'time steps from data ', jptin
261print, 'The first 10 time values (variable timein) = ', timein[0:9]
262;
263; find first and last dates yyyymmdd
264; they will be written in global attributes of output file
265da=jul2date(julday(01, 01, 1957,timein[0]))
266cda0=string(da,format='(i8.8)')
267da=jul2date(julday(01, 01, 1957,timein[jptin-1]))
268cda1=string(da,format='(i8.8)')
269print, 'first date ', cda0
270print, 'last date ' , cda1
271
272; read t2 data
273;++ pb memory t2min=read_ncdf("t2",0,jptin-1,/timestep,file=fullfilename_t2,/nostr)
274; the following line is here just to prepare replacement of read_ncdf by ncdf_lec
275t2min_read_ncdf=read_ncdf("t2",0,10,/timestep,file=fullfilename_t2,/nostr)
276help, t2min_read_ncdf
277;++print, 'The first 10 time values (variable time) = ', time[0:9]
278;++print, 'time steps after read_ncdf (variable jpt) ', jpt
279t2min=ncdf_lec(fullfilename_t2,var='t2')
280;
281mskin=glamt*0.+1.
282
283; define grid parameters with mask file
284initncdf, fullfilename_msk
285domdef
286latout=reform(gphit(0,*))
287lonout=reform(glamt(*,0))
288print, 'lat grid from mask ',min(latout),max(latout),latout(1)-latout(0)
289print, 'lon grid from mask ',min(lonout),max(lonout),lonout(1)-lonout(0)
290mskout=read_ncdf("msk", file=fullfilename_msk,/nostr)
291;
292help, t2min,lonin,latin,mskin,lonout,latout,mskout
293;
294; interpolation and mask
295t2mout=fltarr(jpi,jpj,jptin)
296for jt=0,jptin-1 do begin
297  tab=reform(t2min(*,*,jt))
298  t2mout(*,*,jt)=call_interp2d(tab,lonin,latin,mskin,lonout,latout,method='bilinear')
299  t2mout(*,*,jt)=t2mout(*,*,jt)*mskout+(1.-mskout)*1.e20
300endfor
301
302initncdf, fullfilename_msk
303
304lat=latout
305lon=lonout
306ncfile='!' + fullfilename_out
307print, 'ncfile ', ncfile
308ncdf_getatt, fullfilename_msk, 'longitude', units=units
309ncdf_getatt, fullfilename_msk, 'longitude', long_name=long_name
310lon_attr={units:units, long_name:long_name}
311ncdf_getatt, fullfilename_msk, 'latitude', units=units
312ncdf_getatt, fullfilename_msk, 'latitude', long_name=long_name
313lat_attr={units:units, long_name:long_name}
314ncdf_getatt, fullfilename_t2, 'time', units=units
315ncdf_getatt, fullfilename_t2, 'time', long_name=long_name
316time_attr={units:units, long_name:long_name, time_origin:' 1957-JAN-01 00:00:00'}
317ncdf_getatt, fullfilename_t2, 't2', units=units
318ncdf_getatt, fullfilename_t2, 't2', long_name=long_name
319t2m_attr={units:units, long_name:long_name, missing_value:1e20, short_name:'t2m',axis:'TYX'}
320globattr={source:'Data are from ECMWF ERA-Interim reanalysis', timerange:cda0+' - '+cda1}
321
322
323help, t2mout
324help, timein
325;ncfields = 't2m[longitude,latitude,*time]=t2mout:t2m_attr; ' $
326;                      + 'longitude[]=lon:lon_attr; ' $
327;                      + 'latitude[]=lat:lat_attr; ' $
328;                     + 'time[]=timein:time_attr ' $
329;                      + ' @globattr'
330
331; ok ncfields = 'longitude[]=lon:lon_attr;latitude[]=lat:lat_attr'
332; ok ncfields = 'longitude[]=lon:lon_attr;latitude[]=lat:lat_attr;time[]=timein:time_attr'
333; ok ncfields = 'longitude[]=lon:lon_attr;latitude[]=lat:lat_attr;time[*]=timein:time_attr'
334; ok ncfields = 'longitude[]=lon:lon_attr;latitude[]=lat:lat_attr;time[*]=timein:time_attr@globattr'
335; pas ok ncfields = 't2m[longitude,latitude,*time]=t2mout:t2m_attr;longitude[]=lon:lon_attr;latitude[]=lat:lat_attr;time[*]=timein:time_attr@globattr'
336; pas ok  ncfields = 'longitude[]=lon:lon_attr;latitude[]=lat:lat_attr;time[*]=timein:time_attr;t2m[longitude,latitude,*time]=t2mout:t2m_attr@globattr'
337
338; the simpliest one
339nlat=73
340nlon=96
341latitudetp=findgen(nlat)
342longitudetp=findgen(nlon)
343timetp=findgen(2)
344pressure3d=findgen(nlon,nlat,2)
345patts = {units:'pascal',missing_value:1e10}
346globatts={source:'my program',version:2}
347NCFIELDS = 'pressure3d[longitudetp,latitudetp,*timetp]=pressure3d:patts;longitudetp[];latitudetp[];timetp[]@globatts'
348ncfile='my4.nc'
349@ncdf_quickwrite
350
351timepb=findgen(2)
352t2m=findgen(350,60,2)
353help, lat
354help, lon
355help, t2m
356help, time
357help, timein
358help, timepb
359ncfile='!' + fullfilename_out
360; pas ok ncfields = 'longitude[]=lon:lon_attr;latitude[]=lat:lat_attr;time[]=timein:time_attr;t2m[longitude,latitude,*time]'
361; pas ok ncfields = 't2m[longitude,latitude,*time];longitude[]=lon:lon_attr;latitude[]=lat:lat_attr;time[]=timein:time_attr'
362; ok avec timepb=findgen(2) ncfields = 't2m[longitude,latitude,*time];longitude[]=lon:lon_attr;latitude[]=lat:lat_attr;time[]=timepb:time_attr'
363; ok
364;timepb=findgen(2)
365;timepb[0]=280512.
366;timepb[1]=280536.
367;ncfields = 't2m[longitude,latitude,*time];longitude[]=lon:lon_attr;latitude[]=lat:lat_attr;time[]=timepb:time_attr'
368
369timepb=findgen(7670)
370ncfields = 't2m[longitude,latitude,*time];longitude[]=lon:lon_attr;latitude[]=lat:lat_attr;time[]=timepb:time_attr'
371@ncdf_quickwrite
372
373
374end
Note: See TracBrowser for help on using the repository browser.