aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880>2001-08-01 11:38:17 +0000
committertradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880>2001-08-01 11:38:17 +0000
commit1ec7c99cb05a7a5dde7ed81fbc185be658822bda (patch)
tree40ea9282884da6a01d6cbae0eea39cc0968abb8f /src
parentad7050ddb6009847f4b345dbb6c32e1e02e54466 (diff)
For info output, you can now specify the reduction values to print by setting
IOBasic::outInfo_reductions or add an option string to the variable name in IOBasic::outInfo_vars. Scalar variables will be output by their value. The option string syntax is IOBasic::outInfo_vars = "var1[reductions=<minimum maximum>] var2" and might still change slightly in the future. git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOBasic/trunk@96 b589c3ab-70e8-4b4d-a09f-cba2dd200880
Diffstat (limited to 'src')
-rw-r--r--src/GHExtension.c134
-rw-r--r--src/OutputInfo.c742
-rw-r--r--src/OutputScalar.c (renamed from src/Output.c)88
-rw-r--r--src/Startup.c213
-rw-r--r--src/Write.c185
-rw-r--r--src/WriteGF.c306
-rw-r--r--src/WriteInfo.c185
-rw-r--r--src/WriteScalar.c416
-rw-r--r--src/iobasicGH.h50
-rw-r--r--src/make.code.defn10
10 files changed, 1256 insertions, 1073 deletions
diff --git a/src/GHExtension.c b/src/GHExtension.c
deleted file mode 100644
index df3d69c..0000000
--- a/src/GHExtension.c
+++ /dev/null
@@ -1,134 +0,0 @@
- /*@@
- @file GHExtension.c
- @date Friday 18th September
- @author Gabrielle Allen
- @desc
- IO GH extension stuff.
- @enddesc
- @@*/
-
-/* #define DEBUG_IO */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "cctk.h"
-#include "cctk_Parameters.h"
-#include "iobasicGH.h"
-
-static const char *rcsid = "$Header$";
-
-CCTK_FILEVERSION(CactusBase_IOBasic_GHExtension_c)
-
-void *IOBasic_SetupGH (tFleshConfig *config, int convergence_level, cGH *GH)
-{
- int i;
- iobasicGH *newGH;
-
- newGH = (iobasicGH *) malloc (sizeof (iobasicGH));
- newGH->infovals = (CCTK_REAL **)
- malloc (CCTK_NumVars () * sizeof (CCTK_REAL *));
- for (i=0;i<CCTK_NumVars ();i++)
- {
- newGH->infovals[i] = (CCTK_REAL *) malloc (2 * sizeof (CCTK_REAL));
- }
-
- newGH->do_outScalar = (char *) malloc (CCTK_NumVars () * sizeof (char));
- newGH->outScalar_last = (int *) malloc (CCTK_NumVars () * sizeof (int));
-
- newGH->do_outInfo = (char *) malloc (CCTK_NumVars () * sizeof (char));
- newGH->outInfo_last = (int *) malloc (CCTK_NumVars () * sizeof (int));
-
- return newGH;
-}
-
-int IOBasic_InitGH (cGH *GH)
-{
- int i;
- iobasicGH *myGH;
- DECLARE_CCTK_PARAMETERS
-
- /* get the handles for IOBasic extensions */
- myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")];
- myGH->filenameListScalar = NULL;
-
- /* How often to output */
- myGH->outInfo_every = out_every > 0 ? out_every : -1;
- if (outInfo_every > 0)
- {
- myGH->outInfo_every = outInfo_every;
- }
-
- myGH->outScalar_every = out_every > 0 ? out_every : -1;
- if (outScalar_every > 0)
- {
- myGH->outScalar_every = outScalar_every;
- }
-
- /* Check whether "outdirScalar" was set.
- If so take this dir otherwise default to "IO::outdir" */
- if (CCTK_ParameterQueryTimesSet ("outdirScalar", CCTK_THORNSTRING) > 0)
- {
- myGH->outdirScalar = strdup (outdirScalar);
- }
- else
- {
- myGH->outdirScalar = strdup (outdir);
- }
-
- /* create the output dir */
- if (CCTK_MyProc (GH) == 0)
- {
- i = CCTK_CreateDirectory (0755,myGH->outdirScalar);
- if (i < 0)
- {
- CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOBasic_InitGH: Problem creating Scalar output directory '%s'",
- myGH->outdirScalar);
- }
- if (i > 0)
- {
- CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOBasic_InitGH: Scalar output directory '%s' already exists",
- myGH->outdirScalar);
- }
- }
-
- for (i=0; i<CCTK_NumVars(); i++)
- {
- myGH->outScalar_last[i] = -1;
- myGH->outInfo_last [i] = -1;
- myGH->infovals[i][0] = 0.0;
- myGH->infovals[i][1] = 0.0;
- }
-
- myGH->filenameListScalar = NULL;
-
- /* Provide Information */
- if (CCTK_Equals(newverbose,"standard") || CCTK_Equals(newverbose,"full"))
- {
- if (myGH->outInfo_every > 0)
- {
- CCTK_VInfo("IOBasic","Info: Output every %d iterations",
- myGH->outInfo_every);
- }
- else
- {
- CCTK_VInfo("IOBasic","Info: No output requested");
- }
- CCTK_INFO("Info: Output to screen (standard output)");
- if (myGH->outScalar_every > 0)
- {
- CCTK_VInfo("IOBasic","Scalar: Output every %d iterations",
- myGH->outScalar_every);
- }
- else
- {
- CCTK_VInfo("IOBasic","Scalar: No output requested");
- }
- CCTK_VInfo("IOBasic","Scalar: Output to directory %s",myGH->outdirScalar);
- }
-
- return 0;
-}
diff --git a/src/OutputInfo.c b/src/OutputInfo.c
index 2d763e6..0527425 100644
--- a/src/OutputInfo.c
+++ b/src/OutputInfo.c
@@ -2,14 +2,14 @@
@file OutputInfo.c
@date June 31 1999
@author Gabrielle Allen
- @desc
+ @desc
Functions to deal with info output of variables
- @enddesc
- @version $Header$
+ @enddesc
+ @version $Id$
@@*/
-
+
#include <math.h>
-#include <stdio.h>
+#include <ctype.h>
#include <stdlib.h>
#include <string.h>
@@ -21,349 +21,202 @@
static const char *rcsid = "$Header$";
CCTK_FILEVERSION(CactusBase_IOBasic_OutputInfo_c)
+/********************************************************************
+ ******************** Macro Definitions ***********************
+ ********************************************************************/
/* uncomment the following to get some debugging output */
-/* #define IO_DEBUG 1 */
+/* #define IOBASIC_DEBUG 1 */
-/* the number at which to switch from decimal to exp notation */
+/* the number at which to switch from decimal to exponential notation */
#define DECIMAL_PRECISION 1.0e-8
#define DECIMAL_TOOBIG 1.0e+8
#define USE_DECIMAL_NOTATION(x) ((fabs (x) > DECIMAL_PRECISION) || \
((x) == 0.0) || \
(fabs(x) < DECIMAL_TOOBIG))
-
-/* prototypes of routines defined in this source file */
-int IOBasic_OutputInfoGH (cGH *GH);
-int IOBasic_TimeForInfo (cGH *GH, int vindex);
-int IOBasic_TriggerOutputInfo (cGH *GH, int vindex);
-static void SetOutputFlag (int vindex, const char *optstring, void *arg);
-
-/* static variables */
-static int print_header = 1;
-static int outInfo_vars_lastset = -1;
+#define PRINT_FORMATTED_REDUCTION_VALUE(reduction) \
+ if (reduction->is_valid) \
+ { \
+ if (USE_DECIMAL_NOTATION (reduction->value)) \
+ { \
+ printf ("%13.8f |", reduction->value); \
+ } \
+ else \
+ { \
+ printf ("%11.6e |", reduction->value); \
+ } \
+ } \
+ else \
+ { \
+ printf (" ----------- |"); \
+ }
+
+
+/********************************************************************
+ ******************** Internal Routines ************************
+ ********************************************************************/
+static void CheckSteerableParameters (iobasicGH *myGH);
+static void AssignReductionList (int vindex, const char *optstring, void *arg);
+static void PrintHeader (iobasicGH *myGH, int num_vars);
/*@@
- @routine IOBasic_OutputInfoGH
+ @routine IOBasic_InfoOutputGH
@date June 31 1999
@author Gabrielle Allen
@desc
Loops over all variables and prints output if requested
@enddesc
- @calls CCTK_GHExtension
- CCTK_ParameterQueryTimesSet
- CCTK_TraverseString
- CCTK_NumVars
- CCTK_VarName
+ @calls CheckSteerableParameters
+ PrintHeader
IOBasic_WriteInfo
@var GH
@vdesc Pointer to CCTK GH
@vtype cGH *
@vio in
- @endvar
+ @endvar
@returntype int
@returndesc
0 for success
@endreturndesc
@@*/
-int IOBasic_OutputInfoGH (cGH *GH)
+int IOBasic_InfoOutputGH (cGH *GH)
{
DECLARE_CCTK_PARAMETERS
- int i;
- int ierr1;
- int ierr2;
- int times_set;
- int out_old;
- const char *vname;
+ int vindex, num_vars;
+ iobasic_reduction_t *reduction;
iobasicGH *myGH;
- char ll[80], l1[1024], l2[1024], l3[1024];
- /* Get the GH extensions for IOBasic */
+ /* get the GH extensions for IOBasic */
myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
- /* How often to output */
- out_old = myGH->outInfo_every;
- myGH->outInfo_every = out_every > 0 ? out_every : -1;
- if (outInfo_every > 0)
- {
- myGH->outInfo_every = outInfo_every;
- }
- if (myGH->outInfo_every != out_old)
- {
- if (CCTK_Equals(newverbose,"standard") || CCTK_Equals(newverbose,"full"))
- {
- CCTK_VInfo("IOBasic","Info: Output every %d iterations",
- myGH->outInfo_every);
- }
- }
-
- /* Return if no output is required */
- if (myGH->outInfo_every < 1 ||
- GH->cctk_iteration % myGH->outInfo_every != 0)
+ /* check if steerable parameters changed */
+ CheckSteerableParameters (myGH);
+
+ /* return if no output is required */
+ if (myGH->outInfo_every <= 0 || GH->cctk_iteration % myGH->outInfo_every)
{
return (0);
}
- /* re-parse the 'outInfo_vars' parameter if it was changed
- and also print a header */
- times_set = CCTK_ParameterQueryTimesSet ("outInfo_vars", CCTK_THORNSTRING);
- if (times_set != outInfo_vars_lastset)
+ /* print header if neccessary */
+ num_vars = CCTK_NumVars ();
+ if (myGH->info_reductions_changed)
{
- memset (myGH->do_outInfo, 0, CCTK_NumVars ());
- CCTK_TraverseString (outInfo_vars, SetOutputFlag, myGH->do_outInfo,
- CCTK_GROUP_OR_VAR);
-
- if (CCTK_Equals(newverbose,"full"))
- {
- for (i=0;i<CCTK_NumVars();i++)
- {
- if (myGH->do_outInfo[i] > 0)
- {
- CCTK_VInfo("IOBasic","Info: Output requested for %s",
- CCTK_VarName(i));
- }
- }
- }
-
- /* Save the last setting of 'outInfo_vars' parameter */
- outInfo_vars_lastset = times_set;
-
- print_header = 1;
- }
-
- if (print_header)
- {
- print_header = 0;
-
- sprintf (l1," it | |");
- sprintf (l2," | t |");
- sprintf (l3,"----------------");
-
- for (i = 0; i < CCTK_NumVars (); i++)
- {
- if (myGH->do_outInfo[i])
- {
- if(CCTK_GroupTypeFromVarI(i) != CCTK_SCALAR)
- {
- sprintf (ll, " ");
- ll[25 - strlen (CCTK_VarName (i))] = '\0';
- sprintf (l1, "%s %s%s |", l1, CCTK_VarName (i), ll);
- sprintf (l2, "%s Min Max |", l2);
- sprintf (l3, "%s----------------------------", l3);
- }
- else
- {
- sprintf (ll, " ");
- ll[25 - strlen (CCTK_VarName (i))] = '\0';
- sprintf (l1, "%s %s%s |", l1, CCTK_VarName (i), ll);
- sprintf (l2, "%s Value |", l2);
- sprintf (l3, "%s----------------------------", l3);
- }
- }
- }
- printf ("%s\n%s\n%s\n%s\n", l3, l1, l2, l3);
- fflush (stdout);
+ PrintHeader (myGH, num_vars);
}
-
- /* Print the iteration/timestep information for all variables */
+ /* print the iteration/timestep information for all variables */
if (USE_DECIMAL_NOTATION (GH->cctk_time))
{
- printf ("%4d |%9.3f|", GH->cctk_iteration, GH->cctk_time);
- }
+ printf ("%5d |%9.3f |", GH->cctk_iteration, GH->cctk_time);
+ }
else
{
- printf ("%4d |%7.3e|", GH->cctk_iteration, GH->cctk_time);
+ printf ("%5d |%7.3e |", GH->cctk_iteration, GH->cctk_time);
}
- /* Loop over all variables */
- for (i = 0; i < CCTK_NumVars (); i++)
+ /* loop over all variables */
+ for (vindex = 0; vindex < num_vars; vindex++)
{
-
- /* Check this Variable should be output */
- if (! myGH->do_outInfo[i])
+ /* check this variable should be output */
+ if (myGH->info_reductions[vindex].num_reductions == 0)
{
continue;
}
- ierr1 = ierr2 = 0;
-
- /* Check variable not already output this iteration */
- if (myGH->outInfo_last[i] != GH->cctk_iteration)
+ /* check variable not already output this iteration */
+ if (myGH->outInfo_last[vindex] != GH->cctk_iteration)
{
-
- /* Get the variable name for this index (for filename) */
- vname = CCTK_VarName (i);
-
-#ifdef IO_DEBUG
+#ifdef IOBASIC_DEBUG
printf("\nIn IO OutputInfoGH\n----------------\n");
- printf(" Index = %d\n", i);
- printf(" Variable = -%s-\n", vname);
- printf(" Last output iteration was = %d\n", myGH->outInfo_last[i]);
+ printf(" Index = %d\n", vindex);
+ printf(" Variable = -%s-\n", CCTK_VarName (vindex);
+ printf(" Last output iteration was = %d\n", myGH->outInfo_last[vindex]);
#endif
- if(CCTK_GroupTypeFromVarI(i) != CCTK_SCALAR)
- {
- /* Make the IO call */
- ierr1 = IOBasic_WriteInfo (GH, &myGH->infovals[i][0], i, "minimum",vname);
- ierr2 = IOBasic_WriteInfo (GH, &myGH->infovals[i][1], i, "maximum",vname);
- }
- else
- {
- myGH->infovals[i][0] = *(CCTK_REAL *)GH->data[i][0];
- myGH->infovals[i][1] = *(CCTK_REAL *)GH->data[i][0];
- }
- /* Register GF as having info output this iteration */
- myGH->outInfo_last[i] = GH->cctk_iteration;
+ /* get the data to output */
+ IOBasic_WriteInfo (GH, vindex);
+
+ /* register variable as having info output this iteration */
+ myGH->outInfo_last[vindex] = GH->cctk_iteration;
}
- if(CCTK_GroupTypeFromVarI(i) != CCTK_SCALAR)
+ /* finally print the stuff to screen */
+ reduction = myGH->info_reductions[vindex].reductions;
+ while (reduction)
{
- if (ierr1 == 0)
- {
- /* finally print out the stuff */
- if (USE_DECIMAL_NOTATION (myGH->infovals[i][0]))
- {
- printf ("%12.8f |", myGH->infovals[i][0]);
- }
- else
- {
- printf ("%10.6e |", myGH->infovals[i][0]);
- }
- }
- else
- {
- printf(" ----------- |");
- }
-
- if (ierr2 == 0)
- {
- if (USE_DECIMAL_NOTATION (myGH->infovals[i][1]))
- {
- printf ("%12.8f |", myGH->infovals[i][1]);
- }
- else
- {
- printf ("%10.6e |", myGH->infovals[i][1]);
- }
- }
- else
- {
- printf(" ----------- |");
- }
+ PRINT_FORMATTED_REDUCTION_VALUE (reduction);
+ reduction = reduction->next;
}
- else
- {
- if (USE_DECIMAL_NOTATION (myGH->infovals[i][0]))
- {
- printf (" %12.8f |", myGH->infovals[i][0]);
- }
- else
- {
- printf (" %10.6e |", myGH->infovals[i][0]);
- }
- }
} /* end of loop over all variables */
- /* Add the new line */
- printf ("\n");
- fflush(stdout);
+ /* add the new line */
+ putchar ('\n');
+ fflush (stdout);
return (0);
}
/*@@
- @routine IOBasic_TimeForInfo
+ @routine IOBasic_TimeForInfoOutput
@date June 31 1999
@author Gabrielle Allen
@desc
Decides if it is time to output a variable using info output
@enddesc
- @calls CCTK_GHExtensionHandle
- CCTK_GroupTypeFromVarI
- CCTK_WARN
- CCTK_QueryGroupStorageI
- CCTK_GroupFromVar
-
+ @calls CheckSteerableParameters
+
@var GH
@vdesc Pointer to CCTK GH
@vtype cGH *
@vio in
- @endvar
+ @endvar
@var vindex
- @vdesc index of variable to output
+ @vdesc index of variable to check for output
@vtype int
@vio in
- @endvar
+ @endvar
@returntype int
@returndesc
true/false (1 or 0) if this variable should be output or not
@endreturndesc
@@*/
-int IOBasic_TimeForInfo (cGH *GH, int vindex)
+int IOBasic_TimeForInfoOutput (cGH *GH, int vindex)
{
DECLARE_CCTK_PARAMETERS
int retval;
- int times_set;
+ char *vname;
iobasicGH *myGH;
- char *fullname;
- /* Default is do not do output */
- retval = 0;
-
- /* Get the GH extensions for IOBasic */
+ /* get the GH extensions for IOBasic */
myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
- /* How often to output */
- myGH->outInfo_every = out_every > 0 ? out_every : -1;
- if (outInfo_every > 0)
- {
- myGH->outInfo_every = outInfo_every;
- }
+ /* check if steerable parameters changed */
+ CheckSteerableParameters (myGH);
/* return if no output requested */
- if (myGH->outInfo_every <= 0)
- {
- return (0);
- }
-
- /* re-parse the 'outInfo_vars' parameter if it was changed
- and also print a header */
- times_set = CCTK_ParameterQueryTimesSet ("outInfo_vars", CCTK_THORNSTRING);
- if (times_set != outInfo_vars_lastset)
+ if (myGH->outInfo_every <= 0 || GH->cctk_iteration % myGH->outInfo_every ||
+ myGH->info_reductions[vindex].num_reductions == 0)
{
- memset (myGH->do_outInfo, 0, CCTK_NumVars ());
- CCTK_TraverseString (outInfo_vars, SetOutputFlag, myGH->do_outInfo,
- CCTK_GROUP_OR_VAR);
-
- /* Save the last setting of 'outInfo_vars' parameter */
- outInfo_vars_lastset = times_set;
-
- print_header = 1;
+ retval = 0;
}
-
- /* Check if this variable should be output */
- if (myGH->do_outInfo[vindex] &&
- (GH->cctk_iteration % myGH->outInfo_every == 0))
+ else
{
-
- /* Check GF not already output this iteration */
- if (myGH->outInfo_last[vindex] == GH->cctk_iteration)
+ /* check if not already output this iteration */
+ retval = myGH->outInfo_last[vindex] != GH->cctk_iteration;
+ if (! retval)
{
- fullname = CCTK_FullName (vindex);
+ vname = CCTK_FullName (vindex);
CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,
"Already done Info output for '%s' in current "
- "iteration (probably via triggers)", fullname);
- free (fullname);
- }
- else
- {
- retval = 1;
+ "iteration (probably via triggers)", vname);
+ free (vname);
}
}
@@ -372,14 +225,13 @@ int IOBasic_TimeForInfo (cGH *GH, int vindex)
/*@@
- @routine IOBasic_TriggerOutputInfo
+ @routine IOBasic_TriggerInfoOutput
@date June 31 1999
@author Gabrielle Allen
@desc
Triggers the output of a variable using IOBasic's info output
@enddesc
- @calls CCTK_GHExtensionHandle
- IOBasic_WriteInfo
+ @calls IOBasic_WriteInfo
@var GH
@vdesc Pointer to CCTK GH
@@ -397,49 +249,397 @@ int IOBasic_TimeForInfo (cGH *GH, int vindex)
0 for success
@endreturndesc
@@*/
-int IOBasic_TriggerOutputInfo (cGH *GH, int vindex)
+int IOBasic_TriggerInfoOutput (cGH *GH, int vindex)
{
+ DECLARE_CCTK_PARAMETERS
iobasicGH *myGH;
- const char *vname;
- /* Get the GH extension for IOBasic */
+ /* get the GH extension for IOBasic */
myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
-
- vname = CCTK_VarName (vindex);
- /* Do the Info output */
-#ifdef IO_DEBUG
+#ifdef IOBASIC_DEBUG
printf ("\nIn IO TriggerOutputInfo\n---------------------\n");
printf (" Index = %d\n", vindex);
- printf (" Variable = -%s-\n", vname);
+ printf (" Variable = -%s-\n", CCTK_VarName (vindex);
#endif
-
- IOBasic_WriteInfo (GH, &myGH->infovals[vindex][0], vindex, "minimum", vname);
- IOBasic_WriteInfo (GH, &myGH->infovals[vindex][1], vindex, "maximum", vname);
- /* Register variable as having Info output at this iteration */
+ /* get the data values to output */
+ IOBasic_WriteInfo (GH, vindex);
+
+ /* gegister variable as having Info output at this iteration */
myGH->outInfo_last[vindex] = GH->cctk_iteration;
return (0);
}
-/***************************************************************************/
-/* local functions */
-/***************************************************************************/
-/* callback for CCTK_TraverseString() to set the output flag
- for the given variable */
-static void SetOutputFlag (int vindex, const char *optstring, void *arg)
+/********************************************************************
+ ******************** Internal Routines ************************
+ ********************************************************************/
+ /*@@
+ @routine CheckSteerableParameters
+ @date Tue 31 Jul 2001
+ @author Thomas Radke
+ @desc
+ Re-evaluates 'IOBasic::outInfo_every' and/or 'IO::out_every'
+ resp. to set myGH->outInfo_every to the frequency of info output.
+ Re-evaluates 'IOBasic::outInfo_vars' and
+ 'IOBasic::outInfo_reductions' and sets
+ myGH->info_reductions_changed to true if one of them was changed.
+ @enddesc
+ @calls CCTK_ParameterQueryTimesSet
+
+ @var myGH
+ @vdesc Pointer to IOBasic's GH extension
+ @vtype iobasicGH *
+ @vio in
+ @endvar
+@@*/
+static void CheckSteerableParameters (iobasicGH *myGH)
+{
+ DECLARE_CCTK_PARAMETERS
+ int out_old, times_set;
+ static int outInfo_vars_lastset = -1;
+ static int outInfo_reductions_lastset = -1;
+
+
+ /* how often to output */
+ out_old = myGH->outInfo_every;
+ myGH->outInfo_every = out_every > 0 ? out_every : -1;
+ if (outInfo_every > 0)
+ {
+ myGH->outInfo_every = outInfo_every;
+ }
+ if (myGH->outInfo_every != out_old)
+ {
+ if (CCTK_Equals (newverbose, "standard") ||
+ CCTK_Equals (newverbose, "full"))
+ {
+ CCTK_VInfo (CCTK_THORNSTRING, "Info: Output every %d iterations",
+ myGH->outInfo_every);
+ }
+ }
+
+ /* return if there's nothing to do */
+ if (myGH->outInfo_every <= 0)
+ {
+ return;
+ }
+
+ /* check if the 'outInfo_reductions' parameter if it was changed */
+ times_set = CCTK_ParameterQueryTimesSet ("outInfo_reductions",
+ CCTK_THORNSTRING);
+ myGH->info_reductions_changed |= times_set != outInfo_reductions_lastset;
+ outInfo_reductions_lastset = times_set;
+
+ /* check if the 'outInfo_vars' parameter if it was changed */
+ times_set = CCTK_ParameterQueryTimesSet ("outInfo_vars", CCTK_THORNSTRING);
+ myGH->info_reductions_changed |= times_set != outInfo_vars_lastset;
+ outInfo_vars_lastset = times_set;
+}
+
+
+ /*@@
+ @routine AssignReductionList
+ @date Tue 31 Jul 2001
+ @author Thomas Radke
+ @desc
+ Callback routine called by CCTK_TraverseString() to set the
+ info output for a given variable.
+ For CCTK_GF and CCTK_ARRAY variables, it builds a chained list
+ of reduction operators according to the settings of 'optstring'
+ or 'IOBasic::outInfo_reductions'.
+ @enddesc
+ @calls CCTK_GroupTypeFromVarI
+ CCTK_ReductionHandle
+
+ @var vindex
+ @vdesc index of the variable to set info output
+ @vtype int
+ @vio in
+ @endvar
+ @var optstring
+ @vdesc option string for this variable
+ @vtype const char *
+ @vio in
+ @endvar
+ @var arg
+ @vdesc user-supplied argument to callback routine (IOBasic GH extension)
+ @vtype void *
+ @vio in
+ @endvar
+@@*/
+static void AssignReductionList (int vindex, const char *optstring, void *arg)
{
- char *flags = (char *) arg;
+ DECLARE_CCTK_PARAMETERS
+ iobasicGH *myGH = (iobasicGH *) arg;
+ const char *string_start, *string_end;
+ char *reduction_op, *reduction_op_list;
+ int reduction_handle;
+ iobasic_reductionlist_t *list;
+ iobasic_reduction_t **new_reduction;
+
+
+ list = &myGH->info_reductions[vindex];
+
+ if (CCTK_GroupTypeFromVarI (vindex) == CCTK_SCALAR)
+ {
+ if (optstring)
+ {
+ CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "option list '%s' for variable '%s' ignored",
+ optstring, CCTK_VarName (vindex));
+ }
+
+ list->reductions = (iobasic_reduction_t *)
+ malloc (sizeof (iobasic_reduction_t));
+ if (strncmp (CCTK_VarTypeName (CCTK_VarTypeI (vindex)),
+ "CCTK_VARIABLE_COMPLEX", 21))
+ {
+ list->num_reductions = 1;
+ list->reductions->name = strdup ("scalar value");
+ list->reductions->next = NULL;
+ }
+ else
+ {
+ list->num_reductions = 2;
+ list->reductions->name = strdup ("real part");
+ list->reductions->next = (iobasic_reduction_t *)
+ malloc (sizeof (iobasic_reduction_t));
+ list->reductions->next->name = strdup ("imag part");
+ list->reductions->next->next = NULL;
+ }
+
+#ifdef IOBASIC_DEBUG
+ printf ("Set info scalar output for variable '%s'\n", CCTK_VarName(vindex));
+#endif
+ return;
+ }
- flags[vindex] = 1;
+ /* initialize to empty list */
+ list->num_reductions = 0;
+ list->reductions = NULL;
if (optstring)
{
- CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Optional string '%s' in variable name ignored", optstring);
+ if (strncmp (optstring, "reductions=<", 12) == 0 &&
+ optstring[strlen (optstring) - 1] == '>')
+ {
+ reduction_op_list = strdup (optstring + 12);
+ reduction_op_list[strlen (reduction_op_list) - 1] = 0;
+ }
+ else
+ {
+ CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "AssignReductionList: invalid syntax for option list '%s'",
+ optstring);
+ return;
+ }
+ }
+ else
+ {
+ reduction_op_list = strdup (outInfo_reductions);
+ }
+
+ /* now loop over all reduction operators */
+ string_start = reduction_op_list;
+ reduction_op = (char *) malloc (strlen (string_start) + 1);
+ while (string_start && *string_start)
+ {
+ /* skip leading spaces */
+ while (isspace ((int) *string_start))
+ {
+ string_start++;
+ }
+ if (! *string_start)
+ {
+ break;
+ }
+
+ /* advance to end of the operator string */
+ string_end = string_start + 1;
+ while (*string_end && ! isspace ((int) *string_end))
+ {
+ string_end++;
+ }
+
+ /* copy the operator string */
+ strncpy (reduction_op, string_start, string_end - string_start);
+ reduction_op[string_end - string_start] = 0;
+ string_start = string_end;
+
+ /* get the reduction handle from the reduction operator */
+ reduction_handle = CCTK_ReductionHandle (reduction_op);
+ if (reduction_handle < 0)
+ {
+ CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "AssignReductionList: Invalid reduction operator '%s'",
+ reduction_op);
+ continue;
+ }
+
+ /* add new reduction to end of list */
+ new_reduction = &list->reductions;
+ while (*new_reduction)
+ {
+ if (strcmp ((*new_reduction)->name, reduction_op) == 0)
+ {
+ new_reduction = NULL;
+ break;
+ }
+ new_reduction = &((*new_reduction)->next);
+ }
+ if (new_reduction == NULL)
+ {
+ CCTK_VWarn (3, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "AssignReductionList: Duplicate reduction operator '%s' will "
+ "be ignored", reduction_op);
+ continue;
+ }
+
+ *new_reduction = (iobasic_reduction_t *) malloc (sizeof (iobasic_reduction_t));
+ (*new_reduction)->handle = reduction_handle;
+ (*new_reduction)->name = strdup (reduction_op);
+ (*new_reduction)->next = NULL;
+ list->num_reductions++;
+
+#ifdef IOBASIC_DEBUG
+ printf ("Set info reduction output '%s' for variable '%s'\n",
+ (*new_reduction)->name, CCTK_VarName (vindex));
+#endif
+ }
+
+ free (reduction_op_list);
+ free (reduction_op);
+}
+
+
+ /*@@
+ @routine PrintHeader
+ @date Tue 31 Jul 2001
+ @author Thomas Radke
+ @desc
+ It re-evaluates the info reduction lists of all CCTK variables
+ and prints the header for the info output table.
+ @enddesc
+ @calls CCTK_TraverseString
+
+ @var myGH
+ @vdesc Pointer to IOBasic's GH extension
+ @vtype iobasicGH *
+ @vio in
+ @endvar
+ @var num_vars
+ @vdesc total number of CCTK variables
+ @vtype int
+ @vio in
+ @endvar
+@@*/
+static void PrintHeader (iobasicGH *myGH, int num_vars)
+{
+ DECLARE_CCTK_PARAMETERS
+ int i, num_columns, vindex;
+ char *vname;
+ iobasic_reduction_t *reduction, *next;
+
+
+ /* free old info output lists ... */
+ for (vindex = 0; vindex < num_vars; vindex++)
+ {
+ if (myGH->info_reductions[vindex].num_reductions > 0)
+ {
+ myGH->info_reductions[vindex].num_reductions = 0;
+ reduction = myGH->info_reductions[vindex].reductions;
+ while (reduction)
+ {
+ next = reduction->next;
+ free (reduction->name);
+ free (reduction);
+ reduction = next;
+ }
+ }
+ }
+ /* ... and create new ones */
+ if (CCTK_TraverseString (outInfo_vars, AssignReductionList, myGH,
+ CCTK_GROUP_OR_VAR) < 0)
+ {
+ CCTK_WARN (1, "Failed to parse 'IOBasic::outInfo_vars' parameter");
}
+
+ /* count number of info values to output */
+ num_columns = 0;
+ for (vindex = 0; vindex < num_vars; vindex++)
+ {
+ num_columns += myGH->info_reductions[vindex].num_reductions;
+
+ if (myGH->info_reductions[vindex].num_reductions > 0 &&
+ CCTK_Equals (newverbose, "full"))
+ {
+ CCTK_VInfo (CCTK_THORNSTRING, "Info: Output requested for variable '%s'",
+ CCTK_VarName (vindex));
+ }
+ }
+
+ /* draw a horizontal delimiter line */
+ printf ("------------------");
+ for (i = 0; i < num_columns; i++)
+ {
+ printf ("---------------");
+ }
+ putchar ('\n');
+
+ /* the first header line displays the iteration number (first column)
+ and the full names of the variables to output (third column ff.) */
+ printf (" it | |");
+ if (num_columns > 0)
+ {
+ for (vindex = 0; vindex < num_vars; vindex++)
+ {
+ i = myGH->info_reductions[vindex].num_reductions;
+ if (i > 0)
+ {
+ vname = CCTK_FullName (vindex);
+ if (strlen (vname) > (unsigned int) 15*i - 3)
+ {
+ printf (" *%s |", vname + strlen (vname) - (15*i - 4));
+ }
+ else
+ {
+ printf (" %-*s |", 15*i - 3, vname);
+ }
+ free (vname);
+ }
+ }
+ }
+ putchar ('\n');
+
+ /* the second header line displays the physical time (second column)
+ and the names of the reduction operators to apply (third column ff.) */
+ printf (" | t ");
+ for (vindex = 0; vindex < num_vars; vindex++)
+ {
+ if (myGH->info_reductions[vindex].num_reductions > 0)
+ {
+ reduction = myGH->info_reductions[vindex].reductions;
+ while (reduction)
+ {
+ printf ("| %-12s ", reduction->name);
+ reduction = reduction->next;
+ }
+ }
+ }
+ printf ("|\n");
+
+ /* finally draw another horizontal delimiter line */
+ printf ("------------------");
+ for (i = 0; i < num_columns; i++)
+ {
+ printf ("---------------");
+ }
+ putchar ('\n');
+ fflush (stdout);
+
+ myGH->info_reductions_changed = 0;
}
diff --git a/src/Output.c b/src/OutputScalar.c
index 0461611..155b1dc 100644
--- a/src/Output.c
+++ b/src/OutputScalar.c
@@ -3,11 +3,11 @@
@date Mon 21 September
@author Gabrielle Allen
@desc
- Functions to deal with scalar output of grid variables
+ Functions to deal with scalar output of grid variables
@enddesc
@@*/
-/*#define IO_DEBUG*/
+/* #define IOBASIC_DEBUG 1 */
#include <stdio.h>
#include <stdlib.h>
@@ -22,14 +22,12 @@ static const char *rcsid = "$Header$";
CCTK_FILEVERSION(CactusBase_IOBasic_Output_c)
/* function prototypes */
-int IOBasic_TimeForOutput (cGH *GH, int vindex);
-int IOBasic_OutputGH (cGH *GH);
static void CheckSteerableParameters (iobasicGH *myGH);
static void SetOutputFlag (int vindex, const char *optstring, void *arg);
/*@@
- @routine IOBasic_OutputGH
+ @routine IOBasic_ScalarOutputGH
@date Sat March 6 1999
@author Gabrielle Allen
@desc
@@ -45,7 +43,7 @@ static void SetOutputFlag (int vindex, const char *optstring, void *arg);
@vio in
@endvar
@@*/
-int IOBasic_OutputGH (cGH *GH)
+int IOBasic_ScalarOutputGH (cGH *GH)
{
int vindex;
const char *name;
@@ -53,7 +51,7 @@ int IOBasic_OutputGH (cGH *GH)
/* Get the GH extensions for IOBasic */
- myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")];
+ myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
CheckSteerableParameters (myGH);
@@ -68,7 +66,7 @@ int IOBasic_OutputGH (cGH *GH)
{
/* Is it time for output ? */
- if (! IOBasic_TimeForOutput (GH, vindex))
+ if (! IOBasic_TimeForScalarOutput (GH, vindex))
{
continue;
}
@@ -76,8 +74,8 @@ int IOBasic_OutputGH (cGH *GH)
/* Get the variable name for this index (for filename) */
name = CCTK_VarName (vindex);
-#ifdef IO_DEBUG
- printf("\nIn IOBasic_OutputGH\n----------------\n");
+#ifdef IOBASIC_DEBUG
+ printf("\nIn IOBasic_ScalarOutputGH\n----------------\n");
printf(" Index = %d\n",vindex);
printf(" Variable = -%s-\n",name);
printf(" Last output iteration was = %d\n",myGH->outScalar_last[vindex]);
@@ -86,11 +84,11 @@ int IOBasic_OutputGH (cGH *GH)
/* Make the IO call */
if (CCTK_GroupTypeFromVarI (vindex) == CCTK_SCALAR)
{
- IOBasic_Write (GH, vindex, name);
+ IOBasic_WriteScalarGS (GH, vindex, name);
}
else
{
- IOBasic_WriteGF (GH, vindex, name);
+ IOBasic_WriteScalarGA (GH, vindex, name);
}
/* Register GF as having 0D output this iteration */
@@ -103,13 +101,13 @@ int IOBasic_OutputGH (cGH *GH)
/*@@
- @routine IOBasic_OutputVarAs
+ @routine IOBasic_ScalarOutputVarAs
@date Sat March 6 1999
@author Gabrielle Allen
@desc
unconditional output of a variable using the IOBasic output method
@enddesc
- @calledby IOBasic_OutputGH, CCTK_OutputVarAsByMethod ("IOBasic")
+ @calledby IOBasic_ScalarOutputGH, CCTK_OutputVarAsByMethod ("IOBasic")
@var GH
@vdesc Pointer to CCTK GH
@vtype cGH
@@ -129,15 +127,15 @@ int IOBasic_OutputGH (cGH *GH)
@vcomment
@endvar
@@*/
-int IOBasic_OutputVarAs (cGH *GH, const char *fullname, const char *alias)
+int IOBasic_ScalarOutputVarAs (cGH *GH, const char *fullname, const char *alias)
{
int vindex;
vindex = CCTK_VarIndex (fullname);
-#ifdef IO_DEBUG
- printf("\nIn IOBasic_OutputVarAs\n-------------------\n");
+#ifdef IOBASIC_DEBUG
+ printf("\nIn IOBasic_ScalarOutputVarAs\n-------------------\n");
printf(" Fullname = -%s-\n",fullname);
printf(" Alias = -%s-\n",alias);
printf(" Index = %d\n",vindex);
@@ -145,11 +143,11 @@ int IOBasic_OutputVarAs (cGH *GH, const char *fullname, const char *alias)
if (CCTK_GroupTypeFromVarI (vindex) == CCTK_SCALAR)
{
- IOBasic_Write (GH, vindex, alias);
+ IOBasic_WriteScalarGS (GH, vindex, alias);
}
else
{
- IOBasic_WriteGF (GH, vindex, alias);
+ IOBasic_WriteScalarGA (GH, vindex, alias);
}
return (0);
@@ -157,14 +155,14 @@ int IOBasic_OutputVarAs (cGH *GH, const char *fullname, const char *alias)
/*@@
- @routine IOBasic_TimeForOutput
+ @routine IOBasic_TimeForScalarOutput
@date Sat March 6 1999
@author Gabrielle Allen
@desc
Decides if it is time to output a variable using Scalar output
method
@enddesc
- @calls CCTK_GHExtensionHandle
+ @calls CCTK_GHExtension
CCTK_GroupTypeFromVar
CCTK_WARN
@calledby
@@ -184,8 +182,7 @@ int IOBasic_OutputVarAs (cGH *GH, const char *fullname, const char *alias)
@vcomment
@endvar
@@*/
-
-int IOBasic_TimeForOutput (cGH *GH, int vindex)
+int IOBasic_TimeForScalarOutput (cGH *GH, int vindex)
{
int return_type;
iobasicGH *myGH;
@@ -196,7 +193,7 @@ int IOBasic_TimeForOutput (cGH *GH, int vindex)
return_type = 0;
/* Get the GH extension for IOBasic */
- myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")];
+ myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
CheckSteerableParameters (myGH);
@@ -230,7 +227,7 @@ int IOBasic_TimeForOutput (cGH *GH, int vindex)
/*@@
- @routine IOBasic_TriggerOutput
+ @routine IOBasic_TriggerScalarOutput
@date Sat March 6 1999
@author Gabrielle Allen
@desc
@@ -252,19 +249,19 @@ int IOBasic_TimeForOutput (cGH *GH, int vindex)
@vcomment
@endvar
@@*/
-int IOBasic_TriggerOutput (cGH *GH, int vindex)
+int IOBasic_TriggerScalarOutput (cGH *GH, int vindex)
{
const char *name;
iobasicGH *myGH;
/* Get the GH extension for IOBasic */
- myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")];
-
+ myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
+
name = CCTK_VarName (vindex);
-#ifdef IO_DEBUG
- printf ("\nIn IOBasic_TriggerOutput\n---------------------\n");
+#ifdef IOBASIC_DEBUG
+ printf ("\nIn IOBasic_TriggerScalarOutput\n---------------------\n");
printf (" Index = %d\n", vindex);
printf (" Variable = -%s-\n", name);
#endif
@@ -272,11 +269,11 @@ int IOBasic_TriggerOutput (cGH *GH, int vindex)
/* Do the Scalar output */
if (CCTK_GroupTypeFromVarI (vindex) == CCTK_SCALAR)
{
- IOBasic_Write (GH, vindex, name);
+ IOBasic_WriteScalarGS (GH, vindex, name);
}
else
{
- IOBasic_WriteGF (GH, vindex, name);
+ IOBasic_WriteScalarGA (GH, vindex, name);
}
/* Register variable as having Scalar output this iteration */
@@ -290,29 +287,18 @@ int IOBasic_TriggerOutput (cGH *GH, int vindex)
/* check if steerable parameters have changed */
static void CheckSteerableParameters (iobasicGH *myGH)
{
+ DECLARE_CCTK_PARAMETERS
int times_set;
- int out_old;
- int i;
static int outScalar_vars_lastset = -1;
- DECLARE_CCTK_PARAMETERS
/* How often to output */
- out_old = myGH->outScalar_every;
myGH->outScalar_every = out_every > 0 ? out_every : -1;
if (outScalar_every > 0)
{
myGH->outScalar_every = outScalar_every;
}
- if (myGH->outScalar_every != out_old)
- {
- if (CCTK_Equals(newverbose,"standard") || CCTK_Equals(newverbose,"full"))
- {
- CCTK_VInfo("IOBasic","Scalar: Output every %d iterations",
- myGH->outScalar_every);
- }
- }
-
+
/* re-parse the 'outScalar_vars' parameter if it was changed */
times_set = CCTK_ParameterQueryTimesSet ("outScalar_vars", CCTK_THORNSTRING);
if (times_set != outScalar_vars_lastset)
@@ -321,18 +307,6 @@ static void CheckSteerableParameters (iobasicGH *myGH)
CCTK_TraverseString (outScalar_vars, SetOutputFlag, myGH->do_outScalar,
CCTK_GROUP_OR_VAR);
- if (CCTK_Equals(newverbose,"full"))
- {
- for (i=0;i<CCTK_NumVars();i++)
- {
- if (myGH->do_outScalar[i] > 0)
- {
- CCTK_VInfo("IOBasic","Scalar: Output requested for %s",
- CCTK_VarName(i));
- }
- }
- }
-
/* Save the last setting of 'outScalar_vars' parameter */
outScalar_vars_lastset = times_set;
}
diff --git a/src/Startup.c b/src/Startup.c
index 43637c3..b6b6068 100644
--- a/src/Startup.c
+++ b/src/Startup.c
@@ -2,90 +2,193 @@
@file Startup.c
@date Friday 18th September 1999
@author Gabrielle Allen
- @desc
- Startup routines for IOBasic.
- @enddesc
+ @desc
+ Startup routines for IOBasic.
+ @enddesc
+ @version $Id$
@@*/
-
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include "cctk.h"
#include "cctk_Parameters.h"
+#include "iobasicGH.h"
static const char *rcsid = "$Header$";
CCTK_FILEVERSION(CactusBase_IOBasic_Startup_c)
-void IOBasic_Startup (void);
-/* prototypes of functions to be registered */
-int IOBasic_OutputGH (cGH *GH);
-int IOBasic_TriggerOutput (cGH *GH, int);
-int IOBasic_TimeForOutput (cGH *GH, int);
-int IOBasic_OutputVarAs (cGH *GH, const char *var, const char *alias);
-void *IOBasic_SetupGH (tFleshConfig *config, int convergence_level, cGH *GH);
-int IOBasic_InitGH (cGH *GH);
+/********************************************************************
+ ******************** External Routines ************************
+ ********************************************************************/
+void IOBasic_Startup (void);
-int IOBasic_OutputInfoGH (cGH *GH);
-int IOBasic_TriggerOutputInfo (cGH *GH, int);
-int IOBasic_TimeForInfo (cGH *GH, int);
+/********************************************************************
+ ******************** Internal Routines ************************
+ ********************************************************************/
+static void *IOBasic_SetupGH (tFleshConfig *config,
+ int convergence_level,
+ cGH *GH);
/*@@
- @routine IOBasic_Startup
- @date Friday 18th September 1999
- @author Gabrielle Allen
- @desc
- The startup registration routine for Basic IO.
- Registers the GH extensions needed for IO and
- the registerable routines used for each method of IO.
- IO does not overload any functions.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-
+ @routine IOBasic_Startup
+ @date Friday 18th September 1999
+ @author Gabrielle Allen
+ @desc
+ The startup registration routine for IOBasic.
+ Registers the GH extensions needed for IOBasic
+ along with its setup routine.
+ @enddesc
+ @calls CCTK_RegisterGHExtensionSetupGH
@@*/
void IOBasic_Startup (void)
{
- int IOMethod;
- int IO_GHExtension;
- DECLARE_CCTK_PARAMETERS
-
if (CCTK_GHExtensionHandle ("IO") < 0)
{
CCTK_WARN (1, "Thorn IOUtil was not activated. "
- "No IOBasic IO methods will be enabled.");
+ "No IOBasic I/O methods will be enabled.");
return;
}
- IO_GHExtension = CCTK_RegisterGHExtension ("IOBasic");
- CCTK_RegisterGHExtensionSetupGH (IO_GHExtension, IOBasic_SetupGH);
- CCTK_RegisterGHExtensionInitGH (IO_GHExtension, IOBasic_InitGH);
+ CCTK_RegisterGHExtensionSetupGH (CCTK_RegisterGHExtension ("IOBasic"),
+ IOBasic_SetupGH);
+}
- /* Register the IOBasic routines as output methods */
- IOMethod = CCTK_RegisterIOMethod ("Scalar");
- CCTK_RegisterIOMethodOutputGH (IOMethod, IOBasic_OutputGH);
- CCTK_RegisterIOMethodOutputVarAs (IOMethod, IOBasic_OutputVarAs);
- CCTK_RegisterIOMethodTimeToOutput (IOMethod, IOBasic_TimeForOutput);
- CCTK_RegisterIOMethodTriggerOutput (IOMethod, IOBasic_TriggerOutput);
- IOMethod = CCTK_RegisterIOMethod ("Info");
- CCTK_RegisterIOMethodOutputGH (IOMethod, IOBasic_OutputInfoGH);
- CCTK_RegisterIOMethodTimeToOutput (IOMethod, IOBasic_TimeForInfo);
- CCTK_RegisterIOMethodTriggerOutput (IOMethod, IOBasic_TriggerOutputInfo);
+/****************************************************************************/
+/* local routines */
+/****************************************************************************/
+ /*@@
+ @routine IOBasic_SetupGH
+ @date Sat Feb 6 1999
+ @author Gabrielle Allen
+ @desc
+ Allocates and sets up IOBasic's GH extension structure
+ @enddesc
+
+ @calls CCTK_RegisterIOMethod
+ CCTK_RegisterIOMethodOutputGH
+ CCTK_RegisterIOMethodOutputVarAs
+ CCTK_RegisterIOMethodTimeToOutput
+ CCTK_RegisterIOMethodTriggerOutput
+
+ @var config
+ @vdesc the CCTK configuration as provided by the flesh
+ @vtype tFleshConfig *
+ @vio unused
+ @endvar
+ @var convergence_level
+ @vdesc the convergence level
+ @vtype int
+ @vio unused
+ @endvar
+ @var GH
+ @vdesc Pointer to CCTK grid hierarchy
+ @vtype cGH *
+ @vio in
+ @endvar
+
+ @returntype void *
+ @returndesc
+ pointer to the allocated GH extension structure
+ @endreturndesc
+@@*/
+static void *IOBasic_SetupGH (tFleshConfig *config,
+ int convergence_level,
+ cGH *GH)
+{
+ DECLARE_CCTK_PARAMETERS
+ int i;
+ iobasicGH *newGH;
+
- if (CCTK_Equals(newverbose,"standard") || CCTK_Equals(newverbose,"full"))
+ /* suppress compiler warnings about unused variables */
+ config = config;
+ convergence_level = convergence_level;
+ GH = GH;
+
+ /* allocate the GH extension and its components */
+ newGH = (iobasicGH *) malloc (sizeof (iobasicGH));
+ if (newGH)
{
- CCTK_INFO("IO Method <Scalar> registered");
- CCTK_INFO("Scalar: Output of scalar quantities "
- "(grid scalars, reductions) to ASCII file");
- CCTK_INFO("IO Method <Info> registered");
- CCTK_INFO("Info: Output of reductions of grid functions to screen");
+ /* Register the IOBasic routines as output methods */
+ i = CCTK_RegisterIOMethod ("Scalar");
+ CCTK_RegisterIOMethodOutputGH (i, IOBasic_ScalarOutputGH);
+ CCTK_RegisterIOMethodOutputVarAs (i, IOBasic_ScalarOutputVarAs);
+ CCTK_RegisterIOMethodTimeToOutput (i, IOBasic_TimeForScalarOutput);
+ CCTK_RegisterIOMethodTriggerOutput (i, IOBasic_TriggerScalarOutput);
+
+ i = CCTK_RegisterIOMethod ("Info");
+ CCTK_RegisterIOMethodOutputGH (i, IOBasic_InfoOutputGH);
+ CCTK_RegisterIOMethodTimeToOutput (i, IOBasic_TimeForInfoOutput);
+ CCTK_RegisterIOMethodTriggerOutput (i, IOBasic_TriggerInfoOutput);
+
+ if (CCTK_Equals (newverbose, "standard") ||
+ CCTK_Equals( newverbose, "full"))
+ {
+ CCTK_INFO ("I/O Method 'Scalar' registered");
+ CCTK_INFO ("Scalar: Output of scalar quantities (grid scalars, "
+ "reductions) to ASCII files");
+ CCTK_INFO ("I/O Method 'Info' registered");
+ CCTK_INFO ("Info: Output of scalar quantities (grid scalars, "
+ "reductions) to screen");
+ }
+
+ i = CCTK_NumVars ();
+
+ newGH->info_reductions = (iobasic_reductionlist_t *)
+ calloc (i, sizeof (iobasic_reductionlist_t));
+ newGH->do_outScalar = (char *) malloc (i * sizeof (char));
+ newGH->outInfo_last = (int *) malloc (i * sizeof (int));
+ newGH->outScalar_last = (int *) malloc (i * sizeof (int));
+
+ memset (newGH->outInfo_last, -1, i * sizeof (int));
+ memset (newGH->outScalar_last, -1, i * sizeof (int));
+
+ newGH->filenameListScalar = NULL;
+
+ /* Check whether "IOBasic::outdirScalar" was set.
+ If so take this dir otherwise default to "IO::outdir" */
+ if (CCTK_ParameterQueryTimesSet ("outdirScalar", CCTK_THORNSTRING) <= 0)
+ {
+ outdirScalar = outdir;
+ }
+ /* skip the directory pathname if output goes into current directory */
+ if (strcmp (outdirScalar, "."))
+ {
+ i = strlen (outdirScalar);
+ newGH->outdirScalar = (char *) malloc (i + 2);
+ strcpy (newGH->outdirScalar, outdirScalar);
+ newGH->outdirScalar[i] = '/';
+ newGH->outdirScalar[i+1] = 0;
+ }
+ else
+ {
+ newGH->outdirScalar = "";
+ }
+
+ /* create the output dir */
+ if (*newGH->outdirScalar && CCTK_MyProc (GH) == 0)
+ {
+ i = CCTK_CreateDirectory (0755, newGH->outdirScalar);
+ if (i < 0)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOBasic_SetupGH: Couldn't create Scalar output directory "
+ "'%s'", newGH->outdirScalar);
+ }
+ else if (i > 0)
+ {
+ CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOBasic_InitGH: Scalar output directory '%s' already "
+ "exists", newGH->outdirScalar);
+ }
+ }
}
-
+
+ return (newGH);
}
diff --git a/src/Write.c b/src/Write.c
deleted file mode 100644
index ba1a4c4..0000000
--- a/src/Write.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/*@@
- @routine Write.c
- @date 18th September 1999
- @author Gabrielle Allen
- @desc
- Writes scalar grid variable data.
- @enddesc
- @calls
- @calledby
- @history
- @hauthor @hdate
- @hdesc
- @hendhistory
-@@*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h> /* strlen(3) */
-#include <sys/types.h>
-#include <sys/stat.h> /* stat(2) */
-
-#include "cctk.h"
-#include "cctk_Parameters.h"
-#include "CactusBase/IOUtil/src/ioutil_AdvertisedFiles.h"
-#include "CactusBase/IOUtil/src/ioutil_CheckpointRecovery.h"
-#include "iobasicGH.h"
-
-static const char *rcsid = "$Header$";
-
-CCTK_FILEVERSION(CactusBase_IOBasic_Write_c)
-
-void IOBasic_Write (cGH *GH, int vindex, const char *alias)
-{
- DECLARE_CCTK_PARAMETERS
- char *openmode;
- FILE *file;
- void *data;
- char *fname, buffer[128];
- iobasicGH *myGH;
- char format_str_real[15], format_str_int[15];
- struct stat fileinfo;
-
-
- /* output is done by processor 0 only */
- if (CCTK_MyProc (GH) != 0)
- {
- return;
- }
-
- /* first, check if variable has storage assigned */
- if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (vindex)))
- {
- char *fullname;
-
- fullname = CCTK_FullName (vindex);
- CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOBasic_Write: No scalar output for '%s' (no storage)",
- fullname);
- free (fullname);
- return;
- }
-
- /* set the output format string for the desired notation */
- sprintf (format_str_real, "%%%s\t%%%s\n", out_format, out_format);
- sprintf (format_str_int, "%%%s\t%%d\n", out_format);
-
- /* get the GH extensions for IOBasic */
- myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")];
-
- /* build the output filename */
- /* skip the pathname if output goes into current directory */
- fname = (char *) malloc (strlen (myGH->outdirScalar) + strlen (alias) + 5);
- if (strcmp (myGH->outdirScalar, "."))
- {
- sprintf (fname, "%s/%s.tl", myGH->outdirScalar, alias);
- }
- else
- {
- sprintf (fname, "%s.tl", alias);
- }
-
- /* see if output files for this alias name were already created */
- if (GetNamedData (myGH->filenameListScalar, fname) == NULL)
- {
- /* if restart from recovery, all existing files are opened
- in append mode */
- if (IOUtil_RestartFromRecovery (GH))
- openmode = stat (fname, &fileinfo) == 0 ? "a" : "w";
- else
- openmode = "w";
- }
- else
- {
- openmode = "a";
- }
-
- /* open the output file with the given mode */
- file = fopen (fname, openmode);
- if (file == NULL)
- {
- CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Could not open output file '%s'", fname);
- free (fname);
- return;
- }
-
- if (*openmode == 'w')
- {
- char comment_char;
- ioAdvertisedFileDesc advertised_file;
-
- if (CCTK_Equals (outScalar_style, "gnuplot"))
- {
- comment_char = '#';
- advertised_file.mimetype = "application/gnuplot";
- }
- else
- {
- comment_char = '"'; /* this is for xgraph */
- advertised_file.mimetype = "application/x-graph";
- }
-
- /* just store a non-NULL pointer in database */
- StoreNamedData (&myGH->filenameListScalar, fname, (void *) 1);
-
- /* advertise the file for downloading */
- advertised_file.slice = "tl";
- advertised_file.thorn = CCTK_THORNSTRING;
- advertised_file.varname = CCTK_FullName (vindex);
- advertised_file.description = "Scalar value";
-
- IOUtil_AdvertiseFile (GH, fname, &advertised_file);
-
- /* write the file info and the header */
- if (CCTK_Equals (out_fileinfo, "parameter filename") ||
- CCTK_Equals (out_fileinfo, "all"))
- {
- buffer[0] = 0;
- CCTK_ParameterFilename (sizeof (buffer), buffer);
- fprintf (file, "%cParameter file %s\n", comment_char, buffer);
- }
- if (CCTK_Equals (out_fileinfo, "creation date") ||
- CCTK_Equals (out_fileinfo, "all"))
- {
- buffer[0] = 0;
- Util_CurrentDate (sizeof (buffer), buffer);
- fprintf (file, "%cCreated %s ", comment_char, buffer);
- Util_CurrentTime (sizeof (buffer), buffer);
- fprintf (file, "%s\n", buffer);
- }
- if (CCTK_Equals (out_fileinfo, "axis labels") ||
- CCTK_Equals (out_fileinfo, "all"))
- {
- fprintf (file, "%cx-label time\n", comment_char);
- fprintf (file, "%cy-label %s\n", comment_char, advertised_file.varname);
- }
- fprintf (file, "%c%s v time\n", comment_char, alias);
-
- free (advertised_file.varname);
- }
-
- /* get the data pointer */
- data = CCTK_VarDataPtrI (GH, 0, vindex);
-
- switch (CCTK_VarTypeI (vindex))
- {
- case CCTK_VARIABLE_REAL:
- fprintf (file, format_str_real, GH->cctk_time,
- (double) *(CCTK_REAL *) data);
- break;
- case CCTK_VARIABLE_INT:
- fprintf (file, format_str_int, GH->cctk_time,
- (int) *(CCTK_INT *) data);
- break;
- default:
- CCTK_WARN (3, "Unsupported data type");
- break;
- }
-
- /* close the output file */
- fclose (file);
-
- /* clean up */
- free (fname);
-}
diff --git a/src/WriteGF.c b/src/WriteGF.c
deleted file mode 100644
index ef7378b..0000000
--- a/src/WriteGF.c
+++ /dev/null
@@ -1,306 +0,0 @@
-/*@@
- @routine WriteGF
- @date Tue Apr 1 16:45:35 1997
- @author Paul Walker
- @desc
- Dumps the scalar data of CCTK_ARRAY and CCTK_GF variables.
- @enddesc
- @version $Id$
-@@*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h> /* strlen(3) */
-#include <ctype.h> /* isalpha(3) */
-#include <sys/types.h>
-#include <sys/stat.h> /* stat(2) */
-
-#include "cctk.h"
-#include "cctk_Parameters.h"
-#include "CactusBase/IOUtil/src/ioutil_AdvertisedFiles.h"
-#include "CactusBase/IOUtil/src/ioutil_CheckpointRecovery.h"
-#include "iobasicGH.h"
-
-
-/* the rcs ID and its dummy function to use it */
-static const char *rcsid = "$Id$";
-CCTK_FILEVERSION(CactusBase_IOBasic_WriteGF_c)
-
-
- /*@@
- @routine IOBasic_WriteGF
- @date Mon Jun 19 2000
- @author Thomas Radke
- @desc
- Apply the given reduction operators on the CCTK_ARRAY or
- CCTK_GF variable and output the result into a text file
- suitable for postprocessing by either gluplot or xgraph.
- @enddesc
-
- @calls CCTK_QueryGroupStorageI
- CCTK_Reduce
- CCTK_ReductionHandle
- IOUtil_RestartFromRecovery
- IOUtil_AdvertiseFile
-
- @var GH
- @vdesc Pointer to CCTK grid hierarchy
- @vtype cGH *
- @vio in
- @endvar
- @var vindex
- @vdesc CCTK index of the variable to output
- @vtype int
- @vio in
- @endvar
- @var alias
- @vdesc alias name to use for building the output filename
- @vtype const char *
- @vio in
- @endvar
-@@*/
-void IOBasic_WriteGF (cGH *GH,
- int vindex,
- const char *alias)
-{
- DECLARE_CCTK_PARAMETERS
- int ierr;
- int reduction_handle;
- iobasicGH *myGH;
- FILE *file;
- char *openmode;
- char *filename;
- char *reduction_op;
- char *string_start;
- char *string_end;
- char comment_char;
- char format_str[15];
- const char *file_extension;
- char *fullname, buffer[128];
- struct stat fileinfo;
- ioAdvertisedFileDesc advertised_file;
- CCTK_REAL reduction_value;
- union
- {
- char *non_const_ptr;
- const char *const_ptr;
- } reductions;
-
-
- /* this union helps us to avoid compiler warning about discarding
- the const qualifier from a pointer target type */
- reductions.const_ptr = outScalar_reductions;
-
- /* first, check if variable has storage assigned */
- if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (vindex)))
- {
- fullname = CCTK_FullName (vindex);
- CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOBasic_WriteGF: No scalar output for '%s' (no storage)",
- fullname);
- free (fullname);
- return;
- }
-
- /* set output format */
- sprintf (format_str, "%%%s\t%%%s\n", out_format, out_format);
-
- /* set the output file extension and the output style */
- if (CCTK_Equals (outScalar_style, "gnuplot"))
- {
- file_extension = ".asc";
- comment_char = '#';
- }
- else
- {
- file_extension = ".xg";
- comment_char = '"';
- }
-
- /* get the GH extension handle for IOBasic */
- myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
-
- /* allocate strings for the filename and the reduction operator */
- filename = (char *) malloc (strlen (myGH->outdirScalar) + strlen (alias) +
- strlen (reductions.const_ptr) +
- strlen (file_extension) + 3);
- reduction_op = (char *) malloc (strlen (reductions.const_ptr) + 1);
-
- /* now loop over all reduction operators */
- string_start = reductions.non_const_ptr;
- while (string_start && *string_start)
- {
- /* skip leading spaces */
- while (isspace (*string_start))
- {
- string_start++;
- }
- if (! *string_start)
- {
- break;
- }
-
- /* advance to end of the operator string */
- string_end = string_start + 1;
- while (*string_end && ! isspace (*string_end))
- {
- string_end++;
- }
-
- /* copy the operator string */
- strncpy (reduction_op, string_start, string_end - string_start);
- reduction_op[string_end - string_start] = 0;
- string_start = string_end;
-
- /* get the reduction handle from the reduction operator */
- reduction_handle = CCTK_ReductionHandle (reduction_op);
- if (reduction_handle < 0)
- {
- CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOBasic_WriteGF: Invalid reduction operator '%s'",
- reduction_op);
- continue;
- }
-
- /* do the reduction (all processors) */
- ierr = CCTK_Reduce (GH, 0, reduction_handle, 1, CCTK_VARIABLE_REAL,
- &reduction_value, 1, vindex);
-
- /* dump the reduction value to file by processor 0 */
- if (ierr == 0 && CCTK_MyProc (GH) == 0)
- {
-
- /* build the filename */
- if (new_filename_scheme)
- {
- /* skip the pathname if output goes into current directory */
- if (strcmp (myGH->outdirScalar, "."))
- {
- sprintf (filename, "%s/%s_%s%s", myGH->outdirScalar, alias,
- reduction_op, file_extension);
- }
- else
- {
- sprintf (filename, "%s_%s%s", alias, reduction_op, file_extension);
- }
- }
- else
- {
- /* FIXME: this check can go if we switch to the new filename scheme */
- if (strcmp (reduction_op, "minimum") == 0)
- {
- file_extension = "min";
- }
- else if (strcmp (reduction_op, "maximum") == 0)
- {
- file_extension = "max";
- }
- else if (strcmp (reduction_op, "norm1") == 0)
- {
- file_extension = "nm1";
- }
- else if (strcmp (reduction_op, "norm2") == 0)
- {
- file_extension = "nm2";
- }
- else
- {
- file_extension = "unknown";
- }
- /* skip the pathname if output goes into current directory */
- if (strcmp (myGH->outdirScalar, "."))
- {
- sprintf (filename, "%s/%s_%s.tl", myGH->outdirScalar, alias,
- file_extension);
- }
- else
- {
- sprintf (filename, "%s_%s.tl", alias, file_extension);
- }
- }
-
- /* see if output files for this alias name were already created */
- if (GetNamedData (myGH->filenameListScalar, filename) == NULL)
- {
- /* if restart from recovery, all existing files are opened
- in append mode */
- if (IOUtil_RestartFromRecovery (GH))
- {
- openmode = stat (filename, &fileinfo) == 0 ? "a" : "w";
- }
- else
- {
- openmode = "w";
- }
- }
- else
- {
- openmode = "a";
- }
-
- file = fopen (filename, openmode);
- if (file == NULL)
- {
- CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOBasic_WriteGF: Could not open output file '%s'",
- filename);
- continue;
- }
-
- /* when creating the file, advertise it for downloading,
- write the header and the file info,
- and save the filename in the database */
- if (*openmode == 'w')
- {
- /* advertise the file for downloading */
- advertised_file.slice = reduction_op;
- advertised_file.thorn = CCTK_THORNSTRING;
- advertised_file.varname = CCTK_FullName (vindex);
- advertised_file.description = "Reduction on Grid Functions";
- advertised_file.mimetype = CCTK_Equals (outScalar_style, "gnuplot") ?
- "application/gnuplot" : "application/x-graph";
-
- IOUtil_AdvertiseFile (GH, filename, &advertised_file);
-
- if (CCTK_Equals (out_fileinfo, "parameter filename") ||
- CCTK_Equals (out_fileinfo, "all"))
- {
- buffer[0] = 0;
- CCTK_ParameterFilename (sizeof (buffer), buffer);
- fprintf (file, "%cParameter file %s\n", comment_char, buffer);
- }
- if (CCTK_Equals (out_fileinfo, "creation date") ||
- CCTK_Equals (out_fileinfo, "all"))
- {
- buffer[0] = 0;
- Util_CurrentDate (sizeof (buffer), buffer);
- fprintf (file, "%cCreated %s ", comment_char, buffer);
- Util_CurrentTime (sizeof (buffer), buffer);
- fprintf (file, "%s\n", buffer);
- }
- if (CCTK_Equals (out_fileinfo, "axis labels") ||
- CCTK_Equals (out_fileinfo, "all"))
- {
- fprintf (file, "%cx-label time\n", comment_char);
- fprintf (file, "%cy-label %s\n",
- comment_char, advertised_file.varname);
- }
- fprintf (file, "%c%s %s v time\n", comment_char, alias,
- reduction_op);
-
- free (advertised_file.varname);
-
- /* just store a non-NULL pointer in database */
- StoreNamedData (&myGH->filenameListScalar, filename, (void *) 1);
- }
-
- /* write the data and close the file */
- fprintf (file, format_str, GH->cctk_time, reduction_value);
- fclose (file);
- }
- }
-
- /* free allocated resources */
- free (reduction_op);
- free (filename);
-}
diff --git a/src/WriteInfo.c b/src/WriteInfo.c
index 4c22f9e..3345161 100644
--- a/src/WriteInfo.c
+++ b/src/WriteInfo.c
@@ -1,71 +1,168 @@
/*@@
- @routine WriteInfo
- @date June 31 1999
- @author Gabrielle Allen, Paul Walker
- @desc
- Dumps the Info data.
- @enddesc
- @calls
- @calledby
- @history
- @hauthor Thomas Radke @hdate 17 Mar 1999
- @hdesc included "cctk_Comm.h" to overload CCTK_MyProc() properly
- @hendhistory
+ @file WriteInfo.c
+ @date June 31 1999
+ @author Gabrielle Allen, Paul Walker, Thomas Radke
+ @desc
+ Gets the data for IOBasic's info output.
+ @enddesc
+ @version $Id: /cactusdevcvs/CactusBase/IOBasic/src/OutputInfo.c,v 1.24 2001
@@*/
-#include <stdio.h>
#include <stdlib.h>
#include "cctk.h"
+#include "iobasicGH.h"
+/* the rcs ID and its dummy function to use it */
static const char *rcsid = "$Header$";
-
CCTK_FILEVERSION(CactusBase_IOBasic_WriteInfo_c)
-int IOBasic_WriteInfo (cGH *GH,
- CCTK_REAL *val,
- int index,
- const char *operator,
- const char *alias)
+
+ /*@@
+ @routine IOBasic_WriteInfo
+ @date Tue 31 July 2001
+ @author Thomas Radke
+ @desc
+ Gets the data values to output for a given CCTK variable.
+ For CCTK_SCALAR variables, their value is taken,
+ for CCTK_GF and CCTK_ARRAY variables the appropriate
+ reduction operations are performed and their results taken.
+ @enddesc
+
+ @calls CCTK_VarDataPtrI
+ CCTK_Reduce
+@@*/
+void IOBasic_WriteInfo (cGH *GH, int vindex)
{
- int ierr;
- int reduce_handle;
- int retval = 0;
+ int vtype;
+ char *fullname;
+ iobasicGH *myGH;
+ void *ptr;
+ iobasic_reduction_t *reduction;
+
+
+ myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
+ reduction = myGH->info_reductions[vindex].reductions;
/* first, check if variable has storage assigned */
- if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (index)))
+ if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (vindex)))
{
- char *fullname;
-
- fullname = CCTK_FullName (index);
+ fullname = CCTK_FullName (vindex);
CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOBasic_WriteInfo: No info output for '%s' (no storage)",
+ "IOBasic_WriteInfo: No info output for '%s' (no storage)",
fullname);
free (fullname);
- return -3;
+ /* invalidate data buffer for this variable */
+ while (reduction)
+ {
+ reduction->is_valid = 0;
+ reduction = reduction->next;
+ }
+ return;
}
- reduce_handle = CCTK_ReductionHandle(operator);
-
- if (reduce_handle > -1)
+ /* CCTK scalars are printed by their value, cast into a C double */
+ if (CCTK_GroupTypeFromVarI (vindex) == CCTK_SCALAR)
{
- ierr = CCTK_Reduce(GH, 0, reduce_handle, 1, CCTK_VARIABLE_REAL, val,
- 1, index);
- if (ierr < 0)
+ reduction->is_valid = 1;
+
+ /* get the variable's data type and data pointer */
+ ptr = CCTK_VarDataPtrI (GH, 0, vindex);
+ vtype = CCTK_VarTypeI (vindex);
+ if (vtype == CCTK_VARIABLE_CHAR)
+ {
+ reduction->value = (double) *(CCTK_CHAR *) ptr;
+ }
+ else if (vtype == CCTK_VARIABLE_INT)
+ {
+ reduction->value = (double) *(CCTK_INT *) ptr;
+ }
+ else if (vtype == CCTK_VARIABLE_REAL)
+ {
+ reduction->value = (double) *(CCTK_REAL *) ptr;
+ }
+ else if (vtype == CCTK_VARIABLE_COMPLEX)
+ {
+ reduction->value = (double) ((CCTK_REAL *) ptr)[0];
+ reduction->next->value = (double) ((CCTK_REAL *) ptr)[1];
+ reduction->next->is_valid = 1;
+ }
+#ifdef CCTK_INT2
+ else if (vtype == CCTK_VARIABLE_INT2)
+ {
+ reduction->value = (double) *(CCTK_INT2 *) ptr;
+ }
+#endif
+#ifdef CCTK_INT4
+ else if (vtype == CCTK_VARIABLE_INT4)
{
- CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOBasic_WriteInfo: Internal error in reduction '%s'",
- operator);
- retval = -2;
+ reduction->value = (double) *(CCTK_INT4 *) ptr;
+ }
+#endif
+#ifdef CCTK_INT8
+ else if (vtype == CCTK_VARIABLE_INT8)
+ {
+ reduction->value = (double) *(CCTK_INT8 *) ptr;
+ }
+#endif
+#ifdef CCTK_REAL4
+ else if (vtype == CCTK_VARIABLE_REAL4)
+ {
+ reduction->value = (double) *(CCTK_REAL4 *) ptr;
+ }
+ else if (vtype == CCTK_VARIABLE_COMPLEX8)
+ {
+ reduction->value = (double) ((CCTK_REAL4 *) ptr)[0];
+ reduction->next->value = (double) ((CCTK_REAL4 *) ptr)[1];
+ reduction->next->is_valid = 1;
+ }
+#endif
+#ifdef CCTK_REAL8
+ else if (vtype == CCTK_VARIABLE_REAL8)
+ {
+ reduction->value = (double) *(CCTK_REAL8 *) ptr;
+ }
+ else if (vtype == CCTK_VARIABLE_COMPLEX16)
+ {
+ reduction->value = (double) ((CCTK_REAL8 *) ptr)[0];
+ reduction->next->value = (double) ((CCTK_REAL8 *) ptr)[1];
+ reduction->next->is_valid = 1;
+ }
+#endif
+#ifdef CCTK_REAL16
+ else if (vtype == CCTK_VARIABLE_REAL16)
+ {
+ reduction->value = (double) *(CCTK_REAL16 *) ptr;
+ }
+ else if (vtype == CCTK_VARIABLE_COMPLEX32)
+ {
+ reduction->value = (double) ((CCTK_REAL16 *) ptr)[0];
+ reduction->next->value = (double) ((CCTK_REAL16 *) ptr)[1];
+ reduction->next->is_valid = 1;
+ }
+#endif
+ else
+ {
+ CCTK_WARN (3, "IOBasic_WriteInfo: Unsupported data type");
+ reduction->is_valid = 0;
}
}
else
{
- CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOBasic_WriteInfo: Reduction operator '%s' not found",
- operator);
- retval = -1;
- }
+ /* for CCTK_GF and CCTK_ARRAY variables: loop over all reductions */
+ while (reduction)
+ {
+ reduction->is_valid = CCTK_Reduce (GH, 0, reduction->handle, 1,
+ CCTK_VARIABLE_REAL,
+ &reduction->value, 1, vindex) == 0;
+ if (! reduction->is_valid)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOBasic_WriteInfo: Internal error in reduction '%s'",
+ reduction->name);
+ }
- return retval;
+ reduction = reduction->next;
+ }
+ }
}
diff --git a/src/WriteScalar.c b/src/WriteScalar.c
new file mode 100644
index 0000000..8528bb8
--- /dev/null
+++ b/src/WriteScalar.c
@@ -0,0 +1,416 @@
+/*@@
+ @routine WriteScalar.c
+ @date 18th September 1999
+ @author Gabrielle Allen
+ @desc
+ Dumps data for IOBasic's "Scalar" I/O method to output files
+ @enddesc
+@@*/
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h> /* strlen(3) */
+#include <sys/types.h>
+#include <sys/stat.h> /* stat(2) */
+
+#include "cctk.h"
+#include "cctk_Parameters.h"
+#include "CactusBase/IOUtil/src/ioutil_AdvertisedFiles.h"
+#include "CactusBase/IOUtil/src/ioutil_CheckpointRecovery.h"
+#include "iobasicGH.h"
+
+static const char *rcsid = "$Header$";
+
+CCTK_FILEVERSION(CactusBase_IOBasic_WriteScalar_c)
+
+
+static FILE *OpenScalarFile (cGH *GH,
+ int vindex,
+ const char *filename,
+ const char *slicename,
+ const char *description,
+ const char *aliasname);
+
+ /*@@
+ @routine IOBasic_WriteScalarGA
+ @date Mon Jun 19 2000
+ @author Thomas Radke
+ @desc
+ Apply the given reduction operators on the CCTK_ARRAY or
+ CCTK_GF variable and output the result into a text file
+ suitable for postprocessing by either gluplot or xgraph.
+ @enddesc
+
+ @calls CCTK_QueryGroupStorageI
+ CCTK_Reduce
+ CCTK_ReductionHandle
+ IOUtil_RestartFromRecovery
+ IOUtil_AdvertiseFile
+
+ @var GH
+ @vdesc Pointer to CCTK grid hierarchy
+ @vtype cGH *
+ @vio in
+ @endvar
+ @var vindex
+ @vdesc CCTK index of the variable to output
+ @vtype int
+ @vio in
+ @endvar
+ @var alias
+ @vdesc alias name to use for building the output filename
+ @vtype const char *
+ @vio in
+ @endvar
+@@*/
+void IOBasic_WriteScalarGA (cGH *GH,
+ int vindex,
+ const char *alias)
+{
+ DECLARE_CCTK_PARAMETERS
+ int ierr;
+ int reduction_handle;
+ iobasicGH *myGH;
+ FILE *file;
+ char *filename;
+ char *reduction_op;
+ char *string_start;
+ char *string_end;
+ char format_str[15];
+ const char *file_extension;
+ char *fullname;
+ CCTK_REAL reduction_value;
+ union
+ {
+ char *non_const_ptr;
+ const char *const_ptr;
+ } reductions;
+
+
+ /* this union helps us to avoid compiler warning about discarding
+ the const qualifier from a pointer target type */
+ reductions.const_ptr = outScalar_reductions;
+
+ /* first, check if variable has storage assigned */
+ if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (vindex)))
+ {
+ fullname = CCTK_FullName (vindex);
+ CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOBasic_WriteScalarGA: No scalar output for '%s' (no storage)",
+ fullname);
+ free (fullname);
+ return;
+ }
+
+ /* set output format */
+ sprintf (format_str, "%%%s\t%%%s\n", out_format, out_format);
+
+ /* set the output file extension and the output style */
+ file_extension = CCTK_Equals (outScalar_style, "gnuplot") ? ".asc" : ".xg";
+
+ /* get the GH extension handle for IOBasic */
+ myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
+
+ /* allocate strings for the filename and the reduction operator */
+ filename = (char *) malloc (strlen (myGH->outdirScalar) + strlen (alias) +
+ strlen (reductions.const_ptr) +
+ strlen (file_extension) + 3);
+ reduction_op = (char *) malloc (strlen (reductions.const_ptr) + 1);
+
+ /* now loop over all reduction operators */
+ string_start = reductions.non_const_ptr;
+ while (string_start && *string_start)
+ {
+ /* skip leading spaces */
+ while (isspace ((int) *string_start))
+ {
+ string_start++;
+ }
+ if (! *string_start)
+ {
+ break;
+ }
+
+ /* advance to end of the operator string */
+ string_end = string_start + 1;
+ while (*string_end && ! isspace ((int) *string_end))
+ {
+ string_end++;
+ }
+
+ /* copy the operator string */
+ strncpy (reduction_op, string_start, string_end - string_start);
+ reduction_op[string_end - string_start] = 0;
+ string_start = string_end;
+
+ /* get the reduction handle from the reduction operator */
+ reduction_handle = CCTK_ReductionHandle (reduction_op);
+ if (reduction_handle < 0)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOBasic_WriteScalarGA: Invalid reduction operator '%s'",
+ reduction_op);
+ continue;
+ }
+
+ /* do the reduction (all processors) */
+ ierr = CCTK_Reduce (GH, 0, reduction_handle, 1, CCTK_VARIABLE_REAL,
+ &reduction_value, 1, vindex);
+
+ /* dump the reduction value to file by processor 0 */
+ if (ierr == 0 && CCTK_MyProc (GH) == 0)
+ {
+
+ /* build the filename */
+ if (new_filename_scheme)
+ {
+ sprintf (filename, "%s%s_%s%s", myGH->outdirScalar, alias,
+ reduction_op, file_extension);
+ }
+ else
+ {
+ /* FIXME: this check can go if we switch to the new filename scheme */
+ if (strcmp (reduction_op, "minimum") == 0)
+ {
+ file_extension = "min";
+ }
+ else if (strcmp (reduction_op, "maximum") == 0)
+ {
+ file_extension = "max";
+ }
+ else if (strcmp (reduction_op, "norm1") == 0)
+ {
+ file_extension = "nm1";
+ }
+ else if (strcmp (reduction_op, "norm2") == 0)
+ {
+ file_extension = "nm2";
+ }
+ else
+ {
+ file_extension = "unknown";
+ }
+ sprintf (filename, "%s%s_%s.tl", myGH->outdirScalar, alias,
+ file_extension);
+ }
+
+ file = OpenScalarFile (GH, vindex, filename, reduction_op,
+ "Reduction on Grid Arrays", alias);
+ if (file)
+ {
+ /* write the data and close the file */
+ fprintf (file, format_str, GH->cctk_time, reduction_value);
+ fclose (file);
+ }
+ else
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOBasic_WriteScalarGA: Could not open output file '%s'",
+ filename);
+ }
+ }
+ }
+
+ /* free allocated resources */
+ free (reduction_op);
+ free (filename);
+}
+
+
+ /*@@
+ @routine IOBasic_WriteScalarGS
+ @date Mon Jun 19 2000
+ @author Thomas Radke
+ @desc
+ Output the value of a CCTK_SCALAR variable into an ASCII file
+ suitable for postprocessing by either gluplot or xgraph.
+ @enddesc
+
+ @calls CCTK_QueryGroupStorageI
+ CCTK_Reduce
+ CCTK_ReductionHandle
+ IOUtil_RestartFromRecovery
+ IOUtil_AdvertiseFile
+
+ @var GH
+ @vdesc Pointer to CCTK grid hierarchy
+ @vtype cGH *
+ @vio in
+ @endvar
+ @var vindex
+ @vdesc CCTK index of the variable to output
+ @vtype int
+ @vio in
+ @endvar
+ @var alias
+ @vdesc alias name to use for building the output filename
+ @vtype const char *
+ @vio in
+ @endvar
+@@*/
+void IOBasic_WriteScalarGS (cGH *GH, int vindex, const char *alias)
+{
+ DECLARE_CCTK_PARAMETERS
+ FILE *file;
+ void *data;
+ iobasicGH *myGH;
+ char *fullname, *filename;
+ char format_str_real[15], format_str_int[15];
+
+
+ /* output is done by processor 0 only */
+ if (CCTK_MyProc (GH) != 0)
+ {
+ return;
+ }
+
+ /* first, check if variable has storage assigned */
+ if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (vindex)))
+ {
+ fullname = CCTK_FullName (vindex);
+ CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOBasic_WriteScalarGS: No scalar output for '%s' (no storage)",
+ fullname);
+ free (fullname);
+ return;
+ }
+
+ /* set the output format string for the desired notation */
+ sprintf (format_str_real, "%%%s\t%%%s\n", out_format, out_format);
+ sprintf (format_str_int, "%%%s\t%%d\n", out_format);
+
+ /* get the GH extensions for IOBasic */
+ myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
+
+ /* build the output filename */
+ filename = (char *) malloc (strlen (myGH->outdirScalar) + strlen (alias) + 4);
+ sprintf (filename, "%s%s.tl", myGH->outdirScalar, alias);
+
+ file = OpenScalarFile (GH, vindex, filename, "tl", "Scalar value", alias);
+ if (file)
+ {
+ /* get the data pointer */
+ data = CCTK_VarDataPtrI (GH, 0, vindex);
+
+ switch (CCTK_VarTypeI (vindex))
+ {
+ case CCTK_VARIABLE_REAL:
+ fprintf (file, format_str_real, GH->cctk_time,
+ (double) *(CCTK_REAL *) data);
+ break;
+ case CCTK_VARIABLE_INT:
+ fprintf (file, format_str_int, GH->cctk_time,
+ (int) *(CCTK_INT *) data);
+ break;
+ default:
+ CCTK_WARN (3, "Unsupported data type");
+ break;
+ }
+
+ /* close the output file */
+ fclose (file);
+ }
+ else
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOBasic_WriteScalarGS: Could not open output file '%s'",
+ filename);
+ }
+
+ /* clean up */
+ free (filename);
+}
+
+
+static FILE *OpenScalarFile (cGH *GH,
+ int vindex,
+ const char *filename,
+ const char *slicename,
+ const char *description,
+ const char *aliasname)
+{
+ DECLARE_CCTK_PARAMETERS
+ FILE *file;
+ char comment_char, buffer[128];
+ ioAdvertisedFileDesc advertised_file;
+ iobasicGH *myGH;
+ char *openmode;
+ struct stat fileinfo;
+
+
+ /* get the GH extension handle for IOBasic */
+ myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
+
+ /* see if output files for this alias name were already created */
+ if (GetNamedData (myGH->filenameListScalar, filename) == NULL)
+ {
+ /* if restart from recovery, all existing files are opened
+ in append mode */
+ if (IOUtil_RestartFromRecovery (GH))
+ openmode = stat (filename, &fileinfo) == 0 ? "a" : "w";
+ else
+ openmode = "w";
+ }
+ else
+ {
+ openmode = "a";
+ }
+
+ /* open the output file with the given mode */
+ file = fopen (filename, openmode);
+ if (file && *openmode == 'w')
+ {
+ if (CCTK_Equals (outScalar_style, "gnuplot"))
+ {
+ comment_char = '#';
+ advertised_file.mimetype = "application/gnuplot";
+ }
+ else
+ {
+ comment_char = '"'; /* this is for xgraph */
+ advertised_file.mimetype = "application/x-graph";
+ }
+
+ /* just store a non-NULL pointer in database */
+ StoreNamedData (&myGH->filenameListScalar, filename, (void *) 1);
+
+ /* advertise the file for downloading */
+ advertised_file.slice = strdup (slicename);
+ advertised_file.thorn = CCTK_THORNSTRING;
+ advertised_file.varname = CCTK_FullName (vindex);
+ advertised_file.description = strdup (description);
+
+ IOUtil_AdvertiseFile (GH, filename, &advertised_file);
+
+ /* write the file info and the header */
+ if (CCTK_Equals (out_fileinfo, "parameter filename") ||
+ CCTK_Equals (out_fileinfo, "all"))
+ {
+ buffer[0] = 0;
+ CCTK_ParameterFilename (sizeof (buffer), buffer);
+ fprintf (file, "%cParameter file %s\n", comment_char, buffer);
+ }
+ if (CCTK_Equals (out_fileinfo, "creation date") ||
+ CCTK_Equals (out_fileinfo, "all"))
+ {
+ buffer[0] = 0;
+ Util_CurrentDate (sizeof (buffer), buffer);
+ fprintf (file, "%cCreated %s ", comment_char, buffer);
+ Util_CurrentTime (sizeof (buffer), buffer);
+ fprintf (file, "%s\n", buffer);
+ }
+ if (CCTK_Equals (out_fileinfo, "axis labels") ||
+ CCTK_Equals (out_fileinfo, "all"))
+ {
+ fprintf (file, "%cx-label time\n", comment_char);
+ fprintf (file, "%cy-label %s\n", comment_char, advertised_file.varname);
+ }
+ fprintf (file, "%c%s v time\n", comment_char, aliasname);
+
+ free (advertised_file.description);
+ free (advertised_file.varname);
+ free (advertised_file.slice);
+ }
+
+ return (file);
+}
diff --git a/src/iobasicGH.h b/src/iobasicGH.h
index fe1cb16..d9c6b9a 100644
--- a/src/iobasicGH.h
+++ b/src/iobasicGH.h
@@ -1,9 +1,9 @@
/*@@
- @header iobasic.h
+ @header iobasicGH.h
@date Friday 18th September 1999
@author Gabrielle Allen
- @desc
- The extensions to the GH structure from IOBasic.
+ @desc
+ The extensions to the GH structure from IOBasic.
@enddesc
@version $Header$
@@*/
@@ -11,25 +11,40 @@
#include "StoreNamedData.h"
-typedef struct IOBASICGH {
+typedef struct IOBASIC_REDUCTION
+{
+ int handle;
+ char *name;
+ char is_valid;
+ CCTK_REAL value;
+ struct IOBASIC_REDUCTION *next;
+} iobasic_reduction_t;
+typedef struct IOBASIC_REDUCTIONLIST
+{
+ unsigned int num_reductions;
+ iobasic_reduction_t *reductions;
+} iobasic_reductionlist_t;
+
+typedef struct IOBASIC_GH
+{
/* how often to output */
int outScalar_every;
int outInfo_every;
+ char info_reductions_changed;
- /* flags indicating output for var [i] */
- char *do_outInfo;
+ /* flags indicating output for variable i */
char *do_outScalar;
- /* directory in which to output */
+ /* directory in which to place scalar output */
char *outdirScalar;
/* The last iteration output */
int *outInfo_last;
int *outScalar_last;
- /* The values for info */
- CCTK_REAL **infovals;
+ /* The reduction lists for info output for all variables */
+ iobasic_reductionlist_t *info_reductions;
/* database for names of output files that were already created */
pNamedData *filenameListScalar;
@@ -37,7 +52,16 @@ typedef struct IOBASICGH {
} iobasicGH;
-/* function prototypes */
-void IOBasic_Write (cGH *GH, int vindex, const char *alias);
-void IOBasic_WriteGF (cGH *GH, int vindex, const char *alias);
-int IOBasic_WriteInfo (cGH *GH, CCTK_REAL *val,int vindex, const char *operator, const char *alias);
+/* prototypes of functions to be registered */
+int IOBasic_InfoOutputGH (cGH *GH);
+int IOBasic_TriggerInfoOutput (cGH *GH, int vindex);
+int IOBasic_TimeForInfoOutput (cGH *GH, int vindex);
+int IOBasic_ScalarOutputGH (cGH *GH);
+int IOBasic_TriggerScalarOutput (cGH *GH, int vindex);
+int IOBasic_TimeForScalarOutput (cGH *GH, int vindex);
+int IOBasic_ScalarOutputVarAs (cGH *GH, const char *vname, const char *alias);
+
+/* other function prototypes */
+void IOBasic_WriteInfo (cGH *GH, int vindex);
+void IOBasic_WriteScalarGS (cGH *GH, int vindex, const char *alias);
+void IOBasic_WriteScalarGA (cGH *GH, int vindex, const char *alias);
diff --git a/src/make.code.defn b/src/make.code.defn
index bf9e62d..b28bd34 100644
--- a/src/make.code.defn
+++ b/src/make.code.defn
@@ -3,13 +3,7 @@
# Source files in this directory
SRCS = Startup.c \
- GHExtension.c \
- Output.c \
+ OutputScalar.c \
OutputInfo.c \
- Write.c \
- WriteGF.c \
+ WriteScalar.c \
WriteInfo.c
-
-# Subdirectories containing source files
-SUBDIRS =
-