mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
Add functions for getting attribute/dataset array shape
This commit is contained in:
parent
2c498d3024
commit
3ea64d545c
2 changed files with 32 additions and 0 deletions
|
|
@ -51,6 +51,35 @@ get_shape(hid_t obj_id, hsize_t* dims)
|
|||
}
|
||||
|
||||
|
||||
std::vector<hsize_t> attribute_shape(hid_t obj_id, const char* name)
|
||||
{
|
||||
hid_t attr = H5Aopen(obj_id, name, H5P_DEFAULT);
|
||||
std::vector<hsize_t> shape = object_shape(attr);
|
||||
H5Aclose(attr);
|
||||
return shape;
|
||||
}
|
||||
|
||||
std::vector<hsize_t> object_shape(hid_t obj_id)
|
||||
{
|
||||
// Get number of dimensions
|
||||
auto type = H5Iget_type(obj_id);
|
||||
hid_t dspace;
|
||||
if (type == H5I_DATASET) {
|
||||
dspace = H5Dget_space(obj_id);
|
||||
} else if (type == H5I_ATTR) {
|
||||
dspace = H5Aget_space(obj_id);
|
||||
}
|
||||
int n = H5Sget_simple_extent_ndims(dspace);
|
||||
|
||||
// Get shape of array
|
||||
std::vector<hsize_t> shape(n);
|
||||
H5Sget_simple_extent_dims(dspace, shape.data(), nullptr);
|
||||
|
||||
// Free resources and return
|
||||
H5Sclose(dspace);
|
||||
return shape;
|
||||
}
|
||||
|
||||
void
|
||||
get_shape_attr(hid_t obj_id, const char* name, hsize_t* dims)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -72,6 +72,9 @@ read_nd_vector(hid_t obj_id, const char* name,
|
|||
std::vector<std::vector<std::vector<std::vector<std::vector<double> > > > >& result,
|
||||
bool must_have = false);
|
||||
|
||||
std::vector<hsize_t> attribute_shape(hid_t obj_id, const char* name);
|
||||
std::vector<hsize_t> object_shape(hid_t obj_id);
|
||||
|
||||
//==============================================================================
|
||||
// Fortran compatibility functions
|
||||
//==============================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue