source: trunk/src/interp_erai_lwr.pro @ 190

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

no more IDL prompt in examples

  • Property svn:keywords set to Id
File size: 9.7 KB
Line 
1;+
2;
3;
4; ===================
5; interp_erai_lwr.pro
6; ===================
7;
8; .. function:: interp_erai_lwr(yyyymmddb,yyyymmdde)
9;
10; DESCRIPTION
11; ===========
12;
13; Interpolation of str from ERA-I grid to OAFLUX grid
14;
15; :file:`${PROJECT_ID}/20c3m_erai_str_TROP_1989_2009.nc`
16; containing str 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 OAFLUX mask
22; has been produced by
23; :func:`oaflux_mask_30n30s`.
24;
25; Interpolated str
26; is written in
27; :file:`${PROJECT_OD}/erai_lwr_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
28; if this file not already exists.
29;
30; This output file
31; :file:`${PROJECT_OD}/erai_lwr_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
32; must be processed after by
33; :ref:`add_19890101.sh`.
34;
35; .. only:: man
36;
37;    Figure is visible on PDF and HTML documents only.
38;
39; .. only:: html or latex
40;
41;     .. graphviz::
42;
43;        digraph interp_erai_lwr {
44;
45;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/20c3m_erai_str_TROP_1989_2009.nc"];
46;           mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"];
47;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_lwr_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
48;
49;           interp_erai_lwr [shape=box,
50;           fontname=Courier,
51;           color=blue,
52;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_erai_lwr.pro",
53;           label="${PROJECT}/src/interp_erai_lwr.pro"];
54;
55;           {file_in mask} -> {interp_erai_lwr} -> {file_out}
56;
57;        }
58;
59; SEE ALSO
60; ========
61;
62; :ref:`interpolate_data`
63;
64; Used by :ref:`tropflux.sh`
65;
66; :ref:`project_profile.sh`
67;
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;
77; :ref:`add_19890101.sh`
78;
79; EXAMPLES
80; ========
81;
82; ::
83;
84;  .compile file_interp
85;  yyyymmddb = 20000101L
86;  yyyymmdde = 20001231L
87;  result = interp_erai_lwr(yyyymmddb, yyyymmdde)
88;  print, result
89;
90; TODO
91; ====
92;
93; lwr first date 19991231 vs yyyymmddb = 20000101L
94;
95; make it work : pb on loholt1 idl8:
96;
97; reach end but bad values (all NaN)
98;
99; make it work : pb on loholt1 idl6::
100;
101;   lwr[longitude,latitude,time]=lwrout:lwr_attr; longitude[]=xlon:lon_attr; latitude[]=ylat:lat_attr; tt[*time]=tt:time_attr  @ globattr
102;   % NCDF_VARPUT: Operation Failed, bad file (4) or variable [0] id ?
103;                  (NC_ERROR=-31)
104;   % Stop encountered: INTERP_ERAI_LWR_1989_2009    1
105;     /home/pinsard/tropflux_ws/src/interp_erai_lwr_1989_2009.pro
106;
107; check OUTMASK_IND and SET_OUTMSKVAL added to call_interp2d call
108;
109; use real output of :ref:`compute_erai_daily_region_2d.sh`.
110;
111; remove hard coded time
112;
113; 19890101 is not provided in ERA-Intermim file str : a possible workaround is to copy 19890102
114; dataset to 19890101 using nco after this processing. see :ref:`compute_erai_daily_region_2d.sh`
115;
116; check if there is the same issue with 19790101 vs 19790102.
117;
118; coding rules
119;
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;
126; EVOLUTIONS
127; ==========
128;
129; $Id$
130;
131; $URL: svn+ssh://pinsard@forge.ipsl.jussieu.fr/ipsl/forge/projets/tropflux/svn/trunk/src/interp_erai_lwr.pro $
132;
133; - fplod 20120320
134;
135;   * no more timegen
136;
137; - fplod 20120319
138;
139;   * taking project_overwite into account
140;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
141;   * pro -> function
142;
143; - fplod 20110830T145010Z cratos (Linux)
144;
145;   * replace xlon by lon and xlat by lat; suppress extra initcdf call
146;
147; - fplod 20110830T135030Z cratos (Linux)
148;
149;   * replace tt by time
150;
151; - pinsard 2011-08-23T09:09:16Z loholt1.ipsl.polytechnique.fr (Linux)
152;
153;   * retry on loholt1 with idl8 and idl6
154;
155; - fplod 20110819T084310Z aedon.locean-ipsl.upmc.fr (Darwin)
156;
157;   * replace next step lwr_correction_ncdf.pro by :ref:`add_19890101.sh`
158;   * fix output file name to erai_lwr_19890102_20091231_oafluxgrid.nc
159;
160; - pinsard 2011-08-08T16:03:48Z loholt1.ipsl.polytechnique.fr (Linux)
161;
162;   * remove return statement
163;
164; - fplod 20110808T094156Z cratos (Linux)
165;
166;   * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call
167;   * fix typo
168;     .. note::
169;
170;        IDL do not warn when asking size of an undefined array::
171;
172;           IDL> must_crash=size(ginette)
173;
174; - pinsard 2011-07-05T07:33:36Z loholt1.ipsl.polytechnique.fr (Linux)
175;
176;   * usage of $PROJECT_ID and $PROJECT_OD
177;
178; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
179;
180;   * remove hard coded directory for mask_oaflux_30N30S.nc
181;
182; - fplod 20101215T094137Z aedon.locean-ipsl.upmc.fr (Darwin)
183;
184;   * add graph in header
185;
186; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
187;
188;   * minimal header
189;
190; - pbk 2008
191;
192;   * creation
193;
194;-
195function interp_erai_lwr $
196         , yyyymmddb $
197         , yyyymmdde
198;
199;++compile_opt idl2, strictarrsubs, logical_predicate
200;
201@cm_4cal
202@cm_4data
203@cm_4mesh
204@cm_4data
205@cm_project
206;
207; Return to caller if errors
208ON_ERROR, 2
209;
210result = -1
211;
212usage = 'result = interp_erai_lwr(yyyymmddb, yyyymmdde)'
213nparam = N_PARAMS()
214IF (nparam NE 2) THEN BEGIN
215   ras = report(['Incorrect number of arguments.' $
216         + '!C' $
217         + 'Usage : ' + usage])
218   return, result
219ENDIF
220;
221; check for input directory
222;
223; test if ${PROJECT_ID} defined
224CASE project_id_env OF
225    ''  :  BEGIN
226     msg = 'eee : ${PROJECT_ID} is not defined'
227     ras = report(msg)
228     return, result
229           END
230 ELSE: BEGIN
231     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
232     ras = report(msg)
233       END
234ENDCASE
235;
236iodirin = isadirectory(project_id_env)
237;
238; existence and protection of ${PROJECT_ID}
239IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
240   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
241   ras = report(msg)
242   return, result
243ENDIF
244;
245; build mask filename
246filename_msk='mask_oaflux_30N30S.nc'
247;
248; check if this file exists
249msg='iii : looking for ' + filename_msk
250ras = report(msg)
251fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
252IF fullfilename_msk[0] EQ '' THEN BEGIN
253   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
254   ras = report(msg)
255   return, result
256ENDIF
257;
258st=19890101
259en=20090801
260;
261; build data filename
262filename='20c3m_erai_str_TROP_1989_2009.nc'
263;
264; check if this file exists
265msg='iii : looking for ' + filename
266ras = report(msg)
267fullfilename = isafile(iodirin + filename, NEW=0, /MUST_EXIST)
268IF fullfilename[0] EQ '' THEN BEGIN
269   msg = 'eee : the file ' + fullfilename + ' was not found.'
270   ras = report(msg)
271   return, result
272ENDIF
273;
274; test if ${PROJECT_OD} defined
275CASE project_od_env OF
276  '' : BEGIN
277         msg = 'eee : ${PROJECT_OD} is not defined'
278         ras = report(msg)
279       return, result
280       END
281  ELSE: BEGIN
282          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
283          ras = report(msg)
284        END
285 ENDCASE
286;
287; check if output data will be possible
288iodirout = isadirectory(project_od_env)
289;
290; existence and protection
291IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
292    msg = 'eee : the directory' + iodirout  + ' was not found.'
293    ras = report(msg)
294    return, result
295ENDIF
296;
297; build output filename
298filename_out = 'erai_lwr_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
299fullfilename_out = iodirout + filename_out
300; in order to avoid unexpected overwritten
301IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
302   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
303   ras = report(msg)
304   return, result
305ENDIF
306;
307initncdf, fullfilename
308lwrin=read_ncdf("str",yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr)
309lwrin=-1*lwrin
310timein=24.d*(time-julday(1,1,1957,0,0,0))
311jptin=n_elements(timein)
312da=jul2date(time[0])
313cda0=string(da,format='(i8.8)')
314da=jul2date(time[jpt-1])
315cda1=string(da,format='(i8.8)')
316print, 'lwr first date ', cda0
317print, 'lwr last date ' , cda1
318;
319initncdf, fullfilename
320domdef
321latin=reform(gphit[0,*])
322lonin=reform(glamt[*,0])
323print, 'lat grid ',min(latin),max(latin),latin[1]-latin[0]
324print, 'lon grid ',min(lonin),max(lonin),lonin[1]-lonin[0]
325;
326tab=lwrin[*,*,0]
327mskin=glamt*0.+1.
328;
329initncdf, fullfilename_msk
330domdef
331latout=reform(gphit[0,*])
332lonout=reform(glamt[*,0])
333print, 'lat grid ',min(latout),max(latout),latout[1]-latout[0]
334print, 'lon grid ',min(lonout),max(lonout),lonout[1]-lonout[0]
335mskout=read_ncdf("msk", file=fullfilename_msk,/nostr)
336;
337lwrout=fltarr(jpi,jpj,jptin)
338;
339for jt=0,jptin-1 do begin
340  ; ++print, 'Interpolation jt=',jt,' / ',jptin-1
341;
342  tab=reform(lwrin[*,*,jt])
343  lwrout[*,*,jt]=call_interp2d(tab,lonin,latin,mskin $
344      , lonout,latout,method='bilinear' $
345      , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout)
346  lwrout[*,*,jt]=lwrout[*,*,jt]*mskout+(1.-mskout)*1.e20
347;
348endfor
349;
350lat=latout
351lon=lonout
352ncfile='!' + fullfilename_out
353lon_attr={units:'degrees_east',long_name:'Longitude'}
354lat_attr={units:'degrees_north',long_name:'Latitude'}
355time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
356globattr={source:'Tropical ocean fluxes obtained from ERA Interim',timerange:cda0+' - '+cda1}
357lwr_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net longwave radiation ',short_name:'lwr',axis:'TYX'}
358;
359ncfields = 'lwr[longitude,latitude,*time]=lwrout:lwr_attr; ' $
360                      + 'longitude[]=lon:lon_attr; ' $
361                      + 'latitude[]=lat:lat_attr; ' $
362                      + 'time[]=timein:time_attr ' $
363                      + ' @ globattr'
364;
365@ncdf_quickwrite
366;
367result = 0
368return, result
369;
370end
Note: See TracBrowser for help on using the repository browser.