aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@4825ed28-b72c-4eae-9704-e50c059e567d>2004-09-15 17:35:30 +0000
committertradke <tradke@4825ed28-b72c-4eae-9704-e50c059e567d>2004-09-15 17:35:30 +0000
commita6dacaf84e924dbdcf49c3919fb631578fcc1206 (patch)
tree7f42805c59ce3bd27a3a9b7d5ebafafdf8aaefea
parent6cec8fb74e4c073ba09d3e03b18326ec807d10e0 (diff)
Get the missing metadata information from command line parameters.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOHDF5/trunk@207 4825ed28-b72c-4eae-9704-e50c059e567d
-rw-r--r--src/util/hdf5_convert_from_sdf.c75
1 files changed, 53 insertions, 22 deletions
diff --git a/src/util/hdf5_convert_from_sdf.c b/src/util/hdf5_convert_from_sdf.c
index ef0ca79..dcd5da5 100644
--- a/src/util/hdf5_convert_from_sdf.c
+++ b/src/util/hdf5_convert_from_sdf.c
@@ -84,37 +84,47 @@ CCTK_FILEVERSION(CactusPUGHIO_IOHDF5_util_hdf5_convert_from_sdf_c)
int main (int argc, char **argv)
{
int i, j;
- int version, rank, dsize, csize, grouptype;
+ int version, rank, dsize, csize;
+ const int grouptype = CCTK_GF;
int *dims;
double timestep;
- char *varname, *groupname, *coordname, *tag;
+ char *varname, *coordname, *tag;
+ const char *groupname;
gft_sdf_file_data *infile;
- double *coords, *data, *bbox;
+ double *coords, *data, *bbox, *origin, *delta;
hid_t outfile, dataset, dataspace, attr, attrDataspace;
hid_t group, hdf5String;
hsize_t hdf5Dims[MAXDIM];
int iteration, timelevel, ntimelevels;
char hdf5DatasetName[2 * MAXNAMESIZE];
+ const char *cactus_version = "Cactus Beta14";
- if (argc <= 2)
+ if (argc != 7)
{
- fprintf (stderr, "Usage: %s <inputfile> <outputfile>\n", argv[0]);
- fprintf (stderr, " eg. %s foo.sdf bar.h5\n", argv[0]);
+ fprintf (stderr, "Usage: %s <groupname> <iteration> <timelevel> "
+ "<ntimelevels> <inputfile> <outputfile>\n", argv[0]);
+ fprintf (stderr, " eg. %s ADMBase::metric 0 0 3 foobar.sdf gxx.h5\n",
+ argv[0]);
return (0);
}
- infile = gft_open_sdf_file (argv[1]);
+ groupname = argv[1];
+ iteration = atoi (argv[2]);
+ timelevel = atoi (argv[3]);
+ ntimelevels = atoi (argv[4]);
+
+ infile = gft_open_sdf_file (argv[5]);
if (! infile)
{
- printf ("Could not open SDF input file '%s'\n", argv[1]);
+ printf ("Could not open SDF input file '%s'\n", argv[5]);
return (-1);
}
- outfile = H5Fcreate (argv[2], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ outfile = H5Fcreate (argv[6], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
if (outfile < 0)
{
- fprintf (stderr, "Could not create HDF5 output file '%s'\n", argv[2]);
+ fprintf (stderr, "Could not create HDF5 output file '%s'\n", argv[6]);
return (-1);
}
@@ -122,6 +132,8 @@ int main (int argc, char **argv)
" Cactus SDF-to-HDF5 Converter\n"
" ----------------------------\n");
+ CHECK_ERROR (hdf5String = H5Tcopy (H5T_C_S1));
+
/* add a dummy GLOBAL_ATTRIBUTES_GROUP so that the HDF5 file is recognized as
unchunked Cactus data */
CHECK_ERROR (group = H5Gcreate (outfile, GLOBAL_ATTRIBUTES_GROUP, 0));
@@ -145,23 +157,18 @@ int main (int argc, char **argv)
CHECK_ERROR (H5Awrite (attr, H5T_NATIVE_INT, &i));
CHECK_ERROR (H5Aclose (attr));
- CHECK_ERROR (H5Gclose (group));
-
- CHECK_ERROR (hdf5String = H5Tcopy (H5T_C_S1));
+ CHECK_ERROR (H5Tset_size (hdf5String, strlen (cactus_version)));
+ CHECK_ERROR (attr = H5Acreate (group, "Cactus version", hdf5String,
+ attrDataspace, H5P_DEFAULT));
+ CHECK_ERROR (H5Awrite (attr, hdf5String, cactus_version));
+ CHECK_ERROR (H5Aclose (attr));
- /*** FIXME: get iteration number and timelevel information from user ***/
- iteration = timelevel = 0;
- ntimelevels = 1;
- grouptype = CCTK_GF;
- groupname = "grid::coordinates";
+ CHECK_ERROR (H5Gclose (group));
while (low_read_sdf_stream (1, infile->fp, &timestep, &version, &rank, &dsize,
&csize, &varname, &coordname, &tag, &dims, &bbox,
&coords, &data))
{
- /*** FIXME: give the dataset a valid variable name ***/
- varname = strdup ("grid::x");
-
printf ("Processing dataset '%s' (timestep %f)\n", varname, timestep);
/* convert from int to hsize_t */
@@ -177,6 +184,7 @@ int main (int argc, char **argv)
H5T_NATIVE_DOUBLE,dataspace,H5P_DEFAULT));
CHECK_ERROR (H5Dwrite (dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL,
H5P_DEFAULT, data));
+ CHECK_ERROR (H5Sclose (dataspace));
/* attach necessary attributes */
CHECK_ERROR (H5Tset_size (hdf5String, strlen (groupname)));
@@ -195,9 +203,31 @@ int main (int argc, char **argv)
CHECK_ERROR (H5Awrite (attr, H5T_NATIVE_INT, &ntimelevels));
CHECK_ERROR (H5Aclose (attr));
- CHECK_ERROR (H5Dclose (dataset));
+ CHECK_ERROR (attr = H5Acreate (dataset, "time", H5T_NATIVE_DOUBLE,
+ attrDataspace, H5P_DEFAULT));
+ CHECK_ERROR (H5Awrite (attr, H5T_NATIVE_DOUBLE, &timestep));
+ CHECK_ERROR (H5Aclose (attr));
+ /* set origin/delta from bbox information */
+ origin = malloc (2*rank * sizeof (double));
+ delta = origin + rank;
+ for (j = 0; j < rank; j++)
+ {
+ origin[j] = bbox[2*j+0];
+ delta[j] = (bbox[2*j+1] - bbox[2*j+0]) / (dims[j] - 1);
+ }
+ hdf5Dims[0] = rank;
+ CHECK_ERROR (dataspace = H5Screate_simple (1, hdf5Dims, NULL));
+ CHECK_ERROR (attr = H5Acreate (dataset, "origin", H5T_NATIVE_DOUBLE,
+ dataspace, H5P_DEFAULT));
+ CHECK_ERROR (H5Awrite (attr, H5T_NATIVE_DOUBLE, origin));
+ CHECK_ERROR (H5Aclose (attr));
+ CHECK_ERROR (attr = H5Acreate (dataset, "delta", H5T_NATIVE_DOUBLE,
+ dataspace, H5P_DEFAULT));
+ CHECK_ERROR (H5Awrite (attr, H5T_NATIVE_DOUBLE, delta));
+ CHECK_ERROR (H5Aclose (attr));
CHECK_ERROR (H5Sclose (dataspace));
+ CHECK_ERROR (H5Dclose (dataset));
free (varname);
free (coordname);
@@ -206,6 +236,7 @@ int main (int argc, char **argv)
free (bbox);
free (coords);
free (data);
+ free (origin);
/*** FIXME: increment iteration number to distinguish datasets ***/
iteration++;