aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a>2002-07-01 13:07:37 +0000
committertradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a>2002-07-01 13:07:37 +0000
commit04520bcea06b995a3c7f3be120cbc08f5034374c (patch)
tree2ea3d694960c2c2dd310a04398adf8d6813ae70a
parent0a632ecfa445591cca6514266cdb8db4d4e97a4c (diff)
Extended the generic filereader routines to select variables with a specific
iteration number (see IOUtil's thorn documentation for an example). git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOUtil/trunk@173 b32723a9-ab3a-4a60-88e2-2e5d99d7c17a
-rw-r--r--doc/documentation.tex13
-rw-r--r--src/CheckpointRecovery.c77
-rw-r--r--src/ioGH.h5
3 files changed, 81 insertions, 14 deletions
diff --git a/doc/documentation.tex b/doc/documentation.tex
index 9095042..93f7b30 100644
--- a/doc/documentation.tex
+++ b/doc/documentation.tex
@@ -488,14 +488,19 @@ read from file(s) as initial data:
be separated by spaces)\\
This is useful if a datafile contains multiple variables but only some of
them should be read. Thus it is possible to recover distinguished variables
- from a full checkpoint file. Note that if the file contains several
- timesteps of the same variable only the last one is taken.
+ from a full checkpoint file.\\
+ Note that if the file contains several timesteps of the same variable only
+ the last one is taken by default. This can be changed by adding an option
+ string with the key {\tt cctk\_iteration} and an associated integer scalar
+ value to the variable name denoting the iteration number to choose, like in
+ {\tt IO::filereader\_ID\_vars = "wavetoy::phi[ cctk\_iteration = 10 ]"}.
\end{itemize}
Thorn {\bf IOUtil} also provides a filereader API which can be called
by any application thorn at any time. It gets passed the equivalent information
to the filereader parameters, plus a pointer to the underlying CCTK grid
-hierarchy:
+hierarchy. The return code denotes the total number of variables recovered by
+the filereader.
C API:
\begin{verbatim}
@@ -506,7 +511,7 @@ C API:
Fortran API:
\begin{verbatim}
- call IOUtil_RecoverVarsFromDatafiles (GH, in_files, in_vars)
+ call IOUtil_RecoverVarsFromDatafiles (result, GH, in_files, in_vars)
integer result
CCTK_POINTER GH
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");
+ }
}
}
diff --git a/src/ioGH.h b/src/ioGH.h
index 150e4da..b3e4791 100644
--- a/src/ioGH.h
+++ b/src/ioGH.h
@@ -32,8 +32,9 @@ typedef struct
int recovered; /* flag indicating restart after successful recovery */
/* for data file reader */
- char *do_inVars; /* flags indicating to read in variable [i] */
-
+ CCTK_INT *do_inVars; /* flags indicating to read in variable i with
+ iteration number do_inVars[i] (or -1 to read
+ the last iteration */
} ioGH;