Ticket #53031: test_regrid_plot.ncl

File test_regrid_plot.ncl, 2.5 KB (added by basmac, 8 years ago)
Line 
1; ===============================================================;
2; ----- Generate perturbations based on GLDAS NOAH-MOSAIC EOFs for
3; ----- SMC from GEFS sfc analysis files - unperturbed SMC ----- ;
4; ===============================================================;
5load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
6load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl"
7
8begin
9
10  REGRID = True
11  PLOT   = True
12
13  if REGRID then
14    print("Regrid option is on.")
15  else
16    print("Regrid option is off.")
17  end if
18  if PLOT then
19    print("Plot option is on.")
20  else
21    print("Plot option is off.")
22  end if
23 
24; --- generate random data --- ;
25  print("defining data array")
26  data = random_normal(0,5,(/180,360/))
27  data!0 = "lat"
28  data!1 = "lon"
29  lat = fspan(-89.5,89.5,180)
30  lon = fspan(0,359,360)
31  lat!0 = "lat"
32  lat@units = "degrees_north"
33  lon!0 = "lon"
34  lon@units = "degrees_east"
35  lat&lat = lat
36  lon&lon = lon
37  data&lat = lat
38  data&lon = lon
39  printVarSummary(data)
40
41  if REGRID then
42    print("Regridding!")
43  ; --- new lat and lon arrays to regrid to --- ; 
44    print("defining new lat and lon arrays")
45    newlat = fspan(-89.75,89.75,360)
46    newlon = fspan(0,359.5,720)
47    nlat = dimsizes(newlat)
48    nlon = dimsizes(newlon)
49
50  ; --- regridding options and file names --- ;
51    srcGridName = "src_1deg.nc"
52    dstGridName = "dst_0.5deg.nc"
53    wgtFile_pfx = "1x1deg_to_0.5x0.5deg"
54    outFile_pfx = "regrid_out"
55   
56    print("defining options for regridding")
57    Opt                  = True
58    Opt@SrcFileName      = srcGridName    ; name of output source file
59    Opt@ForceOverwrite   = True   
60    Opt@SrcInputFileName = "Test_regrid"    ; optional, but good idea
61    Opt@SrcTitle         = "1deg Grid"   
62    Opt@DstTitle      = "0.5deg Grid"
63    Opt@DstGridLon    = newlon
64    Opt@DstGridLat    = newlat
65    Opt@DstFileName   = dstGridName
66    Opt@WgtFileName   = wgtFile_pfx + "neareststod.nc"
67    Opt@InterpMethod  = "neareststod"
68    print("Regridding using method = neareststod")
69    dataout           = ESMF_regrid(data,Opt)
70    printVarSummary(dataout)
71  end if
72
73  if PLOT then
74    print("Plotting!")
75    print("open workstation")
76    wks = gsn_open_wks("png","test_png")
77    res = True
78    res@cnFillOn = True
79    res@cnLinesOn = False
80    res@cnFillMode = "RasterFill"
81    res@cnLevelSelectionMode = "ExplicitLevels"
82    res@cnLevels = (/-2., -1., -0.5, 0.5, 1, 2/)
83    print("plotting data")
84    plot = gsn_csm_contour_map_ce(wks,data,res)
85  end if
86
87 
88end