source: trunk/src/interp_erai_t2m_1989_2009.pro @ 91

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

suppress rankdir in sources

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