[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [netcdf-java] reading grib files



Chad,

I forgot to mention that one could use the netcdf-java package also to extract the data at a higher level.


http://www.unidata.ucar.edu/software/netcdf-java/

There's a interface to the package called ToolsUI which permits one to look at/display the data.

It's worth you time to inspect this package instead of dealing with the low level details of Grib unless you need too. There are netcdf-java Java Docs on the page too..


Robb...



On Fri, 24 Jul 2009, Chad Saxon wrote:

Hi all,
i recently have started to looking into reading grib1 and grib2 files using the 
netcdf java library
and need to extract the variables in the file along with their relative data. i 
have some code here:

public class GribPlugin {

GribChecker file = new GribChecker();
Grib1GridDefinitionSection gridSection;


Grib1Input gribInput;
Grib1ProductDefinitionSection productSection;


Grib2ExtractRawData extract;


ArrayList<String> gribRecords;
ArrayList<String> gribProducts;


String testfile = "Pacific.wind.grb";
static int type;


public GribPlugin() throws IOException, NoValidGribException, 
NotSupportedException{


ucar.unidata.io.RandomAccessFile gribfile = new 
ucar.unidata.io.RandomAccessFile(testfile, "rw");
type = file.getEdition(gribfile);
System.out.println("File read in: " + testfile + ", Type of Grib File is " + 
type);


gribInput = new Grib1Input(gribfile);


gribRecords = new ArrayList<String>();
gribProducts = new ArrayList<String>();


gribRecords = gribInput.getRecords();
gribProducts = gribInput.getProducts();


//extract = new Grib2ExtractRawData(gribfile);
//gribRecords = extract.getRecords();
//gribProducts = extract.getProducts();


System.out.println("number of grib records: " + gribRecords.size());
System.out.println("number of grib products: " + gribProducts.size());


//System.out.println(gridSection.getNx() + " " + gridSection.getNy());
//System.out.println("First lat coordinate: " + gridSection.getLa1() + " Last lat 
coordinate: " +
gridSection.getLa2());
//System.out.println("First lon coordinate: " + gridSection.getLo1() + " Last lon 
coordinate: " +
gridSection.getLo2());


}

a printout of this code with this particular file yields:

File read in: Pacific.wind.grb, Type of Grib File is 1
number of grib records: 0
number of grib products: 0

I guess i don't know what i am looking for to get the data and am not as 
familiar with this type of
data as i should be. I guess i need to read up on what "records" or "products" 
really are but i was
wondering if there was any examples hidden somewhere in some javadoc from the 
netcdf java website??

thanks all for the help and suggestions!

Chad




===============================================================================
Robb Kambic                                Unidata Program Center
Software Engineer III                      Univ. Corp for Atmospheric Research
address@hidden             WWW: http://www.unidata.ucar.edu/
===============================================================================