[netcdf-java] reading grib files

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

  • 2009 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: