File and Group¶
The following classes are all defined within namespace HIPP::IO.
Class H5File¶
-
class
H5File¶ The API for HDF5 file.
H5Fileinstance can be copy-constructed, copy-assigned, move-constructed and move-assigned. The copy, move operations and destructor are all noexcept. The copy operations are shallow-copy, i.e., instances of source and target refer to the same underlying file object (like ashared_ptr).-
H5File(const string &name, const string &flag, const H5Proplist &cporp = H5Proplist::defaultval, const H5Proplist &aprop = H5Proplist::defaultval)¶ Constructor - create a new file or open an existing file named
name.flagcontrols the the open/creation and Read/Write mode. It can be one of the following values“w”
create a new file (truncate if existing) as R/W mode.
“r”
open an existing file as R mode.
“a”
open an existing file as R/W mode.
“ac” or “ca”
open an existing file (create if not existing) as R/W mode.
cpropandapropspecify the creation and access properties, respectively.
-
template<typename
T>
H5Datasetcreate_dataset(const string &name, const vector<hsize_t> &dims, const string &flag = "trunc", const H5Proplist &lcprop = H5Proplist::defaultval, const H5Proplist &cprop = H5Proplist::defaultval, const H5Proplist &aprop = H5Proplist::defaultval)¶ -
H5Dataset
create_dataset(const string &name, const H5Datatype &dtype, const vector<hsize_t> &dims, const string &flag = "trunc", const H5Proplist &lcprop = H5Proplist::defaultval, const H5Proplist &cprop = H5Proplist::defaultval, const H5Proplist &aprop = H5Proplist::defaultval)¶ -
template<typename
T>
H5Datasetcreate_dataset_scalar(const string &name, const string &flag = "trunc", const H5Proplist &lcprop = H5Proplist::defaultval, const H5Proplist &cprop = H5Proplist::defaultval, const H5Proplist &aprop = H5Proplist::defaultval)¶ -
H5Dataset
create_dataset_str(const string &name, size_t len, const string &flag = "trunc", const H5Proplist &lcprop = H5Proplist::defaultval, const H5Proplist &cprop = H5Proplist::defaultval, const H5Proplist &aprop = H5Proplist::defaultval)¶ Create a new dataset (or open an existing dataset) under the root group of the file instance.
namespecifies the name of the dataset to open/create. If the dataset does not exist, it is created. Otherwise, ifflag=="trunc", the dataset is opened, or ifflag=="excl", an exceptionErrH5is thrown.lcpropspecifies the link-creation properties,cpropspecifies the dataset creation properties, andapropspecifies the dataset access properties.Four methods are:
create_dataset<T>()creates an array-like dataset with element typeT, array shapedims. TypeTcan be either numeric Predefined Datatypes (e.g., int, float), orstd::string. For the numeric types,dimsis the array shape. Forstd::string,dimsmust be{ num_of_str, max_str_size}, wheremax_str_sizemust contain the space of the terminate null character, i.e., this dataset allows storage for an 1-d array of C strings. It is best to calculate dims useH5TypeStr::shape()create_dataset()creates and array-like dataset with element typedtype, array shapedims.create_dataset_scalar()creates a scalar dataset.create_dataset_str()creates a dataset for a single string.
-
H5Dataset
open_dataset(const string &name, const H5Proplist &aprop = H5Proplist::defaultval)¶ -
bool
dataset_exists(const string &name) const¶ open_dataset(name)opens an existing dataset namedname. If not existing, throw an exceptionErrH5.To check whether a dataset exists, use
dataset_exists(name).
-
template<typename
T>
H5Attrcreate_attr(const string &name, const vector<hsize_t> &dims, const string &flag = "trunc")¶ -
H5Attr
create_attr(const string &name, const H5Datatype &dtype, const vector<hsize_t> &dims, const string &flag = "trunc")¶ -
template<typename
T>
H5Attrcreate_attr_scalar(const string &name, const string &flag = "trunc")¶ -
H5Attr
create_attr_str(const string &name, size_t len, const string &flag = "trunc")¶ Create a new attribute (or open an existing attribute) under the root group of this file instance.
The template parameter and argument list is the same with
create_dataset()and its variants. The difference is that you cannot specify any property list.
-
H5Attr
open_attr(const string &name)¶ -
bool
attr_exists(const string &name) const¶ open_attr(name)opens an existing attribute namedname. If not existing, throw an exceptionErrH5.To check whether an attribute exists, use
attr_exists(name).
-
H5Group
create_group(const string &name)¶ -
H5Group
try_create_group(const string &name)¶ -
H5Group
open_group(const string &name)¶ -
bool
group_exists(const string &name) const¶ Data group manipulation methods.
create_group(name)creates a group namedname. If it has already existed, throw an exceptionErrH5.try_create_group(name)is similar, but open the group if it has already existed.open_group(name)opens an existing group. If it is not existed, throw an exceptionErrH5.group_exists(name)check whether a group exists.
-
static H5Proplist
create_proplist(const string &cls = "c")¶ Create a file-related property list of given class
cls. Possible values are:“c” or “create”
properties for file creation
“a” or “access”
properties for file access
“m” or “mount”
properties for file mounting
-
Class H5Group¶
-
class
H5Group¶ -
template<typename
T>
H5Datasetcreate_dataset(const string &name, const vector<hsize_t> &dims, const string &flag = "trunc", const H5Proplist &lcprop = H5Proplist::defaultval, const H5Proplist &cprop = H5Proplist::defaultval, const H5Proplist &aprop = H5Proplist::defaultval)¶ -
H5Dataset
create_dataset(const string &name, const H5Datatype &dtype, const vector<hsize_t> &dims, const string &flag = "trunc", const H5Proplist &lcprop = H5Proplist::defaultval, const H5Proplist &cprop = H5Proplist::defaultval, const H5Proplist &aprop = H5Proplist::defaultval)¶ -
template<typename
T>
H5Datasetcreate_dataset_scalar(const string &name, const string &flag = "trunc", const H5Proplist &lcprop = H5Proplist::defaultval, const H5Proplist &cprop = H5Proplist::defaultval, const H5Proplist &aprop = H5Proplist::defaultval)¶ -
H5Dataset
create_dataset_str(const string &name, size_t len, const string &flag = "trunc", const H5Proplist &lcprop = H5Proplist::defaultval, const H5Proplist &cprop = H5Proplist::defaultval, const H5Proplist &aprop = H5Proplist::defaultval)¶ Create a new dataset (or open an existing dataset) under the current group instance.
These methods have the same template parameter and argument list as
H5File::create_dataset()and its variants. See there for the details.
-
H5Dataset
open_dataset(const string &name, const H5Proplist &aprop = H5Proplist::defaultval)¶ -
bool
dataset_exists(const string &name) const¶ open_dataset(name)opens an existing dataset namedname. If not existing, throw an exceptionErrH5.To check whether a dataset exists, use
dataset_exists(name).
-
template<typename
T>
H5Attrcreate_attr(const string &name, const vector<hsize_t> &dims, const string &flag = "trunc")¶ -
H5Attr
create_attr(const string &name, const H5Datatype &dtype, const vector<hsize_t> &dims, const string &flag = "trunc")¶ -
template<typename
T>
H5Attrcreate_attr_scalar(const string &name, const string &flag = "trunc")¶ -
H5Attr
create_attr_str(const string &name, size_t len, const string &flag = "trunc")¶ Create a new attribute (or open an existing attribute) under the current group.
The template parameter and argument list are the same with
H5File::create_dataset()and its variants. The difference is that you cannot specify any property list.
-
H5Attr
open_attr(const string &name)¶ -
bool
attr_exists(const string &name) const¶ Opens an existing attribute of name
name. If not existing, throw an errorErrH5.attr_exists()checks whether an attribute has been existed.
-
H5Group
create_group(const string &name)¶ -
H5Group
try_create_group(const string &name)¶ -
H5Group
open_group(const string &name)¶ -
bool
group_exists(const string &name) const¶ Data group manipulation methods.
create_group(name)creates a group namedname. If it has already existed, throw an exceptionErrH5.try_create_group(name)is similar, but open the group if it has already existed.open_group(name)opens an existing group. If it is not existed, throw an exceptionErrH5.group_exists(name)check whether a group exists.
-
template<typename