首页 文章

Java GRIB-Decoder:从GRIB2文件中提取数据

提问于
浏览
1

我从这里下载了一些grib数据文件:ftp://data-portal.ecmwf.int/20160721000000/ (file type is .bin) 并想在我的Java应用程序中从这个文件中提取数据(我想稍后将提取的数据加载到数据库中) . 我只是尝试使用ftp://wmo:essential@data-portal.ecmwf.int/20160721000000/A_HWXE85ECEM210000_C_ECMF_20160721000000_24h_em_ws_850hPa_global_0p5deg_grib2.bin文件 .

因此,我创建了一个新的Java项目并添加了两个库 grib-8.0.29.jarnetcdfAll-4.6.6.jar . 有关 grib API的文档,请访问:http://www.unidata.ucar.edu/software/decoders/grib/javadoc/ . 我需要打开下载的文件来获取数据 . 通过 Grib2Dump 检索一些元数据似乎有效(见下文) . 还有 Grib2Input 实例sais,我有一个版本2的有效GRIB文件 .

这是我检索一些元数据的工作代码:

public static void main(String[] args) throws IOException, InterruptedException {
        File srcDir = new File("C://test//");
        File[] localFiles = srcDir.listFiles();

        for (File tempFile : localFiles) {
             RandomAccessFile raf = new RandomAccessFile(tempFile.getAbsolutePath(), "r");

             System.out.println("======= Grib2GDSVariables ==========");
             Grib2GDSVariables gdsVariables = new Grib2GDSVariables(raf.readBytes(raf.read())); 
             System.out.println("Gds key : " + gdsVariables.getGdsKey());

             System.out.println("======= Grib2Input ==========");
             Grib2Input input = new Grib2Input(raf);
             System.out.println(Grib2Input.isValidFile(raf));
             System.out.println("scan : " + input.scan(true, true));
             System.out.println("getGDSs.size: " + input.getGDSs().size());
             System.out.println("getProducts.size: " + input.getProducts().size());
             System.out.println("getRecords.size: " + input.getRecords().size());
             System.out.println("edition: " + input.getEdition());

             System.out.println("======= Grib2Dump ==========");
             Grib2Dump dump = new Grib2Dump(); 
             dump.gribDump(new String[] {tempFile.getAbsolutePath()});

             System.out.println("======= Grib2ExtractRawData ==========");
             Grib2ExtractRawData extractRawData = new
             Grib2ExtractRawData(raf); extractRawData.main(new String[] {tempFile.getAbsolutePath()});
        }

        System.out.println("finished");
}

这会产生以下输出:

======= Grib2GDSVariables ==========
Gds key : -1732955898
======= Grib2Input ==========
true
scan : true
getGDSs.size: 0
getProducts.size: 0
getRecords.size: 0
edition: 2
======= Grib2Dump ==========
--------------------------------------------------------------------
                        Header : GRIB2
                    Discipline : 0 Meteorological products
                  GRIB Edition : 2
                   GRIB length : 113296
            Originating Center : 98 European Center for Medium-Range Weather Forecasts (RSMC)
        Originating Sub-Center : 0
Significance of Reference Time : 1 Start of forecast
                Reference Time : 2016-07-21T00:00:00Z
                Product Status : 0 Operational products
                  Product Type : 1 Forecast products
         Number of data points : 259920
                     Grid Name : 0 Latitude_Longitude
                     Grid Shape: 6 Earth spherical with radius of 6,371,229.0 m
Number of points along parallel: 720
Number of points along meridian: 361
                   Basic angle : 0
    Subdivisions of basic angle: -9999
  Latitude of first grid point : 90.0
 Longitude of first grid point : 0.0
  Resolution & Component flags : 48
                         Winds : True
   Latitude of last grid point : -90.0
  Longitude of last grid point : 359.5
         i direction increment : 0.5
         j direction increment : 0.5
                    Grid Units : degrees
                 Scanning mode : 0
            Product Definition : 2 Derived forecast on all ensemble members at a point in time
            Parameter Category : 2 Momentum
                Parameter Name : 1 Wind_speed
               Parameter Units : m s-1
       Generating Process Type : 4 Ensemble Forecast
                  ForecastTime : 24
            First Surface Type : 100 Isobaric surface
           First Surface value : 85000.0
           Second Surface Type : 255 Missing
          Second Surface value : -9.999E-252
======= Grib2ExtractRawData ==========
finished

我现在试了两天但是无法上班!我无法从文件中获取内容数据(lat,lon,value)...

有人能举个例子吗?

1 回答

相关问题