;+ ; ; ; =================== ; interp_erai_sst.pro ; =================== ; ; .. function:: interp_erai_sst(yyyymmddb,yyyymmdde, eraitype) ; ; DESCRIPTION ; =========== ; ; Interpolation of sst from ERA-I grid to OAFLUX grid ; ; If eraitype is set to 1, ; :file:`${PROJECT_ID}/20c3m_erai_sstk_TROP_1989_2009.nc` ; containing sst from ERA-I ; has been produced by ; :ref:`compute_erai_daily_region_2d.sh`. ; ; If eraitype is set to 2, ; :file:`${PROJECT_ID}/erai_sst_{yyyyb}_{yyyye}.nc` ; containing sst from ERA-I ; has been produced by ; :ref:`concat_eraiy.sh`. ; ; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc` ; containing ; OAFLUX grid ; has been produced by ; :func:`oaflux_mask_30n30s`. ; ; Interpolated sst ; is written in ; :file:`${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc` ; if this file not already exists. ; ; This output file ; :file:`${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc` ; must be processed after by ; :func:`sst_correction_ncdf`. ; ; .. only:: man ; ; Figure is visible on PDF and HTML documents only. ; ; .. only:: html or latex ; ; .. graphviz:: ; ; digraph interp_erai_sst { ; ; file_in_erai1 [shape=ellipse, ; fontname=Courier, ; label="${PROJECT_ID}/20c3m_erai_sstk_TROP_1989_2009.nc"]; ; file_in_erai2 [shape=ellipse, ; fontname=Courier, ; label="${PROJECT_ID}/erai_sst_{yyyyb}_{yyyye}.nc"]; ; mask [shape=ellipse, ; fontname=Courier, ; label="${PROJECT_ID}/mask_oaflux_30N30S.nc"]; ; file_out [shape=ellipse, ; fontname=Courier, ; label="${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"]; ; ; interp_erai_sst [shape=box, ; fontname=Courier, ; color=blue, ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_erai_sst.pro", ; label="${PROJECT}/src/interp_erai_sst.pro"]; ; ; {file_in_erai1 file_in_erai2 mask} -> {interp_erai_sst} -> {file_out} ; ; } ; ; SEE ALSO ; ======== ; ; :ref:`interpolate_data` ; ; Used by :ref:`tropflux.sh` ; ; :ref:`project_profile.sh` ; ; :ref:`compute_erai_daily_region_2d.sh` ; :ref:`concat_eraiy.sh` ; ; :func:`report ` ; :func:`isadirectory ` ; :func:`isafile ` ; :func:`initncdf ` ; :func:`read_ncdf ` ; :func:`domdef ` ; :func:`call_interp2d ` ; :func:`ncdf_quickwrite ` ; ; :func:`sst_correction_ncdf` ; ; EXAMPLES ; ======== ; ; With ERA-I type 1: ; ; .. code-block:: idl ; ; .compile file_interp ; yyyymmddb = 20000101L ; yyyymmdde = 20001231L ; eraitype = 1 ; result = interp_erai_sst(yyyymmddb, yyyymmdde, eraitype) ; print, result ; ; With ERA-I type 2: ; ; .. code-block:: idl ; ; .compile file_interp ; yyyymmddb = 20000101L ; yyyymmdde = 20001231L ; eraitype = 2 ; result = interp_erai_sst(yyyymmddb, yyyymmdde, eraitype) ; ; TODO ; ==== ; ; on cratos strange red data looking with ncview ; ; check OUTMASK_IND and SET_OUTMSKVAL added to call_interp2d call ; ; coding rules ; ; use real output of :ref:`compute_erai_daily_region_2d.sh` if eraitype is ; set to 1. ; ; scientific validation (strange look of data with ncview now) ; ; check [yyyymmddb,yyyymmdde] validity ; ; check if [yyyymmddb,yyyymmdde] is included in ERA-I file ; ; what happen if yyyymmdde > 20091231 : need to read an other ERA-I file ; ; KNOWN ISSUES ; ============ ; ; test of existence of fullfilename_msk not very efficient because ; MUST_EXIST keyword of :func:`isafile ` not yet implemented ; ; EVOLUTIONS ; ========== ; ; $Id$ ; ; $URL: svn+ssh://pinsard@forge.ipsl.jussieu.fr/ipsl/forge/projets/tropflux/svn/trunk/src/interp_erai_sst.pro $ ; ; - fplod 20120704T113504Z cratos (Linux) ; ; * add eraitype parameter ; * deal with time units (days vs hours) and time origin ; ; - fplod 20120320 ; ; * taking project_overwrite into account ; * try to add compile_opt seems to be incompatible with ncdf_quickwrite ; * pro -> function ; * no more timegen ; ; - pinsard 2011-08-23T09:09:16Z loholt1.ipsl.polytechnique.fr (Linux) ; ; * retry on loholt1 with idl8 and idl6 ; ; - fplod 20110808T094156Z cratos (Linux) ; ; * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call ; ; - pinsard 2011-07-04T15:45:35Z loholt1.ipsl.polytechnique.fr (Linux) ; ; * usage of ${PROJECT_ID} and $PROJECT_OD ; ; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * remove hard coded directory for mask_oaflux_30N30S.nc ; ; - fplod 20101215T100932Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * add graph in header ; ; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * minimal header ; ; - pbk 2008 ; ; * creation ; ;- function interp_erai_sst $ , yyyymmddb $ , yyyymmdde $ , eraitype ; ;++compile_opt idl2, strictarrsubs, logical_predicate ; @cm_4cal @cm_4data @cm_4mesh @cm_4data @cm_project ; ; Return to caller if errors ON_ERROR, 2 ; result = -1 ; usage = 'result = interp_erai_lwr(yyyymmddb, yyyymmdde, eraitype)' nparam = N_PARAMS() IF (nparam NE 3) THEN BEGIN ras = report(['Incorrect number of arguments.' $ + '!C' $ + 'Usage : ' + usage]) return, result ENDIF ; ; check for input directory ; ; test if ${PROJECT_ID} defined CASE project_id_env OF '' : BEGIN msg = 'eee : ${PROJECT_ID} is not defined' ras = report(msg) return, result END ELSE : BEGIN msg = 'iii : ${PROJECT_ID} is ' + project_id_env ras = report(msg) END ENDCASE ; iodirin = isadirectory(project_id_env) ; ; existence and protection of ${PROJECT_ID} IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN msg = 'eee : the directory' + iodirin + ' is not accessible.' ras = report(msg) return, result ENDIF ; ; build mask filename filename_msk='mask_oaflux_30N30S.nc' ; ; check if this file exists msg='iii : looking for ' + filename_msk ras = report(msg) fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST) IF fullfilename_msk[0] EQ '' THEN BEGIN msg = 'eee : the file ' + fullfilename_msk + ' was not found.' ras = report(msg) return, result ENDIF ; ; build data filename IF eraitype EQ 1 THEN BEGIN erai_var = 'sstk' filename='20c3m_erai_sstk_TROP_1989_2009.nc' tutoday = 24.d tmporig = date2jul(19570101L,month=immo,day=iddo,year=iyyyyo) endif IF (eraitype eq 2) THEN BEGIN erai_var = 'sst' tmpb = date2jul(yyyymmddb,month=immb,day=iddb,year=iyyyyb) tmpe = date2jul(yyyymmdde,month=imme,day=idde,year=iyyyye) filename = 'erai_' + erai_var + '_' + string(iyyyyb,format='(I4.4)') + '_' + string(iyyyye,format='(I4.4)') + '.nc' tutoday = 1.d tmporig = date2jul(19500101L,month=immo,day=iddo,year=iyyyyo) ENDIF ; ; check if this file exists msg='iii : looking for ' + filename ras = report(msg) fullfilename = isafile(iodirin + filename, NEW=0, /MUST_EXIST) IF fullfilename[0] EQ '' THEN BEGIN msg = 'eee : the file ' + fullfilename + ' was not found.' ras = report(msg) return, result ENDIF ; ; test if ${PROJECT_OD} defined CASE project_od_env OF '' : BEGIN msg = 'eee : ${PROJECT_OD} is not defined' ras = report(msg) return, result END ELSE : BEGIN msg = 'iii : ${PROJECT_OD} is ' + project_od_env ras = report(msg) END ENDCASE ; ; check if output data will be possible iodirout = isadirectory(project_od_env) ; ; existence and protection IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN msg = 'eee : the directory' + iodirout + ' was not found.' ras = report(msg) return, result ENDIF ; ; build output filename filename_out = 'erai_sst_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc' fullfilename_out = iodirout + filename_out ; in order to avoid unexpected overwritten IF ((FILE_TEST(fullfilename_out) EQ 1) AND (project_overwrite EQ 0)) THEN BEGIN msg = 'eee : the file ' + fullfilename_out + ' already exists.' ras = report(msg) return, result ENDIF ; initncdf, fullfilename domdef latin=reform(gphit[0,*]) lonin=reform(glamt[*,0]) print, 'lat grid ',min(latin),max(latin),latin[1]-latin[0] print, 'lon grid ',min(lonin),max(lonin),lonin[1]-lonin[0] sstkin=read_ncdf(erai_var,yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr) ; timein=tutoday*(time-julday(immo,iddo,iyyyyo,0,0,0)) jptin=n_elements(timein) da=jul2date(time[0]) cda0=string(da,format='(i8.8)') da=jul2date(time[jpt-1]) cda1=string(da,format='(i8.8)') print, 'sst first date ', cda0 print, 'sst last date ' , cda1 ; tab=sstkin[*,*,0] mskin=glamt*0.+1. ind=where((tab eq 1.e9) or finite(tab,/nan)) mskin[ind]=0. ; initncdf, fullfilename_msk domdef latout=reform(gphit[0,*]) lonout=reform(glamt[*,0]) print, 'lat grid ',min(latout),max(latout),latout[1]-latout[0] print, 'lon grid ',min(lonout),max(lonout),lonout[1]-lonout[0] mskout=read_ncdf("msk", file=fullfilename_msk,/nostr) ; help, sstkin,lonin,latin,mskin,lonout,latout,mskout ; sstkout=fltarr(jpi,jpj,jptin) for jt=0,jptin-1 do begin ; ++print, 'Interpolation jt=',jt,' / ',jptin-1 tab=reform(sstkin[*,*,jt]) sstkout[*,*,jt]=call_interp2d(tab,lonin,latin,mskin $ , lonout,latout,method='bilinear' $ , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout) sstkout[*,*,jt]=sstkout[*,*,jt]*mskout+(1.-mskout)*1.e20 endfor ; initncdf, fullfilename_msk ; lat=latout lon=lonout ncfile='!' + fullfilename_out lon_attr={units:'degrees_east',long_name:'Longitude'} lat_attr={units:'degrees_north',long_name:'Latitude'} time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'} globattr={source:'Data are from ECMWF ERA-Interim reanalysis', timerange:cda0+' - '+cda1} sstk_attr={units:'degK',missing_value:1e20,long_name:'Sea Surface Temperature',short_name:'sst',axis:'TYX'} ; ncfields = 'sst[longitude,latitude,*time]=sstkout:sstk_attr; ' $ + 'longitude[]=lon:lon_attr; ' $ + 'latitude[]=lat:lat_attr; ' $ + 'time[]=timein:time_attr ' $ + ' @ globattr' ; @ncdf_quickwrite ; result = 0 return, result ; end