Appendices > A | B | C | D

The scripts and functions listed below are some of ones used in the old "Frequently asked questions" chapter of GSUN, 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

if(ncolors.gt.254)
print("Error: ncolors must be between 1 and 254 inclusive")
exit
else
label_stride = (ncolors/25)+1 ; Make sure we don't have too many labels
end if

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
"lbLabelStride"     : label_stride
"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
```
conmap.ncl:
```begin

path = ncargpath("data")
file1 = addfile(path+"/cdf/941110_UV.cdf","r")    ; open netCDF file
u = file1->u  ; read U and V
v = file1->v
spd = sqrt(u*u+v*v)             ; compute the wind speed

; Create an X11 window.

wks = create "x11" xWorkstationClass defaultapp
"wkColorMap"        : "temp1"    ; use a predefined color map
"wkForegroundColor" : "Black"
"wkBackgroundColor" : "White"
end create

lon = file1->lon   ; store lat/lon values to local variables
lat = file1->lat

; Create the data object needed by ContourPlot.

cndata = create "cndata" scalarFieldClass defaultapp
"sfDataArray": spd
"sfXCStartV" : lon(0)
"sfXCEndV"   : lon(dimsizes(lon)-1)
"sfYCStartV" : lat(0)
"sfYCEndV"   : lat(dimsizes(lat)-1)
end create

; Create the ContourPlot object and assign data to it

contour = create "cn_plot" contourPlotClass wks
"cnScalarFieldData" : cndata              ; assign the data object
"cnFillOn"          : True                ; turn on contour fill
"cnFillColors"      : ispan(2,63,4)       ; array of color indices
"cnLinesOn"         : False               ; turn off contour lines
"cnLineLabelsOn"    : False               ; turn off contour lines
"cnInfoLabelOrthogonalPosF" : 0.15
"cnInfoLabelFontHeightF"    : 0.013
"cnInfoLabelFont"           : "Helvetica"
end create

map = create "map" mapPlotClass wks
"mpGridAndLimbOn" : False           ; turn off grid lines
"vpXF"      : 0.1
"vpYF"      : 0.9
"vpWidthF"  : 0.8
"vpHeightF" : 0.8
end create

overlay(map,contour)   ; Overlay the contour plot on the map plot

getvalues map
"vpXF"         : vpxf    ; Retrieve viewport of map so that we
"vpYF"         : vpyf    ; can draw tickmarks in same location.
"vpWidthF"     : vpwf
"vpHeightF"    : vphf
end getvalues

tickmark = create "tickmarks" tickMarkClass wks
"vpXF"                    : vpxf
"vpYF"                    : vpyf
"vpHeightF"               : vphf
"vpWidthF"                : vpwf

"tmXBDataLeftF"           : lon(0)                ; Define the tick mark
"tmXBDataRightF"          : lon(dimsizes(lon)-1)  ; mins and maxes.
"tmYLDataBottomF"         : lat(0)
"tmYLDataTopF"            : lat(dimsizes(lat)-1)

"tmXBMode"                : "Explicit"
"tmXBLabels"              : (/"180W","120W","60W","0","60E","120E","180E"/)
"tmXBValues"              : (/-180.,-120.,-60.,0,60,120,180/)
"tmXBMinorOn"             : False
"tmXBLabelFont"           : "Helvetica"
"tmXBLabelFontHeightF"    : 0.016

"tmYLMode"                : "Explicit"
"tmYLLabels"              : (/"90S","60S","30S","0","30N","60N","90N"/)
"tmYLValues"              : (/-90, -60,-30,0,30,60,90/)
"tmYLMinorOn"             : False
"tmYLLabelFont"           : "Helvetica"
"tmYLLabelFontHeightF"    : 0.016

"tmXBMajorLengthF"        : 0.016  ; Make portion of outward tickmark
"tmXBMajorOutwardLengthF" : 0.016  ; the same length as whole tickmark
"tmYLMajorLengthF"        : 0.016  ; so that the whole tickmark is
"tmYLMajorOutwardLengthF" : 0.016  ; pointing outward.
end create

; Add the tick mark object as an annotation of the map object, so that
; whenever the map object is drawn the tick mark object will also be
; drawn.  It will also be rescaled automatically.

anno = NhlAddAnnotation(map,tickmark)
setvalues anno
"amZone"         : 0     ; Zone 0 centers tick marks over map.
"amResizeNotify" : True  ; Resize tick marks if map resized.
end setvalues

draw(map)    ; this call will draw the map, contours, and tickmarks
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_add_poly.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin
x  = new(64,float)
x  = ispan(1,64,1)       ; X points for first XY plot
y  = sin(3.14159*x/32.)  ; Y points for first XY plot

xx = (/1.,32.,64/)                ; X points for straight line
ytopline = (/ 0.5, 0.5, 0.5/)     ; Top line
ymidline = (/ 0.0, 0.0, 0.0/)     ; Middle line
ybotline = (/-0.5,-0.5,-0.5/)     ; Bottom line

xdots = x(26:36:5)     ; X and Y coordinates for polymarkers.
ydots = y(26:36:5)

xsquare = (/16.0,48.0,48.0,16.0,16.0/)    ; X and Y coordinates
ysquare = (/-0.5,-0.5, 0.5, 0.5,-0.5/)    ; for polygon.

wks = gsn_open_wks("ncgm","primitives")
gsn_define_colormap(wks,(/"white","black","blue","hotpink",\
"yellow","green"/))

xyres = True
xyres@gsnDraw  = False
xyres@gsnFrame = False
xy1 = gsn_xy(wks,x,y,xyres)   ; Create XY plot, don't draw it or
; advance the frame.
gsres = True
gsres@gsEdgesOn         = True    ; Line will be drawn around polygon.
gsres@gsEdgeDashPattern = 2       ; Make this line dashed.
gsres@gsLineColor       = "Blue"
gsres@gsMarkerColor     = "HotPink"
gsres@gsFillColor       = "Yellow"

gsres@gsMarkerIndex     = 16       ; dots
gsres@gsMarkerSizeF     = 0.014    ; twice normal size
gsres@gsLineThicknessF  = 3.0      ; thrice thickness

;
; Add primitives to plot.  They will be drawn in the order
; they are added, so some primitives may cover other ones.
;
prim1 = gsn_add_polyline(wks,xy1,xx,ymidline,gsres)
prim2 = gsn_add_polygon(wks,xy1,xsquare,ysquare,gsres)
prim3 = gsn_add_polyline(wks,xy1,xx,ytopline,gsres)
prim4 = gsn_add_polyline(wks,xy1,xx,ybotline,gsres)

gsres@gsLineColor      = "Green"
prim5 = gsn_add_polyline(wks,xy1,x(26:36),y(26:36),gsres)
prim6 = gsn_add_polymarker(wks,xy1,xdots,ydots,gsres)

;
; New Y points for second XY plot.
;
y  = cos(3.14159*x/32.)

xy2 = gsn_xy(wks,x,y,xyres)   ; Create but don't draw XY plot.

;
; Add primitives to second plot.
;
gsres@gsLineColor      = "Blue"

prim7 = gsn_add_polyline(wks,xy2,xx,ymidline,gsres)
prim8 = gsn_add_polygon(wks,xy2,xsquare,ysquare,gsres)
prim9 = gsn_add_polyline(wks,xy2,xx,ytopline,gsres)
prim10 = gsn_add_polyline(wks,xy2,xx,ybotline,gsres)

gsres@gsLineColor      = "Green"

xdots2 = x(15:20:5)
ydots2 = y(15:20:5)
prim11 = gsn_add_polyline(wks,xy2,x(15:20),y(15:20),gsres)
prim12 = gsn_add_polymarker(wks,xy2,xdots2,ydots2,gsres)

xdots2 = x(42:47:5)
ydots2 = y(42:47:5)
prim13 = gsn_add_polyline(wks,xy2,x(42:47),y(42:47),gsres)
prim14 = gsn_add_polymarker(wks,xy2,xdots2,ydots2,gsres)

;
; Put these two plots on the same frame.
;
gsn_panel(wks,(/xy1,xy2/),(/2,1/),False)
end
```
gsn_add_text.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin
PI = 3.14159
x  = new(64,float)
x  = ispan(1,64,1)       ; X points for both XY plots
y1 = sin(PI*x/32.)  ; Y points for first XY plot
y2 = cos(PI*x/32.)  ; Y points for first XY plot
wks = gsn_open_wks("ncgm","gsn_add_text")
gsn_define_colormap(wks,(/"white","black","blue","hotpink",\
"yellow","green"/))

xyres = True
xyres@gsnDraw  = False
xyres@gsnFrame = False
xy1 = gsn_xy(wks,x,y1,xyres)  ; Create 2 XY plots; don't draw them
xy2 = gsn_xy(wks,x,y2,xyres)  ; advance the frame.

txres = True
txres@txFont            = "Helvetica-bold"  ; change the font
;
; Add text to first plot.
;
txres@txFontColor       = "blue"      ; change the font color
anno = gsn_add_text(wks,xy1,"this is a",20.,0.3,txres)

;
; Add text to second plot.
;
txres@txFontColor       = "green"     ; change the font color
anno = gsn_add_text(wks,xy2,"text string",10.,0.0,txres)

;
; Panel the plots.
;
gsn_panel(wks,(/xy1,xy2/),(/2,1/),False)
end
```
gsn_attach_plots.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin
;
; Read in some data.
;
datadir  = "\$NCARG_ROOT/lib/ncarg/data/asc/"
datafile = "u.cocos"
data = asciiread(datadir + datafile,(/39,14/),"float")
;
; Open a workstation.
;
wks = gsn_open_wks("ncgm","attach")

pressure  = data(:,0)    ; First column of data is pressure (mb).
u         = data(:,2:13) ; Rest of columns are climatological zonal winds

xyres           = True
xyres@vpWidthF  = 0.8
xyres@vpHeightF = 0.4
xyres@gsnDraw   = False
xyres@gsnFrame  = False
;
; Create three XY plots.
;
xy1 = gsn_xy(wks,ispan(0,12,1),u(0,:),xyres)
xy2 = gsn_xy(wks,ispan(0,12,1),u(1,:),xyres)
xy3 = gsn_xy(wks,ispan(0,12,1),u(2,:),xyres)

;
; Attach these plots, by first attaching plot 3 to plot 2, and then
; by attaching the new plot 2 to plot1.
;
; Make sure the variable returned by gsn_attach_plots is unique
; every time.
;
res2                     = True
res2@gsnAttachPlotsXAxis = True
anno1 = gsn_attach_plots(xy2,xy3,False,res2)
anno2 = gsn_attach_plots(xy1,xy2,False,res2)

draw(xy1)     ; Draw attached plots.
frame(wks)    ; Advance the frame.
end
```
gsn_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 "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.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

if(ncolors.gt.254)
print("Error: ncolors must be between 1 and 254 inclusive")
exit
else
label_stride = (ncolors/25)+1 ; Make sure we don't have too many labels
end if

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 = gsn_open_wks("x11","gsn_color")
gsn_define_colormap(wks,cmap)      ; Set the color map.

;
; Define some labelbar resources.
;
lbres                   = True
lbres@vpWidthF          = 0.97
lbres@vpHeightF         = 0.97
lbres@lbLabelStride     = label_stride
lbres@lbFillColors      = ispan(0,ncolors+1,1)
lbres@lbMonoFillPattern = True
lbres@lbPerimOn         = False
lbres@lbTitleFontHeightF= 0.02
lbres@lbLabelFontHeightF= 0.015
lbres@lbAutoManage      = False
lbres@lbTitleString     = ":F22:ncolors = " + ncolors + \
" :C:hue (" + beg_hue + "," + end_hue + \
"):C:sat (" + beg_sat + "," + end_sat + \
"):C:val (" + beg_val + "," + end_val + ")"

labels = ":F26:Color " + ispan(0,ncolors+1,1)

gsn_labelbar_ndc(wks,ncolors+2,labels,0.10,0.98,lbres)  ; Draw a labelbar

frame(wks)  ; Advance the frame.
end
```
gsn_conmap.ncl:
```;
; This example shows how to create a polar stereographic plot with
; the lat/lon grid labeled.
;
load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "gsn_csm.ncl"

begin

path = ncargpath("data")
file1 = addfile(path+"/cdf/941110_UV.cdf","r")    ; open netCDF file
u = file1->u  ; read U and V
v = file1->v
spd = sqrt(u*u+v*v)             ; compute the wind speed
spd!0   = "lat"
spd!1   = "lon"
spd&lat = file1->lat
spd&lon = file1->lon

type = "x11"
type@wkColorMap        = "temp1"

wks = gsn_open_wks(type,"gsn_conmap")

cnres                           = True
cnres@gsnAddCyclic              = False         ; Don't add a cyclic point.
cnres@cnFillOn                  = True          ; turn on contour fill
cnres@cnFillColors              = ispan(2,63,4) ; array of color indices
cnres@cnLinesOn                 = False         ; turn off contour lines
cnres@cnLineLabelsOn            = False         ; turn off contour lines

contour= gsn_csm_contour_map(wks,spd,cnres)
end
```
gsn_draw_colormap.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin
wks = gsn_open_wks("ncgm","gsn_draw_colormap")
gsn_draw_colormap(wks)   ; Draw the default colormap

gsn_define_colormap(wks,"hotres")   ; Change color map and
gsn_draw_colormap(wks)              ; draw it.

end
```
gsn_fillcon.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.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.
;
wks = gsn_open_wks("x11","gsn_fillcon")   ; Open an X11 workstation.

cnres = True

cnres@cnFillOn          = True   ; Turn on contour level fill.
cnres@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."
;
cnres@cnFillPatterns    = (/0, 2, 3, 0, 6, 8,10,-1, 9, 0,11,12,17,16/)
cnres@cnFillColors      = (/1,10,14, 8, 4, 2, 9, 1,12, 3, 1,13, 5, 7/)

contour = gsn_contour(wks,T,cnres)
end
```
gsn_font.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

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

y = (/1,3,-1,-2,0,2,3/)
x = ispan(0,dimsizes(y)-1,1)

xyres = True
xyres@tiMainString  = "This is an XY plot"
xyres@tiXAxisString = "X values"
xyres@tiYAxisString = "Y values"

xy = gsn_xy(wks,x,y,xyres)   ; Create and draw an XY plot.

end
```
gsn_labelbar.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.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.

;
; Set up variable to hold four contour plots.
;
contour = new(4,graphic)

wks = gsn_open_wks("ncgm","gsn_labelbar")   ; Open an X11 workstation.
gsn_define_colormap(wks,cmap)

;
; Set up contour resources.
;
cnres                      = True

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

cnres@cnFillOn             = True            ; Turn on fill.
cnres@cnLineLabelsOn       = False           ; Turn off line labels.
cnres@cnInfoLabelOn        = False           ; Turn off info label.
cnres@cnLowLabelsOn        = False           ; Turn off low label.
cnres@cnHighLabelsOn       = False           ; Turn off high label.

cnres@gsnDraw              = False           ; Don't draw the plot.
cnres@gsnFrame             = False           ; Don't advance frame.

contour(0) = gsn_contour(wks,cfile->Z(0,3,:,:),cnres)
contour(1) = gsn_contour(wks,cfile->Z(1,3,:,:),cnres)
contour(2) = gsn_contour(wks,cfile->Z(2,3,:,:),cnres)
contour(3) = gsn_contour(wks,cfile->Z(3,3,:,:),cnres)
;
; Turn on a common labelbar, and panel the plots.
;
panelres = True
panelres@gsnPanelLabelBar = True
panelres@lbLabelStride    = 2
gsn_panel(wks,contour,(/2,2/),panelres)
end
```
gsn_labelbar_ndc.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin
wks = gsn_open_wks("x11","gsn_labelbar_ndc")   ; 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_logcon1.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.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)

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

cnres = True
cnres@sfYCStartV    = 10
cnres@sfYCEndV      = 1000
cnres@tiXAxisString = "linear"   ; Label for X axis.
cnres@tiYAxisString = "linear"   ; Label for Y axis.

contour = gsn_contour(wks,T,cnres)  ; Create and draw contour plot.

cnres@tiYAxisString = "log"    ; Label for Y axis.
cnres@trYLog        = True     ; Log scaling for Y axis

contour = gsn_contour(wks,T,cnres)  ; Create and draw contour plot.

end
```
gsn_logcon2.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.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)

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

;
; 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/)

cnres = True
cnres@sfYArray      = y
cnres@tiXAxisString = "linear"              ; Label for X axis.
cnres@tiYAxisString = "irregularly spaced"  ; Label for Y axis.

contour = gsn_contour(wks,T,cnres)  ; Create and draw contour plot.

cnres@gsnYAxisIrregular2Log = True    ; Force irregular axis to be log.
cnres@tiYAxisString         = "log"   ; Label for Y axis.

contour = gsn_contour(wks,T,cnres)  ; Create and draw contour plot.

end
```
gsn_logxy.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin

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

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

xyres = True
xyres@tiXAxisString = "linear"
xyres@tiYAxisString = "linear"

xyplot = gsn_xy(wks,x,y,xyres)  ; Create and draw the XY plot.

;
; Change the Y axis scale to be log and redraw the plot.
;
xyres@trYLog        = True
xyres@tiYAxisString = "log"
xyres@xyComputeYMin = True   ; To keep from getting some warning msgs.

xyplot = gsn_xy(wks,x,y,xyres)  ; Create and draw the XY plot.
end
```
gsn_map.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin
wks = gsn_open_wks("x11","gsn_map")   ; 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_map2.ncl:
```;
; This example shows how to create a polar stereographic plot with
; the lat/lon grid labeled.
;
load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "gsn_csm.ncl"

begin

wks = gsn_open_wks("ncgm","gsn_map2")

mpres                       = True
mpres@mpCenterLonF          = -90.0   ; Change center of projection
mpres@vpXF                  = 0.10    ; Change the location and
mpres@vpYF                  = 0.90    ; the width and height
mpres@vpWidthF              = 0.78    ; of the map.
mpres@vpHeightF             = 0.78
mpres@gsnPolar              = "NH"
map  = gsn_csm_map_polar(wks,mpres)

end
```
gsn_merge_colormaps.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin
wks = gsn_open_wks("ncgm","gsn_merge_colormaps")
;
; Merge two pre-defined colormaps;
;
gsn_merge_colormaps(wks,"rainbow","gsdtol")
gsn_draw_colormap(wks)

;
; Generate grayscale color map.
;
gcmap = new((/11,3/),float)
gcmap(:,0) = ispan(0,10,1)/10.
gcmap(:,1) = gcmap(:,0)
gcmap(:,2) = gcmap(:,0)
;
; Append grayscale map to the end of a Blue-White-Red color map.
;
gsn_merge_colormaps(wks,"BlWhRe",gcmap)
gsn_draw_colormap(wks)
end
```
gsn_misscon.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.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 /)/)

T@_FillValue = 999    ; Set _FillValue.

wks = gsn_open_wks("x11","misscon")   ; Open an X11 workstation.
contour = gsn_contour(wks,T,False)    ; Draw a contour plot.
end
```
gsn_missxy.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

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

y = (/1,3,-1,-2,0,2,3,0,5,-2,1,0,0,8,10,5,-3/)

y@_FillValue = 0               ; Set the missing value.

x = ispan(0,dimsizes(y)-1,1)   ; Generate some x values.

xy = gsn_xy(wks,x,y,False)     ; Create and draw an XY plot.
end
```
gsn_open_wks.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin
wks = gsn_open_wks("x11","gsn_open_wks")   ; Open a X11 window.

gsn_text_ndc(wks,":F21:Nothing too exciting here",0.5,0.5,False) ; Draw text.
frame(wks)  ; Advance frame
end
```
gsn_overlay1.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.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)

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

cnres             = True
cnres@sfXCStartV  = -90.0   ; minimum longitude value for overlay
cnres@sfXCEndV    =  90.0   ; maximum longitude value for overlay
cnres@sfYCStartV  = -45.0   ; minimum latitude value for overlay
cnres@sfYCEndV    =  45.0   ; maximum latitude value for overlay

contour_map = gsn_contour_map(wks,T,cnres) ; Draw contour over map.

end
```
gsn_overlay2.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.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)

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

mpres          = True
mpres@gsnFrame = False  ; Don't advance the frame when map is drawn.

map = gsn_map(wks,"CylindricalEquidistant",mpres)  ; Draw map.

;
; Retrieve the viewport coordinates used in the map plot so they
; can be used in the contour plot.
;
getvalues map
"vpXF"       : xpos
"vpYF"       : ypos
"vpWidthF"   : width
"vpHeightF"  : height
end getvalues
;
; Create a Contour plot using the same viewport coordinates as
; the map plot.
;
cnres            = True
cnres@vpXF       = xpos
cnres@vpYF       = ypos
cnres@vpWidthF   = width
cnres@vpHeightF  = height
contour = gsn_contour(wks,T,cnres)
end
```
gsn_panel.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/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 "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
begin
wks = gsn_open_wks("x11","gsn_polygon")    ; 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 "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
begin
wks = gsn_open_wks("x11","gsn_polygon_ndc")    ; 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 "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
begin
wks = gsn_open_wks("x11","gsn_polymarker") ; 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 "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin
wks = gsn_open_wks("ncgm","gsn_polymarker_ndc")  ; 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_ps.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin

type = "ps"
type@wkDeviceLowerX = -75   ; These coordinates can be negative.
type@wkDeviceLowerY = -50
type@wkDeviceUpperX = 750
type@wkDeviceUpperY = 950

wks = gsn_open_wks(type,"gsn_ps")

;
; Create the default TickMark object.  There is no GSUN equivalent for
; just creating a tickmark object, so use the regular NCL way here.
;
tmid = create "ticks" tickMarkClass wks end create

draw(tmid)  ; Draw the TickMark object.
frame(wks)  ; Advance the frame.
end
```
gsn_retrieve_colormap.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin
wks = gsn_open_wks("ncgm","colors")
cmap = gsn_retrieve_colormap(wks)
print(cmap)
end
```
gsn_stream.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.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/)))

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

stres              = True
stres@vfXCStartV   = -90.0   ; minimum longitude value for overlay
stres@vfXCEndV     =  90.0   ; maximum longitude value for overlay
stres@vfYCStartV   = -45.0   ; minimum latitude value for overlay
stres@vfYCEndV     =  45.0   ; maximum latitude value for overlay

stream = gsn_streamline_map(wks,U,V,stres)   ; Draw streamlines over a map.
end
```
gsn_vector.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.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/)))

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

vcres              = True
vcres@vfXCStartV   = -90.0   ; minimum longitude value for overlay
vcres@vfXCEndV     =  90.0   ; maximum longitude value for overlay
vcres@vfYCStartV   = -45.0   ; minimum latitude value for overlay
vcres@vfYCEndV     =  45.0   ; maximum latitude value for overlay

vector = gsn_vector_map(wks,U,V,vcres)   ; Draw vectors over a map.

end
```
gsn_xyplot1.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

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

y = (/1,3,-1,-2,0,2,3/)
x = ispan(0,dimsizes(y)-1,1)

xyres = True
xyres@xyLineColor      = 3     ; Change the line color to color index 3
; (default is 1, the foreground color).
xyres@xyLineThicknessF = 4.0   ; Quadruple the line thickness.
xyres@xyDashPattern    = 2     ; Change the line to a dash pattern (default
; is 0, a solid line).
xy = gsn_xy(wks,x,y,xyres)
end
```
gsn_xyplot2.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin
wks = gsn_open_wks("x11","gsn_xyplot2")   ; Open an X11 workstation.
;
; Create four data sets.
;
y = new((/4,21/),float)
x = ispan(0,20,1)

pi4 = 3.14159/4.

do i=0,3
y(i,:) = i + sin(x*pi4)
end do

xyres = True
xyres@xyLineColors      = (/1,2,3,4/)     ; Change the line color and
xyres@xyLineThicknesses = (/1.,2.,3.,4./) ; thickness for each line.

xy = gsn_xy(wks,x,y,xyres)
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 "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.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/nclscripts/csm/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.
;
; Set up some labelbar resources.  Set gsnPanelLabelBar to True to
; indicate you want to draw a common labelbar at the bottom of the
; plots. Set gsnPanelFigureStrings to some strings you want to use
; to label the lower righthand corner of each plot.
;
panelres@gsnPanelFigureStrings = (/"(a)","(b)","(c)","(d)","(e)","(f)"/)
panelres@gsnPanelLabelBar   = True
panelres@lbLabelFont        = "helvetica-bold" ; Labelbar font
panelres@lbLabelStride      = 2                ; Draw every other label
panelres@lbLabelFontHeightF = 0.015            ; Labelbar font height
panelres@vpHeightF          = 0.15             ; Height of labelbar
panelres@vpWidthF           = 0.7              ; Width of labelbar
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)

frame(wks)   ; Advance the frame.
end

```
panel2.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin
wks  = gsn_open_wks("ncgm","panel")

res = True
res@gsnDraw         = False
res@gsnFrame        = False
res@mpGridAndLimbOn = False
res@mpOutlineOn     = False
res@mpPerimOn       = True
res@mpPerimLineThicknessF   = 2.0

map = new(10,graphic)
map(0) = gsn_map(wks,"CylindricalEquidistant",res)

do i=1,dimsizes(map)-1
map(i) = map(0)
end do

res = True
res@gsnFrame        = False
gsn_panel(wks,map(0:5),(/3,2/),res)
gsn_text_ndc(wks,":F21:dims = 3 x 2, 6 plots",0.5,0.95,False)
gsn_text_ndc(wks,":F21:1",0.25,0.75,False)
gsn_text_ndc(wks,":F21:2",0.75,0.75,False)
gsn_text_ndc(wks,":F21:3",0.25,0.50,False)
gsn_text_ndc(wks,":F21:4",0.75,0.50,False)
gsn_text_ndc(wks,":F21:5",0.25,0.25,False)
gsn_text_ndc(wks,":F21:6",0.75,0.25,False)
frame(wks)

gsn_panel(wks,map(0:5),(/2,3/),res)
gsn_text_ndc(wks,":F21:dims = 2 x 3, 6 plots",0.5,0.95,False)
gsn_text_ndc(wks,":F21:1",0.15,0.58,False)
gsn_text_ndc(wks,":F21:2",0.50,0.58,False)
gsn_text_ndc(wks,":F21:3",0.83,0.58,False)
gsn_text_ndc(wks,":F21:4",0.15,0.42,False)
gsn_text_ndc(wks,":F21:5",0.50,0.42,False)
gsn_text_ndc(wks,":F21:6",0.83,0.42,False)
frame(wks)

gsn_panel(wks,map(0:4),(/3,2/),res)
gsn_text_ndc(wks,":F21:dims = 3 x 2, 5 plots",0.5,0.95,False)
gsn_text_ndc(wks,":F21:1",0.25,0.75,False)
gsn_text_ndc(wks,":F21:2",0.75,0.75,False)
gsn_text_ndc(wks,":F21:3",0.25,0.50,False)
gsn_text_ndc(wks,":F21:4",0.75,0.50,False)
gsn_text_ndc(wks,":F21:5",0.50,0.25,False)
frame(wks)

gsn_panel(wks,map(0:6),(/3,3/),res)
gsn_text_ndc(wks,":F21:dims = 3 x 3, 7 plots",0.5,0.95,False)
gsn_text_ndc(wks,":F21:1",0.15,0.67,False)
gsn_text_ndc(wks,":F21:2",0.50,0.67,False)
gsn_text_ndc(wks,":F21:3",0.83,0.67,False)
gsn_text_ndc(wks,":F21:4",0.15,0.51,False)
gsn_text_ndc(wks,":F21:5",0.50,0.51,False)
gsn_text_ndc(wks,":F21:6",0.83,0.51,False)
gsn_text_ndc(wks,":F21:7",0.50,0.34,False)
frame(wks)

gsn_panel(wks,map(0:7),(/3,3/),res)
gsn_text_ndc(wks,":F21:dims = 3 x 3, 8 plots",0.5,0.95,False)
gsn_text_ndc(wks,":F21:1",0.15,0.67,False)
gsn_text_ndc(wks,":F21:2",0.50,0.67,False)
gsn_text_ndc(wks,":F21:3",0.83,0.67,False)
gsn_text_ndc(wks,":F21:4",0.15,0.51,False)
gsn_text_ndc(wks,":F21:5",0.50,0.51,False)
gsn_text_ndc(wks,":F21:6",0.83,0.51,False)
gsn_text_ndc(wks,":F21:7",0.33,0.34,False)
gsn_text_ndc(wks,":F21:8",0.67,0.34,False)
frame(wks)

res@gsnPanelRowSpec = True
gsn_panel(wks,map(0:8),(/1,2,3,2,1/),res)
txres = True
txres@txFontHeightF = 0.025
gsn_text_ndc(wks,":F21:gsnPanelRowSpec=True, dims = (1,2,3,2,1), 9 plots",\
0.5,0.95,txres)
gsn_text_ndc(wks,":F21:1",0.50,0.85,False)

gsn_text_ndc(wks,":F21:2",0.33,0.67,False)
gsn_text_ndc(wks,":F21:3",0.67,0.67,False)

gsn_text_ndc(wks,":F21:4",0.15,0.51,False)
gsn_text_ndc(wks,":F21:5",0.50,0.51,False)
gsn_text_ndc(wks,":F21:6",0.83,0.51,False)

gsn_text_ndc(wks,":F21:7",0.33,0.34,False)
gsn_text_ndc(wks,":F21:8",0.67,0.34,False)
gsn_text_ndc(wks,":F21:9",0.50,0.17,False)
frame(wks)
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
```
spread_colors.ncl:
```load "\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin

cdf_file = addfile("\$NCARG_ROOT/lib/ncarg/data/cdf/contour.cdf","r")

Z    = cdf_file->Z(0,0,:,:)           ; geopotential height

wks = gsn_open_wks("ncgm","spread_colors")   ; Open an X11 workstation.

gsn_define_colormap(wks,"temp1")      ; Use a rainbow color map that
; has 63 colors and goes from
; gray to blue to red.
cnres                       = True
cnres@cnFillOn              = True   ; Turn on contour fill.
cnres@pmLabelBarDisplayMode = True   ; Turn on labelbar.
cnres@lbPerimOn             = False  ; Turn off labelbar perimeter.

plot = gsn_contour(wks,Z,cnres)  ; Draw a filled contour plot.  Note
; that the contour colors are mostly
; blue.

cnres@gsnSpreadColors = True     ; Choose colors across whole color map.
plot = gsn_contour(wks,Z,cnres)  ; Draw a filled contour plot.  Note
; that the contour colors now span
; from gray to blue to red.
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
```