source: trunk/src/interp_erai_dewt.pro @ 199

Last change on this file since 199 was 191, checked in by pinsard, 12 years ago

introduce new erai dataset : new terminology and new time unit and origin

  • Property svn:keywords set to Id
File size: 10.0 KB
Line 
1;+
2;
3; ====================
4; interp_erai_dewt.pro
5; ====================
6;
7; .. function:: interp_erai_dewt(yyyymmddb,yyyymmdde, eraitype)
8;
9; DESCRIPTION
10; ===========
11;
12; Interpolation of d2 from ERA-I grid to OAFLUX grid
13;
14; If eraitype is set to 1,
15; :file:`${PROJECT_ID}/20c3m_erai_d2_TROP_1989_2009.nc`
16; containing
17; d2 from ERA-I
18; has been produced by
19; :ref:`compute_erai_daily_region_2d.sh`.
20;
21; If eraitype is set to 2,
22; :file:`${PROJECT_ID}/erai_d2m_{yyyyb}_{yyyye}.nc`
23; containing
24; d2m from ERA-I
25; has been produced by
26; :ref:`concat_eraiy.sh`.
27;
28; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc`
29; containing OAFLUX grid
30; has been produced by
31; :func:`oaflux_mask_30n30s`.
32;
33; Interpolated d2
34; is written in
35; :file:`${PROJECT_OD}/erai_d2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
36; if this file not already exists.
37;
38; This output file
39; :file:`${PROJECT_OD}/erai_d2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
40; must be processed after by
41; :func:`d2m_to_q2m_erai`.
42;
43; .. only:: man
44;
45;    Figure is visible on PDF and HTML documents only.
46;
47; .. only:: html or latex
48;
49;     .. graphviz::
50;
51;        digraph interp_erai_dewt {
52;
53;           file_in_erai1 [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/20c3m_erai_d2_TROP_1989_2009.nc"];
54;           file_in_erai2 [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/erai_d2m_{yyyyb}_{yyyye}.nc"];
55;           mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"];
56;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_d2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
57;
58;           interp_erai_dewt [shape=box,
59;           fontname=Courier,
60;           color=blue,
61;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_erai_dewt.pro",
62;           label="${PROJECT}/src/interp_erai_dewt.pro"];
63;
64;           {file_in_erai1 file_in_erai2 mask} -> {interp_erai_dewt} -> {file_out}
65;
66;        }
67;
68; SEE ALSO
69; ========
70;
71; :ref:`interpolate_data`
72;
73; Used by :ref:`tropflux.sh`
74;
75; :ref:`project_profile.sh`
76;
77; :ref:`compute_erai_daily_region_2d.sh`
78; :ref:`concat_eraiy.sh`
79;
80; :func:`report <saxo:report>`
81; :func:`isadirectory <saxo:isadirectory>`
82; :func:`isafile <saxo:isafile>`
83; :func:`initncdf <saxo:initncdf>`
84; :func:`read_ncdf <saxo:read_ncdf>`
85; :func:`domdef <saxo:domdef>`
86; :func:`call_interp2d <saxo:call_interp2d>`
87; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
88;
89; :func:`d2m_to_q2m_erai`
90;
91; EXAMPLES
92; ========
93;
94; With ERA-I type 1::
95;
96;  .compile file_interp
97;  yyyymmddb = 20000101L
98;  yyyymmdde = 20001231L
99;  eraitype = 1
100;  result = interp_erai_dewt(yyyymmddb, yyyymmdde, eraitype)
101;  print, result
102;
103; With ERA-I type 2::
104;
105;  .compile file_interp
106;  yyyymmddb = 20000101L
107;  yyyymmdde = 20001231L
108;  eraitype = 2
109;  result = interp_erai_dewt(yyyymmddb, yyyymmdde, eraitype)
110;  print, result
111;
112; TIPS
113; ====
114;
115; To see some values of variable ::
116;
117;   $ ncks -v d2m -d time,0,1 -d latitude,0,1 -d longitude,0,1 \
118;     $PROJECT_ID/erai_d2m_19890101_20091231_oafluxgrid.nc
119;
120; TODO
121; ====
122;
123; check OUTMASK_IND and SET_OUTMSKVAL added to call_interp2d call
124;
125; use real output of :ref:`compute_erai_daily_region_2d.sh`.
126;
127; why 19880101,20100930 as dates in read_ncdf.
128; now (20120319) should be yyyymmddb and yyymmdde
129;
130; check [yyyymmddb,yyyymmdde] validity
131;
132; check if [yyyymmddb,yyyymmdde] is included in ERA-I file
133;
134; what happen if yyyymmdde > 20091231 : need to read an other ERA-I file
135;
136; coding rules
137;
138; check time values
139;
140; KNOWN ISSUES
141; ============
142;
143; test of existence of fullfilename_msk not very efficient because
144; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
145;
146; EVOLUTIONS
147; ==========
148;
149; $Id$
150;
151; $URL: svn+ssh://pinsard@forge.ipsl.jussieu.fr/ipsl/forge/projets/tropflux/svn/trunk/src/interp_erai_dewt.pro $
152;
153; - fplod 20120704T113504Z cratos (Linux)
154;
155;   * add eraitype parameter
156;   * deal with time units (days vs hours) and time origin
157;
158; - fplod 20120320
159;
160;   * no more timegen
161;
162; - fplod 20120319
163;
164;   * taking project_overwite into account
165;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
166;   * pro -> function
167;
168; - pinsard 2011-08-23T09:09:16Z loholt1.ipsl.polytechnique.fr (Linux)
169;
170;   * retry on loholt1 with idl8 and idl6
171;
172; - fplod 20110808T094156Z cratos (Linux)
173;
174;   * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call
175;
176; - pinsard 2011-07-05T07:33:36Z loholt1.ipsl.polytechnique.fr (Linux)
177;
178;   * usage of $PROJECT_ID and $PROJECT_OD
179;
180; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
181;
182;   * remove hard coded directory for mask_oaflux_30N30S.nc
183;
184; - fplod 20101215T093710Z aedon.locean-ipsl.upmc.fr (Darwin)
185;
186;   * add graph in header
187;
188; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
189;
190;   * minimal header
191;
192; - pbk 2008
193;
194;   * creation
195;
196;-
197function interp_erai_dewt $
198         , yyyymmddb $
199         , yyyymmdde $
200         , eraitype
201;
202;++compile_opt idl2, strictarrsubs, logical_predicate
203;
204@cm_4cal
205@cm_4data
206@cm_4mesh
207@cm_4data
208@cm_project
209;
210; Return to caller if errors
211ON_ERROR, 2
212;
213result = -1
214;
215usage = 'result = interp_erai_dewt(yyyymmddb, yyyymmdde, eraitype)'
216nparam = N_PARAMS()
217IF (nparam NE 3) THEN BEGIN
218   ras = report(['Incorrect number of arguments.' $
219         + '!C' $
220         + 'Usage : ' + usage])
221   return, result
222ENDIF
223;
224; check for input directory
225;
226; test if ${PROJECT_ID} defined
227CASE project_id_env OF
228    ''  :  BEGIN
229     msg = 'eee : ${PROJECT_ID} is not defined'
230     ras = report(msg)
231     return, result
232           END
233 ELSE: BEGIN
234     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
235     ras = report(msg)
236       END
237ENDCASE
238;
239iodirin = isadirectory(project_id_env)
240;
241; existence and protection of ${PROJECT_ID}
242IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
243   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
244   ras = report(msg)
245   return, result
246ENDIF
247;
248; build mask filename
249filename_msk='mask_oaflux_30N30S.nc'
250;
251; check if this file exists
252msg='iii : looking for ' + filename_msk
253ras = report(msg)
254fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
255IF fullfilename_msk[0] EQ '' THEN BEGIN
256   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
257   ras = report(msg)
258   return, result
259ENDIF
260;
261; build data filename
262IF eraitype EQ 1 THEN BEGIN
263    erai_var = 'd2'
264    filename='20c3m_erai_d2_TROP_1989_2009.nc'
265    tutoday = 24.d
266    tmporig = date2jul(19570101L,month=immo,day=iddo,year=iyyyyo)
267endif
268IF (eraitype eq 2) THEN BEGIN
269    erai_var = 'd2m'
270    tmpb = date2jul(yyyymmddb,month=immb,day=iddb,year=iyyyyb)
271    tmpe = date2jul(yyyymmdde,month=imme,day=idde,year=iyyyye)
272    filename = 'erai_' + erai_var + '_' + string(iyyyyb,format='(I4.4)') + '_' + string(iyyyye,format='(I4.4)') + '.nc'
273    tutoday = 1.d
274    tmporig = date2jul(19500101L,month=immo,day=iddo,year=iyyyyo)
275ENDIF
276;
277; check if this file exists
278msg='iii : looking for ' + filename
279ras = report(msg)
280fullfilename = isafile(iodirin + filename, NEW=0, /MUST_EXIST)
281IF fullfilename[0] EQ '' THEN BEGIN
282   msg = 'eee : the file ' + fullfilename + ' was not found.'
283   ras = report(msg)
284   return, result
285ENDIF
286;
287; test if ${PROJECT_OD} defined
288CASE project_od_env OF
289  '' : BEGIN
290         msg = 'eee : ${PROJECT_OD} is not defined'
291         ras = report(msg)
292       return, result
293       END
294  ELSE: BEGIN
295          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
296          ras = report(msg)
297        END
298 ENDCASE
299;
300; check if output data will be possible
301iodirout = isadirectory(project_od_env)
302;
303; existence and protection
304IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
305    msg = 'eee : the directory' + iodirout  + ' was not found.'
306    ras = report(msg)
307    return, result
308ENDIF
309;
310; build output filename
311filename_out = 'erai_d2m_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
312fullfilename_out = iodirout + filename_out
313; in order to avoid unexpected overwritten
314IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
315   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
316   ras = report(msg)
317   return, result
318ENDIF
319;
320initncdf, fullfilename
321domdef
322latin=reform(gphit[0,*])
323lonin=reform(glamt[*,0])
324print, 'lat grid ',min(latin),max(latin),latin[1]-latin[0]
325print, 'lon grid ',min(lonin),max(lonin),lonin[1]-lonin[0]
326d2min=read_ncdf(erai_var,yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr)
327;
328timein=tutoday*(time-julday(immo,iddo,iyyyyo,0,0,0))
329jptin=n_elements(timein)
330da=jul2date(time[0])
331cda0=string(da,format='(i8.8)')
332da=jul2date(time[jpt-1])
333cda1=string(da,format='(i8.8)')
334print, 'dewt first date ', cda0
335print, 'dewt last date ' , cda1
336;
337tab=d2min[*,*,0]
338mskin=glamt*0.+1.
339;
340initncdf, fullfilename_msk
341domdef
342latout=reform(gphit[0,*])
343lonout=reform(glamt[*,0])
344print, 'lat grid ',min(latout),max(latout),latout[1]-latout[0]
345print, 'lon grid ',min(lonout),max(lonout),lonout[1]-lonout[0]
346mskout=read_ncdf("msk", file=fullfilename_msk,/nostr)
347;
348help, d2min,lonin,latin,mskin,lonout,latout,mskout
349;
350d2mout=fltarr(jpi,jpj,jptin)
351for jt=0,jptin-1 do begin
352  ; ++ print, 'Interpolation jt=',jt,' / ',jptin-1
353  tab=reform(d2min[*,*,jt])
354  d2mout[*,*,jt]=call_interp2d(tab,lonin,latin,mskin $
355      , lonout,latout,method='bilinear' $
356      , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout)
357  d2mout[*,*,jt]=d2mout[*,*,jt]*mskout+(1.-mskout)*1.e20
358endfor
359;
360initncdf, fullfilename_msk
361;
362lat=latout
363lon=lonout
364ncfile='!' + fullfilename_out
365lon_attr={units:'degrees_east',long_name:'Longitude'}
366lat_attr={units:'degrees_north',long_name:'Latitude'}
367time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
368globattr={source:'Data are from ECMWF ERA-Interim reanalysis', timerange:cda0+' - '+cda1}
369d2m_attr={units:'degK',missing_value:1e20,long_name:'Dew Point Temperature at 2m',short_name:'d2m',axis:'TYX'}
370;
371ncfields = 'd2m[longitude,latitude,*time]=d2mout:d2m_attr; ' $
372                      + 'longitude[]=lon:lon_attr; ' $
373                      + 'latitude[]=lat:lat_attr; ' $
374                      + 'time[]=timein:time_attr ' $
375                      + ' @ globattr'
376;
377@ncdf_quickwrite
378;
379result = 0
380return, result
381;
382end
Note: See TracBrowser for help on using the repository browser.