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