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
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; :func:`d2m_to_q2m_erai`.
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; :func:`d2m_to_q2m_erai`
79;
80; EXAMPLES
81; ========
82;
83; ::
84;
85;  IDL> .compile file_interp
86;  IDL> yyyymmddb = 20000101L
87;  IDL> yyyymmdde = 20001231L
88;  IDL> result = interp_erai_msl(yyyymmddb, yyyymmdde)
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 20120320
120;
121;   * no more timegen
122;
123; - fplod 20120319
124;
125;   * taking project_overwite into account
126;   * pro -> function
127;
128; - pinsard 2011-08-23T09:09:16Z loholt1.ipsl.polytechnique.fr (Linux)
129;
130;   * retry on loholt1 with idl8 and idl6
131;
132; - fplod 20110811T113646Z aedon.locean-ipsl.upmc.fr (Darwin)
133;
134;   * check for units in original file before conversion
135;
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;-
150function interp_erai_msl $
151         , yyyymmddb $
152         , yyyymmdde
153;
154;++compile_opt idl2, strictarrsubs, logical_predicate
155;
156@cm_4cal
157@cm_4data
158@cm_4mesh
159@cm_4data
160@cm_project
161;
162; Return to caller if errors
163ON_ERROR, 2
164;
165result = -1
166;
167usage = 'result = interp_erai_msl(yyyymmddb, yyyymmdde)'
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;
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)
183     return, result
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)
197   return, result
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)
210   return, result
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)
223   return, result
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)
231       return, result
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)
246    return, result
247ENDIF
248;
249; build output filename
250filename_out = 'erai_msl_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
251fullfilename_out = iodirout + filename_out
252; in order to avoid unexpected overwritten
253IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
254   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
255   ras = report(msg)
256   return, result
257ENDIF
258;
259initncdf, fullfilename
260domdef
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]
265;++mslin=read_ncdf("msl",yyyymmddb-.5d,yyymmdde,file=fullfilename,/nostr)
266mslin=read_ncdf("msl",19880101,20100930,file=fullfilename,/nostr)
267;
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)')
274print, 'msl first date ', cda0
275print, 'msl last date ' , cda1
276;
277tab=mslin[*,*,0]
278mskin=glamt*0.+1.
279;
280initncdf, fullfilename_msk
281domdef
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]
286mskout=read_ncdf("msk", file=fullfilename_msk,/nostr)
287;
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)
297        return, result
298    END
299ENDCASE
300;
301help, mslin,lonin,latin,mskin,lonout,latout,mskout
302;
303mslout=fltarr(jpi,jpj,jptin)
304for jt=0,jptin-1 do begin
305  ; ++ print, 'Interpolation jt=',jt,' / ',jptin-1
306  tab=reform(mslin[*,*,jt])
307  mslout[*,*,jt]=call_interp2d(tab,lonin,latin,mskin $
308      , lonout,latout,method='bilinear' $
309      , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout)
310  mslout[*,*,jt]=mslout[*,*,jt]*mskout+(1.-mskout)*1.e20
311endfor
312;
313initncdf, fullfilename_msk
314;
315lat=latout
316lon=lonout
317ncfile='!' + fullfilename_out
318lon_attr={units:'degrees_east',long_name:'Longitude'}
319lat_attr={units:'degrees_north',long_name:'Latitude'}
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}
322msl_attr={units:'milibars',missing_value:1e20,long_name:'Mean Sea leval pressure',short_name:'msl',axis:'TYX'}
323;
324ncfields = 'msl[longitude,latitude,*time]=mslout:msl_attr; ' $
325                      + 'longitude[]=lon:lon_attr; ' $
326                      + 'latitude[]=lat:lat_attr; ' $
327                      + 'time[]=timein:time_attr ' $
328                      + ' @ globattr'
329;
330@ncdf_quickwrite
331;
332result = 0
333return, result
334;
335end
Note: See TracBrowser for help on using the repository browser.