aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortradke <tradke@4825ed28-b72c-4eae-9704-e50c059e567d>2001-12-28 21:41:15 +0000
committertradke <tradke@4825ed28-b72c-4eae-9704-e50c059e567d>2001-12-28 21:41:15 +0000
commit1c626d9a839b6ec9a0c07b12cf5ff1205b6c270b (patch)
tree91eff3dc0a397ac37895a7a0f467879c34ad5664 /src
parent8a6b1bab6403eb67ccb68492506087ed9a211b57 (diff)
Added utility program. See ThornGuide for details.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOHDF5/trunk@77 4825ed28-b72c-4eae-9704-e50c059e567d
Diffstat (limited to 'src')
-rw-r--r--src/make.configuration.defn6
-rw-r--r--src/make.configuration.deps16
-rw-r--r--src/util/hdf5_convert_from_ieeeio.c249
3 files changed, 270 insertions, 1 deletions
diff --git a/src/make.configuration.defn b/src/make.configuration.defn
index 4642d40..d51e272 100644
--- a/src/make.configuration.defn
+++ b/src/make.configuration.defn
@@ -1,4 +1,8 @@
# make.configuration.defn for IOHDF5
-# add the recombiner to the Cactus utitlity tools
+# add the recombiner and the IEEEIO converter to the Cactus utitlity tools
ALL_UTILS += hdf5_recombiner
+
+ifeq ($(findstring CactusExternal/FlexIO,$(THORNS)),CactusExternal/FlexIO)
+ALL_UTILS += hdf5_convert_from_ieeeio
+endif
diff --git a/src/make.configuration.deps b/src/make.configuration.deps
index db013a6..1c3ef59 100644
--- a/src/make.configuration.deps
+++ b/src/make.configuration.deps
@@ -1,10 +1,26 @@
+# linking rule for hdf5_recombiner
$(UTIL_DIR)$(DIRSEP)hdf5_recombiner: $(BUILD_DIR)$(DIRSEP)IOHDF5$(DIRSEP)hdf5_recombiner.o
@echo Creating hdf5_recombiner in $(UTIL_DIR) from $<
if [ ! -d $(UTIL_DIR) ]; then $(MKDIR) $(MKDIRFLAGS) $(UTIL_DIR) ; fi
$(LD) $(CREATEEXE)$(OPTIONSEP)$@ $(DEBUG_LD) $(LDFLAGS) $(EXTRAFLAGS) $< -L$(HDF5_LIB_DIRS) $(addprefix -l, $(HDF5_LIBS)) -lm
+# compile rule for hdf5_recombiner
$(BUILD_DIR)$(DIRSEP)IOHDF5$(DIRSEP)hdf5_recombiner.o: $(PACKAGE_DIR)$(DIRSEP)AlphaThorns$(DIRSEP)IOHDF5$(DIRSEP)src$(DIRSEP)util$(DIRSEP)hdf5_recombiner.c
@echo Compiling $<
if [ ! -d $(BUILD_DIR)$(DIRSEP)IOHDF5 ]; then $(MKDIR) $(MKDIRFLAGS) $(BUILD_DIR)$(DIRSEP)IOHDF5 ; fi
cd $(BUILD_DIR)$(DIRSEP)IOHDF5
$(CC) $< -DCCODE $(CFLAGS) -I$(CONFIG) -I$(BINDINGS_DIR)$(DIRSEP)include -I$(FLESH_DIR)$(DIRSEP)include -I$(CCTK_HOME)$(DIRSEP)arrangements -I$(HDF5_INC_DIRS) $(CCOMPILEONLY)$(OPTIONSEP)$@
+
+
+# linking rule for hdf5_convert_from_ieeeio
+$(UTIL_DIR)$(DIRSEP)hdf5_convert_from_ieeeio: $(BUILD_DIR)$(DIRSEP)IOHDF5$(DIRSEP)hdf5_convert_from_ieeeio.o
+ @echo Creating hdf5_convert_from_ieeeio in $(UTIL_DIR) from $<
+ if [ ! -d $(UTIL_DIR) ]; then $(MKDIR) $(MKDIRFLAGS) $(UTIL_DIR) ; fi
+ $(LD) $(CREATEEXE)$(OPTIONSEP)$@ $(DEBUG_LD) $(LDFLAGS) $(EXTRAFLAGS) $< -L$(CCTK_LIBDIR) -lFlexIO -L$(HDF5_LIB_DIRS) $(addprefix -l, $(HDF5_LIBS)) -lm
+
+# compile rule for hdf5_convert_from_ieeeio
+$(BUILD_DIR)$(DIRSEP)IOHDF5$(DIRSEP)hdf5_convert_from_ieeeio.o: $(PACKAGE_DIR)$(DIRSEP)AlphaThorns$(DIRSEP)IOHDF5$(DIRSEP)src$(DIRSEP)util$(DIRSEP)hdf5_convert_from_ieeeio.c
+ @echo Compiling $<
+ if [ ! -d $(BUILD_DIR)$(DIRSEP)IOHDF5 ]; then $(MKDIR) $(MKDIRFLAGS) $(BUILD_DIR)$(DIRSEP)IOHDF5 ; fi
+ cd $(BUILD_DIR)$(DIRSEP)IOHDF5
+ $(CC) $< -DCCODE $(CFLAGS) -DANSI -I$(CONFIG) -I$(BINDINGS_DIR)$(DIRSEP)include -I$(FLESH_DIR)$(DIRSEP)include -I$(CCTK_HOME)$(DIRSEP)arrangements -I$(HDF5_INC_DIRS) -I$(FLEXIO_INC_DIRS) $(CCOMPILEONLY)$(OPTIONSEP)$@
diff --git a/src/util/hdf5_convert_from_ieeeio.c b/src/util/hdf5_convert_from_ieeeio.c
new file mode 100644
index 0000000..d1b1f46
--- /dev/null
+++ b/src/util/hdf5_convert_from_ieeeio.c
@@ -0,0 +1,249 @@
+ /*@@
+ @file hdf5_convert_from_ieeeio.c
+ @date Fri 14 Dec 2001
+ @author Thomas Radke
+ @desc
+ Utility program to convert IOFlexIO datafiles into IOHDF5
+ datafiles.
+ @enddesc
+ @version $Id$
+ @@*/
+
+#define MAXDIM 3
+#define MAXNAMESIZE 100
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+/* FlexIO includes */
+#include "IOProtos.h"
+#include "IEEEIO.h"
+
+/* HDF5 include */
+#include <hdf5.h>
+
+int main (int argc, char **argv)
+{
+ int i, j;
+ IOFile infile;
+ int nDatasets, nAttributes;
+ int ieeeDatatype, rank, dims [MAXDIM];
+ int attrNumberType;
+ Long attrLen;
+ char attrName [MAXNAMESIZE];
+ void *data, *attrData;
+ hid_t outfile, dataset, dataspace, attribute, attrDataspace, hdf5Datatype;
+ hid_t hdf5String;
+ hsize_t hdf5Dims [MAXDIM];
+ herr_t (*old_func) (void *);
+ void *old_client_data;
+ int iteration, timelevel;
+ char ieeeDatasetName [MAXNAMESIZE], hdf5DatasetName [2 * MAXNAMESIZE];
+
+
+ if (argc <= 2) {
+ printf ("Usage: %s <inputfile> <outputfile>\n", argv [0]);
+ printf (" eg. %s foo.ieee bar.hdf5\n", argv [0]);
+ return (0);
+ }
+
+ infile = IEEEopen (argv [1], "r");
+ if (! IOisValid (infile)) {
+ printf ("Could not open input file '%s'\n", argv [1]);
+ return (-1);
+ }
+
+ outfile = H5Fcreate (argv [2], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ if (outfile < 0)
+ {
+ fprintf (stderr, "Could not create output file '%s'\n", argv [2]);
+ return (-1);
+ }
+
+ hdf5String = H5Tcopy (H5T_C_S1);
+
+ nDatasets = IOnDatasets (infile);
+ printf ("Input file contains %d datasets\n", nDatasets);
+
+ for (i = 0; i < nDatasets; i++)
+ {
+ if (IOreadInfo (infile, &ieeeDatatype, &rank, dims, MAXDIM) <= 0)
+ {
+ fprintf (stderr, "Cannot read info of datatset %d, skipping ...\n", i);
+ continue;
+ }
+
+ /* retrieve name and iteration attribute of dataset */
+ strcpy (attrName, "name");
+ j = IOreadAttributeInfo (infile, attrName, &attrNumberType, &attrLen);
+ if (j < 0)
+ {
+ fprintf (stderr,
+ "Cannot find name attribute of dataset %d, skipping ...\n", i);
+ continue;
+ }
+ if (IOreadAttribute (infile, j, ieeeDatasetName) < 0)
+ {
+ fprintf (stderr,
+ "Cannot read name attribute of dataset %d, skipping ...\n", i);
+ continue;
+ }
+ strcpy (attrName, "iteration");
+ j = IOreadAttributeInfo (infile, attrName, &attrNumberType, &attrLen);
+ if (j < 0)
+ {
+ fprintf (stderr, "Cannot find iteration attribute of dataset %d, "
+ "skipping ...\n", i);
+ continue;
+ }
+ if (IOreadAttribute (infile, j, &iteration) < 0)
+ {
+ fprintf (stderr, "Cannot read iteration attribute of dataset %d, "
+ "skipping ...\n", i);
+ continue;
+ }
+ strcpy (attrName, "timelevel");
+ j = IOreadAttributeInfo (infile, attrName, &attrNumberType, &attrLen);
+ if (j < 0)
+ {
+ fprintf (stderr, "Cannot find timelevel attribute of dataset %d,\n"
+ "assuming Cactus 3.x dataset with implicite timelevel 0 "
+ "...\n", i);
+ timelevel = 0;
+ }
+ else if (IOreadAttribute (infile, j, &timelevel) < 0)
+ {
+ fprintf (stderr, "Cannot read timelevel attribute of dataset %d, "
+ "skipping ...\n", i);
+ continue;
+ }
+
+ switch (ieeeDatatype)
+ {
+ case BYTE:
+ case CHAR:
+ hdf5Datatype = H5T_NATIVE_CHAR; break;
+
+ case FLOAT32:
+ hdf5Datatype = H5T_NATIVE_FLOAT; break;
+
+ case FLOAT64:
+ hdf5Datatype = H5T_NATIVE_DOUBLE; break;
+
+ case INT32:
+ hdf5Datatype = H5T_NATIVE_INT; break;
+
+ default:
+ fprintf (stderr, "Unknown datatype %d for dataset %d, skipping ...\n",
+ ieeeDatatype, i);
+ continue;
+ }
+
+ /* convert ordering (FlexIO uses fortran order, HDF5 uses C order) */
+ for (j = 0; j < rank; j++)
+ {
+ hdf5Dims [j] = dims [rank - j - 1];
+ }
+ dataspace = H5Screate_simple (rank, hdf5Dims, NULL);
+ assert (dataspace >= 0);
+
+ sprintf (hdf5DatasetName, "/%s@%d@%d", ieeeDatasetName, iteration, timelevel);
+ dataset = H5Dcreate (outfile, hdf5DatasetName, hdf5Datatype, dataspace,
+ H5P_DEFAULT);
+ assert (dataset >= 0);
+
+ data = malloc (IOnBytes (ieeeDatatype, rank, dims));
+ IOread (infile, data);
+ assert (H5Dwrite (dataset, hdf5Datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT,
+ data) >= 0);
+
+ nAttributes = IOnAttributes (infile);
+ printf ("Processing dataset '%s' with %d attributes\n",
+ ieeeDatasetName, nAttributes);
+
+ for (j = 0; j < nAttributes; j++)
+ {
+ int len;
+
+ if (IOreadIndexedAttributeInfo (infile, j, attrName, &attrNumberType,
+ &attrLen, MAXNAMESIZE) < 0)
+ {
+#if 0
+ /* it's only a bug if IOreadIndexedAttributeInfo() returns -1 */
+ printf ("Cannot read info of attribute %d, skipping ...\n", j);
+ continue;
+#endif
+ }
+
+ len = (int) attrLen;
+ /* I don't know why but I have to add one byte - otherwise
+ it crashes sometimes when freeing this memory */
+ attrData = malloc (1 + IOnBytes (attrNumberType, 1, &len));
+ if (IOreadAttribute (infile, j, attrData) < 0)
+ {
+ fprintf (stderr, "Cannot read value of attribute %d, skipping ...\n",j);
+ continue;
+ }
+
+ switch (attrNumberType)
+ {
+ case BYTE:
+ case CHAR:
+ hdf5Datatype = hdf5String;
+ if (len > 1)
+ {
+ len--; /* cut trailing '\0' */
+ }
+ H5Tset_size (hdf5Datatype, len);
+ attrDataspace = H5Screate (H5S_SCALAR);
+ break;
+
+ case FLOAT64:
+ hdf5Datatype = H5T_NATIVE_DOUBLE;
+ hdf5Dims [0] = len;
+ attrDataspace = H5Screate_simple (1, hdf5Dims, NULL);
+ break;
+
+ case INT32:
+ hdf5Datatype = H5T_NATIVE_INT;
+ hdf5Dims [0] = len;
+ attrDataspace = H5Screate_simple (1, hdf5Dims, NULL);
+ break;
+
+ default:
+ fprintf (stderr, "Unknown datatype %d for attribute %s, skipping "
+ "...\n", attrNumberType, attrName);
+ continue;
+ }
+
+ assert (attrDataspace >= 0);
+
+ /* turn off error handling during check
+ for an already existing attribute */
+ H5Eget_auto (&old_func, &old_client_data);
+ H5Eset_auto (NULL, NULL);
+ H5Adelete (dataset, attrName);
+ H5Eset_auto (old_func, old_client_data);
+
+ attribute = H5Acreate (dataset, attrName, hdf5Datatype,
+ attrDataspace, H5P_DEFAULT);
+ assert (attribute >= 0);
+ assert (H5Awrite (attribute, hdf5Datatype, attrData) >= 0);
+ H5Sclose (attrDataspace);
+ H5Aclose (attribute);
+
+ free (attrData);
+ }
+
+ H5Dclose (dataset);
+ H5Sclose (dataspace);
+ free (data);
+ }
+
+ H5Tclose (hdf5String);
+ H5Fclose (outfile);
+ IOclose (infile);
+
+ return (0);
+}