aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetIOASCII/src
diff options
context:
space:
mode:
authorschnetter <>2001-12-05 15:27:00 +0000
committerschnetter <>2001-12-05 15:27:00 +0000
commit9c13ee1c65f12896dbe5c0138ef78bc4b00e6b8b (patch)
treeed990a94c9f52a1c508cc354e0ab69d9a27671a4 /Carpet/CarpetIOASCII/src
parent32782efd12464461ae20217a20870bffdda09d48 (diff)
Prevent core dump when the specified output coordinate is not on the grid.
darcs-hash:20011205152726-07bb3-5c72caf0c73a825d3aacf4249277ecfa06a56ee0.gz
Diffstat (limited to 'Carpet/CarpetIOASCII/src')
-rw-r--r--Carpet/CarpetIOASCII/src/ioascii.cc22
-rw-r--r--Carpet/CarpetIOASCII/src/ioascii.hh5
2 files changed, 18 insertions, 9 deletions
diff --git a/Carpet/CarpetIOASCII/src/ioascii.cc b/Carpet/CarpetIOASCII/src/ioascii.cc
index d55852b40..b3749a61a 100644
--- a/Carpet/CarpetIOASCII/src/ioascii.cc
+++ b/Carpet/CarpetIOASCII/src/ioascii.cc
@@ -24,7 +24,7 @@
#include "ioascii.hh"
-static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetIOASCII/src/ioascii.cc,v 1.20 2001/11/05 17:53:02 schnetter Exp $";
+static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetIOASCII/src/ioascii.cc,v 1.21 2001/12/05 16:27:26 schnetter Exp $";
@@ -444,7 +444,7 @@ int CarpetIOASCII<outdim>
assert (pcoord);
const CCTK_REAL coord = *pcoord;
assert (ptype == PARAMETER_REAL);
- return CoordToOffset (cgh, dir, coord);
+ return CoordToOffset (cgh, dir, coord, 0);
}
// Second choice: explicit index
@@ -468,7 +468,7 @@ int CarpetIOASCII<outdim>
assert (pcoord);
const CCTK_REAL coord = *pcoord;
assert (ptype == PARAMETER_REAL);
- return CoordToOffset (cgh, dir, coord);
+ return CoordToOffset (cgh, dir, coord, 0);
}
// Fourth choice: explicit global index
@@ -483,22 +483,30 @@ int CarpetIOASCII<outdim>
}
// Fifth choice: default coordinate
- return CoordToOffset (cgh, dir, cfallback);
+ return CoordToOffset (cgh, dir, cfallback, 0);
}
template<int outdim>
int CarpetIOASCII<outdim>
-::CoordToOffset (const cGH* cgh, int dir, CCTK_REAL coord)
+::CoordToOffset (const cGH* cgh, const int dir, const CCTK_REAL coord,
+ const int ifallback)
{
+ assert (dir>=1 && dir<=dim);
+
CCTK_REAL lower, upper;
CCTK_CoordRange (cgh, &lower, &upper, dir, 0, "cart3d");
const int npoints = cgh->cctk_gsh[dir-1];
const CCTK_REAL rindex = (coord - lower) / (upper - lower) * (npoints-1);
- const int cindex = (int)floor(rindex + 0.5 + 1e-6);
+ int cindex = (int)floor(rindex + 0.5 + 1e-6);
+
+ if (cindex<0 || cindex>=npoints) {
+ cindex = ifallback;
+ }
+
assert (cindex>=0 && cindex<npoints);
return cindex;
@@ -517,7 +525,7 @@ const char* CarpetIOASCII<outdim>
int ptype;
const char* const* const ppval
= (const char* const*)CCTK_ParameterGet (parametername, CCTK_THORNSTRING,
- &ptype);
+ &ptype);
assert (ppval);
const char* const pval = *ppval;
assert (ptype == PARAMETER_STRING);
diff --git a/Carpet/CarpetIOASCII/src/ioascii.hh b/Carpet/CarpetIOASCII/src/ioascii.hh
index 7bb8f3bb5..d46445fdd 100644
--- a/Carpet/CarpetIOASCII/src/ioascii.hh
+++ b/Carpet/CarpetIOASCII/src/ioascii.hh
@@ -1,4 +1,4 @@
-// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetIOASCII/src/ioascii.hh,v 1.9 2001/11/05 17:53:03 schnetter Exp $
+// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetIOASCII/src/ioascii.hh,v 1.10 2001/12/05 16:27:27 schnetter Exp $
#include <vector>
@@ -57,7 +57,8 @@ struct CarpetIOASCII {
const char* itempl, const char* iglobal,
const char* ctempl, const char* cglobal,
CCTK_REAL cfallback);
- static int CoordToOffset (const cGH* cgh, int dir, CCTK_REAL coord);
+ static int CoordToOffset (const cGH* cgh, int dir, CCTK_REAL coord,
+ int ifallback);
static const char* GetStringParameter
(const char* parametertemplate, const char* fallback);