ReFRACtor
|
This class reads and writes a HDF5 file. More...
#include <hdf_file.h>
Public Types | |
enum | Mode { READ, CREATE, READ_WRITE } |
Public Member Functions | |
HdfFile (const std::string &Fname, Mode M=READ) | |
Open the given file with the given mode. More... | |
virtual | ~HdfFile () |
void | close () |
Close the underlying file. More... | |
void | dimension_metadata (const std::string &Name, const std::string &Description, int Size) |
The SDOS products have a particular metadata convention where the information about each of the Dimensions that appear in the file are documented. More... | |
const std::string & | file_name () const |
File name. More... | |
H5::H5File & | h5_file () |
const H5::H5File & | h5_file () const |
bool | has_attribute (const std::string &Aname) const |
Check to see if a attribute is in the file. More... | |
bool | has_object (const std::string &Objname) const |
Check to see if an object (such as a Dataset) is in the file. More... | |
Mode | mode () const |
Mode file was opened with. More... | |
template<class T > | |
H5::PredType | pred_arr () const |
template<> | |
H5::PredType | pred_arr () const |
template<> | |
H5::PredType | pred_arr () const |
template<> | |
H5::PredType | pred_arr () const |
template<> | |
H5::PredType | pred_arr () const |
template<class T > | |
H5::PredType | pred_data () const |
template<> | |
H5::PredType | pred_data () const |
template<> | |
H5::PredType | pred_data () const |
template<> | |
H5::PredType | pred_data () const |
template<> | |
H5::PredType | pred_data () const |
void | print (std::ostream &Os) const |
std::string | print_to_string () const |
Print to string. More... | |
template<class T , int D> | |
blitz::Array< T, D > | read_attribute (const std::string &Aname) const |
Read the given attribute attached to a group or dataset. More... | |
template<class T > | |
T | read_attribute (const std::string &Aname) const |
Read the given attribute attached to a group or dataset. More... | |
template<class T , int D> | |
blitz::Array< T, D > | read_field (const std::string &Dataname) const |
Read a given field. More... | |
template<class T , int D> | |
blitz::Array< T, D > | read_field (const std::string &Dataname, const blitz::TinyVector< int, D > &Start, const blitz::TinyVector< int, D > &Size) const |
Read a given field. More... | |
template<class T > | |
T | read_field (const std::string &Dataname) const |
Read a given scalar field. More... | |
template<> | |
std::string | read_field (const std::string &Dataname) const |
template<class T , int D> | |
ArrayWithUnit< T, D > | read_field_with_unit (const std::string &Dataname) const |
Read a given field, along with metadata describing the units. More... | |
template<class T , int D> | |
ArrayWithUnit< T, D > | read_field_with_unit (const std::string &Dataname, const Unit &Default_unit) const |
Read a given field, along with metadata describing the units. More... | |
template<class T , int D> | |
ArrayWithUnit< T, D > | read_field_with_unit (const std::string &Dataname, const blitz::TinyVector< int, D > &Start, const blitz::TinyVector< int, D > &Size) const |
Read a given field, along with metadata describing the units. More... | |
template<class T , int D> | |
ArrayWithUnit< T, D > | read_field_with_unit (const std::string &Dataname, const Unit &Default_unit, const blitz::TinyVector< int, D > &Start, const blitz::TinyVector< int, D > &Size) const |
Adds ability to specify Start and Size along with default units. More... | |
template<int D> | |
blitz::TinyVector< int, D > | read_shape (const std::string &Dataname) const |
Reads the shape of a dataset. More... | |
Unit | read_units (const std::string &Dataname) const |
Read the units for a dataset. More... | |
void | shape_metadata (const std::string &Name, const std::string &Dim1) |
The SDOS products have a particular metadata convention where the information about each of the Shapes that appear in the file are documented. More... | |
void | shape_metadata (const std::string &Name, const std::string &Dim1, const std::string &Dim2) |
The SDOS products have a particular metadata convention where the information about each of the Shapes that appear in the file are documented. More... | |
void | shape_metadata (const std::string &Name, const std::string &Dim1, const std::string &Dim2, const std::string &Dim3) |
The SDOS products have a particular metadata convention where the information about each of the Shapes that appear in the file are documented. More... | |
template<class T , int D> | |
void | write_attribute (const std::string &Aname, const blitz::Array< T, D > &Data) |
Write attribute to file. More... | |
template<class T > | |
void | write_attribute (const std::string &Aname, const T &Data) |
Write attribute to file. More... | |
void | write_attribute (const std::string &Aname, const char *Data) |
template<class T , int D> | |
void | write_field (const std::string &Dataname, const blitz::Array< T, D > &Data) |
Write a given field. More... | |
template<int D> | |
void | write_field (const std::string &Dataname, const blitz::Array< std::string, D > &Data) |
template<int D> | |
void | write_field (const std::string &Dataname, const blitz::Array< const char *, D > &Data) |
template<class T > | |
void | write_field (const std::string &Dataname, const T &Data) |
Write a given field. More... | |
void | write_field (const std::string &Dataname, const std::string &Data) |
void | write_field (const std::string &Dataname, const char *Data) |
template<class T > | |
void | write_field (const std::string &Dataname, const T &Data, H5::DataType P) |
Write a given field. More... | |
template<class T , int D> | |
void | write_field (const std::string &Dataname, const blitz::Array< T, D > &Data, H5::DataType P) |
Write a given field. More... | |
Static Public Member Functions | |
static bool | is_hdf (const std::string &Fname) |
Return true if the given file is an HDF file. More... | |
This class reads and writes a HDF5 file.
Note that this is just a thin layer on top of the HDF 5 libraries to make the file operations we need to do in Level 2 Full Physics easier. There are many other things that can be done with a HDF 5 than what this class exposes.
Note that because it is what is used by Level 2 product, we produce data in 32 bit (either 32 bit integer or 32 bit floating point). On a 64 bit system, the underlying double and int are larger. We map between these types as needed transparently.
HDF supports both fixed length strings and variable length strings. We have the need to write both variable length strings and fixed length strings. As a convention, if std::string are passed we write as variable length. If const char* is passed, we determine the fixed length needed to accommodate the largest string passed and write the data as fixed strings of that length (padding shorter strings with spaces). This is an arbitrary decision, but it allows us to write both types.
Note that in what is a fairly odd convention, we add a trailing '\0' in our fixed length string, so there is one extra character.
Definition at line 39 of file hdf_file.h.
Enumerator | |
---|---|
READ | |
CREATE | |
READ_WRITE |
Definition at line 41 of file hdf_file.h.
Open the given file with the given mode.
Definition at line 261 of file hdf_file.cc.
|
inlinevirtual |
Definition at line 43 of file hdf_file.h.
|
inline |
Close the underlying file.
This is automatically done by the destructor, so you only need to call this if you want to force a close (e.g., for a unit test)
Definition at line 126 of file hdf_file.h.
void HdfFile::dimension_metadata | ( | const std::string & | Name, |
const std::string & | Description, | ||
int | Size | ||
) |
The SDOS products have a particular metadata convention where the information about each of the Dimensions that appear in the file are documented.
This function takes this metadata for dimension and puts it into the file.
Definition at line 463 of file hdf_file.cc.
|
inline |
File name.
Definition at line 131 of file hdf_file.h.
|
inline |
Definition at line 155 of file hdf_file.h.
|
inline |
Definition at line 156 of file hdf_file.h.
bool HdfFile::has_attribute | ( | const std::string & | Aname | ) | const |
Check to see if a attribute is in the file.
Determine if attribute is present.
Definition at line 363 of file hdf_file.cc.
|
inline |
Check to see if an object (such as a Dataset) is in the file.
Definition at line 48 of file hdf_file.h.
|
inlinestatic |
Return true if the given file is an HDF file.
Definition at line 137 of file hdf_file.h.
|
inline |
Mode file was opened with.
Definition at line 118 of file hdf_file.h.
H5::PredType FullPhysics::HdfFile::pred_arr | ( | ) | const |
|
inline |
Definition at line 184 of file hdf_file.h.
|
inline |
Definition at line 186 of file hdf_file.h.
|
inline |
Definition at line 188 of file hdf_file.h.
|
inline |
Definition at line 190 of file hdf_file.h.
H5::PredType FullPhysics::HdfFile::pred_data | ( | ) | const |
|
inline |
Definition at line 192 of file hdf_file.h.
|
inline |
Definition at line 194 of file hdf_file.h.
|
inline |
Definition at line 196 of file hdf_file.h.
|
inline |
Definition at line 198 of file hdf_file.h.
void HdfFile::print | ( | std::ostream & | Os | ) | const |
Definition at line 539 of file hdf_file.cc.
|
inlineinherited |
Print to string.
This is primarily useful for SWIG wrappers to this class, e.g. a to_s method in ruby.
Definition at line 31 of file printable.h.
|
inline |
Read the given attribute attached to a group or dataset.
Definition at line 206 of file hdf_file.h.
|
inline |
Read the given attribute attached to a group or dataset.
Definition at line 241 of file hdf_file.h.
|
inline |
Read a given field.
Definition at line 564 of file hdf_file.h.
blitz::Array< T, D > FullPhysics::HdfFile::read_field | ( | const std::string & | Dataname, |
const blitz::TinyVector< int, D > & | Start, | ||
const blitz::TinyVector< int, D > & | Size | ||
) | const |
Read a given field.
This reads a subset of the data, given by Start and Size.
Definition at line 646 of file hdf_file.h.
|
inline |
Read a given scalar field.
This is a array of size 1, which we return just the value in.
Definition at line 664 of file hdf_file.h.
|
inline |
Definition at line 684 of file hdf_file.h.
|
inline |
Read a given field, along with metadata describing the units.
Definition at line 575 of file hdf_file.h.
|
inline |
Read a given field, along with metadata describing the units.
Some data might be missing the units metadata field. For this variant of read_field_with_unit, this won't be treated as an error, but rather we will use the given default units instead.
Definition at line 608 of file hdf_file.h.
|
inline |
Read a given field, along with metadata describing the units.
Definition at line 589 of file hdf_file.h.
|
inline |
Adds ability to specify Start and Size along with default units.
Definition at line 626 of file hdf_file.h.
|
inline |
Reads the shape of a dataset.
Definition at line 553 of file hdf_file.h.
Unit HdfFile::read_units | ( | const std::string & | Dataname | ) | const |
Read the units for a dataset.
Definition at line 401 of file hdf_file.cc.
void HdfFile::shape_metadata | ( | const std::string & | Name, |
const std::string & | Dim1 | ||
) |
The SDOS products have a particular metadata convention where the information about each of the Shapes that appear in the file are documented.
This function takes this metadata for Shape and puts it into the file.
Definition at line 478 of file hdf_file.cc.
void HdfFile::shape_metadata | ( | const std::string & | Name, |
const std::string & | Dim1, | ||
const std::string & | Dim2 | ||
) |
The SDOS products have a particular metadata convention where the information about each of the Shapes that appear in the file are documented.
This function takes this metadata for Shape and puts it into the file.
Definition at line 491 of file hdf_file.cc.
void HdfFile::shape_metadata | ( | const std::string & | Name, |
const std::string & | Dim1, | ||
const std::string & | Dim2, | ||
const std::string & | Dim3 | ||
) |
The SDOS products have a particular metadata convention where the information about each of the Shapes that appear in the file are documented.
This function takes this metadata for Shape and puts it into the file.
Definition at line 508 of file hdf_file.cc.
|
inline |
Write attribute to file.
Definition at line 694 of file hdf_file.h.
|
inline |
Write attribute to file.
Definition at line 721 of file hdf_file.h.
|
inline |
Definition at line 888 of file hdf_file.h.
|
inline |
Write a given field.
If you give a group (e.g., "Group1/Field1"), then we automatically create the group if it doesn't already exist.
Definition at line 800 of file hdf_file.h.
|
inline |
Definition at line 807 of file hdf_file.h.
|
inline |
Definition at line 838 of file hdf_file.h.
|
inline |
Write a given field.
If you give a group (e.g., "Group1/Field1"), then we automatically create the group if it doesn't already exist.
This is a shortcut for writing an array that is exactly 1 element long, this is the same as calling write_field with a blitz::Array<T, 1> of size 1.
Definition at line 934 of file hdf_file.h.
|
inline |
Definition at line 940 of file hdf_file.h.
|
inline |
Definition at line 963 of file hdf_file.h.
|
inline |
Write a given field.
If you give a group (e.g., "Group1/Field1"), then we automatically create the group if it doesn't already exist.
This is a shortcut for writing an array that is exactly 1 element long, this is the same as calling write_field with a blitz::Array<T, 1> of size 1.
Definition at line 996 of file hdf_file.h.
|
inline |
Write a given field.
If you give a group (e.g., "Group1/Field1"), then we automatically create the group if it doesn't already exist.
This version lets you override the default type of the output data.
Definition at line 900 of file hdf_file.h.