WXP::GribFile Class Reference

This class reads in and decodes GRIB data. More...

#include "../include/GribFile.h"

List of all members.

Public Types

enum  Type {
  NONE, WXP, WMO, WXP_OLD,
  RAW, RAW_NS
}

Public Member Functions

 GribFile ()
 GribFile (const char *filename)
 GribFile (Filename &filename)
 ~GribFile ()
int init ()
bool isOpen ()
int useHdrFile (bool val)
int setMaxBad (int val)
int open (const char *filename, int raccess)
int open (const char *filename)
int open (Filename &filename)
int close ()
int rewind ()
int getVersion ()
const char * getWmoHdr ()
int getHeader (Grid &grid)
int read (Grid &grid)
int read (const char *spec, Grid &grid)
int read (GridSpec &spec, Grid &grid)
int read (Grids &grids)
int makeInfo (GribPDB &pdb, Grid &grid)
int makeDatim (Grid &grid)
int peek (Grid &grid)
int next ()
int readHeader ()
int searchGRIB ()
int readData (int bytes)
int readBits ()
unsigned char getByte (int loc)
int seekData (int val)
int tellData ()
GribParam getVer1Param (int ver, int src, int table, int param)
int readPDB (GribPDB &pdb)
int setPDB (GribPDB &pdb, Grid &grid)
int readGDB (DomainVal &dv)
int readBMB ()
bool checkBMB ()
int readBDB (Grid &grid)
int readSection ()
int skipSection ()
GribParam getVer2Param (int src, int disc, int cat, int param)
int readIDS (GribPDB &pdb)
int readGDS (DomainVal &dv)
int readPDS (GribPDB &pdb)
int readDRS ()
int readBMS ()
int readDS (Grid &grid)
int write (Grid &grid)

Static Public Member Functions

static int checkType (const char *filename)
static float ibmFloatConv (const unsigned char *pc)
static float ieeeFloatConv (const unsigned char *pc)
static float scaleConv (const unsigned char *pc)
static int scaleConv (float scale)
static int setDomain (int type, DomainVal &dv)

Static Public Attributes

static const int LIMIT = 300000

Detailed Description

This class reads in and decodes GRIB data.

Author:
Dan Vietor

Constructor & Destructor Documentation

GribFile::GribFile (  ) 

Constructor. Initializes class values.

References init().

GribFile::GribFile ( const char *  filename  ) 

Constructor. Opens file for reading.

Parameters:
filename Name of GRIB file to read from
GribFile::GribFile ( Filename filename  ) 

Constructor. Opens a file for reading (uses header file if available)

Parameters:
filename Filename class containing filename info
GribFile::~GribFile (  ) 

Destructor.

References close().


Member Function Documentation

bool GribFile::checkBMB (  ) 

Checks the Bit Map Block. If the gridpoint is valid, it returns true.

Returns:
True if valid

Referenced by readBDB(), and readDS().

int GribFile::checkType ( const char *  filename  )  [static]

Attempts to determine the file type by parsing start of file.

Parameters:
filename The filename to check
Returns:
The type of file (WXP, WMO, RAW)

References WXP::File::close(), WXP::StrLib::equal(), WXP::File::isOpen(), WXP::File::open(), and WXP::File::read().

Referenced by open().

int GribFile::close (  ) 

Closes the file

References WXP::File::close().

Referenced by WXP::GridFile::close(), open(), ~GribFile(), and WXP::GridFile::~GridFile().

unsigned char GribFile::getByte ( int  loc  ) 

Gets a byte from the data buffer.

Parameters:
loc Location in buffer to retrieve byte.

Referenced by readBDB(), readBMB(), readBMS(), readDRS(), readGDB(), readGDS(), readIDS(), readPDB(), readPDS(), readSection(), and searchGRIB().

int GribFile::getHeader ( Grid grid  ) 

Reads in a single grid from the file (header data only).

Return values:
grid Grid object to put data into
Returns:
1=more data, 0=end of file

References WXP::File::getLine(), WXP::Grid::init(), next(), WXP::Wxp::outDebug(), readGDB(), readHeader(), readPDB(), WXP::File::seek(), WXP::Grid::setDomain(), and setPDB().

float GribFile::ibmFloatConv ( const unsigned char *  pc  )  [static]

Converts the IBM 370 floating point format. IBM format is: seee eeee mmmm mmmm mmmm mmmm mmmm mmmm x = (-1^s) * mmm.../s^24 * 16^(eeee-64)

Parameters:
pc IBM 370 Data value to convert.
Returns:
Actual floating point number

Referenced by readBDB(), and readPDB().

float GribFile::ieeeFloatConv ( const unsigned char *  pc  )  [static]

Converts the IEEE floating point format. IBM format is: seee eeee emmm mmmm mmmm mmmm mmmm mmmm x = (-1^s) * mmm.../s^24 * 2^(eeee-127)

Parameters:
pc Data value to convert.
Returns:
Actual floating point number

Referenced by readDRS().

int GribFile::init (  ) 

Initializes the class

Referenced by GribFile(), and open().

bool GribFile::isOpen (  ) 

Determines if file is open

Returns:
True if opened

Referenced by WXP::RadMask::getGrids(), and WXP::GridFile::open().

int GribFile::makeDatim ( Grid grid  ) 
int GribFile::makeInfo ( GribPDB pdb,
Grid grid 
)

Creates the info string in the Grid object from information in the GRIB

Parameters:
grid Grid object to update

References WXP::StrLib::append(), WXP::StrLib::clear(), WXP::String::get(), WXP::Grid::getForeTime(), WXP::Grid::getLevel(), WXP::Grid::setInfo(), WXP::Variable::toLabel(), WXP::Level::toLabel(), WXP::ForeTime::toVarLabel(), and WXP::String::valid().

Referenced by setPDB().

int GribFile::next (  ) 

Move to the next GRIB product in file.

References WXP::Wxp::outDebug(), and WXP::File::seek().

Referenced by getHeader(), and read().

int GribFile::open ( Filename filename  ) 
int GribFile::open ( const char *  filename  ) 

Opens the file.

Parameters:
filename Filename to open

References checkType(), close(), init(), WXP::File::isOpen(), WXP::File::open(), and WXP::FileAttr::READ.

int GribFile::read ( Grid grid  ) 
int GribFile::readBDB ( Grid grid  ) 

Processes the Binary Data Block. This block contains the actual gridpoint data.

Return values:
grid Grid to put data into

References WXP::Grid::allocData(), checkBMB(), WXP::DomainVal::dy, getByte(), WXP::Grid::getDomainVal(), WXP::Grid::getValue(), ibmFloatConv(), WXP::Const::MISS, WXP::DomainVal::nx, WXP::DomainVal::ny, WXP::Wxp::outDebug(), readBits(), readData(), scaleConv(), and WXP::Grid::setValue().

Referenced by read().

int GribFile::readBits (  ) 

Reads in a set number of bits from a datafile and returns a integer.

Returns:
Integer value from data buffer.

References WXP::Wxp::outDebug(), WXP::File::read(), and WXP::File::tell().

Referenced by readBDB(), and readDS().

int GribFile::readBMB (  ) 

Reads in the GRIB Bit Map Block and puts it into a BMB data buffer. The BMB tells which gridpoints contain valid data and which don't (MISS).

References getByte(), WXP::Wxp::outDebug(), WXP::File::read(), and readData().

Referenced by read().

int GribFile::readBMS (  ) 

Reads in the GRIB2 Bit Map Section

References getByte(), WXP::Wxp::outDebug(), WXP::File::read(), readData(), and seekData().

Referenced by read().

int GribFile::readData ( int  bytes  ) 

Reads in a set number of bytes from the data file into a data buffer.

Parameters:
bytes The number of bytes to read in.

References WXP::Wxp::outDebug(), WXP::Wxp::outWarning(), WXP::File::read(), and WXP::File::tell().

Referenced by readBDB(), readBMB(), readBMS(), readDRS(), readGDB(), readGDS(), readIDS(), readPDB(), readPDS(), readSection(), and searchGRIB().

int GribFile::readDRS (  ) 

Reads in the GRIB2 Data Representation Section

References getByte(), ieeeFloatConv(), WXP::Wxp::isDebug(), WXP::Wxp::outDebug(), WXP::Wxp::outWarning(), readData(), scaleConv(), and seekData().

Referenced by read().

int GribFile::readDS ( Grid grid  ) 
int GribFile::readGDB ( DomainVal dv  ) 
int GribFile::readGDS ( DomainVal dv  ) 
int GribFile::readHeader (  ) 

Reads in the grid header and position at the front of the GRIB data. This is dependent on the type of datafile and how the GRIB data is encapulated.

References WXP::StrLib::copy(), WXP::StrLib::equal(), WXP::File::getLine(), WXP::Wxp::outDebug(), searchGRIB(), WXP::File::skipLine(), and WXP::File::tell().

Referenced by getHeader(), and read().

int GribFile::readIDS ( GribPDB pdb  ) 

Reads in the GRIB2 Identification Section

Parameters:
pdb GribPDB object to put data

References WXP::DateVal::day, getByte(), WXP::DateVal::hour, WXP::DateVal::min, WXP::DateVal::month, WXP::Wxp::outDebug(), readData(), WXP::DateVal::sec, seekData(), and WXP::DateVal::year.

Referenced by read().

int GribFile::readPDB ( GribPDB pdb  ) 
int GribFile::readPDS ( GribPDB pdb  ) 
int GribFile::readSection (  ) 

Reads in the GRIB2 Section header

References getByte(), WXP::Wxp::outDebug(), WXP::Wxp::outWarning(), and readData().

Referenced by read().

float GribFile::scaleConv ( const unsigned char *  pc  )  [static]

Decodes the scale factor from GRIB. The scale factor is encoded as follows: seee eeee x = 2^((-1^s)*eeee)

Parameters:
pc Data values to convert
Returns:
Scale factor.

Referenced by readBDB(), and readDRS().

int GribFile::searchGRIB (  ) 

Searches for the keyword GRIB.

References WXP::StrLib::equal(), getByte(), WXP::Wxp::outDebug(), WXP::Wxp::outWarning(), readData(), and seekData().

Referenced by readHeader().

int GribFile::seekData ( int  val  ) 

Seeks to a specific location in the data buffer.

Parameters:
val Location to seek to.

References WXP::Wxp::outDebug().

Referenced by read(), readBMS(), readDRS(), readGDB(), readGDS(), readIDS(), readPDB(), readPDS(), and searchGRIB().

int GribFile::setDomain ( int  type,
DomainVal dv 
) [static]

Determines grid domain values from grid type

Parameters:
type The model type
Return values:
dv The domain values

References WXP::DomainVal::clat, WXP::DomainVal::clon, WXP::DomainVal::dx, WXP::DomainVal::dy, WXP::DomainVal::init(), WXP::Domain::LAMB, WXP::Domain::LATLON, WXP::DomainVal::nx, WXP::DomainVal::ny, WXP::DomainVal::param, WXP::DomainVal::plon, and WXP::DomainVal::proj.

Referenced by read().

int GribFile::setMaxBad ( int  val  ) 

Sets the maximum bad limit. This is used to determine how many values that vary wildly from the previous value to let go before the rest of the grid is determined to be bad. If the binary data are corrupt, the values from one gridpoint to another will start varying wildly. This is used to prevent coorrupted data from being used.

Parameters:
val Maximum number of suspected bad values to let go.
int GribFile::setPDB ( GribPDB pdb,
Grid grid 
)

Puts PDB information into the grid

Parameters:
pdb Product definition information
Return values:
grid Grid object to put data

References WXP::ModelName::get(), WXP::Grid::getSource(), makeDatim(), makeInfo(), WXP::Grid::setDate(), WXP::Grid::setForeTime(), WXP::Grid::setGenName(), WXP::Grid::setLevel(), WXP::Grid::setSource(), WXP::Grid::setType(), and WXP::Grid::setVersion().

Referenced by getHeader(), and read().

int GribFile::skipSection (  ) 

Skips over current GRIB2 Section

References WXP::File::seek().

Referenced by read().

int GribFile::useHdrFile ( bool  val  ) 

Sets whether to use header files

Parameters:
val Boolean setting whether to use header file or not

Referenced by WXP::GridFile::open(), and WXP::GridFile::useHdrFile().


The documentation for this class was generated from the following files:

Generated on 8 Jan 2010 for WXP C++ Library by  doxygen 1.6.1