source: trunk/src/interp_erai_lwr.pro @ 169

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

interp_erai_lwr is now a function

  • Property svn:keywords set to Id
File size: 9.6 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;  IDL> .compile file_interp
85;  IDL> yyyymmddb = 19890101
86;  IDL> yyyymmdde = 20091231
87;  IDL> result = interp_erai_lwr(yyyymmddb, yyymmdde)
88;  IDL> print, result
89;
90; TODO
91; ====
92;
93; make it work : pb on loholt1 idl8:
94;
95; reach end but bad values (all NaN)
96;
97; make it work : pb on loholt1 idl6::
98;
99;   lwr[longitude,latitude,time]=lwrout:lwr_attr; longitude[]=xlon:lon_attr; latitude[]=ylat:lat_attr; tt[*time]=tt:time_attr  @ globattr
100;   % NCDF_VARPUT: Operation Failed, bad file (4) or variable [0] id ?
101;                  (NC_ERROR=-31)
102;   % Stop encountered: INTERP_ERAI_LWR_1989_2009    1
103;     /home/pinsard/tropflux_ws/src/interp_erai_lwr_1989_2009.pro
104;
105; check OUTMASK_IND and SET_OUTMSKVAL added to call_interp2d call
106;
107; use real output of :ref:`compute_erai_daily_region_2d.sh`.
108;
109; remove hard coded time
110;
111; 19890101 is not provided in ERA-Intermim file str : a possible workaround is to copy 19890102
112; dataset to 19890101 using nco after this processing. see :ref:`compute_erai_daily_region_2d.sh`
113;
114; st and en not used
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 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;
139; - fplod 20110830T145010Z cratos (Linux)
140;
141;   * replace xlon by lon and xlat by lat; suppress extra initcdf call
142;
143; - fplod 20110830T135030Z cratos (Linux)
144;
145;   * replace tt by time
146;
147; - pinsard 2011-08-23T09:09:16Z loholt1.ipsl.polytechnique.fr (Linux)
148;
149;   * retry on loholt1 with idl8 and idl6
150;
151; - fplod 20110819T084310Z aedon.locean-ipsl.upmc.fr (Darwin)
152;
153;   * replace next step :ref:`lwr_correction_ncdf.pro` by :ref:`add_19890101.sh`
154;   * fix output file name to erai_lwr_19890102_20091231_oafluxgrid.nc
155;
156; - pinsard 2011-08-08T16:03:48Z loholt1.ipsl.polytechnique.fr (Linux)
157;
158;   * remove return statement
159;
160; - fplod 20110808T094156Z cratos (Linux)
161;
162;   * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call
163;   * fix typo
164;     .. note::
165;
166;        IDL do not warn when asking size of an undefined array::
167;
168;           IDL> must_crash=size(ginette)
169;
170; - pinsard 2011-07-05T07:33:36Z loholt1.ipsl.polytechnique.fr (Linux)
171;
172;   * usage of $PROJECT_ID and $PROJECT_OD
173;
174; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
175;
176;   * remove hard coded directory for mask_oaflux_30N30S.nc
177;
178; - fplod 20101215T094137Z aedon.locean-ipsl.upmc.fr (Darwin)
179;
180;   * add graph in header
181;
182; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
183;
184;   * minimal header
185;
186; - pbk 2008
187;
188;   * creation
189;
190;-
191function interp_erai_lwr $
192         , yyyymmddb $
193         , yyyymmdde
194;
195;++compile_opt idl2, strictarrsubs, logical_predicate
196;
197@cm_4cal
198@cm_4data
199@cm_4mesh
200@cm_4data
201@cm_project
202;
203; Return to caller if errors
204ON_ERROR, 2
205;
206result = -1
207;
208usage = 'result = interp_erai_lwr(yyyymmddb, yyyymmdde)
209nparam = N_PARAMS()
210IF (nparam NE 2) THEN BEGIN
211   ras = report(['Incorrect number of arguments.' $
212         + '!C' $
213         + 'Usage : ' + usage])
214   return, result
215ENDIF
216;
217; check for input directory
218;
219; test if ${PROJECT_ID} defined
220CASE project_id_env OF
221    ''  :  BEGIN
222     msg = 'eee : ${PROJECT_ID} is not defined'
223     ras = report(msg)
224     return, result
225           END
226 ELSE: BEGIN
227     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
228     ras = report(msg)
229       END
230ENDCASE
231;
232iodirin = isadirectory(project_id_env)
233;
234; existence and protection of ${PROJECT_ID}
235IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
236   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
237   ras = report(msg)
238   return, result
239ENDIF
240;
241; build mask filename
242filename_msk='mask_oaflux_30N30S.nc'
243;
244; check if this file exists
245msg='iii : looking for ' + filename_msk
246ras = report(msg)
247fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
248IF fullfilename_msk[0] EQ '' THEN BEGIN
249   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
250   ras = report(msg)
251   return, result
252ENDIF
253;
254st=19890101
255en=20090801
256;
257; build data filename
258filename='20c3m_erai_str_TROP_1989_2009.nc'
259;
260; check if this file exists
261msg='iii : looking for ' + filename
262ras = report(msg)
263fullfilename = isafile(iodirin + filename, NEW=0, /MUST_EXIST)
264IF fullfilename[0] EQ '' THEN BEGIN
265   msg = 'eee : the file ' + fullfilename + ' was not found.'
266   ras = report(msg)
267   return, result
268ENDIF
269;
270; test if ${PROJECT_OD} defined
271CASE project_od_env OF
272  '' : BEGIN
273         msg = 'eee : ${PROJECT_OD} is not defined'
274         ras = report(msg)
275       return, result
276       END
277  ELSE: BEGIN
278          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
279          ras = report(msg)
280        END
281 ENDCASE
282;
283; check if output data will be possible
284iodirout = isadirectory(project_od_env)
285;
286; existence and protection
287IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
288    msg = 'eee : the directory' + iodirout  + ' was not found.'
289    ras = report(msg)
290    return, result
291ENDIF
292;
293; build output filename
294filename_out = 'erai_lwr_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
295fullfilename_out = iodirout + filename_out
296; in order to avoid unexpected overwritten
297IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
298   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
299   ras = report(msg)
300   return, result
301ENDIF
302;
303initncdf, fullfilename
304lwrin=read_ncdf("str",0,7668,/timestep,file=fullfilename,/nostr)
305lwrin=-1*lwrin
306;
307initncdf, fullfilename
308domdef
309latin=reform(gphit[0,*])
310lonin=reform(glamt[*,0])
311print, 'lat grid ',min(latin),max(latin),latin[1]-latin[0]
312print, 'lon grid ',min(lonin),max(lonin),lonin[1]-lonin[0]
313;
314jptin=jpt
315tab=lwrin[*,*,0]
316mskin=glamt*0.+1.
317;
318initncdf, fullfilename_msk
319domdef
320latout=reform(gphit[0,*])
321lonout=reform(glamt[*,0])
322print, 'lat grid ',min(latout),max(latout),latout[1]-latout[0]
323print, 'lon grid ',min(lonout),max(lonout),lonout[1]-lonout[0]
324mskout=read_ncdf("msk", file=fullfilename_msk,/nostr)
325;
326lwrout=fltarr(jpi,jpj,jptin)
327;
328for jt=0,jptin-1 do begin
329  ; ++print, 'Interpolation jt=',jt,' / ',jptin-1
330;
331  tab=reform(lwrin[*,*,jt])
332  lwrout[*,*,jt]=call_interp2d(tab,lonin,latin,mskin $
333      , lonout,latout,method='bilinear' $
334      , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout)
335  lwrout[*,*,jt]=lwrout[*,*,jt]*mskout+(1.-mskout)*1.e20
336;
337endfor
338;
339time=timegen(7669, start=julday(1,2,1989,0), units='days')
340jpt=n_elements(time)
341cda0=string(jul2date(time[0]),format='(i8.8)')
342cda1=string(jul2date(time[jpt-1]),format='(i8.8)')
343time=time-julday(1,1,1950,00,00,00)
344;
345lat=latout
346lon=lonout
347ncfile='!' + fullfilename_out
348lon_attr={units:'degrees_east',long_name:'Longitude'}
349lat_attr={units:'degrees_north',long_name:'Latitude'}
350time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
351globattr={source:'Tropical ocean fluxes obtained from ERA Interim',timerange:cda0+' - '+cda1}
352lwr_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net longwave radiation ',short_name:'lwr',axis:'TYX'}
353;
354ncfields = 'lwr[longitude,latitude,time]=lwrout:lwr_attr; ' $
355                      + 'longitude[]=lon:lon_attr; ' $
356                      + 'latitude[]=lat:lat_attr; ' $
357                      + 'time[*time]=time:time_attr ' $
358                      + ' @ globattr'
359;
360@ncdf_quickwrite
361;
362result = 0
363return, result
364;
365end
Note: See TracBrowser for help on using the repository browser.