;+ ; ; =================== ; interp_erai_t2m.pro ; =================== ; ; .. function:: interp_erai_t2m(yyyymmddb,yyyymmdde) ; ; DESCRIPTION ; =========== ; ; Interpolation of t2 from ERA-I grid to OAFLUX grid ; ; :file:`${PROJECT_ID}/20c3m_erai_t2_TROP_1989_2009.nc` ; containing ; t2 from ERA-I ; has been produced by ; :ref:`compute_erai_daily_region_2d.sh`. ; ; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc` ; containing OAFLUX grid ; has been produced by ; :func:`oaflux_mask_30n30s`. ; ; Interpolated t2 ; is written in ; :file:`${PROJECT_OD}/erai_t2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc` ; if this file not already exists. ; ; This output file ; :file:`${PROJECT_OD}/erai_t2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc` ; must be processed after by ; :ref:`t2m_correction_ncdf.pro`. ; ; .. only:: man ; ; Figure is visible on PDF and HTML documents only. ; ; .. only:: html or latex ; ; .. graphviz:: ; ; digraph interp_erai_t2m { ; ; file_in [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/20c3m_erai_t2_TROP_1989_2009.nc"]; ; mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"]; ; file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_t2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"]; ; ; interp_erai_t2m [shape=box, ; fontname=Courier, ; color=blue, ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_erai_t2m.pro", ; label="${PROJECT}/src/interp_erai_t2m.pro"]; ; ; {file_in mask} -> {interp_erai_t2m} -> {file_out} ; ; } ; ; SEE ALSO ; ======== ; ; :ref:`interpolate_data` ; ; Used by :ref:`tropflux.sh` ; ; :ref:`project_profile.sh` ; ; :ref:`compute_erai_daily_region_2d.sh` ; ; :func:`oaflux_mask_30n30s` ; ; :func:`report ` ; :func:`isadirectory ` ; :func:`isafile ` ; :func:`initncdf ` ; :func:`read_ncdf ` ; :func:`ncdf_lec ` ; :func:`domdef ` ; :func:`call_interp2d ` ; :func:`ncdf_quickwrite ` ; :func:`ncdf_getatt ` ; ; :ref:`t2m_correction_ncdf.pro` ; ; EXAMPLES ; ======== ; ; :: ; ; IDL> .compile file_interp ; IDL> yyyymmddb = 19890101 ; IDL> yyyymmdde = 20091231 ; IDL> result = interp_erai_t2m(yyyymmddb, yyymmdde) ; IDL> print, result ; ; TODO ; ==== ; ; 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 ; ; add an example with only one month (ie 200001) ; ; make it work : pb on loholt1 idl8 ; ; reach end but bad time and t2m values :: ; ; $ ncks -v t2m -d time,0,1 -d latitude,0,1 -d longitude,0,1 /homedata/pinsard/tropflux_d/erai_t2m_19890101_20091231_oafluxgrid.nc ; latitude[0]=-29.5 degrees_north ; latitude[1]=-28.5 degrees_north ; ; longitude[0]=30.5 degrees_east ; longitude[1]=31.5 degrees_east ; ; time[0]=9.96920996839e+36 latitude[0]=-29.5 longitude[0]=30.5 t2m[0]=9.96921e+36 degK ; time[0]=9.96920996839e+36 latitude[0]=-29.5 longitude[1]=31.5 t2m[1]=9.96921e+36 degK ; time[0]=9.96920996839e+36 latitude[1]=-28.5 longitude[0]=30.5 t2m[350]=9.96921e+36 degK ; time[0]=9.96920996839e+36 latitude[1]=-28.5 longitude[1]=31.5 t2m[351]=9.96921e+36 degK ; time[1]=9.96920996839e+36 latitude[0]=-29.5 longitude[0]=30.5 t2m[21000]=9.96921e+36 degK ; time[1]=9.96920996839e+36 latitude[0]=-29.5 longitude[1]=31.5 t2m[21001]=9.96921e+36 degK ; time[1]=9.96920996839e+36 latitude[1]=-28.5 longitude[0]=30.5 t2m[21350]=9.96921e+36 degK ; time[1]=9.96920996839e+36 latitude[1]=-28.5 longitude[1]=31.5 t2m[21351]=9.96921e+36 degK ; ; time[0]=9.96920996839e+36 hours since 1957-01-01 00:00:0.0 ; time[1]=9.96920996839e+36 hours since 1957-01-01 00:00:0.0 ; ; loholt1 idl6 : end without error but looking with ncview all brown ! ; ; strange view (lat and lon shift with ncview) : check grid init ; ; remove useless netcdf_read or choose between read_ncdf and ncdf_lec ; ; check time values ; ; why use :func:`call_interp2d ` : this is an hidden function of SAXO ; see :func:`file_interp ` ; ; use as input a file produced by compute_erai_daily_region_2d.sh or ; get_erai.py + grib to netcdf conversion ; ; coding rules ; ; hard coded time in module name and in output filename ; ; why two "initncdf, fullfilename_msk" ; ; hard coded attributes for t2m (missing value, short name, axis) and time (origin) : use ncdf_getatt ; ; CF conventions ; ; check OUTMASK_IND and SET_OUTMSKVAL added to call_interp2d call ; ; 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_t2m.pro $ ; ; - fplod 20120319 ; ; * taking project_overwite into account ; ; - fplod 20120306 ; ; * try to add compile_opt seems to be incompatible with ncdf_quickwrite ; * pro -> function ; ; - pinsard 2011-08-23T09:09:16Z loholt1.ipsl.polytechnique.fr (Linux) ; ; * retry on loholt1 with idl8 and idl6 ; ; - pinsard 2011-08-08T16:11:48Z loholt1.ipsl.polytechnique.fr (Linux) ; ; * remove ncdf_quickwrite exercices ; ; - fplod 20110808T094156Z cratos (Linux) ; ; * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call ; ; - fplod 20110103T153734Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * computed first and last dates ; * start using ncdf_getatt instead of hard coded attributes ; ; - fplod 20101223T130406Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * replace /Volumes/PRAVEEN/TropFlux/input_uncor/ by ${TROPFLUX_OD} ; * complete documentation ; * get time dimension in data file ; * replace read_ncdf by ncdf_lec ; ; usage of timestep keyword in read_ncdf was not efficient because of memory problem : ; can not read the whole time range (ok with 7580, not ok with 7591 while need is 7670 ; :: ; ; % Unable to allocate memory: to make array. ; Cannot allocate memory ; ; When timestep keyword is not used we can see these messages:: ; ; /usr/work/incas/fplod/tropflux_d/20c3m_erai_t2_TROP_1989_2009.nc as no time axis variable ; given by Praveen ; ; Value of Julian date is out of allowed range ; ; % Array used to subscript array contains out of range subscript: DATAIN ; ; - fplod 20101222T163216Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * replace /Volumes/PRAVEEN/ERAI_global by ${TROPFLUX_ID} ; ; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * remove hard coded directory for mask_oaflux_30N30S.nc ; ; - fplod 20101215T112140Z 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_t2m $ , yyyymmddb $ , yyyymmdde ; ;++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_t2m(yyyymmddb, yyyymmdde) nparam = N_PARAMS() IF (nparam NE 2) 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 t2 filename filename_t2='20c3m_erai_t2_TROP_1989_2009.nc' ; ; check if this file exists msg='iii : looking for ' + filename_t2 ras = report(msg) fullfilename_t2 = isafile(iodirin + filename_t2, NEW=0, /MUST_EXIST) IF fullfilename_t2[0] EQ '' THEN BEGIN msg = 'eee : the file ' + fullfilename_t2 + ' 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_t2m_' + 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 ; ; define grid parameters with t2 file initncdf, fullfilename_t2 domdef latin=reform(gphit[0,*]) lonin=reform(glamt[*,0]) print, 'lat grid from data',min(latin),max(latin),latin[1]-latin[0] print, 'lon grid from data',min(lonin),max(lonin),lonin[1]-lonin[0] ; ;; get time in t2 file ;timein=ncdf_lec(fullfilename_t2,var='time') ;jptin=n_elements(timein) ;print, 'time steps from data ', jptin ;print, 'The first 10 time values (variable timein) = ', timein[0:9] ; ; find first and last dates yyyymmdd ;; they will be written in global attributes of output file ;da=jul2date(julday(01, 01, 1957,timein[0])) ;cda0=string(da,format='(i8.8)') ;da=jul2date(julday(01, 01, 1957,timein[jptin-1])) ;cda1=string(da,format='(i8.8)') ;print, 'first date ', cda0 ;print, 'last date ' , cda1 ; ; read t2 data ;++ pb memory t2min=read_ncdf("t2",0,jptin-1,/timestep,file=fullfilename_t2,/nostr) ; the following line is here just to prepare replacement of read_ncdf by ncdf_lec ;t2min_read_ncdf=read_ncdf("t2",0,10,/timestep,file=fullfilename_t2,/nostr) ;help, t2min_read_ncdf ;++print, 'The first 10 time values (variable time) = ', time[0:9] ;++print, 'time steps after read_ncdf (variable jpt) ', jpt ;t2min=ncdf_lec(fullfilename_t2,var='t2') t2min=read_ncdf('t2',yyyymmddb-.5d,yyyymmdde,file=fullfilename_t2,/nost) ;; time:units = "hours since 1957-01-01 00:00:0.0" ; timein=24.d*(time-julday(1,1,1957,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, 'first date ', cda0 print, 'last date ' , cda1 help, t2min ; mskin=glamt*0.+1. ; ; define grid parameters with mask file initncdf, fullfilename_msk domdef latout=reform(gphit[0,*]) lonout=reform(glamt[*,0]) print, 'lat grid from mask ',min(latout),max(latout),latout[1]-latout[0] print, 'lon grid from mask ',min(lonout),max(lonout),lonout[1]-lonout[0] mskout=read_ncdf("msk", file=fullfilename_msk,/nostr) ; help, t2min,lonin,latin,mskin,lonout,latout,mskout ; ; interpolation and mask t2mout=fltarr(jpi,jpj,jptin) for jt=0,jptin-1 do begin tab=reform(t2min[*,*,jt]) t2mout[*,*,jt]=call_interp2d(tab,lonin,latin,mskin $ , lonout,latout,method='bilinear' $ , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout) t2mout[*,*,jt]=t2mout[*,*,jt]*mskout+(1.-mskout)*1.e20 endfor ; initncdf, fullfilename_msk ; lat=latout lon=lonout ncfile='!' + fullfilename_out ncdf_getatt, fullfilename_msk, 'longitude', units=units ncdf_getatt, fullfilename_msk, 'longitude', long_name=long_name lon_attr={units:units, long_name:long_name} ncdf_getatt, fullfilename_msk, 'latitude', units=units ncdf_getatt, fullfilename_msk, 'latitude', long_name=long_name lat_attr={units:units, long_name:long_name} ncdf_getatt, fullfilename_t2, 'time', units=units ncdf_getatt, fullfilename_t2, 'time', long_name=long_name time_attr={units:units, long_name:long_name, time_origin:' 1957-JAN-01 00:00:00'} globattr={source:'Data are from ECMWF ERA-Interim reanalysis', timerange:cda0+' - '+cda1} ncdf_getatt, fullfilename_t2, 't2', units=units ncdf_getatt, fullfilename_t2, 't2', long_name=long_name t2m_attr={units:units, long_name:long_name, missing_value:1e20, short_name:'t2m',axis:'TYX'} ; help, t2mout help, timein ncfields = 't2m[longitude,latitude,*time]=t2mout:t2m_attr; ' $ + 'longitude[]=lon:lon_attr; ' $ + 'latitude[]=lat:lat_attr; ' $ + 'time[]=timein:time_attr ' $ + ' @globattr' @ncdf_quickwrite ; result = 0 return, result ; end