WSL/SLF GitLab Repository

Commit 5a196216 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Improved error message when reaching outside of an array in debug mode and...

Improved error message when reaching outside of an array in debug mode and fixed a stupid allocation bug (swapping two lines in the last commit triggered this bug)
parent e4c44300
......@@ -183,6 +183,7 @@ template<class T> inline T& Array1D<T>::operator()(const unsigned int& index) {
if (index >= nx) {
std::stringstream ss;
ss << "Trying to access array(" << index << ")";
ss << " while array is [" << nx << "]";
throw IndexOutOfBoundsException(ss.str(), AT);
}
#endif
......@@ -194,6 +195,7 @@ template<class T> inline const T Array1D<T>::operator()(const unsigned int& inde
if (index >= nx) {
std::stringstream ss;
ss << "Trying to access array(" << index << ")";
ss << " while array is [" << nx << "]";
throw IndexOutOfBoundsException(ss.str(), AT);
}
#endif
......@@ -243,7 +245,7 @@ template<class T> void Array1D<T>::insertAt(const int& index, T e) {
nx++;
} else {
std::stringstream ss;
ss << "Inserting an element at (" << index << ") in an array of size (" << nx << ")";
ss << "Inserting an element at (" << index << ") in an array of size [" << nx << "]";
throw IndexOutOfBoundsException(ss.str(), AT);
}
}
......
......@@ -232,6 +232,7 @@ template<class T> inline T& Array2D<T>::operator()(const unsigned int& x, const
if ((x >= nx) || (y >= ny)) {
std::stringstream ss;
ss << "Trying to access array(" << x << "," << y << ")";
ss << " while array is [" << nx << "," << ny << "]";
throw IndexOutOfBoundsException(ss.str(), AT);
}
#endif
......@@ -244,6 +245,7 @@ template<class T> inline const T Array2D<T>::operator()(const unsigned int& x, c
if ((x >= nx) || (y >= ny)) {
std::stringstream ss;
ss << "Trying to access array(" << x << "," << y << ")";
ss << " while array is [" << nx << "," << ny << "]";
throw IndexOutOfBoundsException(ss.str(), AT);
}
#endif
......
......@@ -268,6 +268,7 @@ template<class T> inline T& Array3D<T>::operator()(const unsigned int& x, const
if ((x >= nx) || (y >= ny) || (z >= nz)) {
std::stringstream ss;
ss << "Trying to access array(" << x << "," << y << "," << z << ")";
ss << " while array is [" << nx << "," << ny << "," << nz << "]";
throw IndexOutOfBoundsException(ss.str(), AT);
}
#endif
......@@ -281,6 +282,7 @@ template<class T> inline const T Array3D<T>::operator()(const unsigned int& x, c
if ((x >= nx) || (y >= ny) || (z >= nz)) {
std::stringstream ss;
ss << "Trying to access array(" << x << "," << y << "," << z << ")";
ss << " while array is [" << nx << "," << ny << "," << nz << "]";
throw IndexOutOfBoundsException(ss.str(), AT);
}
#endif
......
......@@ -198,14 +198,14 @@ bool Grid2DObject::WGS84_to_grid(Coords& point) const {
void Grid2DObject::set(const unsigned int& i_ncols, const unsigned int& i_nrows,
const double& i_cellsize, const Coords& i_llcorner)
{
grid2D.resize(ncols, nrows, IOUtils::nodata);
grid2D.resize(i_ncols, i_nrows, IOUtils::nodata);
setValues(i_ncols, i_nrows, i_cellsize, i_llcorner);
}
void Grid2DObject::set(const unsigned int& i_ncols, const unsigned int& i_nrows,
const double& i_cellsize, const Coords& i_llcorner, const double& init)
{
grid2D.resize(ncols, nrows, init);
grid2D.resize(i_ncols, i_nrows, init);
setValues(i_ncols, i_nrows, i_cellsize, i_llcorner);
}
......@@ -213,9 +213,7 @@ void Grid2DObject::set(const unsigned int& i_ncols, const unsigned int& i_nrows,
const double& i_cellsize, const Coords& i_llcorner, const Array2D<double>& i_grid2D)
{
//Test for equality in size: Only compatible Array2D<double> grids are permitted
unsigned int nx,ny;
i_grid2D.size(nx,ny);
if ((i_ncols != nx) || (i_nrows != ny)) {
if ((i_ncols != i_grid2D.getNx()) || (i_nrows != i_grid2D.getNy())) {
throw IOException("Mismatch in size of Array2D<double> parameter _grid2D and size of Grid2DObject", AT);
}
......
......@@ -216,14 +216,14 @@ bool Grid3DObject::WGS84_to_grid(Coords point) const
void Grid3DObject::set(const unsigned int& i_ncols, const unsigned int& i_nrows, const unsigned int& i_ndepths,
const double& i_cellsize, const Coords& i_llcorner)
{
grid3D.resize(ncols, nrows, ndepths, IOUtils::nodata);
grid3D.resize(i_ncols, i_nrows, i_ndepths, IOUtils::nodata);
setValues(i_ncols, i_nrows, i_ndepths, i_cellsize, i_llcorner);
}
void Grid3DObject::set(const unsigned int& i_ncols, const unsigned int& i_nrows, const unsigned int& i_ndepths,
const double& i_cellsize, const Coords& i_llcorner, const double& init)
{
grid3D.resize(ncols, nrows, ndepths, init);
grid3D.resize(i_ncols, i_nrows, i_ndepths, init);
setValues(i_ncols, i_nrows, i_ndepths, i_cellsize, i_llcorner);
}
......@@ -231,9 +231,7 @@ void Grid3DObject::set(const unsigned int& i_ncols, const unsigned int& i_nrows,
const double& i_cellsize, const Coords& i_llcorner, const Array3D<double>& i_grid3D)
{
//Test for equality in size: Only compatible Array3D<double> grids are permitted
unsigned int nx, ny, nz;
i_grid3D.size(nx, ny, nz);
if ((i_ncols != nx) || (i_nrows != ny) || (i_ndepths != nz)) {
if ((i_ncols != i_grid3D.getNx()) || (i_nrows != i_grid3D.getNy()) || (i_ndepths != i_grid3D.getNz())) {
throw IOException("Mismatch in size of Array3D<double> parameter grid3D and size of Grid3DObject", AT);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment