From e338c10e1838825912151462eb099b665b3c1c60 Mon Sep 17 00:00:00 2001 From: tradke Date: Tue, 8 Jun 2004 16:34:03 +0000 Subject: Add a GLOBAL_ATTRIBUTES_GROUP to mark the output as a Cactus HDF5 file. Give the HDF5 datasets proper names (following the IOHDF5 naming conventions). This closes PR CactusPUGHIO/1756: "ieee->hdf5 converter problem for 2D files". git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOHDF5/trunk@193 4825ed28-b72c-4eae-9704-e50c059e567d --- src/util/hdf5_convert_from_ieeeio.c | 63 ++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/src/util/hdf5_convert_from_ieeeio.c b/src/util/hdf5_convert_from_ieeeio.c index f712c38..d829288 100644 --- a/src/util/hdf5_convert_from_ieeeio.c +++ b/src/util/hdf5_convert_from_ieeeio.c @@ -26,6 +26,8 @@ /* HDF5 include */ #include +#define GLOBAL_ATTRIBUTES_GROUP "Global Attributes" + /* the rcs ID and its dummy function to use it */ static const char *rcsid = "$Header$"; CCTK_FILEVERSION(CactusPUGHIO_IOHDF5_util_hdf5_convert_from_ieeeio_c) @@ -36,37 +38,67 @@ int main (int argc, char **argv) int i, j; IOFile infile; int nDatasets, nAttributes; - int ieeeDatatype, rank, dims [MAXDIM]; + int ieeeDatatype, rank, dims[MAXDIM]; int attrNumberType; Long attrLen; - char attrName [MAXNAMESIZE]; + char attrName[MAXNAMESIZE]; void *data, *attrData; hid_t outfile, dataset, dataspace, attribute, attrDataspace, hdf5Datatype; - hid_t hdf5String; - hsize_t hdf5Dims [MAXDIM]; + hid_t group, hdf5String; + hsize_t hdf5Dims[MAXDIM]; int iteration, timelevel; - char ieeeDatasetName [MAXNAMESIZE], hdf5DatasetName [2 * MAXNAMESIZE]; + char ieeeDatasetName[MAXNAMESIZE], hdf5DatasetName[2 * MAXNAMESIZE]; if (argc <= 2) { - printf ("Usage: %s \n", argv [0]); - printf (" eg. %s foo.ieee bar.hdf5\n", argv [0]); + printf ("Usage: %s \n", argv[0]); + printf (" eg. %s foo.ieee bar.h5\n", argv[0]); return (0); } - infile = IEEEopen (argv [1], "r"); + infile = IEEEopen (argv[1], "r"); if (! IOisValid (infile)) { - printf ("Could not open input file '%s'\n", argv [1]); + printf ("Could not open input file '%s'\n", argv[1]); return (-1); } - outfile = H5Fcreate (argv [2], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + 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]); + fprintf (stderr, "Could not create output file '%s'\n", argv[2]); return (-1); } + /* add a dummy GLOBAL_ATTRIBUTES_GROUP so that the HDF5 file is recognized as + unchunked Cactus data */ + group = H5Gcreate (outfile, GLOBAL_ATTRIBUTES_GROUP, 0); + assert (group >= 0); + attrDataspace = H5Screate (H5S_SCALAR); + + attribute = H5Acreate (group, "nprocs", H5T_NATIVE_INT, attrDataspace, + H5P_DEFAULT); + assert (attribute >= 0); + i = 1; + assert (H5Awrite (attribute, H5T_NATIVE_INT, &i) >= 0); + H5Aclose (attribute); + + attribute = H5Acreate (group, "ioproc_every", H5T_NATIVE_INT, attrDataspace, + H5P_DEFAULT); + assert (attribute >= 0); + i = 1; + assert (H5Awrite (attribute, H5T_NATIVE_INT, &i) >= 0); + H5Aclose (attribute); + + attribute = H5Acreate (group, "unchunked", H5T_NATIVE_INT, attrDataspace, + H5P_DEFAULT); + assert (attribute >= 0); + i = 1; + assert (H5Awrite (attribute, H5T_NATIVE_INT, &i) >= 0); + H5Aclose (attribute); + + H5Sclose (attrDataspace); + H5Gclose (group); + hdf5String = H5Tcopy (H5T_C_S1); nDatasets = IOnDatasets (infile); @@ -149,12 +181,13 @@ int main (int argc, char **argv) /* convert ordering (FlexIO uses fortran order, HDF5 uses C order) */ for (j = 0; j < rank; j++) { - hdf5Dims [j] = dims [rank - j - 1]; + hdf5Dims[j] = dims[rank - j - 1]; } dataspace = H5Screate_simple (rank, hdf5Dims, NULL); assert (dataspace >= 0); - sprintf (hdf5DatasetName, "/%s@%d@%d", ieeeDatasetName, iteration, timelevel); + sprintf (hdf5DatasetName, "/%s timelevel %d at iteration %d", + ieeeDatasetName, timelevel, iteration); dataset = H5Dcreate (outfile, hdf5DatasetName, hdf5Datatype, dataspace, H5P_DEFAULT); assert (dataset >= 0); @@ -213,13 +246,13 @@ int main (int argc, char **argv) case FLOAT64: hdf5Datatype = H5T_NATIVE_DOUBLE; - hdf5Dims [0] = len; + hdf5Dims[0] = len; attrDataspace = H5Screate_simple (1, hdf5Dims, NULL); break; case INT32: hdf5Datatype = H5T_NATIVE_INT; - hdf5Dims [0] = len; + hdf5Dims[0] = len; attrDataspace = H5Screate_simple (1, hdf5Dims, NULL); break; -- cgit v1.2.3