Re: [decoders] Decoding GRIB2 files!

NOTE: The decoders mailing list is no longer active. The list archives are made available for historical reasons.

On Fri, 17 Dec 2010, Volker Windeck wrote:

Dear GRIB-Decoders,

I am currently trying to decode a GRIB2 file to further process this data in a
java.

Earlier I found an e-mail in your mailing list where you suggested to read in
data with the readDataSlice() method for specific lat/lon coordinates. This way
of reading data from a grib file would take too much time. Is there a way to 
read
in a larger amount of data in less time?

Hi Volker,

We have discouraged folks from directly using the grib decoder because there are many messes details and it's easy to make a mistake. It's better to open the grib file as a netcdf file and perform operations on it. Â

My idea is to read in âv-â and âu-components-of-currentsâ from a GRIB2 file for 
a
predefined field of coordinates.

Many times the v and u componets are in the same record in the Grib file, so one would have to be extra careful.


Are there any manuals on how to work with the java grib decoder? Are there any
java code example files that are close to what I am looking for?

Here's a sample code of opening/reading/closing a netcdf file:

   public static void main() {

     try {
       NetcdfFile ncf = NetcdfFile.open("ruc2.t00z.bgrb13anl.grib2");
       System.out.println("Variable names are:");
       List<Variable> vars = ncf.getVariables();
       for (Variable var : vars) {
         System.out.println(var.getName());
         // once you get the var for a particular variable name, all
         //information is available including the Dimensions.

// http://www.unidata.ucar.edu/software/netcdf-java/v4.2/javadocAll/index.html
// look at ucar.nc2.Variable
       }

//"All the data records for the same parameter on the same grid will be in a single 3-D //(x,y,t) or 4-D (x,y,z,t) variable depending on the data. The grid information is available
       // in several coordinate variables".


       // For example, the coordinate variables for Temperature are:
       //             time   level   y          x
       // Temperature(0:0:1, 0:0:1, 0:336:1, 0:450:1)
// each coordinate variable has a start, end, stride separated by a : so time starts at 0, // ends at 0 and has a stride of 1. This information is available in the above javadoc. // Also, if you are using ToolsUI, click on a variable name and then // ncdump tab and it will open a window show the coordinates and permit you to dump the data

       Variable Temperature = ncf.findVariable("Temperature");
       Array data = Temperature.read("0:0, 0:0, 0:336,0:450");
       // To read all the data at once
       // Array data = Temperature.read();
       IndexIterator iter = data.getIndexIterator();
       System.out.println("Temperature = ");
       while (iter.hasNext()) {
         float val = iter.getFloatNext();
         System.out.println(val);
       }
       ncf.close();
       System.out.println("Success");
     } catch (Exception exc) {
       exc.printStackTrace();
     }
   }



Robb...


Â

Thanks for your support!

Kind regards,


Volker Windeck
University of Hamburg

Â




===============================================================================
Robb Kambic                                Unidata Program Center
Software Engineer II                       Univ. Corp for Atmospheric Research
rkambic@xxxxxxxxxxxxxxxx                   WWW: http://www.unidata.ucar.edu/
===============================================================================
  • 2010 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the decoders archives: