source: trunk/src/interp_erai_lwr.pro @ 199

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

introduce new erai dataset : new terminology and new time unit and origin

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