Panel plot error (wks not defined)

From: <burakows_at_nyahnyahspammersnyahnyah>
Date: Wed Feb 05 2014 - 10:09:33 MST

I am trying to plot six contour plots (2 rows, 3 cols) in a panel plot in
a loop for a six-month WRF simulation. I keep getting an error that says
that (1) wks is undefined and (2) that an error occurred near line 148.

With regard to (1), wks is defined in line 88.

For (2) On line 148, I'm trying to create a panel plot from 'plot_diff',
which is initialized before the loop on line 34 and defined inside the
loop on line 130.

I am trying to follow the example here:
https://www.ncl.ucar.edu/Training/Workshops/Scripts/panel1f.ncl

My script is below. Thanks. Liz.

fatal:Variable (wks) is undefined
fatal:["Execute.c":8567]:Execute: Error occurred at or near line 148 in
file rdPrmWrf.ncl

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"

;======================================================================
; The main code
;======================================================================

begin

;---Specify interpolation to be used
    method = "bilinear"

    wgtFileDir = "/glade/p/work/burakows/plot/NCL/ESMF_regridding/"
    wgtFileName = "PRISM_4kmM2_to_WRF."+method+"_wgt.nc"
    wgtFilePath = wgtFileDir+wgtFileName
    print("wgtFilePath="+wgtFilePath)

;---PRISM files [input]
    varp = "tmax" ; PRISM name
    dirp = "/glade/p/work/burakows/prism/data/"
    filp = systemfunc("cd "+dirp+" ; ls PRISM_"+varp+"*bil.nc")
    nfilp = dimsizes(filp)
    print(filp(0:nfilp-1)) ; 1st 5 file

;---WRF directory
    varw = "T2" ; WRF name
    dirw =
"/glade/p/work/burakows/plot/albedo_CLMV351current_200811-200904/"

    varm = "T2max" ; WRF monthly
name
    prtFlg = True

    plot_diff = new(6,graphic) ; from p.80 of
NCL manual, right before looping

    do nfp=0,nfilp-1
       yyyymm = toint( str_get_field(filp(nfp),5,"_.") ) ; parse
PRISM name for time

       yyyy = yyyymm/100 ; current
year as integer
       mm = yyyymm-(yyyy*100) ; current month

       fp = addfile(dirp+filp(nfp), "r")
       XP = fp->z ; original
PRISM variable (all 'z')
       xp = ESMF_regrid_with_weights(XP,wgtFilePath,False); create new
variable on WRF grid

    filw = "avg_"+varm+"_"+yyyy+"-"+sprinti("%0.2i",mm)+".nc"

     if (isfilepresent(dirw+filw)) then
       fw = addfile(dirw+filw, "r")
       xw = fw->$varm$ ; WRF variable
       ;xw@lat2d = fw->XLAT(0,:,:)
       ;xw@lon2d = fw->XLONG(0,:,:)

;----------------------------------------------------------------------
; Subtract PRISM from WRF section
;----------------------------------------------------------------------

   fwo = addfile(dirw+"wrfout_d03_2008-11-01_00:00:00.nc","r")
        xwo = fwo->T2

       xdiff(i) = xw(0,:,:)-xp ; Avg
monthly WRF minus Prism for month i
       xdiff@long_name = "difference: "+yyyymm ; Assign
long name to difference
       xdiff@units = "Degrees C" ; Assign
units to difference
       printVarSummary(xdiff(i))

       xdiff@lat2d = fwo->XLAT(0,:,:) ; Assign lat
to xdiff
       xdiff@lon2d = fwo->XLONG(0,:,:) ; Assign lon
to xdiff

print("xdiff: min="+min(xdiff)+" max="+max(xdiff))

    minlat = min((/min(xdiff@lat2d),min(fp&y)/))
    maxlat = max((/max(xdiff@lat2d),max(fp&y)/))

    minlon = min((/min(xdiff@lon2d),min(fp&x)/))
    maxlon = min((/max(xdiff@lon2d),max(fp&x)/))

    bndadd = 0.10 ; spacing around the plot edges
;----------------------------------------------------------------------
; Plotting section
;----------------------------------------------------------------------

        pltType = "ps" ; plot type
        pltDir = "./" ; plot directory
        pltName = "Diff_WRF_PRISM"+yyyy ; plot name (ps file)
        pltPath = pltDir+pltName ; plot path

       wks = gsn_open_wks(pltType,pltPath) ; create
workstation for ps file
        gsn_define_colormap(wks,"temp_diff_18lev") ; define color table

        res = True

        res@gsnDraw = False
        res@gsnFrame = False

        res@cnFillOn = True ; color plot desired
        res@cnLinesOn = False ; turn off contour lines
        res@cnLineLabelsOn = False ; turn off contour
labels
        res@cnFillMode = "RasterFill" ; turn raster on

        res@lbLabelBarOn = False ; Will turn on in
panel later
        res@lbOrientation = "Horizontal" ; Horizontal label bar

        res@mpFillOn = False
        res@mpOutlineOn = True
        res@mpOutlineBoundarySets = "AllBoundaries"
        res@mpProjection = "CylindricalEquidistant"

        res@mpLimitMode = "LatLon" ; required
        res@mpMinLatF = minlat-bndadd
        res@mpMaxLatF = maxlat+bndadd
        res@mpMinLonF = minlon-bndadd
        res@mpMaxLonF = maxlon+bndadd
        res@mpCenterLonF = (minlon + maxlon)*0.5
        res@mpCenterLatF = (minlat + maxlat)*0.5

        res@gsnMajorLatSpacing = 2
        ;res@gsnMajorLonSpacing = 2
        res@gsnMinorLonSpacing = 2

        res@cnLinesOn = False
        res@cnLineLabelsOn = False
        res@cnFillOn = True
        res@cnFillMode = "RasterFill"

        res@gsnAddCyclic = False ; regional grid (changes
central meridian)

        ;res@TiMainString = "WRF minus PRISM" + yyyymm

        plot_diff(i) = gsn_csm_contour_map(wks,xdiff(i),res)

        if (prtFlg) then ; first
time only
           printVarSummary(XP)
           printVarSummary(xp)
           printVarSummary(xw)
           prtFlg = False
        end if ; nfp
    end if ; isfilepresent

 ;Create panel of plots with 2 rows and 3 columns from plot_diff

        pres = True
        pres@gsnMaximize = True
        pres@gsnPanelLabelBar = True
        pres@gsnCenterString = "WRF minus PRISM" + yyyymm
        pres@txString = "Monthly averaged WRF T2 minus PRISM"

        gsn_panel(wks,plot_diff,(/2,3/),pres)

  end do
end

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Feb 5 10:09:41 2014

This archive was generated by hypermail 2.1.8 : Fri Feb 07 2014 - 16:39:11 MST