diff options
Diffstat (limited to 'src/CheckpointRecovery.c')
-rw-r--r-- | src/CheckpointRecovery.c | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/src/CheckpointRecovery.c b/src/CheckpointRecovery.c index 9b18728..9345da5 100644 --- a/src/CheckpointRecovery.c +++ b/src/CheckpointRecovery.c @@ -13,6 +13,7 @@ #include "cctk_Parameters.h" #include "cctk_FortranString.h" #include "StoreHandledData.h" +#include "util_Table.h" #include "ioGH.h" #include "ioutil_CheckpointRecovery.h" @@ -371,13 +372,14 @@ void IOUtil_RecoverGH (cGH *GH) @returntype int @returndesc - 0 for success + total number of recovered variables @endreturndesc @@*/ int IOUtil_RecoverVarsFromDatafiles (cGH *GH, const char *in_files, const char *in_vars) { + int retval, num_recovered_vars; ioGH *myGH; char *basefilename, *delim, delim_char; DECLARE_CCTK_PARAMETERS @@ -387,7 +389,7 @@ int IOUtil_RecoverVarsFromDatafiles (cGH *GH, if (CCTK_NumVars () > 0) { - myGH->do_inVars = (char *) calloc (CCTK_NumVars (), sizeof (char)); + myGH->do_inVars = (CCTK_INT *) calloc (CCTK_NumVars (), sizeof (CCTK_INT)); CCTK_TraverseString (in_vars, SetInputFlag, myGH->do_inVars, CCTK_GROUP_OR_VAR); } @@ -396,6 +398,8 @@ int IOUtil_RecoverVarsFromDatafiles (cGH *GH, myGH->do_inVars = NULL; } + num_recovered_vars = 0; + /* duplicate the filename list and parse it */ basefilename = strdup (in_files); while (basefilename) @@ -421,7 +425,12 @@ int IOUtil_RecoverVarsFromDatafiles (cGH *GH, basefilename); } - if (IOUtil_RecoverFromFile (GH, basefilename, FILEREADER_DATA) < 0) + retval = IOUtil_RecoverFromFile (GH, basefilename, FILEREADER_DATA); + if (retval >= 0) + { + num_recovered_vars += retval; + } + else { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Failed to read variables from data file '%s'", basefilename); @@ -442,7 +451,7 @@ int IOUtil_RecoverVarsFromDatafiles (cGH *GH, myGH->do_inVars = NULL; } - return (0); + return (num_recovered_vars); } void CCTK_FCALL CCTK_FNAME (IOUtil_RecoverVarsFromDatafiles) @@ -897,13 +906,65 @@ void IOUtil_SetAllParameters (const char *parameters) for the given variable */ static void SetInputFlag (int vindex, const char *optstring, void *flags) { - ((char *) flags)[vindex] = 1; + int table, iterator; + char key[128]; + CCTK_INT type, nelems; + CCTK_INT *do_inVars = (CCTK_INT *) flags; + + + /* default -1 is to read the last iteration number from the file */ + do_inVars[vindex] = -1; if (optstring) { - CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING, - "SetInputFlag: Optional string '%s' in variable name ignored", - optstring); + table = Util_TableCreateFromString (optstring); + if (table >= 0) + { + if (Util_TableQueryValueInfo (table, &type, &nelems, "cctk_iteration") >0) + { + if (type == CCTK_VARIABLE_INT && nelems == 1) + { + Util_TableGetInt (table, &do_inVars[vindex], "cctk_iteration"); + + /* if a specific iteration number was given then increment it + to keep 0 as disabling value */ + if (do_inVars[vindex] >= 0) + { + do_inVars[vindex]++; + } + } + else + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid value for option 'cctk_iteration' in option " + "string '%s' (must be an integer)", optstring); + CCTK_WARN (1, "Option will be ignored by file reader routines"); + } + Util_TableDeleteKey (table, "cctk_iteration"); + } + + /* warn about other options */ + iterator = Util_TableItCreate (table); + for (iterator = Util_TableItCreate (table); + Util_TableItQueryIsNonNull (iterator) > 0 && + Util_TableItQueryKeyValueInfo (iterator, sizeof (key), key, 0, 0) >0; + Util_TableItAdvance (iterator)) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Found option with unrecognized key '%s' in option string " + "'%s'", key, optstring); + CCTK_WARN (1, "Option will be ignored by file reader routines"); + } + Util_TableItDestroy (iterator); + + Util_TableDestroy (table); + } + else + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Couldn't parse option string '%s'", optstring); + CCTK_WARN (1, "Option will be ignored by file reader routines"); + } } } |