source: trunk/src/interp_erai_dewt.pro @ 166

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

interp_erai_dewt is now a function

  • Property svn:keywords set to Id
File size: 8.7 KB
RevLine 
[6]1;+
2;
[166]3; ====================
4; interp_erai_dewt.pro
5; ====================
[6]6;
[166]7; .. function:: interp_erai_dewt(yyyymmddb,yyyymmdde)
[6]8;
[67]9; DESCRIPTION
10; ===========
11;
[66]12; Interpolation of d2 from ERA-I grid to OAFLUX grid
[6]13;
[92]14; :file:`${PROJECT_ID}/20c3m_erai_d2_TROP_1989_2009.nc`
15; containing
16; d2 from ERA-I
[93]17; has been produced by
[92]18; :ref:`compute_erai_daily_region_2d.sh`.
[66]19;
[92]20; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc`
21; containing OAFLUX grid
[93]22; has been produced by
[166]23; :func:`oaflux_mask_30n30s`.
[66]24;
[92]25; Interpolated d2
26; is written in
[166]27; :file:`${PROJECT_OD}/erai_d2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
[92]28; if this file not already exists.
[66]29;
[92]30; This output file
[166]31; :file:`${PROJECT_OD}/erai_d2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
[92]32; must be processed after by
33; :ref:`d2m_to_q2m_erai.pro`.
[66]34;
[92]35; .. only:: man
36;
37;    Figure is visible on PDF and HTML documents only.
38;
39; .. only:: html or latex
40;
[8]41;     .. graphviz::
42;
[166]43;        digraph interp_erai_dewt {
[71]44;
[66]45;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/20c3m_erai_d2_TROP_1989_2009.nc"];
[50]46;           mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"];
[166]47;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_d2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
[8]48;
[166]49;           interp_erai_dewt [shape=box,
[8]50;           fontname=Courier,
51;           color=blue,
[166]52;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_erai_dewt.pro",
53;           label="${PROJECT}/src/interp_erai_dewt.pro"];
[8]54;
[166]55;           {file_in mask} -> {interp_erai_dewt} -> {file_out}
[8]56;
[71]57;        }
[8]58;
[6]59; SEE ALSO
60; ========
61;
[92]62; :ref:`interpolate_data`
63;
[166]64; Used by :ref:`tropflux.sh`
65;
[50]66; :ref:`project_profile.sh`
[19]67;
[20]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;
[67]77; :ref:`d2m_to_q2m_erai.pro`
[66]78;
[6]79; EXAMPLES
80; ========
81;
82; ::
83;
[66]84;  IDL> .compile file_interp
[166]85;  IDL> yyyymmddb = 19890101
86;  IDL> yyyymmdde = 20091231
87;  IDL> result = interp_erai_dewt(yyyymmddb, yyymmdde)
88;  IDL> print, result
[6]89;
[93]90; TIPS
[6]91; ====
92;
[93]93; To see some values of variable ::
[6]94;
[92]95;   $ ncks -v d2m -d time,0,1 -d latitude,0,1 -d longitude,0,1 \
[166]96;     $PROJECT_ID/erai_d2m_19890101_20091231_oafluxgrid.nc
[92]97;
[93]98; TODO
99; ====
[92]100;
[70]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;
[166]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;
[6]116; coding rules
117;
[166]118; check time values
119;
[19]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;
[6]126; EVOLUTIONS
127; ==========
128;
[66]129; $Id$
130;
[166]131; $URL: svn+ssh://pinsard@forge.ipsl.jussieu.fr/ipsl/forge/projets/tropflux/svn/trunk/src/interp_erai_dewt.pro $
[66]132;
[166]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;
[92]139; - pinsard 2011-08-23T09:09:16Z loholt1.ipsl.polytechnique.fr (Linux)
140;
141;   * retry on loholt1 with idl8 and idl6
142;
[70]143; - fplod 20110808T094156Z cratos (Linux)
144;
145;   * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call
146;
[66]147; - pinsard 2011-07-05T07:33:36Z loholt1.ipsl.polytechnique.fr (Linux)
148;
149;   * usage of $PROJECT_ID and $PROJECT_OD
150;
[19]151; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
152;
153;   * remove hard coded directory for mask_oaflux_30N30S.nc
154;
[8]155; - fplod 20101215T093710Z aedon.locean-ipsl.upmc.fr (Darwin)
156;
157;   * add graph in header
158;
[6]159; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
160;
161;   * minimal header
162;
163; - pbk 2008
164;
165;   * creation
166;
167;-
[166]168function interp_erai_dewt $
169         , yyyymmddb $
170         , yyyymmdde
[66]171;
[166]172;++compile_opt idl2, strictarrsubs, logical_predicate
173;
[66]174@cm_4cal
175@cm_4data
176@cm_4mesh
177@cm_4data
[50]178@cm_project
[19]179;
[166]180; Return to caller if errors
181ON_ERROR, 2
182;
183result = -1
184;
185usage = 'result = interp_erai_t2m(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;
[66]194; check for input directory
[19]195;
[50]196; test if ${PROJECT_ID} defined
197CASE project_id_env OF
[19]198    ''  :  BEGIN
[50]199     msg = 'eee : ${PROJECT_ID} is not defined'
[19]200     ras = report(msg)
[166]201     return, result
[19]202           END
203 ELSE: BEGIN
[50]204     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
[19]205     ras = report(msg)
206       END
207ENDCASE
208;
[50]209iodirin = isadirectory(project_id_env)
[19]210;
[50]211; existence and protection of ${PROJECT_ID}
[19]212IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
213   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
214   ras = report(msg)
[166]215   return, result
[19]216ENDIF
217;
218; build mask filename
219filename_msk='mask_oaflux_30N30S.nc'
220;
221; check if this file exists
[92]222msg='iii : looking for ' + filename_msk
223ras = report(msg)
[19]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)
[166]228   return, result
[19]229ENDIF
230;
[66]231; build data filename
232filename='20c3m_erai_d2_TROP_1989_2009.nc'
[71]233;
234; check if this file exists
[92]235msg='iii : looking for ' + filename
236ras = report(msg)
[66]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)
[166]241   return, result
[66]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)
[166]249       return, result
[66]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)
[166]264    return, result
[66]265ENDIF
266;
267; build output filename
[166]268filename_out = 'erai_d2m_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
[66]269fullfilename_out = iodirout + filename_out
270; in order to avoid unexpected overwritten
[166]271IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
[66]272   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
273   ras = report(msg)
[166]274   return, result
[66]275ENDIF
276;
277initncdf, fullfilename
[5]278domdef
[166]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]
[66]283d2min=read_ncdf("d2",19881201,20101231,file=fullfilename,/nostr)
[97]284;
[94]285jptin=jpt
[166]286tab=d2min[*,*,0]
[5]287mskin=glamt*0.+1.
[97]288;
[19]289initncdf, fullfilename_msk
[5]290domdef
[166]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]
[19]295mskout=read_ncdf("msk", file=fullfilename_msk,/nostr)
[97]296;
[5]297help, d2min,lonin,latin,mskin,lonout,latout,mskout
[97]298;
[5]299d2mout=fltarr(jpi,jpj,jptin)
300for jt=0,jptin-1 do begin
[92]301  ; ++ print, 'Interpolation jt=',jt,' / ',jptin-1
[166]302  tab=reform(d2min[*,*,jt])
303  d2mout[*,*,jt]=call_interp2d(tab,lonin,latin,mskin $
[70]304      , lonout,latout,method='bilinear' $
305      , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout)
[166]306  d2mout[*,*,jt]=d2mout[*,*,jt]*mskout+(1.-mskout)*1.e20
[5]307endfor
[97]308;
[19]309initncdf, fullfilename_msk
[97]310;
[100]311time=timegen(7670, start=julday(1,1,1989,0), units='days')
[94]312jpt=n_elements(time)
[166]313cda0=string(jul2date(time[0]),format='(i8.8)')
314cda1=string(jul2date(time[jpt-1]),format='(i8.8)')
[100]315time=time-julday(1,1,1950,00,00)
[97]316;
[5]317lat=latout
318lon=lonout
[66]319ncfile='!' + fullfilename_out
[5]320lon_attr={units:'degrees_east',long_name:'Longitude'}
321lat_attr={units:'degrees_north',long_name:'Latitude'}
[100]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}
[5]324d2m_attr={units:'degK',missing_value:1e20,long_name:'Dew Point Temperature at 2m',short_name:'d2m',axis:'TYX'}
[97]325;
[5]326ncfields = 'd2m[longitude,latitude,time]=d2mout:d2m_attr; ' $
327                      + 'longitude[]=lon:lon_attr; ' $
328                      + 'latitude[]=lat:lat_attr; ' $
[100]329                      + 'time[*time]=time:time_attr ' $
[5]330                      + ' @ globattr'
[97]331;
[5]332@ncdf_quickwrite
[97]333;
[166]334result = 0
335return, result
336;
[5]337end
Note: See TracBrowser for help on using the repository browser.