source: trunk/src/interp_erai_t2m_1989_2009.pro @ 100

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

start to homogenize (to be 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;     When timestep keyword is not used we can see these messages::
186;
187;        /usr/work/incas/fplod/tropflux_d/20c3m_erai_t2_TROP_1989_2009.nc as no time axis variable
188;        given by Praveen
189;
190;        Value of Julian date is out of allowed range
191;
192;        % Array used to subscript array contains out of range subscript: DATAIN
193;
194; - fplod 20101222T163216Z aedon.locean-ipsl.upmc.fr (Darwin)
195;
196;   * replace /Volumes/PRAVEEN/ERAI_global by ${TROPFLUX_ID}
197;
198; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
199;
200;   * remove hard coded directory for mask_oaflux_30N30S.nc
201;
202; - fplod 20101215T112140Z aedon.locean-ipsl.upmc.fr (Darwin)
203;
204;   * add graph in header
205;
206; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
207;
208;   * minimal header
209;
210; - pbk 2008
211;
212;   * creation
213;
214;-
215pro interp_erai_t2m_1989_2009
216;
217@cm_4cal
218@cm_4data
219@cm_4mesh
220@cm_4data
221@cm_project
222;
223; check for input directory
224;
225; test if ${PROJECT_ID} defined
226CASE project_id_env OF
227    ''  :  BEGIN
228     msg = 'eee : ${PROJECT_ID} is not defined'
229     ras = report(msg)
230     STOP
231           END
232 ELSE: BEGIN
233     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
234     ras = report(msg)
235       END
236ENDCASE
237;
238iodirin = isadirectory(project_id_env)
239;
240; existence and protection of ${PROJECT_ID}
241IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
242   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
243   ras = report(msg)
244   STOP
245ENDIF
246;
247; build mask filename
248filename_msk='mask_oaflux_30N30S.nc'
249;
250; check if this file exists
251msg='iii : looking for ' + filename_msk
252ras = report(msg)
253fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
254IF fullfilename_msk[0] EQ '' THEN BEGIN
255   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
256   ras = report(msg)
257   STOP
258ENDIF
259;
260; build t2 filename
261filename_t2='20c3m_erai_t2_TROP_1989_2009.nc'
262;
263; check if this file exists
264msg='iii : looking for ' + filename_t2
265ras = report(msg)
266fullfilename_t2 = isafile(iodirin + filename_t2, NEW=0, /MUST_EXIST)
267IF fullfilename_t2[0] EQ '' THEN BEGIN
268   msg = 'eee : the file ' + fullfilename_t2 + ' was not found.'
269   ras = report(msg)
270   STOP
271ENDIF
272;
273; test if ${PROJECT_OD} defined
274CASE project_od_env OF
275  '' : BEGIN
276         msg = 'eee : ${PROJECT_OD} is not defined'
277         ras = report(msg)
278       STOP
279       END
280  ELSE: BEGIN
281          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
282          ras = report(msg)
283        END
284 ENDCASE
285;
286; check if output data will be possible
287iodirout = isadirectory(project_od_env)
288;
289; existence and protection
290IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
291    msg = 'eee : the directory' + iodirout  + ' was not found.'
292    ras = report(msg)
293    STOP
294ENDIF
295;
296; build output filename
297filename_out = 'erai_t2m_19890101_20091231_oafluxgrid.nc'
298fullfilename_out = iodirout + filename_out
299; in order to avoid unexpected overwritten
300IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
301   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
302   ras = report(msg)
303   STOP
304ENDIF
305;
306; define grid parameters with t2 file
307initncdf, fullfilename_t2
308domdef
309latin=reform(gphit(0,*))
310lonin=reform(glamt(*,0))
311print, 'lat grid from data',min(latin),max(latin),latin(1)-latin(0)
312print, 'lon grid from data',min(lonin),max(lonin),lonin(1)-lonin(0)
313;
314; get time in t2 file
315timein=ncdf_lec(fullfilename_t2,var='time')
316jptin=n_elements(timein)
317print, 'time steps from data ', jptin
318print, 'The first 10 time values (variable timein) = ', timein[0:9]
319;
320; find first and last dates yyyymmdd
321; they will be written in global attributes of output file
322da=jul2date(julday(01, 01, 1957,timein[0]))
323cda0=string(da,format='(i8.8)')
324da=jul2date(julday(01, 01, 1957,timein[jptin-1]))
325cda1=string(da,format='(i8.8)')
326print, 'first date ', cda0
327print, 'last date ' , cda1
328;
329; read t2 data
330;++ pb memory t2min=read_ncdf("t2",0,jptin-1,/timestep,file=fullfilename_t2,/nostr)
331; the following line is here just to prepare replacement of read_ncdf by ncdf_lec
332t2min_read_ncdf=read_ncdf("t2",0,10,/timestep,file=fullfilename_t2,/nostr)
333help, t2min_read_ncdf
334;++print, 'The first 10 time values (variable time) = ', time[0:9]
335;++print, 'time steps after read_ncdf (variable jpt) ', jpt
336t2min=ncdf_lec(fullfilename_t2,var='t2')
337;
338mskin=glamt*0.+1.
339;
340; define grid parameters with mask file
341initncdf, fullfilename_msk
342domdef
343latout=reform(gphit(0,*))
344lonout=reform(glamt(*,0))
345print, 'lat grid from mask ',min(latout),max(latout),latout(1)-latout(0)
346print, 'lon grid from mask ',min(lonout),max(lonout),lonout(1)-lonout(0)
347mskout=read_ncdf("msk", file=fullfilename_msk,/nostr)
348;
349help, t2min,lonin,latin,mskin,lonout,latout,mskout
350;
351; interpolation and mask
352t2mout=fltarr(jpi,jpj,jptin)
353for jt=0,jptin-1 do begin
354  tab=reform(t2min(*,*,jt))
355  t2mout(*,*,jt)=call_interp2d(tab,lonin,latin,mskin $
356      , lonout,latout,method='bilinear' $
357      , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout)
358  t2mout(*,*,jt)=t2mout(*,*,jt)*mskout+(1.-mskout)*1.e20
359endfor
360;
361initncdf, fullfilename_msk
362;
363lat=latout
364lon=lonout
365ncfile='!' + fullfilename_out
366ncdf_getatt, fullfilename_msk, 'longitude', units=units
367ncdf_getatt, fullfilename_msk, 'longitude', long_name=long_name
368lon_attr={units:units, long_name:long_name}
369ncdf_getatt, fullfilename_msk, 'latitude', units=units
370ncdf_getatt, fullfilename_msk, 'latitude', long_name=long_name
371lat_attr={units:units, long_name:long_name}
372ncdf_getatt, fullfilename_t2, 'time', units=units
373ncdf_getatt, fullfilename_t2, 'time', long_name=long_name
374time_attr={units:units, long_name:long_name, time_origin:' 1957-JAN-01 00:00:00'}
375globattr={source:'Data are from ECMWF ERA-Interim reanalysis', timerange:cda0+' - '+cda1}
376ncdf_getatt, fullfilename_t2, 't2', units=units
377ncdf_getatt, fullfilename_t2, 't2', long_name=long_name
378t2m_attr={units:units, long_name:long_name, missing_value:1e20, short_name:'t2m',axis:'TYX'}
379;
380help, t2mout
381help, timein
382ncfields = 't2m[longitude,latitude,*time]=t2mout:t2m_attr; ' $
383                      + 'longitude[]=lon:lon_attr; ' $
384                      + 'latitude[]=lat:lat_attr; ' $
385                      + 'time[]=timein:time_attr ' $
386                      + ' @globattr'
387@ncdf_quickwrite
388;
389end
Note: See TracBrowser for help on using the repository browser.