aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880>2003-03-10 11:09:54 +0000
committertradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880>2003-03-10 11:09:54 +0000
commitc22176e9d190d0d2c5bfec8891a5a8292f6b0226 (patch)
tree34b6794a0a7684c72fa4b4b4539d14dab8cbf746
parentffc3726120bcc38a5495f248f040b571a650f4ea (diff)
Added routine IOBasic_OutputVarAs() for unconditional output of variables
using the "Scalar" I/O method. git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOBasic/trunk@141 b589c3ab-70e8-4b4d-a09f-cba2dd200880
-rw-r--r--src/OutputScalar.c105
-rw-r--r--src/Startup.c2
-rw-r--r--src/WriteScalar.c35
-rw-r--r--src/iobasicGH.h8
4 files changed, 123 insertions, 27 deletions
diff --git a/src/OutputScalar.c b/src/OutputScalar.c
index b336f49..a744164 100644
--- a/src/OutputScalar.c
+++ b/src/OutputScalar.c
@@ -57,7 +57,7 @@ int IOBasic_ScalarOutputGH (const cGH *GH)
iobasicGH *myGH;
- myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
+ myGH = CCTK_GHExtension (GH, "IOBasic");
CheckSteerableParameters (myGH);
/* return if no output is required */
@@ -84,6 +84,105 @@ int IOBasic_ScalarOutputGH (const cGH *GH)
}
+/*@@
+ @routine IOBasic_OutputVarAs
+ @date Sun 8 Mar 2003
+ @author Thomas Radke
+ @desc
+ Unconditional output of a variable using the "Scalar" I/O method
+ @enddesc
+ @calls IOBasic_WriteScalar
+
+ @var GH
+ @vdesc pointer to CCTK GH
+ @vtype const cGH *
+ @vio in
+ @endvar
+ @var fullname
+ @vdesc complete name of variable to output, maybe appended by an
+ options string
+ @vtype const char *
+ @vio in
+ @endvar
+ @var alias
+ @vdesc variable's alias name used to build the output filename
+ @vtype const char *
+ @vio in
+ @endvar
+
+ @returntype int
+ @returndesc
+ return code of @seeroutine IOBasic_WriteScalar, or<BR>
+ -1 if variable cannot be output by "Scalar"
+ @endreturndesc
+@@*/
+int IOBasic_OutputVarAs (const cGH *GH, const char *fullname, const char *alias)
+{
+ int vindex, old_num_reductions, retval;
+ char *varname, *tmp;
+ iobasic_parseinfo_t info;
+ iobasic_reduction_t *reduction, *old_reductions, *next;
+ iobasicGH *myGH;
+ DECLARE_CCTK_PARAMETERS
+
+
+ /* get the variable index from 'fullname' */
+ varname = strdup (fullname);
+ tmp = strchr (fullname, '[');
+ if (tmp)
+ {
+ varname[tmp - fullname] = 0;
+ }
+
+ vindex = CCTK_VarIndex (varname);
+ free (varname);
+ if (vindex < -1)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOBasic_OutputVarAs: invalid variable name in 'fullname' "
+ "argument '%s'", fullname);
+ return (-1);
+ }
+
+ /* save the old scalar_reductions[vindex] info ... */
+ myGH = CCTK_GHExtension (GH, "IOBasic");
+ old_num_reductions = myGH->scalar_reductions[vindex].num_reductions;
+ old_reductions = myGH->scalar_reductions[vindex].reductions;
+
+ /* ... and create a temporary one from 'fullname' */
+ retval = 0;
+ info.reduction_list = myGH->scalar_reductions;
+ info.reductions_string = outScalar_reductions;
+ if (CCTK_TraverseString (fullname, IOBasic_AssignReductionList, &info,
+ CCTK_VAR) < 0)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOBasic_OutputVarAs: failed to parse 'fullname' argument '%s'",
+ fullname);
+ retval = -1;
+ }
+ else if (myGH->scalar_reductions[vindex].num_reductions > 0)
+ {
+ /* do the actual output */
+ retval = IOBasic_WriteScalar (GH, vindex, alias);
+
+ /* free temporary scalar_reductions[vindex] info and restore the old one */
+ reduction = myGH->scalar_reductions[vindex].reductions;
+ while (reduction)
+ {
+ next = reduction->next;
+ free (reduction->name);
+ free (reduction);
+ reduction = next;
+ }
+ }
+ myGH->scalar_reductions[vindex].num_reductions = old_num_reductions;
+ myGH->scalar_reductions[vindex].reductions = old_reductions;
+
+ return (retval);
+}
+
+
/*@@
@routine IOBasic_TimeForScalarOutput
@date Sat March 6 1999
@@ -117,7 +216,7 @@ int IOBasic_TimeForScalarOutput (const cGH *GH, int vindex)
/* Get the GH extension for IOBasic */
- myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
+ myGH = CCTK_GHExtension (GH, "IOBasic");
CheckSteerableParameters (myGH);
@@ -178,7 +277,7 @@ int IOBasic_TriggerScalarOutput (const cGH *GH, int vindex)
/* Get the GH extension for IOBasic */
- myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
+ myGH = CCTK_GHExtension (GH, "IOBasic");
name = CCTK_VarName (vindex);
diff --git a/src/Startup.c b/src/Startup.c
index c27e7b5..d862003 100644
--- a/src/Startup.c
+++ b/src/Startup.c
@@ -73,6 +73,7 @@ void IOBasic_Startup (void)
@calls CCTK_RegisterIOMethod
CCTK_RegisterIOMethodOutputGH
+ CCTK_RegisterIOMethodOutputVarAs
CCTK_RegisterIOMethodTimeToOutput
CCTK_RegisterIOMethodTriggerOutput
@@ -117,6 +118,7 @@ static void *IOBasic_SetupGH (tFleshConfig *config, int conv_level, cGH *GH)
/* Register the IOBasic routines as output methods */
i = CCTK_RegisterIOMethod ("Scalar");
CCTK_RegisterIOMethodOutputGH (i, IOBasic_ScalarOutputGH);
+ CCTK_RegisterIOMethodOutputVarAs (i, IOBasic_OutputVarAs);
CCTK_RegisterIOMethodTimeToOutput (i, IOBasic_TimeForScalarOutput);
CCTK_RegisterIOMethodTriggerOutput (i, IOBasic_TriggerScalarOutput);
diff --git a/src/WriteScalar.c b/src/WriteScalar.c
index 118b48b..51986e8 100644
--- a/src/WriteScalar.c
+++ b/src/WriteScalar.c
@@ -147,19 +147,9 @@ static int IOBasic_WriteScalarGA (const cGH *GH, int vindex, const char *alias)
char format_str[15];
const char *file_extension;
iobasic_reduction_t *reduction;
- /*** FIXME: can CCTK_Reduce() have a 'const cGH *' parameter ?? ***/
- union
- {
- const cGH *const_ptr;
- cGH *non_const_ptr;
- } GH_fake_const;
DECLARE_CCTK_PARAMETERS
- /* this union helps us to avoid compiler warning about discarding
- the const qualifier from a pointer target type */
- GH_fake_const.const_ptr = GH;
-
/* set output format */
sprintf (format_str, "%%%s\t%%%s\n", out_format, out_format);
@@ -167,15 +157,14 @@ static int IOBasic_WriteScalarGA (const cGH *GH, int vindex, const char *alias)
file_extension = CCTK_Equals (outScalar_style, "gnuplot") ? ".asc" : ".xg";
/* get the GH extension handle for IOBasic */
- myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
+ myGH = CCTK_GHExtension (GH, "IOBasic");
reduction = myGH->scalar_reductions[vindex].reductions;
/* now loop over all reduction operators */
while (reduction)
{
/* do the reduction (all processors) */
- reduction->is_valid = CCTK_Reduce (GH_fake_const.non_const_ptr, 0,
- reduction->handle, 1,
+ reduction->is_valid = CCTK_Reduce (GH, 0, reduction->handle, 1,
CCTK_VARIABLE_REAL,
&reduction->value, 1, vindex) == 0;
if (! reduction->is_valid)
@@ -190,9 +179,9 @@ static int IOBasic_WriteScalarGA (const cGH *GH, int vindex, const char *alias)
if (new_filename_scheme)
{
/* allocate filename string buffer and build the filename */
- filename = (char *) malloc (strlen (myGH->out_dir) +
- strlen (alias) + strlen (reduction->name) +
- strlen (file_extension) + 2);
+ filename = malloc (strlen (myGH->out_dir) +
+ strlen (alias) + strlen (reduction->name) +
+ strlen (file_extension) + 2);
sprintf (filename, "%s%s_%s%s", myGH->out_dir, alias,
reduction->name, file_extension);
}
@@ -221,8 +210,8 @@ static int IOBasic_WriteScalarGA (const cGH *GH, int vindex, const char *alias)
}
/* allocate filename string buffer and build the filename */
- filename = (char *) malloc (strlen (myGH->out_dir) +
- strlen (alias) + strlen (file_extension)+5);
+ filename = malloc (strlen (myGH->out_dir) +
+ strlen (alias) + strlen (file_extension)+5);
sprintf (filename, "%s%s_%s.tl", myGH->out_dir, alias,
file_extension);
}
@@ -308,7 +297,7 @@ static int IOBasic_WriteScalarGS (const cGH *GH, int vindex, const char *alias)
sprintf (format_str_int, "%%%s\t%%d\n", out_format);
/* get the GH extensions for IOBasic */
- myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
+ myGH = CCTK_GHExtension (GH, "IOBasic");
/* set the output file extension according to the output style */
if (new_filename_scheme)
@@ -321,8 +310,8 @@ static int IOBasic_WriteScalarGS (const cGH *GH, int vindex, const char *alias)
}
/* build the output filename */
- filename = (char *) malloc (strlen (myGH->out_dir) + strlen (alias) +
- strlen (file_extension) + 1);
+ filename = malloc (strlen (myGH->out_dir) + strlen (alias) +
+ strlen (file_extension) + 1);
sprintf (filename, "%s%s%s", myGH->out_dir, alias, file_extension);
/* create/reopen the file */
@@ -382,8 +371,8 @@ static FILE *OpenScalarFile (const cGH *GH,
/* get the GH extension handles for IOUtil and IOBasic */
- myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
- ioUtilGH = (const ioGH *) CCTK_GHExtension (GH, "IO");
+ myGH = CCTK_GHExtension (GH, "IOBasic");
+ ioUtilGH = CCTK_GHExtension (GH, "IO");
/* get the variable's full name */
fullname = CCTK_FullName (vindex);
diff --git a/src/iobasicGH.h b/src/iobasicGH.h
index 573ccdf..a77cb0c 100644
--- a/src/iobasicGH.h
+++ b/src/iobasicGH.h
@@ -5,9 +5,12 @@
@desc
The extensions to the GH structure from IOBasic.
@enddesc
- @version $Header$
+ @version $Header$
@@*/
+#ifndef _IOBASIC_IOBASICGH_H_
+#define _IOBASIC_IOBASICGH_H_ 1
+
#include "StoreNamedData.h"
@@ -55,6 +58,7 @@ typedef struct IOBASIC_GH
/* prototypes of functions to be registered */
int IOBasic_InfoOutputGH (const cGH *GH);
+int IOBasic_OutputVarAs (const cGH *GH, const char *fullname,const char *alias);
int IOBasic_TriggerInfoOutput (const cGH *GH, int vindex);
int IOBasic_TimeForInfoOutput (const cGH *GH, int vindex);
int IOBasic_ScalarOutputGH (const cGH *GH);
@@ -65,3 +69,5 @@ int IOBasic_TimeForScalarOutput (const cGH *GH, int vindex);
void IOBasic_AssignReductionList (int vindex, const char *optstring, void *arg);
int IOBasic_WriteInfo (const cGH *GH, int vindex);
int IOBasic_WriteScalar (const cGH *GH, int vindex, const char *alias);
+
+#endif /* _IOBASIC_IOBASICGH_H_ */