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

Re: [netcdf-java] reading grib files



Hiya Chad,

There are some standalone routines that you should look at: Grib1Indexer, Grib1GetData and Grib1Dump . Also the Decoders home page has some important information

http://www.unidata.ucar.edu/software/decoders/

especially the Index tag. There's also JavaDocs on the page.

The Grib1GetData routine is basically a template for your code below, it might be a good starting point.


The package is currently under a major refactor for performance reasons and for new capabilities, ie processing Ensemble type data, etc. The API will change from the version that you are using.

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/
===============================================================================