WXP C++ Library Version 6.74.9
|
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 |
This class reads in and decodes GRIB data.
GribFile::GribFile | ( | ) |
Constructor. Initializes class values.
References init().
GribFile::GribFile | ( | const char * | filename | ) |
Constructor. Opens file for reading.
filename | Name of GRIB file to read from |
References init().
GribFile::GribFile | ( | Filename & | filename | ) |
GribFile::~GribFile | ( | ) |
Destructor.
References close().
bool GribFile::checkBMB | ( | ) |
|
static |
Attempts to determine the file type by parsing start of file.
filename | The filename to check |
References WXP::File::close(), WXP::StrLib::equal(), WXP::File::isOpen(), WXP::File::open(), and WXP::File::read().
int GribFile::close | ( | ) |
Closes the file
References WXP::File::close(), and WXP::File::isOpen().
Referenced by WXP::GridFile::close(), open(), open(), ~GribFile(), and WXP::GridFile::~GridFile().
|
static |
|
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)
val | Data value to convert. |
dat | IBM 370 float data |
|
static |
|
static |
unsigned char GribFile::getByte | ( | int | loc | ) |
int GribFile::getHeader | ( | Grid & | grid | ) |
Reads in a single grid from the file (header data only).
grid | Grid object to put data into |
References WXP::File::getLine(), WXP::Grid::init(), next(), WXP::Wxp::outDebug(), readGDB(), readHeader(), readPDB(), WXP::File::seek(), WXP::Grid::setDomain(), and setPDB().
|
inline |
Get GRIB version number
|
inline |
Get WMO header
int GribFile::init | ( | ) |
Initializes the class
Referenced by GribFile(), GribFile(), GribFile(), open(), and open().
bool GribFile::isOpen | ( | ) |
Determines if file is open
Referenced by WXP::RadPlot::draw(), WXP::RadMask::getGrids(), WXP::GridFile::open(), and WXP::GridFile::open().
int GribFile::makeDatim | ( | Grid & | grid | ) |
Creates date/time string in Grid object from data in GRIB.
grid | The Grid object to update |
References WXP::ForeTime::ACC, WXP::Date::addSeconds(), WXP::ForeTime::ANAL, WXP::StrLib::append(), WXP::StrLib::aprintf(), WXP::ForeTime::AVG, WXP::StrLib::clear(), WXP::StrLib::copy(), WXP::ForeTime::FORE, WXP::String::get(), WXP::Grid::getDateVal(), WXP::Grid::getForeTime(), WXP::Date::getMinute(), WXP::ForeTime::getSeconds(), WXP::DateVal::hour, WXP::Const::MISS, WXP::Date::set(), WXP::ForeTime::set(), WXP::Grid::setDatim(), WXP::Date::toText(), WXP::ForeTime::toTimeLabel(), WXP::ForeTime::toTimeLabelDay(), and WXP::StrLib::valid().
Referenced by setPDB().
Creates the info string in the Grid object from information in the GRIB
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::Level::toLabel(), WXP::Variable::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 | ( | const char * | filename | ) |
Opens the file.
filename | Filename to open |
References checkType(), close(), init(), WXP::File::isOpen(), WXP::File::open(), and WXP::FileAttr::READ.
int GribFile::open | ( | Filename & | filename | ) |
Opens a file using a Filename object. Will use header file if available.
filename | The Filename object to get filename from |
References checkType(), close(), WXP::Filename::getDateval(), WXP::Filename::getHeader(), WXP::Filename::getName(), init(), WXP::File::isOpen(), WXP::DateVal::min, WXP::File::open(), WXP::FileAttr::READ, WXP::DateVal::sec, WXP::Date::set(), and WXP::Filename::validHeader().
int GribFile::read | ( | Grid & | grid | ) |
Reads in a single grid from the file.
grid | Grid object to put data into |
References WXP::File::getLine(), WXP::Grid::init(), WXP::Wxp::isDebug(), next(), WXP::Wxp::outDebug(), WXP::Wxp::outWarning(), readBDB(), readBMB(), readBMS(), readDRS(), readDS(), readGDB(), readGDS(), readHeader(), readIDS(), readPDB(), readPDS(), readSection(), WXP::File::seek(), seekData(), WXP::Grid::setDomain(), setDomain(), setPDB(), and skipSection().
Referenced by WXP::RadPlot::draw(), WXP::RadMask::getGrids(), and WXP::GridFile::read().
int GribFile::readBDB | ( | Grid & | grid | ) |
Processes the Binary Data Block. This block contains the actual gridpoint data.
grid | Grid 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().
int GribFile::readBits | ( | ) |
Reads in a set number of bits from a datafile and returns a integer.
References WXP::File::read().
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.
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 convIEEEFloat(), convScale(), getByte(), WXP::Wxp::outDebug(), WXP::Wxp::outWarning(), readData(), and seekData().
Referenced by read().
int GribFile::readDS | ( | Grid & | grid | ) |
Reads in the GRIB2 Data Section
References WXP::Grid::allocData(), checkBMB(), WXP::Grid::getNx(), WXP::Grid::getNy(), WXP::Grid::getValue(), WXP::Const::MISS, WXP::DomainVal::nx, WXP::DomainVal::ny, WXP::Wxp::outDebug(), WXP::Wxp::outWarning(), WXP::File::read(), readBits(), and WXP::Grid::setValue().
Referenced by read().
int GribFile::readGDB | ( | DomainVal & | dv | ) |
Reads in the GRIB Grid Definition Block
dv | DomainVal structure to put GDB data |
References WXP::DomainVal::clat, WXP::DomainVal::clon, WXP::DomainVal::dx, WXP::DomainVal::dy, getByte(), WXP::DomainVal::init(), WXP::Domain::LAMB, WXP::EarthPoint::lat, WXP::Domain::LATLON, WXP::EarthPoint::lon, WXP::Domain::MERC, WXP::DomainVal::nx, WXP::DomainVal::ny, WXP::Wxp::outDebug(), WXP::Wxp::outWarning(), WXP::DomainVal::param, WXP::DomainVal::plat, WXP::DomainVal::plon, WXP::DomainVal::proj, WXP::Domain::PSTEREO, readData(), seekData(), WXP::Domain::set(), WXP::Domain::tran(), WXP::Point::x, and WXP::Point::y.
Referenced by getHeader(), and read().
int GribFile::readGDS | ( | DomainVal & | dv | ) |
Reads in the GRIB2 Grid Definition Section
dv | DomainVal structure to put GDB data |
References WXP::DomainVal::clat, WXP::DomainVal::clon, WXP::DomainVal::dx, WXP::DomainVal::dy, getByte(), WXP::DomainVal::init(), WXP::Domain::LAMB, WXP::EarthPoint::lat, WXP::Domain::LATLON, WXP::EarthPoint::lon, WXP::Domain::MERC, WXP::DomainVal::nx, WXP::DomainVal::ny, WXP::Wxp::outDebug(), WXP::Wxp::outWarning(), WXP::DomainVal::param, WXP::DomainVal::plat, WXP::DomainVal::plon, WXP::DomainVal::proj, WXP::Domain::PSTEREO, readData(), seekData(), WXP::Domain::set(), WXP::Domain::tran(), WXP::Point::x, and WXP::Point::y.
Referenced by read().
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
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 | ) |
Reads in the GRIB Product Definition Block
pdb | GribPDB object to put data |
References WXP::ForeTime::ACC, WXP::ForeTime::ANAL, WXP::ForeTime::AVG, convIBMFloat(), WXP::DateVal::day, WXP::ForeTime::DAY, WXP::ForeTime::DIFF, WXP::ForeTime::FORE, getByte(), WXP::Variable::getInd(), WXP::Variable::getType(), WXP::Variable::getVal1(), WXP::Variable::getVal2(), WXP::Level::HAG, WXP::Level::HBG, WXP::DateVal::hour, WXP::ForeTime::HOUR, WXP::Level::HT, WXP::DateVal::min, WXP::ForeTime::MINUTE, WXP::Const::MISS, WXP::DateVal::month, WXP::ForeTime::MONTH, WXP::Level::MSL, WXP::Wxp::outDebug(), WXP::Level::PAG, WXP::Level::POT, WXP::Level::PR, readData(), WXP::ForeTime::RNG, WXP::DateVal::sec, seekData(), WXP::ForeTime::set(), WXP::Level::set(), WXP::Variable::setAbbr(), WXP::Variable::setInd(), WXP::Variable::setName(), WXP::Variable::setType(), WXP::Variable::setUnits(), WXP::Variable::setVal1(), WXP::Variable::setVal2(), WXP::Level::SIG, WXP::Level::toTypeCode(), and WXP::DateVal::year.
Referenced by getHeader(), and read().
int GribFile::readPDS | ( | GribPDB & | pdb | ) |
Reads in the GRIB2 Product Definition Section
pdb | GribPDB object to put data |
References WXP::ForeTime::ACC, WXP::ForeTime::ANAL, WXP::ForeTime::AVG, WXP::DateVal::computeSecs(), WXP::DateVal::day, WXP::ForeTime::DIFF, WXP::ForeTime::FORE, getByte(), WXP::Variable::getInd(), WXP::Variable::getType(), WXP::Variable::getVal1(), WXP::Variable::getVal2(), WXP::Level::HBG, WXP::DateVal::hour, WXP::Wxp::isDebug(), WXP::ForeTime::MAX, WXP::DateVal::min, WXP::ForeTime::MIN, WXP::Const::MISS, WXP::DateVal::month, WXP::Level::NONE, WXP::Wxp::outDebug(), WXP::Wxp::outWarning(), WXP::Level::PAG, WXP::Level::POT_VORT, WXP::Level::PR, readData(), WXP::ForeTime::RNG, WXP::DateVal::sec, seekData(), WXP::ForeTime::set(), WXP::Level::set(), WXP::Variable::setAbbr(), WXP::Variable::setInd(), WXP::Variable::setName(), WXP::Variable::setType(), WXP::Variable::setUnits(), WXP::Variable::setVal1(), WXP::Variable::setVal2(), WXP::Level::SFC, and WXP::DateVal::year.
Referenced by read().
int GribFile::readSection | ( | ) |
Reads in the GRIB2 Section header
References getByte(), WXP::Wxp::outDebug(), WXP::Wxp::outWarning(), and readData().
Referenced by read().
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.
val | Location to seek to. |
References WXP::Wxp::outDebug().
Referenced by read(), readBMS(), readDRS(), readGDB(), readGDS(), readIDS(), readPDB(), readPDS(), and searchGRIB().
|
static |
Determines grid domain values from grid type
type | The model type |
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.
val | Maximum number of suspected bad values to let go. |
Puts PDB information into the grid
pdb | Product definition information |
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(), and WXP::Grid::setVersion().
Referenced by getHeader(), and read().
int GribFile::skipSection | ( | ) |
int GribFile::useHdrFile | ( | bool | val | ) |
Sets whether to use header files
val | Boolean setting whether to use header file or not |
Referenced by WXP::RadMask::getGrids(), WXP::GridFile::open(), and WXP::GridFile::useHdrFile().
int GribFile::writeBits | ( | int | val | ) |
Reads in a set number of bits from a datafile and returns a integer.
References WXP::File::write().