diff options
Diffstat (limited to 'src/OutputScalar.c')
-rw-r--r-- | src/OutputScalar.c | 105 |
1 files changed, 102 insertions, 3 deletions
diff --git a/src/OutputScalar.c b/src/OutputScalar.c index b336f49..a744164 100644 --- a/src/OutputScalar.c +++ b/src/OutputScalar.c @@ -57,7 +57,7 @@ int IOBasic_ScalarOutputGH (const cGH *GH) iobasicGH *myGH; - myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic"); + myGH = CCTK_GHExtension (GH, "IOBasic"); CheckSteerableParameters (myGH); /* return if no output is required */ @@ -84,6 +84,105 @@ int IOBasic_ScalarOutputGH (const cGH *GH) } +/*@@ + @routine IOBasic_OutputVarAs + @date Sun 8 Mar 2003 + @author Thomas Radke + @desc + Unconditional output of a variable using the "Scalar" I/O method + @enddesc + @calls IOBasic_WriteScalar + + @var GH + @vdesc pointer to CCTK GH + @vtype const cGH * + @vio in + @endvar + @var fullname + @vdesc complete name of variable to output, maybe appended by an + options string + @vtype const char * + @vio in + @endvar + @var alias + @vdesc variable's alias name used to build the output filename + @vtype const char * + @vio in + @endvar + + @returntype int + @returndesc + return code of @seeroutine IOBasic_WriteScalar, or<BR> + -1 if variable cannot be output by "Scalar" + @endreturndesc +@@*/ +int IOBasic_OutputVarAs (const cGH *GH, const char *fullname, const char *alias) +{ + int vindex, old_num_reductions, retval; + char *varname, *tmp; + iobasic_parseinfo_t info; + iobasic_reduction_t *reduction, *old_reductions, *next; + iobasicGH *myGH; + DECLARE_CCTK_PARAMETERS + + + /* get the variable index from 'fullname' */ + varname = strdup (fullname); + tmp = strchr (fullname, '['); + if (tmp) + { + varname[tmp - fullname] = 0; + } + + vindex = CCTK_VarIndex (varname); + free (varname); + if (vindex < -1) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "IOBasic_OutputVarAs: invalid variable name in 'fullname' " + "argument '%s'", fullname); + return (-1); + } + + /* save the old scalar_reductions[vindex] info ... */ + myGH = CCTK_GHExtension (GH, "IOBasic"); + old_num_reductions = myGH->scalar_reductions[vindex].num_reductions; + old_reductions = myGH->scalar_reductions[vindex].reductions; + + /* ... and create a temporary one from 'fullname' */ + retval = 0; + info.reduction_list = myGH->scalar_reductions; + info.reductions_string = outScalar_reductions; + if (CCTK_TraverseString (fullname, IOBasic_AssignReductionList, &info, + CCTK_VAR) < 0) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "IOBasic_OutputVarAs: failed to parse 'fullname' argument '%s'", + fullname); + retval = -1; + } + else if (myGH->scalar_reductions[vindex].num_reductions > 0) + { + /* do the actual output */ + retval = IOBasic_WriteScalar (GH, vindex, alias); + + /* free temporary scalar_reductions[vindex] info and restore the old one */ + reduction = myGH->scalar_reductions[vindex].reductions; + while (reduction) + { + next = reduction->next; + free (reduction->name); + free (reduction); + reduction = next; + } + } + myGH->scalar_reductions[vindex].num_reductions = old_num_reductions; + myGH->scalar_reductions[vindex].reductions = old_reductions; + + return (retval); +} + + /*@@ @routine IOBasic_TimeForScalarOutput @date Sat March 6 1999 @@ -117,7 +216,7 @@ int IOBasic_TimeForScalarOutput (const cGH *GH, int vindex) /* Get the GH extension for IOBasic */ - myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic"); + myGH = CCTK_GHExtension (GH, "IOBasic"); CheckSteerableParameters (myGH); @@ -178,7 +277,7 @@ int IOBasic_TriggerScalarOutput (const cGH *GH, int vindex) /* Get the GH extension for IOBasic */ - myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic"); + myGH = CCTK_GHExtension (GH, "IOBasic"); name = CCTK_VarName (vindex); |