;+ ; ; ; =================== ; interp_erai_lwr.pro ; =================== ; ; .. function:: interp_erai_lwr(yyyymmddb,yyyymmdde, eraitype) ; ; DESCRIPTION ; =========== ; ; Interpolation of str from ERA-I grid to OAFLUX grid ; ; If eraitype is set to 1, ; :file:`${PROJECT_ID}/20c3m_erai_str_TROP_1989_2009.nc` ; containing str from ERA-I ; has been produced by ; :ref:`compute_erai_daily_region_2d.sh`. ; ; If eraitype is set to 2, ; :file:`${PROJECT_ID}/erai_t2m_{yyyyb}_{yyyye}.nc` ; containing ; lwr from ERA-I ; has been produced by ; :ref:`concat_eraiy.sh`. ; ; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc` ; containing OAFLUX mask ; has been produced by ; :func:`oaflux_mask_30n30s`. ; ; Interpolated str ; is written in ; :file:`${PROJECT_OD}/erai_lwr_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc` ; if this file not already exists. ; ; This output file ; :file:`${PROJECT_OD}/erai_lwr_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc` ; must be processed after by ; :ref:`add_19890101.sh`. ; ; .. only:: man ; ; Figure is visible on PDF and HTML documents only. ; ; .. only:: html or latex ; ; .. graphviz:: ; ; digraph interp_erai_lwr { ; ; file_in_erai1 [shape=ellipse, ; fontname=Courier, ; label="${PROJECT_ID}/20c3m_erai_str_TROP_1989_2009.nc"]; ; file_in_erai2 [shape=ellipse, ; fontname=Courier, ; label="${PROJECT_ID}/erai_lwr_{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_lwr_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"]; ; ; interp_erai_lwr [shape=box, ; fontname=Courier, ; color=blue, ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_erai_lwr.pro", ; label="${PROJECT}/src/interp_erai_lwr.pro"]; ; ; {file_in_erai1 file_in_erai2 mask} -> {interp_erai_lwr} -> {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 ` ; ; :ref:`add_19890101.sh` ; ; EXAMPLES ; ======== ; ; With ERA-I type 1: ; ; .. code-block:: idl ; ; .compile file_interp ; eraitype = 1 ; yyyymmddb = 20000101L ; yyyymmdde = 20001231L ; result = interp_erai_lwr(yyyymmddb, yyyymmdde, eraitype) ; print, result ; ; With ERA-I type 2: ; ; .. code-block:: idl ; ; .compile file_interp ; eraitype = 2 ; yyyymmddb = 20000101L ; yyyymmdde = 20001231L ; result = interp_erai_lwr(yyyymmddb, yyyymmdde, eraitype) ; print, result ; ; TODO ; ==== ; ; lwr first date 19991231 vs yyyymmddb = 20000101L ; ; make it work : pb on loholt1 idl8: ; ; reach end but bad values (all NaN) ; ; make it work : pb on loholt1 idl6: ; ; .. parsed-literal:: ; ; lwr[longitude,latitude,time]=lwrout:lwr_attr; longitude[]=xlon:lon_attr; latitude[]=ylat:lat_attr; tt[*time]=tt:time_attr @ globattr ; % NCDF_VARPUT: Operation Failed, bad file (4) or variable [0] id ? ; (NC_ERROR=-31) ; % Stop encountered: INTERP_ERAI_LWR_1989_2009 1 ; /home/pinsard/tropflux_ws/src/interp_erai_lwr_1989_2009.pro ; ; check OUTMASK_IND and SET_OUTMSKVAL added to call_interp2d call ; ; use real output of :ref:`compute_erai_daily_region_2d.sh`. ; ; remove hard coded time ; ; 19890101 is not provided in ERA-Interim file str : a possible workaround is ; to copy 19890102 dataset to 19890101 using nco after this processing. ; see :ref:`compute_erai_daily_region_2d.sh` ; ; check if there is the same issue with 19790101 vs 19790102. ; ; coding rules ; ; 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_lwr.pro $ ; ; - fplod 20120704T113504Z cratos (Linux) ; ; * add eraitype parameter ; * deal with time units (days vs hours) and time origin ; ; - fplod 20120320 ; ; * no more timegen ; ; - fplod 20120319 ; ; * taking project_overwrite into account ; * try to add compile_opt seems to be incompatible with ncdf_quickwrite ; * pro -> function ; ; - fplod 20110830T145010Z cratos (Linux) ; ; * replace xlon by lon and xlat by lat; suppress extra initncdf call ; ; - fplod 20110830T135030Z cratos (Linux) ; ; * replace tt by time ; ; - pinsard 2011-08-23T09:09:16Z loholt1.ipsl.polytechnique.fr (Linux) ; ; * retry on loholt1 with idl8 and idl6 ; ; - fplod 20110819T084310Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * replace next step lwr_correction_ncdf.pro by :ref:`add_19890101.sh` ; * fix output file name to erai_lwr_19890102_20091231_oafluxgrid.nc ; ; - pinsard 2011-08-08T16:03:48Z loholt1.ipsl.polytechnique.fr (Linux) ; ; * remove return statement ; ; - fplod 20110808T094156Z cratos (Linux) ; ; * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call ; * fix typo ; .. note:: ; ; IDL do not warn when asking size of an undefined array: ; ; .. code-block:: idl ; ; must_crash=size(ginette) ; ; - pinsard 2011-07-05T07:33:36Z 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 20101215T094137Z 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_lwr $ , 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 ; st=19890101 en=20090801 ; ; build data filename IF eraitype EQ 1 THEN BEGIN erai_var = 'str' filename='20c3m_erai_str_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 = 'lwr' 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_lwr_' + 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 lwrin=read_ncdf(erai_var,yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr) lwrin=-1*lwrin 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, 'lwr first date ', cda0 print, 'lwr last date ' , cda1 ; 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] ; tab=lwrin[*,*,0] mskin=glamt*0.+1. ; 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) ; lwrout=fltarr(jpi,jpj,jptin) ; for jt=0,jptin-1 do begin ; ++print, 'Interpolation jt=',jt,' / ',jptin-1 ; tab=reform(lwrin[*,*,jt]) lwrout[*,*,jt]=call_interp2d(tab,lonin,latin,mskin $ , lonout,latout,method='bilinear' $ , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout) lwrout[*,*,jt]=lwrout[*,*,jt]*mskout+(1.-mskout)*1.e20 ; endfor ; 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:'Tropical ocean fluxes obtained from ERA Interim',timerange:cda0+' - '+cda1} lwr_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net longwave radiation ',short_name:'lwr',axis:'TYX'} ; ncfields = 'lwr[longitude,latitude,*time]=lwrout:lwr_attr; ' $ + 'longitude[]=lon:lon_attr; ' $ + 'latitude[]=lat:lat_attr; ' $ + 'time[]=timein:time_attr ' $ + ' @ globattr' ; @ncdf_quickwrite ; result = 0 return, result ; end