aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@4825ed28-b72c-4eae-9704-e50c059e567d>2003-06-06 16:12:57 +0000
committertradke <tradke@4825ed28-b72c-4eae-9704-e50c059e567d>2003-06-06 16:12:57 +0000
commit48f3617899f8612c9ea595d4b84efaf295cf4864 (patch)
tree39339cf209970de7e3c51aa72f2b60119a6275cf
parent6fbe03a65e0f4320ccb11538c4ac025085881248 (diff)
Changed IOHDF5's OutputVarAs() routine to also accept and evaluate an option
string attached to the variable name. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOHDF5/trunk@167 4825ed28-b72c-4eae-9704-e50c059e567d
-rw-r--r--src/Output.c129
1 files changed, 94 insertions, 35 deletions
diff --git a/src/Output.c b/src/Output.c
index 17fa4b0..958ce62 100644
--- a/src/Output.c
+++ b/src/Output.c
@@ -22,9 +22,24 @@ CCTK_FILEVERSION(CactusPUGHIO_IOHDF5_Output_c)
/********************************************************************
+ ************************ Typedefs *****************************
+ ********************************************************************/
+/* typedef for a structure to be passed to the function callback called by
+ IOHDF5_OutputVarAs() via CCTK_TraverseString() */
+typedef struct
+{
+ const cGH *GH;
+ const char *fullname;
+ const char *alias;
+ int retval;
+} callback_info_t;
+
+
+/********************************************************************
******************** Internal Routines ************************
********************************************************************/
static void CheckSteerableParameters (const cGH *GH);
+static void OutputVarAs (int vindex, const char *optstring, void *arg);
/*@@
@@ -57,7 +72,7 @@ int IOHDF5_OutputGH (const cGH *GH)
retval = 0;
- myGH = (const ioHDF5GH *) CCTK_GHExtension (GH, "IOHDF5");
+ myGH = CCTK_GHExtension (GH, "IOHDF5");
/* loop over all variables */
for (vindex = CCTK_NumVars () - 1; vindex >= 0; vindex--)
@@ -81,9 +96,13 @@ int IOHDF5_OutputGH (const cGH *GH)
@author Gabrielle Allen
@desc
Unconditional output of a variable using the IOHDF5 I/O method.
+ Since the 'fullname' argument may have an option string appended
+ to the actual variable's fullname, we just use
+ CCTK_TraverseString() to split both, and let the callback do
+ the actual work.
@enddesc
- @calls IOHDF5_Write
+ @calls CCTK_TraverseString
@var GH
@vdesc pointer to CCTK GH
@@ -91,7 +110,8 @@ int IOHDF5_OutputGH (const cGH *GH)
@vio in
@endvar
@var fullname
- @vdesc complete name of variable to output
+ @vdesc complete name of variable to output, plus an optional options
+ string (in square brackets)
@vtype const char *
@vio in
@endvar
@@ -109,37 +129,11 @@ int IOHDF5_OutputGH (const cGH *GH)
@@*/
int IOHDF5_OutputVarAs (const cGH *GH, const char *fullname, const char *alias)
{
- int vindex, oneshot, retval;
- const ioHDF5GH *myGH;
- DECLARE_CCTK_PARAMETERS
-
-
- vindex = CCTK_VarIndex (fullname);
-
- if (CCTK_Equals (verbose, "full"))
- {
- CCTK_VInfo (CCTK_THORNSTRING, "IOHDF5_OutputVarAs: fullname, alias, "
- "index = (%s, %s, %d)", fullname, alias, vindex);
- }
-
- /* check whether the variable already has an I/O request entry */
- myGH = (ioHDF5GH *) CCTK_GHExtension (GH, "IOHDF5");
- oneshot = myGH->requests[vindex] == NULL;
- if (oneshot)
- {
- IOUtil_ParseVarsForOutput (GH, CCTK_THORNSTRING, "IOHDF5::out_vars",
- fullname, 1, myGH->requests);
- }
+ callback_info_t info = {GH, fullname, alias, 0};
- /* do the output */
- retval = IOHDF5_Write (GH, vindex, alias);
-
- if (oneshot && myGH->requests[vindex])
- {
- IOUtil_FreeIORequest (&myGH->requests[vindex]);
- }
- return (retval);
+ CCTK_TraverseString (fullname, OutputVarAs, &info, CCTK_VAR);
+ return (info.retval);
}
@@ -181,7 +175,7 @@ int IOHDF5_TimeFor (const cGH *GH, int vindex)
CheckSteerableParameters (GH);
/* check if this variable should be output */
- myGH = (ioHDF5GH *) CCTK_GHExtension (GH, "IOHDF5");
+ myGH = CCTK_GHExtension (GH, "IOHDF5");
retval = myGH->requests[vindex] && myGH->requests[vindex]->out_every > 0 &&
GH->cctk_iteration % myGH->requests[vindex]->out_every == 0;
if (retval)
@@ -239,7 +233,7 @@ int IOHDF5_TriggerOutput (const cGH *GH, int vindex)
varname = CCTK_VarName (vindex);
- myGH = (ioHDF5GH *) CCTK_GHExtension (GH, "IOHDF5");
+ myGH = CCTK_GHExtension (GH, "IOHDF5");
if (CCTK_Equals (verbose, "full"))
{
@@ -292,7 +286,7 @@ static void CheckSteerableParameters (const cGH *GH)
/* how often to output */
- myGH = (ioHDF5GH *) CCTK_GHExtension (GH, "IOHDF5");
+ myGH = CCTK_GHExtension (GH, "IOHDF5");
i = myGH->out_every_default;
myGH->out_every_default = out_every >= 0 ? out_every : io_out_every;
@@ -349,3 +343,68 @@ static void CheckSteerableParameters (const cGH *GH)
myGH->out_vars = strdup (out_vars);
}
}
+
+
+/*@@
+ @routine OutputVarAs
+ @date Fri 6 June 2003
+ @author Thomas Radke
+ @desc
+ Unconditional output of a variable using the IOHDF5 I/O method.
+ @enddesc
+
+ @calls IOUtil_ParseVarsForOutput
+ IOHDF5_Write
+ IOUtil_FreeIORequest
+
+ @var index
+ @vdesc variable index of a variable found in the 'fullname' argument
+ string given to IOHDF5_OutputVarAs()
+ @vtype int
+ @vio in
+ @endvar
+ @var optstring
+ @vdesc option string attached to the variable in the fullname
+ @vtype const char *
+ @vio in
+ @endvar
+ @var arg
+ @vdesc user-supplied argument to the callback function
+ @vtype void *
+ @vio in
+ @endvar
+@@*/
+static void OutputVarAs (int vindex, const char *optstring, void *arg)
+{
+ int oneshot;
+ const ioHDF5GH *myGH;
+ callback_info_t *info = arg;
+ DECLARE_CCTK_PARAMETERS
+
+
+ /* don't warn about unused function arguments */
+ (void) (optstring + 0);
+
+ if (CCTK_Equals (verbose, "full"))
+ {
+ CCTK_VInfo (CCTK_THORNSTRING, "IOHDF5_OutputVarAs: fullname, alias, "
+ "index = (%s, %s, %d)", info->fullname, info->alias, vindex);
+ }
+
+ /* check whether the variable already has an I/O request entry */
+ myGH = CCTK_GHExtension (info->GH, "IOHDF5");
+ oneshot = myGH->requests[vindex] == NULL;
+ if (oneshot)
+ {
+ IOUtil_ParseVarsForOutput (info->GH, CCTK_THORNSTRING, "IOHDF5::out_vars",
+ info->fullname, 1, myGH->requests);
+ }
+
+ /* do the output */
+ info->retval = IOHDF5_Write (info->GH, vindex, info->alias);
+
+ if (oneshot && myGH->requests[vindex])
+ {
+ IOUtil_FreeIORequest (&myGH->requests[vindex]);
+ }
+}