source: trunk/src/interp_erai_t2m_1989_2009.pro @ 72

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

try to interp ERA-I on climserv (not ok yet); minimize diffreneces between sources

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