| 200 | } |
| 201 | |
| 202 | AnyMap readH5Attributes(const h5::Group& sub, bool recursive) |
| 203 | { |
| 204 | // restore meta data from attributes |
| 205 | AnyMap out; |
| 206 | for (auto& name : sub.listAttributeNames()) { |
| 207 | h5::Attribute attr = sub.getAttribute(name); |
| 208 | h5::DataType dtype = attr.getDataType(); |
| 209 | h5::DataTypeClass dclass = dtype.getClass(); |
| 210 | if (dclass == h5::DataTypeClass::Float) { |
| 211 | if (attr.getSpace().getElementCount() > 1) { |
| 212 | vector<double> values; |
| 213 | attr.read(values); |
| 214 | out[name] = values; |
| 215 | } else { |
| 216 | double value; |
| 217 | attr.read(value); |
| 218 | out[name] = value; |
| 219 | } |
| 220 | } else if (dclass == h5::DataTypeClass::Integer) { |
| 221 | if (attr.getSpace().getElementCount() > 1) { |
| 222 | vector<long int> values; |
| 223 | attr.read(values); |
| 224 | out[name] = values; |
| 225 | } else { |
| 226 | long int value; |
| 227 | attr.read(value); |
| 228 | out[name] = value; |
| 229 | } |
| 230 | } else if (dclass == h5::DataTypeClass::String) { |
| 231 | if (attr.getSpace().getElementCount() > 1) { |
| 232 | vector<string> values; |
| 233 | attr.read(values); |
| 234 | out[name] = values; |
| 235 | } else { |
| 236 | string value; |
| 237 | attr.read(value); |
| 238 | out[name] = value; |
| 239 | } |
| 240 | } else if (dclass == h5::DataTypeClass::Enum) { |
| 241 | // only booleans are supported |
| 242 | if (attr.getSpace().getElementCount() > 1) { |
| 243 | vector<H5Boolean> values; |
| 244 | attr.read(values); |
| 245 | vector<bool> bValues; |
| 246 | for (auto v : values) { |
| 247 | bValues.push_back(bool(v)); |
| 248 | } |
| 249 | out[name] = bValues; |
| 250 | } else { |
| 251 | H5Boolean value; |
| 252 | attr.read(value); |
| 253 | out[name] = bool(value); |
| 254 | } |
| 255 | } else { |
| 256 | throw NotImplementedError("readH5Attributes", |
| 257 | "Unable to read attribute '{}' with type '{}'", name, dtype.string()); |
| 258 | } |
| 259 | } |
no test coverage detected