source: trunk/src/interp_erai_sst.pro @ 178

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

an other bunch of new functions

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