source: trunk/src/interp_erai_sst.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: 9.9 KB
Line 
1;+
2;
3;
4; ===================
5; interp_erai_sst.pro
6; ===================
7;
8; .. function:: interp_erai_sst(yyyymmddb,yyyymmdde, eraitype)
9;
10; DESCRIPTION
11; ===========
12;
13; Interpolation of sst from ERA-I grid to OAFLUX grid
14;
15; If eraitype is set to 1,
16; :file:`${PROJECT_ID}/20c3m_erai_sstk_TROP_1989_2009.nc`
17; containing sst 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_sst_{yyyyb}_{yyyye}.nc`
23; containing sst from ERA-I
24; has been produced by
25; :ref:`concat_eraiy.sh`.
26;
27; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc`
28; containing
29; OAFLUX grid
30; has been produced by
31; :func:`oaflux_mask_30n30s`.
32;
33; Interpolated sst
34; is written in
35; :file:`${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
36; if this file not already exists.
37;
38; This output file
39; :file:`${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
40; must be processed after by
41; :func:`sst_correction_ncdf`.
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_sst {
52;
53;           file_in_erai1 [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/20c3m_erai_sstk_TROP_1989_2009.nc"];
54;           file_in_erai2 [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/erai_sst_{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_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
57;
58;           interp_erai_sst [shape=box,
59;           fontname=Courier,
60;           color=blue,
61;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_erai_sst.pro",
62;           label="${PROJECT}/src/interp_erai_sst.pro"];
63;
64;           {file_in_erai1 file_in_erai2 mask} -> {interp_erai_sst} -> {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; :func:`sst_correction_ncdf`
90;
91; EXAMPLES
92; ========
93;
94; With ERA-I type 1::
95;
96;  .compile file_interp
97;  yyyymmddb = 20000101L
98;  yyyymmdde = 20001231L
99;  eraitype = 1
100;  result = interp_erai_sst(yyyymmddb, yyyymmdde, eraitype)
101;  print, result
102;
103; With ERA-I type 2::
104;
105;  .compile file_interp
106;  yyyymmddb = 20000101L
107;  yyyymmdde = 20001231L
108;  eraitype = 2
109;  result = interp_erai_sst(yyyymmddb, yyyymmdde, eraitype)
110;
111; TODO
112; ====
113;
114; on cratos strange red data looking with ncview
115;
116; check OUTMASK_IND and SET_OUTMSKVAL added to call_interp2d call
117;
118; coding rules
119;
120; use real output of :ref:`compute_erai_daily_region_2d.sh` if eraitype is set to 1.
121;
122; scientific validation (strange look of data with ncview now)
123;
124; check [yyyymmddb,yyyymmdde] validity
125;
126; check if [yyyymmddb,yyyymmdde] is included in ERA-I file
127;
128; what happen if yyyymmdde > 20091231 : need to read an other ERA-I file
129;
130; KNOWN ISSUES
131; ============
132;
133; test of existence of fullfilename_msk not very efficient because
134; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
135;
136; EVOLUTIONS
137; ==========
138;
139; $Id$
140;
141; $URL: svn+ssh://pinsard@forge.ipsl.jussieu.fr/ipsl/forge/projets/tropflux/svn/trunk/src/interp_erai_sst.pro $
142;
143; - fplod 20120704T113504Z cratos (Linux)
144;
145;   * add eraitype parameter
146;   * deal with time units (days vs hours) and time origin
147;
148; - fplod 20120320
149;
150;   * taking project_overwite into account
151;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
152;   * pro -> function
153;   * no more timegen
154;
155; - pinsard 2011-08-23T09:09:16Z loholt1.ipsl.polytechnique.fr (Linux)
156;
157;   * retry on loholt1 with idl8 and idl6
158;
159; - fplod 20110808T094156Z cratos (Linux)
160;
161;   * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call
162;
163; - pinsard 2011-07-04T15:45:35Z loholt1.ipsl.polytechnique.fr (Linux)
164;
165;   * usage of ${PROJECT_ID} and $PROJECT_OD
166;
167; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
168;
169;   * remove hard coded directory for mask_oaflux_30N30S.nc
170;
171; - fplod 20101215T100932Z aedon.locean-ipsl.upmc.fr (Darwin)
172;
173;   * add graph in header
174;
175; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
176;
177;   * minimal header
178;
179; - pbk 2008
180;
181;   * creation
182;
183;-
184function interp_erai_sst $
185         , yyyymmddb $
186         , yyyymmdde $
187         , eraitype
188;
189;++compile_opt idl2, strictarrsubs, logical_predicate
190;
191@cm_4cal
192@cm_4data
193@cm_4mesh
194@cm_4data
195@cm_project
196;
197; Return to caller if errors
198ON_ERROR, 2
199;
200result = -1
201;
202usage = 'result = interp_erai_lwr(yyyymmddb, yyyymmdde, eraitype)'
203nparam = N_PARAMS()
204IF (nparam NE 3) THEN BEGIN
205   ras = report(['Incorrect number of arguments.' $
206   + '!C' $
207   + 'Usage : ' + usage])
208   return, result
209ENDIF
210;
211; check for input directory
212;
213; test if ${PROJECT_ID} defined
214CASE project_id_env OF
215    ''  :  BEGIN
216     msg = 'eee : ${PROJECT_ID} is not defined'
217     ras = report(msg)
218     return, result
219           END
220 ELSE: BEGIN
221     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
222     ras = report(msg)
223       END
224ENDCASE
225;
226iodirin = isadirectory(project_id_env)
227;
228; existence and protection of ${PROJECT_ID}
229IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
230   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
231   ras = report(msg)
232   return, result
233ENDIF
234;
235; build mask filename
236filename_msk='mask_oaflux_30N30S.nc'
237;
238; check if this file exists
239msg='iii : looking for ' + filename_msk
240ras = report(msg)
241fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
242IF fullfilename_msk[0] EQ '' THEN BEGIN
243   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
244   ras = report(msg)
245   return, result
246ENDIF
247;
248; build data filename
249IF eraitype EQ 1 THEN BEGIN
250    erai_var = 'sstk'
251    filename='20c3m_erai_sstk_TROP_1989_2009.nc'
252    tutoday = 24.d
253    tmporig = date2jul(19570101L,month=immo,day=iddo,year=iyyyyo)
254endif
255IF (eraitype eq 2) THEN BEGIN
256    erai_var = 'sst'
257    tmpb = date2jul(yyyymmddb,month=immb,day=iddb,year=iyyyyb)
258    tmpe = date2jul(yyyymmdde,month=imme,day=idde,year=iyyyye)
259    filename = 'erai_' + erai_var + '_' + string(iyyyyb,format='(I4.4)') + '_' + string(iyyyye,format='(I4.4)') + '.nc'
260    tutoday = 1.d
261    tmporig = date2jul(19500101L,month=immo,day=iddo,year=iyyyyo)
262ENDIF
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_sst_' + 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
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]
313sstkin=read_ncdf(erai_var,yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr)
314;
315timein=tutoday*(time-julday(immo,iddo,iyyyyo,0,0,0))
316jptin=n_elements(timein)
317da=jul2date(time[0])
318cda0=string(da,format='(i8.8)')
319da=jul2date(time[jpt-1])
320cda1=string(da,format='(i8.8)')
321print, 'sst first date ', cda0
322print, 'sst last date ' , cda1
323;
324tab=sstkin[*,*,0]
325mskin=glamt*0.+1.
326ind=where((tab eq 1.e9) or finite(tab,/nan))
327mskin[ind]=0.
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;
337help, sstkin,lonin,latin,mskin,lonout,latout,mskout
338;
339sstkout=fltarr(jpi,jpj,jptin)
340for jt=0,jptin-1 do begin
341  ; ++print, 'Interpolation jt=',jt,' / ',jptin-1
342  tab=reform(sstkin[*,*,jt])
343  sstkout[*,*,jt]=call_interp2d(tab,lonin,latin,mskin $
344      , lonout,latout,method='bilinear' $
345      , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout)
346  sstkout[*,*,jt]=sstkout[*,*,jt]*mskout+(1.-mskout)*1.e20
347endfor
348;
349initncdf, fullfilename_msk
350;
351lat=latout
352lon=lonout
353ncfile='!' + fullfilename_out
354lon_attr={units:'degrees_east',long_name:'Longitude'}
355lat_attr={units:'degrees_north',long_name:'Latitude'}
356time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
357globattr={source:'Data are from ECMWF ERA-Interim reanalysis', timerange:cda0+' - '+cda1}
358sstk_attr={units:'degK',missing_value:1e20,long_name:'Sea Surface Temperature',short_name:'sst',axis:'TYX'}
359;
360ncfields = 'sst[longitude,latitude,*time]=sstkout:sstk_attr; ' $
361                      + 'longitude[]=lon:lon_attr; ' $
362                      + 'latitude[]=lat:lat_attr; ' $
363                      + 'time[]=timein:time_attr ' $
364                      + ' @ globattr'
365;
366@ncdf_quickwrite
367;
368result = 0
369return, result
370;
371end
Note: See TracBrowser for help on using the repository browser.