#include <HDF_fwd.hpp>
Simplified HDF5 I/O utilities.
This class is a wrapper around the HDF5 C library, for simplified reading and writing.
This class represents a HDF reader and writer: it knows which file (open or closed) and which group (open or closed) are the ones that are to be read from/written to. Any calls to read*
or write*
methods write to that group in that file. The file and group can be opened, closed or changed during the lifetime of the object, with user's responsibility being that they are open when writing to/reading from it.
In addition atomic() method can be used to perform open/read/close
or open/write/close
cycle in one line.
Raw C identifiers are exposed with getFileID() and getGroupID() methods and can be used to perform any action not directly supported by this class.
All write
methods create the datasets or attributes required. They also have an overwrite
parameter which is set to false
by default. This means that any attempt to write to an existing object will fail an assertion to prevent accidental deletions of existing data. This can be disabled by setting overwrite = true
, allowing one to overwrite existing data.
All open objects are closed upon destruction.
Usage example:
Definition at line 75 of file HDF_fwd.hpp.
Public Member Functions | |
HDF () | |
Construct an empty HDF reader. More... | |
HDF (std::string filename, Mode mode=APPEND) | |
Construct a HDF reader and open filename with given mode . More... | |
~HDF () | |
Closes all opened objects, by using close(). More... | |
void | open (const std::string &filename, const std::string &group_name="/", Mode mode=APPEND) |
Opens given file and group. More... | |
void | openFile (const std::string &filename, Mode mode=APPEND) |
Opens a given file with a given mode. More... | |
void | reopenFile (Mode mode=APPEND) |
Reopens the current file. More... | |
void | openGroup (std::string group_name) |
Open given group, closing any previously opened group(). More... | |
void | reopenGroup () |
Reopens current group. More... | |
void | reopen (Mode mode=APPEND) |
Reopens current file and group. More... | |
bool | isFileOpen () const |
Returns true is currently specified file is open and false otherwise. More... | |
bool | isGroupOpen () const |
Returns true is currently specified group is open and false otherwise. More... | |
void | flush () const |
Flush opened file, if it is open. More... | |
void | closeGroup () const |
Closes current group, if open. More... | |
void | closeFile () const |
Closes current file and all objects associated with it (e.g. the group), if open. More... | |
void | close () const |
Closes all open objects. Alias of closeFile(). More... | |
const std::string & | filename () const |
Get current filename. More... | |
const std::string & | fileName () const |
Alias of filename(). More... | |
void | setFilename (const std::string &filename) |
Sets new filename without opening the new file. Any previously opened file is closed. More... | |
void | setFileName (const std::string &filename) |
Alias of setFilename(). More... | |
const std::string & | groupName () const |
Get current group name. More... | |
void | setGroupName (const std::string &group_name) |
Set new group name without opening the new group. Any previously opened group is closed. More... | |
template<class T > | |
T | readAttribute (const std::string &attr_name) const |
Read attribute given by attr_name . More... | |
template<class T > | |
void | writeAttribute (const std::string &attr_name, const T &value, const hid_t &type, bool overwrite=false) const |
Writes given attribute with given value and type to file. More... | |
template<typename T > | |
std::pair< std::vector< hsize_t >, std::vector< T > > | readLinearArray (const std::string &dataset_name) const |
Read given dataset into linear dim -D array. More... | |
template<typename T > | |
std::vector< T > | read1DArray (const std::string &dataset_name) const |
Read 1D dataset given by dataset_name . More... | |
template<typename T > | |
std::vector< std::vector< T > > | read2DArray (const std::string &dataset_name) const |
Read given dataset into 2D array of vectors. More... | |
template<typename T > | |
std::vector< std::vector< std::vector< T > > > | read3DArray (const std::string &dataset_name) const |
Read given dataset into 3D array of vectors. More... | |
template<int dim, typename T > | |
void | writeLinearArray (const std::string &dataset_name, const T *value, const std::array< hsize_t, dim > &sizes, hid_t type, bool overwrite) const |
Writes a dim -dimensional dataset stored in 1D array in col-major fashion. More... | |
template<typename T , typename array_t > | |
void | write1DArray (const std::string &dataset_name, const array_t &value, hid_t type, bool overwrite) const |
Writes given 1D array with given value and type to file. More... | |
template<typename T , class array_t > | |
void | write2DArray (const std::string &dataset_name, const array_t &value, hid_t type, bool overwrite) const |
Writes given 2D array of given value and type to file. More... | |
template<typename T , class array_t > | |
void | write3DArray (const std::string &dataset_name, const array_t &value, hid_t type, bool overwrite) const |
Writes given 3D array of given value and type to file. More... | |
int | readIntAttribute (const std::string &attr_name) const |
Reads int attribute. More... | |
bool | readBoolAttribute (const std::string &attr_name) const |
Reads bool attribute. More... | |
double | readDoubleAttribute (const std::string &attr_name) const |
Reads double attribute. More... | |
float | readFloatAttribute (const std::string &attr_name) const |
Reads float attribute. More... | |
std::string | readStringAttribute (const std::string &attr_name) const |
Reads non-null-terminated string attribute. More... | |
std::string | readNullTerminatedStringAttribute (const std::string &attr_name) const |
Reads null-terminated string attribute. More... | |
void | writeIntAttribute (const std::string &attr_name, int value, bool overwrite=false) const |
Write int attribute. More... | |
void | writeBoolAttribute (const std::string &attr_name, bool value, bool overwrite=false) const |
Write bool attribute. More... | |
void | writeDoubleAttribute (const std::string &attr_name, double value, bool overwrite=false) const |
Write double attribute. More... | |
void | writeFloatAttribute (const std::string &attr_name, float value, bool overwrite=false) const |
Write float attribute. More... | |
void | writeStringAttribute (const std::string &attr_name, const std::string &value, bool overwrite=false) const |
Write string attribute. More... | |
std::vector< int > | readIntArray (const std::string &dataset_name) const |
Read given dataset into vector of int s. More... | |
std::vector< double > | readDoubleArray (const std::string &dataset_name) const |
Read given dataset into vector of double s. More... | |
std::vector< float > | readFloatArray (const std::string &dataset_name) const |
Read given dataset into vector of float s. More... | |
template<typename array_t > | |
void | writeIntArray (const std::string &dataset_name, const array_t &value, bool overwrite=false) const |
Write given value as a 1D array of int s. More... | |
template<typename array_t > | |
void | writeDoubleArray (const std::string &dataset_name, const array_t &value, bool overwrite=false) const |
Write given value as a 1D array of double s. More... | |
template<typename array_t > | |
void | writeFloatArray (const std::string &dataset_name, const array_t &value, bool overwrite=false) const |
Write given value as a 1D array of floats s. More... | |
std::vector< std::vector< int > > | readInt2DArray (const std::string &dataset_name) const |
Read given dataset into 2D vector of int s. More... | |
std::vector< std::vector< double > > | readDouble2DArray (const std::string &dataset_name) const |
Read given dataset into 2D vector of double s. More... | |
std::vector< std::vector< float > > | readFloat2DArray (const std::string &dataset_name) const |
Read given dataset into 2D vector of float s. More... | |
template<typename array_t > | |
void | writeInt2DArray (const std::string &dataset_name, const array_t &value, bool overwrite=false) const |
Write given value as a 2D array of int s. More... | |
template<typename array_t > | |
void | writeDouble2DArray (const std::string &dataset_name, const array_t &value, bool overwrite=false) const |
Write given value as a 2D array of double s. More... | |
template<typename array_t > | |
void | writeFloat2DArray (const std::string &dataset_name, const array_t &value, bool overwrite=false) const |
Write given value as a 2D array of float s. More... | |
std::vector< std::vector< std::vector< int > > > | readInt3DArray (const std::string &dataset_name) const |
Read given dataset into 3D vector of int s. More... | |
std::vector< std::vector< std::vector< double > > > | readDouble3DArray (const std::string &dataset_name) const |
Read given dataset into 3D vector of double s. More... | |
std::vector< std::vector< std::vector< float > > > | readFloat3DArray (const std::string &dataset_name) const |
Read given dataset into 3D vector of float s. More... | |
template<typename array_t > | |
void | writeInt3DArray (const std::string &dataset_name, const array_t &value, bool overwrite=false) const |
Write given value as a 3D array of int s. More... | |
template<typename array_t > | |
void | writeDouble3DArray (const std::string &dataset_name, const array_t &value, bool overwrite=false) const |
Write given value as a 3D array of double s. More... | |
template<typename array_t > | |
void | writeFloat3DArray (const std::string &dataset_name, const array_t &value, bool overwrite=false) const |
Write given value as a 3D array of float s. More... | |
template<typename scalar_t = double> | |
Eigen::Matrix< scalar_t, -1, -1, 0, -1, -1 > | readEigen (const std::string &dataset_name) const |
Reads data as an Eigen matrix of type scalar_t . More... | |
template<typename Derived > | |
void | writeEigen (const std::string &dataset_name, const Eigen::MatrixBase< Derived > &value, bool overwrite=false) const |
Write given Eigen expression as a 2D array of its type (either int , double or float ). More... | |
template<typename SparseMatrixType > | |
void | writeSparseMatrix (const std::string &name, SparseMatrixType &matrix, bool one_based=true, bool overwrite=false) |
Writes a sparse matrix. More... | |
template<typename domain_t > | |
void | writeDomain (const std::string &name, const domain_t &domain, bool overwrite=false) |
Writes given domain discretization to file. More... | |
template<typename timer_t > | |
void | writeTimer (const std::string &name, const timer_t &timer, bool overwrite=false) |
Writes given timer to file. More... | |
template<typename conf_t > | |
void | writeXML (const std::string &name, const conf_t &conf, bool overwrite=false) |
Writes given XML object to file. More... | |
HDF | atomic () const |
Allows for "atomic" read and write operations to HDF5 files. More... | |
hid_t | getFileID () const |
Return raw HDF C file identifier. More... | |
hid_t | getGroupID () const |
Return raw HDF C group identifier. More... | |
Members | members () const |
Returns an object with categorized names of all members of current group. More... | |
std::vector< std::string > | groups () const |
Returns names of all subgroups in current group in alphabetical order. More... | |
std::vector< std::string > | datasets () const |
Returns names of all datasets in current group in alphabetical order. More... | |
Public Types | |
enum | Mode : unsigned { APPEND = 256, DESTROY = 128, READONLY = 64 } |
Possible file opening modes. More... | |
Classes | |
struct | Members |
Holds categorized names for all members of a group. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const HDF &hdf) |
Output basic info about HDF reader, such as current group and file. More... | |
Private Member Functions | |
template<typename T , class array_t > | |
void | write2DArray (const std::string &, const array_t &, hid_t, bool, std::false_type) const |
Overload for static_assert for Eigen due to different size method. More... | |
template<typename T , class array_t > | |
void | write2DArray (const std::string &, const array_t &, hid_t, bool, std::true_type) const |
Overload for static_assert for Eigen due to different size method. More... | |
Static Private Member Functions | |
static std::string | str (Mode mode) |
Convert HDF::Mode enum to string. More... | |
static hid_t | openFileHelper (const std::string &filename, Mode mode) |
Opens given file with given mode. More... | |
static herr_t | memberIterateCallback (hid_t loc_id, const char *name, const H5L_info_t *, void *data) |
Callback required by HDF Literate function when getting a list of members. More... | |
Private Attributes | |
std::string | filename_ |
Current file name. More... | |
std::string | group_name_ |
Current group name. More... | |
hid_t | file |
Currently open file identifier. More... | |
hid_t | group |
Currently open group identifier. More... | |
enum mm::HDF::Mode : unsigned |
Possible file opening modes.
Enumerator | |
---|---|
APPEND | Appends to the existing contents, if any exist. |
DESTROY | Removes old contents, if any exist. |
READONLY | Read only open, the file must exist. |
Definition at line 84 of file HDF_fwd.hpp.
|
inline |
Construct an empty HDF reader.
Definition at line 95 of file HDF_fwd.hpp.
Construct a HDF reader and open filename
with given mode
.
It also opens group /
by default, so it is immediately ready for reading / writing.
Assertion | fails if mode was READONLY and the file can not be read. |
Definition at line 101 of file HDF_fwd.hpp.
|
inline |
Closes all opened objects, by using close().
Definition at line 107 of file HDF_fwd.hpp.
HDF mm::HDF::atomic | ( | ) | const |
Allows for "atomic" read and write operations to HDF5 files.
This means that read and write functions open the file and group, before reading/writing and close them afterwards. The filename and group name must be set before use.
|
inline |
Closes all open objects. Alias of closeFile().
Definition at line 164 of file HDF_fwd.hpp.
void mm::HDF::closeFile | ( | ) | const |
void mm::HDF::closeGroup | ( | ) | const |
|
inline |
Returns names of all datasets in current group in alphabetical order.
Definition at line 558 of file HDF_fwd.hpp.
|
inline |
Get current filename.
Definition at line 166 of file HDF_fwd.hpp.
|
inline |
Alias of filename().
Definition at line 168 of file HDF_fwd.hpp.
void mm::HDF::flush | ( | ) | const |
|
inline |
Return raw HDF C file identifier.
Definition at line 523 of file HDF_fwd.hpp.
|
inline |
Return raw HDF C group identifier.
Definition at line 525 of file HDF_fwd.hpp.
|
inline |
Get current group name.
Definition at line 174 of file HDF_fwd.hpp.
|
inline |
Returns names of all subgroups in current group in alphabetical order.
Definition at line 555 of file HDF_fwd.hpp.
|
inline |
Returns true
is currently specified file is open and false
otherwise.
Definition at line 154 of file HDF_fwd.hpp.
|
inline |
Returns true
is currently specified group is open and false
otherwise.
Definition at line 156 of file HDF_fwd.hpp.
|
staticprivate |
HDF::Members mm::HDF::members | ( | ) | const |
|
inline |
Opens given file and group.
filename | Name of the file to open. |
group_name | Name of the group to open. |
mode | Specifies the mode to open the file in, see HDF::Mode. |
Definition at line 120 of file HDF_fwd.hpp.
Opens a given file with a given mode.
Any previously opened file is closed. No group is opened.
Definition at line 130 of file HDF_fwd.hpp.
|
staticprivate |
void mm::HDF::openGroup | ( | std::string | group_name | ) |
Open given group, closing any previously opened group().
group_name | Name of the group to open. The name must be / separated and can be either absolute or relative. Absolute names such as /a/b/c open groups staring from / group and relative names such as a/b/c open groups staring from current group. The groups are created automatically if they do not exist. |
std::vector< T > mm::HDF::read1DArray | ( | const std::string & | dataset_name | ) | const |
Read 1D dataset given by dataset_name
.
dataset_name | Name of the dataset. |
Assertion | fails if the dataset does not exists or cannot be read. |
T
, the function will still attempt to read it the behavior is undefined. Most often the return value is garbage. std::vector< std::vector< T > > mm::HDF::read2DArray | ( | const std::string & | dataset_name | ) | const |
Read given dataset into 2D array of vectors.
dataset_name | Name of the dataset. |
Assertion | fails if the dataset does not exists or cannot be read. |
T
, the function will still attempt to read it the behavior is undefined. Most often the return value is garbage. std::vector< std::vector< std::vector< T > > > mm::HDF::read3DArray | ( | const std::string & | dataset_name | ) | const |
Read given dataset into 3D array of vectors.
dataset_name | Name of the dataset. |
Assertion | fails if the dataset does not exists or cannot be read. |
T
, the function will still attempt to read it the behavior is undefined. Most often the return value is garbage. T mm::HDF::readAttribute | ( | const std::string & | attr_name | ) | const |
Read attribute given by attr_name
.
T | The type to which to read the attribute. |
attr_name | Name of the attribute |
T
. Assertion | fails if the attribute does not exists or cannot be read. |
T
, the function will still attempt to read it the behavior is undefined. Most often the return value is garbage. std::string
. bool mm::HDF::readBoolAttribute | ( | const std::string & | attr_name | ) | const |
std::vector< std::vector< double > > mm::HDF::readDouble2DArray | ( | const std::string & | dataset_name | ) | const |
Read given dataset into 2D vector of double
s.
std::vector< std::vector< std::vector< double > > > mm::HDF::readDouble3DArray | ( | const std::string & | dataset_name | ) | const |
Read given dataset into 3D vector of double
s.
std::vector< double > mm::HDF::readDoubleArray | ( | const std::string & | dataset_name | ) | const |
double mm::HDF::readDoubleAttribute | ( | const std::string & | attr_name | ) | const |
Eigen::Matrix<scalar_t, -1, -1, 0, -1, -1> mm::HDF::readEigen | ( | const std::string & | dataset_name | ) | const |
Reads data as an Eigen matrix of type scalar_t
.
scalar_t | The of the data to read. Set to double by default. |
dataset_name | Name of the dataset to read from. |
std::vector< std::vector< float > > mm::HDF::readFloat2DArray | ( | const std::string & | dataset_name | ) | const |
Read given dataset into 2D vector of float
s.
std::vector< std::vector< std::vector< float > > > mm::HDF::readFloat3DArray | ( | const std::string & | dataset_name | ) | const |
Read given dataset into 3D vector of float
s.
std::vector< float > mm::HDF::readFloatArray | ( | const std::string & | dataset_name | ) | const |
float mm::HDF::readFloatAttribute | ( | const std::string & | attr_name | ) | const |
std::vector< std::vector< int > > mm::HDF::readInt2DArray | ( | const std::string & | dataset_name | ) | const |
Read given dataset into 2D vector of int
s.
std::vector< std::vector< std::vector< int > > > mm::HDF::readInt3DArray | ( | const std::string & | dataset_name | ) | const |
Read given dataset into 3D vector of int
s.
std::vector< int > mm::HDF::readIntArray | ( | const std::string & | dataset_name | ) | const |
int mm::HDF::readIntAttribute | ( | const std::string & | attr_name | ) | const |
std::pair< std::vector< hsize_t >, std::vector< T > > mm::HDF::readLinearArray | ( | const std::string & | dataset_name | ) | const |
Read given dataset into linear dim
-D array.
dataset_name | Name of the dataset. |
Assertion | fails if the dataset does not exists or cannot be read. |
T
, the function will still attempt to read it the behavior is undefined. Most often the return value is garbage. std::string mm::HDF::readNullTerminatedStringAttribute | ( | const std::string & | attr_name | ) | const |
Reads null-terminated string
attribute.
std::string mm::HDF::readStringAttribute | ( | const std::string & | attr_name | ) | const |
Reads non-null-terminated string
attribute.
Any null characters are read as part of the string.
Reopens current file and group.
Definition at line 152 of file HDF_fwd.hpp.
Reopens the current file.
Definition at line 137 of file HDF_fwd.hpp.
|
inline |
Reopens current group.
Definition at line 148 of file HDF_fwd.hpp.
|
inline |
Sets new filename without opening the new file. Any previously opened file is closed.
Definition at line 170 of file HDF_fwd.hpp.
|
inline |
Alias of setFilename().
Definition at line 172 of file HDF_fwd.hpp.
void mm::HDF::setGroupName | ( | const std::string & | group_name | ) |
|
staticprivate |
void mm::HDF::write1DArray | ( | const std::string & | dataset_name, |
const array_t & | value, | ||
hid_t | type, | ||
bool | overwrite | ||
) | const |
Writes given 1D array with given value and type to file.
T | Type to which the elements of value are converted to. |
array_t | Type of the given array. It must support operator[] and .size() . |
dataset_name | Name of the attribute. |
value | Value to be written |
type | HDF5 type of the elements to be written. |
overwrite | If overwriting existing datasets is allowed. If an attribute with the same name is attempted to be written, it must have the same dimensions and type as current value. Otherwise the overwrite will fail. |
|
private |
|
inlineprivate |
Overload for static_assert for Eigen due to different size
method.
Definition at line 309 of file HDF_fwd.hpp.
|
inline |
Writes given 2D array of given value and type to file.
T | Type of array_t elements |
array_t | Type of the given 2D array. It must support .size() , [i].size() and [i][j] operations. |
dataset_name | Name of the dataset. |
value | Value to be written. |
type | HDF5 type of the elements to be written. |
overwrite | If overwriting existing datasets is allowed. If an attribute with the same name is attempted to be written, it must have the same dimensions and type as current value. Otherwise the overwrite will fail. |
Definition at line 296 of file HDF_fwd.hpp.
void mm::HDF::write3DArray | ( | const std::string & | dataset_name, |
const array_t & | value, | ||
hid_t | type, | ||
bool | overwrite | ||
) | const |
Writes given 3D array of given value and type to file.
T | Type of array_t elements |
array_t | Type of the given 2D array. It must support .size() , [i].size() , [i][j] , [i][j].size() and [i][j][k] operations. |
dataset_name | Name of the dataset. |
value | Value to be written. |
type | HDF5 type of the elements to be written. |
overwrite | If overwriting existing datasets is allowed. If an attribute with the same name is attempted to be written, it must have the same dimensions and type as current value. Otherwise the overwrite will fail. |
void mm::HDF::writeAttribute | ( | const std::string & | attr_name, |
const T & | value, | ||
const hid_t & | type, | ||
bool | overwrite = false |
||
) | const |
Writes given attribute with given value and type to file.
attr_name | Name of the attribute. |
value | Value to be written |
type | HDF5 type of the attribute to be written. |
overwrite | If overwriting existing attributes is allowed. If an attribute with the same name is attempted to be written, the existing attribute is deleted and a new one is created instead. |
void mm::HDF::writeBoolAttribute | ( | const std::string & | attr_name, |
bool | value, | ||
bool | overwrite = false |
||
) | const |
void mm::HDF::writeDomain | ( | const std::string & | name, |
const domain_t & | domain, | ||
bool | overwrite = false |
||
) |
Writes given domain discretization to file.
A group with given name is created and 4 datasets and 1 attribute are stored inside:
N
: int attribute storing number of nodes in the domain,pos
: N x dim
double array of positions,types
: int array of length N
representing domain types,bmap
: int array of length N
mapping nodes to boundary nodes (see DomainDiscretization::bmap),normals
: double array of domain normals for boundary nodes. After the function exists, the same group is opened as before the call.name | Name of the group in which the domain is stored. |
domain | Domain to write to file. |
overwrite | If true , allows overwriting of existing entries. |
void mm::HDF::writeDouble2DArray | ( | const std::string & | dataset_name, |
const array_t & | value, | ||
bool | overwrite = false |
||
) | const |
Write given value as a 2D array of double
s.
void mm::HDF::writeDouble3DArray | ( | const std::string & | dataset_name, |
const array_t & | value, | ||
bool | overwrite = false |
||
) | const |
Write given value as a 3D array of double
s.
void mm::HDF::writeDoubleArray | ( | const std::string & | dataset_name, |
const array_t & | value, | ||
bool | overwrite = false |
||
) | const |
Write given value as a 1D array of double
s.
void mm::HDF::writeDoubleAttribute | ( | const std::string & | attr_name, |
double | value, | ||
bool | overwrite = false |
||
) | const |
void mm::HDF::writeEigen | ( | const std::string & | dataset_name, |
const Eigen::MatrixBase< Derived > & | value, | ||
bool | overwrite = false |
||
) | const |
Write given Eigen expression as a 2D array of its type (either int
, double
or float
).
Definition at line 46 of file HDF_Eigen.hpp.
void mm::HDF::writeFloat2DArray | ( | const std::string & | dataset_name, |
const array_t & | value, | ||
bool | overwrite = false |
||
) | const |
Write given value as a 2D array of float
s.
void mm::HDF::writeFloat3DArray | ( | const std::string & | dataset_name, |
const array_t & | value, | ||
bool | overwrite = false |
||
) | const |
Write given value as a 3D array of float
s.
void mm::HDF::writeFloatArray | ( | const std::string & | dataset_name, |
const array_t & | value, | ||
bool | overwrite = false |
||
) | const |
Write given value as a 1D array of floats
s.
void mm::HDF::writeFloatAttribute | ( | const std::string & | attr_name, |
float | value, | ||
bool | overwrite = false |
||
) | const |
void mm::HDF::writeInt2DArray | ( | const std::string & | dataset_name, |
const array_t & | value, | ||
bool | overwrite = false |
||
) | const |
Write given value as a 2D array of int
s.
void mm::HDF::writeInt3DArray | ( | const std::string & | dataset_name, |
const array_t & | value, | ||
bool | overwrite = false |
||
) | const |
Write given value as a 3D array of int
s.
void mm::HDF::writeIntArray | ( | const std::string & | dataset_name, |
const array_t & | value, | ||
bool | overwrite = false |
||
) | const |
Write given value as a 1D array of int
s.
void mm::HDF::writeIntAttribute | ( | const std::string & | attr_name, |
int | value, | ||
bool | overwrite = false |
||
) | const |
void mm::HDF::writeLinearArray | ( | const std::string & | dataset_name, |
const T * | value, | ||
const std::array< hsize_t, dim > & | sizes, | ||
hid_t | type, | ||
bool | overwrite | ||
) | const |
Writes a dim
-dimensional dataset stored in 1D array in col-major fashion.
dim | Dimension (HDF rank) of the dataset, 2 for matrices, 3 for tensors. |
dataset_name | Name of the dataset. |
value | Pointer to values to be written, stored in a linear col-major fashion. The number of values should be equal to the product of sizes . |
sizes | Sizes of the dataset along each dimension. |
type | HDF5 type of the dataset. |
overwrite | See write2DArray() |
void mm::HDF::writeSparseMatrix | ( | const std::string & | name, |
SparseMatrixType & | matrix, | ||
bool | one_based = true , |
||
bool | overwrite = false |
||
) |
Writes a sparse matrix.
Matrix matrix
is written as a N x 3
matrix, where the columns represent vectors I
, J
, V
, such that M(I(i), J(i)) = V(i)
. Matrix values are stored as doubles of native size.
name | Attribute name. |
matrix | A sparse matrix. |
one_based | Whether to store the indices as one or zero based. One based indexes are ready to be read by Matlab's spconvert . |
overwrite | See write2DArray(). |
void mm::HDF::writeStringAttribute | ( | const std::string & | attr_name, |
const std::string & | value, | ||
bool | overwrite = false |
||
) | const |
Write string
attribute.
The string is written as an non-null-terminater array of bytes. It may contain null characters in the middle.
void mm::HDF::writeTimer | ( | const std::string & | name, |
const timer_t & | timer, | ||
bool | overwrite = false |
||
) |
Writes given timer to file.
A group with given name is created and durations (in seconds) between consecutive labels are writen as double attributes named label1-label2
. Additionally, total time between first and last label (in seconds) is stored in the double attribute named total
. After the function exists, the same group is opened as before the call. If timer has 0 labels, only the group is created. If timer has one label, attribute total
with value 0.0
is written.
name | Name of the group in which the timer is stored. |
timer | Timer to write to file. |
overwrite | If true , allows overwriting of existing entries. |
void mm::HDF::writeXML | ( | const std::string & | name, |
const conf_t & | conf, | ||
bool | overwrite = false |
||
) |
Writes given XML object to file.
All attributes in the file, given by XML::getAll, are written in their dot-separated full-path format. They are written either as doubles (if whole value can be parsed as a double
) or strings otherwise. After the function exists, the same group is opened as before the call.
name | Name of the group in which the XML attributes are stored. |
conf | XML object. |
overwrite | If true , allows overwriting of existing entries. |
|
friend |
Output basic info about HDF reader, such as current group and file.
Definition at line 561 of file HDF_fwd.hpp.
|
private |
Currently open file identifier.
Definition at line 79 of file HDF_fwd.hpp.
|
private |
Current file name.
Definition at line 76 of file HDF_fwd.hpp.
|
private |
Currently open group identifier.
Definition at line 80 of file HDF_fwd.hpp.
|
private |
Current group name.
Definition at line 77 of file HDF_fwd.hpp.