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
203
204
|
/*@@
@file GHExtension.c
@date Tue 9th Feb 1999
@author Gabrielle Allen
@desc
IOUtil GH extension stuff.
@enddesc
@history
@endhistory
@@*/
/*#define DEBUG_IO*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "cctk.h"
#include "util_String.h"
#include "cctk_Parameters.h"
#include "StreamedHDF5GH.h"
static char *rcsid = "$Header$";
/* ===============================================================
utility routines used by other IO thorns
===============================================================*/
/*@@
@routine IOUtil_ParseVarsForOutput
@date Sat March 6 1999
@author Gabrielle Allen
@desc
Sets each flag in the do_output[] do_output to true
if var[i] could be found in the list of variable names.
var_list my also contain group names of variables as well as the
special keyword "all" which indicates that output is requested
on all variables.
@enddesc
@history
@endhistory
@var var_list
@vdesc list of variables and/or group names
@vtype const char *
@vio in
@endvar
@var do_output
@vdesc do_output of flags indicating output was requested for var[i]
@vtype char []
@vio out
@endvar
@@*/
void ParseVarsForOutput (StreamedHDF5GH *h5GH, const char *var_list)
{
char *outname=NULL;
char *before=NULL;
char *after=NULL;
char *splitstring;
int first,groupnum,i,last,index,varnum;
StreamGeo_t geo_tmp;
int ierr=0;
/* First initialise every variable to no output */
for (i=0; i<CCTK_NumVars(); i++)
{
h5GH->do_output[i] = 0;
}
/* Initialize geometry structure with default */
SetDefaultGeo(&geo_tmp);
splitstring = (char *) var_list;
/* split string at blanks */
while(Util_SplitString(&before,&after,splitstring," ")==0) {
#ifdef DEBUG_IO
printf(" String is -%s-\n",splitstring);
printf(" Split is -%s- and -%s-\n",before,after);
#endif
if (CCTK_Equals(before," ")) continue;
if (strlen(before) > 0)
{
/* Extract geometry information */
ierr=GeometryParser(before, &outname, &geo_tmp);
if (ierr<0) printf("GeometryParser failed: >%s<\n",before);
/* Look for any special tokens */
if (CCTK_Equals(outname,"all"))
{
int ilab;
for (ilab=0;ilab<CCTK_NumVars();ilab++) {
h5GH->geo_output[ilab]= geo_tmp;
h5GH->do_output[ilab] = 1;
}
}
else
{
/* See if this name is implementation::variable */
varnum = CCTK_VarIndex(outname);
if ( varnum < 0 )
{
/* See if this name is implementation::group */
groupnum = CCTK_GroupIndex(outname);
if (groupnum < 0)
{
char *msg;
msg = (char *)malloc((100+strlen(outname))*sizeof(char));
sprintf(msg,"Ignoring <%s> in IO string (invalid token)",outname);
CCTK_WARN(2,msg);
free(msg);
}
else
{
/* We have a group so now need all the variables in the group */
first = CCTK_FirstVarIndexI(groupnum);
last = first+CCTK_NumVarsInGroupI(groupnum)-1;
for (index=first;index<=last;index++) {
h5GH->geo_output[index]=geo_tmp;
h5GH->do_output[index] =1;
}
}
}
else
{
h5GH->geo_output[varnum]= geo_tmp;
h5GH->do_output[varnum] = 1;
}
}
}
if(before)
{
free(before);
before = NULL;
}
if(outname)
{
free(outname);
outname = NULL;
}
if(splitstring != var_list)
{
free(splitstring);
}
splitstring = after;
}
if (strlen(splitstring)>0) {
/* Extract geometry information */
ierr=GeometryParser(splitstring, &outname, &geo_tmp);
if (ierr<0) printf("GeometryParser failed: >%s<\n",before);
/* Special cases */
if (CCTK_Equals(splitstring,"all")) {
int ilab;
for (ilab=0;ilab<CCTK_NumVars();ilab++) {
h5GH->geo_output[ilab]=geo_tmp;
h5GH->do_output [ilab]=1;
}
} else {
varnum = CCTK_VarIndex(splitstring);
if (varnum < 0) {
groupnum = CCTK_GroupIndex(splitstring);
if (groupnum < 0) {
char *msg;
msg = (char *)malloc((100+strlen(splitstring))*sizeof(char));
sprintf(msg,"Ignoring %s in IO string (invalid token)",splitstring);
CCTK_WARN(2,msg);
free(msg);
} else {
/* We have a group so now need all the variables in the group */
first = CCTK_FirstVarIndexI(groupnum);
last = first+CCTK_NumVarsInGroupI(groupnum)-1;
for (index=first;index<=last;index++) {
h5GH->geo_output[index]=geo_tmp;
h5GH->do_output[index] =1;
}
}
}
else {
h5GH->geo_output[varnum]=geo_tmp;
h5GH->do_output[varnum] =1;
}
}
}
if (before) free(before);
if (after) free(after);
if(splitstring != var_list)
{
free(splitstring);
}
}
|