这是是官方代码官网zonal_4.ncl代码
出现的问题:
atmos.nc打不开
解决方法:由于atmos.nc文件缺失导致的,
去官网这个地方Data files for some of the NCL examples (ucar.edu)找到所需要的文件下载即可
下载的所需文件一定要与ncl在同一个文件夹下,否则要写清楚路径
运行成功但是没有出来图像,生成了png类型的文件,可以去文件夹里找到
要是想直接看到画出的结果可以将官方代码中的
wks = gsn_open_wks("png","zonal")替换为了
wks = gsn_open_wks("x11","zonal")
;*************************************************
; zonal_4.ncl
;
; Concepts illustrated:
; - Drawing a zonal means plot
; - Customzing the axes of a zonal means plot
;************************************************
;
; These files are loaded by default in NCL V6.2.0 and newer
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
;************************************************
begin
;************************************************
; variable and file handling
;************************************************
in = addfile("atmos.nc","r")
T = in->T ; select variable to ave
;************************************************
; calculate zonal average of 3d variable
;************************************************
zave = dim_avg_Wrap(T) ; calculate zonal ave
;************************************************
; calculate eta
;************************************************
a=in->hyam ; select hyam
b=in->hybm ; select hybm
p=in->P0 ; select P0
eta = (a+b)*p ; calc eta
eta = eta/100 ; scale eta by 100
;************************************************
; plotting
;************************************************
wks = gsn_open_wks("x11","zonal") ; send graphics to PNG file
res = True
res@tiXAxisString = "latitude" ; x-axis label
res@tiYAxisString = "eta x 1000" ; y-axis label
res@sfXArray = zave&lat ; put lat on x axis
res@sfYArray = eta ; put eta on y axis
res@trYReverse = True ; reverses y axis
res@trXReverse = True ; reverse X axis
plot=gsn_contour(wks,zave(0,:,:),res) ; plot zonal ave
;***********************************************
end
运行成功