#include <hdffiledata.h>
Public Member Functions | |
HDFFileData (const string &name="", const string &mode="r", const bool open_file=false) | |
Open and initialize the file. | |
HDFFileData (const HDFFileData &hfd) | |
Copy constructor. | |
virtual | ~HDFFileData () |
Destructor. | |
HDFFileData & | operator= (const HDFFileData &hfd) |
Affectation. | |
Hdf_file * | get_hdf_file () |
accessor to the Hdf_file object. | |
void | load_hdf_file () |
open the hdf file in reading mode. Instantiates a Hdf_file object. | |
void | free_hdf_file () |
close the hdf file, and free the ressources used by it | |
const bool | is_hdf_file_loaded () |
Check if the hdf file has already been loaded. | |
HDFFileMetaData * | get_metadata () |
access to the HDF file metadata. | |
void | load_hdf_metadata () |
Read the metadata contained in the hdf file and put them in a tree. | |
void | free_hdf_metadata () |
Release the metadata tree If the metadata haven't been loaded, nothing's done. | |
const bool | is_hdf_metadata_loaded () |
Check if the metadata' tree have already been constructed. | |
virtual void | get_dataset_fill_value (const string &sds_name, void *fill_value) |
read the fill value of the sds given in parametre | |
vector< int > | get_sds_dimension (const string &sds_name) |
access the size of the given sds | |
virtual vector< int > | get_dataset_dimension (const string &sds_name) |
return the given dataset size along each axis | |
vector< int > | get_vdata_dimension (const string &vdata_name) |
access the size of a vdata It returns a 2 values vector like this {nb of vdata records, nb of fields}. It doesn't change if the fields have an order bigger than one. | |
int | get_n_dataset () |
string | get_dataset_name (int i) |
Hdf_sds | get_dataset (string sds_name) |
int | get_dataset_data_type (string sds_name) |
string | get_values_attr_dataset (string sds_name, string attr_name) |
bool | has_attr_dataset (string sds_name, string attr_name) |
void | close_data_file () |
closes the file | |
void | open_data_file () |
open the file | |
string | get_values_attr (string attr_name) |
string | get_file_attr (string attr_name) |
bool | has_attr (string attr_name) |
bool | has_file_attr (string attr_name) |
template<class T > | |
T | get_var_value (const string sds_name, const int &y_index, const int &x_index) |
template<class T > | |
T | get_value_0D (const char *sds_name="Height", int *start=NULL, int *stride=NULL, int *edges=NULL, int &rank=-1) |
template<class T > | |
vector< T > * | get_value_1D (const char *sds_name="Height", int *start=NULL, int *stride=NULL, int *edges=NULL, int &rank=-1) |
template<class T > | |
vector< vector< T > > * | get_value_2D (const char *sds_name="Height", int *start=NULL, int *stride=NULL, int *edges=NULL, int &rank=-1) |
virtual void * | read_data (void *data, const char *sds_name, int *start=NULL, int *stride=NULL, int *edges=NULL, int rank=-1) |
template<typename DataType > | |
DataType * | read_data (DataType *data, const char *sds_name, int *start=NULL, int *stride=NULL, int *edges=NULL, int rank=-1) |
method to read the data of an sds similar to void* read_data(...) This method add a test on the validity of the ouput buffer type compared to the sds one. | |
void * | read_vdata (void *data, const char *vdata_name="", const char *vdata_field="", int start=0, int edges=-1) |
read the data of an hdf VData Field
| |
void | get_fillValue (const string &sds_name, void *fillValue) |
read the given dataset's fill value | |
void | get_scaling (const string &sds_name, float64 &scale, float64 &offset) |
template<typename T > | |
T * | read_data (T *data, const char *sds_name, int *start, int *stride, int *edges, int rank) |
Protected Member Functions | |
template<class T > | |
const vector< int > | get_nearest_index (const vector< T > &v_data, const T &val=T(0)) |
template<class T > | |
const int | get_nearest_index (const vector< T > *data, const T val) |
template<class T > | |
const int | get_nearest_index (const T *data=NULL, const int data_size=0, const T val=T(0)) |
void | init_read_write_null_input_param (const char *sds_name, int *&start, int *&stride, int *&edges, int &rank, bool *initialized_values) |
void | free_read_write_allocations (const bool *are_limits_initialized, int *start, int *stride, int *edges) |
const bool | check_read_write_limits (const char *sds_name, int *start, int *stride, int *edges, const int rank) |
Protected Attributes | |
Hdf_file * | hdf_file |
HDFFileMetaData * | metadata |
Manage the opening, reading, and accessing to the data in a HDF File. This class encapsulates the Hdf_file class, developped by Fabrice Ducos (fabrice.ducos@icare.univ-lille1.fr), which is a lower level interface to HDF.
How to do some useful actions :
> in a C way (with static arrays)
HDFFileData my_hdf=HDFFileData("path_to_desired_hdf_file"); // open the file for reading
Some remarks :
float32 *data =NULL; // define buffer where to put the read data
data=read_data(static_cast<void*>(data),"Name_Of_The_Sds"); // read the sds' data
make your stuff with the data here
delete[] data; // don't forget to free the data after use
> in a C++ way (with STL's vectors)
HDFFileData my_hdf=HDFFileData("path_to_desired_hdf_file"); // open the file for reading
Some remarks :
Vector < T > *v_data=get_value_XD<T>("Name_Of_The_Sds"); // fill a vector with the read data
make your stuff with the data vector here
delete v_data; // don't forget to free the data after use
HDFFileData::HDFFileData | ( | 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). Ex : "/home/kiki/my_file.hdf" | |
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 hdf_file, load_hdf_file(), load_hdf_metadata(), and metadata.
HDFFileData::HDFFileData | ( | const HDFFileData & | hfd | ) |
Copy constructor.
hfd | the HDFFileData object to be recopied. |
void HDFFileData::free_read_write_allocations | ( | const bool * | are_limits_initialized, | |
int * | start, | |||
int * | stride, | |||
int * | edges | |||
) | [protected] |
free the allocations made by the init_read_write_null_input_param methods
Referenced by MODISFileData::read_calibrated_data(), and read_data().
virtual vector<int> HDFFileData::get_dataset_dimension | ( | const string & | sds_name | ) | [inline, virtual] |
return the given dataset size along each axis
ds_name | [IN] dataset name |
Reimplemented from FileData.
References get_sds_dimension().
void HDFFileData::get_dataset_fill_value | ( | const string & | sds_name, | |
void * | fill_value | |||
) | [virtual] |
read the fill value of the sds given in parametre
sds_name | the name of the sds where to read the fill value | |
fill_value | (output) where to store the read value |
Reimplemented from FileData.
References get_hdf_file(), is_hdf_file_loaded(), and load_hdf_file().
Referenced by MODISFileData::read_calibrated_data().
void HDFFileData::get_fillValue | ( | const string & | sds_name, | |
void * | fillValue | |||
) | [virtual] |
Hdf_file * HDFFileData::get_hdf_file | ( | ) |
accessor to the Hdf_file object.
References hdf_file, is_hdf_file_loaded(), and load_hdf_file().
Referenced by get_dataset_fill_value(), and GMAOFileData::get_sds_fill_value().
HDFFileMetaData * HDFFileData::get_metadata | ( | ) |
access to the HDF file metadata.
References is_hdf_metadata_loaded(), load_hdf_metadata(), and metadata.
const vector< int > HDFFileData::get_nearest_index | ( | const vector< T > & | v_data, | |
const T & | val = T(0) | |||
) | [protected] |
find the indexes of the values that are the nearest to val. REM if the return vector have many indexes, the values at those indexes are equal.
v_data | the vector that contains the data to be processed | |
val | the value we are searching for the nearest values in v_data |
const int HDFFileData::get_nearest_index | ( | const vector< T > * | data, | |
const T | val | |||
) | [protected] |
search in a vector the nearest value to val, and retrun its index
data | the vector where must be processed the search | |
val | the value wa are searching for the nearset one |
const int HDFFileData::get_nearest_index | ( | const T * | data = NULL , |
|
const int | data_size = 0 , |
|||
const T | val = T(0) | |||
) | [protected] |
search in a vector the nearest value to val, and retrun its index
data | the array where must be processed the search | |
data_size | the number of values of the array | |
val | the value wa are searching for the nearset one |
vector< int > HDFFileData::get_sds_dimension | ( | const string & | sds_name | ) |
access the size of the given sds
sds_name | the name of the sds |
References free_hdf_file(), hdf_file, is_hdf_file_loaded(), and load_hdf_file().
Referenced by get_dataset_dimension().
T HDFFileData::get_value_0D | ( | const char * | sds_name = "Height" , |
|
int * | start = NULL , |
|||
int * | stride = NULL , |
|||
int * | edges = NULL , |
|||
int & | rank = -1 | |||
) |
In the opened file, read the value of the sds called "sds_name" at the point "start". BE CAREFUL : this array must be given using the order ...[Z][Y][X]. This method is a template, so you have also to precise the data type of the read value while calling it.
If you are trying to read a value in a 2D sds, please refer to the get_var_value method. It's a simplest front-end to this method.
An examples is clearest :
long start[] = {16,25}; // start position
long rank = 2; // the dimension of start
float32 val = hfd.get_value_0D<float32>("Latitude",start,NULL,NULL,rank);
It will read the data of the sds "Latitude", that is composed of float32 values at the position (16,25) using (Y,X) convention (ie (lat,lon)).
sds_name | the name of the sds (Scientific Data Set) we want to access. | |
start | begining of the selection. If NULL, start at (0,0) if rank is 2 ; (0,0,0) if rank is 3... | |
stride | step between 2 interesting values. If NULL, this step is set to 1 in each dimension (ie all values will be read) | |
edges | number of values to be read in each dimension. if NULL, it will be all data along each dimension. | |
rank | the dimension of start |
vector< T > * HDFFileData::get_value_1D | ( | const char * | sds_name = "Height" , |
|
int * | start = NULL , |
|||
int * | stride = NULL , |
|||
int * | edges = NULL , |
|||
int & | rank = -1 | |||
) |
In the opened file, read the values of the sds called "sds_name", starting at the point "start", reading "edges" values, with a step of "stride" between each values. BE CAREFUL : those array values must be given using the order ...[Z][Y][X]. The result data must be a 1D array. If it isn't the case, an error message will prevent you. This method is a template, so you have also to precise the data type of the read values while calling it.
Some examples are clearest : ----------------------------- EXAMPLE 1 ----------------------------
long start[] = {3,0}; // start position
long stride[] = {2,1}; // step between 2 values
long edges[] = {35,1}; // number of values to be read
long rank = 2; // the dimension of start,stride and edges
vector<float32> *v = hfd.get_value_1D<float32>("Latitude",start,stride,edges,rank);
It will read the data of the sds "Latitude", that is composed of float32 values.
----------------------------- EXAMPLE 2 ----------------------------
long start[] = {0,0,0}; // start position
long stride[] = {1,1,1}; // same result if NULL, and even a little bit faster : by default, the step between 2 values is 1
long edges[] = {20,1,1}; // number of values to be read
long rank = 3; // the dimension of start,stride and edges
vector<uint8> *v = hfd.get_value_1D<uint8>("Nb_Layer_Found",start,stride,edges,rank);
It will read the data of the sds "Nb_Layer_Found", that is composed of uint8 values.
TODO----------------------------- EXAMPLE 3 : USING DEFAULT VALUES (not available yet) ---------------------------- TODO
vector<float32> *v = get_value_1D<float32>("Top_Layer_Height",NULL,NULL,NULL,1);
TODO It will return the whole data of type float32 contained in the sds named "Top_Layer_Height". TODO REM : In this case, the sds "Top_Layer_Height" must have a dimension of 1, because the read values' vector must have a dimension of 1.
sds_name | the name of the sds (Scientific Data Set) we want to access. | |
start | begining of the selection. If NULL, start at (0,0) if rank is 2 ; (0,0,0) if rank is 3... | |
stride | step between 2 interesting values. If NULL, this step is set to 1 in each dimension (ie all values will be read) | |
edges | number of values to be read in each dimension. if NULL, it will be all data along each dimension. | |
rank | the dimension of start, stride and edges |
vector< vector< T > > * HDFFileData::get_value_2D | ( | const char * | sds_name = "Height" , |
|
int * | start = NULL , |
|||
int * | stride = NULL , |
|||
int * | edges = NULL , |
|||
int & | rank = -1 | |||
) |
In the opened file, read the values of the sds called "sds_name", starting at the point "start", reading "edges" values, with a step of "stride" between each values. BE CAREFUL : those array values must be given using the order ...[Z][Y][X]. The result data must be a 1D array. If it isn't the case, an error message will prevent you. This method is a template, so you have also to precise the data type of the read values while calling it.
Some examples are clearest : ----------------------------- EXAMPLE 1 ----------------------------
long start[] = {3,0}; // start position
long stride[] = {2,1}; // step between 2 values
long edges[] = {35,2}; // number of values to be read
long rank = 2; // the dimension of start,stride and edges
vector<float32> *v = hfd.get_value_2D<float32>("Latitude",start,stride,edges,rank);
It will read the data of the sds "Latitude", that is composed of float32 values.
----------------------------- EXAMPLE 2 ----------------------------
long start[] = {0,0,0}; // start position
long stride[] = {1,1,1}; // same result if NULL, and even a little bit faster : by default, the step between 2 values is 1
long edges[] = {1,20,15}; // number of values to be read
long rank = 3; // the dimension of start,stride and edges
vector<uint8> *v = hfd.get_value_2D<uint8>("Nb_Layer_Found",start,stride,edges,rank);
It will read the data of the sds "Nb_Layer_Found", that is composed of uint8 values.
In this example, the sense of the return vector will be : the number of cloud's layers found along (20,15) lat_lon mesures.
TODO----------------------------- EXAMPLE 3 : USING DEFAULT VALUES (not available yet) ---------------------------- TODO
vector<float32> *v = get_value_2D<float32>("Longitude",NULL,NULL,NULL,2);
TODO It will return the whole data of type float32 contained in the sds named "Longitude". TODO REM : In this case, the sds "Longitude" must have a dimension of 2, because the read values' vector must have a dimension of 2.
sds_name | the name of the sds (Scientific Data Set) we want to access. | |
start | begining of the selection. If NULL, start at (0,0) if rank is 2 ; (0,0,0) if rank is 3... | |
stride | step between 2 interesting values. If NULL, this step is set to 1 in each dimension (ie all values will be read) | |
edges | number of values to be read in each dimension. if NULL, it will be all data along each dimension. | |
rank | the dimension of start, stride and edges |
T HDFFileData::get_var_value | ( | const string | sds_name, | |
const int & | y_index, | |||
const int & | x_index | |||
) |
Read a value in a sds directly using its y_index and x_index. This method is a convenience method to access to a 2D sds. This method is a template, so you have also to precise the data type of the read value while calling it. Ex :
float32 v = get_var_value<float32>("Latitude",12,1);
will read in the sds "Latitude" the value at (12,1) using (Y,X) convention
vector< int > HDFFileData::get_vdata_dimension | ( | const string & | vdata_name | ) |
access the size of a vdata It returns a 2 values vector like this {nb of vdata records, nb of fields}. It doesn't change if the fields have an order bigger than one.
vdata_name | the name of the vdata |
References free_hdf_file(), hdf_file, is_hdf_file_loaded(), and load_hdf_file().
Referenced by read_vdata().
void HDFFileData::init_read_write_null_input_param | ( | const char * | sds_name, | |
int *& | start, | |||
int *& | stride, | |||
int *& | edges, | |||
int & | rank, | |||
bool * | initialized_values | |||
) | [protected] |
initialize NULL parametres in read_data methods for a specific sds :
References hdf_file.
Referenced by MODISFileData::read_calibrated_data(), and read_data().
const bool HDFFileData::is_hdf_metadata_loaded | ( | ) |
Check if the metadata' tree have already been constructed.
References metadata.
Referenced by get_metadata(), and MODISFileData::set_lat_lon_min_max().
HDFFileData & HDFFileData::operator= | ( | const HDFFileData & | hfd | ) |
Affectation.
hfd | the HDFFileData object to be recopied. |
DataType* HDFFileData::read_data | ( | DataType * | data, | |
const char * | sds_name, | |||
int * | start = NULL , |
|||
int * | stride = NULL , |
|||
int * | edges = NULL , |
|||
int | rank = -1 | |||
) |
method to read the data of an sds similar to void* read_data(...)
This method add a test on the validity of the ouput buffer type compared to the sds one.
data | ||
sds_name | ||
start | ||
stride | ||
edges | ||
rank |
void * HDFFileData::read_data | ( | void * | data, | |
const char * | sds_name, | |||
int * | start = NULL , |
|||
int * | stride = NULL , |
|||
int * | edges = NULL , |
|||
int | rank = -1 | |||
) | [virtual] |
Read the data in a HDF file. Similar to get_value_nD methods, but in a C way : this method fills an array and doesn't use a std::vector. Some examples are clearest : ----------------------------- EXAMPLE 1 ----------------------------
long Y_LENGTH = 2;
long X_LENGTH = 35;
long start[] = {3,0}; // start position
long stride[] = {2,1}; // step between 2 values
long edges[] = {X_LENGTH,Y_LENGTH}; // number of values to be read
long rank = 2; // the dimension of start,stride and edges
float32 data[Y_LENGTH][X_LENGTH]; // buffer where to put the read data
hfd.read_data((void*)data,"Latitude",start,stride,edges,rank);
It will read the data of the sds "Latitude", that is composed of float32 values.
----------------------------- EXAMPLE 2 ----------------------------
long Z_LENGTH = 1;
long Y_LENGTH = 20;
long X_LENGTH = 15;
long start[] = {0,0,0}; // start position
long stride[] = {1,1,1}; // same result if NULL, and even a little bit faster : by default, the step between 2 values is 1
long edges[] = {Z_LENGTH,Y_LENGTH,X_LENGTH}; // number of values to be read
long rank = 3; // the dimension of start,stride and edges
uint8 data[Z_LENGTH][Y_LENGTH][X_LENGTH]; // buffer where to put the read data
hfd.read_data((void*)data,"Nb_Layer_Found",start,stride,edges,rank);
It will read the data of the sds "Nb_Layer_Found", that is composed of uint8 values.
----------------------------- EXAMPLE 3 : USING DEFAULT VALUES ---------------------------- float32 *data = NULL; // buffer where to put the read data
It will read the whole data of type float32 contained in the sds named "Longitude". The method manages the allocation of the data' array
data=(float32*)hfd.read_data((void*)data,"Longitude");// the method allocates the needed memory
// Do what you have to do with data here
delete[] data;// Don't forget to free the memory once used
data | the buffer to fill with the read values | |
sds_name | the name of the sds (Scientific Data Set) we want to access. | |
start | begining of the selection. If NULL, start at (0,0) if rank is 2 ; (0,0,0) if rank is 3... | |
stride | step between 2 interesting values. If NULL, this step is set to 1 in each dimension (ie all values will be read) | |
edges | number of values to be read in each dimension. if NULL, it will be all data along each dimension. | |
rank | the dimension of start, stride and edges |
Implements FileData.
References free_hdf_file(), free_read_write_allocations(), hdf_file, init_read_write_null_input_param(), is_hdf_file_loaded(), and load_hdf_file().
Referenced by IIRFileData::get_latitude_data(), IIRFileData::get_longitude_data(), IIRFileData::get_time_data(), PMFileData::load_geolocation_data(), MODISFileData::load_geolocation_data(), IIRFileData::load_geolocation_data(), DARDARFileData::load_geolocation_data(), CLOUDSATFileData::load_geolocation_data(), CERESFileData::load_geolocation_data(), CALIOPFileData::load_geolocation_data(), CALIOPFileData::load_viewing_directions_data(), and MODISFileData::read_calibrated_data().
void * HDFFileData::read_vdata | ( | void * | data, | |
const char * | vdata_name = "" , |
|||
const char * | vdata_field = "" , |
|||
int | start = 0 , |
|||
int | edges = -1 | |||
) |
read the data of an hdf VData Field
Here is a example :
float32 *data = NULL; // buffer where to put the read data. Set it to NULL to let the method allocate it
data=(float32)hfd.read_vdata((VOIDP)data,"Longitude");// the method allocates the needed memory. Remark that data s set to the method's return value. It works in a malloc way. That's why you also have to cast it
// Do what you have to do with data
delete[] data;// Don't forget to free the memory once used
data | the data buffer. Can be NULL. In this case, the allocation is done by the method. In this case, the caller MUST delete the buffer once | |
vdata_name | the name of the VData | |
vdata_field | the name of the field | |
start | the start point. default : 0 : the record start | |
edges | the number of values to read in all direction. If -1 (default), will read all records |
References free_hdf_file(), get_vdata_dimension(), hdf_file, is_hdf_file_loaded(), and load_hdf_file().
Referenced by CLOUDSATFileData::load_geolocation_data().
Hdf_file* HDFFileData::hdf_file [protected] |
the lower level access class to the file we are working on. Can be NULL. In this case, to access the data, call the load_hdf_file method first
Referenced by free_hdf_file(), get_fillValue(), get_hdf_file(), MODISFileData::get_sds_calibration(), get_sds_dimension(), get_vdata_dimension(), HDFFileData(), init_read_write_null_input_param(), is_hdf_file_loaded(), load_hdf_file(), load_hdf_metadata(), operator=(), MODISFileData::read_calibrated_data(), read_data(), PMFileData::read_node_lon(), read_vdata(), MODISFileData::set_lat_lon_index_max(), and CERESFileData::set_lat_lon_index_max().
HDFFileMetaData* HDFFileData::metadata [protected] |
a tree representing the metadata of the file. Can be NULL. In this case, to access the data, call the load_hdf_metadata method first
Referenced by free_hdf_metadata(), get_metadata(), HDFFileData(), is_hdf_metadata_loaded(), load_hdf_metadata(), operator=(), MODISFileData::set_gring(), MODISFileData::set_lat_lon_min_max(), and CALIOPFileData::set_lat_lon_min_max().