;********************************************************
; Load NCL scripts
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
fiTY = "bwp142005.txt"
; 获取文本文件的行数,相应的还有numAsciiCol函数用于获取列数
nrow = numAsciiRow(fiTY)
YYYYMMDDHH = new(nrow, "string")
lat = new(nrow, "float")
lon = new(nrow, "float")
vmax = new(nrow, "integer")
mslp = new(nrow, "integer")
data = asciiread(fiTY, -1, "string")
YYYYMMDDHH = str_get_field(data, 3,
",")
lat = stringtofloat(str_get_field(data, 7,
",")) *0.1
lon = stringtofloat(str_get_field(data, 8,
",")) *0.1
vmax = stringtoint(str_get_field(data, 9,
","))
mslp = stringtoint(str_get_field(data, 10,
","))
DateChar = stringtochar(YYYYMMDDHH)
MM = chartostring(DateChar(:,5:6))
DD = chartostring(DateChar(:,7:8))
HH = chartostring(DateChar(:,9:10))
HHi = mod(stringtoint(YYYYMMDDHH),
100)
DDi = mod(stringtoint(YYYYMMDDHH)/100,
100)
MMi = mod(stringtoint(YYYYMMDDHH)/10000,
100)
; plot
wks = gsn_open_wks("ps",
"BestTrack1")
gsn_define_colormap(wks,"rainbow")
res = True
res@gsnDraw = False
res@gsnFrame = False
; 设置底图边界
res@mpMinLatF = 10
res@mpMaxLatF = 50
res@mpMinLonF = 110
res@mpMaxLonF = 160
; 设置海陆填充颜色,这里的颜色选取rainbow色表中的第160号颜色
; 海洋默认是白色
res@mpLandFillColor = 160
; res@mpOceanFillColor = "white"
; 绘制洋面经纬网格
res@mpGridAndLimbOn = "True"
res@mpGridMaskMode = "MaskNotOcean"
res@mpGridLineDashPattern = 15
res@mpGridSpacingF = 5.0
; 绘制国界
res@mpOutlineOn = True
res@mpOutlineBoundarySets =
"National"
; 绘制省界
res@mpDataBaseVersion = "MediumRes"
res@mpDataSetName = "Earth..4"
res@mpOutlineSpecifiers =
"China:States"
plot = gsn_csm_map_ce(wks,res)
;================
; 按照vmax(单位:节 knot,海里/小时)变量提供的风速大小对台风强度进行区分,
; 并在绘制时用不同颜色标出
; 0~33.5 热带低压
; 34~63 热带风暴
; 64~80 台风
; 81~99 强台风
; >100 超强台风
colours = (/3, 20, 60, 120, 180/)
resDot = True
resLine = True
dumDot= new(nrow, graphic)
dumLine = new(nrow, graphic)
; 绘制线
resLine@gsLineThicknessF = 3
do i = 0, nrow-2
xx = (/
lon(i), lon(i+1)/)
yy = (/
lat(i), lat(i+1)/)
if
(vmax(i).le.33) then
resLine@gsLineColor = colours(0)
end
if
if
(vmax(i) .ge. 34 .and. vmax(i).le.63) then
resLine@gsLineColor = colours(1)
end
if
if
(vmax(i).ge.64 .and. vmax(i) .le. 80) then
resLine@gsLineColor = colours(2)
end
if
if
(vmax(i).ge.81 .and. vmax(i) .lt. 99) then
resLine@gsLineColor = colours(3)
end
if
if
(vmax(i).ge.100) then
resLine@gsLineColor = colours(4)
end
if
dumLine(i) = gsn_add_polyline(wks, plot, xx, yy, resLine)
end do
; 绘制00时的点
resDot@gsMarkerIndex = 1
resDot@gsMarkerSizeF = 0.02
resDot@gsMarkerColor = "black"
do i = 0, nrow-1
if
(HH(i) .eq. "00") then
dumDot(i) = gsn_add_polymarker(wks, plot, lon(i), lat(i),
resDot)
end
if
end do
; 绘制图例
resLg = True
resLg@lgItemType = "MarkLines"
resLg@lgMonoMarkerIndex = True
resLg@lgMarkerColors = colours
resLg@lgMarkerIndex = 1
resLg@lgMarkerSizeF = 0.02
resLg@lgMonoDashIndex = True
resLg@lgDashIndex = 0
resLg@lgLineColors = colours
resLg@lgLineThicknessF = 3
resLg@vpWidthF = 0.14
resLg@vpHeightF = 0.13
resLg@lgPerimFill = 0
resLg@lgPerimFillColor = "Background"
resLg@lgLabelFontHeightF = 0.08
resLg@lgTitleFontHeightF = 0.015
resLg@lgTitleString = "Best Track"
lbid = gsn_create_legend(wks, 5, (/" 33kt
or less", \
" 34 to 63kt", " 64 to 80kt", " 81 to
99kt", \
" 100 or more"/), resLg)
; 将图例放置在图中
amres = True
amres@amParallelPosF = -0.3
amres@amOrthogonalPosF = -0.3
dumLg = gsn_add_annotation(plot, lbid,
amres)
; 标注00时的日期
dumDate = new(nrow,graphic)
resTx = True
resTx@txFontHeightF = 0.012
resTx@txFontColor = "black"
resTx@txJust = "BottomLeft"
do i = 1, nrow-1
if
(HH(i) .ne. "00" ) then
continue
end
if
dumDate(i) = gsn_add_text(wks,plot, MM(i)+DD(i), lon(i)+0.5,
lat(i), resTx)
end do
draw(wks)
frame(wks)
end |