Appendix B: Scripts and resource files used in "Hints and tips for using NCL" chapter

main appendix | appendix A | appendix B | appendix C | appendix D
The scripts and functions listed below are some of ones used in the "Hints and tips for using NCL" chapter and in appendix A. They are listed alphabetically.

2dgrid.ncl:

begin
  NX = 21
  NY = 21
;
; Define the input data arrays.
;
  x = (/0.00, 1.00, 0.00, 1.00, 0.40, 0.75/)
  y = (/0.00, 0.00, 1.00, 1.00, 0.20, 0.65/)
  z = (/0.00, 0.00, 0.00, 0.00, 1.25, 0.80/)
;
; Define the output grid.
;
  xc = 1./(NX-1.) 
  xo = ispan(0,NX-1,1) * xc

  yc = 1./(NY-1.) 
  yo = ispan(0,NY-1,1) * yc

;
; Do the gridding using natgrids. "natout" will be a 2-dimensional array
; dimensioned 21 x 21.
;
  natout = natgrids(x, y, z, xo, yo)
  print(natout)

;
; Do the gridding using dsgrid2s. "dsout" will be a 2-dimensional array
; dimensioned 21 x 21.
;
  dsout = dsgrid2s(x, y, z, xo, yo)
  print(dsout)
end
3dgrid.ncl:
begin
  NX = 21
  NY = 21
  NZ = 21
  x = (/0.00, 1.00, 0.00, 1.00, 0.40, 0.75/)
  y = (/0.00, 0.00, 1.00, 1.00, 0.20, 0.65/)
  z = (/0.00, 0.00, 0.00, 0.00, 1.25, 0.80/)
  u = x*x + y*y + z*z

  xo = new((/NX/),float)
  yo = new((/NY/),float)
  zo = new((/NZ/),float)

;
; Create the output grid.
;
  xmin = -2.0
  ymin = -2.0
  zmin = -2.0
  xmax =  2.0
  ymax =  2.0
  zmax =  2.0

  ii = fspan(0,20.,21)
  xo = xmin + (ii/(NX-1)) * (xmax-xmin)
  yo = ymin + (ii/(NY-1)) * (ymax-ymin)
  zo = zmin + (ii/(NZ-1)) * (zmax-zmin)

;
; Interpolate.  "output" will be a 3-dimensional grid dimensioned 21x21x21.
;
  output = dsgrid3s(x, y, z, u, xo, yo, zo)
  print(output)
end
color.ncl:
;
; This example shows how to use hsv2rgb to generate a color map.  You
; change the values for ncolors, beg_hue, end_hue, beg_sat, end_sat, 
; beg_val, and end_val and it will generate a labelbar showing the color map.
;

load "hsv2rgb.ncl"

begin
   ncolors = 16      ; Number of colors

   beg_hue = 225.    ; begin HUE value
   end_hue = 360.    ; end HUE value
   beg_sat = 0.67    ; begin SAT value
   end_sat = 0.67    ; end SAT value
   beg_val = 1.0     ; begin VAL value
   end_val = 1.0     ; end VAL value

   hue = fspan(beg_hue,end_hue,ncolors)     ; Set hue range.
   sat = fspan(beg_sat,end_sat,ncolors)     ; Set saturation range.
   val = fspan(beg_val,end_val,ncolors)     ; Set value range.

   cmap  = new((/ncolors+2,3/),float)   ; Define (ncolors+2) x 3 float
                                        ; array to hold the color map.

   cmap(0,:)    = (/1.,1.,1./)   ; Set the background to white.
   cmap(1,:)    = (/0.,0.,0./)   ; Set the foreground to black.

   cmap(2:ncolors+1,:) = hsv2rgb(hue,sat,val) ; Generate smooth range of
                                              ; RGB values.

   wks = create "wks" xWorkstationClass defaultapp
     "wkColorMap" : cmap
   end create

   lb = create "labelbar" labelBarClass wks
     "vpXF"              : 0.10
     "vpYF"              : 0.98
     "vpWidthF"          : 0.97
     "vpHeightF"         : 0.97
     "lbFillColors"      : ispan(0,ncolors+1,1)
     "lbLabelStrings"    : ":F26:Color " + ispan(0,ncolors+1,1)
     "lbMonoFillPattern" : True
     "lbBoxCount"        : ncolors+2
     "lbPerimOn"         : False
     "lbTitleFontHeightF": 0.02
     "lbAutoManage"      : False
     "lbTitleString"     : ":F22:ncolors = " + ncolors + \
                           " :C:hue (" + beg_hue + "," + end_hue + \
                           "):C:sat (" + beg_sat + "," + end_sat + \
                           "):C:val (" + beg_val + "," + end_val + ")"
   end create

   draw(lb)
   frame(wks)
end
fillcon.ncl:
begin

;
; Create some data for the contour plot.
;
  N=25
 
  T = new((/N,N/),float)
 
  jspn = ispan(-N/2,N/2,1)^2
  ispn = ispan(-N/2,N/2,1)^2
  do i = 0, dimsizes(ispn)-1
      T(i,:) = ispn(i) + jspn
  end do
  T = 100.0 - sqrt(8^2 * T)

;
; Create an X workstation.
;
  wid = create "wks" xWorkstationClass defaultapp end create

;
; Create a data object.
;
  dataid = create "data" scalarFieldClass defaultapp
    "sfDataArray" : T
  end create

;
; Create a ContourPlot object.
;
  cnid = create "ContourPlot" contourPlotClass wid
    "cnScalarFieldData" : dataid
    "cnFillOn"          : True   ; Turn on contour level fill.
    "cnMonoFillPattern" : False  ; Indicate you want multiple fill patterns.
;
; Set cnFillPatterns and cnFillColors to various indexes representing
; fill patterns and colors.  A fill pattern index of "0" is solid fill.
; If you don't want any fill for a particular contour level, set it
; to "-1," which means "transparent."
;
    "cnFillPatterns"    : (/0, 2, 3, 0, 6, 8,10,-1, 9, 0,11,12,17,16/)
    "cnFillColors"      : (/1,10,14, 8, 4, 2, 9, 1,12, 3, 1,13, 5, 7/)
  end create

  draw(cnid)    ; Draw contour plot.
  frame(wid)    ; Advance frame.
end
font.ncl:
begin
;
; An application object must be created so that we can have a resource 
; file.  The resource file should be the name name given to the 
; application object ("font" in this case") with a ".res" appended.
;
  appid = create "font" appClass defaultapp 
    "appDefaultParent" : True
  end create

;
; Create an X Workstation.
;
  wks = create "wks" xWorkstationClass defaultapp end create

;
; Create a data object.
;
  dataid = create "data" coordArraysClass appid
    "caYArray" : (/1,3,-1,-2,0,2,3/)
  end create

;
; Create an XY plot.
;
  xy = create "xyplot" xyPlotClass wks
    "xyCoordData"  : dataid
    "tiMainString" : "This is an XY plot"
    "tiXAxisString" : "X values"
    "tiYAxisString" : "Y values"
  end create

  draw(xy)     ; Draw the plot.
  frame(wks)   ; Advance the frame.
end
gsn_labelbar_ndc.ncl:
load "gsn_code.ncl"

begin
  wks = gsn_open_wks("x11","example")   ; Open a workstation.

  labels = (/"1 meter","2 meters","3 meters","4 meters","5 meters"/)

  lbres = True                    ; Indicate you want to set some resources.
  lbres@lbPerimOn = False         ; Turn off labelbar perimeter.
  lbres@lbLabelFont = "helvetica" ; Change font to helvetica.

  gsn_labelbar_ndc(wks,5,labels,0.2,0.8,lbres)   ; Draw labelbar.
  frame(wks)                                     ; Advance frame.
end
gsn_map.ncl:
load "gsn_code.ncl"

begin
  wks = gsn_open_wks("x11","example")   ; Open a workstation.

  mpres = True      ; Indicate you want to set some resources.

  mpres@mpFillOn       = True              ; Turn on map fill.
  mpres@mpGridMaskMode = "MaskLand"        ; Mask grid lines over land.
  mpres@mpFillColors   =  (/0,14,28,14/)   ; Fill land gray, ocean/lakes blue.

  map = gsn_map(wks,"Orthographic",mpres)  ; Draw a filled map.
end
gsn_panel.ncl:
load "gsn_code.ncl"

begin
  ncfile =  addfile("$NCARG_ROOT/lib/ncarg/data/cdf/meccatemp.cdf","r")
     
  wks = gsn_open_wks("x11","panel")   ; Open a workstation.

  cn_plots = new(6,graphic)  ; Create variable to hold plots.

  cnres          = True               ; Set some resources.
  cnres@gsnFrame = False              ; Turn off call to frame and draw
  cnres@gsnDraw  = False              ; since gsn_panel will do this.

  cnres@sfXCStartV = ncfile->lon(0)
  cnres@sfXCEndV   = ncfile->lon(dimsizes(ncfile->lon)-1)
  cnres@sfYCStartV = ncfile->lat(0)
  cnres@sfYCEndV   = ncfile->lat(dimsizes(ncfile->lat)-1)

  do i=1,6
    cnres@tiMainString = ":F26:January Global Surface Temperature - Day " + i
    cn_plots(i-1) = gsn_contour(wks,ncfile->t(i-1,:,:),cnres)
  end do

  gsn_panel(wks,cn_plots,(/2,3/),False)  ; 2 rows, 3 columns of plots.
end
gsn_polygon.ncl:
load "gsn_code.ncl"
begin
  wks = gsn_open_wks("x11","example")    ; Open a workstation.
 
  x = (/1.,2.,3.,4.,5.,6.,7.,8.,9.,10./)  ; Define X and Y arrays
  y = (/1.,2.,3.,4.,5.,6.,7.,8.,9.,10./)  ; for XY plot.

  xyres = True                  ; Indicate you want to set some resources.
  xyres@gsnFrame = False        ; Don't advance frame after plot is drawn.
  xy = gsn_xy(wks,x,y,xyres)    ; Draw XY plot.

  cirx = (/ 4.15, 3.26, 2.25, 1.59, 1.59, 2.25, 3.26, 4.15, 4.50/)
  ciry = (/ 8.46, 8.98, 8.80, 8.01, 6.99, 6.20, 6.02, 6.54, 7.50/)

  gsres = True             ; Indicate you want to set some resources.
  gsres@gsFillColor = 4    ; Change fill color.

  gsn_polygon(wks,xy,cirx,ciry,gsres)   ; Draw a filled polygon on the XY plot.
  frame(wks)                            ; Advance the frame.
end
gsn_polygon_ndc.ncl:
load "gsn_code.ncl"
begin
  wks = gsn_open_wks("x11","example")    ; Open a workstation.
 
  cirx = (/ .415, .326, .225, .159, .159, .225, .326, .415, .450/)
  ciry = (/ .846, .898, .880, .801, .699, .620, .602, .654, .750/)

  gsres = True             ; Indicate you want to set some resources.
  gsres@gsFillColor = 4    ; Change fill color.

  gsn_polygon_ndc(wks,cirx,ciry,gsres)  ; Draw a filled polygon.
  frame(wks)                            ; Advance the frame.
end
gsn_polymarker.ncl:
load "gsn_code.ncl"
begin
  wks = gsn_open_wks("x11","example")    ; Open a workstation.
 
  x = (/1.,2.,3.,4.,5.,6.,7.,8.,9.,10./)  ; Define X and Y arrays
  y = (/1.,2.,3.,4.,5.,6.,7.,8.,9.,10./)  ; for XY plot.

  xyres = True                  ; Indicate you want to set some resources.
  xyres@gsnFrame = False        ; Don't advance frame after plot is drawn.
  xy = gsn_xy(wks,x,y,xyres)    ; Draw XY plot.

  markx = (/ 4.15, 3.26, 2.25, 1.59, 1.59, 2.25, 3.26, 4.15, 4.50/)
  marky = (/ 8.46, 8.98, 8.80, 8.01, 6.99, 6.20, 6.02, 6.54, 7.50/)

  gsres = True              ; Indicate you want to set some resources.
  gsres@gsMarkerColor = 3   ; Change marker color.
  gsres@gsMarkerSizeF = 10. ; Increase marker size by a factor of 10.

  gsn_polymarker(wks,xy,markx,marky,gsres)  ; Draw the polymarkers on
                                            ; the XY plot.

  gsres@gsMarkerColor = 18   ; Change marker color.
  gsres@gsMarkerIndex = 16   ; Change marker type to a filled circle.

  gsn_polymarker(wks,xy,markx+4,marky-4,gsres) ; Draw the polymarkers on
                                               ; the XY plot.
  frame(wks)  ; Advance the frame.
end
gsn_polymarker_ndc.ncl:
load "gsn_code.ncl"

begin
  wks = gsn_open_wks("x11","example")    ; Open a workstation.
 
  markx = (/ .415, .326, .225, .159, .159, .225, .326, .415, .450/)
  marky = (/ .846, .898, .880, .801, .699, .620, .602, .654, .750/)

  gsres = True              ; Indicate you want to set some resources.
  gsres@gsMarkerColor = 3   ; Change marker color.
  gsres@gsMarkerSizeF = 10. ; Increase marker size by a factor of 10.

  gsn_polymarker_ndc(wks,markx,marky,gsres)  ; Draw the polymarkers.

  gsres@gsMarkerColor = 18   ; Change marker color.
  gsres@gsMarkerIndex = 16   ; Change marker type to a filled circle.

  gsn_polymarker_ndc(wks,markx+.4,marky-.4,gsres) ; Draw the polymarkers.

  frame(wks)  ; Advance the frame.
end
gsn_retrieve_colormap.ncl:
load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_code.ncl"

begin
  wks = gsn_open_wks("ncgm","colors")
  cmap = gsn_retrieve_colormap(wks)
  print(cmap)
end
hsv2rgb.ncl:
function hsv2rgb (h[*]:float,s[*]:float,v[*]:float)
begin
        ; This procedure converts between HSV and RGB color space
        ; Input: h [0.0-360.0], s [0.0-1.0], v [0.0-1.0]
        ; Output: r [0.0-1.0], g [0.0-1.0], b [0.0-1.0]
            r_g_b = new((/3,dimsizes(h)/),float)
            r_g_b!0 = "rgb"
            r_g_b!1 = "cmap_len"
 
            if (any((s .eq. 0.0).and.(h.eq.0.0.or.h.eq.360))) then
                indexs = ind((h.eq.0.0.or.h.eq.360).and.s.eq.0.0)
                r_g_b(:,indexs) = (/v(indexs),v(indexs),v(indexs)/)
                delete(indexs)
            end if

            f = new(dimsizes(h),float)
            p = new(dimsizes(h),float)
            q = new(dimsizes(h),float)
            t = new(dimsizes(h),float)
            i = new(dimsizes(h),integer)
            if any(h.eq.360.0)  
                h(ind(h.eq.360.0)) = 0.0
            end if

            h = h/60.0
            i = floattoint(floor(h))
            f = h - i
            p = v*(1.0 - s)
            q = v*(1.0 - (s*f))
            t = v*(1.0 - (s*(1.0 - f)))
            if any(i.eq.0) then
                indexs = ind(i.eq.0)
                r_g_b(:,indexs) = (/v(indexs),t(indexs),p(indexs)/)
                delete(indexs)
            end if
            if any(i.eq.1) then
                indexs = ind(i.eq.1)
                r_g_b(:,indexs) = (/q(indexs),v(indexs),p(indexs)/)
                delete(indexs)
            end if
            if any(i.eq.2) then
                indexs = ind(i.eq.2)
                r_g_b(:,indexs) = (/p(indexs),v(indexs),t(indexs)/)
                delete(indexs)
            end if
            if any(i.eq.3) then
                indexs = ind(i.eq.3)
                r_g_b(:,indexs) = (/p(indexs),q(indexs),v(indexs)/)
                delete(indexs)
            end if
            if any(i.eq.4) then
                indexs = ind(i.eq.4)
                r_g_b(:,indexs) = (/t(indexs),p(indexs),v(indexs)/)
                delete(indexs)
            end if
            if any(i.eq.5) then
                indexs = ind(i.eq.5)
                r_g_b(:,indexs) = (/v(indexs),p(indexs),q(indexs)/)
                delete(indexs)
            end if
            if(any(ismissing(r_g_b)))
                print("WARNING: Some invalid HSV values were passed to hsv2rgb")
            end if
            return(r_g_b(cmap_len|:,rgb|:))
end
labelbar.ncl:
load "hsv2rgb.ncl"
begin

;
; Open NetCDF file containing Geo-Potential height forecast
; information.
;
  filedir = ncargpath("data")
  filename = filedir + "/cdf/contour.cdf"
  cfile = addfile(filename,"r")

;
; Set the color map.
;
   ncolors = 13
   hue = fspan(0.,300.,ncolors)   ; Set hue range.
   sat = fspan(1.0,1.0,ncolors)     ; Set saturation range.
   val = fspan(0.8,0.8,ncolors)     ; Set value range.

   cmap  = new((/ncolors+2,3/),float)   ; Define (ncolors+2) x 3 float
                                        ; array to hold the color map.

   cmap(0,:)    = (/1.,1.,1./)   ; Set the background to white.
   cmap(1,:)    = (/0.,0.,0./)   ; Set the foreground to black.

   cmap(2:ncolors+1,:) = hsv2rgb(hue,sat,val) ; Generate smooth range of
                                              ; RGB values.

;
; Create an X workstation.
;
    wid = create "wks" xWorkstationClass defaultapp
      "wkColorMap" : cmap
    end create

  field = create "field" scalarFieldClass defaultapp
    "sfDataArray"     : cfile->Z(0,3,:,:) 
    "sfMissingValueV" : cfile->Z@_FillValue  ; Set missing value.
  end create

  xpos = (/0.12, 0.57, 0.12, 0.57/)   ; X and Y positions of
  ypos = (/0.95, 0.95, 0.53, 0.53/)   ; the four contour plots.

;
; Create a contour object.
;
  cnid = create "contour" contourPlotClass wid 
    "vpWidthF"             : 0.35
    "vpHeightF"            : 0.35
    "vpXF"                 : xpos(0)
    "vpYF"                 : ypos(0)

    "cnScalarFieldData"    : field

    "cnLevelSelectionMode" : "ManualLevels"  ; Manually select our 
    "cnMinLevelValF"       : 5400.0          ; own contour levels by
    "cnMaxLevelValF"       : 5950.0          ; specifying min, max,
    "cnLevelSpacingF"      :   50.0          ; and spacing.

    "cnFillOn"             : True            ; Turn on fill.
    "cnLineLabelsOn"       : False           ; Turn off line labels.
    "cnInfoLabelOn"        : False           ; Turn off info label.
    "cnLowLabelsOn"        : False           ; Turn off low label.
    "cnHighLabelsOn"       : False           ; Turn off high label.
  end create

  draw(cnid)  ; Draw contour plot.

;
; Loop through three more time steps and create and draw
; contour plots at each one.
;
  do i=1,3
    setvalues field
      "sfDataArray" : cfile->Z(i,3,:,:)   ; Select new time step.
    end setvalues

    setvalues cnid
      "vpXF"     : xpos(i)  ; Change X and Y positions
      "vpYF"     : ypos(i)  ; of the new contour plot.
    end setvalues

    draw(cnid)  ; Draw the new contour plot.
  end do

;
; Retrieve the contour levels and the colors used for filling the
; contours so we can use this information in a labelbar.
;
  getvalues cnid
    "cnLevels"     : levels
    "cnFillColors" : colors
  end getvalues

;
; Create a labelbar.
;
  lbid = create "labelbar" labelBarClass wid
    "vpXF"              : 0.25   ; Specify position of labelbar
    "vpYF"              : 0.13   ; in the viewport.
    "vpWidthF"          : 0.50
    "vpHeightF"         : 0.10

    "lbPerimOn"         : False               ; Turn off perimeter.
    "lbBoxCount"        : dimsizes(levels)+1  ; # of labelbar boxes.
    "lbOrientation"     : "Horizontal"        ; Default is vertical.
    "lbLabelAlignment"  : "InteriorEdges"     ; Default is "BoxCenters".
    "lbLabelStrings"    : levels              ; Labels for boxes.
    "lbFillColors"      : colors              ; Colors for boxes.
    "lbMonoFillPattern" : True                ; Fill them all solid.

  end create

  draw(lbid)  ; Draw the labelbar.
  frame(wid)  ; Advance the frame.
end
lblbar.ncl:
load "gsn_code.ncl"
load "hsv2rgb.ncl"

begin
   ncolors = 16    ; Plus two colors for background and foreground.

   hmin    = 225.  ; hue min
   hmax    = 360.  ; hue max
   smin    = 0.67  ; saturation min
   smax    = 0.67  ; saturation max
   vmin    = 1.0   ; value (intensity) min
   vmax    = 1.0   ; value max

   hue = fspan(hmin,hmax,ncolors)
   sat = fspan(smin,smax,ncolors)
   val = fspan(vmin,vmax,ncolors)

   cmap  = new((/ncolors+2,3/),float)

   cmap(0,:)           = (/1.,1.,1./)           ; white
   cmap(1,:)           = (/0.,0.,0./)           ; black
   cmap(2:ncolors+1,:) = hsv2rgb(hue,sat,val)

   wks = gsn_open_wks("x11","example")   ; Open an X11 window.
   gsn_define_colormap(wks,cmap)         ; Set the new colormap.

   lbres                    = True
   lbres@lbAutoManage       = False
   lbres@lbFillColors       = ispan(0,ncolors+1,1)
   lbres@lbLabelFontHeightF = 0.02
   lbres@lbMonoFillPattern  = True
   lbres@lbOrientation      = "Horizontal"
   lbres@lbPerimOn          = False
   lbres@vpHeightF          = 0.40
   lbres@vpWidthF           = 0.98

   lbstrings = ":F26:" + ispan(0,ncolors+1,1)   ; Labels for labelbar.

   gsn_labelbar_ndc(wks,ncolors+2,lbstrings,0.01,0.98,lbres) ; Draw a
                                                             ; labelbar.
; 
; Title at the bottom.
;
   textres               = True
   textres@txFontHeightF = 0.03
   gsn_text_ndc(wks,":F26:color indices",.5,.64,textres)

   frame(wks)    ; Advance frame.
end
logcon1.ncl:
begin

;
; Create some dummy data for the contour plot.
;
  N=25
 
  T = new((/N,N/),float)
 
  jspn = ispan(-N/2,N/2,1)^2
  ispn = ispan(-N/2,N/2,1)^2
  do i = 0, dimsizes(ispn)-1
      T(i,:) = ispn(i) + jspn
  end do
  T = 100.0 - sqrt(8^2 * T)

;
; Create an X workstation.
;
  wid = create "wks" xWorkstationClass defaultapp end create

;
; Create a data object.  Change the min and max of the Y axes to be
; 10 and 10000 instead of 0 and N-1 (the default), because you can't take
; the log of 0.
;
  dataid = create "data" scalarFieldClass defaultapp
    "sfDataArray" : T      ; Contour data.
    "sfYCStartV"  : 10     ; Min value for Y axis.
    "sfYCEndV"    : 10000  ; Max value for Y axis.
  end create

;
; Create a ContourPlot object and draw it to show what a linear X and
; Y axis looks like.
;
  cnid = create "ContourPlot" contourPlotClass wid
    "cnScalarFieldData" : dataid
    "tiXAxisString"     : "linear"   ; Label for X axis.
    "tiYAxisString"     : "linear"   ; Label for Y axis.
  end create

  draw(cnid)  ; Draw the contour plot.
  frame(wid)  ; Advance the frame.

;
; Now set trYLog to True to indicate the Y axis should be log.
;
  setvalues cnid
    "tiYAxisString"  : "log"    ; Label for Y axis.
    "trYLog"         : True     ; Log scaling for Y axis
  end setvalues

  draw(cnid)  ; Draw the contour plot.
  frame(wid)  ; Advance the frame.

end
logcon2.ncl:
begin

;
; Create some dummy data for the contour plot.
;
  N=25
 
  T = new((/N,N/),float)
 
  jspn = ispan(-N/2,N/2,1)^2
  ispn = ispan(-N/2,N/2,1)^2
  do i = 0, dimsizes(ispn)-1
      T(i,:) = ispn(i) + jspn
  end do
  T = 100.0 - sqrt(8^2 * T)

;
; Create an X workstation.
;
  wid = create "wks" xWorkstationClass defaultapp end create

;
; Create some dummy data for the Y axis that is NOT regularly spaced.
;
  y = (/  10,   50,  100,  150,  250,  500,  750, 1000, 1100, 1300, 1500, \
        1750, 2000, 2200, 2400, 2600, 3000, 4000, 4500, 5000, 5100, 5500, \
        7000, 9000,10000/)

;
; Create a data object with irregularly spaced data for the Y
; axis. Whenever you set the sfYArray or sfXarray resource, this signals
; that that particular axis is now irregularly spaced, regardless of
; whether the data used for these resources is irregularly spaced.
;
  dataid = create "data" scalarFieldClass defaultapp
    "sfDataArray" : T   ; Contour data.
    "sfYArray"    : y   ; Coordinates for Y axis.
  end create

;
; Create a ContourPlot object and draw it to show what the plot
; looks like with a linear X axis and an irregular Y axis.
;
  cnid = create "ContourPlot" contourPlotClass wid
    "cnScalarFieldData" : dataid
    "tiXAxisString"     : "linear"              ; Label for X axis.
    "tiYAxisString"     : "irregularly spaced"  ; Label for Y axis.
  end create

  draw(cnid)  ; Draw plot.
  frame(wid)  ; Advance frame.

;
; Create a LogLin plot in which the ContourPlot will be overlaid in
; order to get the irregular Y axis in log scaling.  This is the only
; way you can currently get an irregularly spaced axis to be in log
; coordinates.
;
  llid = create "loglin" logLinPlotClass wid
    "trXMinF" : 0.      ; Set the min and max for
    "trXMaxF" : N-1     ; the X axis.
    "trYMinF" : min(y)  ; Set the min and max for
    "trYMaxF" : max(y)  ; the Y axis.
    "trYLog"  : True    ; Set the Y axis to be log.
  end create

  setvalues cnid
    "tiYAxisString"  : "log"   ; Change label for Y axis.
  end setvalues

;
; By overlaying the ContourPlot on this LogLinPlot, the ContourPlot
; will be transformed to the coordinates of the LogLinPlot; that is,
; the Y axis will be in log scaling.
;
  overlay(llid,cnid)

  draw(llid)  ; Draw the LogLinPlot, which will include the ContourPlot.
  frame(wid)  ; Advance the frame.
end
logxy.ncl:
begin

;
; Create dummy data for XY plot.
;
  y =  (/10, 100, 5000, 10, 9000, 70, 300, 10000, 600/)

  wid = create "wks" xWorkstationClass defaultapp end create

;
; Create the data object.
;
  dataid = create "data" coordArraysClass defaultapp
    "caYArray": y
  end create

;
; Create and draw an XyPlot with linear scaling.
;
  xyid = create "plot" xyPlotClass wid
    "xyCoordData"   : dataid
    "tiXAxisString" : "linear"   ; Label for X axis.
    "tiYAxisString" : "linear"   ; Label for Y axis.
  end create

  draw(xyid)  ; Draw the XY plot.
  frame(wid)  ; Advance the frame.

;
; Change the Y axis scale to be log and redraw the plot.
;
  setvalues xyid
    "trYLog"        : True   ; Set Y axis to log.
    "tiYAxisString" : "log"  ; Change label for Y axis.
  end setvalues

  draw(xyid)  ; Draw the XY plot.
  frame(wid)  ; Advance the frame.
end
map1.ncl:
begin
;
; Create an X workstation to draw on.
;
  wid = create "wks" xWorkstationClass defaultapp end create

;
; Create the default map plot.
;
  mapid = create "map" mapPlotClass wid end create

;
; Draw the map.
;
  draw(mapid)

;
; Retrieve the view port coordinates of the map so you can draw the tick
; marks in the exact same location.
;
  getvalues mapid
     "vpXF"            : vpx
     "vpYF"            : vpy
     "vpWidthF"        : vpwidth
     "vpHeightF"       : vpheight
  end getvalues

;
; Create a TickMark object.
;
  tmid = create "tickmarks" tickMarkClass wid
     "vpXF"            : vpx        ; Set the viewport location of the
     "vpYF"            : vpy        ; tick marks to be the same as 
     "vpWidthF"        : vpwidth    ; the map.
     "vpHeightF"       : vpheight

     "tmYLDataBottomF" :  -90.0     ; The default map projection goes
     "tmYLDataTopF"    :   90.0     ; from -90,90 latitude and -180,180
     "tmXBDataLeftF"   : -180.0     ; longitude, so use these same 
     "tmXBDataRightF"  :  180.0     ; values for the tick marks.

     "tmXBLabelFont"        : 22    ; Change the font and size of the
     "tmXBLabelFontHeightF" : 0.015 ; bottom tick mark labels.

     "tmXBMode"        : "Explicit" ; Set the tick mark labeling mode
                                    ; to "explicit" so that you can 
                                    ; explicitly define where you want
                                    ; tickmarks and their labels with
                                    ; the resources "tmXBValues" and
                                    ; "tmXBLabels."

     "tmXBValues"      : (/-180., -120., -60.,  0., 60.,  120.,  180./)
     "tmXBLabels"      : (/"180W","120W","60W","0","60E","120E","180E"/)

     "tmYLLabelFont"        : 22    ; Change the font and size of the
     "tmYLLabelFontHeightF" : 0.015 ; left tick mark labels.

     "tmYLMode"        : "Explicit"
     "tmYLValues"      : (/-90., -60., -30.,  0., 30.,  60.,  90./)
     "tmYLLabels"      : (/"90S","60S","30S","0","30N","60N","90N"/)

  end create

;
; Draw the TickMark object.
;
  draw(tmid)

;
; Advance the frame.
;
  frame(wid)

end
map2.ncl:
;
; This example shows how to create a polar stereographic plot with 
; the lat/lon grid labeled.
;
begin

;
; Create an X workstation to draw on.
;
  wid = create "map" xWorkstationClass defaultapp end create

;
; Create a polar stereographic map.
;
  mpid = create "mapplot" mapPlotClass wid
     "vpXF"                  : 0.10    ; Change the location and
     "vpYF"                  : 0.90    ; the width and height
     "vpWidthF"              : 0.78    ; of the map.
     "vpHeightF"             : 0.78

     "mpProjection"          : "Stereographic"
     "mpCenterLatF"          :  90.0           ; Change the center of
     "mpCenterLonF"          : -90.0           ; the projection.

     "mpEllipticalBoundary"  : True    ; Here's what makes it elliptical.

     "mpLimitMode"           : "LatLon"  ; Change the map limit mode
     "mpMinLatF"             :    0.0    ; so that only the northern
     "mpMaxLatF"             :   90.0    ; hemisphere is visible.
     "mpMinLonF"             : -180.0
     "mpMaxLonF"             :  180.0
  end create

;
; Draw the map.
;
  draw(mpid)

;
; Change the viewport of the map object we just created to generate a
; new data space for lat/lon text. Make the new viewport slightly larger
; than the one the map was drawn in, because we want to draw the
; labels on the outside of the map.
;
  setvalues mpid
      "vpXF"      : 0.07
      "vpYF"      : 0.93
      "vpWidthF"  : 0.84
      "vpHeightF" : 0.84
  end setvalues

;
; Create a generic TextItem object that we'll use to label the lat/lon
; grid.  
;
  txid = create "text" textItemClass wid
      "txFont"         : 22     ; Change the font to 22 (helvetica).
      "txFontHeightF"  : 0.015  ; Change the size of the font.
  end create

;
; Define an array of strings to label the longitude values.
;
  labels = (/"0","30E","60E","90E","120E","150E","180","150W",\
             "120W","90W","60W","30W"/)

;
; Create the lat/lon coordinates where you want labels to appear.
; In this case, we want the labels to appear at the equator (lat=0),
; and at longitude values of 0, 30, 60, ..., 330.
;
  lat = fspan(0.,0.,12)
  lon = fspan(0.,330.,12)

;
; Create arrays to hold the NDC values that we're going to convert 
; the lat/lon values to.
;
  xndc = new(dimsizes(lon),float)
  yndc = new(dimsizes(lat),float)

;
; Convert lat/lon coordinates to NDC coordinates since we are 
; drawing the labels in NDC space and NOT in lat/lon space.
;
  datatondc(mpid,lon,lat,xndc,yndc)

;
; Draw each string.
;
  do i=0,dimsizes(labels)-1
    setvalues txid
       "txString" : labels(i)
       "txPosXF"  : xndc(i)
       "txPosYF"  : yndc(i)
    end setvalues

    draw(txid)
  end do

;
; Advance the frame.
;
  frame(wid)
    
end
metafile.ncl:
begin
;
; Create an NCGM Workstation and change the name of the metafile to
; "plot.ncgm."
;
  wks = create "wks" ncgmWorkstationClass defaultapp
    "wkMetaName" : "plot.ncgm"
  end create

  mapid = create "map" mapPlotClass wks end create  ; Create a map object.

  draw(mapid)  ; Draw the map plot.
  frame(wks)   ; Advance the frame.
end
misscon.ncl:
begin

;
; Create some dummy data for the contour plot.
;
  T = (/ (/  7,  7,   7,   7,   7,   7,   7,   7,   7, 7, 7 /),\
         (/  7,  5,   5,   5,   5,   5,   5,   5,   5, 5, 7 /),\
         (/  7,  5, 999, 999, 999, 999, 999, 999, 999, 5, 7 /),\
         (/  7,  5, 999,   3,   3,   3,   3,   3, 999, 5, 7 /),\
         (/  7,  5, 999,   3,   2,   2,   2,   3, 999, 5, 7 /),\
         (/  7,  5, 999,   3,   2,   1,   2,   3, 999, 5, 7 /),\
         (/  7,  5, 999,   3,   2,   2,   2,   3, 999, 5, 7 /),\
         (/  7,  5, 999,   3,   3,   3,   3,   3, 999, 5, 7 /),\
         (/  7,  5, 999, 999, 999, 999, 999, 999, 999, 5, 7 /),\
         (/  7,  5,   5,   5,   5,   5,   5,   5,   5, 5, 7 /),\
         (/  7,  7,   7,   7,   7,   7,   7,   7,   7, 7, 7 /)/)

;
; Create an X workstation.
;
  wid = create "wks" xWorkstationClass defaultapp end create

;
; Create a data object.
;
  dataid = create "data" scalarFieldClass defaultapp
    "sfDataArray"     : T
    "sfMissingValueV" : 999  ; Indicate that 999 is a missing value
                             ; and thus shouldn't be plotted.
  end create

;
; Create a ContourPlot object.
;
  cnid = create "ContourPlot" contourPlotClass wid
    "cnScalarFieldData" : dataid
  end create

  draw(cnid)    ; Draw contour plot.
  frame(wid)    ; Advance frame.
end
missxy.ncl:
begin
;
; Create an X Workstation.
;
  wks = create "wks" xWorkstationClass defaultapp end create

;
; Create a data object.
;
  dataid = create "data" coordArraysClass defaultapp
    "caYArray"    : (/1,3,-1,-2,0,2,3,0,5,-2,1,0,0,8,10,5,-3/)

    "caYMissingV" : 0  ; Indicate that 0 is a missing value and thus
                       ; shouldn't be plotted.
  end create

;
; Create an XY plot.
;
  xy = create "xyplot" xyPlotClass wks
    "xyCoordData"  : dataid
  end create

  draw(xy)     ; Draw the XY plot.
  frame(wks)   ; Advance the frame.
end
multiple.ncl:
begin
;
; Define four dummy data sets (for four XY plots).
;
  npts = 101
  y = new((/4,npts/),float)
  y(0,:) = sin(3.14159*fspan(0.,20.,npts)/2.)
  y(1,:) = sin(3.14159*fspan(0.,20.,npts)/4.)
  y(2,:) = sin(3.14159*fspan(0.,20.,npts)/8.)
  y(3,:) = sin(3.14159*fspan(0.,20.,npts)/16.)

;
; Define the X and Y positions in the viewport of each XY plot.
; (0.,0.) represents the lower left corner and (1.,1.) represents
; the upper right corner of the viewport.  The (x,y) position that you
; specify is the position for the upper left corner of the plot, so
; a position of (0.10,0.90) will place the upper left corner of the plot
; in the upper left corner of the viewport.  A position of (0.60,0.45)
; will place the upper left corner of the plot at roughly the middle of
; the viewport (slightly below and to the right of the middle).
;
  xpos = (/0.10, 0.60, 0.10, 0.60/)
  ypos = (/0.90, 0.90, 0.45, 0.45/)

;
; Create an X workstation.
;
  wid = create "xyplots" xWorkstationClass defaultapp  end create

;
; Create arrays to hold the data and plot objects.
;
  dataid = new(4,graphic)
  plotid = new(4,graphic)

;
; Loop through the four plots, create each one, and draw it.
;
  do i = 0,3
    dataid(i) = create "data" coordArraysClass defaultapp
      "caYArray": y(i,:)
    end create

    plotid(i) = create "plot" xyPlotClass wid
      "vpXF"        : xpos(i)
      "vpYF"        : ypos(i)
      "vpWidthF"    : 0.35     ; The width and height is the same for
      "vpHeightF"   : 0.35     ; each plot.

      "xyCoordData" : dataid(i)

      "tiMainString" : "Plot " + i + " (" + xpos(i) + "," + ypos(i) + ")"
    end create

    draw(plotid(i))
  end do

;
; Advance the frame.
;
  frame(wid)

end
overlay1.ncl:
begin

;
; Create some data for the contour plot.
;
  M=25
  N=25
 
  T = new((/N,M/),float)
 
  jspn = ispan(-M/2,M/2,1)^2
  ispn = ispan(-N/2,N/2,1)^2
  do i = 0, dimsizes(ispn)-1
      T(i,:) = ispn(i) + jspn
  end do
  T = 100.0 - sqrt(8^2 * T)

;
; Create an X workstation.
;
  wid = create "wks" xWorkstationClass defaultapp end create

;
; Create a data object.
;
  dataid = create "data" scalarFieldClass defaultapp
    "sfDataArray" : T
    "sfXCStartV"  : -90.0   ; minimum longitude value for overlay
    "sfXCEndV"    :  90.0   ; maximum longitude value for overlay
    "sfYCStartV"  : -45.0   ; minimum latitude value for overlay
    "sfYCEndV"    :  45.0   ; maximum latitude value for overlay
  end create

;
; Create a ContourPlot object.
;
  cnid = create "ContourPlot" contourPlotClass wid
    "cnScalarFieldData" : dataid
  end create

;
; Create the default MapPlot object.
;
  mpid = create "MapPlot" mapPlotClass wid end create
  
  overlay(mpid,cnid) ; Overlay contour plot on map plot.
  draw(mpid)         ; Draw map plot (contour plot will be drawn too).
  frame(wid)         ; Advance frame.
end
overlay2.ncl:
begin

;
; Create some data for the contour plot.
;
  M=25
  N=25
 
  T = new((/N,M/),float)
 
  jspn = ispan(-M/2,M/2,1)^2
  ispn = ispan(-N/2,N/2,1)^2
  do i = 0, dimsizes(ispn)-1
      T(i,:) = ispn(i) + jspn
  end do
  T = 100.0 - sqrt(8^2 * T)

;
; Create an X workstation.
;
  wid = create "wks" xWorkstationClass defaultapp end create

;
; Create a data object.
;
  dataid = create "data" scalarFieldClass defaultapp
    "sfDataArray" : T
  end create

;
; Create and draw a MapPlot object.
;
  mpid = create "MapPlot" mapPlotClass wid end create

  draw(mpid)         ; Draw map plot.

;
; Retrieve the viewport coordinates used in the map plot so they
; can be used in the contour plot.
;
  getvalues mpid
    "vpXF"       : xpos
    "vpYF"       : ypos
    "vpWidthF"   : width
    "vpHeightF"  : height
  end getvalues

;
; Create a ContourPlot object using the same viewport coordinates as
; the map plot.
;
  cnid = create "ContourPlot" contourPlotClass wid
    "vpXF"       : xpos
    "vpYF"       : ypos
    "vpWidthF"   : width
    "vpHeightF"  : height

    "cnScalarFieldData" : dataid
  end create

  draw(cnid)   ; Draw the contour plot.

  frame(wid)   ; Advance frame.
end
panel.ncl:
load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_code.ncl"

begin
;
; Open a netCDF file containing storm data.
;
  tfile = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/Tstorm.cdf","r")
;
; Get the temperature arrays for the first 6 time steps.
;
  nplots = 6
  temp = tfile->t(0:nplots-1,:,:)

;
; Save the lat and lon arrays to a variable.
;
  lat = tfile->t&lat
  lon = tfile->t&lon

  lat@name = "latitude"    ; Name the lat variable.
  lon@name = "longitude"   ; Name the lon variable.

  wks = gsn_open_wks("x11","panel")  ; Open an X11 workstation.

;
; Define a color map.
;
  cmap = (/(/1.00,1.00,1.00/),(/0.00,0.00,0.00/),(/1.00,.000,.000/),\
           (/.950,.010,.000/),(/.870,.050,.000/),(/.800,.090,.000/),\
           (/.700,.090,.000/),(/.700,.120,.000/),(/.700,.180,.000/),\
           (/.700,.260,.000/),(/.700,.285,.000/),(/.680,.330,.000/),\
           (/.570,.420,.000/),(/.560,.530,.000/),(/.550,.550,.000/),\
           (/.130,.570,.000/),(/.060,.680,.000/),(/.000,.690,.000/),\
           (/.000,.700,.100/),(/.000,.600,.300/),(/.000,.500,.500/),\
           (/.000,.400,.700/),(/.000,.300,.700/),(/.000,.200,.700/),\
           (/.000,.100,.700/),(/.000,.000,.700/),(/.100,.100,.700/),\
           (/.200,.200,.700/),(/.300,.300,.700/),(/.420,.400,.700/),\
           (/.560,.500,.700/),(/.610,.600,.700/),(/.700,.700,.700/)/)

  gsn_define_colormap(wks,cmap)

;
; The next set of resources will apply to all four plots.
;
  resources               = True

  resources@gsnDraw       = False      ; Don't draw plot or advance the
  resources@gsnFrame      = False      ; frame after plot is created.
;
; Loop through four of the timesteps and create each plot. Title each
; plot according to which timestep it is.
;

  plot = new(nplots,graphic)
  do i=0,nplots-1
    resources@tiMainString  = "Temperature at time = " + i
    plot(i) = gsn_contour(wks,temp(i,:,:),resources)
  end do

  gsn_panel(wks,plot(0:3),(/2,2/),False) ; Draw 2 rows/2 columns of plots.

;
; This section will set resources for drawing contour plots
; over a map.
;
  delete(resources@tiMainString)  ; Don't set a main title.

  resources@sfXArray       = lon  ; Portion of map on which to overlay
  resources@sfYArray       = lat  ; contour plot.

  resources@cnInfoLabelOn  = False   ; Turn off info label.
  resources@cnLineLabelsOn = False   ; Turn off contour line labels.
  resources@cnLinesOn      = False   ; Turn off contour lines.
  resources@cnFillOn       = True    ; Turn on contour fill.

  resources@cnLevelSelectionMode = "ManualLevels"  ; Select contour levels.
  resources@cnMinLevelValF       = 245.
  resources@cnMaxLevelValF       = 302.5
  resources@cnLevelSpacingF      =   2.5

  resources@mpLimitMode    = "LatLon"  ; Limit portion of map that is viewed.
  resources@mpMinLatF      = min(lat)
  resources@mpMaxLatF      = max(lat)
  resources@mpMinLonF      = min(lon)
  resources@mpMaxLonF      = max(lon)

  resources@mpPerimOn       = True    ; Turn on map perimeter.
  resources@mpGridAndLimbOn = False   ; Turn off map grid.

  do i=0,nplots-1
    plot(i) = gsn_contour_map(wks,temp(i,:,:),resources)
  end do

  panelres                = True
  panelres@gsnFrame       = False ; Don't advance the frame.
  panelres@gsnPanelBottom = 0.1   ; More white space at bottom for labelbar.
                                  ; Default is 0.

  gsn_panel(wks,plot,(/3,2/),panelres)  ; Draw 3 rows and 2 columns of plots.

;
; Draw two titles at the top.
;
  textres               = True
  textres@txFontHeightF = 0.025   ; Size of title.

  gsn_text_ndc(wks,":F26:Temperature (K) at every six hours",0.5,.97,textres)

  textres@txFontHeightF = 0.02    ; Make second title slightly smaller.

  gsn_text_ndc(wks,":F26:January 1996",0.5,.935,textres)

;
; Retrieve level and colors for use in labelbar.
;
  getvalues plot@contour
    "cnLevels"     : levels
    "cnFillColors" : colors
  end getvalues

;
; Only label every other line in the labelbar.
;
  lev_labels = new(dimsizes(levels),string)
  do i = 0,dimsizes(levels)-1,2
    lev_labels(i) = levels(i)
    if(i.lt.dimsizes(levels)-1) 
      lev_labels(i+1) = ""
    end if
  end do

  lbres = True

  lbres@lbFillColors       = colors           ; Set the colors to use.
  lbres@lbLabelAlignment   = "InteriorEdges"  ; Only label interior lines.
  lbres@lbLabelFont        = "helvetica-bold" ; Change label font.
  lbres@lbLabelFontHeightF = 0.07             ; Change label font height.
  lbres@lbMonoFillPattern  = True             ; Fill each box solid.
  lbres@lbOrientation      = "horizontal"     ; Horizontal labelbar.
  lbres@lbPerimOn          = False            ; Turn off perimeter.
  lbres@vpHeightF          = 0.2              ; Height of labelbar.
  lbres@vpWidthF           = 0.9              ; Width of labelbar.

  gsn_labelbar_ndc(wks,dimsizes(colors),lev_labels,0.05,0.2,lbres)

  frame(wks)   ; Advance the frame.
end
ps.ncl:
begin

;
; Open a PostScript workstation. Note that the coordinates selected
; do not form a square, so the aspect ratio of the plot will also
; not be a square.  
;
  wid = create "workstation" psWorkstationClass defaultapp
      "wkDeviceLowerX" : -75   ; These coordinates can be negative.
      "wkDeviceLowerY" : -50
      "wkDeviceUpperX" : 750
      "wkDeviceUpperY" : 950
  end create

;
; Create the default TickMark object.
;
  tmid = create "ticks" tickMarkClass wid end create

  draw(tmid)  ; Draw the TickMark object.
  frame(wid)  ; Advance the frame.
end
readasc.ncl:
begin
;
; Read an ASCII file.  The file "oceanland30e.asc" contains a single
; column of integers, 16471 of them.  The function "asciiread" allows
; you to specify the dimensionality of the data, and in this case we
; are passing dimensions (/91,181/), so "ocean1" will be a 2-dimensional
; array dimensioned 91 x 181, which can be verified by printing the
; dimsizes of "ocean1."
;
  filedir = ncargpath("data")
  ocean1 = asciiread(filedir + "/asc/oceanland30e.asc",(/91,181/),"integer")
  print(dimsizes(ocean1))

;
; Write out part of "ocean1" to a new ASCII file.  "data.asc" will contain
; 15 integers, since (7:3:2,0:4) is a 3 x 5 array.
;	
  asciiwrite("data.asc",ocean1(7:3:2,0:4))

end
readnc.ncl:
begin
;
; Open netCDF file and print its contents.
;
  filedir = ncargpath("data")
  ncfilename = filedir + "/cdf/contour.cdf"
  netcdf_file = addfile(ncfilename,"r")
  print(netcdf_file)

;
; Open GRIB file and print its contents.
;
  grbfilename = filedir + "/grb/ced1.lf00.t00z.eta.grb"
  grib_file = addfile(grbfilename,"r")
  print(grib_file)

;
; Open a netCDF file called "data.nc" and write some of the GRIB contents
; to it.  The "data.nc" file will contain variables "PRES," "HGT,"
; "A_PCP," "NCPCP," "ACPCP," and "CAPE," which you can verify with:
;
;       ncdump -h data.nc
;
  ncfile_out = addfile("data.nc","c")
  ncfile_out->PRES  = grib_file->PRES_6_SFC 
  ncfile_out->HGT   = grib_file->HGT_6_SFC 
  ncfile_out->A_PCP = grib_file->A_PCP_6_SFC_acc
  ncfile_out->NCPCP = grib_file->NCPCP_6_SFC_acc
  ncfile_out->ACPCP = grib_file->ACPCP_6_SFC_acc
  ncfile_out->CAPE  = grib_file->CAPE_6_SFC
end
scale1.ncl:
begin

;
; Define a Y array to plot.
;
  y = (/2.0,0.9,2.2,4.3,3.9,4.6,4.8,4.8,4.6,3.5,3.9,2.5,2.0/)

;
; Define an array of randomly spaced pressure values.  These are the 
; values that we want to go on the right Y axis.
;
  pressure = (/1000, 925, 875, 800, 700, 575, 450, 350, 200, 175, 75, 50/)
 
;
; Create an X workstation.
;
  wid = create "xwid" xWorkstationClass defaultapp end create

;
; Create a data object.
;
  dataid = create "xyData" coordArraysClass defaultapp
      "caYArray": y
  end create

;
; Create an XY plot.
;
  plotid = create "xyPlot" xyPlotClass wid
      "xyCoordData" : dataid

      "trYMinF"     : min(y)      ; Make sure the min/max of our Y axis
      "trYMaxF"     : max(y)      ; is the same as our data.

      "tmYUseLeft"  : False       ; Don't use tick marks on the right side
                                  ; that are used on left side.

      "tmYRMode"    : "Explicit"  ; Explicitly define where we want tick
                                  ; marks and what labels we want at them.

;
; Place the pressure values at equal intervals along the right Y axis.
; Note that the pressure values themselves are NOT equally spaced, but
; they will be placed at equal intervals on the axis.
;
      "tmYRValues"   : fspan(min(y),max(y),dimsizes(pressure))
      "tmYRLabels"   : pressure

      "tmYRLabelsOn" : True   ; We have to turn on labels for the right axes,
                              ; otherwise they won't appear.
  end create

  draw(plotid)   ; Draw the XY plot.

;
; Create a text item to label the left Y axis.
;
  txid = create "text" textItemClass wid
    "txPosXF"        : 0.10   ; X pos. of text
    "txPosYF"        : 0.50   ; Y pos. of text
    "txFontHeightF"  : 0.02   ; Change the size of the font.
    "txAngleF"       : 90.0   ; Rotate the text 90 deg. counter-clockwise.
    "txString"       : "Height (km)"
  end create

  draw(txid)   ; Draw the text item.

;
; Change some values of previous text item to create a new label for
; the right Y axis.
;
  setvalues txid
    "txPosXF"  :   0.9   ; X pos. of text (use same Y position as before)
    "txAngleF" : -90.0   ; Rotate the text 90 deg. clockwise
    "txString" : "Pressure (mb)"
  end setvalues

  draw(txid)   ; Draw the text item.

  frame(wid)   ; Advance the frame

end
scale2.ncl:
begin

;
; Define a Y array to plot.
;
  y = (/2.0,0.9,2.2,4.3,3.9,4.6,4.8,4.8,4.6,3.5,3.9,2.5,2.0/)

;
; Define an array of randomly spaced pressure values.  These are the 
; values that we want to go on the right Y axis.
;
  pressure = (/1000, 925, 875, 800, 700, 575, 450, 350, 200, 175, 75, 50/)
 
;
; Create an X workstation.
;
  wid = create "xwid" xWorkstationClass defaultapp end create

;
; Create a data object.
;
  dataid = create "xyData" coordArraysClass defaultapp
      "caYArray": y
  end create

;
; Create an XY plot.
;
  plotid = create "xyPlot" xyPlotClass wid
      "vpXF"         : 0.20   ; Change the size and location of
      "vpYF"         : 0.80   ; the XY plot in the viewport.
      "vpWidthF"     : 0.60
      "vpHeightF"    : 0.60

      "xyCoordData"  : dataid

      "trYMinF"      : min(y) ; Make sure the min/max of our Y axis
      "trYMaxF"      : max(y) ; is the same as our data.

      "tmYROn"       : False  ; Turn off right Y axis tick marks.
  end create

  draw(plotid)   ; Draw the XY plot.

  tmid = create "tickmarks" tickMarkClass wid
      "vpXF"         : 0.20 ; Use the same size and location that
      "vpYF"         : 0.80 ; was used for the XY plot.
      "vpWidthF"     : 0.60
      "vpHeightF"    : 0.60

      "tmXBDataLeftF"   : 0.0             ; Set the min and max of
      "tmXBDataRightF"  : dimsizes(y) -1  ; the bottom X axis.

      "tmYLDataBottomF" : max(pressure)   ; Set the min and max of 
      "tmYLDataTopF"    : min(pressure)   ; the left Y axis.

      "tmYLStyle"           : "Irregular" ; Indicate that the left Y
      "tmYLIrregularPoints" : pressure    ; axis values are irregular.
                                          ; By default, since we are 
                                          ; defining the left axis, we are
                                          ; also defining the right axis.

      "tmXBOn"       : False    ; Turn off the bottom, top, and
      "tmXTOn"       : False    ; left tick marks and labels.
      "tmYLOn"       : False
      "tmXBLabelsOn" : False
      "tmYLLabelsOn" : False

      "tmYRLabelsOn" : True     ; Turn on the right y axis labels.

      "tmYLMode"     : "Explicit"  ; Explicitly define where we want
      "tmYLValues"   : pressure    ; tick marks and what labels we want
      "tmYLLabels"   : pressure    ; at them.
  end create

  draw(tmid)  ; Draw the tick mark object.

;
; Create a text item to label the left Y axis.
;
  txid = create "text" textItemClass wid
    "txPosXF"        : 0.10   ; X pos. of text
    "txPosYF"        : 0.50   ; Y pos. of text
    "txFontHeightF"  : 0.02   ; Change the size of the font.
    "txAngleF"       : 90.0   ; Rotate the text 90 deg. counter-clockwise.
    "txString"       : "Height (km)"
  end create

  draw(txid)   ; Draw the text item.

;
; Change some values of previous text item to create a new label for
; the right Y axis.
;
  setvalues txid
    "txPosXF"  :   0.9   ; X pos. of text (use same Y position as before)
    "txAngleF" : -90.0   ; Rotate the text 90 deg. clockwise
    "txString" : "Pressure (mb)"
  end setvalues

  draw(txid)   ; Draw the text item.

  frame(wid)  ; Advance the frame.

end
scale3.ncl:
begin

;
; Create some dummy data for the contour plot.
;
  N=12
 
  T = new((/N,N/),float)
 
  jspn = ispan(-N/2,(N/2)-1,1)^2
  ispn = ispan(-N/2,(N/2)-1,1)^2
  do i = 0, dimsizes(ispn)-1
      T(i,:) = ispn(i) + jspn
  end do
  T = 100.0 - sqrt(8^2 * T)

;
; Define an array of randomly spaced pressure values.  These are the 
; values that we want to go on the right Y axis.
;
  pressure = (/1000, 925, 875, 800, 700, 575, 450, 350, 200, 175, 75, 50/)
 
;
; Create an X workstation.
;
  wid = create "xwid" ncgmWorkstationClass defaultapp end create

;
; Create a data object.
;
  dataid = create "contourdata" scalarFieldClass defaultapp
      "sfDataArray": T
  end create

;
; Create an XY plot.
;
  plotid = create "contour" contourPlotClass wid
      "cnScalarFieldData" : dataid

      "tmYUseLeft"  : False       ; Don't use tick marks on the right side
                                  ; that are used on left side.

      "tmYRMode"    : "Explicit"  ; Explicitly define where we want tick
                                  ; marks and what labels we want at them.

;
; Place the pressure values at equal intervals along the right Y axis.
; Note that the pressure values themselves are NOT equally spaced, but
; they will be placed at equal intervals on the axis.
;
      "tmYRValues"   : fspan(0.,N-1,dimsizes(pressure))
      "tmYRLabels"   : pressure

      "tmYRLabelsOn" : True   ; We have to turn on labels for the right axes,
                              ; otherwise they won't appear.
  end create

  draw(plotid)   ; Draw the contour plot.

;
; Create a text item to label the left Y axis.
;
  txid = create "text" textItemClass wid
    "txPosXF"        : 0.12   ; X pos. of text
    "txPosYF"        : 0.50   ; Y pos. of text
    "txFontHeightF"  : 0.02   ; Change the size of the font.
    "txAngleF"       : 90.0   ; Rotate the text 90 deg. counter-clockwise.
    "txString"       : "Height (km)"
  end create

  draw(txid)   ; Draw the text item.

;
; Change some values of previous text item to create a new label for
; the right Y axis.
;
  setvalues txid
    "txPosXF"  :   0.91  ; X pos. of text (use same Y position as before)
    "txAngleF" : -90.0   ; Rotate the text 90 deg. clockwise
    "txString" : "Pressure (mb)"
  end setvalues

  draw(txid)   ; Draw the text item.

  frame(wid)   ; Advance the frame

end
stream.ncl:
begin

;
; Generate streamline data arrays.
;
  M=30
  N=30
  PI=3.14159

  U = 10.0 * sin(onedtond((2.0 * PI / N) * ispan(0,N-1,1),(/M,N/)))
  V = 10.0 * cos(onedtond((2.0 * PI / M) * ispan(0,M-1,1),(/N,M/)))

;
; Create an X workstation.
;
  wid = create "wks" xWorkstationClass defaultapp end create

;
; Create a data object.
;
  vfid = create "data" vectorFieldClass defaultapp
    "vfUDataArray" : U
    "vfVDataArray" : V
    "vfXCStartV"   : -90.0   ; minimum longitude value for overlay
    "vfXCEndV"     :  90.0   ; maximum longitude value for overlay
    "vfYCStartV"   : -45.0   ; minimum latitude value for overlay
    "vfYCEndV"     :  45.0   ; maximum latitude value for overlay
  end create

;
; Create a StreamlinePlot object.
;
  stid = create "StreamlinePlot" streamlinePlotClass wid
    "stVectorFieldData" : vfid
  end create

;
; Create the default MapPlot object.
;
  mpid = create "MapPlot" mapPlotClass wid end create
  
  overlay(mpid,stid) ; Overlay streamline plot on map plot.
  draw(mpid)         ; Draw map plot (streamline plot will be drawn too).
  frame(wid)         ; Advance frame.
end
tdez2d.ncl:
begin

;
; Create some dummy data for the surface plot.
;
  N  = 41
  PI = 3.14159

  x = fspan(0.,N-1,N)
  y = fspan(0.,N-1,N)
  z = 3.*sin(onedtond((PI/5) * ispan(0,N-1,1),(/N,N/)))
;
; Create an X workstation.
;
  wid = create "wks" xWorkstationClass defaultapp end create

;
; Retrieve the GKS workstation id, which is necessary in order to
; interact with low-level libraries.
;
  getvalues wid
    "wkGksWorkId" : gkswid
  end getvalues

;
; Call tdez2d to draw a surface plot.
;
  rho   =   3.0
  theta = -45.0
  phi   =  55.0

  tdez2d(gkswid, x, y, z, rho, theta, phi, 6)

  frame(wid) ; Advance the frame.
end
tdez3d.ncl:
begin

;
; Create some dummy data for the surface plot.
;
  NX = 21
  NY = 21
  NZ = 21

  xi = (/0.055483, 0.138127, 0.808924,-1.501205,-0.891079, 0.141545,\
         1.068575,-1.392315,-0.612384,-0.395337, 1.726188, 0.698080,\
        -0.443068, 1.307718, 1.916745, 1.833857, 1.120456,-1.887692,\
        -1.028046, 1.824213,-0.2324901/)

  yi = (/-1.297098, 1.790521,-1.094333,-1.664418,-0.527787, 1.062716,\
          1.120945, 0.501907, 1.668813, 0.427076, 1.479720, 1.033662,\
         -0.577471,-0.336375,-1.494247, 0.949919, 1.031587,-0.725059,\
          0.358226,-0.723472, 1.660146/)

  zi = (/-0.765465,-1.313089,-0.020937,-0.441481, 1.933836, 0.585894,\
          1.291848,-0.741295, 0.079043, 1.141697, 1.466170, 0.327586,\
         -1.199072,-0.145940,-1.149510,-0.363842, 1.827387, 1.027802,\
         -1.826411,-1.762566, 0.289010/) 

  wi = xi*xi + yi*yi + zi*zi

;
; Create the output grid.
;
  xmin = -2.0
  ymin = -2.0
  zmin = -2.0
  xmax =  2.0
  ymax =  2.0
  zmax =  2.0
  ii = fspan(0,20.,21)
  xo = xmin + (ii/(NX-1)) * (xmax-xmin)
  yo = ymin + (ii/(NY-1)) * (ymax-ymin)
  zo = zmin + (ii/(NZ-1)) * (zmax-zmin)

;
; Interpolate.
;
  wo = dsgrid3s(xi, yi, zi, wi, xo, yo, zo)

;
; Create an X workstation.
;
  wid = create "wks" ncgmWorkstationClass defaultapp end create

;
; Retrieve the GKS workstation id, which is necessary in order to
; interact with low-level libraries.
;
  getvalues wid
    "wkGksWorkId" : gkswid
  end getvalues

;
; Call tdez3d to draw a 3D plot.
;
  tdez3d(gkswid,xo,yo,zo,wo,3.,2.,-35.,65.,6)

  frame(wid) ; Advance the frame.
end
title.ncl:
begin  
; Create an App object.
  appid = create "title_app" appClass defaultapp end create

; Create an X Workstation object.
  wid   = create "example" xWorkstationClass appid end create

; Create a Title object.
  tid   = create "title" titleClass wid end create
 
  draw(tid)    ; Draw the title.
  frame(wid)   ; Advance the frame.
end
vector.ncl:
begin

;
; Generate vector data arrays.
;
  M=30
  N=30
  PI=3.14159

  U = 10.0 * sin(onedtond((2.0 * PI / N) * ispan(0,N-1,1),(/M,N/)))
  V = 10.0 * cos(onedtond((2.0 * PI / M) * ispan(0,M-1,1),(/N,M/)))

;
; Create an X workstation.
;
  wid = create "wks" xWorkstationClass defaultapp end create

;
; Create a data object.
;
  vfid = create "data" vectorFieldClass defaultapp
    "vfUDataArray" : U
    "vfVDataArray" : V
    "vfXCStartV"   : -90.0   ; minimum longitude value for overlay
    "vfXCEndV"     :  90.0   ; maximum longitude value for overlay
    "vfYCStartV"   : -45.0   ; minimum latitude value for overlay
    "vfYCEndV"     :  45.0   ; maximum latitude value for overlay
  end create

;
; Create a VectorPlot object.
;
  vcid = create "VectorPlot" vectorPlotClass wid
    "vcVectorFieldData" : vfid
  end create

;
; Create the default MapPlot object.
;
  mpid = create "MapPlot" mapPlotClass wid end create
  
  overlay(mpid,vcid) ; Overlay vector plot on map plot.
  draw(mpid)         ; Draw map plot (vector plot will be drawn too).
  frame(wid)         ; Advance frame.
end
xyplot1.ncl:
begin
;
; Create an X Workstation.
;
  wks = create "wks" xWorkstationClass defaultapp end create

;
; Create a data object.
;
  dataid = create "data" coordArraysClass defaultapp
    "caYArray" : (/1,3,-1,-2,0,2,3/)
  end create

;
; Create an XY plot.
;
  xy = create "xyplot" xyPlotClass wks
    "xyCoordData"  : dataid
  end create

;
; Retrieve xyCoordDataSpec.
;
  getvalues xy
    "xyCoordDataSpec" : dataspec
  end getvalues

;
; Set the desired resources using "setvalues" on the resource we
; just retrieved.
;
  setvalues dataspec
    "xyLineColor"      : 3     ; Change the line color to color index 3
                               ; (default is "1", the foreground color).
    "xyLineThicknessF" : 4.0   ; Quadruple the line thickness.
    "xyDashPattern"    : 2     ; Change the line to a dash pattern (default
                               ; is a solid line).
  end setvalues

  draw(xy)     ; Draw the XY plot.
  frame(wks)   ; Advance the frame.
end
xyplot2.ncl:
begin
;
; Create an X Workstation.
;
  wks = create "wks" xWorkstationClass defaultapp end create

;
; Create four data objects.
;
  dataid = new(4,graphic)

  do i=0,3
    dataid(i) = create "data" coordArraysClass defaultapp
      "caYArray" : i + sin(ispan(0,20,1)*3.14159/4.)
    end create
  end do

;
; Create an XY plot, passing the array of data objects just created.
;
  xy = create "xyplot" xyPlotClass wks
    "xyCoordData"  : dataid
  end create

;
; Retrieve xyCoordDataSpec (it will be an array of four elements, one
; for each data object created).
;
  getvalues xy
    "xyCoordDataSpec" : dataspec
  end getvalues

;
; Set the desired resources using "setvalues" on the resource we
; just retrieved.
;
  do i=0,3
    setvalues dataspec(i)
      "xyLineColor"      : i+1  ; Change the line color for each line.
      "xyLineThicknessF" : i+1  ; Change the line thickness for each line.
      "xyDashPattern"    : i    ; Change the dash pattern for each line.
    end setvalues
  end do

  draw(xy)     ; Draw the XY plot.
  frame(wks)   ; Advance the frame.
end

home | toc | about doc | intro | examples | basics | beyond basics | hints and tips | appendix | glossary