xref: /petsc/include/petscviewerhdf5.h (revision 9a0502c650a1f9e8ff1ace346fad63beb9fe6c5d)
1d70abbfaSBarry Smith 
2d70abbfaSBarry Smith #if !defined(__PETSCVIEWERHDF5_H)
3d70abbfaSBarry Smith #define __PETSCVIEWERHDF5_H
4d70abbfaSBarry Smith 
5d70abbfaSBarry Smith #include <petscviewer.h>
6d70abbfaSBarry Smith 
72c1a2d08SJed Brown #if defined(PETSC_HAVE_HDF5)
82c1a2d08SJed Brown 
9d70abbfaSBarry Smith #include <hdf5.h>
10d70abbfaSBarry Smith PETSC_EXTERN PetscErrorCode PetscViewerHDF5GetFileId(PetscViewer,hid_t*);
11d70abbfaSBarry Smith PETSC_EXTERN PetscErrorCode PetscViewerHDF5OpenGroup(PetscViewer, hid_t *, hid_t *);
127adab82aSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscViewerHDF5ReadSizes(PetscViewer, const char[], PetscInt *, PetscInt *);
13d70abbfaSBarry Smith 
14d70abbfaSBarry Smith /* On 32 bit systems HDF5 is limited by size of integer, because hsize_t is defined as size_t */
15d70abbfaSBarry Smith #define PETSC_HDF5_INT_MAX  2147483647
16d70abbfaSBarry Smith #define PETSC_HDF5_INT_MIN -2147483647
17d70abbfaSBarry Smith 
18d70abbfaSBarry Smith #undef __FUNCT__
19d70abbfaSBarry Smith #define __FUNCT__ "PetscHDF5IntCast"
20d70abbfaSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscHDF5IntCast(PetscInt a,hsize_t *b)
21d70abbfaSBarry Smith {
22d70abbfaSBarry Smith   PetscFunctionBegin;
23d70abbfaSBarry Smith #if defined(PETSC_USE_64BIT_INDICES) && (PETSC_SIZEOF_SIZE_T == 4)
24d70abbfaSBarry Smith   if ((a) > PETSC_HDF5_INT_MAX) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Array too long for HDF5");
25d70abbfaSBarry Smith #endif
26d70abbfaSBarry Smith   *b =  (hsize_t)(a);
27d70abbfaSBarry Smith   PetscFunctionReturn(0);
28d70abbfaSBarry Smith }
2936bce6e8SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDataTypeToHDF5DataType(PetscDataType,hid_t*);
3036bce6e8SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscHDF5DataTypeToPetscDataType(hid_t,PetscDataType*);
312c1a2d08SJed Brown 
3270efba33SBarry Smith #define PetscStackCallHDF5(func,args) do {                        \
33729ab6d9SBarry Smith     herr_t _status;                                               \
34729ab6d9SBarry Smith     PetscStackPush(#func);_status = func args;PetscStackPop; if (_status) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in HDF5 call %s() Status %d",#func,(int)_status); \
35729ab6d9SBarry Smith   } while (0)
36729ab6d9SBarry Smith 
37729ab6d9SBarry Smith #define PetscStackCallHDF5Return(ret,func,args) do {              \
38729ab6d9SBarry Smith     PetscStackPush(#func);ret = func args;PetscStackPop; if (ret < 0) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in HDF5 call %s() Status %d",#func,(int)ret); \
3970efba33SBarry Smith   } while (0)
4070efba33SBarry Smith 
412c1a2d08SJed Brown #endif  /* defined(PETSC_HAVE_HDF5) */
42d70abbfaSBarry Smith 
43ad0c61feSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscViewerHDF5ReadAttribute(PetscViewer,const char[],const char[],PetscDataType,void*);
4436bce6e8SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscViewerHDF5WriteAttribute(PetscViewer,const char[],const char[],PetscDataType,const void*);
45e7bdbf8eSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscViewerHDF5HasAttribute(PetscViewer, const char[], const char[], PetscBool *);
46d70abbfaSBarry Smith PETSC_EXTERN PetscErrorCode PetscViewerHDF5WriteSDS(PetscViewer,float *,int,int *,int);
47d70abbfaSBarry Smith 
48d70abbfaSBarry Smith PETSC_EXTERN PetscErrorCode PetscViewerHDF5Open(MPI_Comm,const char[],PetscFileMode,PetscViewer*);
49d70abbfaSBarry Smith PETSC_EXTERN PetscErrorCode PetscViewerHDF5PushGroup(PetscViewer,const char *);
50d70abbfaSBarry Smith PETSC_EXTERN PetscErrorCode PetscViewerHDF5PopGroup(PetscViewer);
51d70abbfaSBarry Smith PETSC_EXTERN PetscErrorCode PetscViewerHDF5GetGroup(PetscViewer, const char **);
52d70abbfaSBarry Smith PETSC_EXTERN PetscErrorCode PetscViewerHDF5IncrementTimestep(PetscViewer);
53d70abbfaSBarry Smith PETSC_EXTERN PetscErrorCode PetscViewerHDF5SetTimestep(PetscViewer,PetscInt);
54d70abbfaSBarry Smith PETSC_EXTERN PetscErrorCode PetscViewerHDF5GetTimestep(PetscViewer,PetscInt*);
55d70abbfaSBarry Smith 
5682ea9b62SBarry Smith PETSC_EXTERN PetscErrorCode PetscViewerHDF5SetBaseDimension2(PetscViewer,PetscBool);
5782ea9b62SBarry Smith PETSC_EXTERN PetscErrorCode PetscViewerHDF5GetBaseDimension2(PetscViewer,PetscBool*);
5882ea9b62SBarry Smith 
59*9a0502c6SHåkon Strandenes PETSC_EXTERN PetscErrorCode PetscViewerHDF5SetSPOutput(PetscViewer,PetscBool);
60*9a0502c6SHåkon Strandenes PETSC_EXTERN PetscErrorCode PetscViewerHDF5GetSPOutput(PetscViewer,PetscBool*);
61*9a0502c6SHåkon Strandenes 
62e1e7ae07SJed Brown /* Reset __FUNCT__ in case the user does not define it themselves */
63e1e7ae07SJed Brown #undef __FUNCT__
64e1e7ae07SJed Brown #define __FUNCT__ "User provided function"
65e1e7ae07SJed Brown 
66d70abbfaSBarry Smith #endif
67