diff options
author | tradke <tradke@4825ed28-b72c-4eae-9704-e50c059e567d> | 2000-10-12 12:08:46 +0000 |
---|---|---|
committer | tradke <tradke@4825ed28-b72c-4eae-9704-e50c059e567d> | 2000-10-12 12:08:46 +0000 |
commit | a32c28145338ad35cbfa9d14d9b5a49b172f4fd5 (patch) | |
tree | efa28027836e90a6b8e9bdf9d75dadc664530c3e /src/Output.c | |
parent | 1f56ad69714215149c2a78143e18997c7fdfb2fc (diff) |
These files now do output as requested by the 'IOHDF5::out_xxx' parameters.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOHDF5/trunk@26 4825ed28-b72c-4eae-9704-e50c059e567d
Diffstat (limited to 'src/Output.c')
-rw-r--r-- | src/Output.c | 322 |
1 files changed, 322 insertions, 0 deletions
diff --git a/src/Output.c b/src/Output.c new file mode 100644 index 0000000..69609f8 --- /dev/null +++ b/src/Output.c @@ -0,0 +1,322 @@ + /*@@ + @file Output.c + @date Tue Jan 9 1999 + @author Gabrielle Allen + @desc + Functions to deal with output of variables in HDF5 file format + @enddesc + @version $Id$ + @@*/ + + +#include <stdlib.h> + +#include "cctk.h" +#include "cctk_Parameters.h" +#include "ioHDF5GH.h" + +/* the rcs ID and its dummy function to use it */ +static char *rcsid = "$Id$"; +CCTK_FILEVERSION(AlphaThorns_IOHDF5_Output_c) + + +/* function prototypes */ +int IOHDF5_TimeFor (cGH *GH, int index); +int IOHDF5_OutputVarAs (cGH *GH, const char *var, const char *alias); +static void CheckSteerableParameters (ioHDF5GH *myGH); + + +/*@@ + @routine IOHDF5_OutputGH + @date Sat March 6 1999 + @author Gabrielle Allen + @desc + Loops over all variables and outputs them if necessary + @enddesc + + @calls IOHDF5_TimeFor + IOHDF5_OutputVarAs + + @var GH + @vdesc Pointer to CCTK GH + @vtype cGH * + @vio in + @endvar +@@*/ +int IOHDF5_OutputGH (cGH *GH) +{ + DECLARE_CCTK_PARAMETERS + int index; + ioHDF5GH *myGH; + const char *name; + char *fullname; + + + /* Get the GH extension for IOHDF5 */ + myGH = (ioHDF5GH *) CCTK_GHExtension (GH, "IOHDF5"); + + CheckSteerableParameters (myGH); + + if (myGH->out_every <= 0) + { + return (0); + } + + /* Loop over all variables */ + for (index = 0; index < CCTK_NumVars (); index++) + { + + if (IOHDF5_TimeFor (GH, index)) + { + name = CCTK_VarName (index); + fullname = CCTK_FullName (index); + + if (verbose) + { + CCTK_VInfo (CCTK_THORNSTRING, "IOHDF5_OutputGH: (fullname / name) = " + "(%s / %s)", fullname, name); + } + + IOHDF5_OutputVarAs (GH, fullname, name); + + free (fullname); + + /* Register variable as having output this iteration */ + myGH->out_last[index] = GH->cctk_iteration; + } + } + + return (0); +} + + +/*@@ + @routine IOHDF5_OutputVarAs + @date Sat March 6 1999 + @author Gabrielle Allen + @desc + Unconditional output of a variable + using the IOHDF5 output method. + @enddesc + + @calls IOHDF5_Write + + @var GH + @vdesc Pointer to CCTK GH + @vtype cGH * + @vio in + @endvar + @var fullname + @vdesc complete name of variable to output + @vtype const char * + @vio in + @endvar + @var alias + @vdesc alias name of variable to output + (used to generate output filename) + @vtype const char * + @vio in + @endvar +@@*/ +int IOHDF5_OutputVarAs (cGH *GH, const char *fullname, const char *alias) +{ + DECLARE_CCTK_PARAMETERS + int index; + + + index = CCTK_VarIndex (fullname); + + if (verbose) + CCTK_VInfo (CCTK_THORNSTRING, "IOHDF5_OutputVarAs: fullname, alias, " + "index = (%s, %s, %d)", fullname, alias, index); + + /* Do the output */ + IOHDF5_Write (GH, index, alias); + + return (0); +} + + +/*@@ + @routine IOHDF5_TimeFor + @date Sat March 6 1999 + @author Gabrielle Allen + @desc + Decides if it is time to output a variable + using the IOHDF5 output method. + @enddesc + + @calls CheckSteerableParameters + + @var GH + @vdesc Pointer to CCTK GH + @vtype cGH * + @vio in + @endvar + @var index + @vdesc index of variable + @vtype int + @vio in + @endvar + + @returntype int + @returndesc + 1 if output should take place + 0 if not + @endreturndesc +@@*/ +int IOHDF5_TimeFor (cGH *GH, int index) +{ + ioHDF5GH *myGH; + + + /* Get the GH extension for IOHDF5 */ + myGH = (ioHDF5GH *) CCTK_GHExtension (GH, "IOHDF5"); + + CheckSteerableParameters (myGH); + + /* Check if any output was requested */ + if(myGH->out_every <= 0) + { + return (0); + } + + /* Check this variable should be output */ + if (! (myGH->do_output[index] && GH->cctk_iteration % myGH->out_every == 0)) + { + return (0); + } + + /* Check variable not already output this iteration */ + if (myGH->out_last[index] == GH->cctk_iteration) + { + CCTK_WARN (2, "Already done output in IOHDF5"); + return (0); + } + + return (1); +} + + +/*@@ + @routine IOHDF5_TriggerOutput + @date Sat March 6 1999 + @author Gabrielle Allen + @desc + Triggers the output of a variable using the IOHDF5 output. + @enddesc + + @calls IOHDF5_Write + + @var GH + @vdesc Pointer to CCTK GH + @vtype cGH * + @vio in + @endvar + @var index + @vdesc index of variable + @vtype int + @vio in + @endvar +@@*/ +int IOHDF5_TriggerOutput (cGH *GH, int index) +{ + DECLARE_CCTK_PARAMETERS + ioHDF5GH *myGH; + char *fullname; + const char *varname; + + + varname = CCTK_VarName (index); + + myGH = (ioHDF5GH *) CCTK_GHExtension (GH, "IOHDF5"); + + if (verbose) + { + fullname = CCTK_FullName (index); + CCTK_VInfo (CCTK_THORNSTRING, "IOHDF5_TriggerOutput: " + "output of (varname, fullname) " + "= ('%s', '%s')", varname, fullname); + free (fullname); + } + + /* Do the output */ + IOHDF5_Write (GH, index, varname); + + /* Register variable as having output this iteration */ + myGH->out_last[index] = GH->cctk_iteration; + + return (0); +} + + +/***************************************************************************/ +/* local functions */ +/***************************************************************************/ +/*@@ + @routine CheckSteerableParameters + @date Mon Oct 10 2000 + @author Thomas Radke + @desc + Checks if IOHDF5 steerable parameters were changed + and does appropriate re-evaluation. + @enddesc + + @calls IOHDF5Util_ParseVarsForOutput + + @var myGH + @vdesc Pointer to IOHDF5 GH + @vtype ioHDF5GH * + @vio in + @endvar +@@*/ +static void CheckSteerableParameters (ioHDF5GH *myGH) +{ + DECLARE_CCTK_PARAMETERS + int times_set; + static int out_vars_lastset = 0; + + + /* How often to output */ + myGH->out_every = out_every > 0 ? out_every : -1; + if (outHDF5_every > 0) + { + myGH->out_every = outHDF5_every; + } + + /* re-parse the 'IOHDF5::out_vars' parameter if it was changed */ + times_set = CCTK_ParameterQueryTimesSet ("out_vars", CCTK_THORNSTRING); + if (times_set != out_vars_lastset) + { + IOHDF5Util_ParseVarsForOutput (out_vars, myGH->do_output, myGH->out_geo); + +#if 0 + FIXME: replace this with real parsing routine + memset (myGH->do_output, 0, CCTK_NumVars ()); + CCTK_TraverseString (out_vars, SetOutputFlag, myGH->do_output, + CCTK_GROUP_OR_VAR); +#endif + + /* Save the last setting of 'out_vars' parameter */ + out_vars_lastset = times_set; + } +} + + +#if 0 +/* callback for CCTK_TraverseString() to set the output flag + for the given variable */ +static void SetOutputFlag (int index, const char *optstring, void *arg) +{ + char *flags = (char *) arg; + + + flags[index] = 1; + + if (optstring) + { + CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING, + "Optional string '%s' in variable name ignored", optstring); + } +} +#endif |