diff options
author | tradke <tradke@ebee0441-1374-4afa-a3b5-247f3ba15b9a> | 2002-07-01 13:07:34 +0000 |
---|---|---|
committer | tradke <tradke@ebee0441-1374-4afa-a3b5-247f3ba15b9a> | 2002-07-01 13:07:34 +0000 |
commit | b79f7981747153ba462782fb548868c0814fe9d9 (patch) | |
tree | 809ad5a99aa5134f20ba2919bc0f7c92eb2ded65 | |
parent | b324a78e90cb0353f88a9dcde47d2e5ca27294f0 (diff) |
Extended the routine registered as IOFlexIO's filereader to select variables
with a specific iteration number (see IOUtil's thorn documentation for an example).
You must also update thorn IOUtil now.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOFlexIO/trunk@260 ebee0441-1374-4afa-a3b5-247f3ba15b9a
-rw-r--r-- | src/RestoreFile.c | 111 |
1 files changed, 80 insertions, 31 deletions
diff --git a/src/RestoreFile.c b/src/RestoreFile.c index a3f2213..4027c87 100644 --- a/src/RestoreFile.c +++ b/src/RestoreFile.c @@ -13,6 +13,8 @@ #include "cctk.h" #include "cctk_Parameters.h" +#include "util_String.h" + #include "CactusPUGH/PUGH/src/include/pugh.h" #include "CactusBase/IOUtil/src/ioGH.h" #include "ioFlexGH.h" @@ -37,7 +39,8 @@ CCTK_FILEVERSION(CactusPUGHIO_IOFlexIO_RestoreFile_c) ******************** Internal Routines ************************ ********************************************************************/ static int GetCommonAttributes (cGH *GH, IOFile fid, int unchunked, int *vindex, - int *grouptype, int *timelevel,int has_version); + int *grouptype, int *timelevel, int *iteration, + int has_version); #ifdef CCTK_MPI static int GetChunkAttributes (IOFile fid, int vindex); #endif @@ -84,7 +87,7 @@ int IOFlexIOi_RecoverVariables (cGH *GH, fileinfo_t *file); @@*/ int IOFlexIOi_RecoverVariables (cGH *GH, fileinfo_t *file) { - int vindex, gtype, timelevel, myproc, nprocs; + int vindex, gtype, timelevel, iteration, myproc, nprocs; int nDatasets, currentDataset; const pGH *pughGH; const ioGH *ioUtilGH; @@ -154,8 +157,8 @@ int IOFlexIOi_RecoverVariables (cGH *GH, fileinfo_t *file) for (currentDataset = 0; currentDataset < nDatasets; currentDataset++) { /* read in the next dataset's attributes and verify them */ - if (GetCommonAttributes (GH, file->fid, file->unchunked, &vindex, - >ype, &timelevel, file->has_version) < 0) + if (GetCommonAttributes (GH, file->fid, file->unchunked, &vindex, >ype, + &timelevel, &iteration, file->has_version) < 0) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Ignoring dataset %d", currentDataset); @@ -164,14 +167,13 @@ int IOFlexIOi_RecoverVariables (cGH *GH, fileinfo_t *file) /* if we read in initial data via the file reader interface check whether the user wants to have this variable restored */ - if (ioUtilGH->do_inVars && ! ioUtilGH->do_inVars[vindex]) + if (ioUtilGH->do_inVars && ioUtilGH->do_inVars[vindex] >= 0 && + ioUtilGH->do_inVars[vindex] != iteration + 1) { if (CCTK_Equals (verbose, "full")) { - fullname = CCTK_FullName (vindex); - CCTK_VInfo (CCTK_THORNSTRING, "Ignoring variable '%s' for file " - "reader recovery", fullname); - free (fullname); + CCTK_VInfo (CCTK_THORNSTRING, "Ignoring dataset %d for file reader " + "recovery", currentDataset); } continue; } @@ -371,6 +373,7 @@ int IOFlexIOi_RecoverVariables (cGH *GH, fileinfo_t *file) - group type - variable type - ntimelevels + - iteration number - sizes (rank, dimensions) according to chunking mode If there is a mismatch a warning (warning level 2) is printed and value of -1 @@ -380,15 +383,18 @@ int IOFlexIOi_RecoverVariables (cGH *GH, fileinfo_t *file) */ static int GetCommonAttributes (cGH *GH, IOFile fid, int unchunked, int *vindex, - int *grouptype, int *timelevel, int has_version) + int *grouptype, int *timelevel, int *iteration, + int has_version) { - int i, flag, atype, vartype_stored, rank_stored, result; + int i, flag, atype, vartype_stored, rank_stored, groupindex, result; Long asize; - pGExtras *extras; - cGroup groupdata; - CCTK_INT4 grouptype_stored, numtimelevels_stored, timelevel_stored; - int *dims, dims_stored[MAXDIM]; - char *groupname; + cGroup group_static_data; + cGroupDynamicData group_dynamic_data; + CCTK_INT4 grouptype_stored, numtimelevels_stored, timelevel_stored, + iteration_stored; + char *groupname, *msg; + const int *dims; + int dims_stored[MAXDIM]; char fullname[512], groupname_stored[512]; @@ -448,6 +454,17 @@ static int GetCommonAttributes (cGH *GH, IOFile fid, int unchunked, int *vindex, } FLEXIO_ERROR (IOreadAttribute (fid, i, &grouptype_stored)); + /* read the iteration number */ + i = IOreadAttributeInfo (fid, "iteration", &atype, &asize); + if (i < 0 || atype != FLEXIO_INT4 || asize != 1) + { + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "Can't read iteration attribute for '%s'", fullname); + return (-1); + } + FLEXIO_ERROR (IOreadAttribute (fid, i, &iteration_stored)); + *iteration = iteration_stored; + /* read the number of timelevels */ i = IOreadAttributeInfo (fid, "ntimelevels", &atype, &asize); if (i < 0 || atype != FLEXIO_INT4 || asize != 1) @@ -470,19 +487,20 @@ static int GetCommonAttributes (cGH *GH, IOFile fid, int unchunked, int *vindex, *timelevel = (int) timelevel_stored; /* verify group type, variable type, dims, sizes and ntimelevels */ - if (CCTK_GroupData (CCTK_GroupIndex (groupname_stored), &groupdata) != 0) + groupindex = CCTK_GroupIndex (groupname_stored); + if (CCTK_GroupData (groupindex, &group_static_data) != 0) { CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, "Could not get group info for '%s'", fullname); return (-1); } - if (groupdata.grouptype != grouptype_stored) + if (group_static_data.grouptype != grouptype_stored) { CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, "Group types don't match for '%s'", fullname); return (-1); } - if (groupdata.numtimelevels != numtimelevels_stored) + if (group_static_data.numtimelevels != numtimelevels_stored) { CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, "Number of timelevels don't match for '%s'", fullname); @@ -496,15 +514,15 @@ static int GetCommonAttributes (cGH *GH, IOFile fid, int unchunked, int *vindex, /* The CCTK variable type defines do not correlate with the IEEEIO defines so compare them explicitely here. */ if ((vartype_stored == FLEXIO_REAL && - groupdata.vartype == CCTK_VARIABLE_REAL) || + group_static_data.vartype == CCTK_VARIABLE_REAL) || (vartype_stored == FLEXIO_INT && - groupdata.vartype == CCTK_VARIABLE_INT) || + group_static_data.vartype == CCTK_VARIABLE_INT) || (vartype_stored == FLEXIO_CHAR && - groupdata.vartype == CCTK_VARIABLE_CHAR) || + group_static_data.vartype == CCTK_VARIABLE_CHAR) || #if 0 /* FIXME: Don't know how to support COMPLEX type too !! */ (vartype_stored == FLEXIO_REAL && - groupdata.vartype == CCTK_VARIABLE_COMPLEX)) + group_static_data.vartype == CCTK_VARIABLE_COMPLEX)) #else 0) { @@ -519,24 +537,55 @@ static int GetCommonAttributes (cGH *GH, IOFile fid, int unchunked, int *vindex, } /* verify the dims and sizes */ - flag = groupdata.dim != rank_stored; - if (groupdata.grouptype == CCTK_SCALAR) + flag = group_static_data.dim != rank_stored; + if (group_static_data.grouptype == CCTK_SCALAR) { flag |= dims_stored[0] != 1; } else { - extras = ((pGA ***) PUGH_pGH (GH)->variables)[*vindex][*timelevel]->extras; - dims = unchunked ? extras->nsize : extras->lnsize; - for (i = 0; i < groupdata.dim; i++) + if (CCTK_GroupDynamicData (GH, groupindex, &group_dynamic_data) != 0) + { + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "Cannot get dynamic group data for '%s'", fullname); + return (-1); + } + + dims = unchunked ? group_dynamic_data.gsh : group_dynamic_data.lsh; + for (i = 0; i < group_static_data.dim; i++) { flag |= dims[i] != dims_stored[i]; } } if (flag) { - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Variable sizes don't match for '%s'", fullname); + if (group_static_data.dim != rank_stored) + { + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "Variable dimensions don't match for '%s', got %d, expected " + "%d", fullname, rank_stored, group_static_data.dim); + } + else + { + msg = NULL; + Util_asprintf (&msg, "Variable sizes don't match for '%s', got (%d", + fullname, dims_stored[0]); + for (i = 1; i < group_static_data.dim; i++) + { + Util_asprintf (&msg, "%s, %d", msg, dims_stored[i]); + } + dims = unchunked ? group_dynamic_data.gsh : group_dynamic_data.lsh; + Util_asprintf (&msg, "%s), expected (%d", msg, + dims[group_static_data.dim - 1]); + for (i = 1; i < group_static_data.dim; i++) + { + Util_asprintf (&msg, "%s, %d", msg, dims[group_static_data.dim-i-1]); + } + Util_asprintf (&msg, "%s)", msg); + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, msg); + free (msg); + } + return (-1); } @@ -547,7 +596,7 @@ static int GetCommonAttributes (cGH *GH, IOFile fid, int unchunked, int *vindex, return (-1); } - *grouptype = groupdata.grouptype; + *grouptype = group_static_data.grouptype; return (0); } |