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 WriteInfo.c
@date June 31 1999
@author Gabrielle Allen, Paul Walker, Thomas Radke
@desc
Gets the data for IOBasic's info output.
@enddesc
@version $Id: /cactusdevcvs/CactusBase/IOBasic/src/OutputInfo.c,v 1.24 2001
@@*/
#include <stdlib.h>
#include "cctk.h"
#include "iobasicGH.h"
/* the rcs ID and its dummy function to use it */
static const char *rcsid = "$Header$";
CCTK_FILEVERSION(CactusBase_IOBasic_WriteInfo_c)
/*@@
@routine IOBasic_WriteInfo
@date Tue 31 July 2001
@author Thomas Radke
@desc
Gets the data values to output for a given CCTK variable.
For CCTK_SCALAR variables, their value is taken,
for CCTK_GF and CCTK_ARRAY variables the appropriate
reduction operations are performed and their results taken.
@enddesc
@calls CCTK_VarDataPtrI
CCTK_Reduce
@var GH
@vdesc Pointer to CCTK grid hierarchy
@vtype const cGH *
@vio in
@endvar
@var vindex
@vdesc CCTK index of the variable to output
@vtype int
@vio in
@endvar
@var alias
@vdesc alias name to use for building the output filename
@vtype const char *
@vio in
@endvar
@returntype int
@returndesc
0 for success, or<BR>
-1 if variable has no storage assigned
@endreturndesc
@@*/
int IOBasic_WriteInfo (const cGH *GH, int vindex)
{
int vtype;
char *fullname;
iobasicGH *myGH;
void *ptr;
iobasic_reduction_t *reduction;
/*** FIXME: can CCTK_Reduce() have a 'const cGH *' parameter ?? ***/
union
{
const cGH *const_ptr;
cGH *non_const_ptr;
} GH_fake_const;
GH_fake_const.const_ptr = GH;
myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
reduction = myGH->info_reductions[vindex].reductions;
/* first, check if variable has storage assigned */
if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (vindex)))
{
fullname = CCTK_FullName (vindex);
CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
"IOBasic_WriteInfo: No info output for '%s' (no storage)",
fullname);
free (fullname);
/* invalidate data buffer for this variable */
while (reduction)
{
reduction->is_valid = 0;
reduction = reduction->next;
}
return (-1);
}
/* CCTK scalars are printed by their value, cast into a C double */
if (CCTK_GroupTypeFromVarI (vindex) == CCTK_SCALAR)
{
reduction->is_valid = 1;
/* get the variable's data type and data pointer */
ptr = CCTK_VarDataPtrI (GH, 0, vindex);
vtype = CCTK_VarTypeI (vindex);
if (vtype == CCTK_VARIABLE_CHAR)
{
reduction->value = (double) *(CCTK_CHAR *) ptr;
}
else if (vtype == CCTK_VARIABLE_INT)
{
reduction->value = (double) *(CCTK_INT *) ptr;
}
else if (vtype == CCTK_VARIABLE_REAL)
{
reduction->value = (double) *(CCTK_REAL *) ptr;
}
else if (vtype == CCTK_VARIABLE_COMPLEX)
{
reduction->value = (double) ((CCTK_REAL *) ptr)[0];
reduction->next->value = (double) ((CCTK_REAL *) ptr)[1];
reduction->next->is_valid = 1;
}
#ifdef CCTK_INT2
else if (vtype == CCTK_VARIABLE_INT2)
{
reduction->value = (double) *(CCTK_INT2 *) ptr;
}
#endif
#ifdef CCTK_INT4
else if (vtype == CCTK_VARIABLE_INT4)
{
reduction->value = (double) *(CCTK_INT4 *) ptr;
}
#endif
#ifdef CCTK_INT8
else if (vtype == CCTK_VARIABLE_INT8)
{
reduction->value = (double) *(CCTK_INT8 *) ptr;
}
#endif
#ifdef CCTK_REAL4
else if (vtype == CCTK_VARIABLE_REAL4)
{
reduction->value = (double) *(CCTK_REAL4 *) ptr;
}
else if (vtype == CCTK_VARIABLE_COMPLEX8)
{
reduction->value = (double) ((CCTK_REAL4 *) ptr)[0];
reduction->next->value = (double) ((CCTK_REAL4 *) ptr)[1];
reduction->next->is_valid = 1;
}
#endif
#ifdef CCTK_REAL8
else if (vtype == CCTK_VARIABLE_REAL8)
{
reduction->value = (double) *(CCTK_REAL8 *) ptr;
}
else if (vtype == CCTK_VARIABLE_COMPLEX16)
{
reduction->value = (double) ((CCTK_REAL8 *) ptr)[0];
reduction->next->value = (double) ((CCTK_REAL8 *) ptr)[1];
reduction->next->is_valid = 1;
}
#endif
#ifdef CCTK_REAL16
else if (vtype == CCTK_VARIABLE_REAL16)
{
reduction->value = (double) *(CCTK_REAL16 *) ptr;
}
else if (vtype == CCTK_VARIABLE_COMPLEX32)
{
reduction->value = (double) ((CCTK_REAL16 *) ptr)[0];
reduction->next->value = (double) ((CCTK_REAL16 *) ptr)[1];
reduction->next->is_valid = 1;
}
#endif
else
{
CCTK_WARN (3, "IOBasic_WriteInfo: Unsupported data type");
reduction->is_valid = 0;
}
}
else
{
/* for CCTK_GF and CCTK_ARRAY variables: loop over all reductions */
while (reduction)
{
reduction->is_valid = CCTK_Reduce (GH_fake_const.non_const_ptr, 0,
reduction->handle, 1,
CCTK_VARIABLE_REAL,
&reduction->value, 1, vindex) == 0;
if (! reduction->is_valid)
{
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"IOBasic_WriteInfo: Internal error in reduction '%s'",
reduction->name);
}
reduction = reduction->next;
}
}
return (0);
}
|