source: trunk/src/interp_erai_t2m_1989_2009.pro @ 94

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

try to make progress with idl8 (cont.)

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