12#ifndef ARCANE_HDF5_HDF5UTILS_H
13#define ARCANE_HDF5_HDF5UTILS_H
18#include "arcane/utils/String.h"
19#include "arcane/utils/Array.h"
20#include "arcane/utils/NumericTypes.h"
22#include "arcane/datatype/DataTypes.h"
24#include "arcane/hdf5/ArcaneHdf5Global.h"
37#if (H5_VERS_MAJOR < 2) && (H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 10)
38#error "This version of HDF5 is too old. Version 1.10+ is required"
42#define ARCANE_HDF5_1_6_AND_AFTER
43#define ARCANE_HDF5_1_8_AND_AFTER
62ARCANE_HDF5_EXPORT herr_t _ArcaneHdf5UtilsGroupIterateMe(hid_t,
const char*,
void*);
68class ARCANE_HDF5_EXPORT Hdf5Mutex
73 Hdf5Mutex(std::mutex& mutex,
bool& is_active)
75 , m_is_active(is_active)
100extern "C++" ARCANE_HDF5_EXPORT
Hdf5Mutex&
101_ArcaneHdf5UtilsMutex();
110class ARCANE_HDF5_EXPORT HInit
121#ifdef H5_HAVE_PARALLEL
150class ARCANE_HDF5_EXPORT Hid
166 void _setId(hid_t
id) { m_id = id; }
167 void _setNullId() { m_id = -1; }
171 Hid& operator=(
const Hid& hid) =
delete;
175 hid_t id()
const {
return m_id; }
176 bool isBad()
const {
return m_id < 0; }
188class ARCANE_HDF5_EXPORT HProperty
193 HProperty() { _setId(H5P_DEFAULT); }
198 HProperty(HProperty&& rhs)
203 HProperty& operator=(HProperty&& rhs)
212 HProperty(
const HProperty& v) =
delete;
213 HProperty& operator=(
const HProperty& hid) =
delete;
219 void create(hid_t cls_id);
220 void setId(hid_t new_id)
273class ARCANE_HDF5_EXPORT HFile
279 ~HFile() { _close(); }
285 HFile& operator=(HFile&& rhs)
291 HFile& operator=(
const HFile& hid) =
delete;
295 ARCANE_DEPRECATED_REASON(
"Y2023: Copy constructor is deprecated. This class has unique ownership")
296 HFile(
const HFile& rhs)
302 void openTruncate(
const String& var);
303 void openAppend(
const String& var);
304 void openRead(
const String& var);
305 void openTruncate(
const String& var, hid_t plist_id);
306 void openAppend(
const String& var, hid_t plist_id);
307 void openRead(
const String& var, hid_t plist_id);
320class ARCANE_HDF5_EXPORT HGroupSearch
324 HGroupSearch(
const String& group_name)
325 : m_group_name(group_name)
331 herr_t iterateMe(
const char* member_name)
334 if (m_group_name == member_name)
349class ARCANE_HDF5_EXPORT HGroup
355 ~HGroup() { close(); }
361 HGroup& operator=(HGroup&& rhs)
367 HGroup& operator=(
const HGroup& hid) =
delete;
371 ARCANE_DEPRECATED_REASON(
"Y2023: Copy constructor is deprecated. This class has unique ownership")
372 HGroup(
const HGroup& rhs)
378 void create(
const Hid& loc_id,
const String& group_name);
379 void openOrCreate(
const Hid& loc_id,
const String& group_name);
380 void recursiveCreate(
const Hid& loc_id,
const String& var);
381 void recursiveCreate(
const Hid& loc_id,
const Array<String>& paths);
382 void checkDelete(
const Hid& loc_id,
const String& var);
383 void recursiveOpen(
const Hid& loc_id,
const String& var);
384 void open(
const Hid& loc_id,
const String& var);
385 void openIfExists(
const Hid& loc_id,
const Array<String>& var);
386 bool hasChildren(
const String& var);
388 static bool hasChildren(hid_t loc_id,
const String& var);
392 hid_t _checkOrCreate(hid_t loc_id,
const String& group_name);
393 hid_t _checkExist(hid_t loc_id,
const String& group_name);
403class ARCANE_HDF5_EXPORT HSpace
409 explicit HSpace(hid_t
id)
418 HSpace& operator=(HSpace&& rhs)
424 HSpace& operator=(
const HSpace& hid) =
delete;
428 ARCANE_DEPRECATED_REASON(
"Y2023: Copy constructor is deprecated. This class has unique ownership")
429 HSpace(
const HSpace& v)
435 void createSimple(
int nb, hsize_t dims[]);
436 void createSimple(
int nb, hsize_t dims[], hsize_t max_dims[]);
438 herr_t getDimensions(hsize_t dims[], hsize_t max_dims[]);
446class ARCANE_HDF5_EXPORT HDataset
452 ~HDataset() { close(); }
453 HDataset(HDataset&& rhs)
458 HDataset& operator=(HDataset&& rhs)
464 HDataset& operator=(
const HDataset& hid) =
delete;
468 ARCANE_DEPRECATED_REASON(
"Y2023: Copy constructor is deprecated. This class has unique ownership")
469 HDataset(
const HDataset& v)
476 void create(
const Hid& loc_id,
const String& var, hid_t save_type,
const HSpace& space_id, hid_t plist);
477 void create(
const Hid& loc_id,
const String& var, hid_t save_type,
480 void recursiveCreate(
const Hid& loc_id,
const String& var, hid_t save_type,
const HSpace& space_id, hid_t plist);
481 void open(
const Hid& loc_id,
const String& var);
482 void openIfExists(
const Hid& loc_id,
const String& var);
483 herr_t write(hid_t native_type,
const void* array);
484 herr_t write(hid_t native_type,
const void* array,
const HSpace& memspace_id,
485 const HSpace& filespace_id, hid_t plist);
486 herr_t write(hid_t native_type,
const void* array,
const HSpace& memspace_id,
488 herr_t read(hid_t native_type,
void* array);
489 void readWithException(hid_t native_type,
void* array);
491 herr_t setExtent(
const hsize_t new_dims[]);
495 void _remove(hid_t hid,
const String& var);
503class ARCANE_HDF5_EXPORT HAttribute
510 HAttribute(HAttribute&& rhs)
515 HAttribute& operator=(HAttribute&& rhs)
521 HAttribute& operator=(
const HAttribute& hid) =
delete;
525 ARCANE_DEPRECATED_REASON(
"Y2023: Copy constructor is deprecated. This class has unique ownership")
526 HAttribute(
const HAttribute& v)
532 void remove(
const Hid& loc_id,
const String& var);
533 void create(
const Hid& loc_id,
const String& var, hid_t save_type,
const HSpace& space_id);
534 void open(
const Hid& loc_id,
const String& var);
535 herr_t write(hid_t native_type,
void* array);
536 herr_t read(hid_t native_type,
void* array);
545class ARCANE_HDF5_EXPORT HType
557 HType& operator=(HType&& rhs)
563 HType& operator=(
const HType& hid) =
delete;
567 ARCANE_DEPRECATED_REASON(
"Y2023: Copy constructor is deprecated. This class has unique ownership")
568 HType(
const HType& v)
574 void setId(hid_t new_id)
606 ARCANE_DEPRECATED_REASON(
"Y2023: Copy constructor is deprecated. This class has unique ownership")
620 hid_t nativeType(
float)
const {
return H5T_NATIVE_FLOAT; }
621 hid_t nativeType(
double)
const {
return H5T_NATIVE_DOUBLE; }
626 hid_t nativeType(
long double)
const {
return H5T_NATIVE_LDOUBLE; }
627 hid_t nativeType(
unsigned int)
const {
return H5T_NATIVE_UINT; }
628 hid_t nativeType(
unsigned long)
const {
return H5T_NATIVE_ULONG; }
629 hid_t nativeType(
unsigned long long)
const {
return H5T_NATIVE_ULLONG; }
630 hid_t nativeType(
int)
const {
return H5T_NATIVE_INT; }
631 hid_t nativeType(
long long)
const {
return H5T_NATIVE_LLONG; }
632 hid_t nativeType(
long)
const {
return H5T_NATIVE_LONG; }
633 hid_t nativeType(
char)
const {
return H5T_NATIVE_CHAR; }
634 hid_t nativeType(
unsigned char)
const {
return H5T_NATIVE_UCHAR; }
635 hid_t nativeType(
signed char)
const {
return H5T_NATIVE_SCHAR; }
636 hid_t nativeType(
unsigned short)
const {
return H5T_NATIVE_USHORT; }
637 hid_t nativeType(
short)
const {
return H5T_NATIVE_SHORT; }
638#ifdef ARCANE_REAL_NOT_BUILTIN
639 hid_t nativeType(
Real)
const;
647 hid_t saveType(
float)
const
651 hid_t saveType(
double)
const
655 hid_t saveType(
Real2)
const
659 hid_t saveType(
Real3)
const
671 hid_t saveType(
long double)
const
675 hid_t saveType(
short)
const
679 hid_t saveType(
unsigned short)
const
683 hid_t saveType(
unsigned int)
const
687 hid_t saveType(
unsigned long)
const
691 hid_t saveType(
unsigned long long)
const
695 hid_t saveType(
int)
const
699 hid_t saveType(
long)
const
703 hid_t saveType(
long long)
const
707 hid_t saveType(
char)
const
711 hid_t saveType(
unsigned char)
const
715 hid_t saveType(
signed char)
const
727#ifdef ARCANE_REAL_NOT_BUILTIN
728 hid_t saveType(
Real)
const
768 void _H5Tinsert(hid_t type,
const char* name,
Integer offset, hid_t field_id);
777class ARCANE_HDF5_EXPORT StandardArray
781 StandardArray(hid_t hfile,
const String& hpath);
782 virtual ~StandardArray() {}
795 virtual bool exists()
const;
799 void _write(
const void* buffer,
Integer nb_element, hid_t save_type, hid_t native_type);
818template <
typename DataType>
819class ARCANE_HDF5_EXPORT StandardArrayT
820:
public StandardArray
835 return m_uid < rhs.m_uid;
841 StandardArrayT(hid_t hfile,
const String& hpath);
875template <
typename DataType>
Declarations of types used in Arcane.
Modifiable view of an array of type T.
Base class for 1D data vectors.
Constant view of an array of type T.
Half-precision floating-point type.
Encapsulates a hid_t for a dataset.
Class serving as an initializer for HDF.
static constexpr bool hasParallelHdf5()
True HDF5 is compiled with MPI support.
Encapsulates a hid_t for a property (H5P*).
void createDatasetTransfertCollectiveMPIIO()
Creates a dataset property for MPIIO.
void createFilePropertyMPIIO(IParallelMng *pm)
Creates a file property for MPIIO.
void createDatasetTransfertIndependentMPIIO()
Creates a dataset property for MPIIO.
Encapsulates a hid_t for a dataspace.
Encapsulates a hid_t for a type.
void read(StandardTypes &st, ArrayView< DataType > buffer)
Reads the dataset of a 1D array. This operation is only valid after calling readDim()....
void directRead(StandardTypes &st, Array< DataType > &buffer)
Reads the dataset of a 1D array.
void setIdsPath(const String &ids_path)
When reading, positions the path in hfile to the dataset containing the unique_ids.
StandardScalarT(hid_t hfile, const String &hpath)
Constructor.
Definition of standard Arcane types for hdf5.
HType m_bfloat16_id
HDF identifier for BFloat16.
HType m_real2x2_id
HDF identifier for Real2x2.
StandardTypes()
Creates an instance by initializing the types.
HType m_long_id
HDF identifier for signed longs.
HType m_int_id
HDF identifier for signed integers.
HType m_short_id
HDF identifier for signed shorts.
HType m_real3x3_id
HDF identifier for Real3x3.
HType m_real_id
HDF identifier for reals.
HType m_ushort_id
HDF identifier for unsigned shorts.
HType m_ulong_id
HDF identifier for unsigned longs.
HType m_schar_id
HDF identifier for signed characters.
HType m_uchar_id
HDF identifier for unsigned characters.
HType m_real2_id
HDF identifier for Real2.
HType m_float32_id
HDF identifier for Float32.
HType m_float16_id
HDF identifier for Float16.
HType m_char_id
HDF identifier for characters.
void initialize()
Initializes the types.
HType m_uint_id
HDF identifier for unsigned integers.
HInit m_init
Class initializing HDF.
HType m_real3_id
HDF identifier for Real3.
Interface of the parallelism manager for a subdomain.
Class managing a 2-dimensional real vector.
Class managing a 2x2 matrix of reals.
Class managing a 3-dimensional real vector.
Class managing a 3x3 real matrix.
Unicode character string.
Utility functions for Hdf5.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Array< Int64 > Int64Array
Dynamic one-dimensional array of 64-bit integers.
UniqueArray< Int64 > Int64UniqueArray
Dynamic 1D array of 64-bit integers.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
double Real
Type representing a real number.