load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
begin
cdf_file = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/contour.cdf","r")
temp = cdf_file->T(0,0,:,:) ; 变量temperature
Z = cdf_file->Z(0,0,:,:) ; 变量geopotential height
pres = cdf_file->Psl(0,:,:) ; 变量pressure at mean sea level
lat = cdf_file->lat ; 变量latitude
lon = cdf_file->lon ; 变量longitude
temp = temp - 273.15 ; 温度转换 Kelvin -> Celsius
pres = pres * 0.01 ; 气压转换 Pa -> mb
temp@units = "(C)" ; 改变单位
pres@units = "(mb)" ; 改变单位
xwks = gsn_open_wks("x11","gsun02n") ; 打开x11的工作空间.
plot = gsn_contour(xwks,temp,False) ; 绘制一个等值线图
;----------- Begin second plot -----------------------------------------
resources = True ; 资源设置
resources@cnMonoLineColor = False ; 关闭绘制一种颜色的方案
resources@tiMainString = "Temperature (C)" ; 标题
plot = gsn_contour(xwks,temp,resources) ; 绘制等值线图
;----------- Begin third plot -----------------------------------------
resources@cnFillOn = True ; 打开等值线图填充
resources@cnMonoFillPattern = False ; 关闭等值线图单线填充
resources@cnMonoFillColor = True
resources@cnMonoLineColor = True
resources@tiXAxisString = lon@long_name
resources@tiYAxisString = lat@long_name
resources@sfXArray = lon
resources@sfYArray = lat
plot = gsn_contour(xwks,temp,resources) ; 绘制等值线图
;---------- Begin fourth plot ------------------------------------------
resources@cnMonoFillPattern = True ; 使用solid填充
resources@cnMonoFillColor = False ; 使用复杂颜色
resources@cnLineLabelsOn = False ; 线条标签
resources@cnInfoLabelOn = False ; 信息标签
resources@cnLinesOn = False ; 等值线
resources@pmLabelBarDisplayMode = "Always" ; 工具栏
resources@lbPerimOn = False ; 关闭周长
resources@tiMainString = Z@long_name
resources@tiMainFont = 26
resources@tiXAxisFont = 26
resources@tiYAxisFont = 26
plot = gsn_contour(xwks,Z,resources) ; 绘制等值线图
;---------- Begin fifth plot ------------------------------------------
cmap = (/(/0.,0.,0./),(/1.,1.,1./),(/.1,.1,.1/),(/.15,.15,.15/),\
(/.2,.2,.2/),(/.25,.25,.25/),(/.3,.3,.3/),(/.35,.35,.35/),\
(/.4,.4,.4/),(/.45,.45,.45/),(/.5,.5,.5/),(/.55,.55,.55/),\
(/.6,.6,.6/),(/.65,.65,.65/),(/.7,.7,.7/),(/.75,.75,.75/),\
(/.8,.8,.8/),(/.85,.85,.85/)/)
gsn_define_colormap(xwks,cmap) ; 定义一个新的颜色map
resources@tiMainString = pres@long_name
plot = gsn_contour(xwks,pres,resources) ; 绘制一个等值线图
print(temp(2:5,7:9)) ;输出temp变量
print(temp!0) ; 输出temp的一维名称
print(temp!1) ; 输出temp的二维名称
print(temp@long_name) ; 输出属性long_name和units
print(temp@units)
print(temp&lat) ; 输出变量lat
print(temp&lon) ; 输出变量lon
ascii_file = "data.asc" ;创建ASC11文件名
system("/bin/rm -f " + ascii_file) ; 移除asc11文件
asciiwrite(ascii_file,temp(7:3:2,0:4)) ; 写入ASC11
delete(plot) ;清除
delete(temp)
delete(resources)
end