{ "thorn_name": "CactusBase/IOBasic", "url": "https://bitbucket.org/cactuscode/cactusbase.git", "configuration": "# Configuration definition for thorn IOBasic\n# $Header$\n\nREQUIRES IOUtil\n\nREQUIRES THORNS: IOUtil\n", "interface": "# Interface definition for thorn IOBasic\n# $Header$\n\nimplements: IOBasic\ninherits: IO\n\nreal next_info_output_time type=scalar\nreal next_scalar_output_time type=scalar\n\n\nCCTK_INT FUNCTION IO_TruncateOutputFiles \\\n (CCTK_POINTER_TO_CONST IN GH)\n\nREQUIRES FUNCTION IO_TruncateOutputFiles\n", "param": "# Parameter definitions for thorn IOBasic\n# $Header$\n\n\n#############################################################################\n### declare IOBasic parameters\n#############################################################################\nprivate:\n\n##########################\n# Directory to output to\n##########################\nSTRING out_dir \"Output directory for IOBasic's scalar files, overrides IO::out_dir\" STEERABLE = RECOVER\n{\n \".+\" :: \"A valid directory name\"\n \"^$\" :: \"An empty string to choose the default from IO::out_dir\"\n} \"\"\n\n##########################\n# What variables to output\n##########################\nSTRING outInfo_vars \"Variables to output as Info to screen\" STEERABLE = ALWAYS\n{\n \".+\" :: \"Space-separated list of fully qualified variable/group names\"\n \"^$\" :: \"An empty string to output nothing\"\n} \"\"\nSTRING outScalar_vars \"Variables to output into files\" STEERABLE = ALWAYS\n{\n \".+\" :: \"Space-separated list of fully qualified variable/group names\"\n \"^$\" :: \"An empty string to output nothing\"\n} \"\"\n\n\n##########################\n# What reductions to output\n##########################\nSTRING outInfo_reductions \"List of reductions to output as Info to screen\" STEERABLE = ALWAYS\n{\n \".+\" :: \"Space-separated list of reduction operators\"\n} \"minimum maximum\"\nSTRING outScalar_reductions \"List of reductions to output into files\" STEERABLE = ALWAYS\n{\n \".+\" :: \"Space-separated list of reduction operators\"\n} \"minimum maximum norm1 norm2\"\n\n\n########################\n# How often to do output\n########################\nKEYWORD outInfo_criterion \"Criterion to select Info output intervals\"\n{\n \"never\" :: \"Never output\"\n \"iteration\" :: \"Output every so many iterations\"\n \"time\" :: \"Output every that much coordinate time\"\n} \"iteration\"\nINT outInfo_every \"How often to do Info output\" STEERABLE = ALWAYS\n{\n 1:* :: \"Every so many iterations\"\n 0: :: \"Disable Info output\"\n -1: :: \"Default to IO::out_every\"\n} -1\nREAL outInfo_dt \"How often to do Info output\" STEERABLE = ALWAYS\n{\n (0:* :: \"In intervals of that much coordinate time\"\n 0 :: \"As often as possible\"\n -1 :: \"Disable output\"\n -2 :: \"Default to IO::out_dt\"\n} -2\n\nKEYWORD outScalar_criterion \"Criterion to select Scalar output intervals\"\n{\n \"never\" :: \"Never output\"\n \"iteration\" :: \"Output every so many iterations\"\n \"time\" :: \"Output every that much coordinate time\"\n} \"iteration\"\nINT outScalar_every \"How often to do Scalar output\" STEERABLE = ALWAYS\n{\n 1:* :: \"Every so many iterations\"\n 0: :: \"Disable Scalar output\"\n -1: :: \"Default to IO::out_every\"\n} -1\nREAL outScalar_dt \"How often to do Scalar output\" STEERABLE = ALWAYS\n{\n (0:* :: \"In intervals of that much coordinate time\"\n 0 :: \"As often as possible\"\n -1 :: \"Disable output\"\n -2 :: \"Default to IO::out_dt\"\n} -2\n\n\n#####################\n# Scalar output style\n#####################\nKEYWORD outScalar_style \"Which style for Scalar output\" STEERABLE = RECOVER\n{\n \"gnuplot\" :: \"1D output readable by gnuplot\"\n \"xgraph\" :: \"1D output readable by xgraph\"\n} \"xgraph\"\n\nSTRING out_format \"Which format for Scalar floating-point number output\" STEERABLE = ALWAYS\n{\n \"^(\\.[1]?[0-9])?[EGefg]$\" :: \"output with given precision in exponential / floating point notation\"\n} \".13f\"\n\n\n#############################################################################\n### import IOUtil parameters\n#############################################################################\nshares: IO\n\nUSES STRING out_dir AS io_out_dir\nUSES KEYWORD out_criterion\nUSES INT out_every\nUSES REAL out_dt\nUSES KEYWORD verbose\nUSES KEYWORD out_fileinfo\nUSES BOOLEAN new_filename_scheme\nUSES BOOLEAN strict_io_parameter_check\n", "schedule": "# Schedule definitions for thorn IOBasic\n# $Header$\n\n########################################################################\n### register IOBasic routines\n########################################################################\nschedule IOBasic_Startup at STARTUP after IOUtil_Startup\n{\n LANG:C\n} \"Startup routine\"\n\n\n########################################################################\n### register IOBasic routines\n########################################################################\nstorage: next_info_output_time next_scalar_output_time\nschedule IOBasic_Init at INITIAL\n{\n LANG:C\n WRITES: IOBasic::next_info_output_time(everywhere)\n WRITES: IOBasic::next_scalar_output_time(everywhere)\n} \"Initialisation routine\"\n", "src": { "make.code.defn": "# Main make.code.defn file for thorn IOBasic\n# $Header$\n\n# Source files in this directory\nSRCS = Startup.c \\\n OutputScalar.c \\\n OutputInfo.c \\\n WriteScalar.c \\\n WriteInfo.c \n", "OutputScalar.c": "/*@@\n @file Output.c\n @date Mon 21 September\n @author Gabrielle Allen\n @desc\n Functions to deal with scalar output of grid variables\n @enddesc\n@@*/\n\n/* #define IOBASIC_DEBUG 1 */\n\n#include \n#include \n#include \n\n#include \"cctk.h\"\n#include \"cctk_Arguments.h\"\n#include \"cctk_Parameters.h\"\n#include \"util_String.h\"\n#include \"iobasicGH.h\"\n\nstatic const char *rcsid = \"$Header$\";\n\nCCTK_FILEVERSION(CactusBase_IOBasic_OutputScalar_c)\n\n/********************************************************************\n ******************** Static Variables ************************\n ********************************************************************/\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\nstatic int TimeForOutput(const cGH *cctkGH);\n\n/********************************************************************\n ******************** External Routines ************************\n ********************************************************************/\n/*@@\n @routine IOBasic_ScalarOutputGH\n @date Sat March 6 1999\n @author Gabrielle Allen\n @desc\n Loops over all variables and outputs them if necessary\n @enddesc\n @calls IOBasic_TimeForScalarOutput\n IOBasic_WriteScalar\n\n @var GH\n @vdesc Pointer to CCTK GH\n @vtype const cGH *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n the number of variables which were output at this iteration\n (or 0 if it wasn't time to output yet)\n @endreturndesc\n@@*/\nint IOBasic_ScalarOutputGH(const cGH *GH) {\n int vindex, retval;\n iobasicGH *myGH;\n\n /* get the GH extensions for IOBasic */\n myGH = CCTK_GHExtension(GH, \"IOBasic\");\n\n /* check if steerable parameters changed */\n IOBasic_CheckSteerableScalarParameters(myGH);\n\n if (!TimeForOutput(GH))\n return 0;\n\n retval = 0;\n\n /* loop over all variables */\n for (vindex = CCTK_NumVars() - 1; vindex >= 0; vindex--) {\n if (IOBasic_TimeForScalarOutput(GH, vindex) &&\n IOBasic_WriteScalar(GH, vindex, CCTK_VarName(vindex)) == 0) {\n /* register variable as having output this iteration */\n myGH->outScalar_last[vindex] = GH->cctk_iteration;\n retval++;\n }\n }\n\n return (retval);\n}\n\n/*@@\n @routine IOBasic_OutputVarAs\n @date Sun 8 Mar 2003\n @author Thomas Radke\n @desc\n Unconditional output of a variable using the \"Scalar\" I/O method\n @enddesc\n @calls IOBasic_WriteScalar\n\n @var GH\n @vdesc pointer to CCTK GH\n @vtype const cGH *\n @vio in\n @endvar\n @var fullname\n @vdesc complete name of variable to output, maybe appended by an\n options string\n @vtype const char *\n @vio in\n @endvar\n @var alias\n @vdesc variable's alias name used to build the output filename\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine IOBasic_WriteScalar, or
\n -1 if variable cannot be output by \"Scalar\"\n @endreturndesc\n@@*/\nint IOBasic_OutputVarAs(const cGH *GH, const char *fullname,\n const char *alias) {\n int vindex, old_num_reductions, retval;\n char *varname, *tmp;\n iobasic_parseinfo_t info;\n iobasic_reduction_t *reduction, *old_reductions, *next;\n iobasicGH *myGH;\n DECLARE_CCTK_PARAMETERS\n\n /* get the variable index from 'fullname' */\n varname = strdup(fullname);\n tmp = strchr(fullname, '[');\n if (tmp) {\n varname[tmp - fullname] = 0;\n }\n\n vindex = CCTK_VarIndex(varname);\n free(varname);\n if (vindex < -1) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"IOBasic_OutputVarAs: invalid variable name in 'fullname' \"\n \"argument '%s'\",\n fullname);\n return (-1);\n }\n\n /* save the old scalar_reductions[vindex] info ... */\n myGH = CCTK_GHExtension(GH, \"IOBasic\");\n old_num_reductions = myGH->scalar_reductions[vindex].num_reductions;\n old_reductions = myGH->scalar_reductions[vindex].reductions;\n\n /* ... and create a temporary one from 'fullname' */\n retval = 0;\n info.reduction_list = myGH->scalar_reductions;\n info.reductions_string = outScalar_reductions;\n if (CCTK_TraverseString(fullname, IOBasic_AssignReductionList, &info,\n CCTK_VAR) < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"IOBasic_OutputVarAs: failed to parse 'fullname' argument '%s'\",\n fullname);\n retval = -1;\n } else if (myGH->scalar_reductions[vindex].num_reductions > 0) {\n /* do the actual output */\n retval = IOBasic_WriteScalar(GH, vindex, alias);\n\n /* free temporary scalar_reductions[vindex] info and restore the old one */\n reduction = myGH->scalar_reductions[vindex].reductions;\n while (reduction) {\n next = reduction->next;\n free(reduction->name);\n free(reduction);\n reduction = next;\n }\n }\n myGH->scalar_reductions[vindex].num_reductions = old_num_reductions;\n myGH->scalar_reductions[vindex].reductions = old_reductions;\n\n return (retval);\n}\n\n/*@@\n @routine IOBasic_TimeForScalarOutput\n @date Sat March 6 1999\n @author Gabrielle Allen\n @desc\n Decides if it is time to do Scalar output.\n @enddesc\n\n @var GH\n @vdesc Pointer to CCTK GH\n @vtype const cGH *\n @vio in\n @endvar\n @var vindex\n @vdesc index of variable\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n 1 if output should take place at this iteration, or
\n 0 if not\n @endreturndesc\n@@*/\nint IOBasic_TimeForScalarOutput(const cGH *GH, int vindex) {\n char *fullname;\n iobasicGH *myGH;\n\n /* get the GH extensions for IOBasic */\n myGH = CCTK_GHExtension(GH, \"IOBasic\");\n\n /* check if steerable parameters changed */\n IOBasic_CheckSteerableScalarParameters(myGH);\n\n if (myGH->scalar_reductions[vindex].num_reductions == 0) {\n return 0;\n }\n\n if (!TimeForOutput(GH)) {\n return 0;\n }\n\n /* Check if variable wasn't already output this iteration */\n if (myGH->outScalar_last[vindex] == GH->cctk_iteration) {\n fullname = CCTK_FullName(vindex);\n CCTK_VWarn(5, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Already done scalar output for '%s' in current iteration \"\n \"(probably via triggers)\",\n fullname);\n free(fullname);\n return 0;\n }\n\n return 1;\n}\n\n/*@@\n @routine IOBasic_TriggerScalarOutput\n @date Sat March 6 1999\n @author Gabrielle Allen\n @desc\n Triggers the output of a variable using IOBasic's Scalar\n output method\n @enddesc\n\n @var GH\n @vdesc Pointer to CCTK GH\n @vtype const cGH *\n @vio in\n @endvar\n @var vindex\n @vdesc index of variable to output\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine IOBasic_WriteScalar\n @endreturndesc\n@@*/\nint IOBasic_TriggerScalarOutput(const cGH *GH, int vindex) {\n int retval;\n const char *name;\n iobasicGH *myGH;\n\n /* Get the GH extension for IOBasic */\n myGH = CCTK_GHExtension(GH, \"IOBasic\");\n\n name = CCTK_VarName(vindex);\n\n#ifdef IOBASIC_DEBUG\n printf(\"\\nIn IOBasic_TriggerScalarOutput\\n---------------------\\n\");\n printf(\" Index = %d\\n\", vindex);\n printf(\" Variable = -%s-\\n\", name);\n#endif\n\n /* do the Scalar output */\n retval = IOBasic_WriteScalar(GH, vindex, name);\n if (retval == 0) {\n /* register variable as having Scalar output this iteration */\n myGH->outScalar_last[vindex] = GH->cctk_iteration;\n }\n\n return (retval);\n}\n\n/*@@\n @routine IOBasic_CheckSteerableScalarParameters\n @date Tue 31 Jul 2001\n @author Thomas Radke\n @desc\n Re-evaluates 'IOBasic::outScalar_every' and/or 'IO::out_every'\n resp. to set myGH->outScalar_every to the frequency of scalar\n output. Re-evaluates 'IOBasic::outScalar_vars' and\n 'IOBasic::outScalar_reductions'.\n @enddesc\n @calls CCTK_ParameterQueryTimesSet\n\n @var myGH\n @vdesc Pointer to IOBasic's GH extension\n @vtype iobasicGH *\n @vio in\n @endvar\n@@*/\nvoid IOBasic_CheckSteerableScalarParameters(iobasicGH *myGH) {\n int vindex, out_old, times_set, update_reductions_list, num_vars;\n CCTK_REAL outdt_old;\n iobasic_reduction_t *reduction, *next;\n static int outScalar_vars_lastset = -1;\n static int outScalar_reductions_lastset = -1;\n iobasic_parseinfo_t info;\n char *msg, *oldmsg, *fullname;\n DECLARE_CCTK_PARAMETERS\n\n if (CCTK_EQUALS(outScalar_criterion, \"never\")) {\n return;\n } else if (CCTK_EQUALS(outScalar_criterion, \"iteration\")) {\n /* how often to output */\n out_old = myGH->outScalar_every;\n myGH->outScalar_every = outScalar_every >= 0 ? outScalar_every : out_every;\n\n /* report if frequency changed */\n if (myGH->outScalar_every != out_old && !CCTK_Equals(verbose, \"none\")) {\n if (myGH->outScalar_every > 0) {\n CCTK_VInfo(CCTK_THORNSTRING,\n \"Periodic scalar output every %d iterations\",\n myGH->outScalar_every);\n } else {\n CCTK_INFO(\"Periodic scalar output turned off\");\n }\n }\n\n /* return if there's nothing to do */\n if (myGH->outScalar_every <= 0) {\n return;\n }\n } else if (CCTK_EQUALS(outScalar_criterion, \"time\")) {\n /* how often to output */\n outdt_old = myGH->outScalar_dt;\n myGH->outScalar_dt = outScalar_dt >= 0 ? outScalar_dt : out_dt;\n\n /* report if frequency changed */\n if (myGH->outScalar_dt != outdt_old && !CCTK_Equals(verbose, \"none\")) {\n if (myGH->outScalar_dt >= 0) {\n CCTK_VInfo(CCTK_THORNSTRING, \"Periodic scalar output dt %g\",\n (double)myGH->outScalar_dt);\n } else {\n CCTK_INFO(\"Periodic scalar output turned off\");\n }\n }\n\n /* return if there's nothing to do */\n if (myGH->outScalar_dt < 0) {\n return;\n }\n } else {\n if (!(0))\n CCTK_VWarn(0, __LINE__, __FILE__, \"IOBasic\",\n \"outScalar_criterion out of bounds\");\n }\n\n /* check if the 'outScalar_reductions' parameter if it was changed */\n times_set =\n CCTK_ParameterQueryTimesSet(\"outScalar_reductions\", CCTK_THORNSTRING);\n update_reductions_list = times_set != outScalar_reductions_lastset;\n outScalar_reductions_lastset = times_set;\n\n /* check if the 'outScalar_vars' parameter if it was changed */\n times_set = CCTK_ParameterQueryTimesSet(\"outScalar_vars\", CCTK_THORNSTRING);\n update_reductions_list |= times_set != outScalar_vars_lastset;\n outScalar_vars_lastset = times_set;\n\n if (update_reductions_list) {\n /* free old reduction lists ... */\n num_vars = CCTK_NumVars();\n for (vindex = 0; vindex < num_vars; vindex++) {\n if (myGH->scalar_reductions[vindex].num_reductions > 0) {\n myGH->scalar_reductions[vindex].num_reductions = 0;\n reduction = myGH->scalar_reductions[vindex].reductions;\n while (reduction) {\n next = reduction->next;\n free(reduction->name);\n free(reduction);\n reduction = next;\n }\n }\n }\n\n /* ... and create new ones */\n info.reduction_list = myGH->scalar_reductions;\n info.reductions_string = outScalar_reductions;\n if (CCTK_TraverseString(outScalar_vars, IOBasic_AssignReductionList, &info,\n CCTK_GROUP_OR_VAR) < 0) {\n CCTK_WARN(myGH->stop_on_parse_errors ? 0 : 1,\n \"error while parsing parameter 'IOBasic::outScalar_vars'\");\n } else if (!CCTK_Equals(verbose, \"none\")) {\n msg = NULL;\n for (vindex = 0; vindex < num_vars; vindex++) {\n if (myGH->scalar_reductions[vindex].num_reductions) {\n fullname = CCTK_FullName(vindex);\n if (!msg) {\n Util_asprintf(&msg, \"Periodic scalar output requested for '%s'\",\n fullname);\n } else {\n oldmsg = msg;\n Util_asprintf(&msg, \"%s, '%s'\", oldmsg, fullname);\n free(oldmsg);\n }\n free(fullname);\n }\n }\n if (msg) {\n CCTK_INFO(msg);\n free(msg);\n }\n }\n }\n}\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\nstatic int TimeForOutput(const cGH *cctkGH) {\n DECLARE_CCTK_ARGUMENTS;\n DECLARE_CCTK_PARAMETERS;\n iobasicGH *myGH;\n\n /* get the GH extensions for IOBasic */\n myGH = CCTK_GHExtension(cctkGH, \"IOBasic\");\n\n /* check if steerable parameters changed */\n IOBasic_CheckSteerableScalarParameters(myGH);\n\n /* how to decide when to output? */\n /* (return if no output is required) */\n if (CCTK_EQUALS(outScalar_criterion, \"never\")) {\n return 0;\n } else if (CCTK_EQUALS(outScalar_criterion, \"iteration\")) {\n if (myGH->outScalar_every <= 0 || cctk_iteration % myGH->outScalar_every) {\n return 0;\n }\n } else if (CCTK_EQUALS(outScalar_criterion, \"time\")) {\n if (myGH->outScalar_dt < 0) {\n return 0;\n }\n if (myGH->outScalar_dt > 0) {\n static int output_iteration = -1;\n static int output_this_iteration;\n if (!(cctk_iteration >= output_iteration))\n CCTK_VWarn(0, __LINE__, __FILE__, \"IOBasic\",\n \"cctk_iteration out of bounds\");\n if (cctk_iteration > output_iteration) {\n output_iteration = cctk_iteration;\n output_this_iteration =\n cctk_time >= *next_scalar_output_time - 1.0e-12 * cctk_delta_time;\n if (output_this_iteration) {\n *next_scalar_output_time += myGH->outScalar_dt;\n }\n }\n if (!output_this_iteration) {\n return 0;\n }\n }\n } else {\n if (!(0))\n CCTK_VWarn(0, __LINE__, __FILE__, \"IOBasic\",\n \"outScalar_criterion out of bounds\");\n }\n\n return 1;\n}\n", "WriteScalar.c": "/*@@\n @routine WriteScalar.c\n @date 18th September 1999\n @author Gabrielle Allen\n @desc\n Dumps data for IOBasic's \"Scalar\" I/O method to output files\n @enddesc\n @version $Id$\n@@*/\n\n#include \n#include \n#include \n#include /* strlen(3) */\n#include \n#include /* stat(2) */\n\n#include \"cctk.h\"\n#include \"cctk_Parameters.h\"\n#include \"CactusBase/IOUtil/src/ioutil_AdvertisedFiles.h\"\n#include \"iobasicGH.h\"\n\nstatic const char *rcsid = \"$Header$\";\n\nCCTK_FILEVERSION(CactusBase_IOBasic_WriteScalar_c);\n\nstatic int IOBasic_WriteScalarGS(const cGH *GH, int vindex, const char *alias);\nstatic int IOBasic_WriteScalarGA(const cGH *GH, int vindex, const char *alias);\nstatic FILE *OpenScalarFile(const cGH *GH, int vindex, const char *filename,\n const char *slicename, const char *description,\n const char *aliasname);\n\n/*@@\n @routine IOBasic_WriteScalar\n @date Mon Jun 19 2000\n @author Thomas Radke\n @desc\n Write a scalar value of a CCTK variable into an ASCII file\n suitable for postprocessing by either gnuplot or xgraph.\n This routine just calls the appropriate output routine\n according to the variable type.\n @enddesc\n\n @calls CCTK_QueryGroupStorageI\n CCTK_GroupIndexFromVarI\n CCTK_GroupTypeFromVarI\n IOBasic_WriteScalarGS\n IOBasic_WriteScalarGA\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var vindex\n @vdesc CCTK index of the variable to output\n @vtype int\n @vio in\n @endvar\n @var alias\n @vdesc alias name to use for building the output filename\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of either @seeroutine IOBasic_WriteScalarGS or\n @seeroutine IOBasic_WriteScalarGA, or\n -1 if variable has no storage assigned\n @endreturndesc\n@@*/\nint IOBasic_WriteScalar(const cGH *GH, int vindex, const char *alias) {\n int retval;\n char *fullname;\n\n /* check if variable has storage assigned */\n if (!CCTK_QueryGroupStorageI(GH, CCTK_GroupIndexFromVarI(vindex))) {\n fullname = CCTK_FullName(vindex);\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"IOBasic_WriteScalar: No scalar output for '%s' (no storage)\",\n fullname);\n free(fullname);\n retval = -1;\n } else if (CCTK_GroupTypeFromVarI(vindex) == CCTK_SCALAR) {\n retval = IOBasic_WriteScalarGS(GH, vindex, alias);\n } else {\n retval = IOBasic_WriteScalarGA(GH, vindex, alias);\n }\n\n return (retval);\n}\n\n/*@@\n @routine IOBasic_WriteScalarGA\n @date Mon Jun 19 2000\n @author Thomas Radke\n @desc\n Apply the given reduction operators on the CCTK_ARRAY or\n CCTK_GF variable and output the result into a text file\n suitable for postprocessing by either gnuplot or xgraph.\n @enddesc\n\n @calls CCTK_ReduceGridArrays\n CCTK_ReductionHandle\n IOUtil_RestartFromRecovery\n IOUtil_AdvertiseFile\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var vindex\n @vdesc CCTK index of the variable to output\n @vtype int\n @vio in\n @endvar\n @var alias\n @vdesc alias name to use for building the output filename\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n 0 for success\n @endreturndesc\n@@*/\nstatic int IOBasic_WriteScalarGA(const cGH *GH, int vindex, const char *alias) {\n iobasicGH *myGH;\n FILE *file;\n char *filename;\n char format_str[15];\n const char *file_extension;\n iobasic_reduction_t *reduction;\n DECLARE_CCTK_PARAMETERS\n\n CCTK_INT input_array[1];\n CCTK_INT output_array_type_codes[1];\n CCTK_REAL output_value;\n void *reduction_value[1];\n\n input_array[0] = vindex;\n output_array_type_codes[0] = CCTK_VARIABLE_REAL;\n reduction_value[0] = &output_value;\n\n /* set output format */\n sprintf(format_str, \"%%%s\\t%%%s\\n\", out_format, out_format);\n\n /* set the output file extension and the output style */\n file_extension = CCTK_Equals(outScalar_style, \"gnuplot\") ? \".asc\" : \".xg\";\n\n /* get the GH extension handle for IOBasic */\n myGH = CCTK_GHExtension(GH, \"IOBasic\");\n reduction = myGH->scalar_reductions[vindex].reductions;\n\n /* now loop over all reduction operators */\n while (reduction) {\n /* do the reduction (all processors) */\n reduction->is_valid =\n CCTK_ReduceGridArrays(GH, 0, reduction->handle, -1, 1, input_array, 1,\n output_array_type_codes, reduction_value) == 0;\n reduction->value = output_value;\n\n if (!reduction->is_valid) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"IOBasic_WriteScalar: Internal error in reduction '%s'\",\n reduction->name);\n } else if (CCTK_MyProc(GH) == 0) {\n /* dump the reduction value to file by processor 0 */\n if (new_filename_scheme) {\n /* allocate filename string buffer and build the filename */\n filename = malloc(strlen(myGH->out_dir) + strlen(alias) +\n strlen(reduction->name) + strlen(file_extension) + 2);\n sprintf(filename, \"%s%s_%s%s\", myGH->out_dir, alias, reduction->name,\n file_extension);\n } else {\n /* FIXME: this check can go if we switch to the new filename scheme */\n if (strcmp(reduction->name, \"minimum\") == 0) {\n file_extension = \"min\";\n } else if (strcmp(reduction->name, \"maximum\") == 0) {\n file_extension = \"max\";\n } else if (strcmp(reduction->name, \"norm1\") == 0) {\n file_extension = \"nm1\";\n } else if (strcmp(reduction->name, \"norm2\") == 0) {\n file_extension = \"nm2\";\n } else {\n file_extension = reduction->name;\n }\n\n /* allocate filename string buffer and build the filename */\n filename = malloc(strlen(myGH->out_dir) + strlen(alias) +\n strlen(file_extension) + 5);\n sprintf(filename, \"%s%s_%s.tl\", myGH->out_dir, alias, file_extension);\n }\n\n file = OpenScalarFile(GH, vindex, filename, reduction->name,\n \"Reduction on Grid Arrays\", alias);\n if (file) {\n /* write the data and close the file */\n fprintf(file, format_str, GH->cctk_time, reduction->value);\n fclose(file);\n } else {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"IOBasic_WriteScalarGA: Could not open output file '%s'\",\n filename);\n }\n free(filename);\n }\n\n reduction = reduction->next;\n }\n\n return (0);\n}\n\n/*@@\n @routine IOBasic_WriteScalarGS\n @date Mon Jun 19 2000\n @author Thomas Radke\n @desc\n Output the value of a CCTK_SCALAR variable into an ASCII file\n suitable for postprocessing by either gnuplot or xgraph.\n @enddesc\n\n @calls CCTK_MyProc\n CCTK_GHExtension\n CCTK_Equals\n OpenScalarFile\n CCTK_VarDataPtrI\n CCTK_VarTypeI\n CCTK_WARN\n CCTK_VWarn\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var vindex\n @vdesc CCTK index of the variable to output\n @vtype int\n @vio in\n @endvar\n @var alias\n @vdesc alias name to use for building the output filename\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n 0 for success\n @endreturndesc\n@@*/\nstatic int IOBasic_WriteScalarGS(const cGH *GH, int vindex, const char *alias) {\n FILE *file;\n void *data;\n iobasicGH *myGH;\n char *filename;\n const char *file_extension;\n char format_str_real[15], format_str_int[15];\n DECLARE_CCTK_PARAMETERS\n\n /* output is done by processor 0 only */\n if (CCTK_MyProc(GH) != 0) {\n return (0);\n }\n\n /* set the output format string for the desired notation */\n sprintf(format_str_real, \"%%%s\\t%%%s\\n\", out_format, out_format);\n sprintf(format_str_int, \"%%%s\\t%%d\\n\", out_format);\n\n /* get the GH extensions for IOBasic */\n myGH = CCTK_GHExtension(GH, \"IOBasic\");\n\n /* set the output file extension according to the output style */\n if (new_filename_scheme) {\n file_extension = CCTK_Equals(outScalar_style, \"gnuplot\") ? \".asc\" : \".xg\";\n } else {\n file_extension = \".tl\";\n }\n\n /* build the output filename */\n filename = malloc(strlen(myGH->out_dir) + strlen(alias) +\n strlen(file_extension) + 1);\n sprintf(filename, \"%s%s%s\", myGH->out_dir, alias, file_extension);\n\n /* create/reopen the file */\n file = OpenScalarFile(GH, vindex, filename, \"tl\", \"Scalar value\", alias);\n if (file) {\n /* get the data pointer */\n data = CCTK_VarDataPtrI(GH, 0, vindex);\n\n switch (CCTK_VarTypeI(vindex)) {\n case CCTK_VARIABLE_REAL:\n fprintf(file, format_str_real, GH->cctk_time, (double)*(CCTK_REAL *)data);\n break;\n case CCTK_VARIABLE_INT:\n fprintf(file, format_str_int, GH->cctk_time, (int)*(CCTK_INT *)data);\n break;\n default:\n CCTK_WARN(3, \"Unsupported data type\");\n break;\n }\n\n /* close the output file */\n fclose(file);\n } else {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"IOBasic_WriteScalarGS: Could not open output file '%s'\",\n filename);\n }\n\n /* clean up */\n free(filename);\n\n return (0);\n}\n\nstatic FILE *OpenScalarFile(const cGH *GH, int vindex, const char *filename,\n const char *slicename, const char *description,\n const char *aliasname) {\n int first_time_through;\n FILE *file;\n iobasicGH *myGH;\n char *fullname;\n char comment_char, buffer[128];\n ioAdvertisedFileDesc advertised_file;\n DECLARE_CCTK_PARAMETERS\n\n /* get the GH extension handle for IOBasic */\n myGH = CCTK_GHExtension(GH, \"IOBasic\");\n\n /* get the variable's full name */\n fullname = CCTK_FullName(vindex);\n\n /* create the output file the first time through\n If restart from recovery, existing files are opened in append mode. */\n first_time_through = GetNamedData(myGH->filenameListScalar, filename) == NULL;\n file = fopen(filename,\n IO_TruncateOutputFiles(GH) && first_time_through ? \"w\" : \"a\");\n if (!file) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"OpenScalarFile: Cannot open output file '%s'\", filename);\n } else if (first_time_through) {\n if (CCTK_Equals(outScalar_style, \"gnuplot\")) {\n comment_char = '#';\n advertised_file.mimetype = \"application/gnuplot\";\n } else {\n comment_char = '\"'; /* this is for xgraph */\n advertised_file.mimetype = \"application/x-graph\";\n }\n\n /* just store a non-NULL pointer in database */\n StoreNamedData(&myGH->filenameListScalar, filename, (void *)1);\n\n /* advertise the file for downloading */\n advertised_file.slice = slicename;\n advertised_file.thorn = CCTK_THORNSTRING;\n advertised_file.varname = fullname;\n advertised_file.description = description;\n\n IOUtil_AdvertiseFile(GH, filename, &advertised_file);\n\n /* write the file info and the header */\n if (CCTK_Equals(out_fileinfo, \"parameter filename\") ||\n CCTK_Equals(out_fileinfo, \"all\")) {\n buffer[0] = 0;\n CCTK_ParameterFilename(sizeof(buffer), buffer);\n fprintf(file, \"%cParameter file %s\\n\", comment_char, buffer);\n }\n if (CCTK_Equals(out_fileinfo, \"creation date\") ||\n CCTK_Equals(out_fileinfo, \"all\")) {\n buffer[0] = 0;\n Util_CurrentDate(sizeof(buffer), buffer);\n fprintf(file, \"%cCreated %s \", comment_char, buffer);\n Util_CurrentTime(sizeof(buffer), buffer);\n fprintf(file, \"%s\\n\", buffer);\n }\n if (CCTK_Equals(out_fileinfo, \"axis labels\") ||\n CCTK_Equals(out_fileinfo, \"all\")) {\n fprintf(file, \"%cx-label time\\n\", comment_char);\n fprintf(file, \"%cy-label %s\\n\", comment_char, advertised_file.varname);\n }\n fprintf(file, \"%c%s v time\\n\", comment_char, aliasname);\n }\n\n free(fullname);\n\n return (file);\n}\n", "iobasicGH.h": "/*@@\n @header iobasicGH.h\n @date Friday 18th September 1999\n @author Gabrielle Allen\n @desc\n The extensions to the GH structure from IOBasic.\n @enddesc\n @version $Header$\n@@*/\n\n#ifndef _IOBASIC_IOBASICGH_H_\n#define _IOBASIC_IOBASICGH_H_ 1\n\n#include \"StoreNamedData.h\"\n\ntypedef struct IOBASIC_REDUCTION {\n int handle;\n char *name;\n char is_valid;\n CCTK_REAL value;\n struct IOBASIC_REDUCTION *next;\n} iobasic_reduction_t;\n\ntypedef struct IOBASIC_REDUCTIONLIST {\n unsigned int num_reductions;\n iobasic_reduction_t *reductions;\n} iobasic_reductionlist_t;\n\ntypedef struct IOBASIC_PARSEINFO {\n const char *reductions_string;\n iobasic_reductionlist_t *reduction_list;\n} iobasic_parseinfo_t;\n\ntypedef struct IOBASIC_GH {\n /* how often to output */\n int outScalar_every, outInfo_every;\n CCTK_REAL outScalar_dt, outInfo_dt;\n char info_reductions_changed;\n\n /* directory in which to place scalar output */\n char *out_dir;\n\n /* The last iteration output */\n int *outInfo_last, *outScalar_last;\n\n /* The reduction lists for info and scalar output for all variables */\n iobasic_reductionlist_t *info_reductions, *scalar_reductions;\n\n /* database for names of output files that were already created */\n pNamedData *filenameListScalar;\n\n /* stop on I/O parameter parsing errors ? */\n int stop_on_parse_errors;\n\n} iobasicGH;\n\n/* prototypes of functions to be registered */\nint IOBasic_InfoOutputGH(const cGH *GH);\nint IOBasic_OutputVarAs(const cGH *GH, const char *fullname, const char *alias);\nint IOBasic_TriggerInfoOutput(const cGH *GH, int vindex);\nint IOBasic_TimeForInfoOutput(const cGH *GH, int vindex);\nint IOBasic_ScalarOutputGH(const cGH *GH);\nint IOBasic_TriggerScalarOutput(const cGH *GH, int vindex);\nint IOBasic_TimeForScalarOutput(const cGH *GH, int vindex);\n\n/* other function prototypes */\nvoid IOBasic_AssignReductionList(int vindex, const char *optstring, void *arg);\nint IOBasic_WriteInfo(const cGH *GH, int vindex);\nint IOBasic_WriteScalar(const cGH *GH, int vindex, const char *alias);\nvoid IOBasic_CheckSteerableInfoParameters(iobasicGH *myGH);\nvoid IOBasic_CheckSteerableScalarParameters(iobasicGH *myGH);\n\n#endif /* _IOBASIC_IOBASICGH_H_ */\n", "OutputInfo.c": "/*@@\n @file OutputInfo.c\n @date June 31 1999\n @author Gabrielle Allen\n @desc\n Functions to deal with info output of variables\n @enddesc\n @version $Id$\n@@*/\n\n#include \n#include \n#include \n#include \n\n#include \"cctk.h\"\n#include \"cctk_Arguments.h\"\n#include \"cctk_Parameters.h\"\n#include \"util_String.h\"\n#include \"iobasicGH.h\"\n\n/* the rcs ID and its dummy function to use it */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusBase_IOBasic_OutputInfo_c)\n\n/********************************************************************\n ******************** Macro Definitions ***********************\n ********************************************************************/\n/* uncomment the following to get some debugging output */\n/* #define IOBASIC_DEBUG 1 */\n\n/* the number at which to switch from decimal to exponential notation */\n#define DECIMAL_SMALLEST 1.0e-8\n#define DECIMAL_TOOBIG 1.0e+3\n#define USE_DECIMAL_NOTATION(x) \\\n ((x) == 0.0 || \\\n (fabs((double)x) >= DECIMAL_SMALLEST && fabs((double)x) < DECIMAL_TOOBIG))\n#define PRINT_FORMATTED_REDUCTION_VALUE(reduction) \\\n if (reduction->is_valid) { \\\n if (USE_DECIMAL_NOTATION(reduction->value)) { \\\n printf(\"% 13.8f |\", reduction->value); \\\n } else { \\\n printf(\"% 11.6e |\", reduction->value); \\\n } \\\n } else { \\\n printf(\" ------------ |\"); \\\n }\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\nstatic void PrintHeader(iobasicGH *myGH, int num_vars);\nstatic int TimeForOutput(const cGH *cctkGH);\n\nstatic int TimeForOutput(const cGH *cctkGH) {\n DECLARE_CCTK_ARGUMENTS;\n DECLARE_CCTK_PARAMETERS;\n iobasicGH *myGH;\n\n /* get the GH extensions for IOBasic */\n myGH = CCTK_GHExtension(cctkGH, \"IOBasic\");\n\n /* check if steerable parameters changed */\n IOBasic_CheckSteerableInfoParameters(myGH);\n\n /* how to decide when to output? */\n /* (return if no output is required) */\n if (CCTK_EQUALS(outInfo_criterion, \"never\")) {\n return 0;\n } else if (CCTK_EQUALS(outInfo_criterion, \"iteration\")) {\n if (myGH->outInfo_every <= 0 || cctk_iteration % myGH->outInfo_every) {\n return 0;\n }\n } else if (CCTK_EQUALS(outInfo_criterion, \"time\")) {\n if (myGH->outInfo_dt < 0) {\n return 0;\n }\n if (myGH->outInfo_dt > 0) {\n static int output_iteration = -1;\n static int output_this_iteration;\n if (!(cctk_iteration >= output_iteration))\n CCTK_VWarn(0, __LINE__, __FILE__, \"IOBasic\",\n \"cctk_iteration out of bounds\");\n if (cctk_iteration > output_iteration) {\n output_iteration = cctk_iteration;\n output_this_iteration =\n cctk_time >= *next_info_output_time - 1.0e-12 * cctk_delta_time;\n if (output_this_iteration) {\n *next_info_output_time += myGH->outInfo_dt;\n }\n }\n if (!output_this_iteration) {\n return 0;\n }\n }\n } else {\n if (!(0))\n CCTK_VWarn(0, __LINE__, __FILE__, \"IOBasic\",\n \"outInfo_criterion out of bounds\");\n }\n\n return 1;\n}\n\n/*@@\n @routine IOBasic_InfoOutputGH\n @date June 31 1999\n @author Gabrielle Allen\n @desc\n Loops over all variables and prints output if requested\n @enddesc\n @calls IOBasic_CheckSteerableInfoParameters\n PrintHeader\n IOBasic_WriteInfo\n\n @var GH\n @vdesc Pointer to CCTK GH\n @vtype const cGH *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n the number of variables which were output at this iteration\n (or 0 if it wasn't time to output yet)\n @endreturndesc\n@@*/\nint IOBasic_InfoOutputGH(const cGH *GH) {\n int vindex, num_vars, retval;\n iobasic_reduction_t *reduction;\n iobasicGH *myGH;\n\n /* get the GH extensions for IOBasic */\n myGH = CCTK_GHExtension(GH, \"IOBasic\");\n\n /* check if steerable parameters changed */\n IOBasic_CheckSteerableInfoParameters(myGH);\n\n if (!TimeForOutput(GH))\n return 0;\n\n retval = 0;\n\n /* print header if neccessary */\n num_vars = CCTK_NumVars();\n if (myGH->info_reductions_changed) {\n PrintHeader(myGH, num_vars);\n }\n\n /* print the iteration/timestep information for all variables */\n if (USE_DECIMAL_NOTATION(GH->cctk_time)) {\n printf(\"%6d |%9.3f |\", GH->cctk_iteration, GH->cctk_time);\n } else {\n printf(\"%6d |%7.3e |\", GH->cctk_iteration, GH->cctk_time);\n }\n\n /* loop over all variables */\n for (vindex = 0; vindex < num_vars; vindex++) {\n /* check this variable should be output */\n if (myGH->info_reductions[vindex].num_reductions == 0) {\n continue;\n }\n\n /* check variable not already output this iteration */\n if (myGH->outInfo_last[vindex] != GH->cctk_iteration) {\n#ifdef IOBASIC_DEBUG\n printf(\"\\nIn IO OutputInfoGH\\n----------------\\n\");\n printf(\" Index = %d\\n\", vindex);\n printf(\" Variable = -%s-\\n\", CCTK_VarName (vindex);\n printf(\" Last output iteration was = %d\\n\", myGH->outInfo_last[vindex]);\n#endif\n\n /* get the data to output */\n if (IOBasic_WriteInfo (GH, vindex) == 0)\n {\n /* register variable as having info output this iteration */\n myGH->outInfo_last[vindex] = GH->cctk_iteration;\n retval++;\n }\n }\n\n /* finally print the stuff to screen */\n reduction = myGH->info_reductions[vindex].reductions;\n while (reduction) {\n PRINT_FORMATTED_REDUCTION_VALUE(reduction);\n reduction = reduction->next;\n }\n } /* end of loop over all variables */\n\n /* add the new line */\n putchar('\\n');\n fflush(stdout);\n\n return (retval);\n}\n\n/*@@\n @routine IOBasic_TimeForInfoOutput\n @date June 31 1999\n @author Gabrielle Allen\n @desc\n Decides if it is time to output a variable using info output\n @enddesc\n @calls IOBasic_CheckSteerableInfoParameters\n\n @var GH\n @vdesc Pointer to CCTK GH\n @vtype const cGH *\n @vio in\n @endvar\n @var vindex\n @vdesc index of variable to check for output\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n true/false (1 or 0) if this variable should be output or not\n @endreturndesc\n@@*/\nint IOBasic_TimeForInfoOutput(const cGH *GH, int vindex) {\n char *fullname;\n iobasicGH *myGH;\n\n /* get the GH extensions for IOBasic */\n myGH = CCTK_GHExtension(GH, \"IOBasic\");\n\n /* check if steerable parameters changed */\n IOBasic_CheckSteerableInfoParameters(myGH);\n\n if (myGH->info_reductions[vindex].num_reductions == 0) {\n return 0;\n }\n\n if (!TimeForOutput(GH))\n return 0;\n\n /* check if variable was not already output this iteration */\n if (myGH->outInfo_last[vindex] == GH->cctk_iteration) {\n fullname = CCTK_FullName(vindex);\n CCTK_VWarn(5, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Already done Info output for '%s' in current iteration \"\n \"(probably via triggers)\",\n fullname);\n free(fullname);\n return 0;\n }\n\n return 1;\n}\n\n/*@@\n @routine IOBasic_TriggerInfoOutput\n @date June 31 1999\n @author Gabrielle Allen\n @desc\n Triggers the output of a variable using IOBasic's info output\n @enddesc\n @calls IOBasic_WriteInfo\n\n @var GH\n @vdesc Pointer to CCTK GH\n @vtype const cGH *\n @vio in\n @endvar\n @var vindex\n @vdesc index of variable to output\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine IOBasic_WriteInfo\n @endreturndesc\n@@*/\nint IOBasic_TriggerInfoOutput(const cGH *GH, int vindex) {\n int retval;\n iobasicGH *myGH;\n\n /* get the GH extension for IOBasic */\n myGH = CCTK_GHExtension(GH, \"IOBasic\");\n\n#ifdef IOBASIC_DEBUG\n printf(\"\\nIn IO TriggerOutputInfo\\n---------------------\\n\");\n printf(\" Index = %d\\n\", vindex);\n printf (\" Variable = -%s-\\n\", CCTK_VarName (vindex);\n#endif\n\n /* get the data values to output */\n retval = IOBasic_WriteInfo (GH, vindex);\n\n if (retval == 0)\n {\n /* register variable as having Info output at this iteration */\n myGH->outInfo_last[vindex] = GH->cctk_iteration;\n }\n\n return (retval);\n}\n\n/*@@\n @routine IOBasic_CheckSteerableInfoParameters\n @date Tue 31 Jul 2001\n @author Thomas Radke\n @desc\n Re-evaluates 'IOBasic::outInfo_every' and/or 'IO::out_every'\n resp. to set myGH->outInfo_every to the frequency of info output.\n Re-evaluates 'IOBasic::outInfo_vars' and\n 'IOBasic::outInfo_reductions' and sets\n myGH->info_reductions_changed to true if one of them was changed.\n @enddesc\n @calls CCTK_ParameterQueryTimesSet\n\n @var myGH\n @vdesc Pointer to IOBasic's GH extension\n @vtype iobasicGH *\n @vio in\n @endvar\n@@*/\nvoid IOBasic_CheckSteerableInfoParameters(iobasicGH *myGH) {\n int vindex, out_old, times_set, update_reductions_list;\n CCTK_REAL outdt_old;\n iobasic_reduction_t *reduction, *next;\n static int outInfo_vars_lastset = -1;\n static int outInfo_reductions_lastset = -1;\n iobasic_parseinfo_t info;\n DECLARE_CCTK_PARAMETERS\n\n if (CCTK_EQUALS(outInfo_criterion, \"never\")) {\n return;\n } else if (CCTK_EQUALS(outInfo_criterion, \"iteration\")) {\n /* how often to output */\n out_old = myGH->outInfo_every;\n myGH->outInfo_every = outInfo_every >= 0 ? outInfo_every : out_every;\n\n /* report if frequency changed */\n if (myGH->outInfo_every != out_old && !CCTK_Equals(verbose, \"none\")) {\n if (myGH->outInfo_every > 0) {\n CCTK_VInfo(CCTK_THORNSTRING, \"Periodic info output every %d iterations\",\n myGH->outInfo_every);\n } else {\n CCTK_INFO(\"Periodic info output turned off\");\n }\n }\n\n /* return if there's nothing to do */\n if (myGH->outInfo_every <= 0) {\n return;\n }\n } else if (CCTK_EQUALS(outInfo_criterion, \"time\")) {\n /* how often to output */\n outdt_old = myGH->outInfo_dt;\n myGH->outInfo_dt = outInfo_dt >= 0 ? outInfo_dt : out_dt;\n\n /* report if frequency changed */\n if (myGH->outInfo_dt != outdt_old && !CCTK_Equals(verbose, \"none\")) {\n if (myGH->outInfo_dt >= 0) {\n CCTK_VInfo(CCTK_THORNSTRING, \"Periodic info output dt %g\",\n (double)myGH->outInfo_dt);\n } else {\n CCTK_INFO(\"Periodic info output turned off\");\n }\n }\n\n /* return if there's nothing to do */\n if (myGH->outInfo_dt < 0) {\n return;\n }\n } else {\n if (!(0))\n CCTK_VWarn(0, __LINE__, __FILE__, \"IOBasic\",\n \"outInfo_criterion out of bounds\");\n }\n\n /* check if the 'outInfo_reductions' parameter if it was changed */\n times_set =\n CCTK_ParameterQueryTimesSet(\"outInfo_reductions\", CCTK_THORNSTRING);\n update_reductions_list = times_set != outInfo_reductions_lastset;\n outInfo_reductions_lastset = times_set;\n\n /* check if the 'outInfo_vars' parameter if it was changed */\n times_set = CCTK_ParameterQueryTimesSet(\"outInfo_vars\", CCTK_THORNSTRING);\n update_reductions_list |= times_set != outInfo_vars_lastset;\n outInfo_vars_lastset = times_set;\n\n if (update_reductions_list) {\n /* free old info output lists ... */\n for (vindex = CCTK_NumVars() - 1; vindex >= 0; vindex--) {\n if (myGH->info_reductions[vindex].num_reductions > 0) {\n myGH->info_reductions[vindex].num_reductions = 0;\n reduction = myGH->info_reductions[vindex].reductions;\n while (reduction) {\n next = reduction->next;\n free(reduction->name);\n free(reduction);\n reduction = next;\n }\n }\n }\n\n /* ... and create new ones */\n info.reduction_list = myGH->info_reductions;\n info.reductions_string = outInfo_reductions;\n if (CCTK_TraverseString(outInfo_vars, IOBasic_AssignReductionList, &info,\n CCTK_GROUP_OR_VAR) < 0) {\n CCTK_WARN(myGH->stop_on_parse_errors ? 0 : 1,\n \"error while parsing parameter 'IOBasic::outInfo_vars'\");\n }\n\n myGH->info_reductions_changed = 1;\n }\n}\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\n/*@@\n @routine PrintHeader\n @date Tue 31 Jul 2001\n @author Thomas Radke\n @desc\n It re-evaluates the info reduction lists of all CCTK variables\n and prints the header for the info output table.\n @enddesc\n @calls CCTK_TraverseString\n\n @var myGH\n @vdesc Pointer to IOBasic's GH extension\n @vtype iobasicGH *\n @vio in\n @endvar\n @var num_vars\n @vdesc total number of CCTK variables\n @vtype int\n @vio in\n @endvar\n@@*/\nstatic void PrintHeader(iobasicGH *myGH, int num_vars) {\n DECLARE_CCTK_PARAMETERS\n int i, num_columns, vindex;\n char *fullname, *msg, *oldmsg;\n iobasic_reduction_t *reduction;\n\n /* count number of info values to output */\n num_columns = 0;\n msg = NULL;\n for (vindex = 0; vindex < num_vars; vindex++) {\n num_columns += myGH->info_reductions[vindex].num_reductions;\n\n if (myGH->info_reductions[vindex].num_reductions > 0 &&\n !CCTK_Equals(verbose, \"none\")) {\n fullname = CCTK_FullName(vindex);\n if (!msg) {\n Util_asprintf(&msg, \"Periodic info output requested for '%s'\",\n fullname);\n } else {\n oldmsg = msg;\n Util_asprintf(&msg, \"%s, '%s'\", oldmsg, fullname);\n free(oldmsg);\n }\n free(fullname);\n }\n }\n if (msg) {\n CCTK_INFO(msg);\n free(msg);\n }\n\n /* draw a horizontal delimiter line */\n printf(\"-------------------\");\n for (i = 0; i < num_columns; i++) {\n printf(\"---------------\");\n }\n putchar('\\n');\n\n /* the first header line displays the iteration number (first column)\n and the full names of the variables to output (third column ff.) */\n printf(\" it | |\");\n if (num_columns > 0) {\n for (vindex = 0; vindex < num_vars; vindex++) {\n i = myGH->info_reductions[vindex].num_reductions;\n if (i > 0) {\n fullname = CCTK_FullName(vindex);\n if (strlen(fullname) > (unsigned int)15 * i - 3) {\n printf(\" *%s |\", fullname + strlen(fullname) - (15 * i - 4));\n } else {\n printf(\" %-*s |\", 15 * i - 3, fullname);\n }\n free(fullname);\n }\n }\n }\n putchar('\\n');\n\n /* the second header line displays the physical time (second column)\n and the names of the reduction operators to apply (third column ff.) */\n printf(\" | t \");\n for (vindex = 0; vindex < num_vars; vindex++) {\n if (myGH->info_reductions[vindex].num_reductions > 0) {\n reduction = myGH->info_reductions[vindex].reductions;\n while (reduction) {\n printf(\"| %-12s \", reduction->name);\n reduction = reduction->next;\n }\n }\n }\n printf(\"|\\n\");\n\n /* finally draw another horizontal delimiter line */\n printf(\"-------------------\");\n for (i = 0; i < num_columns; i++) {\n printf(\"---------------\");\n }\n putchar('\\n');\n fflush(stdout);\n\n myGH->info_reductions_changed = 0;\n}\n", "WriteInfo.c": "/*@@\n @file WriteInfo.c\n @date June 31 1999\n @author Gabrielle Allen, Paul Walker, Thomas Radke\n @desc\n Gets the data for IOBasic's info output.\n @enddesc\n @version $Id: /cactusdevcvs/CactusBase/IOBasic/src/OutputInfo.c,v 1.24 2001\n@@*/\n\n#include \n\n#include \"cctk.h\"\n#include \"iobasicGH.h\"\n\n/* the rcs ID and its dummy function to use it */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusBase_IOBasic_WriteInfo_c)\n\n/*@@\n @routine IOBasic_WriteInfo\n @date Tue 31 July 2001\n @author Thomas Radke\n @desc\n Gets the data values to output for a given CCTK variable.\n For CCTK_SCALAR variables, their value is taken,\n for CCTK_GF and CCTK_ARRAY variables the appropriate\n reduction operations are performed and their results taken.\n @enddesc\n\n @calls CCTK_VarDataPtrI\n CCTK_ReduceGridArrays\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var vindex\n @vdesc CCTK index of the variable to output\n @vtype int\n @vio in\n @endvar\n @var alias\n @vdesc alias name to use for building the output filename\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n 0 for success, or
\n -1 if variable has no storage assigned\n @endreturndesc\n@@*/\nint IOBasic_WriteInfo(const cGH *GH, int vindex) {\n int vtype;\n char *fullname;\n iobasicGH *myGH;\n void *ptr;\n iobasic_reduction_t *reduction;\n\n CCTK_INT input_array[1];\n CCTK_INT output_array_type_codes[1];\n CCTK_REAL output_value;\n void *reduction_value[1];\n\n input_array[0] = vindex;\n output_array_type_codes[0] = CCTK_VARIABLE_REAL;\n reduction_value[0] = &output_value;\n\n myGH = CCTK_GHExtension(GH, \"IOBasic\");\n reduction = myGH->info_reductions[vindex].reductions;\n\n /* first, check if variable has storage assigned */\n if (!CCTK_QueryGroupStorageI(GH, CCTK_GroupIndexFromVarI(vindex))) {\n fullname = CCTK_FullName(vindex);\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"IOBasic_WriteInfo: No info output for '%s' (no storage)\",\n fullname);\n free(fullname);\n\n /* invalidate data buffer for this variable */\n while (reduction) {\n reduction->is_valid = 0;\n reduction = reduction->next;\n }\n return (-1);\n }\n\n /* CCTK scalars are printed by their value, cast into a C double */\n if (CCTK_GroupTypeFromVarI(vindex) == CCTK_SCALAR) {\n reduction->is_valid = 1;\n\n /* get the variable's data type and data pointer */\n ptr = CCTK_VarDataPtrI(GH, 0, vindex);\n vtype = CCTK_VarTypeI(vindex);\n switch (vtype) {\n case CCTK_VARIABLE_BYTE:\n reduction->value = (double)*(CCTK_BYTE *)ptr;\n break;\n case CCTK_VARIABLE_INT:\n reduction->value = (double)*(CCTK_INT *)ptr;\n break;\n case CCTK_VARIABLE_REAL:\n reduction->value = (double)*(CCTK_REAL *)ptr;\n break;\n case CCTK_VARIABLE_COMPLEX:\n reduction->value = (double)((CCTK_REAL *)ptr)[0];\n reduction->next->value = (double)((CCTK_REAL *)ptr)[1];\n reduction->next->is_valid = 1;\n break;\n#ifdef HAVE_CCTK_INT1\n case CCTK_VARIABLE_INT1:\n reduction->value = (double)*(CCTK_INT1 *)ptr;\n break;\n#endif\n#ifdef HAVE_CCTK_INT2\n case CCTK_VARIABLE_INT2:\n reduction->value = (double)*(CCTK_INT2 *)ptr;\n break;\n#endif\n#ifdef HAVE_CCTK_INT4\n case CCTK_VARIABLE_INT4:\n reduction->value = (double)*(CCTK_INT4 *)ptr;\n break;\n#endif\n#ifdef HAVE_CCTK_INT8\n case CCTK_VARIABLE_INT8:\n reduction->value = (double)*(CCTK_INT8 *)ptr;\n break;\n#endif\n#ifdef HAVE_CCTK_INT16\n case CCTK_VARIABLE_INT16:\n reduction->value = (double)*(CCTK_INT16 *)ptr;\n break;\n#endif\n#ifdef HAVE_CCTK_REAL4\n case CCTK_VARIABLE_REAL4:\n reduction->value = (double)*(CCTK_REAL4 *)ptr;\n break;\n case CCTK_VARIABLE_COMPLEX8:\n reduction->value = (double)((CCTK_REAL4 *)ptr)[0];\n reduction->next->value = (double)((CCTK_REAL4 *)ptr)[1];\n reduction->next->is_valid = 1;\n break;\n#endif\n#ifdef HAVE_CCTK_REAL8\n case CCTK_VARIABLE_REAL8:\n reduction->value = (double)*(CCTK_REAL8 *)ptr;\n break;\n case CCTK_VARIABLE_COMPLEX16:\n reduction->value = (double)((CCTK_REAL8 *)ptr)[0];\n reduction->next->value = (double)((CCTK_REAL8 *)ptr)[1];\n reduction->next->is_valid = 1;\n break;\n#endif\n#ifdef HAVE_CCTK_REAL16\n case CCTK_VARIABLE_REAL16:\n reduction->value = (double)*(CCTK_REAL16 *)ptr;\n break;\n case CCTK_VARIABLE_COMPLEX32:\n reduction->value = (double)((CCTK_REAL16 *)ptr)[0];\n reduction->next->value = (double)((CCTK_REAL16 *)ptr)[1];\n reduction->next->is_valid = 1;\n break;\n#endif\n default:\n CCTK_WARN(3, \"IOBasic_WriteInfo: Unsupported data type\");\n reduction->is_valid = 0;\n break;\n }\n } else {\n /* for CCTK_GF and CCTK_ARRAY variables: loop over all reductions */\n while (reduction) {\n reduction->is_valid =\n CCTK_ReduceGridArrays(GH, -1, reduction->handle, -1, 1, input_array,\n 1, output_array_type_codes,\n reduction_value) == 0;\n reduction->value = output_value;\n\n if (!reduction->is_valid) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"IOBasic_WriteInfo: Internal error in reduction '%s'\",\n reduction->name);\n }\n\n reduction = reduction->next;\n }\n }\n\n return (0);\n}\n", "Startup.c": "/*@@\n @file Startup.c\n @date Friday 18th September 1999\n @author Gabrielle Allen\n @desc\n Startup routines for IOBasic.\n @enddesc\n @version $Id$\n@@*/\n\n#include \n#include \n#include \n#include \n\n#include \"cctk.h\"\n#include \"cctk_Arguments.h\"\n#include \"cctk_Parameters.h\"\n#include \"util_Table.h\"\n#include \"CactusBase/IOUtil/src/ioutil_Utils.h\"\n#include \"iobasicGH.h\"\n\nstatic const char *rcsid = \"$Header$\";\n\nCCTK_FILEVERSION(CactusBase_IOBasic_Startup_c)\n\n/********************************************************************\n ******************** External Routines ************************\n ********************************************************************/\nint IOBasic_Startup(void);\nvoid IOBasic_Init(CCTK_ARGUMENTS);\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\nstatic void *IOBasic_SetupGH(tFleshConfig *config, int conv_level, cGH *GH);\n\n/*@@\n @routine IOBasic_Startup\n @date Friday 18th September 1999\n @author Gabrielle Allen\n @desc\n The startup registration routine for IOBasic.\n Registers the GH extensions needed for IOBasic\n along with its setup routine.\n @enddesc\n @calls CCTK_RegisterGHExtensionSetupGH\n@@*/\nint IOBasic_Startup(void) {\n if (CCTK_GHExtensionHandle(\"IO\") < 0) {\n CCTK_WARN(1, \"Thorn IOUtil was not activated. \"\n \"No IOBasic I/O methods will be enabled.\");\n return 0;\n }\n\n CCTK_RegisterGHExtensionSetupGH(CCTK_RegisterGHExtension(\"IOBasic\"),\n IOBasic_SetupGH);\n\n return 0;\n}\n\n/*@@\n @routine IOBasic_Init\n @date Tue 30 Dec 2003\n @author Erik Schnetter\n @desc\n Initialise the next_*_output_time variables.\n @enddesc\n@@*/\nvoid IOBasic_Init(CCTK_ARGUMENTS) {\n DECLARE_CCTK_ARGUMENTS_IOBasic_Init;\n *next_info_output_time = cctk_time;\n *next_scalar_output_time = cctk_time;\n}\n\n/****************************************************************************/\n/* local routines */\n/****************************************************************************/\n/*@@\n @routine IOBasic_SetupGH\n @date Sat Feb 6 1999\n @author Gabrielle Allen\n @desc\n Allocates and sets up IOBasic's GH extension structure\n @enddesc\n\n @calls CCTK_RegisterIOMethod\n CCTK_RegisterIOMethodOutputGH\n CCTK_RegisterIOMethodOutputVarAs\n CCTK_RegisterIOMethodTimeToOutput\n CCTK_RegisterIOMethodTriggerOutput\n\n @var config\n @vdesc the CCTK configuration as provided by the flesh\n @vtype tFleshConfig *\n @vio unused\n @endvar\n @var conv_level\n @vdesc the convergence level\n @vtype int\n @vio unused\n @endvar\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype cGH *\n @vio in\n @endvar\n\n @returntype void *\n @returndesc\n pointer to the allocated GH extension structure\n @endreturndesc\n@@*/\nstatic void *IOBasic_SetupGH(tFleshConfig *config, int conv_level, cGH *GH) {\n int i;\n iobasicGH *myGH;\n const char *my_out_dir;\n DECLARE_CCTK_PARAMETERS\n\n /* suppress compiler warnings about unused parameters */\n (void)(config + 0);\n (void)(conv_level + 0);\n (void)(GH + 0);\n\n /* allocate the GH extension and its components */\n myGH = malloc(sizeof(iobasicGH));\n if (!myGH) {\n return (NULL);\n }\n\n /* Register the IOBasic routines as output methods */\n i = CCTK_RegisterIOMethod(\"Scalar\");\n CCTK_RegisterIOMethodOutputGH(i, IOBasic_ScalarOutputGH);\n CCTK_RegisterIOMethodOutputVarAs(i, IOBasic_OutputVarAs);\n CCTK_RegisterIOMethodTimeToOutput(i, IOBasic_TimeForScalarOutput);\n CCTK_RegisterIOMethodTriggerOutput(i, IOBasic_TriggerScalarOutput);\n\n i = CCTK_RegisterIOMethod(\"Info\");\n CCTK_RegisterIOMethodOutputGH(i, IOBasic_InfoOutputGH);\n CCTK_RegisterIOMethodTimeToOutput(i, IOBasic_TimeForInfoOutput);\n CCTK_RegisterIOMethodTriggerOutput(i, IOBasic_TriggerInfoOutput);\n\n i = CCTK_NumVars();\n\n myGH->info_reductions = calloc(2 * i, sizeof(iobasic_reductionlist_t));\n myGH->scalar_reductions = myGH->info_reductions + i;\n myGH->outInfo_last = malloc(2 * i * sizeof(int));\n myGH->outScalar_last = myGH->outInfo_last + i;\n\n /* initialize counters for how often to do output with a value different\n to the current parameter values\n this forces info output about periodic output */\n myGH->outInfo_every = outInfo_every >= 0 ? outInfo_every : out_every;\n myGH->outScalar_every = outScalar_every >= 0 ? outScalar_every : out_every;\n myGH->outInfo_dt = outInfo_dt >= 0 ? outInfo_dt : out_dt;\n myGH->outScalar_dt = outScalar_dt >= 0 ? outScalar_dt : out_dt;\n\n memset(myGH->outInfo_last, -1, 2 * i * sizeof(int));\n\n myGH->filenameListScalar = NULL;\n\n myGH->stop_on_parse_errors = strict_io_parameter_check;\n if (!CCTK_Equals(verbose, \"none\")) {\n CCTK_INFO(\"I/O Method 'Scalar' registered: output of scalar quantities \"\n \"(grid scalars, reductions) to ASCII files\");\n }\n IOBasic_CheckSteerableInfoParameters(myGH);\n if (!CCTK_Equals(verbose, \"none\")) {\n CCTK_INFO(\"I/O Method 'Info' registered: output of scalar quantities \"\n \"(grid scalars, reductions) to screen\");\n }\n IOBasic_CheckSteerableInfoParameters(myGH);\n myGH->stop_on_parse_errors = 0;\n\n /* get the name of IOBasic's output directory */\n my_out_dir = out_dir;\n if (*my_out_dir == 0) {\n my_out_dir = io_out_dir;\n }\n\n /* skip the directory pathname if output goes into current directory */\n if (strcmp(my_out_dir, \".\")) {\n i = strlen(my_out_dir);\n myGH->out_dir = malloc(i + 2);\n strcpy(myGH->out_dir, my_out_dir);\n myGH->out_dir[i] = '/';\n myGH->out_dir[i + 1] = 0;\n } else {\n myGH->out_dir = strdup(\"\");\n }\n\n /* create the output dir */\n if (*myGH->out_dir && CCTK_MyProc(GH) == 0) {\n i = IOUtil_CreateDirectory(GH, myGH->out_dir, 0, 0);\n if (i < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"IOBasic_SetupGH: Couldn't create Scalar output directory \"\n \"'%s'\",\n myGH->out_dir);\n } else if (i >= 0 && CCTK_Equals(verbose, \"full\")) {\n CCTK_VInfo(CCTK_THORNSTRING, \"Scalar: Output to directory '%s'\",\n myGH->out_dir);\n }\n }\n\n return (myGH);\n}\n\n/*@@\n @routine IOBasic_AssignReductionList\n @date Tue 31 Jul 2001\n @author Thomas Radke\n @desc\n Callback routine called by CCTK_TraverseString() to set the\n reduction list for a given variable.\n For CCTK_GF and CCTK_ARRAY variables, it builds a chained list\n of reduction operators according to the settings of 'optstring'\n or the 'IOBasic::out{Info|Scalar}_reductions' parameter.\n @enddesc\n @calls CCTK_GroupTypeFromVarI\n CCTK_LocalArrayReductionHandle\n\n @var vindex\n @vdesc index of the variable to set info output\n @vtype int\n @vio in\n @endvar\n @var optstring\n @vdesc option string for this variable\n @vtype const char *\n @vio in\n @endvar\n @var arg\n @vdesc user-supplied argument to callback routine\n @vtype void *\n @vio in\n @endvar\n@@*/\nvoid IOBasic_AssignReductionList(int vindex, const char *optstring, void *arg) {\n int table, iterator, reduction_handle;\n char key[128];\n CCTK_INT type, nelems;\n const char *string_start, *string_end;\n char *fullname, *reduction_op, *reduction_op_list;\n iobasic_reductionlist_t *list;\n iobasic_reduction_t **new_reduction;\n const iobasic_parseinfo_t *info;\n\n info = (const iobasic_parseinfo_t *)arg;\n list = info->reduction_list + vindex;\n\n if (CCTK_GroupTypeFromVarI(vindex) == CCTK_SCALAR) {\n if (optstring) {\n CCTK_VWarn(5, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"option list '%s' for variable '%s' ignored\", optstring,\n CCTK_VarName(vindex));\n }\n\n list->reductions = malloc(sizeof(iobasic_reduction_t));\n if (strncmp(CCTK_VarTypeName(CCTK_VarTypeI(vindex)),\n \"CCTK_VARIABLE_COMPLEX\", 21)) {\n list->num_reductions = 1;\n list->reductions->name = strdup(\"scalar value\");\n list->reductions->next = NULL;\n } else {\n list->num_reductions = 2;\n list->reductions->name = strdup(\"real part\");\n list->reductions->next = malloc(sizeof(iobasic_reduction_t));\n list->reductions->next->name = strdup(\"imag part\");\n list->reductions->next->next = NULL;\n }\n\n return;\n }\n\n /* initialize to empty list */\n list->num_reductions = 0;\n list->reductions = NULL;\n\n if (optstring) {\n reduction_op_list = NULL;\n fullname = CCTK_FullName(vindex);\n\n table = Util_TableCreateFromString(optstring);\n if (table >= 0) {\n if (Util_TableQueryValueInfo(table, &type, &nelems, \"reductions\") > 0) {\n if (type == CCTK_VARIABLE_CHAR && nelems > 0) {\n reduction_op_list = malloc(nelems + 1);\n Util_TableGetString(table, nelems + 1, reduction_op_list,\n \"reductions\");\n } else {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Key 'reductions' in option string '%s' for variable \"\n \"'%s' must have a non-empty string value\",\n optstring, fullname);\n }\n Util_TableDeleteKey(table, \"reductions\");\n }\n\n /* warn about other options */\n iterator = Util_TableItCreate(table);\n for (iterator = Util_TableItCreate(table);\n Util_TableItQueryIsNonNull(iterator) > 0 &&\n Util_TableItQueryKeyValueInfo(iterator, sizeof(key), key, 0, 0) >\n 0;\n Util_TableItAdvance(iterator)) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Option with key '%s' in option string '%s' for variable \"\n \"'%s' not recognized\",\n key, optstring, fullname);\n }\n Util_TableItDestroy(iterator);\n\n Util_TableDestroy(table);\n } else {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Option string '%s' for variable '%s' couldn't be parsed\",\n optstring, fullname);\n }\n free(fullname);\n\n if (!reduction_op_list) {\n reduction_op_list = strdup(info->reductions_string);\n }\n } else {\n reduction_op_list = strdup(info->reductions_string);\n }\n\n /* now loop over all reduction operators */\n string_start = reduction_op_list;\n reduction_op = malloc(strlen(string_start) + 1);\n while (string_start && *string_start) {\n /* skip leading spaces */\n while (isspace((int)*string_start)) {\n string_start++;\n }\n if (!*string_start) {\n break;\n }\n\n /* advance to end of the operator string */\n string_end = string_start + 1;\n while (*string_end && !isspace((int)*string_end)) {\n string_end++;\n }\n\n /* copy the operator string */\n strncpy(reduction_op, string_start, string_end - string_start);\n reduction_op[string_end - string_start] = 0;\n string_start = string_end;\n\n /* get the reduction handle from the reduction operator */\n reduction_handle = CCTK_LocalArrayReductionHandle(reduction_op);\n if (reduction_handle < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Unknown reduction operator '%s'. Maybe you forgot to \"\n \"activate thorn LocalReduce?\",\n reduction_op);\n continue;\n }\n\n /* add new reduction to end of list */\n new_reduction = &list->reductions;\n while (*new_reduction) {\n if (strcmp((*new_reduction)->name, reduction_op) == 0) {\n new_reduction = NULL;\n break;\n }\n new_reduction = &((*new_reduction)->next);\n }\n if (new_reduction == NULL) {\n CCTK_VWarn(3, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"IOBasic_AssignReductionList: Duplicate reduction operator \"\n \"'%s' will be ignored\",\n reduction_op);\n continue;\n }\n\n *new_reduction = malloc(sizeof(**new_reduction));\n (*new_reduction)->handle = reduction_handle;\n (*new_reduction)->name = strdup(reduction_op);\n (*new_reduction)->next = NULL;\n list->num_reductions++;\n }\n\n free(reduction_op_list);\n free(reduction_op);\n}\n" }, "test": { "test.ccl": "EXTENSIONS xg tl asc gnuplot\n" }, "doc": { "documentation.tex": "\\documentclass{article}\n\n% Use the Cactus ThornGuide style file\n% (Automatically used from Cactus distribution, if you have a \n% thorn without the Cactus Flesh download this from the Cactus\n% homepage at www.cactuscode.org)\n\\usepackage{../../../../doc/latex/cactus}\n\n\\begin{document}\n\n\\title{IOBasic}\n\\author{Gabrielle Allen \\\\ Thomas Radke}\n\\date{$ $Date$ $}\n\n\\maketitle\n\n% Do not delete next line\n% START CACTUS THORNGUIDE\n\\begin{abstract}\nThorn {\\bf IOBasic} provides I/O methods for outputting scalar values in\nASCII format into files and for printing them as runtime information to screen.\n\\end{abstract}\n\n\n\\section{Purpose}\nThorn {\\bf IOBasic} registers 2 I/O methods with the I/O interface in the flesh\nwhich both output the same following information:\n%\n\\begin{itemize}\n \\item for CCTK\\_SCALAR variables, the value of the scalar versus time\n \\item for CCTK\\_GF and CCTK\\_ARRAY variables, the values of global reduction\n operations (eg. minimum, maximum, L1, and L2 norm) versus time\n\\end{itemize}\n%\nThe I/O methods differ in the destination the output is written to:\n\\begin{itemize}\n \\item{\\tt Scalar}\\\\\n This method outputs the information into ASCII files named {\\tt \".\\{asc|xg\\}\"} (for CCTK\\_SCALAR variables) and {\\tt \"\\_.\\{asc|xg\\}\"}\n (for CCTK\\_GF and CCTK\\_ARRAY variables where {\\tt reduction} would stand\n for the type of reduction value that is output).\\\\\n The output data can be plotted by using either {\\it xgraph} (for {\\tt \"*.xg\"} files) or\n {\\it gnuplot} (for {\\tt \"*.asc\"} files). The output style can be selected via parameter settings.\n \\item {\\tt Info}\\\\\n This method prints the data as runtime information to {\\it stdout}.\\\\\n The output occurs as a table with columns containing the current iteration\n number, the physical time at this iteration, and more columns for\n scalar/reduction values of each variable to be output.\\\\\n\\end{itemize}\n%\n%\n\\section{{\\bf IOBasic} Parameters}\n%\nParameters to control the {\\tt Scalar} I/O method are:\n\\begin{itemize}\n \\item {\\tt IOBasic::outScalar\\_criterion} (steerable)\\\\\n The criterion that decides when to {\\tt Scalar} output. If\n this parameter is set in the parameter file, it will override\n the setting of the shared {\\tt IO::out\\_criterion} parameter.\n \\item {\\tt IOBasic::outScalar\\_every} (steerable)\\\\\n How often, in terms of iterations, to do {\\tt Scalar} output.\n If this parameter is set in the\n parameter file, it will override the setting of the shared\n {\\tt IO::out\\_every} parameter.\n \\item {\\tt IOBasic::outScalar\\_dt} (steerable)\\\\\n How often, in terms of simulation time, to do {\\tt Scalar}\n output. If this parameter is set in the parameter file, it\n will override the setting of the shared {\\tt IO::out\\_dt}\n parameter.\n \\item {\\tt IOBasic::out\\_dir}\\\\\n The directory in which to place the {\\tt Scalar} ASCII output files.\n If the directory doesn't exist at startup it will be created.\\\\\n If this paraeter is set to an empty string {\\tt Scalar} output will go\n to the standard output directory as specified in {\\tt IO::out\\_dir}.\n \\item {\\tt IOBasic::outScalar\\_style}\\\\\n How to start comments in the {\\tt Scalar} ASCII output files.\\\\\n Possible choices for this keywork parameter are {\\it xgraph} and\n {\\it gnuplot}.\n \\item {\\tt IOBasic::out\\_format} (steerable)\\\\\n The output format for floating-point numbers in {\\tt Scalar} output.\\\\\n This parameter conforms to the format modifier of the C library routine\n {\\it fprintf(3)}. You can set the format for outputting floating-point\n numbers (fixed or exponential) as well as their precision (number of\n digits).\n \\item {\\tt IOBasic::outScalar\\_vars} (steerable)\\\\\n The list of variables to output into individual ASCII files.\\\\\n The variables must be given by their fully qualified variable or group\n name. The special keyword {\\it all} requests {\\tt Scalar}\n output for all\n variables. Multiple variables must be separated by spaces.\n For CCTK\\_GF and CCTK\\_ARRAY variables, an option string can\n be appended \n in curly braces to the name of the variable. The only option\n supported so far is an individual list of reductions for that variable\n which would take precedence over the default reduction operations to\n perform.\n \\item {\\tt IOBasic::outScalar\\_reductions} (steerable)\\\\\n The list of global reduction operations to perform on\n CCTK\\_GF and CCTK\\_ARRAY variables for {\\tt Scalar} output.\n This setting can be overridden for individual variables using an\n option string.\\\\\n Multiple reduction names must be separated by spaces.\n\\end{itemize}\n%\n%\nParameters to control the {\\tt Info} I/O method are:\n\\begin{itemize}\n \\item {\\tt IOBasic::outInfo\\_criterion} (steerable)\\\\\n The criterion that decides when to {\\tt Info} output. If\n this parameter is set in the parameter file, it will override\n the setting of the shared {\\tt IO::out\\_criterion} parameter.\n \\item {\\tt IOBasic::outInfo\\_every} (steerable)\\\\\n How often, in terms of iterations, to do {\\tt Info} output.\n If this parameter is set in the\n parameter file, it will override the setting of the shared\n {\\tt IO::out\\_every} parameter.\n \\item {\\tt IOBasic::outInfo\\_dt} (steerable)\\\\\n How often, in terms of simulation time, to do {\\tt Info}\n output. If this parameter is set in the parameter file, it\n will override the setting of the shared {\\tt IO::out\\_dt}\n parameter.\n \\item {\\tt IOBasic::outInfo\\_vars} (steerable)\\\\\n The list of variables to output to screen.\\\\\n The variables must be given by their fully qualified variable or group\n name. The special keyword {\\it all} requests {\\tt Info} output for all\n variables. Multiple variables must be separated by spaces.\\\\\n For CCTK\\_GF and CCTK\\_ARRAY variables, an option string can\n be appended \n in curly braces to the name of the variable. The only option\n supported so far is an individual list of reductions for that variable\n which would take precedence over the default reduction operations to\n perform.\n \\item {\\tt IOBasic::outInfo\\_reductions} (steerable)\\\\\n The default list of global reduction operations to perform on\n CCTK\\_GF and CCTK\\_ARRAY variables. This setting can be overridden\n for individual variables using an option string.\\\\\n Multiple reduction names must be separated by spaces.\n\\end{itemize}\nAll of the above parameters marked as steerable can be changed at runtime.\n%\n%\n\\section{Examples}\n%\n\\subsection {Example for {\\tt Info} Output}\n%\nThe following parameter settings request info output for variables {\\tt\ngrid::r, wavetoy::phi} (both are CCTK grid functions) and {\\tt\nmythorn::complex}\n(a complex CCTK scalar) at every other iteration.\n\nThe minimum and maximum of {\\tt grid::r} is printed according to the list\nof default reductions for info output (parameter {\\tt\nIOBasic::outInfo\\_reductions}). This list is overridden for {\\tt\nwavetoy::phi} where only the L2 norm\nis output as specified in the option string for this variable. You can also\nadd other reduction operators within the $\\{\\}$ braces.\n\nFor the scalar variable {\\tt mythorn::complex} both the real and\nimaginary part are printed.\n\\begin{verbatim}\n IOBasic::outInfo_every = 2\n IOBasic::outInfo_vars = \"grid::r\n wavetoy::phi{reductions = 'norm2'}\n mythorn::complex\"\n IOBasic::outInfo_reductions = \"minimum maximum\"\n\\end{verbatim}\nThe resulting screen output would look like this:\n\\begin{verbatim}\n---------------------------------------------------------------------------------------------\n it | | GRID::r | WAVETOY::phi | MYTHORN::complex |\n | t | minimum | maximum | norm2 | real part | imag part |\n---------------------------------------------------------------------------------------------\n 0 | 0.000 | 0.02986294 | 0.86602540 | 0.04217014 | 6.90359593 | 0.00000000 |\n 2 | 0.034 | 0.02986294 | 0.86602540 | 0.00934749 | 6.90359593 | 0.00000000 |\n 4 | 0.069 | 0.02986294 | 0.86602540 | 0.02989811 | 6.90359593 | 0.00000000 |\n 6 | 0.103 | 0.02986294 | 0.86602540 | 0.05899959 | 6.90359593 | 0.00000000 |\n 8 | 0.138 | 0.02986294 | 0.86602540 | 0.07351147 | 6.90359593 | 0.00000000 |\n 10 | 0.172 | 0.02986294 | 0.86602540 | 0.07781795 | 6.90359593 | 0.00000000 |\n\\end{verbatim}\n%\n\\subsection {Example for {\\tt Scalar} Output}\n%\nThe following parameter settings request scalar output for all grid function\nvariables in the group {\\tt grid::coordinates} and for the scalar variable\n{\\tt grid::coarse\\_dx}.\\\\\nOutput occurs every 10th iteration. {\\tt gnuplot} output style is selected\nfor the ASCII files which are placed into a subdirectory {\\tt scalar\\_output}.\nThe minimum and maximum of {\\tt grid::r} is printed according to the list\nof default reductions for scalar output (parameter {\\tt\nIOBasic::outScalar\\_reductions}). This list is overridden for {\\tt\nwavetoy::phi} where only the L1 norm\nis output as specified in the option string for this variable. You can also\nadd other reduction operators within the $\\{\\}$ braces.\n\n\\begin{verbatim}\n IOBasic::outScalar_every = 10\n IOBasic::outScalar_vars = \"grid::coordinates grid::coarse_dx wavetoy::phi{reductions = 'norm1'}\"\n IOBasic::outScalar_reductions = \"minimum maximum\"\n IOBasic::outScalar_style = \"gnuplot\"\n IOBasic::out_dir = \"scalar_output\"\n\\end{verbatim}\nThis would create the following ASCII files:\n\\begin{verbatim}\n ~/Cactus/par> ls scalar_output\n coarse_dx.asc r_minimum.asc x_minimum.asc y_minimum.asc z_minimum.asc\n r_maximum.asc x_maximum.asc y_maximum.asc z_maximum.asc phi_norm1.asc\n\\end{verbatim}\n%\n%\n\\section{Comments}\n%\n{\\bf Possible Reduction Operations}\\\\\n%\nIn order to get output of reduction values for {\\tt CCTK\\_GF} and {\\tt\nCCTK\\_ARRAY} variables you need to activate a thorn which provides\nreduction operators (eg. thorn {\\tt PUGHReduce} in the {\\tt CactusPUGH}\narrangement). For a list of possible reduction operations please refer to\nthe documention of this reduction thorn.\\\\[3ex]\n%\n{\\bf Getting Output from {\\bf IOBasic}'s I/O Mehtods}\\\\\n%\nYou obtain output by an I/O method by either\n%\n\\begin{itemize}\n \\item setting the appropriate I/O parameters\n \\item calling one of the routines of the I/O function interface\n provided by the flesh\n\\end{itemize}\n%\nFor a description of basic I/O parameters and the I/O function interface to\ninvoke I/O methods by application thorns please see the documentation of thorn\n{\\tt IOUtil} and the flesh.\\\\[3ex]\n%\n%\n{\\bf Building Cactus configurations with {\\bf IOBasic}}\\\\\n%\nSince {\\bf IOBasic} uses parameters from {\\tt IOUtil} it also needs this I/O\nhelper thorn be compiled into Cactus and activated at runtime in the\n{\\tt ActiveThorns} parameter in your parameter file.\n\n% Do not delete next line\n% END CACTUS THORNGUIDE\n\n\\end{document}\n" } }