aboutsummaryrefslogtreecommitdiff
path: root/src/Startup.c
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 /src/Startup.c
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
Diffstat (limited to 'src/Startup.c')
-rw-r--r--src/Startup.c239
1 files changed, 101 insertions, 138 deletions
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);
}