diff options
author | tradke <tradke@7842ec3a-9562-4be5-9c5b-06ba18f2b668> | 2000-10-12 11:45:59 +0000 |
---|---|---|
committer | tradke <tradke@7842ec3a-9562-4be5-9c5b-06ba18f2b668> | 2000-10-12 11:45:59 +0000 |
commit | 87adfe63f5d5e8373345231a5331b14abfd14cab (patch) | |
tree | 91d3d5b13a778de67793c8c01432c3969701821e /src/ioHDF5UtilGH.h | |
parent | 52f2259ab2b7445288e2e7d7688cd8e50fa39fd1 (diff) |
This commit was generated by cvs2svn to compensate for changes in r2, which
included commits to RCS files with non-trunk default branches.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOHDF5Util/trunk@3 7842ec3a-9562-4be5-9c5b-06ba18f2b668
Diffstat (limited to 'src/ioHDF5UtilGH.h')
-rw-r--r-- | src/ioHDF5UtilGH.h | 217 |
1 files changed, 217 insertions, 0 deletions
diff --git a/src/ioHDF5UtilGH.h b/src/ioHDF5UtilGH.h new file mode 100644 index 0000000..de2de80 --- /dev/null +++ b/src/ioHDF5UtilGH.h @@ -0,0 +1,217 @@ + /*@@ + @header ioHDF5UtilGH.h + @date Fri Oct 6 2000 + @author Thomas Radke + @desc + The GH extensions structure for IOHDF5Util. + @version $Id$ + @@*/ + +#ifndef _IOUTILHDF5_IOUTILHDF5GH_H_ +#define _IOUTILHDF5_IOUTILHDF5GH_H_ + +/* 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; \ + \ + \ + 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 \ + { \ + int len; \ + hid_t attr; \ + void *val = value; \ + hsize_t arrayDim = dim; \ + \ + \ + if (H5Tget_class (datatype) == H5T_STRING) \ + { \ + len = strlen ((char *) val); \ + if (len == 0) /* HDF5 doesn't like zero-len strings */ \ + { \ + len++; \ + } \ + IOHDF5_ERROR (H5Tset_size (datatype, len)); \ + } \ + if (arrayDim > 0) \ + { \ + IOHDF5_ERROR (H5Sset_extent_simple (dataspace, 1, \ + &arrayDim, NULL)); \ + } \ + IOHDF5_ERROR (attr = H5Acreate (dataset, name, datatype, \ + dataspace, H5P_DEFAULT)); \ + IOHDF5_ERROR (H5Awrite (attr, datatype, val)); \ + IOHDF5_ERROR (H5Aclose (attr)); \ + } while (0); + +/* macro for reading an attribute */ +#define READ_ATTRIBUTE(dataset, attrname, requested_type, buffer) \ + do \ + { \ + hid_t attr, attrtype; \ + hsize_t asize = 0; \ + \ + \ + if ((attr = H5Aopen_name (dataset, attrname)) < 0) \ + { \ + CCTK_WARN (1, "Can't find " attrname " attribute"); \ + } \ + if (requested_type == H5T_C_S1) \ + { \ + IOHDF5_ERROR (attrtype = H5Aget_type (attr)); \ + IOHDF5_ERROR (asize = H5Tget_size (attrtype)); \ + if (asize + 1 >= sizeof (buffer)) \ + { \ + CCTK_WARN (1, "Can't read " attrname " attribute (too long)");\ + } \ + } \ + else \ + { \ + attrtype = requested_type; \ + } \ + if (H5Aread (attr, attrtype, buffer) < 0) \ + { \ + CCTK_WARN (1, "Can't read " attrname " attribute"); \ + } \ + if (requested_type == H5T_C_S1) \ + { \ + ((char *) buffer)[asize] = 0; \ + IOHDF5_ERROR (H5Tclose (attrtype)); \ + } \ + IOHDF5_ERROR (H5Aclose (attr)); \ + } while (0) + + +/* Mapping off CCTK datatypes to HDF5 datatypes */ +#define IOHDF5_REAL4 H5T_NATIVE_FLOAT + +#ifdef CCTK_REAL_PRECISION_16 +#define IOHDF5_REAL H5T_NATIVE_LDOUBLE +#elif CCTK_REAL_PRECISION_8 +#define IOHDF5_REAL H5T_NATIVE_DOUBLE +#elif CCTK_REAL_PRECISION_4 +#define IOHDF5_REAL H5T_NATIVE_FLOAT +#endif + +#define IOHDF5_INT (sizeof (CCTK_INT) == sizeof (int) ? \ + H5T_NATIVE_INT : H5T_NATIVE_SHORT) +#define IOHDF5_INT4 (sizeof (int) == 4 ? \ + H5T_NATIVE_INT : H5T_NATIVE_SHORT) +#define IOHDF5_CHAR H5T_NATIVE_CHAR + + +/* Constants to index timers within the timers array */ +#define CP_PARAMETERS_TIMER 0 +#define CP_VARIABLES_TIMER 1 +#define CP_TOTAL_TIMER 2 +#define RECOVERY_TIMER 3 +#define IOHDF5_NUM_TIMERS 4 + +/* names of the groups that hold global attributes and parameters */ +#define GLOBAL_ATTRIBUTES_GROUP "Global Attributes" +#define CACTUS_PARAMETERS_GROUP "Cactus Parameters" +#define ALL_PARAMETERS "All Parameters" + + +/* Geometry information structure for output variable */ +/* FIXME: allocate arrays dynamically */ +#define IOHDF5_MAXDIM 5 +typedef struct +{ + int vdim; + int sdim; + int direction[IOHDF5_MAXDIM]; + int origin[IOHDF5_MAXDIM]; + int length[IOHDF5_MAXDIM]; + int downsample[IOHDF5_MAXDIM]; + int actlen[IOHDF5_MAXDIM]; /* actual index slab length (by PUGHSlab)*/ +} ioHDF5Geo_t; + + +/* 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 */ +} fileinfo_t; + + +/* IOHDF5Util 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; + + /* predefined datatype for writing C string string attributes */ + hid_t IOHDF5_STRING; + +} ioHDF5UtilGH; + + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* exported functions */ +int IOHDF5Util_ParseVarsForOutput (const char *var_list, + char do_output[], + ioHDF5Geo_t geo_output[]); +void IOHDF5Util_DefaultGeo (ioHDF5Geo_t *slab); +void IOHDF5Util_DumpParameters (cGH *GH, hid_t group); +void IOHDF5Util_DumpGHExtensions (cGH *GH, hid_t group); +int IOHDF5Util_DumpGH (cGH *GH, int timers[], hid_t file); +void IOHDF5Util_DumpCommonAttributes (cGH *GH, + int index, + int timelevel, + CCTK_INT global_shape[], + ioHDF5Geo_t *slab, + hid_t dataset); +int IOHDF5Util_DumpVar (cGH *GH, + int index, + int timelevel, + ioHDF5Geo_t *slab, + hid_t file, + int check_exisiting_objects); +int IOHDF5Util_RecoverParameters (fileinfo_t *filenfo); +int IOHDF5Util_RecoverGHextensions (cGH *GH, + fileinfo_t *filenfo); +int IOHDF5Util_RecoverVariables (cGH *GH, + fileinfo_t *filenfo); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* _IOUTILHDF5_IOUTILHDF5GH_H_ */ |