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
|
/*@@
@file Write3D.c
@date Fri May 21 1999
@author Thomas Radke, Gerd Lanfermann
@desc
Output and trigger routines for 3D output into HDF5 files.
Added general hyperslab extraction
@enddesc
@history
@hauthor Thomas Radke @hdate May 21 1999
@hdesc Just copied from thorn FlexIO.
@hendhistory
@@*/
#include "cctk.h"
#include "cctk_Parameters.h"
#include "StoreNamedData.h"
#include "CactusPUGH/PUGH/src/include/pugh.h"
#include "CactusBase/IOUtil/src/ioGH.h"
#include "ioHDF5GH.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
/* local function prototypes */
void IOHDF5i_DumpParameters (cGH *GH, hid_t group);
void IOHDF5i_DumpGHExtensions (cGH *GH, hid_t group);
char *IOHDF5_Get_filename_ND (cGH *GH, int index, ioHDF5Geo_t *slab_geo,
const char *name, int *isNewFile);
/*@@
@routine Write3D
@author Paul Walker
@date Feb 1997
@calledby IOHDF5_Output3DVarAs, IOHDF5_TriggerOutput3D
@var GH
@vdesc Pointer to CCTK GH
@vtype cGH
@vio in
@vcomment
@endvar
@var index
@vdesc index of variable to output
@vtype int
@vio in
@vcomment
@endvar
@var alias
@vdesc alias name of variable to output
@vtype const char *
@vio in
@vcomment
@endvar
@@*/
int IOHDF5_Write3D (cGH *GH, int index, const char *alias)
{
DECLARE_CCTK_PARAMETERS
int timelevel;
ioGH *ioUtilGH;
ioHDF5GH *h5GH;
hid_t fid, plist;
int isNewFile;
char *filename;
int ierr=0;
ioHDF5Geo_t geo;
int SDIM;
/* Get the handle for IO extensions */
ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")];
h5GH = (ioHDF5GH *) GH->extensions [CCTK_GHExtensionHandle ("IOHDF5")];
/* The dimension of the slab - HARDCODED */
SDIM = 3;
/* Get the slab geometry for 2D slabs */
geo = h5GH->out_geo[index][SDIM];
/* Set geo.sdim to announce 3d output */
geo.sdim = SDIM;
/* get the dimension of the variable */
geo.vdim = CCTK_GroupDimFromVarI(index);
/* check if variable has storage assigned */
if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (index)))
{
char *fullname = CCTK_FullName (index);
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"No IOHDF5 3D output for '%s' (no storage)", fullname);
free (fullname);
return(-1);
}
if (verbose)
CCTK_VInfo (CCTK_THORNSTRING, "HDF5 %dD-output of variable '%s', "
"downsampling parameters (%d, %d, %d)", SDIM, alias,
geo.downs[0], geo.downs [1], geo.downs[2]);
/* get the filename for output */
if (!(filename = IOHDF5_Get_filename_ND (GH, index, &geo,
alias, &isNewFile))) {
char *fullname = CCTK_FullName (index);
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"Unable to construct file name for '%s'", fullname);
free(fullname);
return(-1);
}
/* open the output file on IO procs
or - in case of parallel HDF5 - on all procs */
#ifdef HAVE_PARALLEL
if (CCTK_MyProc (GH) != ioUtilGH->ioproc && ! ioUtilGH->unchunked)
#else
if (CCTK_MyProc (GH) != ioUtilGH->ioproc)
#endif
{
fid = -1;
}
else
{
if (verbose)
CCTK_VInfo (CCTK_THORNSTRING, "%s HDF5 output file '%s'",
isNewFile ? "Opening" : "Appending", filename);
CACTUS_IOHDF5_ERROR (plist = H5Pcreate (H5P_FILE_ACCESS));
#ifdef CCTK_MPI
#ifdef HAVE_PARALLEL
if (ioUtilGH->unchunked)
CACTUS_IOHDF5_ERROR (H5Pset_mpi (plist, PUGH_pGH (GH)->PUGH_COMM_WORLD,
MPI_INFO_NULL));
#endif
#endif
if (isNewFile)
CACTUS_IOHDF5_ERROR (fid = H5Fcreate (filename, H5F_ACC_TRUNC,
H5P_DEFAULT, plist));
else
CACTUS_IOHDF5_ERROR (fid = H5Fopen (filename, H5F_ACC_RDWR, plist));
H5Pclose (plist);
}
/* get the current timelevel */
timelevel = 0;
/* output global attributes */
if (isNewFile && fid >= 0)
{
hid_t group;
/* all GH extension variables and parameter stuff which is not
specific to any dataset goes into dedicated groups */
if (out3D_parameters)
{
CACTUS_IOHDF5_ERROR (group = H5Gcreate (fid, GLOBAL_PARAMETERS_GROUP, 0));
IOHDF5i_DumpParameters (GH, group);
CACTUS_IOHDF5_ERROR (H5Gclose (group));
}
if (verbose)
CCTK_INFO ("Dumping GH extensions ...");
CACTUS_IOHDF5_ERROR (group = H5Gcreate (fid, GHEXTENSIONS_GROUP, 0));
IOHDF5i_DumpGHExtensions (GH, group);
CACTUS_IOHDF5_ERROR (H5Gclose (group));
}
/* output the data */
ierr = IOHDF5_DumpVar (GH, index, timelevel, &geo, fid);
/* close the file */
if (fid >= 0)
{
if (verbose)
CCTK_INFO ("Closing HDF5 output file from this iteration");
CACTUS_IOHDF5_ERROR (H5Fclose (fid));
}
/* free the filename if it was not registered for re-opening
in IOHDF5_net3D_filename () */
if (out3D_septimefiles)
free (filename);
return(ierr);
}
|