source: trunk/src/interp_erai_sst.pro @ 174

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

bunch of new functions

  • Property svn:keywords set to Id
File size: 8.6 KB
Line 
1;+
2;
3;
4; ===================
5; interp_erai_sst.pro
6; ===================
7;
8; .. function:: interp_erai_sst(yyyymmddb,yyyymmdde)
9;
10; DESCRIPTION
11; ===========
12;
13; Interpolation of sst from ERA-I grid to OAFLUX grid
14;
15; :file:`${PROJECT_ID}/20c3m_erai_sstk_TROP_1989_2009.nc`
16; containing sst 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
22; OAFLUX grid
23; has been produced by
24; :func:`oaflux_mask_30n30s`.
25;
26; Interpolated sst
27; is written in
28; :file:`${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
29; if this file not already exists.
30;
31; This output file
32; :file:`${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
33; must be processed after by
34; :ref:`sst_correction_ncdf.pro`.
35;
36; .. only:: man
37;
38;    Figure is visible on PDF and HTML documents only.
39;
40; .. only:: html or latex
41;
42;     .. graphviz::
43;
44;        digraph interp_erai_sst {
45;
46;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/20c3m_erai_sstk_TROP_1989_2009.nc"];
47;           mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"];
48;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
49;
50;           interp_erai_sst [shape=box,
51;           fontname=Courier,
52;           color=blue,
53;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_erai_sst.pro",
54;           label="${PROJECT}/src/interp_erai_sst.pro"];
55;
56;           {file_in mask} -> {interp_erai_sst} -> {file_out}
57;
58;        }
59;
60; SEE ALSO
61; ========
62;
63; :ref:`interpolate_data`
64;
65; Used by :ref:`tropflux.sh`
66;
67; :ref:`project_profile.sh`
68;
69; :func:`report <saxo:report>`
70; :func:`isadirectory <saxo:isadirectory>`
71; :func:`isafile <saxo:isafile>`
72; :func:`initncdf <saxo:initncdf>`
73; :func:`read_ncdf <saxo:read_ncdf>`
74; :func:`domdef <saxo:domdef>`
75; :func:`call_interp2d <saxo:call_interp2d>`
76; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
77;
78; :ref:`sst_correction_ncdf.pro`
79;
80; EXAMPLES
81; ========
82;
83; ::
84;
85;  IDL> .compile file_interp
86;  IDL> yyyymmddb = 20000101L
87;  IDL> yyyymmdde = 20001231L
88;  IDL> result = interp_erai_sst(yyyymmddb, yyyymmdde)
89;  IDL> print, result
90;
91;
92; TODO
93; ====
94;
95; on cratos strange red data looking with ncview
96;
97; check OUTMASK_IND and SET_OUTMSKVAL added to call_interp2d call
98;
99; coding rules
100;
101; use real output of :ref:`compute_erai_daily_region_2d.sh`.
102;
103; scientific validation (strange look of data with ncview now)
104;
105; check [yyyymmddb,yyyymmdde] validity
106;
107; check if [yyyymmddb,yyyymmdde] is included in ERA-I file
108;
109; what happen if yyyymmdde > 20091231 : need to read an other ERA-I file
110;
111; KNOWN ISSUES
112; ============
113;
114; test of existence of fullfilename_msk not very efficient because
115; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
116;
117; EVOLUTIONS
118; ==========
119;
120; $Id$
121;
122; $URL: svn+ssh://pinsard@forge.ipsl.jussieu.fr/ipsl/forge/projets/tropflux/svn/trunk/src/interp_erai_sst.pro $
123;
124; - fplod 20120320
125;
126;   * taking project_overwite into account
127;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
128;   * pro -> function
129;   * no more timegen
130;
131; - pinsard 2011-08-23T09:09:16Z loholt1.ipsl.polytechnique.fr (Linux)
132;
133;   * retry on loholt1 with idl8 and idl6
134;
135; - fplod 20110808T094156Z cratos (Linux)
136;
137;   * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call
138;
139; - pinsard 2011-07-04T15:45:35Z loholt1.ipsl.polytechnique.fr (Linux)
140;
141;   * usage of ${PROJECT_ID} and $PROJECT_OD
142;
143; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
144;
145;   * remove hard coded directory for mask_oaflux_30N30S.nc
146;
147; - fplod 20101215T100932Z aedon.locean-ipsl.upmc.fr (Darwin)
148;
149;   * add graph in header
150;
151; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
152;
153;   * minimal header
154;
155; - pbk 2008
156;
157;   * creation
158;
159;-
160function interp_erai_sst $
161         , yyyymmddb $
162         , yyyymmdde
163;
164;++compile_opt idl2, strictarrsubs, logical_predicate
165;
166@cm_4cal
167@cm_4data
168@cm_4mesh
169@cm_4data
170@cm_project
171;
172; Return to caller if errors
173ON_ERROR, 2
174;
175result = -1
176;
177usage = 'result = interp_erai_lwr(yyyymmddb, yyyymmdde)'
178nparam = N_PARAMS()
179IF (nparam NE 2) THEN BEGIN
180   ras = report(['Incorrect number of arguments.' $
181   + '!C' $
182   + 'Usage : ' + usage])
183   return, result
184ENDIF
185;
186; check for input directory
187;
188; test if ${PROJECT_ID} defined
189CASE project_id_env OF
190    ''  :  BEGIN
191     msg = 'eee : ${PROJECT_ID} is not defined'
192     ras = report(msg)
193     return, result
194           END
195 ELSE: BEGIN
196     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
197     ras = report(msg)
198       END
199ENDCASE
200;
201iodirin = isadirectory(project_id_env)
202;
203; existence and protection of ${PROJECT_ID}
204IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
205   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
206   ras = report(msg)
207   return, result
208ENDIF
209;
210; build mask filename
211filename_msk='mask_oaflux_30N30S.nc'
212;
213; check if this file exists
214msg='iii : looking for ' + filename_msk
215ras = report(msg)
216fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
217IF fullfilename_msk[0] EQ '' THEN BEGIN
218   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
219   ras = report(msg)
220   return, result
221ENDIF
222;
223; build data filename
224filename='20c3m_erai_sstk_TROP_1989_2009.nc'
225;
226; check if this file exists
227msg='iii : looking for ' + filename
228ras = report(msg)
229fullfilename = isafile(iodirin + filename, NEW=0, /MUST_EXIST)
230IF fullfilename[0] EQ '' THEN BEGIN
231   msg = 'eee : the file ' + fullfilename + ' was not found.'
232   ras = report(msg)
233   return, result
234ENDIF
235;
236; test if ${PROJECT_OD} defined
237CASE project_od_env OF
238  '' : BEGIN
239         msg = 'eee : ${PROJECT_OD} is not defined'
240         ras = report(msg)
241       return, result
242       END
243  ELSE: BEGIN
244          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
245          ras = report(msg)
246        END
247 ENDCASE
248;
249; check if output data will be possible
250iodirout = isadirectory(project_od_env)
251;
252; existence and protection
253IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
254    msg = 'eee : the directory' + iodirout  + ' was not found.'
255    ras = report(msg)
256    return, result
257ENDIF
258;
259; build output filename
260filename_out = 'erai_sst_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
261fullfilename_out = iodirout + filename_out
262; in order to avoid unexpected overwritten
263IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
264   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
265   ras = report(msg)
266   return, result
267ENDIF
268;
269initncdf, fullfilename
270domdef
271latin=reform(gphit[0,*])
272lonin=reform(glamt[*,0])
273print, 'lat grid ',min(latin),max(latin),latin[1]-latin[0]
274print, 'lon grid ',min(lonin),max(lonin),lonin[1]-lonin[0]
275sstkin=read_ncdf("sstk",yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr)
276;
277timein=24.d*(time-julday(1,1,1957,0,0,0))
278jptin=n_elements(timein)
279da=jul2date(time[0])
280cda0=string(da,format='(i8.8)')
281da=jul2date(time[jpt-1])
282cda1=string(da,format='(i8.8)')
283print, 'sst first date ', cda0
284print, 'sst last date ' , cda1
285;
286tab=sstkin[*,*,0]
287mskin=glamt*0.+1.
288ind=where((tab eq 1.e9) or finite(tab,/nan))
289mskin[ind]=0.
290;
291initncdf, fullfilename_msk
292domdef
293latout=reform(gphit[0,*])
294lonout=reform(glamt[*,0])
295print, 'lat grid ',min(latout),max(latout),latout[1]-latout[0]
296print, 'lon grid ',min(lonout),max(lonout),lonout[1]-lonout[0]
297mskout=read_ncdf("msk", file=fullfilename_msk,/nostr)
298;
299help, sstkin,lonin,latin,mskin,lonout,latout,mskout
300;
301sstkout=fltarr(jpi,jpj,jptin)
302for jt=0,jptin-1 do begin
303  ; ++print, 'Interpolation jt=',jt,' / ',jptin-1
304  tab=reform(sstkin[*,*,jt])
305  sstkout[*,*,jt]=call_interp2d(tab,lonin,latin,mskin $
306      , lonout,latout,method='bilinear' $
307      , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout)
308  sstkout[*,*,jt]=sstkout[*,*,jt]*mskout+(1.-mskout)*1.e20
309endfor
310;
311initncdf, fullfilename_msk
312;
313lat=latout
314lon=lonout
315ncfile='!' + fullfilename_out
316lon_attr={units:'degrees_east',long_name:'Longitude'}
317lat_attr={units:'degrees_north',long_name:'Latitude'}
318time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
319globattr={source:'Data are from ECMWF ERA-Interim reanalysis', timerange:cda0+' - '+cda1}
320sstk_attr={units:'degK',missing_value:1e20,long_name:'Sea Surface Temperature',short_name:'sst',axis:'TYX'}
321;
322ncfields = 'sst[longitude,latitude,*time]=sstkout:sstk_attr; ' $
323                      + 'longitude[]=lon:lon_attr; ' $
324                      + 'latitude[]=lat:lat_attr; ' $
325                      + 'time[]=timein:time_attr ' $
326                      + ' @ globattr'
327;
328@ncdf_quickwrite
329;
330result = 0
331return, result
332;
333end
Note: See TracBrowser for help on using the repository browser.