source: trunk/src/interp_erai_dewt.pro @ 169

Last change on this file since 169 was 167, checked in by pinsard, 12 years ago

interp_erai_lwr is now a function

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