17 #include <isce3/core/DateTime.h>
20 #include <isce3/io/IH5.h>
33 template <
typename H5obj>
34 inline bool exists(H5obj & h5obj,
const std::string & name,
35 const std::string start =
".",
const std::string type =
"BOTH") {
37 std::vector<std::string> objs = h5obj.find(name, start, type,
"FULL");
39 if (objs.size() > 0) {
51 template <
typename H5obj,
typename T>
52 inline void loadFromH5(H5obj & h5obj,
const std::string & datasetPath, T & v) {
64 template <
typename H5obj,
typename T>
65 inline void loadFromH5(H5obj & h5obj,
const std::string & datasetPath,
78 template <
typename H5obj,
typename T>
79 inline void loadFromH5(H5obj & h5obj,
const std::string & datasetPath,
80 std::valarray<T> & v) {
92 template <
typename H5obj,
typename T>
93 inline void loadFromH5(H5obj & h5obj,
const std::string & datasetPath,
107 template<
typename H5obj,
typename T>
108 inline void saveToH5(H5obj& h5obj,
const std::string &datasetPath,
109 const T &val,
const std::string & units=
"") {
111 if (
exists(h5obj, datasetPath)) {
117 if (units.length() > 0) {
128 template <
typename H5obj,
typename T>
129 inline void saveToH5(H5obj & h5obj,
const std::string & datasetPath,
130 const std::vector<T> & v,
const std::string & units =
"") {
132 if (
exists(h5obj, datasetPath)) {
138 if (units.length() > 0) {
149 template <
typename H5obj,
typename T>
150 inline void saveToH5(H5obj & h5obj,
const std::string & datasetPath,
151 const std::valarray<T> & v,
const std::string & units =
"") {
153 if (
exists(h5obj, datasetPath)) {
159 if (units.length() > 0) {
170 template <
typename H5obj,
typename T,
size_t S>
171 inline void saveToH5(H5obj & h5obj,
const std::string & datasetPath,
172 const std::vector<T> & v, std::array<size_t, S> dims,
173 const std::string & units =
"") {
175 if (
exists(h5obj, datasetPath)) {
181 if (units.length() > 0) {
192 template <
typename H5obj,
typename T,
size_t S>
193 inline void saveToH5(H5obj & h5obj,
const std::string & datasetPath,
194 const std::valarray<T> & v, std::array<size_t, S> dims,
195 const std::string & units =
"") {
197 if (
exists(h5obj, datasetPath)) {
203 if (units.length() > 0) {
214 template <
typename H5obj,
typename T>
215 inline void saveToH5(H5obj & h5obj,
const std::string & datasetPath,
217 const std::string & units =
"") {
219 if (
exists(h5obj, datasetPath)) {
223 std::array<size_t, 2> dims{mat.
length(), mat.
width()};
226 if (units.length() > 0) {
235 template <
typename H5obj>
236 inline std::vector<int>
getImageDims(H5obj & h5obj,
const std::string & datasetPath) {
248 template <
typename H5obj>
255 std::string unitAttr;
256 std::string attribute(
"units");
257 dset.
read(unitAttr, attribute);
260 std::string dummy1, dummy2, datestr, timestr;
261 std::istringstream ss(unitAttr);
262 ss >> dummy1 >> dummy2 >> datestr >> timestr;
263 std::string inputstr = datestr +
"T" + timestr +
".00";
275 template <
typename H5obj>
276 inline void setRefEpoch(H5obj & h5obj,
const std::string & datasetPath,
285 "seconds since %04d-%02d-%02d %02d:%02d:%02d",
292 std::string unitsAttr{buffer};
std::vector< int > getDimensions(const std::string &v="")
Get the size of each dimension of the dataset or given attribute.
Definition: IH5.cpp:162
void loadFromH5(H5obj &h5obj, const std::string &datasetPath, T &v)
Load scalar dataset from HDF5 file.
Definition: Serialization.h:52
void read(T &v, const std::string &att="")
Reading scalar (non string) dataset or attributes.
Definition: IH5.icc:130
Data structure to store date time to nano-sec precision.
Definition: DateTime.h:18
void createAttribute(const std::string &name, const T &data)
Creating and writing a scalar as an attribute.
Definition: IH5.icc:824
std::vector< int > getImageDims(H5obj &h5obj, const std::string &datasetPath)
Get dimensions of complex imagery from HDF5 file.
Definition: Serialization.h:236
cell_t * data()
Access to data buffer.
Definition: Matrix.icc:219
size_t length() const
Get matrix length.
Definition: Matrix.icc:357
Our derived dataset structure that includes utility functions.
Definition: IH5.h:44
void saveToH5(H5obj &h5obj, const std::string &datasetPath, const T &val, const std::string &units="")
Write scalar dataset to HDF5 file.
Definition: Serialization.h:108
bool exists(H5obj &h5obj, const std::string &name, const std::string start=".", const std::string type="BOTH")
Check existence of a dataset or group.
Definition: Serialization.h:34
isce3::core::DateTime getRefEpoch(H5obj &h5obj, const std::string &datasetPath)
Parse time units in a dataset attribute to get a reference epoch.
Definition: Serialization.h:249
void setRefEpoch(H5obj &h5obj, const std::string &datasetPath, const isce3::core::DateTime &refEpoch)
Save reference epoch DateTime as an attribute.
Definition: Serialization.h:276
size_t width() const
Get matrix width.
Definition: Matrix.icc:349