aboutsummaryrefslogtreecommitdiff
path: root/src/Startup.c
diff options
context:
space:
mode:
authortradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880>2002-03-16 22:04:30 +0000
committertradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880>2002-03-16 22:04:30 +0000
commitf1d419cc71594cd0e4bb2ae426af55000712bb28 (patch)
treede6cfaeaa3d576a2527aed111a7a3e4f6c2b09f9 /src/Startup.c
parent297bfb0299ddc1d6bea56c14bf898fa409fe136b (diff)
Allow individual reductions on variables by parsing the options string
in the 'IOBasic::outScalar_vars' parameter. This closes PR CactusBase/895. git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOBasic/trunk@116 b589c3ab-70e8-4b4d-a09f-cba2dd200880
Diffstat (limited to 'src/Startup.c')
-rw-r--r--src/Startup.c227
1 files changed, 201 insertions, 26 deletions
diff --git a/src/Startup.c b/src/Startup.c
index 30c6bc4..3821d86 100644
--- a/src/Startup.c
+++ b/src/Startup.c
@@ -11,6 +11,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <ctype.h>
#include "cctk.h"
#include "cctk_Parameters.h"
@@ -73,7 +74,6 @@ void IOBasic_Startup (void)
@calls CCTK_RegisterIOMethod
CCTK_RegisterIOMethodOutputGH
- CCTK_RegisterIOMethodOutputVarAs
CCTK_RegisterIOMethodTimeToOutput
CCTK_RegisterIOMethodTriggerOutput
@@ -119,7 +119,6 @@ static void *IOBasic_SetupGH (tFleshConfig *config,
/* 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);
@@ -128,8 +127,7 @@ static void *IOBasic_SetupGH (tFleshConfig *config,
CCTK_RegisterIOMethodTimeToOutput (i, IOBasic_TimeForInfoOutput);
CCTK_RegisterIOMethodTriggerOutput (i, IOBasic_TriggerInfoOutput);
- if (CCTK_Equals (newverbose, "standard") ||
- CCTK_Equals( newverbose, "full"))
+ if (! CCTK_Equals (newverbose, "none"))
{
CCTK_INFO ("I/O Method 'Scalar' registered");
CCTK_INFO ("Scalar: Output of scalar quantities (grid scalars, "
@@ -142,51 +140,61 @@ static void *IOBasic_SetupGH (tFleshConfig *config,
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));
+ calloc (2 * i, sizeof (iobasic_reductionlist_t));
+ newGH->scalar_reductions = newGH->info_reductions + i;
+ newGH->outInfo_last = (int *) malloc (2 * i * sizeof (int));
+ newGH->outScalar_last = newGH->outInfo_last + i;
- memset (newGH->outInfo_last, -1, i * sizeof (int));
- memset (newGH->outScalar_last, -1, i * sizeof (int));
+ memset (newGH->outInfo_last, -1, 2 * i * sizeof (int));
newGH->filenameListScalar = NULL;
- /* Check whether "IOBasic::outdirScalar" was set.
+ /* Check whether "IOBasic::outdir" was set.
If so take this dir otherwise default to "IO::outdir" */
- if (CCTK_ParameterQueryTimesSet ("outdirScalar", CCTK_THORNSTRING) <= 0)
+ if (CCTK_ParameterQueryTimesSet ("outdir", CCTK_THORNSTRING) > 0 ||
+ CCTK_ParameterQueryTimesSet ("outdirScalar", CCTK_THORNSTRING) > 0)
{
- outdirScalar = outdir;
+ if (CCTK_ParameterQueryTimesSet ("outdir", CCTK_THORNSTRING) <= 0)
+ {
+ CCTK_WARN (1, "Parameter 'IOBasic::outdirScalar is depricated in "
+ "BETA12, please use 'IOBasic::outdir' instead");
+ outdir = outdirScalar;
+ }
+ }
+ else
+ {
+ outdir = *(const char **)
+ CCTK_ParameterGet ("outdir", CCTK_ImplementationThorn ("IO"), &i);
}
+
/* skip the directory pathname if output goes into current directory */
- if (strcmp (outdirScalar, "."))
+ if (strcmp (outdir, "."))
{
- i = strlen (outdirScalar);
- newGH->outdirScalar = (char *) malloc (i + 2);
- strcpy (newGH->outdirScalar, outdirScalar);
- newGH->outdirScalar[i] = '/';
- newGH->outdirScalar[i+1] = 0;
+ i = strlen (outdir);
+ newGH->outdir = (char *) malloc (i + 2);
+ strcpy (newGH->outdir, outdir);
+ newGH->outdir[i] = '/';
+ newGH->outdir[i+1] = 0;
}
else
{
- newGH->outdirScalar = "";
+ newGH->outdir = "";
}
/* create the output dir */
- if (*newGH->outdirScalar && CCTK_MyProc (GH) == 0)
+ if (*newGH->outdir && CCTK_MyProc (GH) == 0)
{
- i = IOUtil_CreateDirectory (GH, newGH->outdirScalar, 0, 0);
+ i = IOUtil_CreateDirectory (GH, newGH->outdir, 0, 0);
if (i < 0)
{
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"IOBasic_SetupGH: Couldn't create Scalar output directory "
- "'%s'", newGH->outdirScalar);
+ "'%s'", newGH->outdir);
}
else if (i >= 0 && CCTK_Equals (newverbose, "full"))
{
- CCTK_VInfo (CCTK_THORNSTRING,
- "Scalar: Output to directory '%s'",
- newGH->outdirScalar);
+ CCTK_VInfo (CCTK_THORNSTRING, "Scalar: Output to directory '%s'",
+ newGH->outdir);
}
}
@@ -194,3 +202,170 @@ static void *IOBasic_SetupGH (tFleshConfig *config,
return (newGH);
}
+
+
+ /*@@
+ @routine IOBasic_AssignReductionList
+ @date Tue 31 Jul 2001
+ @author Thomas Radke
+ @desc
+ Callback routine called by CCTK_TraverseString() to set the
+ reduction list 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 the 'IOBasic::out{Info|Scalar}_reductions' parameter.
+ @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
+ @vtype void *
+ @vio in
+ @endvar
+@@*/
+void IOBasic_AssignReductionList (int vindex, const char *optstring, void *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;
+ const iobasic_parseinfo_t *info;
+
+
+ info = (const iobasic_parseinfo_t *) arg;
+ list = info->reduction_list + 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;
+ }
+
+ return;
+ }
+
+ /* initialize to empty list */
+ list->num_reductions = 0;
+ list->reductions = NULL;
+
+ if (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 (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOBasic_AssignReductionList: invalid syntax for option list "
+ "'%s'", optstring);
+ return;
+ }
+ }
+ else
+ {
+ reduction_op_list = strdup (info->reductions_string);
+ }
+
+ /* 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,
+ "IOBasic_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,
+ "IOBasic_AssignReductionList: Duplicate reduction operator "
+ "'%s' will be ignored", reduction_op);
+ continue;
+ }
+
+ *new_reduction = (iobasic_reduction_t *) malloc (sizeof (**new_reduction));
+ (*new_reduction)->handle = reduction_handle;
+ (*new_reduction)->name = strdup (reduction_op);
+ (*new_reduction)->next = NULL;
+ list->num_reductions++;
+ }
+
+ free (reduction_op_list);
+ free (reduction_op);
+}