aboutsummaryrefslogtreecommitdiff
path: root/src/Startup.c
blob: 4fa5eabe62b3f83109fc7dcd97dc70784607c84f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
 /*@@
   @file      Startup.c
   @date      Sat Feb 6 1999
   @author    Gabrielle Allen
   @desc 
              Startup routines for IOASCII.
   @enddesc 
   @version   $Id$
 @@*/


#include <stdio.h>
#include <string.h>

#include "cctk.h"
#include "cctk_IOMethods.h"
#include "cctk_Parameters.h"
#include "ioASCIIGH.h"

/* the rcs ID and its dummy function to use it */
static char *rcsid = "$Id$";
CCTK_FILEVERSION(CactusBase_IOASCII_Startup_c)


/* prototypes of routines defined in this source file */
void IOASCII_Startup (void);
static void *IOASCII_SetupGH (tFleshConfig *config,
                              int convergence_level,
                              cGH *GH);

/* prototypes of functions to be registered */
int IOASCII_Output1DGH (cGH *GH);
int IOASCII_TriggerOutput1D (cGH *GH, int);
int IOASCII_TimeFor1D (cGH *GH, int);
int IOASCII_Output1DVarAs (cGH *GH, const char *var, const char *alias);
int IOASCII_Output2DGH (cGH *GH);
int IOASCII_TriggerOutput2D (cGH *GH, int);
int IOASCII_TimeFor2D (cGH *GH, int);
int IOASCII_Output2DVarAs (cGH *GH, const char *var, const char *alias);


 /*@@
   @routine   IOASCII_Startup
   @date      Sat Feb 6 1999
   @author    Gabrielle Allen
   @desc 
              The startup registration routine for IOASCII.
              Registers the GH extensions needed for IOASCII
              along with its setup routine.
   @enddesc 
   @calls     CCTK_RegisterGHExtensionSetupGH
@@*/
void IOASCII_Startup (void)
{
  /* check that thorn IOUtil was activated */
  if (CCTK_GHExtensionHandle ("IO") < 0)
  {
    CCTK_WARN (1, "Thorn IOUtil was not activated. "
                  "No IOASCII IO methods will be enabled.");
    return;
  }

  CCTK_RegisterGHExtensionSetupGH (CCTK_RegisterGHExtension ("IOASCII"),
                                   IOASCII_SetupGH);

}


/****************************************************************************/
/*                           local routines                                 */
/****************************************************************************/
 /*@@
   @routine   IOASCII_SetupGH
   @date      Sat Feb 6 1999
   @author    Gabrielle Allen
   @desc 
              Allocates and sets up IOASCII's GH extension structure
   @enddesc 

   @calls     CCTK_RegisterIOMethod
              CCTK_RegisterIOMethodOutputGH
              CCTK_RegisterIOMethodOutputVarAs
              CCTK_RegisterIOMethodTimeToOutput
              CCTK_RegisterIOMethodTriggerOutput

   @var       config
   @vdesc     the CCTK configuration as provided by the flesh
   @vtype     tFleshConfig *
   @vio       unused
   @endvar
   @var       convergence_level
   @vdesc     the convergence level
   @vtype     int
   @vio       unused
   @endvar
   @var       GH
   @vdesc     Pointer to CCTK grid hierarchy
   @vtype     cGH *
   @vio       in
   @endvar

   @returntype  void *
   @returndesc
                pointer to the allocated GH extension structure
   @endreturndesc
@@*/
static void *IOASCII_SetupGH (tFleshConfig *config,
                              int convergence_level,
                              cGH *GH)
{
  DECLARE_CCTK_PARAMETERS
  int i;
  asciiioGH *newGH;


  /* suppress compiler warnings about unused variables */
  config = config;
  convergence_level = convergence_level;
  GH = GH;

  /* Register the IOASCII routines as output methods  */
  i = CCTK_RegisterIOMethod ("IOASCII_1D");
  CCTK_RegisterIOMethodOutputGH (i, IOASCII_Output1DGH);
  CCTK_RegisterIOMethodOutputVarAs (i, IOASCII_Output1DVarAs);
  CCTK_RegisterIOMethodTimeToOutput (i, IOASCII_TimeFor1D);
  CCTK_RegisterIOMethodTriggerOutput (i, IOASCII_TriggerOutput1D);

  i = CCTK_RegisterIOMethod ("IOASCII_2D");
  CCTK_RegisterIOMethodOutputGH (i, IOASCII_Output2DGH);
  CCTK_RegisterIOMethodOutputVarAs (i, IOASCII_Output2DVarAs);
  CCTK_RegisterIOMethodTimeToOutput (i, IOASCII_TimeFor2D);
  CCTK_RegisterIOMethodTriggerOutput (i, IOASCII_TriggerOutput2D);

  /* allocate the GH extension and its components */
  newGH = (asciiioGH *) malloc (sizeof (asciiioGH));

  i = CCTK_NumVars ();
  newGH->do_out1D = (char *) malloc (i * sizeof (char));
  newGH->do_out2D = (char *) malloc (i * sizeof (char));
  newGH->out1D_last = (int *) malloc (i * sizeof (int));
  newGH->out2D_last = (int *) malloc (i * sizeof (int));
  newGH->spxyz = (int ***) malloc (CCTK_MaxDim() * sizeof (int **));
  newGH->sp2xyz = (int **) malloc (3 * sizeof (int *));

  for (i = CCTK_MaxDim () - 1; i >= 0; i--)
  {
    newGH->spxyz[i]    = (int **) malloc (3 * sizeof (int *));
    newGH->spxyz[i][0] = (int  *) malloc (3 * sizeof (int ));
    newGH->spxyz[i][1] = (int  *) malloc (3 * sizeof (int ));
    newGH->spxyz[i][2] = (int  *) malloc (3 * sizeof (int ));

    newGH->sp2xyz[i]   = (int  *) malloc (3 * sizeof (int ));
  }

  /* How often to output */
  newGH->out1D_every = out_every > 0 ? out_every : -1;
  if (out1D_every > 0)
  {
    newGH->out1D_every = out1D_every;
  }
  newGH->out2D_every = out_every > 0 ? out_every : -1;
  if (out2D_every > 0)
  {
    newGH->out2D_every = out2D_every;
  }

  /* 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);

  /* create the output dir */
  if (CCTK_MyProc (GH) == 0)
  {
    i = CCTK_CreateDirectory (0755, newGH->outdir1D);
    if (i < 0)
    {
      CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "IOASCII_InitGH: Problem creating 1D output directory '%s'",
                  newGH->outdir1D);
    }
    if (i > 0)
    {
      CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "IOASCII_InitGH: 1D output directory '%s' already exists", 
                  newGH->outdir1D);
    }
    i = CCTK_CreateDirectory (0755, newGH->outdir2D);
    if (i < 0)
    {
      CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "IOASCII_InitGH: Problem creating 2D output directory '%s'",
                  newGH->outdir2D);
    }
    if (i > 0)
    {
      CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "IOASCII_InitGH: 2D output directory '%s' already exists", 
                  newGH->outdir2D);
    }
  }

  for (i = 0; i < CCTK_NumVars (); i++)
  {
    newGH->out1D_last[i] = -1;
    newGH->out2D_last[i] = -1;
  }

  newGH->filenameList1D = NULL;
  newGH->fileList_2D = NULL;

  return (newGH);
}