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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
/*@@
@file OutputInfo.c
@date June 31 1999
@author Gabrielle Allen
@desc
Functions to deal with Info output of Variables
@enddesc
@@*/
/*#define IO_DEBUG*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cctk.h"
#include "cctk_parameters.h"
#include "iobasicGH.h"
CCTK_REAL IOBasic_WriteInfo (cGH *GH, int index, const char *operator, const char *alias);
static int first = 1;
int IOBasic_OutputInfoGH (cGH *GH)
{
DECLARE_CCTK_PARAMETERS
int i;
int grouptype;
char *name=NULL;
iobasicGH *myGH;
/* Get the GH extensions for IOBasic */
myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")];
/* Return if no output is required (should use do_1dio parameter) */
if (myGH->infoevery < 1 ||
GH->cctk_iteration % myGH->infoevery != 0)
return 0;
/* Print a header the first time through */
if (first == 1)
{
char l1[1024],l2[1024],l3[1024];
sprintf (l1," it | |");
sprintf (l2," | t |");
sprintf (l3,"--------------");
for (i = 0; i < CCTK_NumVars (); i++)
{
char ll[80];
if(myGH->infonum[i] != 0)
{
sprintf (ll," ");
ll[25-strlen(CCTK_VarName(i))] = '\0';
sprintf (l1,"%s %s%s |",l1,CCTK_VarName(i),ll);
sprintf (l2,"%s Min Max |",l2);
sprintf (l3,"%s----------------------------",l3);
}
}
printf ("%s\n%s\n%s\n%s\n",l3,l1,l2,l3);
fflush(stdout);
first = 0;
}
/* Print the timestep information for all variables */
printf("%4d |%7.3f|",GH->cctk_iteration,GH->cctk_time);
/* Loop over all variables */
for (i = 0; i < CCTK_NumVars (); i++) {
grouptype = CCTK_GroupTypeFromVarI (i);
/* Check this Variable should be output */
if (myGH->infonum [i] != 0) {
/* Check variable not already output this iteration */
if (myGH->infolast [i] == GH->cctk_iteration) {
printf("%12.8f |%12.8f |",myGH->infovals[i][0],myGH->infovals[i][1]);
}
/* Check GF has storage */
else if (grouptype == GROUP_GF && ! CCTK_QueryGroupStorageI (GH,
CCTK_GroupIndexFromVarI (i))){
char *msg, *varname;
varname = CCTK_VarName(i);
msg = (char *) malloc (200 * sizeof (char) + strlen (varname));
sprintf (msg, "No info output in IOBasic_OutputInfoGH for '%s' "
"(no storage)", varname);
CCTK_WARN (2, msg);
free (msg);
} else {
/* Get the variable name for this index (for filename) */
name = CCTK_VarName(i);
#ifdef IO_DEBUG
printf("\nIn IO OutputInfoGH\n----------------\n");
printf(" Index = %d\n",i);
printf(" Variable = -%s-\n",name);
printf(" Last output iteration was = %d\n",myGH->infolast[i]);
printf(" Output iteration number = %d\n",myGH->infonum[i]);
#endif
/* Make the IO call */
myGH->infovals[i][0]=IOBasic_WriteInfo (GH, i, "minimum", name);
myGH->infovals[i][1]=IOBasic_WriteInfo (GH, i, "maximum", name);
printf("%12.8f |%12.8f |",myGH->infovals[i][0],myGH->infovals[i][1]);
/* Register another info output for this variable */
myGH->infonum [i]++;
/* Register GF as having info output this iteration */
myGH->infolast [i] = GH->cctk_iteration;
}
}
}
/* Add the new line */
if (CCTK_MyProc(GH) == 0)
printf("\n");
return 0;
}
/*@@
@routine IOBasic_TimeForInfo
@date June 31 1999
@author Gabrielle Allen
@desc
Decides if it is time to output a variable using info output
method
@enddesc
@calls CCTK_GHExtensionHandle
CCTK_GroupTypeFromVarI
CCTK_WARN
CCTK_QueryGroupStorageI
CCTK_GroupFromVar
@calledby
@history
@endhistory
@var GH
@vdesc Pointer to CCTK GH
@vtype cGH
@vio in
@vcomment
@endvar
@var var
@vdesc index of variable
@vtype int
@vio in
@vcomment
@endvar
@@*/
int IOBasic_TimeForInfo (cGH *GH, int var)
{
int return_type;
int grouptype;
iobasicGH *myGH;
/* Default is do not do output */
return_type = 0;
/* Get the GH extensions for IOBasic */
myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")];
grouptype = CCTK_GroupTypeFromVarI (var);
/* Check this GF should be output */
if (myGH->infonum [var] != 0
&& (GH->cctk_iteration % myGH->infoevery == 0)) {
/* Check GF not already output this iteration */
if (myGH->infolast [var] == GH->cctk_iteration)
CCTK_WARN (2, "Already done info output in IO");
else
return_type = 1;
}
return return_type;
}
int IOBasic_TriggerOutputInfo (cGH *GH, int variable)
{
char *var;
iobasicGH *myGH;
/* Get the GH extension for IOBasic */
myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")];
var = CCTK_VarName (variable);
/* Do the Info output */
#ifdef IO_DEBUG
printf("\nIn IO TriggerOutputInfo\n---------------------\n");
printf(" Index = %d\n",variable);
printf(" Variable = -%s-\n",var);
#endif
myGH->infovals[variable][0]=IOBasic_WriteInfo (GH, variable, "minimum",var);
myGH->infovals[variable][1]=IOBasic_WriteInfo (GH, variable, "maximum",var);
/* Register another Info output for this GF */
myGH->infonum [variable]++;
/* Register GF as having Info output this iteration */
myGH->infolast [variable] = GH->cctk_iteration;
return 0;
}
|