aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@94b1c47f-dcfd-45ef-a468-0854c0e9e350>2002-04-18 22:45:45 +0000
committertradke <tradke@94b1c47f-dcfd-45ef-a468-0854c0e9e350>2002-04-18 22:45:45 +0000
commitc80aad909253d8654578d613ea085faee45055c0 (patch)
tree5529b62c7a360415ba5933bfeede4a79ec22a604
parentbed4e30fff00ce199f97fb781999fa332798ce8a (diff)
Moved all of the slice center initialization into ChooseOutput.c.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOASCII/trunk@107 94b1c47f-dcfd-45ef-a468-0854c0e9e350
-rw-r--r--src/ChooseOutput.c75
-rw-r--r--src/Startup.c239
2 files changed, 143 insertions, 171 deletions
diff --git a/src/ChooseOutput.c b/src/ChooseOutput.c
index ca6a739..55fb071 100644
--- a/src/ChooseOutput.c
+++ b/src/ChooseOutput.c
@@ -3,7 +3,7 @@
@author Gabrielle Allen
@date July 6 2000
@desc
- Choose what data to write for different IO methods in IOASCII
+ Choose what 1D slices and 2D planes to output by IOASCII.
@enddesc
@version $Id$
@@ -13,7 +13,6 @@
#include <string.h>
#include "cctk.h"
-#include "cctk_Arguments.h"
#include "cctk_Parameters.h"
#include "CactusBase/IOUtil/src/ioutil_Utils.h"
#include "ioASCIIGH.h"
@@ -23,6 +22,9 @@ static const char *rcsid = "$Header$";
CCTK_FILEVERSION(CactusBase_IOASCII_ChooseOutput_c)
+/********************************************************************
+ ******************** Macro Definitions ************************
+ ********************************************************************/
/* macro to choose origin according actual parameter settings:
1. Indices from IOASCII
2. Indices from IOUtil
@@ -30,6 +32,7 @@ CCTK_FILEVERSION(CactusBase_IOASCII_ChooseOutput_c)
4. Coords from IOUtil
*/
#define GET_SLICE(IOASCII_param, IOUtil_param, origin_index, origin_phys) \
+ { \
origin_index = -1; \
if (CCTK_ParameterQueryTimesSet (#IOASCII_param "i", "IOASCII") > 0)\
{ \
@@ -46,11 +49,15 @@ CCTK_FILEVERSION(CactusBase_IOASCII_ChooseOutput_c)
else \
{ \
origin_phys = IOUtil_param; \
- }
+ } \
+ }
+
-/* prototypes of routines defined in this source file */
-void IOASCII_Choose1D (cGH *GH);
-void IOASCII_Choose2D (cGH *GH);
+/********************************************************************
+ ******************** External Routines ************************
+ ********************************************************************/
+void IOASCII_Choose1D (const cGH *GH);
+void IOASCII_Choose2D (const cGH *GH);
/*@@
@@ -58,7 +65,7 @@ void IOASCII_Choose2D (cGH *GH);
@author Gabrielle Allen
@date July 6 2000
@desc
- Use parameters to choose the 1D slices through the output data.
+ Use parameters to choose the 1D slices through the output data.
@enddesc
@calls CCTK_ParameterQueryTimesSet
@@ -66,17 +73,17 @@ void IOASCII_Choose2D (cGH *GH);
@var GH
@vdesc Pointer to CCTK grid hierarchy
- @vtype cGH *
+ @vtype const cGH *
@vio in
@endvar
@@*/
-void IOASCII_Choose1D (cGH *GH)
+void IOASCII_Choose1D (const cGH *GH)
{
- DECLARE_CCTK_PARAMETERS
- int i, j;
+ int i, j, maxdim;
asciiioGH *myGH;
int *origin_index[3];
CCTK_REAL *origin_phys[3];
+ DECLARE_CCTK_PARAMETERS
/* allocate arrays for origins */
@@ -95,20 +102,22 @@ void IOASCII_Choose1D (cGH *GH)
GET_SLICE (out1D_zline_x, out_zline_x, origin_index[2][0], origin_phys[2][0]);
GET_SLICE (out1D_zline_y, out_zline_y, origin_index[2][1], origin_phys[2][1]);
+ maxdim = CCTK_MaxDim ();
myGH = (asciiioGH *) CCTK_GHExtension (GH, "IOASCII");
+ myGH->spxyz = (int ***) malloc (maxdim * sizeof (int **));
- for (i = 1; i <= CCTK_MaxDim (); i++)
+ for (i = 0; i < maxdim; i++)
{
- if (i <= 3)
+ myGH->spxyz[i] = (int **) malloc ((i + 1) * sizeof (int *));
+
+ for (j = 0; j <= i; j++)
{
- IOUtil_1DLines (GH, i, origin_index, origin_phys, myGH->spxyz[i-1]);
+ myGH->spxyz[i][j] = (int *) calloc (i + 1, sizeof (int));
}
- else
+
+ if (i < 3)
{
- for (j = 0; j < i; j++)
- {
- memset (myGH->spxyz[i-1][j], 0, i);
- }
+ IOUtil_1DLines (GH, i + 1, origin_index, origin_phys, myGH->spxyz[i]);
}
}
@@ -123,7 +132,7 @@ void IOASCII_Choose1D (cGH *GH)
@author Gabrielle Allen
@date July 6 2000
@desc
- Use parameters to choose the 2D slices through the output data.
+ Use parameters to choose the 2D slices through the output data.
@enddesc
@calls CCTK_ParameterQueryTimesSet
@@ -131,34 +140,34 @@ void IOASCII_Choose1D (cGH *GH)
@var GH
@vdesc Pointer to CCTK grid hierarchy
- @vtype cGH *
+ @vtype const cGH *
@vio in
@endvar
@@*/
-void IOASCII_Choose2D (cGH *GH)
+void IOASCII_Choose2D (const cGH *GH)
{
+ int i, maxdim;
+ asciiioGH *myGH;
+ int origin_index[3];
+ CCTK_REAL origin_phys[3];
DECLARE_CCTK_PARAMETERS
- int i;
- asciiioGH *myGH; /* IOASCII extension handle */
- int origin_index[3]; /* Specify output planes by indices */
- CCTK_REAL origin_phys[3]; /* Specify output planes by coordinates */
GET_SLICE (out2D_xyplane_z, out_xyplane_z, origin_index[0], origin_phys[0]);
GET_SLICE (out2D_xzplane_y, out_xzplane_y, origin_index[1], origin_phys[1]);
GET_SLICE (out2D_yzplane_x, out_yzplane_x, origin_index[2], origin_phys[2]);
+ maxdim = CCTK_MaxDim ();
myGH = (asciiioGH *) CCTK_GHExtension (GH, "IOASCII");
+ myGH->sp2xyz = (int **) malloc (3 * sizeof (int *));
- for (i = 1; i <= CCTK_MaxDim (); i++)
+ for (i = 0; i < maxdim; i++)
{
- if (i > 1 && i <= 3)
- {
- IOUtil_2DPlanes (GH, i, origin_index, origin_phys, myGH->sp2xyz[i-1]);
- }
- else
+ myGH->sp2xyz[i] = (int *) calloc (i + 1, sizeof (int));
+
+ if (i > 0 && i < 3)
{
- memset (myGH->sp2xyz[i-1], 0, i * sizeof (myGH->sp2xyz[i-1][0]));
+ IOUtil_2DPlanes (GH, i + 1, origin_index, origin_phys, myGH->sp2xyz[i]);
}
}
}
diff --git a/src/Startup.c b/src/Startup.c
index 8d3494c..73ad0e4 100644
--- a/src/Startup.c
+++ b/src/Startup.c
@@ -9,7 +9,6 @@
@@*/
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -24,11 +23,55 @@ static const char *rcsid = "$Id$";
CCTK_FILEVERSION(CactusBase_IOASCII_Startup_c)
-/* prototypes of routines defined in this source file */
+/********************************************************************
+ ******************** Macro Definitions ************************
+ ********************************************************************/
+#define CREATE_OUTDIR(dir) \
+ { \
+ /* check whether "dir" was set; if not default to "IO::outdir" */ \
+ if (CCTK_ParameterQueryTimesSet (#dir, CCTK_THORNSTRING) <= 0) \
+ { \
+ dir = outdir; \
+ } \
+ \
+ /* omit the directory name if it's the current working dir */ \
+ if (strcmp (dir, ".") == 0) \
+ { \
+ myGH->dir = strdup (""); \
+ } \
+ else \
+ { \
+ myGH->dir = (char *) malloc (strlen (dir) + 2); \
+ sprintf (myGH->dir, "%s/", dir); \
+ } \
+ \
+ /* create the directory */ \
+ i = IOUtil_CreateDirectory (GH, myGH->outdir1D, 0, 0); \
+ if (i < 0) \
+ { \
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, \
+ "IOASCII_SetupGH: Problem creating IOASCII output " \
+ "directory '%s'", myGH->dir); \
+ } \
+ else if (i >= 0 && CCTK_Equals (newverbose, "full")) \
+ { \
+ CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_1D: Output to directory " \
+ "'%s'", myGH->dir); \
+ } \
+ }
+
+
+/********************************************************************
+ ******************** External Routines ************************
+ ********************************************************************/
void IOASCII_Startup (void);
-static void *IOASCII_SetupGH (tFleshConfig *config,
- int convergence_level,
- cGH *GH);
+
+
+/********************************************************************
+ ******************** Internal Routines ************************
+ ********************************************************************/
+static void *IOASCII_SetupGH (tFleshConfig *config, int conv_level, cGH *GH);
+
/*@@
@routine IOASCII_Startup
@@ -39,27 +82,19 @@ static void *IOASCII_SetupGH (tFleshConfig *config,
Registers the GH extensions needed for IOASCII
along with its setup routine.
@enddesc
- @calls CCTK_RegisterGHExtensionSetupGH
+ @calls CCTK_RegisterGHExtension
+ CCTK_RegisterGHExtensionSetupGH
@@*/
void IOASCII_Startup (void)
{
- /* check that thorn IOUtil was activated */
- if (CCTK_GHExtensionHandle ("IO") >= 0)
- {
- CCTK_RegisterGHExtensionSetupGH (CCTK_RegisterGHExtension ("IOASCII"),
- IOASCII_SetupGH);
- }
- else
- {
- CCTK_WARN (1, "IOASCII_Startup: Thorn IOUtil was not activated. "
- "No IOASCII IO methods will be enabled.");
- }
+ CCTK_RegisterGHExtensionSetupGH (CCTK_RegisterGHExtension ("IOASCII"),
+ IOASCII_SetupGH);
}
-/****************************************************************************/
-/* local routines */
-/****************************************************************************/
+/********************************************************************
+ ******************** Internal Routines ************************
+ ********************************************************************/
/*@@
@routine IOASCII_SetupGH
@date Sat Feb 6 1999
@@ -79,7 +114,7 @@ void IOASCII_Startup (void)
@vtype tFleshConfig *
@vio unused
@endvar
- @var convergence_level
+ @var conv_level
@vdesc the convergence level
@vtype int
@vio unused
@@ -90,26 +125,31 @@ void IOASCII_Startup (void)
@vio in
@endvar
- @returntype void *
+ @returntype void *
@returndesc
- pointer to the allocated GH extension structure
+ pointer to the allocated GH extension structure
@endreturndesc
@@*/
-static void *IOASCII_SetupGH (tFleshConfig *config,
- int convergence_level,
- cGH *GH)
+static void *IOASCII_SetupGH (tFleshConfig *config, int conv_level, cGH *GH)
{
- int i, j, numvars, maxdim;
- asciiioGH *newGH;
+ int i, numvars;
+ asciiioGH *myGH;
DECLARE_CCTK_PARAMETERS
/* suppress compiler warnings about unused variables */
- config = config;
- convergence_level = convergence_level;
- GH = GH;
+ (void) (config + 0);
+ (void) (conv_level + 0);
+ (void) (GH + 0);
+
+ /* allocate the GH extension and its components */
+ myGH = (asciiioGH *) malloc (sizeof (asciiioGH));
+ if (! myGH)
+ {
+ CCTK_WARN (0, "IOASCII_SetupGH: Unable to allocate memory for GH");
+ }
- /* Register the IOASCII routines as output methods */
+ /* register the IOASCII routines as output methods */
i = CCTK_RegisterIOMethod ("IOASCII_1D");
CCTK_RegisterIOMethodOutputGH (i, IOASCII_Output1DGH);
CCTK_RegisterIOMethodOutputVarAs (i, IOASCII_Output1DVarAs);
@@ -137,116 +177,39 @@ static void *IOASCII_SetupGH (tFleshConfig *config,
CCTK_INFO ("IOASCII_2D: Output of 2D planes of grid functions/arrays "
"to ASCII files");
CCTK_INFO ("I/O Method 'IOASCII_3D' registered");
- CCTK_INFO ("IOASCII_3D: Output of 3D grid functions/arrays "
- "to ASCII files");
+ CCTK_INFO ("IOASCII_3D: Output of 3D grid functions/arrays to ASCII files");
}
- /* allocate the GH extension and its components */
- newGH = (asciiioGH *) malloc (sizeof (asciiioGH));
+ numvars = CCTK_NumVars ();
+ myGH->out1D_every = (int *) malloc (numvars * sizeof (int));
+ myGH->out2D_every = (int *) malloc (numvars * sizeof (int));
+ myGH->out3D_every = (int *) malloc (numvars * sizeof (int));
+ myGH->out1D_last = (int *) malloc (numvars * sizeof (int));
+ myGH->out2D_last = (int *) malloc (numvars * sizeof (int));
+ myGH->out3D_last = (int *) malloc (numvars * sizeof (int));
- if (newGH)
+ for (i = 0; i < numvars; i++)
{
- numvars = CCTK_NumVars ();
- newGH->out1D_every = (int *) malloc (numvars * sizeof (int));
- newGH->out2D_every = (int *) malloc (numvars * sizeof (int));
- newGH->out3D_every = (int *) malloc (numvars * sizeof (int));
- 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->out1D_vars = strdup ("");
- newGH->out2D_vars = strdup ("");
- newGH->out3D_vars = strdup ("");
- newGH->out1D_every_default = 0;
- newGH->out2D_every_default = 0;
- newGH->out3D_every_default = 0;
-
- newGH->filenameList1D = NULL;
- newGH->fileList_2D = NULL;
- newGH->fileList_3D = NULL;
-
- maxdim = CCTK_MaxDim ();
- newGH->spxyz = (int ***) malloc (maxdim * sizeof (int **));
- newGH->sp2xyz = (int **) malloc (3 * sizeof (int *));
-
- for (i = maxdim - 1; i >= 0; i--)
- {
- newGH->spxyz[i] = (int **) malloc ((i+1) * sizeof (int *));
-
- for (j = 0; j <= i; j++)
- {
- newGH->spxyz[i][j] = (int *) calloc ((i+1), sizeof (int ));
- }
-
- newGH->sp2xyz[i] = (int *) calloc ((i+1), sizeof (int ));
- }
-
- /* Deal with the output directories */
- /* Check whether "outdirXD" was set.
- If so take this dir otherwise default to "IO::outdir" */
- newGH->outdir1D =
- CCTK_ParameterQueryTimesSet ("outdir1D", CCTK_THORNSTRING) > 0 ?
- strdup (outdir1D) : strdup (outdir);
- 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);
- if (i < 0)
- {
- CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOASCII_InitGH: Problem creating IOASCII 1D output"
- " directory '%s'", newGH->outdir1D);
- }
- else if (i >= 0 && CCTK_Equals (newverbose, "full"))
- {
- CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_1D: Output to directory '%s'",
- newGH->outdir1D);
- }
-
- /* create the 2D output dir */
- i = IOUtil_CreateDirectory (GH, newGH->outdir2D, 0, 0);
- if (i < 0)
- {
- CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOASCII_InitGH: problem creating IOASCII 2D output"
- " directory '%s'", newGH->outdir2D);
- }
- else if (i >= 0 && CCTK_Equals (newverbose, "full"))
- {
- 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);
- }
- }
- else
- {
- CCTK_WARN (0, "IOASCII_InitGH: Unable to allocate memory for GH");
+ myGH->out1D_last[i] = -1;
+ myGH->out2D_last[i] = -1;
+ myGH->out3D_last[i] = -1;
}
- return (newGH);
+ myGH->out1D_vars = strdup ("");
+ myGH->out2D_vars = strdup ("");
+ myGH->out3D_vars = strdup ("");
+ myGH->out1D_every_default = 0;
+ myGH->out2D_every_default = 0;
+ myGH->out3D_every_default = 0;
+
+ myGH->filenameList1D = NULL;
+ myGH->fileList_2D = NULL;
+ myGH->fileList_3D = NULL;
+
+ /* make sure all output directories exist */
+ CREATE_OUTDIR (outdir1D);
+ CREATE_OUTDIR (outdir2D);
+ CREATE_OUTDIR (outdir3D);
+
+ return (myGH);
}