source: trunk/src/interp_erai_msl.pro @ 169

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

interp_erai_dewt is now a function

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