爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 12063|回复: 0

[作图] ncl画JMA 台风最佳路径集一直报错

[复制链接]
发表于 2019-3-11 18:16:08 | 显示全部楼层 |阅读模式
3金钱
本帖最后由 专打小破孩 于 2019-3-11 18:21 编辑

参照http://bbs.06climate.com/forum.p ... 8%B7%E7%C2%B7%BE%B6
和http://blog.sina.com.cn/s/blog_a134572301014xft.html 在此感谢风人风语 指甲钳 的分享!
对日本气象局东京台风中心 最佳路径集进行画图。
一直报错,尝试了很多天都没有改正过来。
请大家帮忙看下。

warning:stringtointeger: a bad value was passed; input strings must contain nume   ric digits, replacing with missing value
warning:stringtointeger: a bad value was passed; input strings must contain nume   ric digits, replacing with missing value
fatal:The result of the conditional expression yields a missing value. NCL can n   ot determine branch, see ismissing function
fatal:["Execute.c":8640]:Execute: Error occurred at or near line 101 in file /ho   me/Administrator/SZbsttrack.ncl


警告:StringToInteger:传递了错误的值;输入字符串必须包含nume-ric数字,替换为缺少的值
警告:StringToInteger:传递了错误的值;输入字符串必须包含nume-ric数字,替换为缺少的值
致命:条件表达式的结果生成一个缺少的值。NCL无法确定分支,请参见ISMIssing函数
致命:[“execute.c”:8640]:execute:在文件/ho me/administrator/szbstrack.ncl的第101行或其附近发生错误


我尝试对数据进行更改比如把002改成2 000 改成0 或者先提取所需数据,仍然报错。
数据和脚本如下:

18090612 002 2 118 1702 1008     000                                    
18090618 002 2 120 1692 1008     000                                    
18090700 002 2 120 1678 1008     000                                    
18090706 002 2 123 1666 1006     000                                    
18090712 002 3 127 1654 1000     035     00000 0000 90150 0150         
18090718 002 3 130 1639 1000     035     00000 0000 90150 0150         
18090800 002 3 136 1623  998     040     00000 0000 90150 0150         
18090806 002 3 143 1606  996     040     00000 0000 90150 0150         
18090812 002 3 145 1592  992     045     00000 0000 90150 0150         
18090818 002 4 146 1574  990     050     00000 0000 90160 0160         
18090900 002 5 148 1552  975     065     90060 0060 90180 0180         
18090906 002 5 153 1529  975     065     90060 0060 90180 0180         
18090912 002 5 151 1514  970     070     90060 0060 90180 0180         
18090918 002 5 146 1491  955     080     90070 0070 90180 0180         
18091000 002 5 146 1475  955     080     90070 0070 90180 0180         
18091006 002 5 144 1456  955     080     90070 0070 90180 0180         
18091012 002 5 142 1442  950     085     90070 0070 90180 0180         
18091018 002 5 140 1426  940     090     90080 0080 90180 0180         
18091100 002 5 140 1413  935     095     90090 0090 90180 0180         
18091106 002 5 139 1398  915     105     90110 0110 90180 0180         
18091112 002 5 137 1387  905     110     90110 0110 90210 0210         
18091118 002 5 140 1374  905     110     90110 0110 90240 0240         
18091200 002 5 139 1362  905     110     90110 0110 90240 0240         
18091206 002 5 140 1352  905     110     90110 0110 90240 0240         
18091212 002 5 143 1340  905     110     90110 0110 10280 0240         
18091218 002 5 144 1325  905     110     90110 0110 10300 0240         
18091300 002 5 145 1314  905     110     90110 0110 10300 0240         
18091306 002 5 148 1300  905     110     90110 0110 10300 0240         
18091312 002 5 149 1289  905     110     90120 0120 30400 0300         
18091318 002 5 152 1279  905     110     90120 0120 30400 0300         
18091400 002 5 160 1269  905     110     90120 0120 30400 0300         
18091406 002 5 167 1257  905     110     90120 0120 30400 0300         
18091412 002 5 174 1241  905     110     90120 0120 30400 0300         
18091418 002 5 180 1223  905     110     90120 0120 20400 0300         
18091500 002 5 180 1205  940     090     90120 0120 20400 0300         
18091506 002 5 185 1197  940     090     90120 0120 20400 0300         
18091512 002 5 192 1183  950     085     90120 0120 20350 0240         
18091518 002 5 198 1170  955     080     90120 0120 20350 0240         
18091600 002 5 206 1153  960     075     90090 0090 20350 0240         
18091606 002 5 217 1135  960     075     90090 0090 20350 0210         
18091612 002 5 222 1116  970     065     90090 0090 20300 0180         
18091618 002 4 227 1097  980     055     90090 0090 20300 0180         
18091700 002 3 232 1083  992     045     00000 0000 40300 0180         
18091706 002 2 240 1070  998     000                                    
18091712 002 2 240 1056 1002     000                                    
18091718 002 2 241 1039 1004     000                                    


;********************************************************
; 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 = "./SZ.txt"

; 获取文本文件的行数,相应的还有numAsciiCol函数用于获取列数
  nrow = numAsciiRow(fiTY) +1

  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, 1, ",")
  lat = stringtofloat(str_get_field(data, 4, ",")) *0.1
  lon = stringtofloat(str_get_field(data, 5, ",")) *0.1
  vmax = stringtoint(str_get_field(data, 7, ","))
  mslp = stringtoint(str_get_field(data, 6, ","))

  DateChar = stringtochar(YYYYMMDDHH)
  MM = chartostring(DateChar(:,3:4))
  DD = chartostring(DateChar(:,5:6))
  HH = chartostring(DateChar(:,7:8))

  HHi = mod(stringtoint(YYYYMMDDHH), 100)
  DDi = mod(stringtoint(YYYYMMDDHH)/100, 100)
  MMi = mod(stringtoint(YYYYMMDDHH)/10000, 100)

; plot

  wks = gsn_open_wks("png", "SZ")
  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


密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表