爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 5570|回复: 4

[作图] 有大神能帮我看看这个ncl简单画图程序错在哪里吗?

[复制链接]

新浪微博达人勋

发表于 2019-12-17 10:04:46 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 dongjunhui11 于 2019-12-17 10:04 编辑

因写论文需要自学用ncl绘图
我想画一个位势高度的图
这个脚本运行后报变量截取超出范围(也就是这一行  u = f->hgt(79634,1000,:,:) )
可我实在不知道哪里超出了
望各位大神帮忙看看 感谢!

以下是我的脚本:
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
  f    = addfile("hgt.2018.nc","r")            
  u = f->hgt(79634,1000,:,:)


  wks  = gsn_open_wks("png","hgtmap")   
  plot = gsn_csm_contour(wks,u,False)      

  res                  = True
  res@cnMonoLineColor  = False           
  res@cnLineColors     = span_color_rgba ("NCV_jet",11)   
  res@cnLineThicknessF = 5.0            

  plot = gsn_csm_contour(wks,u,res)

end

以下是报错:
fatal:Subscript out of range, error in subscript #0
fatal:Execute: Error occurred at or near line 7 in file hgtmap.nc


以下是nc数据:
filename:       hgt.2018
path:   hgt.2018.nc
   file global attributes:
      title : Once daily NCEP geopotential height data
      delta_time : once daily
      supplier : NCEP
      producer : NCEP
      history : created 2017/12 by Hoop (netCDF3)
      description : Data is from NCEP initialized analysis
(2x/day).  It consists of most variables interpolated to
pressure surfaces from model (sigma) surfaces. Data
is averged from 2x daily

      platform : Model
      Conventions : CF-1.2
      dataset_title : NCEP Global Data Assimilation System GDAS
   dimensions:
      lon = 144
      lat = 73
      level = 12
      time = 365  // unlimited
   variables:
      float hgt ( time, level, lat, lon )
         long_name :    Geopotential height
         actual_range : ( -606.6207, 21200.11 )
         valid_range :  ( -700, 29000 )
         units :        m
         missing_value :        -9.96921e+36
         var_desc :     Geopotential height
         precision :    2
         dataset :      NCEP
         level_desc :   Multiple levels
         statistic :    Mean
         parent_stat :  Individual Obs
         _FillValue :   -999

      float lon ( lon )
         units :        degrees_east
         long_name :    Longitude
         actual_range : (  0, 357.5 )
         standard_name :        longitude
         axis : X

      float lat ( lat )
         units :        degrees_north
         actual_range : ( 90, -90 )
         long_name :    Latitude
         standard_name :        latitude
         axis : Y

      float level ( level )
         units :        mb
         long_name :    Level
         actual_range : ( 50, 1000 )
         positive :     down
         axis : Z

      double time ( time )
         units :        days since 1800-1-1  00:00:0.0
         long_name :    Time
         actual_range : ( 79623, 79987 )
         delta_t :      0000-00-01 00:00:00
         avg_period :   0000-00-01 00:00:00
         prev_avg_period :      0000-00-00 06:00:00
         standard_name :        time
         axis : T

      short head ( time, level )
         valid_range :  ( 0, 3 )
         long_name :    Missing

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

新浪微博达人勋

发表于 2019-12-17 10:15:20 | 显示全部楼层
变量维数
hgt ( time, level, lat, lon ),
dimensions:
      lon = 144
      lat = 73
      level = 12
      time = 365  // unlimited
你读取的方式:u = f->hgt(79634,1000,:,:)
数组越界。以time为例,一共是365个位置,你却要读取位置为79634的数据,当然没有
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2019-12-17 13:06:00 | 显示全部楼层
变量选取使用的是数据所在的地址而不是数据具体的值,假如level(y)=1000,time(x)=79634,那你要写hgt(x,y,:,:)而不是hgt(79634,1000,:,:)。
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2019-12-17 13:15:53 | 显示全部楼层
楼上正解呀
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2019-12-20 12:25:48 | 显示全部楼层
数学学得特别好 发表于 2019-12-17 13:06
变量选取使用的是数据所在的地址而不是数据具体的值,假如level(y)=1000,time(x)=79634,那你要写hgt(x,y, ...

谢谢!问题解决了
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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