爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 18218|回复: 16

[作图] 读取多个文件之后提示的错误

[复制链接]

新浪微博达人勋

发表于 2012-3-1 15:09:25 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 小诸葛 于 2012-3-1 15:11 编辑

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/wrf/WRFUserARW.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
begin
  files = systemfunc ("ls ../../wrfout_d01*")
  f     = addfiles (files + ".nc" , "r")   ;多个文件读取

  f     = addfile("../../*.nc","r")  ;单个文件读取
  wks = gsn_open_wks(“x11”,"wrfout_wind")
  res = True
  res@MainTitle       = " WRF RESULT--WIND "
  res@tiXAxisString   = " Latitude "
  res@tiYAxisString   = " Longitude "
   pltres = True
  mpres  = True
   times  = wrf_user_list_times(f)  ; get times in the file
   ntimes = dimsizes(times)         ; number of times in the file
   do it = 0,ntimes-1
      u  = wrf_user_getvar(f,"ua",it)      ; u averaged to mass points
      v  = wrf_user_getvar(f,"va",it)      ; v averaged to mass points
   end do
     uu  = dim_avg_n(u,0)
     vv  = dim_avg_n(v,0)  
     spd = sqrt(uu*uu + vv*vv)           ; speed in m/sec
     wrf_smooth_2d( spd, 3)              ; smooth speed   
     spd@description = "Wind Speed"
     spd@units = "m/s"
       opts = res
       opts@ContourParameters = (/ 1., 12., 1. /)
       opts@cnFillOn          = True
       opts@cnLevelSelectionMode   ="ManualLevels"         
       gsn_define_colormap(wks,"BlAqGrYeOrReVi200")
       opts@cnLabelMasking    = True
       contour = wrf_contour(f,wks,spd(:,:),opts)
       delete(opts)   
end

    当读取单个文件的时候没有问题,但是当读取多个文件的时候会提示:fatal:Argument type mismatch on argument (0) of (wrf_contour) can not coerce,,错误在contour = wrf_contour(f,wks,spd(:,:),opts)这一行,查询了下解决办法:http://www.ncl.ucar.edu/Support/talk_archives/2011/2451.html,建议将contour = wrf_contour(f,wks,spd(:,:),opts)改为contour = wrf_contour(f(0),wks,spd(:,:),opts),但是还是提示同样的错误,大家有谁遇到过同样的问题或者哪位达人帮忙解决下,不胜感激!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2012-3-6 15:56:50 | 显示全部楼层

就是将contour = wrf_contour(f,wks,spd(:,:),opts)改为contour = wrf_contour(f[0],wks,spd(:,:),opts),不是小括号而是中括号

评分

参与人数 2金钱 +13 收起 理由
D.B.L + 10 解决了我的问题,感谢楼主
mofangbao + 3

查看全部评分

密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2012-3-6 09:18:29 | 显示全部楼层
问题已解决
密码修改失败请联系微信:mofangbao

新浪微博达人勋

0
早起挑战累计收入
发表于 2012-3-6 09:40:28 | 显示全部楼层

虽然没有人能够解答你的问题,但是我仍然期待楼主能够把解决方法描述一下,这样就不仅仅是你解决了问题,还能帮助以后的很多朋友,先谢过了!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2012-6-15 13:37:14 | 显示全部楼层
今天学习ncl,也遇到了同样的问题。看到你的解决方案,很快解决了我的问题,非常感谢!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2013-11-18 15:42:54 | 显示全部楼层
不错  解决了问题
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-2-22 17:37:57 | 显示全部楼层
解决了问题,但是不知道原理是啥?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-4-16 15:28:04 | 显示全部楼层
遇到了同样的问题  感谢楼主贴出解决方法
希望以后大家解决问题后能把解决方法也贴上来,方便大家
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-4-18 18:15:49 | 显示全部楼层
好,学习中...
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2014-11-4 19:10:44 | 显示全部楼层
谢谢楼主!问题解决。我的理解是批量读文件以后,f就多了一维,所以f[0]才代表文件,不知道对的吧
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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