From 9bfe99ac487e42ed154a1860bd24b3869bfda2d2 Mon Sep 17 00:00:00 2001 From: tradke Date: Wed, 18 Sep 2002 15:37:39 +0000 Subject: When called by the filereader API, check whether to read in a dataset by name even before opening a dataset and verifying its attributes. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOHDF5Util/trunk@79 7842ec3a-9562-4be5-9c5b-06ba18f2b668 --- src/RecoverVar.c | 187 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 96 insertions(+), 91 deletions(-) (limited to 'src') diff --git a/src/RecoverVar.c b/src/RecoverVar.c index 5771ca5..980d653 100644 --- a/src/RecoverVar.c +++ b/src/RecoverVar.c @@ -333,28 +333,25 @@ int IOHDF5Util_RecoverParameters (const fileinfo_t *fileinfo) /* local routine GetCommonAttributes() reads in the next dataset's attributes and verifies them: - * checks if there is a variable with the name given by the name attribute - * verifies that this variable still belongs to the same group + * checks if variable belongs to the same group * checks the group data info: - group type - variable type - ntimelevels - - iteration - sizes (rank, dimensions) according to chunking mode If there is a mismatch a warning (warning level 2) is printed and a negative value is returned to indicate that this dataset should be ignored. - If successful, the global variable index, the group type and the timelevel - to restore are stored in {*vindex, *gtype, *timelevel}, and 0 is returned. + If successful, the group type and the possibly corrected timelevel + to restore are stored in {*gtype, *timelevel}, and 0 is returned. */ static int GetCommonAttributes (cGH *GH, hid_t dataset, - const char *datasetname, + int vindex, + const char *fullname, int unchunked, - int *vindex, int *grouptype, int *timelevel, - int *iteration, int is_group, int has_version) { @@ -367,30 +364,12 @@ static int GetCommonAttributes (cGH *GH, hsize_t rank_stored, *dims_stored; int grouptype_stored, numtimelevels_stored; char *groupname, *msg; - char groupname_stored[128], fullvarname[128]; + char groupname_stored[128]; - /* decompose the datasetname, ignore the iteration number */ - if (sscanf (datasetname, "%[^ ] timelevel %d at iteration %d", - fullvarname, timelevel, iteration) != 3) - { - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Cannot parse datasetname '%s'", datasetname); - return (-1); - } - - /* check if there is a matching variable */ - *vindex = CCTK_VarIndex (fullvarname); - if (*vindex < 0) - { - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "No matching variable found for '%s'", fullvarname); - return (-1); - } - /* read and verify the group name */ READ_ATTRIBUTE (dataset, "groupname", H5T_C_S1, groupname_stored); - groupname = CCTK_GroupNameFromVarI (*vindex); + groupname = CCTK_GroupNameFromVarI (vindex); if (! CCTK_Equals (groupname_stored, groupname)) { CCTK_WARN (2, "Groupnames don't match"); @@ -407,7 +386,7 @@ static int GetCommonAttributes (cGH *GH, if (CCTK_GroupData (groupindex, &group_static_data) != 0) { CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Cannot get static group data for '%s'", fullvarname); + "Cannot get static group data for '%s'", fullname); return (-1); } @@ -415,13 +394,13 @@ static int GetCommonAttributes (cGH *GH, if (group_static_data.grouptype != grouptype_stored) { CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Group types don't match for '%s'", fullvarname); + "Group types don't match for '%s'", fullname); return (-1); } if (group_static_data.numtimelevels != numtimelevels_stored) { CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Number of timelevels don't match for '%s'", fullvarname); + "Number of timelevels don't match for '%s'", fullname); return (-1); } /* increment the timelevel for data from old checkpoint files */ @@ -455,7 +434,7 @@ static int GetCommonAttributes (cGH *GH, if (! flag) { CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Variable types don't match for '%s'", fullvarname); + "Variable types don't match for '%s'", fullname); return (-1); } @@ -482,7 +461,7 @@ static int GetCommonAttributes (cGH *GH, if (CCTK_GroupDynamicData (GH, groupindex, &group_dynamic_data) != 0) { CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Cannot get dynamic group data for '%s'", fullvarname); + "Cannot get dynamic group data for '%s'", fullname); return (-1); } dims = unchunked ? group_dynamic_data.gsh : group_dynamic_data.lsh; @@ -501,13 +480,13 @@ static int GetCommonAttributes (cGH *GH, { CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, "Variable dimensions don't match for '%s', got %d, expected " - "%d", fullvarname, (int) rank_stored, group_static_data.dim); + "%d", fullname, (int) rank_stored, group_static_data.dim); } else { msg = NULL; Util_asprintf (&msg, "Variable sizes don't match for '%s', got (%d", - fullvarname, (int) dims_stored[0]); + fullname, (int) dims_stored[0]); for (i = 1; i < group_static_data.dim; i++) { Util_asprintf (&msg, "%s, %d", msg, (int) dims_stored[i]); @@ -533,7 +512,7 @@ static int GetCommonAttributes (cGH *GH, if (! CCTK_QueryGroupStorageI (GH, groupindex)) { CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Can't read into variable '%s': no storage", fullvarname); + "Can't read into variable '%s': no storage", fullname); return (-1); } @@ -739,6 +718,51 @@ static herr_t processDataset (hid_t group, const char *datasetname, void *arg) retval = 0; + /* decompose the datasetname, ignore the iteration number */ + fullname = malloc (strlen (datasetname)); + if (sscanf (datasetname, "%[^ ] timelevel %d at iteration %d", + fullname, &timelevel, &iteration) != 3) + { + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "Cannot parse datasetname '%s'", datasetname); + retval = -1; + } + + /* check if there is a matching variable */ + vindex = CCTK_VarIndex (fullname); + if (vindex < 0) + { + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "No matching variable found for '%s'", fullname); + retval = -1; + } + + if (retval < 0) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Ignoring dataset '%s'", datasetname); + free (fullname); + return (0); + } + + ioUtilGH = (ioGH *) CCTK_GHExtension (it_info->GH, "IO"); + myGH = (ioHDF5UtilGH *) CCTK_GHExtension (it_info->GH, "IOHDF5Util"); + + /* if we read in initial data via the file reader interface + check whether the user wants to have this variable with a specific + iteration number restored */ + if (ioUtilGH->do_inVars && ioUtilGH->do_inVars[vindex] >= 0 && + ioUtilGH->do_inVars[vindex] != iteration + 1) + { + if (CCTK_Equals (verbose, "full")) + { + CCTK_VInfo (CCTK_THORNSTRING, "Ignoring dataset '%s' for file reader " + "recovery", datasetname); + } + free (fullname); + return (0); + } + HDF5_ERROR (H5Gget_objinfo (group, datasetname, 0, &object_info)); is_group = object_info.type == H5G_GROUP; if (is_group) @@ -751,78 +775,57 @@ static herr_t processDataset (hid_t group, const char *datasetname, void *arg) } /* read in the dataset's attributes and verify them */ - if (GetCommonAttributes (it_info->GH, dataset, datasetname, - it_info->unchunked, &vindex, >ype, &timelevel, - &iteration, is_group, it_info->has_version) < 0) + if (GetCommonAttributes (it_info->GH, dataset, vindex, fullname, + it_info->unchunked, >ype, &timelevel, + is_group, it_info->has_version) < 0) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Ignoring dataset '%s'", datasetname); } else { - ioUtilGH = (ioGH *) CCTK_GHExtension (it_info->GH, "IO"); - myGH = (ioHDF5UtilGH *) CCTK_GHExtension (it_info->GH, "IOHDF5Util"); - - /* if we read in initial data via the file reader interface - check whether the user wants to have this variable with a specific - iteration number restored */ - if (ioUtilGH->do_inVars && ioUtilGH->do_inVars[vindex] >= 0 && - ioUtilGH->do_inVars[vindex] != iteration + 1) + if (CCTK_Equals (verbose, "full") || + (ioUtilGH->do_inVars && ! CCTK_Equals (verbose, "none"))) { - if (CCTK_Equals (verbose, "full")) - { - CCTK_VInfo (CCTK_THORNSTRING, "Ignoring dataset '%s' for file reader " - "recovery", datasetname); - } + CCTK_VInfo (CCTK_THORNSTRING, "Restoring variable '%s' (timelevel %d, " + "cctk_iteration %d)", fullname, timelevel, iteration); } - else - { - if (CCTK_Equals (verbose, "full") || - (ioUtilGH->do_inVars && ! CCTK_Equals (verbose, "none"))) - { - fullname = CCTK_FullName (vindex); - CCTK_VInfo (CCTK_THORNSTRING, "Restoring variable '%s' (timelevel %d, " - "cctk_iteration %d)", fullname, timelevel, iteration); - free (fullname); - } - vtype = CCTK_VarTypeI (vindex); - rec_info.it_info = it_info; - rec_info.element_size = CCTK_VarTypeSize (vtype); + vtype = CCTK_VarTypeI (vindex); + rec_info.it_info = it_info; + rec_info.element_size = CCTK_VarTypeSize (vtype); #ifdef CCTK_MPI - rec_info.mpi_type = PUGH_MPIDataType (PUGH_pGH (it_info->GH), vtype); + rec_info.mpi_type = PUGH_MPIDataType (PUGH_pGH (it_info->GH), vtype); #endif - rec_info.hdf5type = IOHDF5Util_DataType (myGH, vtype); - if (rec_info.element_size <= 0 || + rec_info.hdf5type = IOHDF5Util_DataType (myGH, vtype); + if (rec_info.element_size <= 0 || #ifdef CCTK_MPI - rec_info.mpi_type == MPI_DATATYPE_NULL || + rec_info.mpi_type == MPI_DATATYPE_NULL || #endif - rec_info.hdf5type < 0) - { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Unsupported variable datatype %d", vtype); - } - else if (gtype != CCTK_SCALAR && gtype != CCTK_GF && gtype != CCTK_ARRAY) + rec_info.hdf5type < 0) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Unsupported variable datatype %d", vtype); + } + else if (gtype != CCTK_SCALAR && gtype != CCTK_GF && gtype != CCTK_ARRAY) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Unsupported group type %d", gtype); + } + else + { + /* Read in the data */ + if (gtype == CCTK_SCALAR) { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Unsupported group type %d", gtype); + IOHDF5Util_RestoreGS (dataset, vindex, timelevel, &rec_info); } else { - /* Read in the data */ - if (gtype == CCTK_SCALAR) - { - IOHDF5Util_RestoreGS (dataset, vindex, timelevel, &rec_info); - } - else - { - IOHDF5Util_RestoreGA (dataset, vindex, timelevel, &rec_info); - } - - /* increment counter for total number of recovered variables */ - it_info->num_recovered++; + IOHDF5Util_RestoreGA (dataset, vindex, timelevel, &rec_info); } - retval = 1; + + /* increment counter for total number of recovered variables */ + it_info->num_recovered++; } } @@ -835,5 +838,7 @@ static herr_t processDataset (hid_t group, const char *datasetname, void *arg) HDF5_ERROR (H5Dclose (dataset)); } - return (retval); + free (fullname); + + return (0); } -- cgit v1.2.3