Public Member Functions | |
GribFileData (const string &name="", const string &mode="r", const bool open_file=false) | |
Open and initialize the file. | |
GribFileData (const GribFileData &fdata) | |
Copy constructor. | |
virtual | ~GribFileData () |
Destructor. | |
GribFileData & | operator= (const GribFileData &fdata) |
Affectation. | |
void | open_data_file () |
open the file in read mode and create the API handle | |
void | close_data_file () |
close the file and free the ressources used by it | |
const bool | is_file_loaded () |
Check if the file has already been loaded. | |
const bool | is_existing_dataset (const string &ds_name) |
check if ds_name is an existing dataset | |
const t_grib_var_desc & | get_dataset_desc (const string &ds_name) |
return a reference the related variable descriptor | |
string | get_msg_key (int i_msg, const string &key) |
for a given message, search the value of a key Raise an exception if the key does not exist | |
virtual void | get_dataset_fill_value (const string &dataset_name, void *fill_value) |
read the fill value of the dataset given in parametre | |
vector< int > | get_dataset_dimension (const string &dataset_name) |
access the size of the given dataset | |
int | get_n_dataset () |
return the number of datasets in the file | |
string | get_dataset_name (int i_dataset) |
get the short name of the record at index i | |
string | get_dataset_long_name (int i_dataset) |
get the extended name of the record at index i | |
string | get_dataset_level (int i_dataset) |
get the level of the record at index i | |
void | print_msg_keys (int i_msg, unsigned int keys_filter=GRIB_KEYS_ITERATOR_ALL_KEYS) |
print the keys of the message number i_msg The keys_filter parametre is set using the GRIB API constants as described in http://www.ecmwf.int/publications/manuals/grib_api/group__keys__iterator.html | |
void | get_msg_keys (int i_msg, vector< pair< string, string > > &v_keys, unsigned int keys_filter=GRIB_KEYS_ITERATOR_ALL_KEYS) |
print the keys of the message number i_msg The keys_filter parametre is set using the GRIB API constants as described in http://www.ecmwf.int/publications/manuals/grib_api/group__keys__iterator.html | |
void | print_keys (unsigned int keys_filter=GRIB_KEYS_ITERATOR_ALL_KEYS) |
display the keys of all messages The keys_filter parametre is set using the GRIB API constants as described in http://www.ecmwf.int/publications/manuals/grib_api/group__keys__iterator.html | |
int | get_dataset_data_type (string dataset_name) |
retrieve the native data type of the specified dataset | |
void | print_param_table (void) |
print all variables entries | |
void * | read_data (void *data, const char *dataset_name, int *start=NULL, int *stride=NULL, int *edges=NULL, int rank=-1) |
read a variable data | |
template<typename T > | |
T * | get_msg_data (const int i_msg, vector< int > &sz_dim, T *outdata=NULL) |
read the whole data buffer of a GRIB message Due to the GRIB format, the message is always read as double. The cast to T is done in a second time | |
const void | print_msg_data (const int i_msg) |
print out the data buffer (as double) of a message | |
void | init_selector (const char *ds_name, int *&start, int *&stride, int *&edges, int &rank, bool is_selector_allocated[3]) |
guess the Region Of Interest selectors start, stride and edges if their are NULL | |
void | free_selector (const bool *is_selector_allocated, int *start, int *stride, int *edges) |
frees the selectors that have been internally allocated | |
void | check_selector (const char *ds_name, int *start, int *stride, int *edges, const int rank) |
check the validity of the start, stride and edges selectors for the given datasets. It mainly checks if one is out of bounds. | |
void | get_scaling (int i_msg, double &scale, double &offset) |
retrieve the scaling factors of the given message | |
const int | get_n_msg () const |
return the number of messages (ie records) in the file | |
Protected Types | |
typedef map< string, t_grib_var_desc > | t_var_table |
Protected Attributes | |
FILE * | fd |
int | n_msg |
t_var_table | var_table |
Static Protected Attributes | |
static const string | var_name_id = "shortName" |
static const string | parameter_code_id = "paramId" |
static const string | parameter_name_id = "parameterName" |
static const string | fill_value_id = "missingValue" |
static const string | scale_factor_id = "scaleValuesBy" |
static const string | add_offset_id = "offsetValuesBy" |
static const string | x_dim_id = "Ni" |
static const string | y_dim_id = "Nj" |
static const string | level_type_id = "typeOfLevel" |
static const string | level_id = "level" |
static const string | data_flag_id = "dataFlag" |
static const string | data_width_id = "bitsPerValue" |
static const string | data_id = "values" |
read access in a GRIB1 or GRIB2 file There is some specific words used in GRIB files :
typedef map< string, t_grib_var_desc > GribFileData::t_var_table [protected] |
current processed message maps the parametres, using their names, to its variable descriptor
GribFileData::GribFileData | ( | const string & | name = "" , |
|
const string & | mode = "r" , |
|||
const bool | open_file = false | |||
) |
Open and initialize the file.
name | the filename of the file to be opened (including its path) | |
mode | the opening mode : "r", "w" or "rw". At this time, only the reading "r" mode is fully implemented | |
open_file | tell wether the file must be opened during the instantiation or not |
References close_data_file(), fd, n_msg, and open_data_file().
GribFileData::GribFileData | ( | const GribFileData & | fdata | ) |
void GribFileData::check_selector | ( | const char * | ds_name, | |
int * | start, | |||
int * | stride, | |||
int * | edges, | |||
const int | rank | |||
) |
check the validity of the start, stride and edges selectors for the given datasets. It mainly checks if one is out of bounds.
g_exception | in case of mismatch |
ds_name | name of the variable | |
start | indices of extraction start. If NULL, start at (0,0) if rank is 2 ; (0,0,0) if rank is 3... | |
stride | step between 2 read values. Ignored at this time | |
edges | number of values to read along each dimension. if NULL, it will be all data along each dimension. | |
rank | number of dimensions of the dataset |
References get_dataset_dimension().
Referenced by read_data().
void GribFileData::free_selector | ( | const bool * | is_selector_allocated, | |
int * | start, | |||
int * | stride, | |||
int * | edges | |||
) |
frees the selectors that have been internally allocated
is_selector_allocated | tells which selector between start, stride and edges are internally allocated, and so, which one to free | |
start | indices of extraction start. If NULL, start at (0,0) if rank is 2 ; (0,0,0) if rank is 3... | |
stride | step between 2 read values. Ignored at this time | |
edges | number of values to read along each dimension. if NULL, it will be all data along each dimension |
Referenced by read_data().
int GribFileData::get_dataset_data_type | ( | string | dataset_name | ) |
retrieve the native data type of the specified dataset
dataset_name | name of a dataset |
const t_grib_var_desc& GribFileData::get_dataset_desc | ( | const string & | ds_name | ) | [inline] |
return a reference the related variable descriptor
ds_name | name of a dataset |
Referenced by ECMWFFileData::get_nb_pressure_levels(), and ECMWFFileData::get_pressure_levels().
vector< int > GribFileData::get_dataset_dimension | ( | const string & | dataset_name | ) | [virtual] |
access the size of the given dataset
dataset_name | the name of the dataset |
Reimplemented from FileData.
References is_existing_dataset().
Referenced by check_selector().
void GribFileData::get_dataset_fill_value | ( | const string & | dataset_name, | |
void * | fill_value | |||
) | [virtual] |
read the fill value of the dataset given in parametre
dataset_name | the name of the dataset where to read the fill value | |
fill_value | (output) where to store the read value |
Reimplemented from FileData.
string GribFileData::get_dataset_level | ( | int | i_dataset | ) | [inline] |
get the level of the record at index i
i_dataset | index of the dataset |
References level_id.
string GribFileData::get_dataset_long_name | ( | int | i_dataset | ) | [inline] |
get the extended name of the record at index i
i_dataset | index of the dataset |
References parameter_name_id.
string GribFileData::get_dataset_name | ( | int | i_dataset | ) | [inline] |
get the short name of the record at index i
i_dataset | index of the dataset |
References var_name_id.
T * GribFileData::get_msg_data | ( | const int | i_msg, | |
vector< int > & | sz_dim, | |||
T * | outdata = NULL | |||
) |
read the whole data buffer of a GRIB message Due to the GRIB format, the message is always read as double. The cast to T is done in a second time
i_msg | indice of the message to read | |
sz_dim | number of values in the buffer along each dimensions, as [Y,X] | |
outdata | output buffer. If NULL, allocation is done internally. If not NULL, it is supposed to already have the good size and no control will be done on it |
References data_id, x_dim_id, and y_dim_id.
Referenced by read_data().
string GribFileData::get_msg_key | ( | int | i_msg, | |
const string & | key | |||
) |
for a given message, search the value of a key Raise an exception if the key does not exist
i_msg | indice of the searched message | |
key | the searched key |
References get_msg_keys().
Referenced by ECMWFFileData::init_grid().
void GribFileData::get_msg_keys | ( | int | i_msg, | |
vector< pair< string, string > > & | v_keys, | |||
unsigned int | keys_filter = GRIB_KEYS_ITERATOR_ALL_KEYS | |||
) |
print the keys of the message number i_msg The keys_filter parametre is set using the GRIB API constants as described in http://www.ecmwf.int/publications/manuals/grib_api/group__keys__iterator.html
i_msg | indice of the message to read | |
v_keys | [OUT] vector that stores the key = value pairs as strings | |
keys_filter | sets which type of keys should be printed. All are printed by default |
Referenced by get_msg_key(), and print_msg_keys().
int GribFileData::get_n_dataset | ( | ) | [inline] |
return the number of datasets in the file
const int GribFileData::get_n_msg | ( | ) | const [inline] |
return the number of messages (ie records) in the file
void GribFileData::get_scaling | ( | int | i_msg, | |
double & | scale, | |||
double & | offset | |||
) | [inline] |
retrieve the scaling factors of the given message
i_msg | indice of the searched message | |
scale | scale factor | |
offset | add offset |
References add_offset_id, and scale_factor_id.
void GribFileData::init_selector | ( | const char * | ds_name, | |
int *& | start, | |||
int *& | stride, | |||
int *& | edges, | |||
int & | rank, | |||
bool | is_selector_allocated[3] | |||
) |
guess the Region Of Interest selectors start, stride and edges if their are NULL
ds_name | [IN] name of the variable to read | |
start | [INOUT] indices of extraction start. If NULL, start at (0,0) if rank is 2 ; (0,0,0) if rank is 3... | |
stride | [INOUT] step between 2 read values. Ignored at this time | |
edges | [INOUT] number of values to read along each dimension. if NULL, it will be all data along each dimension. | |
rank | [INOUT] the number of dimensions of the dataset | |
is_selector_allocated | [INOUT] tells which selector between start, stride and edges are allocated in the method. Used to correctly free them after use |
Referenced by read_data().
const bool GribFileData::is_existing_dataset | ( | const string & | ds_name | ) | [inline] |
check if ds_name is an existing dataset
ds_name | name of a dataset |
Referenced by get_dataset_dimension(), and read_data().
GribFileData & GribFileData::operator= | ( | const GribFileData & | fdata | ) |
void GribFileData::print_keys | ( | unsigned int | keys_filter = GRIB_KEYS_ITERATOR_ALL_KEYS |
) |
display the keys of all messages The keys_filter parametre is set using the GRIB API constants as described in http://www.ecmwf.int/publications/manuals/grib_api/group__keys__iterator.html
keys_filter | sets which type of keys should be printed. All are printed by default |
References fd, is_file_loaded(), and FileData::name.
const void GribFileData::print_msg_data | ( | const int | i_msg | ) |
print out the data buffer (as double) of a message
i_msg | indice of the message to read |
void GribFileData::print_msg_keys | ( | int | i_msg, | |
unsigned int | keys_filter = GRIB_KEYS_ITERATOR_ALL_KEYS | |||
) |
print the keys of the message number i_msg The keys_filter parametre is set using the GRIB API constants as described in http://www.ecmwf.int/publications/manuals/grib_api/group__keys__iterator.html
i_msg | indice of the message to read | |
keys_filter | sets which type of keys should be printed. All are printed by default |
References get_msg_keys().
void * GribFileData::read_data | ( | void * | data, | |
const char * | dataset_name, | |||
int * | start = NULL , |
|||
int * | stride = NULL , |
|||
int * | edges = NULL , |
|||
int | rank = -1 | |||
) | [virtual] |
read a variable data
data | the output buffer of read values as float64 (void* is used for interfaces compatibility). If NULL, allocation is done internally | |
dataset_name | name of the variable to read | |
start | indices of extraction start. If NULL, start at (0,0) if rank is 2 ; (0,0,0) if rank is 3... | |
stride | step between 2 interesting values. Ignored at this time | |
edges | number of values to read along each dimension. if NULL, it will be all data along each dimension. | |
rank | the dimension of start, stride and edges |
Implements FileData.
References check_selector(), free_selector(), get_msg_data(), init_selector(), is_existing_dataset(), and is_file_loaded().
const string GribFileData::add_offset_id = "offsetValuesBy" [static, protected] |
scale offset key ID
Referenced by get_scaling().
const string GribFileData::data_flag_id = "dataFlag" [static, protected] |
binary data description flag key ID
const string GribFileData::data_id = "values" [static, protected] |
data values access key ID
Referenced by get_msg_data().
const string GribFileData::data_width_id = "bitsPerValue" [static, protected] |
number of bits used by a value key ID
FILE* GribFileData::fd [protected] |
low level file descriptor
Referenced by close_data_file(), GribFileData(), is_file_loaded(), open_data_file(), operator=(), and print_keys().
const string GribFileData::fill_value_id = "missingValue" [static, protected] |
fill value key ID
const string GribFileData::level_id = "level" [static, protected] |
pressure level key ID
Referenced by get_dataset_level().
const string GribFileData::level_type_id = "typeOfLevel" [static, protected] |
pressure type of level key ID. Type can be surface, isobaricInhPa or hybrid
int GribFileData::n_msg [protected] |
the GRIB API low level file handle total number of messages
Referenced by GribFileData().
const string GribFileData::parameter_code_id = "paramId" [static, protected] |
name of a parameter code key ID
const string GribFileData::parameter_name_id = "parameterName" [static, protected] |
int name of a parameter
Referenced by get_dataset_long_name().
const string GribFileData::scale_factor_id = "scaleValuesBy" [static, protected] |
scale factor key ID
Referenced by get_scaling().
const string GribFileData::var_name_id = "shortName" [static, protected] |
name of a parameter key ID
Referenced by get_dataset_name().
const string GribFileData::x_dim_id = "Ni" [static, protected] |
longitude dimension key ID
Referenced by get_msg_data().
const string GribFileData::y_dim_id = "Nj" [static, protected] |
latitude dimension key ID
Referenced by get_msg_data().