source: trunk/src/interp_erai_t2m_1989_2009.pro @ 85

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

try (and failed) correction on climserv

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