;---------------------------------------------------------------------- ; ESMF_regrid_template.ncl ; ; This is a template file for use with ESMF regridding. This is the ; template that uses the single "ESMF_regrid" function to do the ; regridding. There's another template, "ESMF_template.ncl", that ; does the regridding in several individual steps. This can be ; useful if you need to skip any of the steps. ; ; The ESMF_regrid function does the following: ; ; 1. Generates a description file (SCRIP or ESMF) for the source grid. ; ; 2. Generates a description file (SCRIP or ESMF) for the destination ; grid. ; ; 3. Generates the weights file, using the source and destination ; files. ; ; 4. Applies the weights to the data you want to regrid. ; ; 5. Attaches metadata to regridded variable, if appropriate. ; ;---------------------------------------------------------------------- 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 INTERP_METHOD = "patch" ;---Input file that contains lat/lon grid of source grid, and some data to regrid srcFileName = "./data/HUY3-SCEAN1D_21.nc" ;---Input file that contains lat/lon grid of destination grid, if applicable. dstFileName = "./data/CISM2_nplaea_4km_180312_x_y_4000.nc" ;---Open the source data file and get some data to regrid sfile = addfile(srcFileName,"r") x = sfile->ice(0,:,:) ; You may need to subscript this. ;---Open the destination data file dfile = addfile(dstFileName,"r") ;---Set up options for regridding Opt = True Opt@SrcGridLat = sfile->latitude ; Be sure to use appropriate names Opt@SrcGridLon = sfile->longitude ;here Opt@SrcRegional = True ; Necessary if source grid not global Opt@SrcTitle = "NCEP Grid" ; Optional ; Opt@SrcGridMask = where(.not.ismissing(x),1,0) ; Necessary if has ; missing values. ; Opt@DstGridMask = where((d_mask .eq. 1).or.(d_mask .eq. 4),1,0) ; ; If your destination grid is contained in a file, then use this code. ; Otherwise, if you just want to regrid to a generic grid, like a ; "1x1 degree grid, then skip to the next set of resources. ; dstlat = dfile->lat(0,:,:) ; Be sure to use appropriate names dstlon = dfile->lon(0,:,:) ; here. Opt@DstGridLon = dstlon Opt@DstGridLat = dstlat ; Opt@DstMask2D = where(.not.ismissing(dstlat).and.\ ; .not.ismissing(dstlon),1,0) ; Necessary if lat/lon ; has missing values. ; ; Use this if you just want to regrid to some generic grid, like a "1x ; "1x1 degree grid. ; ;; Opt@DstGridType = "1x" ; Opt@DstRegional = True ; Necessary if destination grid not global Opt@ForceOverwrite = True ; Optional, but recommended Opt@PrintTimings = True ; Optional Opt@InterpMethod = INTERP_METHOD ; "patch", "conserve" x_regrid = ESMF_regrid(x,Opt) rgrdFileName = "./results/HUY3-SCEAN1D_21_cism4km.nc" system("rm -f " + rgrdFileName) rgrd_nc = addfile(rgrdFileName,"c") ;---Create variable to hold global file attributes global = True copy_VarAtts(dfile, global) if (isatt(dfile,"title")) then global@TITLE = "REMAPPED: " + dfile@title end if global@remap = "NCL: ESMF_regrid_with_weights (NCL version '" + \ get_ncl_version() + "')" global@remap_method = INTERP_METHOD global@creation_date = systemfunc("date") fileattdef(rgrd_nc, global) ; copy global file attributes filedimdef(rgrd_nc,"TIME",-1,True) ; force an unlimited dimension ; ; Write variables to file. Coordinate arrays will be written ; automatically ; rgrd_nc->ice = x_regrid end