source: trunk/src/interp_erai_t2m_1989_2009.pro @ 70

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

fix call_interp2d call

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