From 455d60f6a4e492628a52fc9c38b3838fe6bf66ae Mon Sep 17 00:00:00 2001 From: tradke Date: Tue, 10 Jun 2003 11:42:21 +0000 Subject: Added command line option '-single_precision'. If set, double-precision floating point datasets will be recombined and written in single precision. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOHDF5/trunk@169 4825ed28-b72c-4eae-9704-e50c059e567d --- src/util/hdf5_recombiner.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/util/hdf5_recombiner.c b/src/util/hdf5_recombiner.c index 0a3df97..d984ba7 100644 --- a/src/util/hdf5_recombiner.c +++ b/src/util/hdf5_recombiner.c @@ -72,7 +72,7 @@ static int nprocs = 0; /* total number of processors */ static int ioproc_every = 0; /* I/O was done on every N'th processor */ static int ninfiles = 0; /* number of input files */ static unsigned int nerrors = 0; /* global error counter */ - +static int single_precision = 0; /* recombine fp data in single precision */ /*****************************************************************************/ /* local function prototypes */ @@ -112,7 +112,7 @@ static int RecombineGroupData (const char *groupname); 0 for success, negative return values indicate an error @endreturndesc @@*/ -int main (int argc, const char *const argv[]) +int main (int argc, const char *argv[]) { int unchunked; char *tmp, *template; @@ -124,10 +124,20 @@ int main (int argc, const char *const argv[]) "\n Cactus 4 HDF5 File Recombiner" "\n -----------------------------\n\n"); + if (argc > 1 && strcmp (argv[1], "-single_precision") == 0) + { + single_precision = 1; + if (argc-- == 4) + { + argv[1] = argv[2]; + argv[2] = argv[3]; + } + } + /* give some help if called with incorrect number of parameters */ if (argc != 3) { - fprintf (stderr, "Usage: %s \n" + fprintf (stderr, "Usage: %s [-single_precision] \n" " eg, %s alp.file_0.h5 alp.h5\n\n", argv[0], argv[0]); return (0); } @@ -458,6 +468,14 @@ static herr_t CopyObject (hid_t from, CHECK_ERROR (from = H5Dopen (from, objectname)); CHECK_ERROR (datatype = H5Dget_type (from)); + + /* recombine floating-point data in single precision if requested */ + if (single_precision && H5Tget_class (datatype) == H5T_FLOAT) + { + CHECK_ERROR (H5Tclose (datatype)); + CHECK_ERROR (datatype = H5Tcopy (H5T_NATIVE_FLOAT)); + } + CHECK_ERROR (dataspace = H5Dget_space (from)); CHECK_ERROR (to = H5Dcreate (to, objectname, datatype, dataspace, H5P_DEFAULT)); @@ -745,6 +763,14 @@ static int RecombineGroupData (const char *groupname) /* the unchunked dataset gets the same datatype as the first chunk */ CHECK_ERROR (unchunked_datatype = H5Dget_type (chunked_dataset)); + + /* recombine floating-point data in single precision if requested */ + if (single_precision && H5Tget_class (unchunked_datatype) == H5T_FLOAT) + { + CHECK_ERROR (H5Tclose (unchunked_datatype)); + CHECK_ERROR (unchunked_datatype = H5Tcopy (H5T_NATIVE_FLOAT)); + } + CHECK_ERROR (unchunked_dataset = H5Dcreate (outfile, pathname, unchunked_datatype, unchunked_dataspace, -- cgit v1.2.3