From c0d7c72fb498b9a8c6cf062a31dbbbae75fec444 Mon Sep 17 00:00:00 2001 From: tradke Date: Tue, 20 Jun 2000 08:52:29 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r2, which included commits to RCS files with non-trunk default branches. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOStreamedHDF5/trunk@3 0888f3d4-9f52-45d2-93bc-d00801ff5e46 --- src/Output.c | 270 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 270 insertions(+) create mode 100644 src/Output.c (limited to 'src/Output.c') diff --git a/src/Output.c b/src/Output.c new file mode 100644 index 0000000..cfb0a97 --- /dev/null +++ b/src/Output.c @@ -0,0 +1,270 @@ + /*@@ + @file Output.c + @date Tue Jan 9 1999 + @author Gabrielle Allen + @desc + Functions to deal with output of variables in HDF5 FiberBundle format + @enddesc + @history + @hauthor Thomas Radke @hdate 16 Mar 1999 + @hdesc Converted to Cactus 4.0 + @hendhistory + @@*/ + + + +#include +#include +#include + +#include "cctk.h" +#include "cctk_Parameters.h" +#include "CactusBase/IOUtil/src/ioGH.h" +#include "StreamedHDF5GH.h" + + +/* function prototypes */ +int StreamedHDF5_TimeFor (cGH *GH, int index); +int StreamedHDF5_OutputVarAs (cGH *GH, const char *var, const char *alias); +static void CheckSteerableParameters (StreamedHDF5GH *myGH); + + +/*@@ + @routine StreamedHDF5_OutputGH + @date Sat March 6 1999 + @author Gabrielle Allen + @desc + Loops over all variables and outputs them if necessary + @enddesc + @calledby CCTK_OutputGH ("StreamedHDF5") + @history + + @endhistory + @var GH + @vdesc Pointer to CCTK GH + @vtype cGH + @vio in + @endvar +@@*/ + +int StreamedHDF5_OutputGH (cGH *GH) +{ + DECLARE_CCTK_PARAMETERS + int i; + StreamedHDF5GH *myGH; + const char *name; + char *fullname; + + + /* Get the GH extension for StreamedHDF5 */ + myGH = (StreamedHDF5GH *) GH->extensions [CCTK_GHExtensionHandle ("StreamedHDF5")]; + + CheckSteerableParameters (myGH); + + if (myGH->out_every <= 0) + return (0); + + /* Loop over all variables */ + for (i = 0; i < CCTK_NumVars (); i++) + { + + if (StreamedHDF5_TimeFor (GH, i)) + { + + name = CCTK_VarName (i); + fullname = CCTK_FullName (i); + + if (verbose) + CCTK_VInfo (CCTK_THORNSTRING, "StreamedHDF5_OutputGH: fullname / name = " + "%s / %s", fullname, name); + + StreamedHDF5_OutputVarAs (GH, fullname, name); + + free (fullname); + + /* Register variable as having output this iteration */ + myGH->out_last [i] = GH->cctk_iteration; + } + } + + return (0); +} + + +/*@@ + @routine StreamedHDF5_OutputVarAs + @date Sat March 6 1999 + @author Gabrielle Allen + @desc + unconditional output of a variable using the StreamedHDF5 output method + @enddesc + @calledby StreamedHDF5_OutputGH, CCTK_OutputVarAsByMethod ("StreamedHDF5") + @var GH + @vdesc Pointer to CCTK GH + @vtype cGH + @vio in + @vcomment + @endvar + @var fullname + @vdesc complete name of variable to output + @vtype const char * + @vio in + @vcomment + @endvar + @var alias + @vdesc alias name of variable to output (used to generate output filename) + @vtype const char * + @vio in + @vcomment + @endvar +@@*/ + +int StreamedHDF5_OutputVarAs (cGH *GH, const char *fullname, const char *alias) +{ + DECLARE_CCTK_PARAMETERS + int index; + + + index = CCTK_VarIndex (fullname); + + if (verbose) + CCTK_VInfo (CCTK_THORNSTRING, "StreamedHDF5_OutputVarAs: fullname, alias, " + "index = (%s, %s, %d)", fullname, alias, index); + + /* Do the output */ + StreamedHDF5_Write (GH, index, alias); + + return (0); +} + + +/*@@ + @routine StreamedHDF5_TimeFor + @date Sat March 6 1999 + @author Gabrielle Allen + @desc + Decides if it is time to output a variable using the StreamedHDF5 output + method + @enddesc + @calledby StreamedHDF5_OutputGH + @history + + @endhistory + @var GH + @vdesc Pointer to CCTK GH + @vtype cGH + @vio in + @vcomment + @endvar + @var index + @vdesc index of variable + @vtype int + @vio in + @vcomment + @endvar +@@*/ + +int StreamedHDF5_TimeFor (cGH *GH, int index) +{ + StreamedHDF5GH *myGH; + + + /* Get the GH extension for StreamedHDF5 */ + myGH = (StreamedHDF5GH *) GH->extensions [CCTK_GHExtensionHandle ("StreamedHDF5")]; + + 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 StreamedHDF5"); + return (0); + } + + return (1); +} + + +/*@@ + @routine StreamedHDF5_TriggerOutput + @date Sat March 6 1999 + @author Gabrielle Allen + @desc + Triggers the output a variable using the StreamedHDF5 output + method + @enddesc + @calledby CCTK scheduler + @var GH + @vdesc Pointer to CCTK GH + @vtype cGH + @vio in + @vcomment + @endvar + @var index + @vdesc index of variable to output + @vtype int + @vio in + @vcomment + @endvar +@@*/ + +int StreamedHDF5_TriggerOutput (cGH *GH, int index) +{ + DECLARE_CCTK_PARAMETERS + StreamedHDF5GH *myGH; + const char *varname; + + varname = CCTK_VarName (index); + + myGH = (StreamedHDF5GH *) GH->extensions [CCTK_GHExtensionHandle ("StreamedHDF5")]; + + if (verbose) + CCTK_VInfo (CCTK_THORNSTRING, "StreamedHDF5_TriggerOutput: varname, index = " + "(%s, %d)", varname, index); + + /* Do the output */ + StreamedHDF5_Write (GH, index, varname); + + /* Register variable as having output this iteration */ + myGH->out_last [index] = GH->cctk_iteration; + + return (0); +} + + +/**************************** local functions ******************************/ +static void CheckSteerableParameters (StreamedHDF5GH *myGH) +{ + DECLARE_CCTK_PARAMETERS + const cParamData *paramdata; + static int out_vars_lastset = 0; + + + /* How often to output */ + myGH->out_every = out_every > 0 ? out_every : -1; + if (out_every > 0) + myGH->out_every = out_every; + + /* Check the 'out_vars' parameter */ + paramdata = CCTK_ParameterData ("out_vars", CCTK_THORNSTRING); + if (! paramdata) { + CCTK_WARN (1, "Couldn't get info on parameter 'out_vars'"); + return; + } + + /* re-parse the 'out_vars' parameter if it was changed */ + if (paramdata->n_set != out_vars_lastset) { + ParseVarsForOutput (out_vars, myGH->do_output); + + /* Save the last setting of 'out_vars' parameter */ + out_vars_lastset = paramdata->n_set; + } + +} -- cgit v1.2.3