source: trunk/src/interp_erai_msl.pro @ 178

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

bunch of new functions

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