aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README7
-rw-r--r--doc/documentation.tex59
-rw-r--r--src/Output3D.c390
-rw-r--r--src/Startup.c85
-rw-r--r--src/Write3D.c459
-rw-r--r--src/ioASCIIGH.h56
-rw-r--r--src/make.code.defn8
7 files changed, 986 insertions, 78 deletions
diff --git a/README b/README
index 14f1020..4531142 100644
--- a/README
+++ b/README
@@ -5,7 +5,7 @@ CVS info : $Header$
1. Purpose of the thorn
-This thorn does 1D and 2D output of 3D variables in ASCII format.
+This thorn does 1D, 2D, and 3D output of 3D variables in ASCII format.
1D output slices through the edge (in octant mode) or center
(in all origin-centered modes) of the grid in the x,y, and z directions.
@@ -15,7 +15,10 @@ Ouput files can be processed with either gnuplot or xgraph.
2D output is done for the xy, xz, and yz plane.
Ouput files can be processed with the splot command in gnuplot.
-The IO methods "IOASCII_1D" and "IOASCII_2D" are registered
+3D output is simply done for the full 3D grid variables.
+Ouput files can be processed with the splot command in gnuplot.
+
+The IO methods "IOASCII_1D", "IOASCII_2D", and "IOASCII_3D" are registered
which can be called by other thorns via CCTK_OutputVarAsByMethod()
to output a variable without specifying it in the parameter file.
diff --git a/doc/documentation.tex b/doc/documentation.tex
index 013ff8e..85f070e 100644
--- a/doc/documentation.tex
+++ b/doc/documentation.tex
@@ -7,40 +7,45 @@
\date{1998-1999}
\maketitle
-\abstract{Thorn IOASCII provides an IO method for 1D and 2D output of
+\abstract{Thorn IOASCII provides I/O methods for 1D, 2D, and 3D output of
grid arrays into files in ASCII format.}
\section{Purpose}
-Thorn IOASCII registers two IO methods named {\tt IOASCII\_1D} and
-{\tt IOASCII\_2D} with the IO interface in the flesh.\\
-{\tt IOASCII\_1D} creates one-dimensional output of 3D grid functions and arrays
-by slicing through the edge (in the octant case) or center (in all
-origin centered cases) of the grid in the x, y, and z directions.
-If your grid is cubed it will also slice in the diagonal direction.
-Output for each direction can be selected individually via parameters.\\
-Data is written in ASCII format and goes into files named
-{\tt "<GF\_name>.[xyzd]l"}. These files can be processed directly by either
-xgraph or gnuplot (you can select the style of output via parameter
-settings).\\\\
+Thorn IOASCII registers three I/O methods named {\tt IOASCII\_1D}, {\tt IOASCII\_2D}, and
+{\tt IOASCII\_3D} with the I/O interface in the flesh.
+
+\begin{enumerate}
+ \item {\tt IOASCII\_1D} creates one-dimensional output of 3D grid functions
+ and arrays by slicing through the edge (in the octant case) or center
+ (in all origin centered cases) of the grid in the x, y, and z directions.
+ If your grid is cubed it will also slice in the diagonal direction.
+ Output for each direction can be selected individually via parameters.\\
+ Data is written in ASCII format and goes into files named
+ {\tt "<GF\_name>.[xyzd]l"}. These files can be processed directly by either
+ xgraph or gnuplot (you can select the style of output via parameter
+ settings).
+ \item {\tt IOASCII\_2D} outputs two-dimensional slices of grid functions and
+ arrays as xy, xz, and yz planes. Again, slicing is done through the edge
+ (in the octant case) or center (in all origin centered cases).\\
+ Data is written in ASCII format and goes into files named
+ {\tt "<varname>\_2d\_[{xy}{xz}{yz}.gnuplot"}. These files can be visualized
+ by gnuplot using its {\it splot} command.
+ \item {\tt IOASCII\_3D} outputs three-dimensional grid functions and arrays
+ as a whole.\\
+ Data is written in ASCII format and goes into files named
+ {\tt "<varname>\_2D.asc"}. These files can be visualized by gnuplot using
+ its {\it splot} command.
+\end{enumerate}
%
-{\tt IOASCII\_2D} outputs two-dimensional slices of grid functions and arrays
-as xy, xz, and yz planes. Again, slicing is done through the edge
-(in the octant case) or center (in all origin centered cases).\\
-Data is written in ASCII format and goes into files named
-{\tt "<varname>\_2d\_[{xy}{xz}{yz}.gnuplot"}. These files can be visualized
-by gnuplot using its {\it splot} command.
-%
-\newline
-%
-You obtain output by an IO method by either
+You obtain output by an I/O method by either
%
\begin{itemize}
- \item setting the appropriate IO parameters
- \item calling one the routines of the IO function interface provided by the flesh
+ \item setting the appropriate I/O parameters
+ \item calling one the routines of the I/O function interface provided by the flesh
\end{itemize}
%
-For a description of basic IO parameters and the IO function interface to
-invoke IO methods by application thorns please see the documentation of thorn
+For a description of basic I/O parameters and the I/O function interface to
+invoke I/O methods by application thorns please see the documentation of thorn
IOUtil and the flesh.
%
\section{Comments}
@@ -52,7 +57,7 @@ IMPORTANT: Must select data to output AFTER spatial coordinates are set up
%
Since IOASCII uses parameters from IOUtil
-it also needs this IO skeleton thorn be compiled into Cactus and activated.
+it also needs this I/O utility thorn be compiled into Cactus and activated.
\section{Examples}
diff --git a/src/Output3D.c b/src/Output3D.c
new file mode 100644
index 0000000..1bd1085
--- /dev/null
+++ b/src/Output3D.c
@@ -0,0 +1,390 @@
+ /*@@
+ @file Output3D.c
+ @date Wed 12 Dec 2001
+ @author Thomas Radke
+ @desc
+ Functions to deal with 3D ASCII output of variables
+ @enddesc
+ @version $Id$
+ @@*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "cctk.h"
+#include "cctk_Parameters.h"
+#include "util_String.h"
+#include "ioASCIIGH.h"
+
+/* the rcs ID and its dummy function to use it */
+static const char *rcsid = "$Id$";
+CCTK_FILEVERSION(CactusBase_IOASCII_Output3D_c)
+
+/* define this if you want debug output */
+/*#define IOASCII_DEBUG 1*/
+
+
+/* prototypes of routines defined in this source file */
+static int CheckOutputVar (int vindex);
+static void CheckSteerableParameters (asciiioGH *myGH);
+static void SetOutputFlag (int vindex, const char *optstring, void *arg);
+
+
+/*@@
+ @routine IOASCII_Output3DGH
+ @date Wed 12 Dec 2001
+ @author Thomas Radke
+ @desc
+ Loops over all variables and outputs them if necessary
+ @enddesc
+ @calls IOASCII_TimeFor3D
+ IOASCII_Write3D
+
+ @var GH
+ @vdesc Pointer to CCTK GH
+ @vtype const cGH *
+ @vio in
+ @endvar
+@@*/
+int IOASCII_Output3DGH (const cGH *GH)
+{
+ int vindex;
+ asciiioGH *myGH;
+ const char *name;
+
+
+ /* Get the GH extensions for IOASCII */
+ myGH = (asciiioGH *) CCTK_GHExtension (GH, "IOASCII");
+
+ CheckSteerableParameters (myGH);
+
+ /* Return if no output is required */
+ if (myGH->out3D_every <= 0)
+ {
+ return (0);
+ }
+
+ /* Loop over all variables */
+ for (vindex = 0; vindex < CCTK_NumVars (); vindex++)
+ {
+
+ /* Check if this variable should be output */
+ if (! IOASCII_TimeFor3D (GH, vindex))
+ {
+ continue;
+ }
+
+ /* Get the variable name for this index (for filename) */
+ name = CCTK_VarName (vindex);
+
+#ifdef IO_DEBUG
+ printf ("\nIn IOASCII Output3DGH\n---------------------\n");
+ printf (" Index = %d\n", vindex);
+ printf (" Variable = -%s-\n", name);
+ printf (" On iteration %d\n", GH->cctk_iteration);
+ printf (" Last output iteration was = %d\n", myGH->out3D_last[vindex]);
+#endif
+
+ /* Make the IO call */
+ IOASCII_Write3D (GH, vindex, name);
+
+ /* Register GF as having 3D output this iteration */
+ myGH->out3D_last[vindex] = GH->cctk_iteration;
+
+ } /* end of loop over all variables */
+
+ return (0);
+}
+
+
+/*@@
+ @routine IOASCII_Output3DVarAs
+ @date Wed 12 Dec 2001
+ @author Thomas Radke
+ @desc
+ Unconditional output of a variable
+ using the IOASCII 3D output method
+ @enddesc
+ @calls IOASCII_Write3D
+
+ @var GH
+ @vdesc Pointer to CCTK GH
+ @vtype const cGH *
+ @vio in
+ @endvar
+ @var fullname
+ @vdesc complete name of variable to output
+ @vtype const char *
+ @vio in
+ @endvar
+ @var alias
+ @vdesc alias name of variable to output
+ (used to generate output filename)
+ @vtype const char *
+ @vio in
+ @endvar
+@@*/
+int IOASCII_Output3DVarAs (const cGH *GH, const char *fullname, const char *alias)
+{
+ int vindex;
+
+
+ vindex = CCTK_VarIndex (fullname);
+
+#ifdef IO_DEBUG
+ printf ("\nIn IOASCII Output3DVarAs\n-------------------\n");
+ printf (" Fullname = -%s-\n", fullname);
+ printf (" Alias = -%s-\n", alias);
+ printf (" Index = %d\n", vindex);
+#endif
+
+ if (CheckOutputVar (vindex) == 0)
+ {
+ IOASCII_Write3D (GH, vindex, alias);
+ }
+
+ return (0);
+}
+
+
+ /*@@
+ @routine IOASCII_TimeFor3D
+ @date Wed 12 Dec 2001
+ @author Thomas Radke
+ @desc
+ Decides if it is time to output a variable
+ using the IOASCII 3D output method
+ @enddesc
+
+ @var GH
+ @vdesc Pointer to CCTK GH
+ @vtype const cGH *
+ @vio in
+ @endvar
+ @var vindex
+ @vdesc index of variable
+ @vtype int
+ @vio in
+ @endvar
+@@*/
+int IOASCII_TimeFor3D (const cGH *GH, int vindex)
+{
+ int return_type;
+ asciiioGH *myGH;
+ char *fullname;
+
+
+ /* Default is do not do output */
+ return_type = 0;
+
+ /* Get the GH extensions for IOASCII */
+ myGH = (asciiioGH *) CCTK_GHExtension (GH, "IOASCII");
+
+ CheckSteerableParameters (myGH);
+
+ /* return if no output requested */
+ if (myGH->out3D_every <= 0)
+ {
+ return (0);
+ }
+
+ /* Check if this variable should be output */
+ if (myGH->do_out3D[vindex] && (GH->cctk_iteration % myGH->out3D_every == 0))
+ {
+ /* Check if variable wasn't already output this iteration */
+ if (myGH->out3D_last[vindex] == GH->cctk_iteration)
+ {
+ fullname = CCTK_FullName (vindex);
+ CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Already done IOASCII 3D output for '%s' in current "
+ "iteration (probably via triggers)", fullname);
+ free (fullname);
+ }
+ else
+ {
+ return_type = 1;
+ }
+ }
+
+ return (return_type);
+}
+
+
+/*@@
+ @routine IOASCII_TriggerOutput3D
+ @date Wed 12 Dec 2001
+ @author Thomas Radke
+ @desc
+ Triggers the output of a variable
+ using the IOASCII 3D output method
+ @enddesc
+ @calls IOASCII_Write3D
+
+ @var GH
+ @vdesc Pointer to CCTK GH
+ @vtype const cGH *
+ @vio in
+ @endvar
+ @var vindex
+ @vdesc index of variable to output
+ @vtype int
+ @vio in
+ @endvar
+@@*/
+int IOASCII_TriggerOutput3D (const cGH *GH, int vindex)
+{
+ const char *var;
+ asciiioGH *myGH;
+
+
+ /* get GH extensions for IOASCII */
+ myGH = (asciiioGH *) CCTK_GHExtension (GH, "IOASCII");
+
+ var = CCTK_VarName (vindex);
+
+ /* Do the 3D output */
+#ifdef IO_DEBUG
+ printf ("\nIn IOASCII TriggerOutput3D\n---------------------\n");
+ printf (" Index = %d\n", vindex);
+ printf (" Variable = -%s-\n", var);
+#endif
+
+ IOASCII_Write3D (GH, vindex, var);
+
+ /* Register variables as having 3D output this iteration */
+ myGH->out3D_last[vindex] = GH->cctk_iteration;
+
+ return (0);
+}
+
+
+/**************************** local functions ******************************/
+/* check if steerable parameters have changed */
+static void CheckSteerableParameters (asciiioGH *myGH)
+{
+ int i, out_old, times_set, num_vars;
+ char *fullname, *msg;
+ static int out3D_vars_lastset = -1;
+ DECLARE_CCTK_PARAMETERS
+
+
+ out_old = myGH->out3D_every;
+
+ /* How often to output */
+ myGH->out3D_every = out_every > 0 ? out_every : -1;
+ if (out3D_every > 0)
+ {
+ myGH->out3D_every = out3D_every;
+ }
+
+ /* Report if frequency changed */
+
+ if (myGH->out3D_every != out_old)
+ {
+ if (CCTK_Equals (newverbose, "standard") ||
+ CCTK_Equals (newverbose, "full"))
+ {
+ CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_3D: Output every %d iterations",
+ myGH->out3D_every);
+ }
+ }
+
+ /* re-parse the 'out3D_vars' parameter if it was changed */
+ times_set = CCTK_ParameterQueryTimesSet ("out3D_vars", CCTK_THORNSTRING);
+ if (times_set != out3D_vars_lastset)
+ {
+ num_vars = CCTK_NumVars ();
+ memset (myGH->do_out3D, 0, num_vars);
+ CCTK_TraverseString (out3D_vars, SetOutputFlag, myGH->do_out3D,
+ CCTK_GROUP_OR_VAR);
+
+ if (CCTK_Equals (newverbose, "standard") ||
+ CCTK_Equals (newverbose, "full"))
+ {
+ msg = NULL;
+ for (i = 0; i < num_vars; i++)
+ {
+ if (myGH->do_out3D[i])
+ {
+ fullname = CCTK_FullName (i);
+ if (! msg)
+ {
+ Util_asprintf (&msg, "IOASCII_3D: Output requested for %s",
+ fullname);
+ }
+ else
+ {
+ Util_asprintf (&msg, "%s %s", msg, fullname);
+ }
+ free (fullname);
+ }
+ }
+ if (msg)
+ {
+ CCTK_INFO (msg);
+ free (msg);
+ }
+ }
+
+ /* Save the last setting of 'out3D_vars' parameter */
+ out3D_vars_lastset = times_set;
+ }
+
+}
+
+
+/* check if this variable can be output (static conditions) */
+static int CheckOutputVar (int vindex)
+{
+ int groupindex;
+ cGroup groupinfo;
+ char *fullname;
+ const char *errormsg;
+
+
+ /* get the variable group information */
+ groupindex = CCTK_GroupIndexFromVarI (vindex);
+ CCTK_GroupData (groupindex, &groupinfo);
+
+ /* check if variable is grid array type with 3 dimensions */
+ errormsg = NULL;
+ if (groupinfo.dim != 3)
+ {
+ errormsg = "No IOASCII 3D output for '%s' (dim != 3)";
+ }
+ else if (groupinfo.grouptype != CCTK_GF && groupinfo.grouptype != CCTK_ARRAY)
+ {
+ errormsg = "No IOASCII 3D output for '%s' (not a grid function or array)";
+ }
+
+ if (errormsg)
+ {
+ fullname = CCTK_FullName (vindex);
+ CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, errormsg, fullname);
+ free (fullname);
+ }
+
+ return (errormsg != NULL);
+}
+
+
+/* callback for CCTK_TraverseString() to set the output flag
+ for the given variable */
+static void SetOutputFlag (int vindex, const char *optstring, void *arg)
+{
+ char *flags = (char *) arg;
+
+
+ /* Check the variable type */
+ if (CheckOutputVar (vindex) == 0)
+ {
+ flags[vindex] = 1;
+ }
+
+ if (optstring)
+ {
+ CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Optional string '%s' in variable name ignored", optstring);
+ }
+}
diff --git a/src/Startup.c b/src/Startup.c
index cf6a0d0..86e639a 100644
--- a/src/Startup.c
+++ b/src/Startup.c
@@ -30,17 +30,6 @@ static void *IOASCII_SetupGH (tFleshConfig *config,
int convergence_level,
cGH *GH);
-/* prototypes of functions to be registered */
-int IOASCII_Output1DGH (const cGH *GH);
-int IOASCII_TriggerOutput1D (const cGH *GH, int);
-int IOASCII_TimeFor1D (const cGH *GH, int);
-int IOASCII_Output1DVarAs (const cGH *GH, const char *var, const char *alias);
-int IOASCII_Output2DGH (const cGH *GH);
-int IOASCII_TriggerOutput2D (const cGH *GH, int);
-int IOASCII_TimeFor2D (const cGH *GH, int);
-int IOASCII_Output2DVarAs (const cGH *GH, const char *var, const char *alias);
-
-
/*@@
@routine IOASCII_Startup
@date Sat Feb 6 1999
@@ -133,15 +122,24 @@ static void *IOASCII_SetupGH (tFleshConfig *config,
CCTK_RegisterIOMethodTimeToOutput (i, IOASCII_TimeFor2D);
CCTK_RegisterIOMethodTriggerOutput (i, IOASCII_TriggerOutput2D);
+ i = CCTK_RegisterIOMethod ("IOASCII_3D");
+ CCTK_RegisterIOMethodOutputGH (i, IOASCII_Output3DGH);
+ CCTK_RegisterIOMethodOutputVarAs (i, IOASCII_Output3DVarAs);
+ CCTK_RegisterIOMethodTimeToOutput (i, IOASCII_TimeFor3D);
+ CCTK_RegisterIOMethodTriggerOutput (i, IOASCII_TriggerOutput3D);
+
if (CCTK_Equals (newverbose, "standard") ||
CCTK_Equals( newverbose, "full"))
{
CCTK_INFO ("I/O Method 'IOASCII_1D' registered");
CCTK_INFO ("IOASCII_1D: Output of 1D lines of grid functions/arrays "
- "to ASCII files");
+ "to ASCII files");
CCTK_INFO ("I/O Method 'IOASCII_2D' registered");
CCTK_INFO ("IOASCII_2D: Output of 2D planes of grid functions/arrays "
- "to ASCII files");
+ "to ASCII files");
+ CCTK_INFO ("I/O Method 'IOASCII_3D' registered");
+ CCTK_INFO ("IOASCII_3D: Output of 3D grid functions/arrays "
+ "to ASCII files");
}
/* allocate the GH extension and its components */
@@ -151,18 +149,22 @@ static void *IOASCII_SetupGH (tFleshConfig *config,
{
numvars = CCTK_NumVars ();
newGH->do_out1D = (char *) malloc (numvars * sizeof (char));
- newGH->do_out2D = (char *) malloc (numvars * sizeof (char));
+ newGH->do_out2D = (char *) malloc (numvars * sizeof (char));
+ newGH->do_out3D = (char *) malloc (numvars * sizeof (char));
newGH->out1D_last = (int *) malloc (numvars * sizeof (int));
newGH->out2D_last = (int *) malloc (numvars * sizeof (int));
+ newGH->out3D_last = (int *) malloc (numvars * sizeof (int));
for (i = 0; i < numvars; i++)
{
newGH->out1D_last[i] = -1;
newGH->out2D_last[i] = -1;
+ newGH->out3D_last[i] = -1;
}
newGH->filenameList1D = NULL;
newGH->fileList_2D = NULL;
+ newGH->fileList_3D = NULL;
maxdim = CCTK_MaxDim ();
newGH->spxyz = (int ***) malloc (maxdim * sizeof (int **));
@@ -191,27 +193,41 @@ static void *IOASCII_SetupGH (tFleshConfig *config,
{
newGH->out2D_every = out2D_every;
}
+ newGH->out3D_every = out_every > 0 ? out_every : -1;
+ if (out3D_every > 0)
+ {
+ newGH->out3D_every = out3D_every;
+ }
if (CCTK_Equals (newverbose, "standard") ||
- CCTK_Equals (newverbose, "full"))
+ CCTK_Equals (newverbose, "full"))
{
if (out1D_every > 0)
{
- CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_1D: Output every %d iterations",
- newGH->out1D_every);
+ CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_1D: Output every %d iterations",
+ newGH->out1D_every);
}
else
{
- CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_1D: Output not activated");
+ CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_1D: Output not activated");
}
if (out2D_every > 0)
{
- CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_2D: Output every %d iterations",
- newGH->out2D_every);
+ CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_2D: Output every %d iterations",
+ newGH->out2D_every);
+ }
+ else
+ {
+ CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_2D: Output not activated");
+ }
+ if (out3D_every > 0)
+ {
+ CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_3D: Output every %d iterations",
+ newGH->out3D_every);
}
else
{
- CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_2D: Output not activated");
+ CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_3D: Output not activated");
}
}
@@ -226,6 +242,9 @@ static void *IOASCII_SetupGH (tFleshConfig *config,
newGH->outdir2D =
CCTK_ParameterQueryTimesSet ("outdir2D", CCTK_THORNSTRING) > 0 ?
strdup (outdir2D) : strdup (outdir);
+ newGH->outdir3D =
+ CCTK_ParameterQueryTimesSet ("outdir3D", CCTK_THORNSTRING) > 0 ?
+ strdup (outdir3D) : strdup (outdir);
/* create the 1D output dir */
i = IOUtil_CreateDirectory (GH, newGH->outdir1D, 0, 0);
@@ -237,9 +256,8 @@ static void *IOASCII_SetupGH (tFleshConfig *config,
}
else if (i >= 0 && CCTK_Equals (newverbose, "full"))
{
- CCTK_VInfo (CCTK_THORNSTRING,
- "IOASCII_1D: Output to directory '%s'",
- newGH->outdir1D);
+ CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_1D: Output to directory '%s'",
+ newGH->outdir1D);
}
/* create the 2D output dir */
@@ -252,9 +270,22 @@ static void *IOASCII_SetupGH (tFleshConfig *config,
}
else if (i >= 0 && CCTK_Equals (newverbose, "full"))
{
- CCTK_VInfo (CCTK_THORNSTRING,
- "IOASCII_2D: Output to directory '%s'",
- newGH->outdir2D);
+ CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_2D: Output to directory '%s'",
+ newGH->outdir2D);
+ }
+
+ /* create the 3D output dir */
+ i = IOUtil_CreateDirectory (GH, newGH->outdir3D, 0, 0);
+ if (i < 0)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOASCII_InitGH: problem creating IOASCII 3D output"
+ " directory '%s'", newGH->outdir3D);
+ }
+ else if (i >= 0 && CCTK_Equals (newverbose, "full"))
+ {
+ CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_3D: Output to directory '%s'",
+ newGH->outdir3D);
}
}
diff --git a/src/Write3D.c b/src/Write3D.c
new file mode 100644
index 0000000..c092535
--- /dev/null
+++ b/src/Write3D.c
@@ -0,0 +1,459 @@
+/*@@
+ @file Write3D.c
+ @date Wed 12 Dec 2001
+ @author Thomas Radke
+ @desc
+ Three-dimensional output of variables in ASCII gnuplot format.
+ @enddesc
+ @version $Id$
+ @@*/
+
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "cctk.h"
+#include "cctk_Parameters.h"
+#include "Hyperslab.h"
+#include "CactusBase/IOUtil/src/ioutil_AdvertisedFiles.h"
+#include "CactusBase/IOUtil/src/ioutil_CheckpointRecovery.h"
+#include "ioASCIIGH.h"
+
+/* the rcs ID and its dummy function to use it */
+static const char *rcsid = "$Id$";
+CCTK_FILEVERSION(CactusBase_IOASCII_Write3D_c)
+
+/* enable debug output */
+/*#define IOASCII_DEBUG 1*/
+
+
+/* macro to output a time volume as typed data */
+#define OUTPUT_TYPED_DATA(hsize, coord, stagger_offset, cctk_type, c_type, \
+ data, have_coords, is_cmplx_type, fmt_string, file) \
+ { \
+ int _i, _j, _k; \
+ const cctk_type *_typed_data = (const cctk_type *) (data); \
+ \
+ \
+ /* output coordinates if available otherwise just the indices */ \
+ if (have_coords) \
+ { \
+ for (_k = 0; _k < hsize[2]; _k++) \
+ { \
+ for (_j = 0; _j < hsize[1]; _j++) \
+ { \
+ for (_i = 0; _i < hsize[0]; _i++) \
+ { \
+ fprintf (file, fmt_string, \
+ (double) (*coord[0]++ + stagger_offset[0]), \
+ (double) (*coord[1]++ + stagger_offset[1]), \
+ (double) (*coord[2]++ + stagger_offset[2]), \
+ (c_type) *_typed_data++); \
+ if (is_cmplx_type) \
+ { \
+ fprintf (file, "\t\t"); \
+ fprintf (file, out_real_format, (double)*_typed_data++);\
+ } \
+ fprintf (file, "\n"); \
+ } \
+ fprintf (file, "\n"); \
+ } \
+ } \
+ coord[0] -= hsize[0] * hsize[1] * hsize[2]; \
+ coord[1] -= hsize[0] * hsize[1] * hsize[2]; \
+ coord[2] -= hsize[0] * hsize[1] * hsize[2]; \
+ } \
+ else \
+ { \
+ for (_k = 0; _k < hsize[2]; _k++) \
+ { \
+ for (_j = 0; _j < hsize[1]; _j++) \
+ { \
+ for (_i = 0; _i < hsize[0]; _i++) \
+ { \
+ fprintf (file, fmt_string, \
+ (double) _i, \
+ (double) _j, \
+ (double) _k, \
+ (c_type) *_typed_data++); \
+ if (is_cmplx_type) \
+ { \
+ fprintf (file, "\t\t"); \
+ fprintf (file, out_real_format, (double)*_typed_data++);\
+ } \
+ fprintf (file, "\n"); \
+ } \
+ fprintf (file, "\n"); \
+ } \
+ } \
+ } \
+ }
+
+
+/*@@
+ @routine IOASCII_Write3D
+ @date Wed 12 Dec 2001
+ @author Thomas Radke
+ @desc
+ Writes the 3D volume of a variable into a gnuplot ASCII file.
+ @enddesc
+ @calls IOUtil_RestartFromRecovery
+ IOUtil_AdvertiseFile
+
+ @var GH
+ @vdesc Pointer to CCTK GH
+ @vtype const cGH *
+ @vio in
+ @endvar
+ @var vindex
+ @vdesc index of variable to output
+ @vtype int
+ @vio in
+ @endvar
+ @var alias
+ @vdesc alias name of variable to output
+ @vtype const char *
+ @vio in
+ @endvar
+@@*/
+void IOASCII_Write3D (const cGH *GH, int vindex, const char *alias)
+{
+ DECLARE_CCTK_PARAMETERS
+ int myproc, groupindex, dir, have_coords;
+ asciiioGH *myGH;
+ char header_fmt_string[30]; /* header format string */
+ char out_real_format[30]; /* data format string for a real type */
+ char time_fmt_string[30]; /* time format string */
+ char data_fmt_string_int[30]; /* data format string for int types */
+ char data_fmt_string_real[30]; /* data format string for real types */
+ FILE **file;
+ int coord_index[3]; /* variable indices for xyz coordinates */
+ CCTK_REAL coord_lower[3]; /* coordinates' minima */
+ CCTK_REAL dummy;
+ char *filename;
+ char *fullname;
+ cGroup groupinfo;
+ ioAdvertisedFileDesc advertised_file;
+ char buffer[128];
+ const int directions[3] = {1, 1, 1};
+ const int origin[3] = {0, 0, 0};
+ const int lengths[3] = {-1, -1, -1};
+ const int downsamples[3] = {1, 1, 1};
+ int hsize[3];
+ CCTK_REAL *coord_data[3], stagger_offset[3];
+ void *data;
+
+
+ /* to make the compiler happy */
+ file = NULL;
+ filename = fullname = NULL;
+
+ /* get the variable group information */
+ groupindex = CCTK_GroupIndexFromVarI (vindex);
+ CCTK_GroupData (groupindex, &groupinfo);
+
+ /* check if variable has storage assigned */
+ if (! CCTK_QueryGroupStorageI (GH, groupindex))
+ {
+ fullname = CCTK_FullName (vindex);
+ CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "No IOASCII 3D output for '%s' (no storage)", fullname);
+ free (fullname);
+ return;
+ }
+
+ /* Get the handle for IOASCII extensions */
+ myGH = (asciiioGH *) CCTK_GHExtension (GH, "IOASCII");
+
+ /* set header and data format strings */
+ sprintf (header_fmt_string, "\n\n#Time = %%%s\n", out_format);
+ sprintf (out_real_format, "%%%s", out_format);
+ dir = 0;
+ if (CCTK_Equals (out3D_style, "gnuplot f(t,x,y,z)"))
+ {
+ sprintf (time_fmt_string, "%%%s\t\t", out_format);
+ sprintf (data_fmt_string_int, time_fmt_string, (double) GH->cctk_time);
+ sprintf (data_fmt_string_real, time_fmt_string, (double) GH->cctk_time);
+ dir = strlen (data_fmt_string_int);
+ }
+ sprintf (data_fmt_string_int + dir, "%%%s\t\t%%%s\t\t%%d\t\t%%d",
+ out_format, out_format);
+ sprintf (data_fmt_string_real + dir, "%%%s\t\t%%%s\t\t%%%s\t\t%%%s",
+ out_format, out_format, out_format, out_format);
+
+ /* get the coordinate indices if we output a grid function */
+ if (groupinfo.grouptype == CCTK_GF)
+ {
+ have_coords = 1;
+ for (dir = 0; dir < 3; dir++)
+ {
+ CCTK_CoordRange (GH, &coord_lower[dir], &dummy, dir+1, NULL, "cart3d");
+ coord_index[dir] = CCTK_CoordIndex (dir + 1, NULL, "cart3d");
+ have_coords &= coord_index[dir] >= 0;
+ }
+
+ if (! have_coords)
+ {
+ CCTK_VWarn (8, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOASCII_Write3D: No coordinate ranges found for '%s'",
+ "cart3d");
+ }
+ }
+ else
+ {
+ /* CCTK_ARRAY variables never have coordinates associated */
+ have_coords = 0;
+ }
+
+ /* What processor are we on? */
+ myproc = CCTK_MyProc (GH);
+
+ /* Open the files on the first trip through if we are proc. 0 */
+ if (myproc == 0)
+ {
+ /* see if output file for this alias name was already created */
+ file = (FILE **) GetNamedData (myGH->fileList_3D, alias);
+ if (file == NULL)
+ {
+ file = (FILE **) malloc (sizeof (FILE *));
+ filename = (char *) malloc (strlen (myGH->outdir3D) + strlen (alias) + 9);
+
+ /* get the variable's full name */
+ fullname = CCTK_FullName (vindex);
+
+ /* Open/Create the file */
+ /* skip pathname if output goes into current directory */
+ if (strcmp (myGH->outdir3D, "."))
+ {
+ sprintf (filename, "%s/%s_3D.asc", myGH->outdir3D, alias);
+ }
+ else
+ {
+ sprintf (filename, "%s_3D.asc", alias);
+ }
+
+ /* if restart from recovery, try to open an existing file ... */
+ *file = NULL;
+ if (IOUtil_RestartFromRecovery (GH))
+ {
+ *file = fopen (filename, "a");
+ }
+
+ /* otherwise or if that failed, create a new one */
+ if (! *file)
+ {
+ *file = fopen (filename, "w");
+ }
+ if (! *file)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Cannot open 3D IOASCII output file '%s'", filename);
+ return;
+ }
+
+ /* advertise the file for downloading and write file info */
+ /* FIXME: this can go when we permanently switch the the
+ new filename scheme */
+ advertised_file.slice = "";
+ advertised_file.thorn = CCTK_THORNSTRING;
+ advertised_file.varname = fullname;
+ advertised_file.description = "Full-dimensional variable contents";
+ advertised_file.mimetype = "application/gnuplot";
+
+ 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, "#Parameter file %s\n", buffer);
+ }
+ if (CCTK_Equals (out_fileinfo, "creation date") ||
+ CCTK_Equals (out_fileinfo, "all"))
+ {
+ buffer[0] = 0;
+ Util_CurrentDate (sizeof (buffer), buffer);
+ fprintf (*file, "#Created %s ", 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, "#z-label %s\n", advertised_file.varname);
+ }
+ }
+
+ /* store file desriptors in database */
+ StoreNamedData (&myGH->fileList_3D, alias, file);
+
+ free (filename);
+ free (fullname);
+ }
+
+ /* get the coordinates for grid function output */
+ if (have_coords)
+ {
+ /* get the i-coordinate volume */
+ if (Hyperslab_GetHyperslab (GH, 0, coord_index[0], 0, 3,
+ origin, directions, lengths, downsamples,
+ (void **) &coord_data[0], hsize) < 0)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Failed to extract 3D hyperslab for x-coordinate");
+ return;
+ }
+
+ /* get the j-coordinate volume */
+ if (Hyperslab_GetHyperslab (GH, 0, coord_index[1], 0, 3,
+ origin, directions, lengths, downsamples,
+ (void **) &coord_data[1], hsize) < 0)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Failed to extract 3D hyperslab for y-coordinate");
+ free (coord_data[0]);
+ return;
+ }
+
+ /* get the k-coordinate volume */
+ if (Hyperslab_GetHyperslab (GH, 0, coord_index[2], 0, 3,
+ origin, directions, lengths, downsamples,
+ (void **) &coord_data[2], hsize) < 0)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Failed to extract 3D hyperslab for z-coordinate");
+ free (coord_data[1]);
+ free (coord_data[0]);
+ return;
+ }
+ }
+ else
+ {
+ /* grid arrays don't have coordinates assigned */
+ coord_data[0] = coord_data[1] = coord_data[2] = NULL;
+ }
+
+ /* get the variable volume */
+ if (Hyperslab_GetHyperslab (GH, 0, vindex, 0, 3, origin, directions,
+ lengths, downsamples, &data, hsize) < 0)
+ {
+ fullname = CCTK_FullName (vindex);
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Failed to extract 3D hyperslab for variable '%s'", fullname);
+ free (fullname);
+ for (dir = 0; dir < 3; dir++)
+ {
+ if (coord_data[dir])
+ {
+ free (coord_data[dir]);
+ }
+ }
+ return;
+ }
+
+ /* proc 0 writes */
+ if (myproc == 0)
+ {
+ /* get the staggering offset for the coordinates */
+ for (dir = 0; dir < 3; dir++)
+ {
+ stagger_offset[dir] = CCTK_StaggerDirIndex (dir, groupinfo.stagtype) *
+ 0.5 * GH->cctk_delta_space[dir];
+ }
+
+ /* print out header */
+ fprintf (*file, header_fmt_string, GH->cctk_time);
+
+ switch (groupinfo.vartype)
+ {
+ case CCTK_VARIABLE_CHAR:
+ OUTPUT_TYPED_DATA (hsize, coord_data, stagger_offset, CCTK_BYTE, int,
+ data, have_coords, 0, data_fmt_string_int, *file);
+ break;
+
+ case CCTK_VARIABLE_INT:
+ OUTPUT_TYPED_DATA (hsize, coord_data, stagger_offset, CCTK_INT, int,
+ data, have_coords, 0, data_fmt_string_int, *file);
+ break;
+
+ case CCTK_VARIABLE_REAL:
+ case CCTK_VARIABLE_COMPLEX:
+ OUTPUT_TYPED_DATA (hsize, coord_data, stagger_offset, CCTK_REAL, double,
+ data, have_coords,
+ groupinfo.vartype == CCTK_VARIABLE_COMPLEX,
+ data_fmt_string_real, *file);
+ break;
+
+#ifdef CCTK_INT2
+ case CCTK_VARIABLE_INT2:
+ OUTPUT_TYPED_DATA (hsize, coord_data, stagger_offset, CCTK_INT2, int,
+ data, have_coords, 0, data_fmt_string_int, *file);
+ break;
+#endif
+
+#ifdef CCTK_INT4
+ case CCTK_VARIABLE_INT4:
+ OUTPUT_TYPED_DATA (hsize, coord_data, stagger_offset, CCTK_INT4, int,
+ data, have_coords, 0, data_fmt_string_int, *file);
+ break;
+#endif
+
+#ifdef CCTK_INT8
+ case CCTK_VARIABLE_INT8:
+ OUTPUT_TYPED_DATA (hsize, coord_data, stagger_offset, CCTK_INT8, int,
+ data, have_coords, 0, data_fmt_string_int, *file);
+ break;
+#endif
+
+#ifdef CCTK_REAL4
+ case CCTK_VARIABLE_REAL4:
+ case CCTK_VARIABLE_COMPLEX8:
+ OUTPUT_TYPED_DATA (hsize, coord_data, stagger_offset, CCTK_REAL4,
+ double, data, have_coords,
+ groupinfo.vartype == CCTK_VARIABLE_COMPLEX8,
+ data_fmt_string_real, *file);
+ break;
+#endif
+
+#ifdef CCTK_REAL8
+ case CCTK_VARIABLE_REAL8:
+ case CCTK_VARIABLE_COMPLEX16:
+ OUTPUT_TYPED_DATA (hsize, coord_data, stagger_offset, CCTK_REAL8,
+ double, data, have_coords,
+ groupinfo.vartype == CCTK_VARIABLE_COMPLEX16,
+ data_fmt_string_real, *file);
+ break;
+#endif
+
+#ifdef CCTK_REAL16
+ case CCTK_VARIABLE_REAL16:
+ case CCTK_VARIABLE_COMPLEX32:
+ OUTPUT_TYPED_DATA (hsize, coord_data, stagger_offset, CCTK_REAL16,
+ double, data, have_coords,
+ groupinfo.vartype == CCTK_VARIABLE_COMPLEX32,
+ data_fmt_string_real, *file);
+ break;
+#endif
+
+ default:
+ CCTK_WARN (1, "Unsupported variable type");
+ break;
+ }
+
+ /* keep the file open but flush it */
+ fflush (*file);
+
+ /* free the hyperslabs */
+ free (data);
+ for (dir = 0; dir < 3; dir++)
+ {
+ if (coord_data[dir])
+ {
+ free (coord_data[dir]);
+ }
+ }
+
+ } /* end of outputting the data by processor 0 */
+
+}
diff --git a/src/ioASCIIGH.h b/src/ioASCIIGH.h
index 2fbdf83..71230f9 100644
--- a/src/ioASCIIGH.h
+++ b/src/ioASCIIGH.h
@@ -3,55 +3,79 @@
@date Tue 9th Jan 1999
@author Gabrielle Allen
@desc
- The extensions to the GH structure from IO.
- @history
- @hauthor Thomas Radke @hdate 16 Mar 1999
- @hdesc Added parameters for 2D and 3D output
- @hauthor Thomas Radke @hdate 17 Mar 1999
- @hdesc Changed naming: IEEEIO -> FlexIO
- @hauthor Thomas Radke @hdate 30 Mar 1999
- @hdesc Undefined DI macro
- @endhistory
- @version $Header$
+ The extensions to the GH structure from IO.
+ @version $Header$
@@*/
-#include "StoreNamedData.h"
+#ifndef _IOASCII_IOASCII_H_
+#define _IOASCII_IOASCII_H_
-/* supported gridtypes: full,octant,quadrant,bitant */
+#include "StoreNamedData.h"
-typedef struct IOASCIIGH {
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+typedef struct IOASCIIGH
+{
/* the number of times output */
int out1D_every;
int out2D_every;
+ int out3D_every;
/* flags indicating output for var [i] */
char *do_out1D;
char *do_out2D;
+ char *do_out3D;
/* directories in which to output */
char *outdir1D;
char *outdir2D;
+ char *outdir3D;
/* the last iteration output for var [i] */
int *out1D_last;
int *out2D_last;
+ int *out3D_last;
/* database for names of output files that were already created */
pNamedData *filenameList1D;
pNamedData *fileList_2D;
+ pNamedData *fileList_3D;
- /* for 1d lines, we define the index where to start the line:
+ /* for 1D lines, we define the index where to start the line:
spxyz[maxdim][XYZdirection][xyzstart_index] */
int ***spxyz;
- /* for 2d planes, we define the index where to locate the plane
+ /* for 2D planes, we define the index where to locate the plane
sp2xyz[maxdim][perpendicular direction] */
int **sp2xyz;
} asciiioGH;
-/* function prototypes */
+/* prototypes of functions to be registered as I/O methods */
+int IOASCII_Output1DGH (const cGH *GH);
+int IOASCII_TriggerOutput1D (const cGH *GH, int);
+int IOASCII_TimeFor1D (const cGH *GH, int);
+int IOASCII_Output1DVarAs (const cGH *GH, const char *var, const char *alias);
+int IOASCII_Output2DGH (const cGH *GH);
+int IOASCII_TriggerOutput2D (const cGH *GH, int);
+int IOASCII_TimeFor2D (const cGH *GH, int);
+int IOASCII_Output2DVarAs (const cGH *GH, const char *var, const char *alias);
+int IOASCII_Output3DGH (const cGH *GH);
+int IOASCII_TriggerOutput3D (const cGH *GH, int);
+int IOASCII_TimeFor3D (const cGH *GH, int);
+int IOASCII_Output3DVarAs (const cGH *GH, const char *var, const char *alias);
+
+/* other function prototypes */
void IOASCII_Write1D (const cGH *GH, int vindex, const char *alias);
void IOASCII_Write2D (const cGH *GH, int vindex, const char *alias);
+void IOASCII_Write3D (const cGH *GH, int vindex, const char *alias);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif /* _IOASCII_IOASCII_H_ */
diff --git a/src/make.code.defn b/src/make.code.defn
index b250174..8199d8e 100644
--- a/src/make.code.defn
+++ b/src/make.code.defn
@@ -2,9 +2,5 @@
# $Header$
# Source files in this directory
-SRCS = Startup.c\
- ChooseOutput.c\
- Output1D.c\
- Write1D.c\
- Output2D.c\
- Write2D.c
+SRCS = Startup.c ChooseOutput.c Output1D.c Write1D.c Output2D.c Write2D.c \
+ Output3D.c Write3D.c