source: trunk/src/interp_erai_t2m_1989_2009.pro @ 66

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

no more hard coded path in iterp_erai*.pro

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