Line graphs & xy plots Line graphs are probably the most basic thing you can do in NCL. However as soon as you get in to any data processing, it gets a little more difficult. The NCL program below computes the root mean squared error of two different files. However, the second file in the program has 18 levels and the other has 17 levels. Therefore the file with 18 levels must be interpolated so the two files can be compared. Both files have been converted from a CCM history tape to a netCDFfile.

begin

; --------------------------------------------

; this file has 17 levels
; they are already at the desired pressure levels
;---------------------------------------------

rmse = new((/5,17/),float)

DATE1 = (/"dec96.nc","dec96.nc","dec96.nc","dec96.nc","dec96.nc"/)
DATE2 =(/"96-P-1.nc","96-P-2.nc","96-P-3.nc","96-P-4.nc","96-P-5.nc"/)
tGet = (/349.5,349.5,349.5,349.5,349.5/)
nDATE = dimsizes(DATE1)
do i=0, nDATE-1

time = a->time({tGet(i)})
date = a->date({tGet(i)})
lev = a->lev
hyam = a->hyam
hybm = a->hybm
P0mb = 0.01*a->P0
gw = a->gw

V = a->V({tGet(i)},:,:,:) ; Meridonial Wind Component
U = a->U({tGet(i)},:,:,:) ; Zonal Wind Component
T = a->T({tGet(i)},:,:,:) ;Temperature
PS = a->PS({tGet(i)},:,:) ;Surface Pressure

T = T - 273.15 ;convert Kelvin -> Celsius
T@units = "(C)" ; Change units to reflect

;--------------------------------------------

; desired pressure levels
;--------------------------------------------

lev_p = (/ lev /) ; use pressure levels from 1st file
lev_p@units = "hPa"
lev_p@positive = "down"
lev_p!0 = "lev_p"
lev_p&lev_p = lev_p

;--------------------------------------------

; vinth2p
;--------------------------------------------

interp = 1
extrap = False

;-------------------------------------------

; next file has 18 hybrid levels
;-------------------------------------------

btime = b->time(0)
bdate = b->date(0)
blev = b->lev
bhyam = b->hyam
bhybm = b->hybm
bP0mb = 0.01*b->P0
bU = b->U(0,:,:,:) ;Meridonial Wind Component
bU@_FillValue = 1.e+20
bPS = b->PS(0,:,:) ;Surface Pressure
BUonP = vinth2p(bU(lev|:,lat|:,lon|:),bhyam,bhybm,lev_p,bPS,interp \ ,bP0mb,1,extrap)
copy_VarAtts (bU, BUonP)
;-----------------calculate RMSE at each level--------------

rmse(i,:) = wgt_arearmse (BUonP, U, (gw/2.), 1.0, 0)
rmse@long_name = "Global RMSE"
rmse@units = BUonP@units
rmse!0 = "lev_p"
print(rmse)
end do

klev = dimsizes(lev)

;--------------------begin plotting--------------------------
xy = (/rmse/)
wks = gsn_open_wks("x11","compareLOOP")
res = True
res@trYReverse = True
getvalues wks
"wkColorMap" : cmap
end getvalues
cmap(0,:)= (/1.,1.,1./)
cmap(1,:)= (/0.,0.,0./)
gsn_define_colormap(wks, cmap)
res@trYLog = True ; change y-axis to log
res@trYMinF = lev_p(0) ; set max and mins
res@trYMaxF = lev_p(klev-1)
res@tmYLMode = "Explicit" ; Define tick mark labels.
res@tmYLValues = (/1000., 700., 500., 400., 300., \ 250., 200., 150., 100., 50., 10./)
res@tmYLLabels = (/"1000","700","500","400","300", \ "250","200","150","100", "50", "10"/)
res@tmYLMinorOn = False ; No minor tick marks.
res@tiMainString = ("U (m/s)")
res@xyLineColors = (/"yellow","green","blue","red","purple"/)
res@pmLegendDisplayMode = "Always" ;turn on legend
res@pmLegendZone = 0.3
res@pmLegendOrthogonalPosF = 0.63
res@lgJustification = "BottomRight"
res@LegendWidthF = 0.40
res@pmLegendHeightF = 0.11
res@pmLegendSide = "Top"
res@lgPerimOn = False
res@xyExplicitLegendLabels = (/""+DATE2(0),""+DATE2(1),""+DATE2(2),""+DATE2(3),""+DATE2(4)/)
plot = gsn_csm_xy(wks,xy,lev_p,res)
end