爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 21829|回复: 26

[讨论] 求助 如何用MATLAB读取grib2数据

[复制链接]

新浪微博达人勋

发表于 2017-8-1 14:45:57 | 显示全部楼层 |阅读模式

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

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

x
求助各位大神

最近需要读取海浪数据,数据是grib2格式的,如何用MATLAB读取grib2数据?matlab是2012版。

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

新浪微博达人勋

 成长值: 32430
发表于 2017-8-1 20:14:26 | 显示全部楼层
oppion123 发表于 2017-8-1 17:56
谢谢你,我已经将nctoolbox下载下来了,你可不可以告诉我一下在matlab读取grib2的数据的详细步骤。
谢谢 ...

setup_nctoolbox
nc = ncgeodataset(file)
nc.variables
nc.data('……');
密码修改失败请联系微信:mofangbao
回复 支持 1 反对 0

使用道具 举报

新浪微博达人勋

 成长值: 32430
发表于 2017-8-1 15:04:22 | 显示全部楼层
nctoolbox
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

 成长值: 32430
发表于 2017-8-1 15:04:46 | 显示全部楼层
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-8-1 17:56:24 | 显示全部楼层

谢谢你,我已经将nctoolbox下载下来了,你可不可以告诉我一下在matlab读取grib2的数据的详细步骤。
谢谢你。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-8-1 21:08:50 来自手机 | 显示全部楼层
谢谢你,我按照这个步骤做,出现以下问题:       Error using ncdataset (line 97) Failed to open C:/workfile/gribdata/fnl_20150811_12_00.grib2  Error in cfdataset (line 59)             obj = obj@ncdataset(url);  Error in ncgeodataset (line 74)             obj = obj@cfdataset(url);  Caused by:     Error using ncdataset (line 81)     Java exception occurred:     java.lang.RuntimeException: java.lang.NoSuchFieldError: alwaysUseFieldBuilders              at ucar.nc2.NetcdfFile.<init>(NetcdfFile.java:1535)              at ucar.nc2.NetcdfFile.open(NetcdfFile.java:887)              at ucar.nc2.NetcdfFile.open(NetcdfFile.java:496)              at ucar.nc2.dataset.NetcdfDataset.openOrAcquireFile(NetcdfDataset.java:693)              at ucar.nc2.dataset.NetcdfDataset.openDataset(NetcdfDataset.java:424)              at ucar.nc2.dataset.NetcdfDataset.openDataset(NetcdfDataset.java:407)              at ucar.nc2.dataset.NetcdfDataset.openDataset(NetcdfDataset.java:392)              at ucar.nc2.dataset.NetcdfDataset.openDataset(NetcdfDataset.java:379)      Caused by: java.lang.NoSuchFieldError: alwaysUseFieldBuilders              at ucar.nc2.grib.grib2.Grib2IndexProto$Grib2Index.access$5400(Grib2IndexProto.java:2635)              at         ucar.nc2.grib.grib2.Grib2IndexProto$Grib2Index$Builder.maybeForceBuilderInitialization(Grib2IndexProto.java:2914)                      at ucar.nc2.grib.grib2.Grib2IndexProto$Grib2Index$Builder.<init>(Grib2IndexProto.java:2906)              at ucar.nc2.grib.grib2.Grib2IndexProto$Grib2Index$Builder.create(Grib2IndexProto.java:2920)              at         ucar.nc2.grib.grib2.Grib2IndexProto$Grib2Index$Builder.access$5200(Grib2IndexProto.java:2891)              at ucar.nc2.grib.grib2.Grib2IndexProto$Grib2Index.newBuilder(Grib2IndexProto.java:2878)              at ucar.nc2.grib.grib2.Grib2Index.makeIndex(Grib2Index.java:231)              at ucar.nc2.grib.GribIndex.makeGribCollectionFromSingleFile(GribIndex.java:112)              at ucar.nc2.grib.grib2.Grib2Iosp.open(Grib2Iosp.java:310)              at ucar.nc2.NetcdfFile.<init>(NetcdfFile.java:1499)              ... 7 more      我试了几次都是这样,我java是1.6的,matlab是2008的,你帮我看看什么原因,谢谢你。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-8-2 08:49:46 | 显示全部楼层
二爷名声在外 发表于 2017-8-1 20:14
setup_nctoolbox
nc = ncgeodataset(file)
nc.variables

你好,希望麻烦你帮我看看是什么原因啊,谢谢你。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 成长值: 32430
发表于 2017-8-2 09:24:08 | 显示全部楼层
你的代码呢???
问问题之前请站在对方的角度思考一下
首先你的这个帖子发的时候就没有搜索,要不然根本就不会发出来这个帖子
其次你问这个工具箱的用法,论坛里面也不是没有
最后你问你出现的问题,连你的代码都不给,难道还要别人猜你写了什么吗?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-8-2 10:00:35 | 显示全部楼层
二爷名声在外 发表于 2017-8-2 09:24
你的代码呢???
问问题之前请站在对方的角度思考一下
首先你的这个帖子发的时候就没有搜索,要不然根本 ...

实在不好意思,我是做船舶的,需要查看一下某地地方的海浪情况,在这方面确实不是太懂。
之前也搜索了本站的相关帖子,跟着做也没有做出来,所以又发了个帖子。
我在NOAA上下了一个grib2文件,文件D盘,D:\grib2\HTSGW_00.t00z.grib2,我想用Matlab读取里面的数据,因为直接打开是乱码。(也想用本站里面推荐的其他软件打开,但是都不好下载,所以就用matlab了)
nctoolbox是在网上下载的,大概15M左右,解压放到了D盘grib2文件夹下。
然后启用matlab
输入setup_nctoolbox
nc = ncgeodataset('D:\grib2\HTSGW_00.t00z.grib2')
就出现以下问题:
>> setup_nctoolbox
NCTOOLBOX added to Matlab path
>> nc = ncgeodataset('D:\grib2\HTSGW_00.t00z.grib2')
2017-08-02 09:59:14,897 [main] WARN  ucar.nc2.grib.grib2.Grib2Index  - Grib2Index bad size = -1 for D:/grib2/HTSGW_00.t00z.grib2 index = D:\grib2\HTSGW_00.t00z.grib2.gbx9

2017-08-02 09:59:14,897 [main] WARN  ucar.nc2.grib.grib2.Grib2Index  - Grib2Index bad size = -1 for D:/grib2/HTSGW_00.t00z.grib2 index = D:\grib2\HTSGW_00.t00z.grib2.gbx9

Warning: Escape sequence 'g' is not valid. See 'help sprintf' for valid escape sequences.
> In ncdataset>ncdataset.ncdataset at 95
  In cfdataset>cfdataset.cfdataset at 59
  In ncgeodataset>ncgeodataset.ncgeodataset at 74
Error using ncdataset (line 97)
Failed to open D:

Error in cfdataset (line 59)
            obj = obj@ncdataset(url);

Error in ncgeodataset (line 74)
            obj = obj@cfdataset(url);

Caused by:
    Error using ncdataset (line 81)
    Java exception occurred:
    java.lang.RuntimeException: java.lang.NoSuchFieldError: alwaysUseFieldBuilders

            at ucar.nc2.NetcdfFile.<init>(NetcdfFile.java:1535)

            at ucar.nc2.NetcdfFile.open(NetcdfFile.java:887)

            at ucar.nc2.NetcdfFile.open(NetcdfFile.java:496)

            at ucar.nc2.dataset.NetcdfDataset.openOrAcquireFile(NetcdfDataset.java:693)

            at ucar.nc2.dataset.NetcdfDataset.openDataset(NetcdfDataset.java:424)

            at ucar.nc2.dataset.NetcdfDataset.openDataset(NetcdfDataset.java:407)

            at ucar.nc2.dataset.NetcdfDataset.openDataset(NetcdfDataset.java:392)

            at ucar.nc2.dataset.NetcdfDataset.openDataset(NetcdfDataset.java:379)

    Caused by: java.lang.NoSuchFieldError: alwaysUseFieldBuilders

            at
        ucar.nc2.grib.grib2.Grib2IndexProto$Grib2Index.access$5400(Grib2IndexProto.java:2635)

            at
        ucar.nc2.grib.grib2.Grib2IndexProto$Grib2Index$Builder.maybeForceBuilderInitialization(Grib2IndexProto.java:2914)
        
            at
        ucar.nc2.grib.grib2.Grib2IndexProto$Grib2Index$Builder.<init>(Grib2IndexProto.java:2906)
        
            at
        ucar.nc2.grib.grib2.Grib2IndexProto$Grib2Index$Builder.create(Grib2IndexProto.java:2920)
        
            at
        ucar.nc2.grib.grib2.Grib2IndexProto$Grib2Index$Builder.access$5200(Grib2IndexProto.java:2891)
        
            at
        ucar.nc2.grib.grib2.Grib2IndexProto$Grib2Index.newBuilder(Grib2IndexProto.java:2878)

            at ucar.nc2.grib.grib2.Grib2Index.makeIndex(Grib2Index.java:231)

            at ucar.nc2.grib.GribIndex.makeGribCollectionFromSingleFile(GribIndex.java:112)

            at ucar.nc2.grib.grib2.Grib2Iosp.open(Grib2Iosp.java:310)

            at ucar.nc2.NetcdfFile.<init>(NetcdfFile.java:1499)

            ... 7 more
确实在这方面接触很少,所以遇到问题也不知道该怎么解决。
希望你帮我看看问题出在哪里。代码我就按照你写的那个写了第一句就出现问题了。
再次谢谢你。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 成长值: 32430
发表于 2017-8-2 10:02:40 | 显示全部楼层
看这个提示是这个文件有问题啊
楼主检查一下是文件有问题还是路径什么的有问题
实在不行换一个文件试一下
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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