-----------------------------------------------------------------------------
| 254 | } |
| 255 | //----------------------------------------------------------------------------- |
| 256 | void io::hdf5::add_group(hid_t handle, const std::string& group_name) |
| 257 | { |
| 258 | std::string _group_name(group_name); |
| 259 | |
| 260 | // Cannot create the root level group |
| 261 | if (_group_name.size() == 0 or _group_name == "/") |
| 262 | return; |
| 263 | |
| 264 | // Prepend a slash if missing |
| 265 | if (_group_name[0] != '/') |
| 266 | _group_name = "/" + _group_name; |
| 267 | |
| 268 | // Starting from the root level, check and create groups if needed |
| 269 | std::size_t pos = 0; |
| 270 | while (pos != std::string::npos) |
| 271 | { |
| 272 | pos++; |
| 273 | pos = _group_name.find('/', pos); |
| 274 | const std::string parent_name(_group_name, 0, pos); |
| 275 | if (!has_group(handle, parent_name)) |
| 276 | { |
| 277 | const hid_t group_id_vis = H5Gcreate2( |
| 278 | handle, parent_name.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
| 279 | if (group_id_vis < 0) |
| 280 | throw std::runtime_error("Failed to add HDF5 group"); |
| 281 | |
| 282 | if (H5Gclose(group_id_vis) < 0) |
| 283 | throw std::runtime_error("Failed to close HDF5 group"); |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | //----------------------------------------------------------------------------- |
| 288 | std::vector<std::int64_t> |
| 289 | io::hdf5::get_dataset_shape(hid_t handle, const std::string& dataset_path) |