WXP C++ Library Version 6.74.9
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
WXP::GribFile Class Reference

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

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

Public Types

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

Public Member Functions

 GribFile ()
 
 GribFile (const char *filename)
 
 GribFile (Filename &filename)
 
 ~GribFile ()
 
int init ()
 
bool isOpen ()
 
int setParam (const char *str)
 
int useHdrFile (bool val)
 
int setMaxBad (int val)
 
int setMissValue (float rmiss)
 
int setValueBits (int val)
 
int setWrap (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 writeBits (int val)
 
int write (Grid &grid)
 

Static Public Member Functions

static int checkType (const char *filename)
 
static float convIBMFloat (const unsigned char *pc)
 
static int convIBMFloat (float val, unsigned char *pc)
 
static float convIEEEFloat (const unsigned char *pc)
 
static float convScale (const unsigned char *pc)
 
static int convScale (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() [1/3]

GribFile::GribFile ( )

Constructor. Initializes class values.

References init().

◆ GribFile() [2/3]

GribFile::GribFile ( const char *  filename)

Constructor. Opens file for reading.

Parameters
filenameName of GRIB file to read from

References init().

◆ GribFile() [3/3]

GribFile::GribFile ( Filename filename)

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

Parameters
filenameFilename class containing filename info

References init().

◆ ~GribFile()

GribFile::~GribFile ( )

Destructor.

References close().

Member Function Documentation

◆ checkBMB()

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().

◆ checkType()

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

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

Parameters
filenameThe 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(), and open().

◆ close()

int GribFile::close ( )

◆ convIBMFloat() [1/2]

float GribFile::convIBMFloat ( const unsigned char *  dat)
static

Decodes 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
datIBM 370 float value to convert.
Returns
Actual floating point number

Referenced by readBDB(), and readPDB().

◆ convIBMFloat() [2/2]

int GribFile::convIBMFloat ( float  val,
unsigned char *  dat 
)
static

Converts val to 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
valData value to convert.
datIBM 370 float data

◆ convIEEEFloat()

float GribFile::convIEEEFloat ( const unsigned char *  dat)
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
datData value to convert.
Returns
Actual floating point number

Referenced by readDRS().

◆ convScale()

float GribFile::convScale ( const unsigned char *  dat)
static

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

Parameters
datData values to convert
Returns
Scale factor.

Referenced by readBDB(), and readDRS().

◆ getByte()

unsigned char GribFile::getByte ( int  loc)

Gets a byte from the data buffer.

Parameters
locLocation in buffer to retrieve byte.

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

◆ getHeader()

int GribFile::getHeader ( Grid grid)

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

Return values
gridGrid 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().

◆ getVersion()

int WXP::GribFile::getVersion ( )
inline

Get GRIB version number

◆ getWmoHdr()

const char * WXP::GribFile::getWmoHdr ( )
inline

Get WMO header

◆ init()

int GribFile::init ( )

Initializes the class

Referenced by GribFile(), GribFile(), GribFile(), open(), and open().

◆ isOpen()

bool GribFile::isOpen ( )

Determines if file is open

Returns
True if opened

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

◆ makeDatim()

int GribFile::makeDatim ( Grid grid)

◆ makeInfo()

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

◆ next()

int GribFile::next ( )

Move to the next GRIB product in file.

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

Referenced by getHeader(), and read().

◆ open() [1/2]

int GribFile::open ( const char *  filename)

Opens the file.

Parameters
filenameFilename to open

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

◆ open() [2/2]

int GribFile::open ( Filename filename)

◆ read()

int GribFile::read ( Grid grid)

◆ readBDB()

int GribFile::readBDB ( Grid grid)

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

Return values
gridGrid to put data into

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

Referenced by read().

◆ readBits()

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::File::read().

Referenced by readBDB(), and readDS().

◆ readBMB()

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().

◆ readBMS()

int GribFile::readBMS ( )

Reads in the GRIB2 Bit Map Section

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

Referenced by read().

◆ readData()

int GribFile::readData ( int  bytes)

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

Parameters
bytesThe 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().

◆ readDRS()

int GribFile::readDRS ( )

Reads in the GRIB2 Data Representation Section

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

Referenced by read().

◆ readDS()

int GribFile::readDS ( Grid grid)

◆ readGDB()

int GribFile::readGDB ( DomainVal dv)

◆ readGDS()

int GribFile::readGDS ( DomainVal dv)

◆ readHeader()

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().

◆ readIDS()

int GribFile::readIDS ( GribPDB pdb)

Reads in the GRIB2 Identification Section

Parameters
pdbGribPDB 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().

◆ readPDB()

int GribFile::readPDB ( GribPDB pdb)

◆ readPDS()

int GribFile::readPDS ( GribPDB pdb)

◆ readSection()

int GribFile::readSection ( )

Reads in the GRIB2 Section header

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

Referenced by read().

◆ searchGRIB()

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().

◆ seekData()

int GribFile::seekData ( int  val)

Seeks to a specific location in the data buffer.

Parameters
valLocation to seek to.

References WXP::Wxp::outDebug().

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

◆ setDomain()

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

Determines grid domain values from grid type

Parameters
typeThe model type
Return values
dvThe 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().

◆ setMaxBad()

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
valMaximum number of suspected bad values to let go.

◆ setPDB()

int GribFile::setPDB ( GribPDB pdb,
Grid grid 
)

Puts PDB information into the grid

Parameters
pdbProduct definition information
Return values
gridGrid 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(), and WXP::Grid::setVersion().

Referenced by getHeader(), and read().

◆ skipSection()

int GribFile::skipSection ( )

Skips over current GRIB2 Section

References WXP::File::seek().

Referenced by read().

◆ useHdrFile()

int GribFile::useHdrFile ( bool  val)

Sets whether to use header files

Parameters
valBoolean setting whether to use header file or not

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

◆ writeBits()

int GribFile::writeBits ( int  val)

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

Returns
Integer value from data buffer.

References WXP::File::write().


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