File size: 28,676 Bytes
0950351
 
 
 
 
10a2580
0950351
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
  "thorn_name": "CactusExamples/SampleIO",
  "url": "https://bitbucket.org/cactuscode/cactusexamples.git",
  "configuration": "# Configuration definition for thorn SampleIO\n# $Header$\n\n# names of the capabilities that this thorn requires\nRequires IOUtil\n",
  "interface": "# Interface definition for thorn SampleIO\n# $Header$\n\n# name of implementation this thorn provides\nImplements: SampleIO\nInherits:   IO\n\n\n# names of alias functions this thorn is using\nCCTK_INT FUNCTION \\\n  Hyperslab_Get (CCTK_POINTER_TO_CONST IN cctkGH, \\\n                 CCTK_INT IN mapping_handle, \\\n                 CCTK_INT IN proc, \\\n                 CCTK_INT IN vindex, \\\n                 CCTK_INT IN timelevel, \\\n                 CCTK_INT IN hdatatype, \\\n                 CCTK_POINTER IN hdata)\n\nCCTK_INT FUNCTION \\\n  Hyperslab_GlobalMappingByIndex (CCTK_POINTER_TO_CONST IN cctkGH, \\\n                                  CCTK_INT IN vindex, \\\n                                  CCTK_INT IN hdim, \\\n                                  CCTK_INT ARRAY IN direction, \\\n                                  CCTK_INT ARRAY IN origin, \\\n                                  CCTK_INT ARRAY IN extent, \\\n                                  CCTK_INT ARRAY IN downsample, \\\n                                  CCTK_INT IN table_handle, \\\n                                  CCTK_INT IN CCTK_FPOINTER \\\n                                   conversion_fn (CCTK_INT IN nelems, \\\n                                                  CCTK_INT IN src_stride,\\\n                                                  CCTK_INT IN dst_stride,\\\n                                                  CCTK_INT IN src_type, \\\n                                                  CCTK_INT IN dst_type, \\\n                                                  CCTK_POINTER_TO_CONST IN from, \\\n                                                  CCTK_POINTER IN to), \\\n                                  CCTK_INT ARRAY OUT hsize)\n\nCCTK_INT FUNCTION Hyperslab_FreeMapping (CCTK_INT IN mapping_handle)\n\n\nREQUIRES FUNCTION Hyperslab_Get\nREQUIRES FUNCTION Hyperslab_GlobalMappingByIndex\nREQUIRES FUNCTION Hyperslab_FreeMapping\n",
  "param": "# Parameter definitions for thorn SampleIO\n# $Header$\n\n##############################################\n### Declare all SampleIO parameters as private\n### (not shared by other thorns)\n##############################################\nprivate:\n\nINT out_every \"How often to do SampleIO output, overrides IO::out_every\" STEERABLE = ALWAYS\n{\n   1:* :: \"Every so many iterations\"\n   0:  :: \"Disable SampleIO output\"\n  -1:  :: \"Choose the default from IO::out_every\"\n} -1\n\nSTRING out_vars \"Variables to output by SampleIO\" STEERABLE = ALWAYS\n{\n  \".+\" :: \"Space-separated list of fully qualified variable/group names\"\n  \"^$\" :: \"An empty string to output nothing\"\n} \"\"\n\nINT point_x \"x-index (starting from 0) locating the array element to output\" STEERABLE = ALWAYS\n{\n  0:* :: \"An index between [0, nx)\"\n} 0\nINT point_y \"y-index (starting from 0) locating the array element to output\" STEERABLE = ALWAYS\n{\n  0:* :: \"An index between [0, ny)\"\n} 0\nINT point_z \"z-index (starting from 0) locating the array element to output\" STEERABLE = ALWAYS\n{\n  0:* :: \"An index between [0, nz)\"\n} 0\n\n\n####################################################\n### Import generic parameters from implementation IO\n####################################################\nshares: IO\n\nUSES INT out_every AS io_out_every\nUSES KEYWORD verbose\nUSES BOOLEAN strict_io_parameter_check\n",
  "schedule": "# Schedule definitions for thorn SampleIO\n# $Header$\n\n##############################\n### Register SampleIO routines\n##############################\nschedule SampleIO_Startup at STARTUP after IOUtil_Startup\n{\n  LANG:C\n} \"Startup routine\"\n",
  "src": {
    "make.code.defn": "# Main make.code.defn file for thorn SampleIO\n# $Header$\n\n# Source files in this directory\nSRCS = Startup.c Output.c Write.c\n",
    "Output.c": " /*@@\n   @file      Output.c\n   @date      Tue 14 May 2002\n   @author    Thomas Radke\n   @desc\n              Functions registered as I/O method \"SampleIO\"\n   @enddesc\n   @version   $Id$\n @@*/\n\n#include <stdlib.h>\n#include <string.h>\n\n#include \"cctk.h\"\n#include \"cctk_Parameters.h\"\n#include \"util_String.h\"\n#include \"CactusBase/IOUtil/src/ioutil_Utils.h\"\n#include \"ioSampleIOMethodGH.h\"\n\n/* the rcs ID and its dummy function to use it (this is so that you can grep\n   for a version number of this source file in a Cactus executable) */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusExamples_SampleIO_Output_c)\n\n\n/********************************************************************\n ********************    Internal Routines   ************************\n ********************************************************************/\nstatic int CheckOutputVar (int vindex, const cGH *GH);\nstatic void SetOutputFrequency (int vindex, const char *optstring, void *arg);\n\n\n/*@@\n   @routine    SampleIO_OutputGH\n   @date       Tue 14 May 2002\n   @author     Thomas Radke\n   @desc\n               Loops over all variables and outputs them if necessary\n   @enddesc\n   @calls      SampleIO_TimeFor\n               SampleIO_Write\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 SampleIO_OutputGH (const cGH *GH)\n{\n  int vindex, retval;\n  const ioSampleIOMethodGH *myGH;\n\n\n  retval = 0;\n  myGH = CCTK_GHExtension (GH, \"SampleIO\");\n\n  /* loop over all variables */\n  for (vindex = CCTK_NumVars () - 1; vindex >= 0; vindex--)\n  {\n    if (SampleIO_TimeFor (GH, vindex) &&\n        SampleIO_Write (GH, vindex) == 0)\n    {\n      /* register variable as having output this iteration */\n      myGH->out_last[vindex] = GH->cctk_iteration;\n      retval++;\n    }\n  }\n\n  return (retval);\n}\n\n\n/*@@\n   @routine    SampleIO_OutputVarAs\n   @date       Tue 14 May 2002\n   @author     Thomas Radke\n   @desc\n               Unconditional output of a variable using the \"SampleIO\"\n               I/O method\n   @enddesc\n   @calls      SampleIO_Write\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\n   @vtype      const char *\n   @vio        in\n   @endvar\n   @var        alias\n   @vdesc      alias name of variable to output\n   @vtype      const char *\n   @vio        unused\n   @endvar\n\n   @returntype int\n   @returndesc\n               return code of @seeroutine SampleIO_Write, or<BR>\n               -1 if variable cannot be output by \"SampleIO\"\n   @endreturndesc\n@@*/\nint SampleIO_OutputVarAs (const cGH *GH, const char *fullname,\n                          const char *alias)\n{\n  int vindex, retval;\n\n\n  /* avoid compiler warning about unused function argument */\n  (void) (alias + 0);\n\n  retval = -1;\n  vindex = CCTK_VarIndex (fullname);\n\n  /* make sure this variable can be output by \"SampleIO\" */\n  if (CheckOutputVar (vindex, GH))\n  {\n    retval = SampleIO_Write (GH, vindex);\n  }\n\n  return (retval);\n}\n\n\n /*@@\n   @routine    SampleIO_TimeFor\n   @date       Tue 14 May 2002\n   @author     Thomas Radke\n   @desc\n               Decides if it is time to output a variable using the \"SampleIO\"\n               I/O 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\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<BR>\n               0 if not\n   @endreturndesc\n@@*/\nint SampleIO_TimeFor (const cGH *GH, int vindex)\n{\n  int result;\n  char *fullname;\n  ioSampleIOMethodGH *myGH;\n\n\n  /* check whether steerable parameters have changed */\n  myGH = CCTK_GHExtension (GH, \"SampleIO\");\n  SampleIO_CheckSteerableParameters (GH, myGH);\n\n  /* check if this variable should be output */\n  result = myGH->out_every[vindex] > 0 &&\n           GH->cctk_iteration % myGH->out_every[vindex] == 0;\n  if (result)\n  {\n    /* check if variable wasn't already output this iteration */\n    if (myGH->out_last[vindex] == GH->cctk_iteration)\n    {\n      fullname = CCTK_FullName (vindex);\n      CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,\n                  \"Already done SampleIO output for '%s' in current \"\n                  \"iteration (probably via triggers)\", fullname);\n      free (fullname);\n      result = 0;\n    }\n  }\n\n  return (result);\n}\n\n\n/*@@\n   @routine    SampleIO_TriggerOutput\n   @date       Tue 14 May 2002\n   @author     Thomas Radke\n   @desc\n               Triggers the output of a variable using the \"SampleIO\" I/O method\n   @enddesc\n   @calls      SampleIO_Write\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 SampleIO_Write\n   @endreturndesc\n@@*/\nint SampleIO_TriggerOutput (const cGH *GH, int vindex)\n{\n  int retval;\n  const ioSampleIOMethodGH *myGH;\n\n\n  /* do the output */\n  retval = SampleIO_Write (GH, vindex);\n  if (retval == 0)\n  {\n    /* register variable as having output this iteration */\n    myGH = CCTK_GHExtension (GH, \"SampleIO\");\n    myGH->out_last[vindex] = GH->cctk_iteration;\n  }\n\n  return (retval);\n}\n\n\n/*@@\n   @routine    SampleIO_CheckSteerableParameters\n   @date       Mon Oct 10 2000\n   @author     Thomas Radke\n   @desc\n               Checks if SampleIO steerable parameters were changed\n               and does appropriate re-evaluation.\n   @enddesc\n\n   @calls      CCTK_TraverseString\n\n   @var        GH\n   @vdesc      pointer to CCTK grid hierarchy\n   @vtype      const cGH *\n   @vio        in\n   @endvar\n   @var        myGH\n   @vdesc      pointer to SampleIO grid hierarchy\n   @vtype      ioSampleIOMethodGH *\n   @vio        inout\n   @endvar\n@@*/\nvoid SampleIO_CheckSteerableParameters (const cGH *GH, ioSampleIOMethodGH *myGH)\n{\n  int i, num_vars;\n  char *fullname, *msg;\n  DECLARE_CCTK_PARAMETERS\n\n\n  /* check the 'out_every' parameter from both implementations\n     \"SampleIO\" and \"IO\" (the first overriding the latter) */\n  i = myGH->out_every_default;\n  myGH->out_every_default = out_every >= 0 ? out_every : io_out_every;\n\n  /* report if periodic output frequency changed */\n  if (myGH->out_every_default != i && ! CCTK_Equals (verbose, \"none\"))\n  {\n    if (myGH->out_every_default > 0)\n    {\n      CCTK_VInfo (CCTK_THORNSTRING, \"Periodic SampleIO output every \"\n                  \"%d iterations\", myGH->out_every_default);\n    }\n    else\n    {\n      CCTK_INFO (\"Periodic SampleIO output turned off\");\n    }\n  }\n\n  /* re-parse the 'SampleIO::out_vars' parameter if it was changed */\n  if (strcmp (out_vars, myGH->out_vars) || myGH->out_every_default != i)\n  {\n    num_vars = CCTK_NumVars ();\n\n    /* reset all variables' output frequencies to zero (disable output) */\n    memset (myGH->out_every, 0, num_vars * sizeof (CCTK_INT));\n\n    /* set output frequency for selected variables by traversing the 'out_vars'\n       string */\n    if (CCTK_TraverseString (out_vars, SetOutputFrequency, &GH,\n                             CCTK_GROUP_OR_VAR) < 0)\n    {\n      CCTK_WARN (myGH->stop_on_parse_errors ? 0 : 1,\n                 \"error while parsing parameter 'SampleIO::out_vars'\");\n    }\n\n    /* report the variables to do periodic output for */\n    if (myGH->out_every_default == i || ! CCTK_Equals (verbose, \"none\"))\n    {\n      msg = NULL;\n      for (i = 0; i < num_vars; i++)\n      {\n        if (myGH->out_every[i] > 0)\n        {\n          fullname = CCTK_FullName (i);\n          if (! msg)\n          {\n            Util_asprintf (&msg, \"Periodic SampleIO output requested \"\n                           \"for '%s'\", fullname);\n          }\n          else\n          {\n            char *tmp = msg;\n            Util_asprintf (&msg, \"%s, '%s'\", msg, fullname);\n            free (tmp);\n          }\n          free (fullname);\n        }\n      }\n      if (msg)\n      {\n        CCTK_INFO (msg);\n        free (msg);\n      }\n    }\n\n    /* save the last setting of the 'SampleIO::out_vars' parameter */\n    free (myGH->out_vars);\n    myGH->out_vars = strdup (out_vars);\n  }\n}\n\n\n/********************************************************************\n ********************    Internal Routines   ************************\n ********************************************************************/\n/*\n * check if this variable can be output by I/O method \"SampleIO\"\n * A variable can be output if\n *   - it is a grid function or array\n *   - it is not of any of the CCTK_COMPLEX data types\n *   - it has 3 dimensions\n *   - its extents are larger than the selected point position to output\n */\nstatic int CheckOutputVar (int vindex, const cGH *GH)\n{\n  int groupindex;\n  cGroup groupinfo;\n  char *fullname;\n  int extent[3];\n  const char *errormsg;\n  DECLARE_CCTK_PARAMETERS\n\n\n  /* get the variable group information */\n  groupindex = CCTK_GroupIndexFromVarI (vindex);\n  CCTK_GroupData (groupindex, &groupinfo);\n\n  errormsg = NULL;\n  if (groupinfo.grouptype != CCTK_GF && groupinfo.grouptype != CCTK_ARRAY)\n  {\n    errormsg = \"is not a grid function or array\";\n  }\n  else if (! strncmp (CCTK_VarTypeName (groupinfo.vartype), \"CCTK_COMPLEX\", 12))\n  {\n    errormsg = \"CCTK_COMPLEX variables cannot be dealt with\";\n  }\n  else if (groupinfo.dim != 3)\n  {\n    errormsg = \"grid function/array dimension is other than 3\";\n  }\n  else\n  {\n    /* get the extents of the variable */\n    CCTK_GroupgshGI (GH, 3, extent, groupindex);\n    if (extent[0] <= point_x || extent[1] <= point_y || extent[2] <= point_z)\n    {\n      errormsg = \"grid point location exceeds grid function/array extents\";\n    }\n  }\n\n  if (errormsg)\n  {\n    fullname = CCTK_FullName (vindex);\n    CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n                \"No SampleIO output for '%s': %s\", fullname, errormsg);\n    free (fullname);\n  }\n\n  return (errormsg == NULL);\n}\n\n\n/*\n * callback for CCTK_TraverseString() to set the output flag\n * for the given variable\n */\nstatic void SetOutputFrequency (int vindex, const char *optstring, void *arg)\n{\n  const cGH *GH = *(const cGH **) arg;\n  const ioSampleIOMethodGH *myGH;\n\n\n  /* only set frequency if this variable can be output */\n  if (CheckOutputVar (vindex, GH))\n  {\n    /* take the default output frequency, or set the value from the option\n       string if supplied */\n    myGH = CCTK_GHExtension (GH, \"SampleIO\");\n    myGH->out_every[vindex] = myGH->out_every_default;\n\n    if (optstring)\n    {\n      IOUtil_ParseOutputFrequency (CCTK_THORNSTRING, \"SampleIO::out_vars\",\n                                   myGH->stop_on_parse_errors, vindex,\n                                   optstring, &myGH->out_every[vindex], NULL);\n    }\n  }\n}\n",
    "ioSampleIOMethodGH.h": " /*@@\n   @header    ioSampleIOMethodGH.h\n   @date      Tue 14 May 2002\n   @author    Thomas Radke\n   @desc\n              The extensions to the GH structure from thorn SampleIO\n   @enddesc\n   @version   $Header$\n @@*/\n\n#ifndef IOSAMPLEIOMETHOD_IOSAMPLEIOMETHODGH_H_\n#define IOSAMPLEIOMETHOD_IOSAMPLEIOMETHODGH_H_ 1\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\ntypedef struct SampleIOGH\n{\n  /* default number of times to output */\n  int out_every_default;\n\n  /* number of times to output each individual variable */\n  CCTK_INT *out_every;\n\n  /* the last iteration output for each variable */\n  int *out_last;\n\n  /* current list of variables to output */\n  char *out_vars;\n\n  /* stop on I/O parameter parsing errors ? */\n  int stop_on_parse_errors;\n\n} ioSampleIOMethodGH;\n\n\n/* functions which are registered as \"SampleIO\" I/O method */\nint SampleIO_OutputGH (const cGH *GH);\nint SampleIO_OutputVarAs (const cGH *GH, const char *fullname,\n                          const char *alias);\nint SampleIO_TimeFor (const cGH *GH, int vindex);\nint SampleIO_TriggerOutput (const cGH *GH, int vindex);\n\n/* other function prototypes for thorn-internal routines */\nint SampleIO_Write (const cGH *GH, int vindex);\nvoid SampleIO_CheckSteerableParameters (const cGH *GH, ioSampleIOMethodGH *myGH);\n\n\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n#endif /* IOSAMPLEIOMETHOD_IOSAMPLEIOMETHODGH_H_ */\n",
    "Write.c": "/*@@\n   @file      Write.c\n   @date      Thu 18 April 2002\n   @author    Thomas Radke\n   @desc\n              Function which implements output method.\n   @enddesc\n   @version   $Id$\n @@*/\n\n\n#include <stdlib.h>\n#include <string.h>\n\n#include \"cctk.h\"\n#include \"cctk_Parameters.h\"\n#include \"ioSampleIOMethodGH.h\"\n\n/* the rcs ID and its dummy function to use it (this is so that you can grep\n   for a version number of this source file in a Cactus executable) */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusExamples_SampleIO_Write_c)\n\n\n/*@@\n   @routine   SampleIO_Write\n   @date      Thu 18 April 2002\n   @author    Thomas Radke\n   @desc\n              Gets the value of a grid function/array at a chosen location\n              as a hyperslab and prints it to screen\n   @enddesc\n   @calls     Hyperslab_GlobalMappingByIndex\n              Hyperslab_FreeMapping\n              Hyperslab_Get\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                0 for success, or<BR>\n               -1 if variable has no storage assigned<BR>\n               -2 if hyperslab mapping couldn't be defined<BR>\n               -3 if hyperslab point couldn't be extracted\n   @endreturndesc\n@@*/\nint SampleIO_Write (const cGH *GH, int vindex)\n{\n  int retval;\n  char *fullname;\n  CCTK_INT mapping;\n  CCTK_INT origin[3], extent[1], direction[1*3];\n  CCTK_REAL value;\n  DECLARE_CCTK_PARAMETERS;\n\n\n  retval = 0;\n\n  /* get the full variable name (used for error messages) */\n  fullname = CCTK_FullName (vindex);\n\n  /* check if variable has storage assigned */\n  if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (vindex)))\n  {\n    CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,\n                \"No SampleIO output for '%s' (no storage)\", fullname);\n    free (fullname);\n    return (-1);\n  }\n\n  /*\n   * set the origin from SampleIO's parameters,\n   * the extent being 1 (for a single point),\n   * and the direction as a diagonal (spanning in each direction of the 3D grid)\n   */\n  origin[0] = point_x; origin[1] = point_y; origin[2] = point_z;\n  extent[0] = 1;\n  direction[0] = 1; direction[1] = direction[2] = 0;\n\n  /* define the point to output at as a 1D hyperslab */\n  mapping = Hyperslab_GlobalMappingByIndex (GH, vindex, 1, direction,\n                                            origin, extent, NULL, -1,\n                                            NULL, NULL);\n  if (mapping >= 0)\n  {\n    /*\n     * get the hyperslab data as a REAL value on all processors\n     * and print it to screen\n     */\n    if (! Hyperslab_Get (GH, mapping, -1, vindex, 0, CCTK_VARIABLE_REAL,\n                         (CCTK_POINTER) &value))\n    {\n      CCTK_VInfo (CCTK_THORNSTRING, \"'%s' at [x][y][z] = [%d][%d][%d]: %f\",\n                  fullname,\n                  (int) point_x, (int) point_y, (int) point_z, (double) value);\n    }\n    else\n    {\n      CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n                  \"Failed to extract hyperslab for variable '%s'\", fullname);\n      retval = -3;\n    }\n\n    /* release the mapping structure */\n    Hyperslab_FreeMapping (mapping);\n  }\n  else\n  {\n    CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n                \"Failed to define hyperslab mapping for variable '%s'\",\n                fullname);\n    retval = -2;\n  }\n\n  free (fullname);\n\n  return (retval);\n}\n",
    "Startup.c": " /*@@\n   @file      Startup.c\n   @date      Tue 14 May 2002\n   @author    Thomas Radke\n   @desc\n              Startup routines for thorn SampleIO\n   @enddesc\n   @version   $Id$\n @@*/\n\n#include <stdlib.h>\n#include <string.h>\n\n#include \"cctk.h\"\n#include \"cctk_Parameters.h\"\n#include \"ioSampleIOMethodGH.h\"\n\n/* the rcs ID and its dummy function to use it (this is so that you can grep\n   for a version number of this source file in a Cactus executable) */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusExamples_SampleIO_Startup_c)\n\n\n/********************************************************************\n ********************    External Routines   ************************\n ********************************************************************/\nint SampleIO_Startup (void);\n\n\n/********************************************************************\n ********************    Internal Routines   ************************\n ********************************************************************/\nstatic void *SetupGH (tFleshConfig *config, int conv_level, cGH *GH);\n\n\n /*@@\n   @routine   SampleIO_Startup\n   @date      Tue 14 May 2002\n   @author    Thomas Radke\n   @desc\n              The startup registration routine for thorn SampleIO.\n              Registers the GH extension for this thorn along with its\n              setup routine.\n   @enddesc\n   @calls     CCTK_RegisterGHExtension\n              CCTK_RegisterGHExtensionSetupGH\n@@*/\nint SampleIO_Startup (void)\n{\n  int extension;\n\n\n  /* register a new GH extension with a unique name */\n  extension = CCTK_RegisterGHExtension (\"SampleIO\");\n  if (extension >= 0)\n  {\n    CCTK_RegisterGHExtensionSetupGH (extension, SetupGH);\n  }\n  else\n  {\n    CCTK_WARN (1, \"Couldn't register GH extension 'SampleIO'. \"\n                  \"This I/O method will not be registered\");\n  }\n  return 0;\n}\n\n\n/********************************************************************\n ********************    Internal Routines   ************************\n ********************************************************************/\n /*@@\n   @routine   SetupGH\n   @date      Tue 14 May 2002\n   @author    Thomas Radke\n   @desc\n              Allocates and sets up SampleIO'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       unused\n   @endvar\n\n   @returntype void *\n   @returndesc\n               pointer to the allocated GH extension structure\n   @endreturndesc\n@@*/\nstatic void *SetupGH (tFleshConfig *config, int conv_level, cGH *GH)\n{\n  int i, numvars;\n  ioSampleIOMethodGH *myGH;\n  DECLARE_CCTK_PARAMETERS\n\n\n  /* suppress compiler warnings about unused variables */\n  (void) (config + 0);\n  (void) (conv_level + 0);\n  (void) (GH + 0);\n\n  /* allocate the GH extension and its components */\n  myGH = (ioSampleIOMethodGH *) malloc (sizeof (ioSampleIOMethodGH));\n  if (! myGH)\n  {\n    CCTK_WARN (0, \"Unable to allocate memory for GH\");\n  }\n\n  /* register routines as a new I/O method \"SampleIO\" */\n  i = CCTK_RegisterIOMethod (\"SampleIO\");\n  CCTK_RegisterIOMethodOutputGH (i, SampleIO_OutputGH);\n  CCTK_RegisterIOMethodOutputVarAs (i, SampleIO_OutputVarAs);\n  CCTK_RegisterIOMethodTimeToOutput (i, SampleIO_TimeFor);\n  CCTK_RegisterIOMethodTriggerOutput (i, SampleIO_TriggerOutput);\n\n  /* announcing this new I/O method to the user */\n  if (! CCTK_Equals (verbose, \"none\"))\n  {\n    CCTK_INFO (\"I/O Method 'SampleIO' registered\");\n    CCTK_INFO (\"SampleIO: Print the value of 3D grid functions/arrays \"\n               \"at a chosen location to screen\");\n  }\n\n  /* now allocate and initialize the GH extension structure's components */\n  numvars = CCTK_NumVars ();\n  myGH->out_every = (CCTK_INT *) malloc (numvars * sizeof (CCTK_INT));\n  myGH->out_last = (int *) malloc (numvars * sizeof (int));\n\n  for (i = 0; i < numvars; i++)\n  {\n    myGH->out_last[i] = -1;\n  }\n\n  myGH->out_vars = strdup (\"\");\n  myGH->out_every_default = out_every - 1;\n\n  myGH->stop_on_parse_errors = strict_io_parameter_check;\n  if (! CCTK_Equals (verbose, \"none\"))\n  {\n    CCTK_INFO (\"I/O Method 'SampleIO' registered: output of individual grid \"\n               \"points from grid variables to screen\");\n  }\n  SampleIO_CheckSteerableParameters (GH, myGH);\n  myGH->stop_on_parse_errors = 0;\n\n  return (myGH);\n}\n"
  },
  "test": {},
  "doc": {
    "documentation.tex": "% Thorn documentation template\n\\documentclass{article}\n\n\\begin{document}\n\\title{SampleIO}\n\\author{Thomas Radke}\n\\date{$ $Date$ $}\n\\maketitle\n\n\\abstract{\nThorn {\\bf SampleIO} serves as an example for creating your own I/O thorns.\nIts code is clearly structured and well documented, and implements a very\nsimple and light-weight but fully functioning Cactus I/O method.\\\\\nTogether with the documentation about I/O methods in the {\\it Cactus Users'\nGuide} and the chapter about thorn {\\bf IOUtil} in the {\\it Cactus Thorn Guide}\nyou should be able to use this code and modify/extend it according to your\nneeds.\n}\n\n\\section{Purpose}\nThorn {\\bf SampleIO} registers the I/O method {\\tt SampleIO} with the Cactus\nflesh I/O interface. This method prints the data values of\nthree-dimensional, distributed Cactus grid functions/arrays at a chosen\nlocation to screen.\n\nThe implemented I/O method makes use of the Cactus Hyperslabbing API to obtain\nthe data values to print.\n\n\\section{{\\bf SampleIO} Parameters}\nParameters to control the {\\tt SampleIO} I/O method are:\n\n\\begin{itemize}\n  \\item{\\tt SampleIO::out\\_vars}\\\\\n    This parameter denotes the variables to output as a space-separated list\n    of full variable and/or group names.\n  \\item{\\tt SampleIO::point\\_x, SampleIO::point\\_y, SampleIO::point\\_z}\\\\\n    The location of the data point to output for all variables is given in\n    index coordinates (starting from 0) on a three-dimensional computational\n    grid.\n  \\item{\\tt SampleIO::out\\_every}\\\\\n    This parameter sets the frequency for periodic output.\n    A positive value means to output every so many iterations. A negative value\n    chooses the value of the general {\\tt IO::out\\_every} integer parameter to\n    be taken.  A value of zero disables {\\tt SampleIO} periodic output.\\\\\n    The value for {\\tt out\\_every} is used for all variables by default.\n    This can be overwritten for individual variables by appending an option\n    string to the variable name, like in\n    \\center{\\tt SampleIO::out\\_vars = \"MyThorn::MyVar[out\\_every=2]\"}.\n\\end{itemize}\n\nAll parameters are steerable, ie. they can be changed at runtime.\\\\\nThe code in thorn {\\bf SampleIO} includes the logic to check whether a parameter\nhas been changed since the last output, and how to re-evaluate the I/O\nparameters.\n\n\\section{Notes}\nLike any other I/O thorn should do, {\\bf SampleIO} inherits general I/O\nparameters from thorn {\\bf IOUtil}. Therefore this I/O helper thorn must be\nincluded in the {\\tt ThornList} of a Cactus configuration in order to compile\nthorn {\\bf SampleIO}, and also activated at runtime in the {\\tt ActiveThorns}\nparameter in your parameter file.\n\n\\end{document}\n"
  }
}