aboutsummaryrefslogtreecommitdiff
path: root/src/Startup.c
blob: 710e35c62cfdaa062ba2c7c5035ebb8c3119d693 (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
 /*@@
   @file      Startup.c
   @date      Fri Oct 6 2000
   @author    Thomas Radke
   @desc 
              Startup and termination routines for IOHDF5Util.
   @enddesc 
   @version   $Id$
@@*/


#include <stdlib.h>

#include "cctk.h"
#include "cctk_Parameters.h"
#include "ioHDF5UtilGH.h"


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

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


 /*@@
   @routine   IOHDF5Util_Startup
   @date      Fri Oct 6 2000
   @author    Thomas Radke
   @desc 
              The startup registration routine for IOHDF5Util.
              Registers the GH extensions needed for IOHDF5Util
              and the routine to set it up.
   @enddesc 

   @calls     CCTK_RegisterGHExtensionSetupGH
@@*/
void IOHDF5Util_Startup (void)
{
  /* check dynamic thorn dependencies */
  if (CCTK_GHExtensionHandle ("IO") < 0)
  {
    CCTK_WARN (1, "Thorn IOUtil was not activated. "
                  "No HDF5 IO methods will be registered.");
  }
  else if (CCTK_GHExtensionHandle ("PUGH") < 0)
  {
    CCTK_WARN (1, "Thorn PUGH was not activated. "
                  "No HDF5 IO methods will be registered.");
  }
  else
  {
    CCTK_RegisterGHExtensionSetupGH (CCTK_RegisterGHExtension ("IOHDF5Util"),
                                     IOHDF5Util_SetupGH);
  }
}


 /*@@
   @routine   IOHDF5Util_Terminate
   @date      Fri Oct 6 2000
   @author    Thomas Radke
   @desc 
              The termination registration routine for IOHDF5Util.
              It frees any resources kept on the GH extensions.
   @enddesc 
   @var        GH
   @vdesc      Pointer to CCTK GH
   @vtype      cGH *
   @vio        in
   @endvar
@@*/
void IOHDF5Util_Terminate (cGH *GH)
{
  ioHDF5UtilGH *myGH;


  myGH = (ioHDF5UtilGH *) CCTK_GHExtension (GH, "IOHDF5Util");
  if (myGH)
  {
    /* close the dataspaces used to write scalar and array attributes */
    if (myGH->scalar_dataspace >= 0)
    {
      IOHDF5_ERROR (H5Sclose (myGH->scalar_dataspace));
    }
    if (myGH->array_dataspace >= 0)
    {
      IOHDF5_ERROR (H5Sclose (myGH->array_dataspace));
    }

    /* close the predefined complex and string datatypes */
    if (myGH->IOHDF5_COMPLEX >= 0)
    {
      IOHDF5_ERROR (H5Tclose (myGH->IOHDF5_COMPLEX));
    }
#ifdef CCTK_REAL4
    if (myGH->IOHDF5_COMPLEX8 >= 0)
    {
      IOHDF5_ERROR (H5Tclose (myGH->IOHDF5_COMPLEX8));
    }
#endif
#ifdef CCTK_REAL8
    if (myGH->IOHDF5_COMPLEX16 >= 0)
    {
      IOHDF5_ERROR (H5Tclose (myGH->IOHDF5_COMPLEX16));
    }
#endif
#ifdef CCTK_REAL16
    if (myGH->IOHDF5_COMPLEX32 >= 0)
    {
      IOHDF5_ERROR (H5Tclose (myGH->IOHDF5_COMPLEX32));
    }
#endif
    if (myGH->IOHDF5_STRING >= 0)
    {
      IOHDF5_ERROR (H5Tclose (myGH->IOHDF5_STRING));
    }
  }
}


/****************************************************************************/
/*                           local routines                                 */
/****************************************************************************/
 /*@@
   @routine     IOHDF5Util_SetupGH
   @date        Fri Oct 6 2000
   @author      Thomas Radke
   @desc 
                Allocate a GH extension structure for IOHDF5Util and set it up.
   @enddesc 

   @returntype  void *
   @returndesc
                pointer to the allocated GH extension structure
   @endreturndesc
@@*/
static void *IOHDF5Util_SetupGH (tFleshConfig *config,
                                 int convergence_level,
                                 cGH *GH)
{
  DECLARE_CCTK_PARAMETERS
  ioHDF5UtilGH *myGH;


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

  myGH = (ioHDF5UtilGH *) malloc (sizeof (ioHDF5UtilGH));

  /* save the original error printing routine and its argument */
  IOHDF5_ERROR (H5Eget_auto (&myGH->print_error_fn, &myGH->print_error_fn_arg));

  /* predefine dataspaces for writing scalar and array attributes */
  /* the dimension of the array dataspace is set when used */
  IOHDF5_ERROR (myGH->scalar_dataspace = H5Screate (H5S_SCALAR));
  IOHDF5_ERROR (myGH->array_dataspace  = H5Screate (H5S_SIMPLE));

  /* predefine IOHDF5_COMPLEX datatypes */
  IOHDF5_ERROR (myGH->IOHDF5_COMPLEX =
                H5Tcreate (H5T_COMPOUND, sizeof (CCTK_COMPLEX)));
  IOHDF5_ERROR (H5Tinsert (myGH->IOHDF5_COMPLEX, "real",
                           offsetof (CCTK_COMPLEX, Re), IOHDF5_REAL));
  IOHDF5_ERROR (H5Tinsert (myGH->IOHDF5_COMPLEX, "imag",
                           offsetof (CCTK_COMPLEX, Im), IOHDF5_REAL));
#ifdef CCTK_REAL4
  IOHDF5_ERROR (myGH->IOHDF5_COMPLEX8 =
                H5Tcreate (H5T_COMPOUND, sizeof (CCTK_COMPLEX8)));
  IOHDF5_ERROR (H5Tinsert (myGH->IOHDF5_COMPLEX8, "real",
                           offsetof (CCTK_COMPLEX8, Re), IOHDF5_REAL4));
  IOHDF5_ERROR (H5Tinsert (myGH->IOHDF5_COMPLEX8, "imag",
                           offsetof (CCTK_COMPLEX8, Im), IOHDF5_REAL4));
#endif
#ifdef CCTK_REAL8
  IOHDF5_ERROR (myGH->IOHDF5_COMPLEX16 =
                H5Tcreate (H5T_COMPOUND, sizeof (CCTK_COMPLEX16)));
  IOHDF5_ERROR (H5Tinsert (myGH->IOHDF5_COMPLEX16, "real",
                           offsetof (CCTK_COMPLEX16, Re), IOHDF5_REAL8));
  IOHDF5_ERROR (H5Tinsert (myGH->IOHDF5_COMPLEX16, "imag",
                           offsetof (CCTK_COMPLEX16, Im), IOHDF5_REAL8));
#endif
#ifdef CCTK_REAL16
  IOHDF5_ERROR (myGH->IOHDF5_COMPLEX32 =
                H5Tcreate (H5T_COMPOUND, sizeof (CCTK_COMPLEX32)));
  IOHDF5_ERROR (H5Tinsert (myGH->IOHDF5_COMPLEX32, "real",
                           offsetof (CCTK_COMPLEX32, Re), IOHDF5_REAL16));
  IOHDF5_ERROR (H5Tinsert (myGH->IOHDF5_COMPLEX32, "imag",
                           offsetof (CCTK_COMPLEX32, Im), IOHDF5_REAL16));
#endif

  /* predefine a C string datatype */
  IOHDF5_ERROR (myGH->IOHDF5_STRING = H5Tcopy (H5T_C_S1));

  return (myGH);
}