;----------------------------------------------------------------- ; Neil P. Barton ; 01/28/13 16:01:53 ;----------------------------------------------------------------- ;----------------------------------------------------------------- ; interp MERRA Data onto SEAICE EASE Grid ;----------------------------------------------------------------- ;----------------------------------------------------------------- ; load modules load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl" ;----------------------------------------------------------------- begin srcFileName = "/p/lscratchc/barton30/DATA-NPB/CRE/MERRA.nc" ; Source file src_file = addfile(srcFileName,"r") dstFileName = "/p/lscratchc/barton30/DATA-NPB/CRE/SEAICE.nc" dst_file = addfile(dstFileName,"r") time = src_file->time lev = src_file->level latD = dst_file->latitude lonD = dst_file->longitude ntime = dimsizes(time) nlev = dimsizes(lev) nlat = dimsizes(latD) nlon = dimsizes(lonD) ;----------------------------------------------------------------- ;----------------------------------------------------------------- ; Save File cdf_filename = "/p/lscratchc/barton30/DATA-NPB/CRE/MERRA_ncl1.nc" system("/bin/rm -f " + cdf_filename) cdf_file = addfile(cdf_filename,"c") ; Create a new netCDF file. ; Globale Atrributes cdf_file@title = "Interpolated Data from ESMF" ; Add some global attributes to cdf_file@author = "Neil P. Barton" cdf_file@organization = "LLNL/PCMDI" cdf_file@email = "barton30@llnl.gov" cdf_file@date = systemfunc("date") ; the netCDF file. ;----------------------------------------------------------------- ;----------------------------------------------------------------- ; write dimensions for file dimNames = (/"time", "level", "latitude", "longitude"/) dimSizes = (/ ntime, nlev, nlat(0), nlon(1)/) dimUnlim = (/ False, False, False, False/) filedimdef(cdf_file,dimNames,dimSizes,dimUnlim) filevardef(cdf_file, "time", typeof(time) ,(/"time"/)) cdf_file->time = time filevardef(cdf_file, "level", typeof(lev) ,(/"level"/)) cdf_file->level = lev filevardef(cdf_file, "latitude", typeof(latD) ,(/"latitude","longitude"/)) cdf_file->latitude = latD filevardef(cdf_file, "longitude", typeof(lonD) ,(/"latitude","longitude"/)) cdf_file->longitude = lonD ;----------------------------------------------------------------- ;----------------------------------------------------------------- ; Grab Dimensions for interpolation latD1d = ndtooned(latD) lonD1d = ndtooned(lonD) index = ind(latD1d.gt.59.0) latlon_dims = dimsizes(latD) ;----------------------------------------------------------------- ;----------------------------------------------------------------- ; grab lon sizes lon = src_file->longitude nlonS = dimsizes(lon) lon2 = src_file->longitude2 nlonS2 = dimsizes(lon2) ; options for regridding Opt = True Opt@SrcFileName = "/p/lscratchc/barton30/DATA-NPB/CRE/MERRA_3D_SCRIP.nc" Opt@DstFileName = "/p/lscratchc/barton30/DATA-NPB/CRE/MERRA_3D_EASE_ESMF.nc" Opt@WgtFileName = "/p/lscratchc/barton30/DATA-NPB/CRE/MERRA_3D_weights_patch.nc" Opt@ForceOverwrite = True Opt@InterpMethod = "patch" Opt@Debug = True Opt@PrintTimings = True ; destination grid Opt@DstGridType = "unstructured" Opt@DstGridLat = latD1d(index) Opt@DstGridLon = lonD1d(index) ; index Opt@RemapIndexes = True ; This is necessary to remap Opt@Indexes = index ; regridded values back to Opt@IndexesDims = latlon_dims ; locations on destination grid Opt@CopyVarCoords = False ; we can't copy the coords because the weights on the file are only for the non-missing lat/lon values. ;----------------------------------------------------------------- ;----------------------------------------------------------------- ; loop the variables names = getfilevarnames(src_file) j = 0 do i = 0,dimsizes(names)-1 strQ = "Q" strT = "T" strRH = "RH" strCL = "CLDLIQ" strPS = "PS" ;if(names(i).eq.strQ .or. names(i).eq.strT .or. names(i).eq.strRH .or. names(i).eq.strCL .or. names(i).eq.strT) then if(names(i).eq.strQ .or. names(i).eq.strT) then print(" ") print(" ") print(names(i)) print(" ") print(" ") if(j.eq.0) then ; generate files only the first time Opt@SkipSrcGrid = False Opt@SkipDstGrid = False Opt@SkipWgtGen = False Opt@DstESMF = True else Opt@SkipSrcGrid = True Opt@SkipDstGrid = True Opt@SkipWgtGen = True Opt@DstESMF = True j = 1 end if datS = src_file->$names(i)$ datS@_FillValue = -9999.0 datD = ESMF_regrid(datS,Opt) dimS = dimsizes(datS) if(dimS(1).eq.nlev) then filevardef(cdf_file, names(i), typeof(datD) ,(/"time","level","latitude","longitude"/)) else filevardef(cdf_file, names(i), typeof(datD) ,(/"time","latitude","longitude"/)) end if ;----------------------------------------------------------------- ;----------------------------------------------------------------- ; Save Data cdf_file->$names(i)$ = datD delete(datS) delete(datD) end if end do end ;----------------------------------------------------------------- ;----------------------------------------------------------------- ;----------------------------------------------------------------- ;----------------------------------------------------------------- ;-----------------------------------------------------------------