aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetIOASCII/src/ioascii.cc
diff options
context:
space:
mode:
Diffstat (limited to 'Carpet/CarpetIOASCII/src/ioascii.cc')
-rw-r--r--Carpet/CarpetIOASCII/src/ioascii.cc675
1 files changed, 403 insertions, 272 deletions
diff --git a/Carpet/CarpetIOASCII/src/ioascii.cc b/Carpet/CarpetIOASCII/src/ioascii.cc
index e8ef28719..d45163d96 100644
--- a/Carpet/CarpetIOASCII/src/ioascii.cc
+++ b/Carpet/CarpetIOASCII/src/ioascii.cc
@@ -30,7 +30,7 @@
#include "ioascii.hh"
extern "C" {
- static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetIOASCII/src/ioascii.cc,v 1.55 2003/11/13 16:03:38 schnetter Exp $";
+ static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetIOASCII/src/ioascii.cc,v 1.56 2004/01/25 14:57:28 schnetter Exp $";
CCTK_FILEVERSION(Carpet_CarpetIOASCII_ioascii_cc);
}
@@ -48,8 +48,6 @@ namespace CarpetIOASCII {
using namespace std;
using namespace Carpet;
- bool CheckForVariable (const cGH* const cgh,
- const char* const varlist, const int vindex);
void SetFlag (int index, const char* optstring, void* arg);
template<int D,int DD>
@@ -60,23 +58,34 @@ namespace CarpetIOASCII {
const int time,
const vect<int,D>& org,
const vect<int,DD>& dirs,
- const int tl,
const int rl,
- const int c,
const int ml,
+ const int m,
+ const int c,
+ const int tl,
const CCTK_REAL coord_time,
const vect<CCTK_REAL,D>& coord_lower,
const vect<CCTK_REAL,D>& coord_upper);
- int CarpetIOASCIIStartup()
+ void CarpetIOASCIIStartup()
{
IOASCII<1>::Startup();
IOASCII<2>::Startup();
IOASCII<3>::Startup();
+ }
+
+
+
+ void CarpetIOASCIIInit (CCTK_ARGUMENTS)
+ {
+ DECLARE_CCTK_ARGUMENTS;
- return 0;
+ for (int d=0; d<3; ++d) {
+ next_output_iteration[d] = 0;
+ next_output_time[d] = cctkGH->cctk_time;
+ }
}
@@ -158,7 +167,14 @@ namespace CarpetIOASCII {
{
DECLARE_CCTK_PARAMETERS;
+ assert (is_level_mode());
+
const int n = CCTK_VarIndex(varname);
+ if (n<0) {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Variable \"%s\" does not exist", varname);
+ return -1;
+ }
assert (n>=0 && n<CCTK_NumVars());
const int group = CCTK_GroupIndexFromVarI (n);
assert (group>=0 && group<(int)Carpet::arrdata.size());
@@ -178,21 +194,23 @@ namespace CarpetIOASCII {
}
const int grouptype = CCTK_GroupTypeI(group);
- const int rl = grouptype==CCTK_GF ? reflevel : 0;
+ if (grouptype != CCTK_GF) assert (reflevel==0);
+
+ const int groupdim = CCTK_GroupDimI(group);
+ assert (outdim <= groupdim);
// Get grid hierarchy extentsion from IOUtil
const ioGH * const iogh = (const ioGH *)CCTK_GHExtension (cgh, "IO");
assert (iogh);
// Create the output directory
- const char* myoutdir = GetStringParameter("out%dD_dir", out_dir);
+ const char* const myoutdir = GetStringParameter("out%dD_dir", out_dir);
if (CCTK_MyProc(cgh)==0) {
CCTK_CreateDirectory (0755, myoutdir);
}
// Loop over all direction combinations
- vect<int,outdim> dirs;
- for (int d=0; d<outdim; ++d) dirs[d] = 0;
+ vect<int,outdim> dirs (0);
bool done;
do {
@@ -247,222 +265,254 @@ namespace CarpetIOASCII {
// Skip output if not desired
if (desired) {
-
- // Invent a file name
- ostringstream filenamebuf;
- filenamebuf << myoutdir << "/" << alias << ".";
- for (int d=0; d<outdim; ++d) {
- assert (dirs[d]>=0 && dirs[d]<3);
- const char* const coords = "xyz";
- filenamebuf << coords[dirs[d]];
- }
- const char* const suffixes = "lpv";
- filenamebuf << suffixes[outdim-1];
- // we need a persistent temporary here
- string filenamestr = filenamebuf.str();
- const char* const filename = filenamestr.c_str();
-
- ofstream file;
-
- if (CCTK_MyProc(cgh)==0) {
- // If this is the first time, then write a nice header on
- // the root processor
- if (do_truncate[n]) {
- struct stat fileinfo;
- if (! iogh->recovered
- || stat(filename, &fileinfo)!=0) {
- file.open (filename, ios::out | ios::trunc);
- if (! file.good()) {
- CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Could not open output file \"%s\" for variable \"%s\"",
- filename, varname);
- }
- assert (file.good());
- file << "# " << varname;
- for (int d=0; d<outdim; ++d) {
- file << " " << "xyz"[dirs[d]];
- }
- file << " (" << alias << ")" << endl;
- file << "#" << endl;
- assert (file.good());
- }
- }
- if (! file.is_open()) {
- file.open (filename, ios::out | ios::app);
- assert (file.good());
- }
- file << setprecision(15);
- assert (file.good());
- }
-
- assert (outdim <= CCTK_GroupDimI(group));
-
- // Find the output offset
- vect<int,dim> offset(0);
- switch (outdim) {
- case 1:
- switch (dirs[0]) {
- case 0:
- offset[1] = GetGridOffset (cgh, 2,
- "out%dD_xline_yi", "out_xline_yi",
- "out%dD_xline_y", "out_xline_y",
- out_xline_y);
- offset[2] = GetGridOffset (cgh, 3,
- "out%dD_xline_zi", "out_xline_zi",
- "out%dD_xline_z", "out_xline_z",
- out_xline_z);
- break;
- case 1:
- offset[0] = GetGridOffset (cgh, 1,
- "out%dD_yline_xi", "out_yline_xi",
- "out%dD_yline_x", "out_yline_x",
- out_yline_x);
- offset[2] = GetGridOffset (cgh, 3,
- "out%dD_yline_zi", "out_yline_zi",
- "out%dD_yline_z", "out_yline_z",
- out_yline_z);
- break;
- case 2:
- offset[0] = GetGridOffset (cgh, 1,
- "out%dD_zline_xi", "out_zline_xi",
- "out%dD_zline_x", "out_zline_x",
- out_zline_x);
- offset[1] = GetGridOffset (cgh, 2,
- "out%dD_zline_yi", "out_zline_yi",
- "out%dD_zline_y", "out_zline_y",
- out_zline_y);
- break;
- default:
- assert (0);
- }
- break;
- case 2:
- if (dirs[0]==0 && dirs[1]==1) {
- offset[2] = GetGridOffset
- (cgh, 3,
- "out%dD_xyplane_zi", "out_xyplane_zi",
- "out%dD_xyplane_z", "out_xyplane_z",
- out_xyplane_z);
- } else if (dirs[0]==0 && dirs[1]==2) {
- offset[1] = GetGridOffset
- (cgh, 2,
- "out%dD_xzplane_yi", "out_xzplane_yi",
- "out%dD_xzplane_y", "out_xzplane_y",
- out_xzplane_y);
- } else if (dirs[0]==1 && dirs[1]==2) {
- offset[0] = GetGridOffset
- (cgh, 1,
- "out%dD_yzplane_xi", "out_yzplane_xi",
- "out%dD_yzplane_x", "out_yzplane_x",
- out_yzplane_x);
- } else {
- assert (0);
- }
- break;
- case 3:
- // The offset doesn't matter in this case
- break;
- default:
- assert (0);
- }
-
- // Traverse all components on this refinement and multigrid
- // level
- BEGIN_COMPONENT_LOOP(cgh, grouptype) {
-
- const ggf<dim>* ff = 0;
-
- assert (var < (int)arrdata[group].data.size());
- ff = (ggf<dim>*)arrdata[group].data[var];
-
- const int mintl = output_all_timelevels ? 1-num_tl : 0;
- const int maxtl = 0;
- for (int tl=mintl; tl<=maxtl; ++tl) {
-
- const gdata<dim>* const data
- = (*ff) (tl, rl, component, mglevel);
- bbox<int,dim> ext = data->extent();
-
- vect<int,dim> lo = ext.lower();
- vect<int,dim> hi = ext.upper();
- vect<int,dim> str = ext.stride();
-
- // Ignore ghost zones if desired
- for (int d=0; d<dim; ++d) {
- bool output_lower_ghosts
- = cgh->cctk_bbox[2*d] ? out3D_outer_ghosts : out3D_ghosts;
- bool output_upper_ghosts
- = cgh->cctk_bbox[2*d+1] ? out3D_outer_ghosts : out3D_ghosts;
-
- if (! output_lower_ghosts) {
- lo[d] += cgh->cctk_nghostzones[d] * str[d];
+
+ // Traverse all maps on this refinement and multigrid level
+ BEGIN_MAP_LOOP(cgh, grouptype) {
+
+ // Find the output offset
+ ivect offset(0);
+ if (grouptype == CCTK_GF) {
+ switch (outdim) {
+ case 1:
+ switch (dirs[0]) {
+ case 0:
+ offset[1] = GetGridOffset (cgh, 2,
+ "out%dD_xline_yi", "out_xline_yi",
+ "out%dD_xline_y", "out_xline_y",
+ out_xline_y);
+ offset[2] = GetGridOffset (cgh, 3,
+ "out%dD_xline_zi", "out_xline_zi",
+ "out%dD_xline_z", "out_xline_z",
+ out_xline_z);
+ break;
+ case 1:
+ offset[0] = GetGridOffset (cgh, 1,
+ "out%dD_yline_xi", "out_yline_xi",
+ "out%dD_yline_x", "out_yline_x",
+ out_yline_x);
+ offset[2] = GetGridOffset (cgh, 3,
+ "out%dD_yline_zi", "out_yline_zi",
+ "out%dD_yline_z", "out_yline_z",
+ out_yline_z);
+ break;
+ case 2:
+ offset[0] = GetGridOffset (cgh, 1,
+ "out%dD_zline_xi", "out_zline_xi",
+ "out%dD_zline_x", "out_zline_x",
+ out_zline_x);
+ offset[1] = GetGridOffset (cgh, 2,
+ "out%dD_zline_yi", "out_zline_yi",
+ "out%dD_zline_y", "out_zline_y",
+ out_zline_y);
+ break;
+ default:
+ assert (0);
}
- if (! output_upper_ghosts) {
- hi[d] -= cgh->cctk_nghostzones[d] * str[d];
+ break;
+ case 2:
+ if (dirs[0]==0 && dirs[1]==1) {
+ offset[2] = GetGridOffset
+ (cgh, 3,
+ "out%dD_xyplane_zi", "out_xyplane_zi",
+ "out%dD_xyplane_z", "out_xyplane_z",
+ out_xyplane_z);
+ } else if (dirs[0]==0 && dirs[1]==2) {
+ offset[1] = GetGridOffset
+ (cgh, 2,
+ "out%dD_xzplane_yi", "out_xzplane_yi",
+ "out%dD_xzplane_y", "out_xzplane_y",
+ out_xzplane_y);
+ } else if (dirs[0]==1 && dirs[1]==2) {
+ offset[0] = GetGridOffset
+ (cgh, 1,
+ "out%dD_yzplane_xi", "out_yzplane_xi",
+ "out%dD_yzplane_x", "out_yzplane_x",
+ out_yzplane_x);
+ } else {
+ assert (0);
}
+ break;
+ case 3:
+ // The offset doesn't matter in this case
+ break;
+ default:
+ assert (0);
}
- ext = bbox<int,dim>(lo,hi,str);
+ } // if grouptype is GF
+
+ ofstream file;
+ if (CCTK_MyProc(cgh)==0) {
- // coordinates
- const CCTK_REAL coord_time = cgh->cctk_time;
- vect<CCTK_REAL,dim> global_lower;
- vect<CCTK_REAL,dim> coord_delta;
- if (grouptype == CCTK_GF) {
- for (int d=0; d<dim; ++d) {
- global_lower[d] = cgh->cctk_origin_space[d];
- coord_delta[d] = cgh->cctk_delta_space[d] / maxreflevelfact;
+ // Invent a file name
+ ostringstream filenamebuf;
+ if (new_filename_scheme) {
+ filenamebuf << myoutdir << "/" << alias << ".";
+ if (maps > 1) {
+ cout << Carpet::map << "-";
+ }
+ for (int d=0; d<outdim; ++d) {
+ const char* const coords = "xyz";
+ filenamebuf << coords[dirs[d]];
}
+// The offsets differ per level
+// for (int dd=0; dd<groupdim; ++dd) {
+// bool print_dir = true;
+// for (int d=0; d<outdim; ++d) {
+// print_dir = print_dir && dirs[d] != dd;
+// }
+// if (print_dir) {
+// filenamebuf << "." << offset[dd];
+// }
+// }
+ filenamebuf << ".asc";
} else {
- for (int d=0; d<dim; ++d) {
- global_lower[d] = 0.0;
- coord_delta[d] = 1.0 / (cgh->cctk_gsh[d] - 1);
+ filenamebuf << myoutdir << "/" << alias << ".";
+ if (maps > 1) {
+ cout << Carpet::map << "-";
}
+ for (int d=0; d<outdim; ++d) {
+ assert (dirs[d]>=0 && dirs[d]<3);
+ const char* const coords = "xyz";
+ filenamebuf << coords[dirs[d]];
+ }
+ const char* const suffixes = "lpv";
+ filenamebuf << suffixes[outdim-1];
}
- // Note: don't permute the "coord_delta" and
- // "data->extent().lower()"
- // (it seems that for gcc 2.95 you then pick up the
- // integer operator*)
- const vect<CCTK_REAL,dim> coord_lower = global_lower + coord_delta * vect<CCTK_REAL,dim>(lo);
- const vect<CCTK_REAL,dim> coord_upper = global_lower + coord_delta * vect<CCTK_REAL,dim>(hi);
+ // we need a persistent temporary here
+ string filenamestr = filenamebuf.str();
+ const char* const filename = filenamestr.c_str();
- vect<int,dim> offset1;
- for (int d=0; d<dim; ++d) {
- assert (cgh->cctk_levoffdenom[d]==1);
- offset1[d] = (cgh->cctk_levoff[d] + offset[d]) * ext.stride()[d];
+ // If this is the first time, then write a nice header
+ if (do_truncate[n]) {
+ struct stat fileinfo;
+ if (! iogh->recovered
+ || stat(filename, &fileinfo)!=0) {
+ file.open (filename, ios::out | ios::trunc);
+ if (! file.good()) {
+ CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Could not open output file \"%s\" for variable \"%s\"",
+ filename, varname);
+ }
+ assert (file.good());
+ file << "# " << varname;
+ for (int d=0; d<outdim; ++d) {
+ file << " " << "xyz"[dirs[d]];
+ }
+ file << " (" << alias << ")" << endl;
+ file << "#" << endl;
+ assert (file.good());
+ }
}
- for (int d=0; d<outdim; ++d) {
- offset1[dirs[d]] = ext.lower()[dirs[d]];
+
+ // Open the file
+ if (! file.is_open()) {
+ file.open (filename, ios::out | ios::app);
+ assert (file.good());
}
- WriteASCII (file, data, ext, n, cgh->cctk_iteration, offset1, dirs,
- tl, rl, component, mglevel,
- coord_time, coord_lower, coord_upper);
+ file << setprecision(15);
+ assert (file.good());
- // Append EOL after every component
- if (CCTK_MyProc(cgh)==0) {
- if (separate_components) {
- assert (file.good());
- file << endl;
+ } // if on the root processor
+
+ // Traverse and components on this multigrid and
+ // refinement level and map
+ BEGIN_COMPONENT_LOOP(cgh, grouptype) {
+
+ const ggf<dim>* ff = 0;
+
+ assert (var < (int)arrdata[group][Carpet::map].data.size());
+ ff = (ggf<dim>*)arrdata[group][Carpet::map].data[var];
+
+ const int mintl = output_all_timelevels ? 1-num_tl : 0;
+ const int maxtl = 0;
+ for (int tl=mintl; tl<=maxtl; ++tl) {
+
+ const gdata<dim>* const data
+ = (*ff) (tl, reflevel, component, mglevel);
+ ibbox ext = data->extent();
+
+ ivect lo = ext.lower();
+ ivect hi = ext.upper();
+ ivect str = ext.stride();
+
+ // Ignore ghost zones if desired
+ for (int d=0; d<dim; ++d) {
+ bool output_lower_ghosts
+ = cgh->cctk_bbox[2*d] ? out3D_outer_ghosts : out3D_ghosts;
+ bool output_upper_ghosts
+ = cgh->cctk_bbox[2*d+1] ? out3D_outer_ghosts : out3D_ghosts;
+
+ if (! output_lower_ghosts) {
+ lo[d] += cgh->cctk_nghostzones[d] * str[d];
+ }
+ if (! output_upper_ghosts) {
+ hi[d] -= cgh->cctk_nghostzones[d] * str[d];
+ }
+ }
+ ext = ibbox(lo,hi,str);
+
+ // coordinates
+ const CCTK_REAL coord_time = cgh->cctk_time;
+ rvect global_lower;
+ rvect coord_delta;
+ if (grouptype == CCTK_GF) {
+ for (int d=0; d<dim; ++d) {
+ global_lower[d] = cgh->cctk_origin_space[d];
+ coord_delta[d] = cgh->cctk_delta_space[d] / maxreflevelfact;
+ }
+ } else {
+ for (int d=0; d<dim; ++d) {
+ global_lower[d] = 0.0;
+ coord_delta[d] = 1.0 / (cgh->cctk_gsh[d] - 1);
+ }
+ }
+ const rvect coord_lower
+ = global_lower + coord_delta * rvect(lo);
+ const rvect coord_upper
+ = global_lower + coord_delta * rvect(hi);
+
+ ivect offset1;
+ for (int d=0; d<dim; ++d) {
+ assert (cgh->cctk_levoffdenom[d]==1);
+ offset1[d] = (cgh->cctk_levoff[d] + offset[d]) * ext.stride()[d];
+ }
+ for (int d=0; d<outdim; ++d) {
+ offset1[dirs[d]] = ext.lower()[dirs[d]];
+ }
+
+ WriteASCII (file, data, ext, n, cgh->cctk_iteration,
+ offset1, dirs,
+ reflevel, mglevel, Carpet::map, component, tl,
+ coord_time, coord_lower, coord_upper);
+
+ // Append EOL after every component
+ if (CCTK_MyProc(cgh)==0) {
+ if (separate_components) {
+ assert (file.good());
+ file << endl;
+ }
}
+ assert (file.good());
+
+ } // for tl
+
+ } END_COMPONENT_LOOP;
+
+ // Append EOL after every complete set of components
+ if (CCTK_MyProc(cgh)==0) {
+ if (separate_grids) {
+ assert (file.good());
+ file << endl;
}
+ file.close();
assert (file.good());
-
- } // for tl
-
- } END_COMPONENT_LOOP;
-
- // Append EOL after every complete set of components
- if (CCTK_MyProc(cgh)==0) {
- if (separate_grids) {
- assert (file.good());
- file << endl;
- }
- file.close();
- assert (file.good());
- }
-
- assert (! file.is_open());
-
+ }
+
+ assert (! file.is_open());
+
+ } END_MAP_LOOP;
+
} // if (desired)
} // if (ascending)
@@ -471,7 +521,7 @@ namespace CarpetIOASCII {
done = true;
for (int d=0; d<outdim; ++d) {
++dirs[d];
- if (dirs[d]<CCTK_GroupDimI(group)) {
+ if (dirs[d]<groupdim) {
done = false;
break;
}
@@ -490,30 +540,86 @@ namespace CarpetIOASCII {
template<int outdim>
int IOASCII<outdim>
- ::TimeToOutput (const cGH* const cgh, const int vindex)
+ ::TimeToOutput (const cGH* const cctkGH, const int vindex)
{
+ DECLARE_CCTK_ARGUMENTS;
DECLARE_CCTK_PARAMETERS;
assert (vindex>=0 && vindex<CCTK_NumVars());
- const int myoutevery = GetIntParameter("out%dD_every", out_every);
+ static int output_iteration = -1;
+ static bool output_this_iteration;
+ static vector<bool> output_variables;
- if (myoutevery <= 0) {
- // Nothing should be output at all
- return 0;
- }
+ assert (cctk_iteration >= output_iteration);
+ if (cctk_iteration > output_iteration) {
+ // A new iteration; check whether output should happen
+
+ output_iteration = cctk_iteration;
+
+ const char * const myoutcriterion
+ = GetStringParameter("out%dD_criterion", out_criterion);
+ if (CCTK_EQUALS (myoutcriterion, "never")) {
+
+ // Never output
+ output_this_iteration = false;
+
+ } else if (CCTK_EQUALS (myoutcriterion, "iteration")) {
+
+ const int myoutevery = GetIntParameter("out%dD_every", out_every);
+ if (myoutevery <= 0) {
+ output_this_iteration = false;
+ } else {
+ output_this_iteration
+ = cctk_iteration >= next_output_iteration[outdim-1];
+ if (output_this_iteration) {
+ next_output_iteration[outdim-1] += myoutevery;
+ }
+ }
+
+ } else if (CCTK_EQUALS (myoutcriterion, "time")) {
+
+ const CCTK_REAL myoutdt = GetRealParameter("out%dD_dt", out_dt);
+ if (myoutdt < 0) {
+ output_this_iteration = false;
+ } else if (myoutdt == 0) {
+ output_this_iteration = true;
+ } else {
+ output_this_iteration = cctk_time >= (next_output_time[outdim-1]
+ - 1.0e-12 * cctk_delta_time);
+ if (output_this_iteration) {
+ next_output_time[outdim-1] += myoutdt;
+ }
+ }
+
+ } else {
+
+ assert (0);
+
+ } // select output criterion
+
+
+
+ // check which variables to output
+ const int numvars = CCTK_NumVars();
+ assert (vindex>=0 && vindex<numvars);
+ output_variables.resize (numvars);
+
+ const char * const varlist = GetStringParameter("out%dD_vars", "");
+ CCTK_TraverseString
+ (varlist, SetFlag, &output_variables, CCTK_GROUP_OR_VAR);
+
+ } // check whether output should happen
+
+ if (! output_this_iteration) return 0;
+ if (! output_variables[vindex]) return 0;
+
+ const int grouptype = CCTK_GroupTypeFromVarI(vindex);
+ if (grouptype != CCTK_GF && reflevel > 0) return 0;
- if (cgh->cctk_iteration % myoutevery != 0) {
- // Nothing should be output during this iteration
- return 0;
- }
- if (! CheckForVariable(cgh, GetStringParameter("out%dD_vars", ""), vindex)) {
- // This variable should not be output
- return 0;
- }
- if (last_output[reflevel][vindex] == cgh->cctk_iteration) {
+ if (last_output[reflevel][vindex] == cctk_iteration) {
// Has already been output during this iteration
char* varname = CCTK_FullName(vindex);
CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,
@@ -525,7 +631,7 @@ namespace CarpetIOASCII {
return 0;
}
- assert (last_output[reflevel][vindex] < cgh->cctk_iteration);
+ assert (last_output[reflevel][vindex] < cctk_iteration);
// Should be output during this iteration
return 1;
@@ -559,7 +665,7 @@ namespace CarpetIOASCII {
{
// First choice: explicit coordinate
char cparam[1000];
- sprintf (cparam, ctempl, outdim);
+ snprintf (cparam, sizeof cparam, ctempl, outdim);
const int ncparam = CCTK_ParameterQueryTimesSet (cparam, CCTK_THORNSTRING);
assert (ncparam >= 0);
if (ncparam > 0) {
@@ -575,7 +681,7 @@ namespace CarpetIOASCII {
// Second choice: explicit index
char iparam[1000];
- sprintf (iparam, itempl, outdim);
+ snprintf (iparam, sizeof iparam, itempl, outdim);
const int niparam = CCTK_ParameterQueryTimesSet (iparam, CCTK_THORNSTRING);
assert (niparam >= 0);
if (niparam > 0) {
@@ -629,7 +735,7 @@ namespace CarpetIOASCII {
{
assert (dir>=1 && dir<=dim);
- assert (reflevel!=-1 && mglevel!=-1);
+ assert (mglevel!=-1 && reflevel!=-1 && Carpet::map!=-1);
const int npoints = cgh->cctk_gsh[dir-1];
const CCTK_REAL delta = cgh->cctk_delta_space[dir-1] / cgh->cctk_levfac[dir-1];
@@ -640,10 +746,13 @@ namespace CarpetIOASCII {
int cindex = (int)floor(rindex + 0.75);
if (cindex<0 || cindex>=npoints) {
- CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "The specified coordinate value %g is not within the grid range [%g,%g]",
- coord, lower, upper);
cindex = ifallback;
+
+ assert (dir>=1 && dir<=3);
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "The specified coordinate value %g for the %c-direction is not within the grid range [%g,%g] on convergence level %d, level %d, map %d; using %g instead",
+ coord, "xyz"[dir-1], lower, upper,
+ mglevel, reflevel, Carpet::map, lower + delta * cindex);
}
assert (cindex>=0 && cindex<npoints);
@@ -659,7 +768,7 @@ namespace CarpetIOASCII {
const char* const fallback)
{
char parametername[1000];
- sprintf (parametername, parametertemplate, outdim);
+ snprintf (parametername, sizeof parametername, parametertemplate, outdim);
const int ntimes =
CCTK_ParameterQueryTimesSet (parametername, CCTK_THORNSTRING);
assert (ntimes >= 0);
@@ -669,7 +778,7 @@ namespace CarpetIOASCII {
(parametername, CCTK_THORNSTRING, &ptype);
assert (ppval);
const char* const pval = *ppval;
- assert (ptype == PARAMETER_STRING);
+ assert (ptype == PARAMETER_STRING || ptype == PARAMETER_KEYWORD);
return pval;
}
@@ -679,22 +788,23 @@ namespace CarpetIOASCII {
template<int outdim>
- int IOASCII<outdim>
- ::GetIntParameter (const char* const parametertemplate, const int fallback)
+ CCTK_INT IOASCII<outdim>
+ ::GetIntParameter (const char* const parametertemplate,
+ const CCTK_INT fallback)
{
char parametername[1000];
- sprintf (parametername, parametertemplate, outdim);
+ snprintf (parametername, sizeof parametername, parametertemplate, outdim);
const int ntimes =
CCTK_ParameterQueryTimesSet (parametername, CCTK_THORNSTRING);
assert (ntimes >= 0);
if (ntimes > 0) {
int ptype;
- const int* const ppval
- = (const int*)CCTK_ParameterGet
+ const CCTK_INT* const ppval
+ = (const CCTK_INT*)CCTK_ParameterGet
(parametername, CCTK_THORNSTRING, &ptype);
assert (ppval);
- const int pval = *ppval;
- assert (ptype == PARAMETER_INT);
+ const CCTK_INT pval = *ppval;
+ assert (ptype == PARAMETER_INT || ptype == PARAMETER_BOOLEAN);
return pval;
}
@@ -703,19 +813,32 @@ namespace CarpetIOASCII {
- bool CheckForVariable (const cGH* const cgh,
- const char* const varlist, const int vindex)
+ template<int outdim>
+ CCTK_REAL IOASCII<outdim>
+ ::GetRealParameter (const char* const parametertemplate,
+ const CCTK_REAL fallback)
{
- const int numvars = CCTK_NumVars();
- assert (vindex>=0 && vindex<numvars);
-
- vector<bool> flags(numvars);
-
- CCTK_TraverseString (varlist, SetFlag, &flags, CCTK_GROUP_OR_VAR);
+ char parametername[1000];
+ snprintf (parametername, sizeof parametername, parametertemplate, outdim);
+ const int ntimes =
+ CCTK_ParameterQueryTimesSet (parametername, CCTK_THORNSTRING);
+ assert (ntimes >= 0);
+ if (ntimes > 0) {
+ int ptype;
+ const CCTK_REAL* const ppval
+ = (const CCTK_REAL*)CCTK_ParameterGet
+ (parametername, CCTK_THORNSTRING, &ptype);
+ assert (ppval);
+ const CCTK_REAL pval = *ppval;
+ assert (ptype == PARAMETER_REAL);
+ return pval;
+ }
- return flags[vindex];
+ return fallback;
}
+
+
void SetFlag (int index, const char* optstring, void* arg)
{
vector<bool>& flags = *(vector<bool>*)arg;
@@ -733,10 +856,11 @@ namespace CarpetIOASCII {
const int time,
const vect<int,D>& org,
const vect<int,DD>& dirs,
- const int tl,
const int rl,
- const int c,
const int ml,
+ const int m,
+ const int c,
+ const int tl,
const CCTK_REAL coord_time,
const vect<CCTK_REAL,D>& coord_lower,
const vect<CCTK_REAL,D>& coord_upper)
@@ -753,8 +877,12 @@ namespace CarpetIOASCII {
assert (os.good());
os << "# iteration " << time << endl
- << "# time level " << tl << " refinement level " << rl
- << " component " << c << " multigrid level " << ml << endl
+ << "# refinement level " << rl
+ << " multigrid level " << ml
+ << " map " << m
+ << " component " << c
+ << " time level " << tl
+ << endl
<< "# column format: it tl rl c ml ";
assert (D>=1 && D<=3);
const char* const coords = "xyz";
@@ -770,25 +898,25 @@ namespace CarpetIOASCII {
// Check whether the output origin is contained in the extent
// of the data that should be output
- vect<int,dim> org1(org);
+ ivect org1(org);
for (int d=0; d<DD; ++d) org1[dirs[d]] = ext.lower()[d];
if (gfext.contains(org1)) {
for (typename bbox<int,DD>::iteratorT it=ext.beginT();
it!=ext.endT(); ++it) {
- vect<int,dim> index(org);
+ ivect index(org);
for (int d=0; d<DD; ++d) index[dirs[d]] = (*it)[d];
os << time << " " << tl << " " << rl << " " << c << " " << ml
- << " ";
- for (int d=0; d<D; ++d) os << index[d] << " ";
- os << " " << coord_time << " ";
+ << " ";
+ for (int d=0; d<D; ++d) os << " " << index[d];
+ os << " " << coord_time << " ";
for (int d=0; d<D; ++d) {
assert (gfext.upper()[d] - gfext.lower()[d] != 0);
- os << (coord_lower[d] + (index[d] - gfext.lower()[d])
- * (coord_upper[d] - coord_lower[d])
- / (gfext.upper()[d] - gfext.lower()[d])) << " ";
+ os << " " << (coord_lower[d] + (index[d] - gfext.lower()[d])
+ * (coord_upper[d] - coord_lower[d])
+ / (gfext.upper()[d] - gfext.lower()[d]));
}
- os << " ";
+ os << " ";
switch (CCTK_VarTypeI(vi)) {
#define WANT_NO_COMPLEX
#define TYPECASE(N,T) \
@@ -837,7 +965,7 @@ namespace CarpetIOASCII {
for (comm_state<dim> state; !state.done(); state.step()) {
tmp->copy_from (state, gfdata, gfdata->extent());
}
- WriteASCII (os, tmp, gfext, vi, time, org, dirs, tl, rl, c, ml,
+ WriteASCII (os, tmp, gfext, vi, time, org, dirs, rl, ml, m, c, tl,
coord_time, coord_lower, coord_upper);
delete tmp;
@@ -861,10 +989,11 @@ namespace CarpetIOASCII {
const int time,
const vect<int,3>& org,
const vect<int,1>& dirs,
- const int tl,
const int rl,
- const int c,
const int ml,
+ const int m,
+ const int c,
+ const int tl,
const CCTK_REAL coord_time,
const vect<CCTK_REAL,3>& coord_lower,
const vect<CCTK_REAL,3>& coord_upper);
@@ -877,10 +1006,11 @@ namespace CarpetIOASCII {
const int time,
const vect<int,3>& org,
const vect<int,2>& dirs,
- const int tl,
const int rl,
- const int c,
const int ml,
+ const int m,
+ const int c,
+ const int tl,
const CCTK_REAL coord_time,
const vect<CCTK_REAL,3>& coord_lower,
const vect<CCTK_REAL,3>& coord_upper);
@@ -893,10 +1023,11 @@ namespace CarpetIOASCII {
const int time,
const vect<int,3>& org,
const vect<int,3>& dirs,
- const int tl,
const int rl,
- const int c,
const int ml,
+ const int m,
+ const int c,
+ const int tl,
const CCTK_REAL coord_time,
const vect<CCTK_REAL,3>& coord_lower,
const vect<CCTK_REAL,3>& coord_upper);