aboutsummaryrefslogtreecommitdiff
path: root/src/Startup.c
blob: 30c6bc48a06086f1356c2bdf2a95804ebae94af5 (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
 /*@@
   @file      Startup.c
   @date      Friday 18th September 1999
   @author    Gabrielle Allen
   @desc
              Startup routines for IOBasic.
   @enddesc
   @version   $Id$
 @@*/

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

#include "cctk.h"
#include "cctk_Parameters.h"
#include "CactusBase/IOUtil/src/ioutil_Utils.h"
#include "iobasicGH.h"

static const char *rcsid = "$Header$";

CCTK_FILEVERSION(CactusBase_IOBasic_Startup_c)


/********************************************************************
 ********************    External Routines   ************************
 ********************************************************************/
void IOBasic_Startup (void);

/********************************************************************
 ********************    Internal Routines   ************************
 ********************************************************************/
static void *IOBasic_SetupGH (tFleshConfig *config,
                              int convergence_level,
                              cGH *GH);


 /*@@
   @routine   IOBasic_Startup
   @date      Friday 18th September 1999
   @author    Gabrielle Allen
   @desc
              The startup registration routine for IOBasic.
              Registers the GH extensions needed for IOBasic
              along with its setup routine.
   @enddesc
   @calls     CCTK_RegisterGHExtensionSetupGH
@@*/
void IOBasic_Startup (void)
{
  if (CCTK_GHExtensionHandle ("IO") < 0)
  {
    CCTK_WARN (1, "Thorn IOUtil was not activated. "
                  "No IOBasic I/O methods will be enabled.");
    return;
  }

  CCTK_RegisterGHExtensionSetupGH (CCTK_RegisterGHExtension ("IOBasic"),
                                   IOBasic_SetupGH);
}


/****************************************************************************/
/*                           local routines                                 */
/****************************************************************************/
 /*@@
   @routine   IOBasic_SetupGH
   @date      Sat Feb 6 1999
   @author    Gabrielle Allen
   @desc
              Allocates and sets up IOBasic'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 *IOBasic_SetupGH (tFleshConfig *config,
                              int convergence_level,
                              cGH *GH)
{
  DECLARE_CCTK_PARAMETERS
  int i;
  iobasicGH *newGH;


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

  /* allocate the GH extension and its components */
  newGH = (iobasicGH *) malloc (sizeof (iobasicGH));
  if (newGH)
  {
    /* Register the IOBasic routines as output methods  */
    i = CCTK_RegisterIOMethod ("Scalar");
    CCTK_RegisterIOMethodOutputGH (i, IOBasic_ScalarOutputGH);
    CCTK_RegisterIOMethodOutputVarAs (i, IOBasic_ScalarOutputVarAs);
    CCTK_RegisterIOMethodTimeToOutput (i, IOBasic_TimeForScalarOutput);
    CCTK_RegisterIOMethodTriggerOutput (i, IOBasic_TriggerScalarOutput);

    i = CCTK_RegisterIOMethod ("Info");
    CCTK_RegisterIOMethodOutputGH (i, IOBasic_InfoOutputGH);
    CCTK_RegisterIOMethodTimeToOutput (i, IOBasic_TimeForInfoOutput);
    CCTK_RegisterIOMethodTriggerOutput (i, IOBasic_TriggerInfoOutput);

    if (CCTK_Equals (newverbose, "standard") ||
        CCTK_Equals( newverbose, "full"))
    {
      CCTK_INFO ("I/O Method 'Scalar' registered");
      CCTK_INFO ("Scalar: Output of scalar quantities (grid scalars, "
                 "reductions) to ASCII files");
      CCTK_INFO ("I/O Method 'Info' registered");
      CCTK_INFO ("Info: Output of scalar quantities (grid scalars, "
                 "reductions) to screen");
    }

    i = CCTK_NumVars ();

    newGH->info_reductions = (iobasic_reductionlist_t *)
                             calloc (i, sizeof (iobasic_reductionlist_t));
    newGH->do_outScalar   = (char *) malloc (i * sizeof (char));
    newGH->outInfo_last   = (int *)  malloc (i * sizeof (int));
    newGH->outScalar_last = (int *)  malloc (i * sizeof (int));

    memset (newGH->outInfo_last,   -1, i * sizeof (int));
    memset (newGH->outScalar_last, -1, i * sizeof (int));

    newGH->filenameListScalar = NULL;

    /* Check whether "IOBasic::outdirScalar" was set.
       If so take this dir otherwise default to "IO::outdir" */
    if (CCTK_ParameterQueryTimesSet ("outdirScalar", CCTK_THORNSTRING) <= 0)
    {
      outdirScalar = outdir;
    }
    /* skip the directory pathname if output goes into current directory */
    if (strcmp (outdirScalar, "."))
    {
      i = strlen (outdirScalar);
      newGH->outdirScalar = (char *) malloc (i + 2);
      strcpy (newGH->outdirScalar, outdirScalar);
      newGH->outdirScalar[i] = '/';
      newGH->outdirScalar[i+1] = 0;
    }
    else
    {
      newGH->outdirScalar = "";
    }

    /* create the output dir */
    if (*newGH->outdirScalar && CCTK_MyProc (GH) == 0)
    {
      i = IOUtil_CreateDirectory (GH, newGH->outdirScalar, 0, 0);
      if (i < 0)
      {
        CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                    "IOBasic_SetupGH: Couldn't create Scalar output directory "
                    "'%s'", newGH->outdirScalar);
      }
      else if (i >= 0 && CCTK_Equals (newverbose, "full"))
      {
	CCTK_VInfo (CCTK_THORNSTRING,
		    "Scalar: Output to directory '%s'",
		    newGH->outdirScalar);
      }

    }
  }

  return (newGH);
}