source: trunk/src/interp_erai_t2m_1989_2009.pro @ 67

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

fix for doc

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