aboutsummaryrefslogtreecommitdiff
path: root/src/ioHDF5UtilGH.h
diff options
context:
space:
mode:
authortradke <tradke@7842ec3a-9562-4be5-9c5b-06ba18f2b668>2002-04-23 14:58:00 +0000
committertradke <tradke@7842ec3a-9562-4be5-9c5b-06ba18f2b668>2002-04-23 14:58:00 +0000
commitb31eef3fee54b3133265c466eec75714d34d4e99 (patch)
treeb7ed2ac60935828bf93f92a829913e63d2352862 /src/ioHDF5UtilGH.h
parent1111ce1fb848e6490b311b1ec5ba4363765e0333 (diff)
Code cleanup before moving into production mode.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOHDF5Util/trunk@58 7842ec3a-9562-4be5-9c5b-06ba18f2b668
Diffstat (limited to 'src/ioHDF5UtilGH.h')
-rw-r--r--src/ioHDF5UtilGH.h292
1 files changed, 149 insertions, 143 deletions
diff --git a/src/ioHDF5UtilGH.h b/src/ioHDF5UtilGH.h
index dfdb31e..62dc98a 100644
--- a/src/ioHDF5UtilGH.h
+++ b/src/ioHDF5UtilGH.h
@@ -3,88 +3,87 @@
@date Fri Oct 6 2000
@author Thomas Radke
@desc
- The GH extensions structure for IOHDF5Util.
+ The GH extensions structure for thorn IOHDF5Util.
@enddesc
- @version $Id$
+ @version $Header$
@@*/
#ifndef _IOUTILHDF5_IOUTILHDF5GH_H_
-#define _IOUTILHDF5_IOUTILHDF5GH_H_
+#define _IOUTILHDF5_IOUTILHDF5GH_H_ 1
-/* include the HDF5 header file */
#include <hdf5.h>
-/*****************************************************************************/
-/* some useful macros */
-/*****************************************************************************/
-/* Check error flags from HDF5 calls */
-#define IOHDF5_ERROR(fn_call) \
- do \
- { \
- int _error_code = fn_call; \
+/********************************************************************
+ ******************** Macro Definitions ************************
+ ********************************************************************/
+/* check return code of HDF5 call and print a warning in case of an error */
+#define HDF5_ERROR(fn_call) \
+ { \
+ int _error_code = fn_call; \
\
\
- if (_error_code < 0) \
- { \
- CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, \
- "HDF5 call '%s' returned error code %d\n", \
- #fn_call, _error_code); \
- } \
- } while (0)
-
-/* macro for writing an attribute */
-#define WRITE_ATTRIBUTE(name, value, dataset, dataspace, dim, datatype) \
- do \
+ if (_error_code < 0) \
{ \
- int _len; \
- hid_t _attr; \
- /* this union is only there to fix a bug in the HDF5 API */ \
- union \
- { \
- const void *const_val; \
- void *non_const_val; \
- } _v; \
- hsize_t _arrayDim = dim; \
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, \
+ "HDF5 call '%s' returned error code %d", \
+ #fn_call, _error_code); \
+ } \
+ }
+
+/* append an attribute to a given file object */
+#define WRITE_ATTRIBUTE(name, value, object, ioHDF5UtilGH, dim, datatype) \
+ { \
+ int _len; \
+ hid_t _attr, _dataspace; \
+ /* this union is only there to fix a bug in the HDF5 API */ \
+ union \
+ { \
+ const void *const_val; \
+ void *non_const_val; \
+ } _v; \
+ hsize_t _dim = dim; \
\
\
- _v.const_val = value; \
- if (H5Tget_class (datatype) == H5T_STRING) \
- { \
- _len = strlen ((const char *) _v.const_val); \
- if (_len == 0) /* HDF5 doesn't like zero-len strings */ \
- { \
- _len++; \
- } \
- IOHDF5_ERROR (H5Tset_size (datatype, _len)); \
- } \
- if (_arrayDim > 0) \
+ _v.const_val = value; \
+ if (H5Tget_class (datatype) == H5T_STRING) \
+ { \
+ _len = strlen ((const char *) _v.const_val); \
+ if (_len == 0) /* HDF5 doesn't like zero-len strings */ \
{ \
- IOHDF5_ERROR (H5Sset_extent_simple (dataspace, 1, \
- &_arrayDim, NULL)); \
+ _len++; \
} \
- IOHDF5_ERROR (_attr = H5Acreate (dataset, name, datatype, \
- dataspace, H5P_DEFAULT)); \
- IOHDF5_ERROR (H5Awrite (_attr, datatype, _v.non_const_val)); \
- IOHDF5_ERROR (H5Aclose (_attr)); \
- } while (0);
-
-/* macro for reading an attribute */
-#define READ_ATTRIBUTE(dataset, attrname, requested_type, buffer) \
- do \
+ HDF5_ERROR (H5Tset_size (datatype, _len)); \
+ } \
+ if (_dim > 0) \
{ \
- hid_t _attr, _attrtype; \
- hsize_t _asize = 0; \
+ _dataspace = ioHDF5UtilGH->array_dataspace; \
+ HDF5_ERROR (H5Sset_extent_simple (_dataspace, 1, &_dim, NULL)); \
+ } \
+ else \
+ { \
+ _dataspace = ioHDF5UtilGH->scalar_dataspace; \
+ } \
+ HDF5_ERROR (_attr = H5Acreate (object, name, datatype, _dataspace, \
+ H5P_DEFAULT)); \
+ HDF5_ERROR (H5Awrite (_attr, datatype, _v.non_const_val)); \
+ HDF5_ERROR (H5Aclose (_attr)); \
+ }
+
+/* read an attribute in a given file object */
+#define READ_ATTRIBUTE(object, attrname, requested_type, buffer) \
+ { \
+ hid_t _attr, _attrtype; \
+ hsize_t _asize = 0; \
\
\
- if ((_attr = H5Aopen_name (dataset, attrname)) < 0) \
- { \
- CCTK_WARN (1, "Can't find " attrname " attribute"); \
- } \
+ _attr = H5Aopen_name (object, attrname); \
+ if (_attr >= 0) \
+ { \
if (requested_type == H5T_C_S1) \
{ \
- IOHDF5_ERROR (_attrtype = H5Aget_type (_attr)); \
- IOHDF5_ERROR (_asize = H5Tget_size (_attrtype)); \
+ HDF5_ERROR (_attrtype = H5Aget_type (_attr)); \
+ HDF5_ERROR (_asize = H5Tget_size (_attrtype)); \
if (_asize + 1 >= sizeof (buffer)) \
{ \
CCTK_WARN (1, "Can't read " attrname " attribute (too long)");\
@@ -96,81 +95,84 @@
} \
if (H5Aread (_attr, _attrtype, buffer) < 0) \
{ \
- CCTK_WARN (1, "Can't read " attrname " attribute"); \
+ CCTK_WARN (1, "Can't read '" attrname "' attribute"); \
} \
if (requested_type == H5T_C_S1) \
{ \
((char *) buffer)[_asize] = 0; \
- IOHDF5_ERROR (H5Tclose (_attrtype)); \
+ HDF5_ERROR (H5Tclose (_attrtype)); \
} \
- IOHDF5_ERROR (H5Aclose (_attr)); \
- } while (0)
+ HDF5_ERROR (H5Aclose (_attr)); \
+ } \
+ else \
+ { \
+ CCTK_WARN (1, "Can't find '" attrname "' attribute"); \
+ } \
+ }
-/***
- Define the different datatypes used for HDF5 I/O
- NOTE: the complex datatype is defined dynamically at runtime in Startup.c
+/*** Define the different datatypes used for HDF5 I/O
+ NOTE: the complex datatype is defined dynamically at runtime in Startup.c
***/
/* char type is easy */
-#define IOHDF5_CHAR H5T_NATIVE_CHAR
+#define HDF5_CHAR H5T_NATIVE_CHAR
/* floating point types are architecture-independent,
ie. a float has always 4 bytes, and a double has 8 bytes
-
- IOHDF5_REAL is used for storing reals of the generic CCTK_REAL type
- IOHDF5_REALn is used to explicitely store n-byte reals */
+ HDF5_REAL is used for storing reals of the generic CCTK_REAL type
+ HDF5_REALn is used to explicitely store n-byte reals */
#ifdef CCTK_REAL4
-#define IOHDF5_REAL4 H5T_NATIVE_FLOAT
+#define HDF5_REAL4 H5T_NATIVE_FLOAT
#endif
#ifdef CCTK_REAL8
-#define IOHDF5_REAL8 H5T_NATIVE_DOUBLE
+#define HDF5_REAL8 H5T_NATIVE_DOUBLE
#endif
#ifdef CCTK_REAL16
-#define IOHDF5_REAL16 (sizeof (CCTK_REAL16) == sizeof (long double) ? \
- H5T_NATIVE_LDOUBLE : -1)
+#define HDF5_REAL16 (sizeof (CCTK_REAL16) == sizeof (long double) ? \
+ H5T_NATIVE_LDOUBLE : -1)
#endif
#ifdef CCTK_REAL_PRECISION_16
-#define IOHDF5_REAL IOHDF5_REAL16
+#define HDF5_REAL HDF5_REAL16
#elif CCTK_REAL_PRECISION_8
-#define IOHDF5_REAL IOHDF5_REAL8
+#define HDF5_REAL HDF5_REAL8
#elif CCTK_REAL_PRECISION_4
-#define IOHDF5_REAL IOHDF5_REAL4
+#define HDF5_REAL HDF5_REAL4
#endif
/* integer types are architecture-dependent:
- IOHDF5_INT is used for communicating integers of the generic CCTK_INT type
- IOHDF5_INTn is used to explicitely communicate n-byte integers */
+ HDF5_INT is used for communicating integers of the generic CCTK_INT type
+ HDF5_INTn is used to explicitely communicate n-byte integers */
#ifdef CCTK_INT8
-#define IOHDF5_INT8 (sizeof (CCTK_INT8) == sizeof (int) ? H5T_NATIVE_INT : \
- sizeof (CCTK_INT8) == sizeof (long) ? H5T_NATIVE_LONG :\
- sizeof (CCTK_INT8) == sizeof (long long) ? \
- H5T_NATIVE_LLONG : -1)
+#define HDF5_INT8 (sizeof (CCTK_INT8) == sizeof (int) ? H5T_NATIVE_INT : \
+ sizeof (CCTK_INT8) == sizeof (long) ? H5T_NATIVE_LONG : \
+ sizeof (CCTK_INT8) == sizeof (long long) ? \
+ H5T_NATIVE_LLONG : -1)
#endif
#ifdef CCTK_INT4
-#define IOHDF5_INT4 (sizeof (CCTK_INT4) == sizeof (int) ? H5T_NATIVE_INT : \
- sizeof (CCTK_INT4) == sizeof (short) ? \
- H5T_NATIVE_SHORT : -1)
+#define HDF5_INT4 (sizeof (CCTK_INT4) == sizeof (int) ? H5T_NATIVE_INT : \
+ sizeof (CCTK_INT4) == sizeof (short) ? \
+ H5T_NATIVE_SHORT : -1)
#endif
#ifdef CCTK_INT2
-#define IOHDF5_INT2 (sizeof (CCTK_INT2) == sizeof (short) ? \
- H5T_NATIVE_SHORT : -1)
+#define HDF5_INT2 (sizeof (CCTK_INT2) == sizeof (short) ? \
+ H5T_NATIVE_SHORT : -1)
#endif
#ifdef CCTK_INTEGER_PRECISION_8
-#define IOHDF5_INT IOHDF5_INT8
+#define HDF5_INT HDF5_INT8
#elif CCTK_INTEGER_PRECISION_4
-#define IOHDF5_INT IOHDF5_INT4
+#define HDF5_INT HDF5_INT4
#elif CCTK_INTEGER_PRECISION_2
-#define IOHDF5_INT IOHDF5_INT2
+#define HDF5_INT HDF5_INT2
#endif
-/* Constants to index timers within the timers array */
+/* constants to index timers within the timers array */
#define CP_PARAMETERS_TIMER 0
#define CP_VARIABLES_TIMER 1
#define CP_TOTAL_TIMER 2
@@ -188,82 +190,86 @@ extern "C"
{
#endif
-/* Geometry information structure for output variable */
+/* structure for hyperslab descriptions of output variables */
typedef struct
{
- int vdim;
- int sdim;
- int *direction;
- int *origin;
- int *length;
- int *downsample;
- int *actlen; /* actual index slab length (by PUGHSlab)*/
-} ioHDF5Geo_t;
+ /* index and timelevel of the variable */
+ int vindex, timelevel;
+
+ /* dimensionality of the variable and the hyperslab */
+ int vdim, hdim;
+ /* CCTK datatype for the hyperslab */
+ int hdatatype;
-/* Structure describing a given recovery file */
+ /* flag indicating wheter check whether an object to be written already
+ exists (and remove it in that case) */
+ int check_exist;
+
+ /* pointer to allocated buffers */
+ CCTK_INT *vectors;
+
+ /* hyperslab mapping parameters */
+ CCTK_INT *origin, *direction, *extent, *downsample;
+
+ /* offset and sizes of hyperslab into the variable's dataspace */
+ CCTK_INT *hoffset, *hsize, *hsize_chunk;
+
+} ioSlab;
+
+
+/* structure describing a given recovery file */
typedef struct
{
- int is_HDF5_file; /* flag indicating valid file info */
- hid_t file; /* HDF5 file handle */
- char *filename; /* complete file name for recovery */
- int nprocs; /* number of total processors */
- int ioproc; /* the associated IO processor */
- int ioproc_every; /* how many IO processors there are */
- int unchunked; /* whether data was written chunked or unchunked */
- int has_version; /* whether file contains a Cactus version ID
- (this is used to distinguish checkpoint files
- with old/new timelevel naming scheme) */
+ /* flag indicating valid file info */
+ int is_HDF5_file;
+
+ /* HDF5 file handle */
+ hid_t file;
+
+ /* complete file name for recovery */
+ char *filename;
+
+ /* number of total and I/O processors, the associated IO processor,
+ flag telling whether data was written chunked or unchunked */
+ int nprocs, ioproc_every, ioproc, unchunked;
+
+ /* whether file contains a Cactus version ID (used to distinguish checkpoint
+ files with old/new timelevel naming scheme) */
+ int has_version;
+
} fileinfo_t;
-/* IOHDF5Util GH extension structure */
+/* IOHDF5Util's GH extension structure */
typedef struct
{
- /* while HDF5 error output is disabled
- we keep the original error printing routine and its argument in here */
- H5E_auto_t print_error_fn;
- void *print_error_fn_arg;
-
/* predefined dataspaces for writing scalar and array attributes */
hid_t scalar_dataspace, array_dataspace;
/* predefined datatype for writing CCTK_COMPLEX types */
- hid_t IOHDF5_COMPLEX,
- IOHDF5_COMPLEX8,
- IOHDF5_COMPLEX16,
- IOHDF5_COMPLEX32;
+ hid_t HDF5_COMPLEX, HDF5_COMPLEX8, HDF5_COMPLEX16, HDF5_COMPLEX32;
/* predefined datatype for writing C string string attributes */
- hid_t IOHDF5_STRING;
+ hid_t HDF5_STRING;
} ioHDF5UtilGH;
/* exported functions */
hid_t IOHDF5Util_DataType (const ioHDF5UtilGH *myGH, int cctk_type);
-void IOHDF5Util_ParseVarsForOutput (const char *output_varstring,
- ioHDF5Geo_t *output_request_list[]);
+void IOHDF5Util_ParseVarsForOutput (const cGH *GH, const char *output_varstring,
+ ioSlab *output_request_list[]);
void IOHDF5Util_DumpParameters (const cGH *GH, int all, hid_t group);
void IOHDF5Util_DumpGHExtensions (const cGH *GH, hid_t group);
int IOHDF5Util_DumpGH (const cGH *GH, const int *timers, hid_t file);
-void IOHDF5Util_DumpCommonAttributes (const cGH *GH,
- int vindex,
- int timelevel,
- const CCTK_INT *global_shape,
- const ioHDF5Geo_t *slab,
+void IOHDF5Util_DumpCommonAttributes (const cGH *GH, const ioSlab *slab,
hid_t dataset);
-int IOHDF5Util_DumpVar (const cGH *GH,
- int vindex,
- int timelevel,
- const ioHDF5Geo_t *slab,
- hid_t file,
- int check_exisiting_objects);
+int IOHDF5Util_DumpVar (const cGH *GH, const ioSlab *slab, hid_t file);
+
int IOHDF5Util_RecoverParameters (const fileinfo_t *filenfo);
-int IOHDF5Util_RecoverGHextensions (cGH *GH,
- const fileinfo_t *filenfo);
-int IOHDF5Util_RecoverVariables (cGH *GH,
- const fileinfo_t *filenfo);
+int IOHDF5Util_RecoverGHextensions (cGH *GH, const fileinfo_t *filenfo);
+int IOHDF5Util_RecoverVariables (cGH *GH, const fileinfo_t *filenfo);
#ifdef __cplusplus
} // extern "C"