source: trunk/src/interp_erai_lwr.pro @ 175

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

an other bunch of new functions

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