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


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


/* local function prototypes */
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));
    }
    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;


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

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

  return (myGH);
}