net.sourceforge.jgrib
Class GribFile

java.lang.Object
  extended by net.sourceforge.jgrib.GribFile

public class GribFile
extends java.lang.Object

A class that represents a GRIB file. It consists of a number of records which are represented by GribRecord objects. To retrieve a specific record or records, the standard sequence of methods is: getGridsForType getZunitsForTypeGrid getLevelsForTypeGridUnit getDatesForTypeGridLevel get2dRecord or get3dRecord

Version:
1.0
Author:
Benjamin Stark

Constructor Summary
GribFile(BitInputStream in)
          Constructs a GribFile object from a bit input stream
GribFile(java.io.InputStream in)
          Constructs a GribFile object from an input stream
GribFile(java.lang.String filename)
          Constructs a GribFile object from a file.
 
Method Summary
 GribRecord get2dRecord(java.lang.String aType, GribRecordGDS aGDS, GribPDSLevel aLevel, java.util.Date aDate)
          rdg - added this method to work with refined methods.
 GribRecord[] get3dRecord(java.lang.String aType, GribRecordGDS aGDS, GribPDSLevel[] levels, java.util.Date aDate)
          rdg - added this method to work with refined methods.
 java.util.Date[] getDatesForTypeGridLevel(java.lang.String aType, GribRecordGDS aGDS, GribPDSLevel aLevel)
          rdg - an override of the method passing a GribPDSLevel, vice a string for a level Get forecast times (sorted) for type and grid
 java.util.Date[] getDatesForTypeGridLevel(java.lang.String aType, GribRecordGDS aGDS, java.lang.String aLevel)
          Deprecated. - use same method name that uses a GribPDSLevel vice a string
 java.lang.String getDescriptionForType(java.lang.String aType)
          Get description for type name
 GribRecordGDS[] getGridForType(java.lang.String aType)
          Deprecated. - use getGridsForType - it better reflects the functionality
 GribRecordGDS[] getGrids()
          Get get grids
 GribRecordGDS[] getGridsForType(java.lang.String aType)
          Get Grids used for type (variable)
 java.lang.String[] getLevelsForTypeGrid(java.lang.String aType, GribRecordGDS aGDS)
          Deprecated. - allows ambiguity - use getLevelsForTypeGridUnit instead
 GribPDSLevel[] getLevelsForTypeGridUnit(java.lang.String aType, GribRecordGDS aGDS, int aUnit)
          rdg - added this method to distinguish between different vertical coordinate units (e.g. hPa vs. meters).
 GribRecordLight[] getLightRecords()
          Get Light GRIB records
 GribRecord getRecord(int i)
          Get a specific GRIB record of this GRIB file as GribRecord object.
 GribRecord getRecord(java.lang.String aType, GribRecordGDS aGDS, java.lang.String aLevel, java.util.Date aDate)
          Get a specified grid record
 int getRecordCount()
          Get the number of records this GRIB file contains.
 GribRecordLight[] getRecordForDescription(java.lang.String aDesc)
          Added by Richard Gonzalez 23 Sep 02 Get Records whose description matches (aDesc)
 GribRecordLight[] getRecordForType(java.lang.String aType)
          Added by Richard Gonzalez 23 Sep 02 Get Records for type (variable)
 java.lang.String[] getTypeNames()
          Get type names
static java.lang.String getVersion()
          Buildin version, so you can get it from within a jar file.
 int[] getZunitsForTypeGrid(java.lang.String aType, GribRecordGDS aGDS)
          rdg - added this method to distinguish between vertical coordinate types.
 void listParameters(java.io.PrintStream out)
          Method added by Richard Gonzalez 23 Sep 02.
 void listRecords(java.io.PrintStream out)
          Print out overview of GRIB file content.
 java.lang.String toString()
          Get a string representation of the GRIB file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GribFile

public GribFile(java.lang.String filename)
         throws java.io.FileNotFoundException,
                java.io.IOException,
                NotSupportedException,
                NoValidGribException
Constructs a GribFile object from a file.

Parameters:
filename - name of the GRIB file
Throws:
java.io.FileNotFoundException - if file can not be found
java.io.IOException - if file can not be opened etc.
NotSupportedException - if file contains features not yet in jgrib
NoValidGribException - if file is no valid GRIB file

GribFile

public GribFile(java.io.InputStream in)
         throws java.io.IOException,
                NotSupportedException,
                NoValidGribException
Constructs a GribFile object from an input stream

Parameters:
in - input stream with GRIB content
Throws:
java.io.IOException - if stream can not be opened etc.
NotSupportedException - if file contains features not yet in jgrib
NoValidGribException - if stream does not contain a valid GRIB file

GribFile

public GribFile(BitInputStream in)
         throws java.io.IOException,
                NotSupportedException,
                NoValidGribException
Constructs a GribFile object from a bit input stream

Parameters:
in - bit input stream with GRIB content
Throws:
java.io.IOException - if stream can not be opened etc.
NotSupportedException - if file contains features not yet in jgrib
NoValidGribException - if stream does not contain a valid GRIB file
Method Detail

getVersion

public static java.lang.String getVersion()
Buildin version, so you can get it from within a jar file.

Returns:
String - Current version of JGRIB

getDescriptionForType

public java.lang.String getDescriptionForType(java.lang.String aType)
Get description for type name

Parameters:
aType - type name
Returns:
description of type

getRecordForDescription

public GribRecordLight[] getRecordForDescription(java.lang.String aDesc)
Added by Richard Gonzalez 23 Sep 02 Get Records whose description matches (aDesc)

Parameters:
aDesc - String representing type name
Returns:
array of GribRecords

getRecordForType

public GribRecordLight[] getRecordForType(java.lang.String aType)
Added by Richard Gonzalez 23 Sep 02 Get Records for type (variable)

Parameters:
aType - String representing type name
Returns:
array of GribRecords

getGridForType

public GribRecordGDS[] getGridForType(java.lang.String aType)
Deprecated. - use getGridsForType - it better reflects the functionality

Get Grids used for type (variable)

Parameters:
aType - type name
Returns:
array of grids

getGridsForType

public GribRecordGDS[] getGridsForType(java.lang.String aType)
Get Grids used for type (variable)

Parameters:
aType - type name
Returns:
array of grids rdg - renamed to better represent functionality

getZunitsForTypeGrid

public int[] getZunitsForTypeGrid(java.lang.String aType,
                                  GribRecordGDS aGDS)
rdg - added this method to distinguish between vertical coordinate types. e.g. hPa vs. meters vs. layer between hPa surfaces Get level indices for type and grid Can't use the unit string because it may be blank for many types

Parameters:
aType - type name
aGDS - grid
Returns:
array of level indices from table 3

getLevelsForTypeGridUnit

public GribPDSLevel[] getLevelsForTypeGridUnit(java.lang.String aType,
                                               GribRecordGDS aGDS,
                                               int aUnit)
rdg - added this method to distinguish between different vertical coordinate units (e.g. hPa vs. meters). Get levels (sorted) for type and grid and vertical coordinate unit index Using index guards against blank unit strings matching each other

Parameters:
aType - type name
aGDS - grid
aUnit - index of vertical axis units from table 3
Returns:
array of GribPDSLevel-s

getLevelsForTypeGrid

public java.lang.String[] getLevelsForTypeGrid(java.lang.String aType,
                                               GribRecordGDS aGDS)
Deprecated. - allows ambiguity - use getLevelsForTypeGridUnit instead

rdg - this is superceded by getLevelsForTypeGridUnit - should be deleted Get levels (sorted) for type and grid

Parameters:
aType - type name
aGDS - grid
Returns:
array of forecast time

getDatesForTypeGridLevel

public java.util.Date[] getDatesForTypeGridLevel(java.lang.String aType,
                                                 GribRecordGDS aGDS,
                                                 java.lang.String aLevel)
Deprecated. - use same method name that uses a GribPDSLevel vice a string

Get forecast times (sorted) for type and grid.

Parameters:
aType - type name
aGDS - grid
aLevel -
Returns:
array of forecast time

getDatesForTypeGridLevel

public java.util.Date[] getDatesForTypeGridLevel(java.lang.String aType,
                                                 GribRecordGDS aGDS,
                                                 GribPDSLevel aLevel)
rdg - an override of the method passing a GribPDSLevel, vice a string for a level Get forecast times (sorted) for type and grid

Parameters:
aType - type name
aGDS - grid
aLevel -
Returns:
array of forecast time

getRecord

public GribRecord getRecord(java.lang.String aType,
                            GribRecordGDS aGDS,
                            java.lang.String aLevel,
                            java.util.Date aDate)
                     throws java.io.IOException,
                            NoValidGribException,
                            NotSupportedException
Get a specified grid record

Parameters:
aType - type name
aGDS - grid
aLevel -
aDate - forecast date
Returns:
GribRecord
Throws:
java.io.IOException
NoValidGribException
NotSupportedException

get2dRecord

public GribRecord get2dRecord(java.lang.String aType,
                              GribRecordGDS aGDS,
                              GribPDSLevel aLevel,
                              java.util.Date aDate)
                       throws java.io.IOException,
                              NoValidGribException,
                              NotSupportedException
rdg - added this method to work with refined methods. Also made name more specific to what you are getting. Get a specified grid record

Parameters:
aType - parameter type name
aGDS - grid
aLevel - level
aDate - forecast date
Returns:
- a GribRecord for a single level of a parameter
Throws:
java.io.IOException
NoValidGribException
NotSupportedException

get3dRecord

public GribRecord[] get3dRecord(java.lang.String aType,
                                GribRecordGDS aGDS,
                                GribPDSLevel[] levels,
                                java.util.Date aDate)
                         throws java.io.IOException,
                                NoValidGribException,
                                NotSupportedException
rdg - added this method to work with refined methods. Also made name more specific to what you are getting. Get a specified grid record

Parameters:
aType - parameter type name
aGDS - grid
levels - levels to be retrieved - should already be sorted
aDate - forecast date
Returns:
- an array of GribRecord-s representing a volume of a parameter
Throws:
java.io.IOException
NoValidGribException
NotSupportedException

getRecord

public GribRecord getRecord(int i)
                     throws java.util.NoSuchElementException,
                            java.io.IOException,
                            NoValidGribException,
                            NotSupportedException
Get a specific GRIB record of this GRIB file as GribRecord object.

Parameters:
i - number of GRIB record, first record is number 1
Returns:
GRIB record object
Throws:
java.util.NoSuchElementException - if record number does not exist
java.io.IOException - if record can not be opened etc.
NoValidGribException - if record is no valid GRIB record
NotSupportedException - if JGrib doesn't yet support the operation

getTypeNames

public java.lang.String[] getTypeNames()
Get type names

Returns:
array with names

getLightRecords

public GribRecordLight[] getLightRecords()
Get Light GRIB records

Returns:
Array with Light Grib Records

getGrids

public GribRecordGDS[] getGrids()
Get get grids

Returns:
array with grids

getRecordCount

public int getRecordCount()
Get the number of records this GRIB file contains.

Returns:
number of records in this GRIB file

listRecords

public void listRecords(java.io.PrintStream out)
                 throws java.io.IOException,
                        NoValidGribException,
                        NotSupportedException
Print out overview of GRIB file content.

Parameters:
out - print stream the output is written to
Throws:
java.io.IOException - if a record can not be opened etc.
NoValidGribException - if a record is no valid GRIB record
NotSupportedException - if JGrib doesn't support something yet

listParameters

public void listParameters(java.io.PrintStream out)
Method added by Richard Gonzalez 23 Sep 02. Print out listing of parameters in GRIB file.

Parameters:
out - print stream the output is written to

toString

public java.lang.String toString()
Get a string representation of the GRIB file.

Overrides:
toString in class java.lang.Object
Returns:
NoValidGribException if record is no valid GRIB record