;***这两行指令必须加载,类似于c语言中的库函数
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
begin ;开始标志
a = addfile("/home/yuanm/surface.nc","r") ;文件读取
; 绘图类型(依次为,窗口显示,pdf,ps,ncgm格式)
type = "x11"
; type = "pdf"
; type = "ps"
; type = "ncgm"
wks = gsn_open_wks(type,"ECMWF_surface") ;创建工作空间
; 时间维数(如该例子中,只有00,08,16,24四个时间段)
times = a->time ; 箭头表示数据a中的时间向量
ntimes = dimsizes(times) ; 时间维数
;循环结构
do it = 0,(ntimes-1),1
msl1 = a->msl(it,:,:) ; mean sea level pressure
t2m1 = a->t2m(it,:,:) ; temperature at 2m
u101 = a->u10(it,:,:) ; 10 metre U wind component
v101 = a->v10(it,:,:) ; 10 metre V wind component
msl = short2flt(msl1) ;数据类型转换
msl = smth9(msl,0.50,0.25,False) ;平滑
t2m = short2flt(t2m1)
t2m = smth9(t2m,0.50,0.25,False)
t2m = t2m-273.15
u10 = short2flt(u101)
v10 = short2flt(v101)
msl = msl/100.
msl@units="hPa"
;绘图参数控制
res = True
res@gsnDraw = False ;为调整绘制顺序,让该图暂时不画出来
res@gsnFrame = False
; res@gsnMaximize = True ; Maximize plot in frame
; Add map resources
; res@mpGridAndLimbOn = True ; Turn off lat/lon lines
; res@mpGridLineColor = "gray"
res@mpGeophysicalLineColor = "gray"
res@pmTickMarkDisplayMode = "Conditional" ; Turn on map tickmarks
res@mpMaxLonF = 180. ;经度最大值
res@mpMinLonF = 100.
res@mpMaxLatF = 50.
res@mpMinLatF = -10.
res@mpFillOn = False
; 温度场绘图
res2 = True
res2 = res
res2@cnFillOn = True
res2@cnLinesOn = False
res2@cnInfoLabelOn = False
res2@cnLevelSelectionMode = "ManualLevels"
res2@cnMinLevelValF = 0.0
res2@cnMaxLevelValF = 40.0
res2@cnLevelSpacingF = 2.0
res2@gsnLeftString =" "
res2@gsnRightString = " "
map1 = gsn_csm_contour_map(wks,t2m,res2)
draw(map1)
delete(res2)
; Set some contouring resources.
res1 = True
res1 = res
res1@cnFillOn = False
res1@cnLineLabelsOn = True
; res1@cnLineLabelFontAspectF = 0.6
res1@cnLineLabelFontColor = "blue"
res1@cnLineLabelPerimOn = False
res1@cnLineLabelPlacementMode = "Constant"
; res1@cnLineLabelConstantSpacingF = 1.0
res1@cnLineLabelInterval = 1.0
; res1@cnLineDashSegLenF = 0.20
res1@cnInfoLabelOn = False
; res1@cnLevelSelectionMode = "ExplicitLevels"
; res1@cnLevels = (/5800.,5840.,5850.,5860.,5870.,5880.,5890.,5900./)
res1@cnLevelSpacingF = 2.0
; res1@cnHighLabelsOn = True
; res1@cnHighLabelString = "H"
res1@cnHighLabelBackgroundColor = -1
res1@cnHighLabelFontColor = "blue"
; res1@cnHighLabelFontAspectF = 5.0
; res1@cnLowLabelsOn = True
; res1@cnLowLabelString = "L"
res1@cnLowLabelBackgroundColor = -1
res1@cnLowLabelFontColor = "red"
res1@cnLowLabelFontAspectF = 2.0
res1@cnLineColor = "Blue"
res1@gsnContourLineThicknessesScale = 3.0
res1@gsnLeftString = ""
res1@gsnRightString = ""
map = gsn_csm_contour_map(wks,msl, res1)
draw(map)
delete(res1)
;create vector plot
res3 = True
res3 = res
res3@vcRefMagnitudeF= 20.0
res3@vcRefLengthF= 0.05
res3@vcMinDistanceF= 0.03
res3@vcGlyphStyle= "CurlyVector"
res3@vcRefAnnoOn = True ;do not draw reference vector annotation
res3@vcRefAnnoOrthogonalPosF = -0.15 ; vertical position
res3@vcRefAnnoParallelPosF = 0.98
res3@vcLineArrowThicknessF = 2.0
res3@gsnDraw = False
res3@gsnFrame = False
res3@gsnLeftString = " "
res3@gsnRightString = " "
map2= gsn_csm_vector_map(wks,u10,v10,res3)
draw(map2)
delete(res3)
frame(wks)
end do
end
注:
grib资料与ncl资料大同小异,都是先提取变量,然后做数据处理。
变量查看指令:ncl_filedump "资料名“(如"surface.nal")
然后根据所查看到的变量信息提取变量。