load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl" begin ;---Read data to be regridded. fname = "uv300.nc" f = addfile(fname,"r") u = f->U(0,:,:) ; 64 x 128 printVarSummary(u) ;---Define the destination grid nlat = 37 nlon = 73 dst_lat = fspan(-90,90,nlat) dst_lon = fspan(-180,180,nlon) printVarSummary(dst_lat) printVarSummary(dst_lon) ;---Do the regridding Opt = True Opt@DstGridLat = dst_lat Opt@DstGridLon = dst_lon Opt@ForceOverwrite = True u_regrid = ESMF_regrid(u,Opt) printVarSummary(u_regrid) dims_orig = dimsizes(u) dims_regrid = dimsizes(u_regrid) ;---Create plots of original data and regridded data. wks = gsn_open_wks("png","u_regridded") res = True ; Plot mods desired. res@gsnMaximize = True ; Maximize plot res@gsnDraw = False ; We will panel later. res@gsnFrame = False res@cnFillOn = True ; color plot desired res@cnLinesOn = False ; turn off contour lines res@cnLineLabelsOn = False ; turn off contour lines ;---Be sure to use same levels across all times and depths mnmxint = nice_mnmxintvl( min(u_regrid), max(u_regrid), 18, False) res@cnLevelSelectionMode = "ManualLevels" res@cnMinLevelValF = mnmxint(0) res@cnMaxLevelValF = mnmxint(1) res@cnLevelSpacingF = mnmxint(2) res@lbLabelBarOn = False ; Labelbar will be in panel ;---Create plot of original variable res@tiMainString = "u: original data (" + \ str_join(tostring(dims_orig)," x ") + ")" plot_orig = gsn_csm_contour_map(wks,u,res) ;---Create plot of regridded variable res@gsnAddCyclic = False res@tiMainString = "u: regridded to 5x5 grid (" +\ str_join(tostring(dims_regrid)," x ") + ")" plot_regrid = gsn_csm_contour_map(wks,u_regrid,res) ;---If desired, add lines showing the lat/lon grid of the original data and the regridded data. ADD_GRID = False if(ADD_GRID) then lnres = True lnres@gsLineColor = "gray50" lnres@gsLineThicknessF = 2.0 lnres@gsnCoordsAsLines = True ; draw grid as lines, not markers lnres@gsnCoordsAttach = True gsn_coordinates(wks,plot_orig,u,lnres) gsn_coordinates(wks,plot_regrid,u_regrid,lnres) end if ;---Panel both plots on same page. pres = True pres@gsnMaximize = True pres@gsnPanelLabelBar = True gsn_panel(wks,(/plot_orig,plot_regrid/),(/2,1/),pres) end