source: trunk/src/interp_erai_dewt.pro @ 190

Last change on this file since 190 was 180, checked in by pinsard, 12 years ago

no more IDL prompt in examples

  • 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; :func:`d2m_to_q2m_erai`.
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; :func:`d2m_to_q2m_erai`
78;
79; EXAMPLES
80; ========
81;
82; ::
83;
84;  .compile file_interp
85;  yyyymmddb = 20000101L
86;  yyyymmdde = 20001231L
87;  result = interp_erai_dewt(yyyymmddb, yyyymmdde)
88;  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; coding rules
115;
116; check time values
117;
118; KNOWN ISSUES
119; ============
120;
121; test of existence of fullfilename_msk not very efficient because
122; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
123;
124; EVOLUTIONS
125; ==========
126;
127; $Id$
128;
129; $URL: svn+ssh://pinsard@forge.ipsl.jussieu.fr/ipsl/forge/projets/tropflux/svn/trunk/src/interp_erai_dewt.pro $
130;
131; - fplod 20120320
132;
133;   * no more timegen
134;
135; - fplod 20120319
136;
137;   * taking project_overwite into account
138;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
139;   * pro -> function
140;
141; - pinsard 2011-08-23T09:09:16Z loholt1.ipsl.polytechnique.fr (Linux)
142;
143;   * retry on loholt1 with idl8 and idl6
144;
145; - fplod 20110808T094156Z cratos (Linux)
146;
147;   * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call
148;
149; - pinsard 2011-07-05T07:33:36Z loholt1.ipsl.polytechnique.fr (Linux)
150;
151;   * usage of $PROJECT_ID and $PROJECT_OD
152;
153; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
154;
155;   * remove hard coded directory for mask_oaflux_30N30S.nc
156;
157; - fplod 20101215T093710Z aedon.locean-ipsl.upmc.fr (Darwin)
158;
159;   * add graph in header
160;
161; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
162;
163;   * minimal header
164;
165; - pbk 2008
166;
167;   * creation
168;
169;-
170function interp_erai_dewt $
171         , yyyymmddb $
172         , yyyymmdde
173;
174;++compile_opt idl2, strictarrsubs, logical_predicate
175;
176@cm_4cal
177@cm_4data
178@cm_4mesh
179@cm_4data
180@cm_project
181;
182; Return to caller if errors
183ON_ERROR, 2
184;
185result = -1
186;
187usage = 'result = interp_erai_dewt(yyyymmddb, yyyymmdde)'
188nparam = N_PARAMS()
189IF (nparam NE 2) THEN BEGIN
190   ras = report(['Incorrect number of arguments.' $
191         + '!C' $
192         + 'Usage : ' + usage])
193   return, result
194ENDIF
195;
196; check for input directory
197;
198; test if ${PROJECT_ID} defined
199CASE project_id_env OF
200    ''  :  BEGIN
201     msg = 'eee : ${PROJECT_ID} is not defined'
202     ras = report(msg)
203     return, result
204           END
205 ELSE: BEGIN
206     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
207     ras = report(msg)
208       END
209ENDCASE
210;
211iodirin = isadirectory(project_id_env)
212;
213; existence and protection of ${PROJECT_ID}
214IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
215   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
216   ras = report(msg)
217   return, result
218ENDIF
219;
220; build mask filename
221filename_msk='mask_oaflux_30N30S.nc'
222;
223; check if this file exists
224msg='iii : looking for ' + filename_msk
225ras = report(msg)
226fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
227IF fullfilename_msk[0] EQ '' THEN BEGIN
228   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
229   ras = report(msg)
230   return, result
231ENDIF
232;
233; build data filename
234filename='20c3m_erai_d2_TROP_1989_2009.nc'
235;
236; check if this file exists
237msg='iii : looking for ' + filename
238ras = report(msg)
239fullfilename = isafile(iodirin + filename, NEW=0, /MUST_EXIST)
240IF fullfilename[0] EQ '' THEN BEGIN
241   msg = 'eee : the file ' + fullfilename + ' was not found.'
242   ras = report(msg)
243   return, result
244ENDIF
245;
246; test if ${PROJECT_OD} defined
247CASE project_od_env OF
248  '' : BEGIN
249         msg = 'eee : ${PROJECT_OD} is not defined'
250         ras = report(msg)
251       return, result
252       END
253  ELSE: BEGIN
254          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
255          ras = report(msg)
256        END
257 ENDCASE
258;
259; check if output data will be possible
260iodirout = isadirectory(project_od_env)
261;
262; existence and protection
263IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
264    msg = 'eee : the directory' + iodirout  + ' was not found.'
265    ras = report(msg)
266    return, result
267ENDIF
268;
269; build output filename
270filename_out = 'erai_d2m_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
271fullfilename_out = iodirout + filename_out
272; in order to avoid unexpected overwritten
273IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
274   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
275   ras = report(msg)
276   return, result
277ENDIF
278;
279initncdf, fullfilename
280domdef
281latin=reform(gphit[0,*])
282lonin=reform(glamt[*,0])
283print, 'lat grid ',min(latin),max(latin),latin[1]-latin[0]
284print, 'lon grid ',min(lonin),max(lonin),lonin[1]-lonin[0]
285d2min=read_ncdf("d2",yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr)
286;
287timein=24.d*(time-julday(1,1,1957,0,0,0))
288jptin=n_elements(timein)
289da=jul2date(time[0])
290cda0=string(da,format='(i8.8)')
291da=jul2date(time[jpt-1])
292cda1=string(da,format='(i8.8)')
293print, 'dewt first date ', cda0
294print, 'dewt last date ' , cda1
295;
296tab=d2min[*,*,0]
297mskin=glamt*0.+1.
298;
299initncdf, fullfilename_msk
300domdef
301latout=reform(gphit[0,*])
302lonout=reform(glamt[*,0])
303print, 'lat grid ',min(latout),max(latout),latout[1]-latout[0]
304print, 'lon grid ',min(lonout),max(lonout),lonout[1]-lonout[0]
305mskout=read_ncdf("msk", file=fullfilename_msk,/nostr)
306;
307help, d2min,lonin,latin,mskin,lonout,latout,mskout
308;
309d2mout=fltarr(jpi,jpj,jptin)
310for jt=0,jptin-1 do begin
311  ; ++ print, 'Interpolation jt=',jt,' / ',jptin-1
312  tab=reform(d2min[*,*,jt])
313  d2mout[*,*,jt]=call_interp2d(tab,lonin,latin,mskin $
314      , lonout,latout,method='bilinear' $
315      , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout)
316  d2mout[*,*,jt]=d2mout[*,*,jt]*mskout+(1.-mskout)*1.e20
317endfor
318;
319initncdf, fullfilename_msk
320;
321lat=latout
322lon=lonout
323ncfile='!' + fullfilename_out
324lon_attr={units:'degrees_east',long_name:'Longitude'}
325lat_attr={units:'degrees_north',long_name:'Latitude'}
326time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
327globattr={source:'Data are from ECMWF ERA-Interim reanalysis', timerange:cda0+' - '+cda1}
328d2m_attr={units:'degK',missing_value:1e20,long_name:'Dew Point Temperature at 2m',short_name:'d2m',axis:'TYX'}
329;
330ncfields = 'd2m[longitude,latitude,*time]=d2mout:d2m_attr; ' $
331                      + 'longitude[]=lon:lon_attr; ' $
332                      + 'latitude[]=lat:lat_attr; ' $
333                      + 'time[]=timein:time_attr ' $
334                      + ' @ globattr'
335;
336@ncdf_quickwrite
337;
338result = 0
339return, result
340;
341end
Note: See TracBrowser for help on using the repository browser.