source: trunk/src/interp_erai_ws.pro @ 172

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

interp_erai_ws, d2m_to_q2m_erai and interp_olr_30n30s are now functions

  • Property svn:keywords set to Id
File size: 11.6 KB
Line 
1;+
2;
3;
4; ==================
5; interp_erai_ws.pro
6; ==================
7;
8; .. function:: interp_erai_ws(yyyymmddb,yyyymmdde)
9;
10; DESCRIPTION
11; ===========
12;
13; Interpolation of u10 and v10 from ERA-I grid to OAFLUX grid
14;
15; :file:`${PROJECT_ID}/20c3m_erai_u10_TROP_1989_2009.nc`
16; containing
17; u10 from ERA-I
18; has been produced by
19; :ref:`compute_erai_daily_region_2d.sh`.
20;
21; :file:`${PROJECT_ID}/20c3m_erai_v10_TROP_1989_2009.nc`
22; containing
23; v10 from ERA-I
24; has been produced by
25; :ref:`compute_erai_daily_region_2d.sh`.
26;
27; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc`
28; containing OAFLUX grid
29; has been produced by
30; :func:`oaflux_mask_30n30s`.
31;
32; Interpolated u10 and v10 are written in
33; :file:`${PROJECT_OD}/erai_ws_19890101_20091231_oafluxgrid.nc`
34; if this file not already exists.
35;
36; This output file
37; :file:`${PROJECT_OD}/erai_ws_19890101_20091231_oafluxgrid.nc`
38; must be processed after by
39; :ref:`ws_correction_ncdf.pro`.
40;
41; .. only:: man
42;
43;    Figure is visible on PDF and HTML documents only.
44;
45; .. only:: html or latex
46;
47;     .. graphviz::
48;
49;        digraph interp_erai_ws {
50;
51;           file_u10 [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/20c3m_erai_u10_TROP_1989_2009.nc"];
52;           file_v10 [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/20c3m_erai_v10_TROP_1989_2009.nc"];
53;           mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"];
54;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_ws_19890101_20091231_oafluxgrid.nc"];
55;
56;           interp_erai_ws [shape=box,
57;           fontname=Courier,
58;           color=blue,
59;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_erai_ws.pro",
60;           label="${PROJECT}/src/interp_erai_ws.pro"];
61;
62;           {file_u10 file_v10 mask} -> {interp_erai_ws} -> {file_out}
63;
64;        }
65;
66; SEE ALSO
67; ========
68;
69; :ref:`interpolate_data`
70;
71; :ref:`project_profile.sh`
72;
73; Used by :ref:`tropflux.sh`
74;
75; :func:`report <saxo:report>`
76; :func:`isadirectory <saxo:isadirectory>`
77; :func:`isafile <saxo:isafile>`
78; :func:`initncdf <saxo:initncdf>`
79; :func:`read_ncdf <saxo:read_ncdf>`
80; :func:`domdef <saxo:domdef>`
81; :func:`call_interp2d <saxo:call_interp2d>`
82; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
83;
84; :ref:`ws_correction_ncdf.pro`
85;
86; EXAMPLES
87; ========
88;
89; ::
90;
91;  IDL> .compile file_interp
92;  IDL> yyyymmddb = 20000101L
93;  IDL> yyyymmdde = 20001231L
94;  IDL> result = interp_erai_ws(yyyymmddb, yyyymmdde)
95;  IDL> print, result
96;
97; TODO
98; ====
99;
100; compare time between u10 and v10 after reading
101;
102; make it work : pb on loholt1 idl8
103;
104; reach end but bad values et nb timestep 4581::
105;
106;     ncks -v u10  -d time,0,1 -d latitude,0,1 -d longitude,0,1 /homedata/pinsard/tropflux_d/erai_ws_19890101_20091231_oafluxgrid.nc
107;     latitude[0]=-29.5 degrees_north
108;     latitude[1]=-28.5 degrees_north
109;
110;     longitude[0]=30.5 degrees_east
111;     longitude[1]=31.5 degrees_east
112;
113;     time[0] latitude[0]=-29.5 longitude[0]=30.5 u10[0]=9.96921e+36 m/s
114;     time[0] latitude[0]=-29.5 longitude[1]=31.5 u10[1]=9.96921e+36 m/s
115;     time[0] latitude[1]=-28.5 longitude[0]=30.5 u10[350]=9.96921e+36 m/s
116;     time[0] latitude[1]=-28.5 longitude[1]=31.5 u10[351]=9.96921e+36 m/s
117;     time[1] latitude[0]=-29.5 longitude[0]=30.5 u10[21000]=9.96921e+36 m/s
118;     time[1] latitude[0]=-29.5 longitude[1]=31.5 u10[21001]=9.96921e+36 m/s
119;     time[1] latitude[1]=-28.5 longitude[0]=30.5 u10[21350]=9.96921e+36 m/s
120;     time[1] latitude[1]=-28.5 longitude[1]=31.5 u10[21351]=9.96921e+36 m/s
121;
122; make it work : pb on loholt1 idl6::
123;
124;   Writing fields:
125;   u10[longitude,latitude,time]=u10out:u10_attr; v10[longitude,latitude,time]=v10out:v10_attr; longitude[]=xlon:lon_attr; latitude[]=ylat:lat_attr; tt[*time]=tt:time_attr  @ globattr
126;   % NCDF_VARPUT: Operation Failed, bad file (6) or variable [0] id ?
127;                  (NC_ERROR=-31)
128;   % Stop encountered: INTERP_ERAI_WS_1989_2009    1
129;
130; check OUTMASK_IND and SET_OUTMSKVAL added to call_interp2d call
131;
132; use real output of :ref:`compute_erai_daily_region_2d.sh`.
133;
134; coding rules
135;
136; check [yyyymmddb,yyyymmdde] validity
137;
138; check if [yyyymmddb,yyyymmdde] is included in ERA-I file
139;
140; what happen if yyyymmdde > 20091231 : need to read an other ERA-I file
141;
142; KNOWN ISSUES
143; ============
144;
145; test of existence of fullfilename_msk not very efficient because
146; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
147;
148; EVOLUTIONS
149; ==========
150;
151; $Id$
152;
153; $URL: svn+ssh://pinsard@forge.ipsl.jussieu.fr/ipsl/forge/projets/tropflux/svn/trunk/src/interp_erai_ws.pro $
154;
155; - fplod 20120320
156;
157;   * taking project_overwite into account
158;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
159;   * pro -> function
160;   * hard coded st and en replaced by yyyymmddb and yyyymmdde parameters
161;   * start to homogenize time handling regarding :func:`interp_erai_t2m`
162;
163; - fplod 20110830T135212Z cratos (Linux)
164;
165;   * replace tt by time
166;
167; - pinsard 2011-08-23T09:09:16Z loholt1.ipsl.polytechnique.fr (Linux)
168;
169;   * retry on loholt1 with idl8 and idl6
170;
171; - fplod 20110808T094156Z cratos (Linux)
172;
173;   * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call
174;
175; - pinsard 2011-07-05T07:33:36Z loholt1.ipsl.polytechnique.fr (Linux)
176;
177;   * usage of $PROJECT_ID and $PROJECT_OD
178;
179; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
180;
181;   * remove hard coded directory for mask_oaflux_30N30S.nc
182;
183; - fplod 20101215T112657Z aedon.locean-ipsl.upmc.fr (Darwin)
184;
185;   * add graph in header
186;
187; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
188;
189;   * minimal header
190;
191; - pbk 2008
192;
193;   * creation
194;
195;-
196function interp_erai_ws $
197         , yyyymmddb $
198         , yyyymmdde
199;
200;++compile_opt idl2, strictarrsubs, logical_predicate
201;
202; Return to caller if errors
203ON_ERROR, 2
204;
205result = -1
206;
207usage = 'result = interp_erai_lwr(yyyymmddb, yyyymmdde)'
208nparam = N_PARAMS()
209IF (nparam NE 2) THEN BEGIN
210ras = report(['Incorrect number of arguments.' $
211      + '!C' $
212      + 'Usage : ' + usage])
213      return, result
214ENDIF
215;
216@cm_4cal
217@cm_4data
218@cm_4mesh
219@cm_4data
220@cm_project
221;
222; check for input directory
223;
224; test if ${PROJECT_ID} defined
225CASE project_id_env OF
226    ''  :  BEGIN
227     msg = 'eee : ${PROJECT_ID} is not defined'
228     ras = report(msg)
229     return, result
230           END
231 ELSE: BEGIN
232     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
233     ras = report(msg)
234       END
235ENDCASE
236;
237iodirin = isadirectory(project_id_env)
238;
239; existence and protection of ${PROJECT_ID}
240IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
241   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
242   ras = report(msg)
243   return, result
244ENDIF
245;
246; build mask filename
247filename_msk='mask_oaflux_30N30S.nc'
248;
249; check if this file exists
250msg='iii : looking for ' + filename_msk
251ras = report(msg)
252fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
253IF fullfilename_msk[0] EQ '' THEN BEGIN
254   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
255   ras = report(msg)
256   return, result
257ENDIF
258;
259; build u10 data filename
260filename='20c3m_erai_u10_TROP_1989_2009.nc'
261;
262; check if this file exists
263msg='iii : looking for ' + filename
264ras = report(msg)
265fullfilename = isafile(iodirin + filename, NEW=0, /MUST_EXIST)
266IF fullfilename[0] EQ '' THEN BEGIN
267   msg = 'eee : the file ' + fullfilename + ' was not found.'
268   ras = report(msg)
269   return, result
270ENDIF
271;
272; test if ${PROJECT_OD} defined
273CASE project_od_env OF
274  '' : BEGIN
275         msg = 'eee : ${PROJECT_OD} is not defined'
276         ras = report(msg)
277       return, result
278       END
279  ELSE: BEGIN
280          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
281          ras = report(msg)
282        END
283 ENDCASE
284;
285; check if output data will be possible
286iodirout = isadirectory(project_od_env)
287;
288; existence and protection
289IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
290    msg = 'eee : the directory' + iodirout  + ' was not found.'
291    ras = report(msg)
292    return, result
293ENDIF
294;
295; build output filename
296filename_out = 'erai_ws_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
297fullfilename_out = iodirout + filename_out
298; in order to avoid unexpected overwritten
299IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
300   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
301   ras = report(msg)
302   return, result
303ENDIF
304;
305initncdf, fullfilename
306u10in=read_ncdf("u10", yyyymmddb - .5d, yyyymmdde, file=fullfilename,/nostr)
307;
308timein=24.d*(time-julday(1,1,1957,0,0,0))
309jpt=n_elements(timein)
310da=jul2date(time[0])
311cda0=string(da,format='(i8.8)')
312da=jul2date(time[jpt-1])
313cda1=string(da,format='(i8.8)')
314print, 'u10 first date ', cda0
315print, 'u10 last date ' , cda1
316;
317; build v10 data filename
318filename='20c3m_erai_v10_TROP_1989_2009.nc'
319;
320; check if this file exists
321msg='iii : looking for ' + filename
322ras = report(msg)
323fullfilename = isafile(iodirin + filename, NEW=0, /MUST_EXIST)
324IF fullfilename[0] EQ '' THEN BEGIN
325   msg = 'eee : the file ' + fullfilename + ' was not found.'
326   ras = report(msg)
327   return, result
328ENDIF
329initncdf, fullfilename
330v10in=read_ncdf("v10", yyyymmddb - .5d, yyyymmdde, file=fullfilename,/nostr)
331;
332initncdf, fullfilename
333domdef
334latin=reform(gphit[0,*])
335lonin=reform(glamt[*,0])
336print, 'lat grid ',min(latin),max(latin),latin[1]-latin[0]
337print, 'lon grid ',min(lonin),max(lonin),lonin[1]-lonin[0]
338;
339timein=24.d*(time-julday(1,1,1957,0,0,0))
340jptin=n_elements(timein)
341da=jul2date(time[0])
342cda0=string(da,format='(i8.8)')
343da=jul2date(time[jpt-1])
344cda1=string(da,format='(i8.8)')
345print, 'v10 first date ', cda0
346print, 'v10 last date ' , cda1
347help, v10in
348;
349tab=u10in[*,*,0]
350mskin=glamt*0.+1.
351;
352initncdf, fullfilename_msk
353domdef
354latout=reform(gphit[0,*])
355lonout=reform(glamt[*,0])
356print, 'lat grid ',min(latout),max(latout),latout[1]-latout[0]
357print, 'lon grid ',min(lonout),max(lonout),lonout[1]-lonout[0]
358mskout=read_ncdf("msk", file=fullfilename_msk,/nostr)
359;
360help, u10in, v10in,lonin,latin,mskin,lonout,latout,mskout
361;
362u10out=fltarr(jpi,jpj,jptin)
363v10out=fltarr(jpi,jpj,jptin)
364;
365for jt=0,jptin-1 do begin
366  ; ++print, 'Interpolation jt=',jt,' / ',jptin-1
367  tab=reform(u10in[*,*,jt])
368  u10out[*,*,jt]=call_interp2d(tab,lonin,latin,mskin $
369      , lonout,latout,method='bilinear' $
370      , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout)
371  u10out[*,*,jt]=u10out[*,*,jt]*mskout+(1.-mskout)*1.e20
372;
373  tab=reform(v10in[*,*,jt])
374  v10out[*,*,jt]=call_interp2d(tab,lonin,latin,mskin $
375      , lonout,latout,method='bilinear' $
376      , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout)
377  v10out[*,*,jt]=v10out[*,*,jt]*mskout+(1.-mskout)*1.e20
378;
379endfor
380;
381xlon=reform(glamt[*,0] )
382ylat=reform(gphit[0,*])
383;
384initncdf, fullfilename_msk
385valmask=1.e20
386;
387ylat=latout
388xlon=lonout
389ncfile='!' + fullfilename_out
390lon_attr={units:'degrees_east',long_name:'Longitude'}
391lat_attr={units:'degrees_north',long_name:'Latitude'}
392time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
393globattr={source:'Tropical ocean winds obtained from ERA Interim',timerange:cda0+' - '+cda1}
394u10_attr={units:'m/s',missing_value:valmask,long_name:'10 metre u wind component',short_name:'u10',axis:'TYX'}
395v10_attr={units:'m/s',missing_value:valmask,long_name:'10 metre v wind component',short_name:'v10',axis:'TYX'}
396;
397help, u10out
398help, v10out
399help, timein
400;
401ncfields = 'u10[longitude,latitude,*time]=u10out:u10_attr; ' $
402          +'v10[longitude,latitude,*time]=v10out:v10_attr; ' $
403                      + 'longitude[]=xlon:lon_attr; ' $
404                      + 'latitude[]=ylat:lat_attr; ' $
405                      + 'time[]=timein:time_attr ' $
406                      + ' @ globattr'
407;
408@ncdf_quickwrite
409;
410result = 0
411return, result
412;
413end
Note: See TracBrowser for help on using the repository browser.