Skip to content

Commit

Permalink
coordinat_util validate bounds_to_extent calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
burlen committed May 6, 2021
1 parent 56c4132 commit 088c08c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
4 changes: 3 additions & 1 deletion alg/teca_cartesian_mesh_regrid.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ std::vector<teca_metadata> teca_cartesian_mesh_regrid::get_upstream_request(
else
{
if (teca_coordinate_util::bounds_to_extent(request_bounds,
target_x, target_y, target_z, target_extent))
target_x, target_y, target_z, target_extent) ||
teca_coordinate_util::validate_extent(target_x->size(),
target_y->size(), target_z->size(), target_extent, true))
{
TECA_ERROR("invalid bounds requested [" << request_bounds[0] << ", "
<< request_bounds[1] << ", " << request_bounds[2] << ", "
Expand Down
6 changes: 4 additions & 2 deletions alg/teca_cartesian_mesh_source.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,10 @@ const_p_teca_dataset teca_cartesian_mesh_source::execute(unsigned int port,
{
// bounds key was present, convert the bounds to an
// an extent that covers them.
if (teca_coordinate_util::bounds_to_extent(
req_bounds, in_x, in_y, in_z, req_extent))
if (teca_coordinate_util::bounds_to_extent(req_bounds,
in_x, in_y, in_z, req_extent) ||
teca_coordinate_util::validate_extent(in_x->size(),
in_y->size(), in_z->size(), req_extent, true))
{
TECA_ERROR("invalid bounds requested.")
return nullptr;
Expand Down
6 changes: 4 additions & 2 deletions alg/teca_cartesian_mesh_subset.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ teca_metadata teca_cartesian_mesh_subset::get_output_metadata(
}

this->extent.resize(6, 0UL);
if (teca_coordinate_util::bounds_to_extent(
this->bounds.data(), x, y, z, this->extent.data()))
if (teca_coordinate_util::bounds_to_extent(this->bounds.data(),
x, y, z, this->extent.data()) ||
teca_coordinate_util::validate_extent(x->size(),
y->size(), z->size(), this->extent.data(), true))
{
TECA_ERROR("Failed to convert bounds to extent")
return teca_metadata();
Expand Down
6 changes: 4 additions & 2 deletions alg/teca_normalize_coordinates.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,10 @@ std::vector<teca_metadata> teca_normalize_coordinates::get_upstream_request(
unsigned long extent_out[6];
memcpy(extent_out, extent_in, 6*sizeof(unsigned long));

if (teca_coordinate_util::bounds_to_extent(tfm_bounds, in_x,
in_y, z, extent_out))
if (teca_coordinate_util::bounds_to_extent(tfm_bounds,
in_x, in_y, z, extent_out) ||
teca_coordinate_util::validate_extent(in_x->size(),
in_y->size(), z->size(), extent_out, true))
{
TECA_ERROR("invalid bounds requested.")
return up_reqs;
Expand Down
21 changes: 15 additions & 6 deletions data/teca_coordinate_util.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ int bounds_to_extent(const double *bounds, const teca_metadata &md,
teca_metadata coords;
if (md.get("coordinates", coords))
{
TECA_ERROR("missing cooridnates")
TECA_ERROR("Metadata issue, missing cooridnates")
return -1;
}

Expand All @@ -150,11 +150,20 @@ int bounds_to_extent(const double *bounds, const teca_metadata &md,

if (!x || !y || !z)
{
TECA_ERROR("empty coordinate axes")
TECA_ERROR("Metadata issue, empty coordinate axes")
return -1;
}

return bounds_to_extent(bounds, x, y, z, extent);
if (bounds_to_extent(bounds, x, y, z, extent) ||
validate_extent(x->size(), y->size(), z->size(), extent, true))
{
TECA_ERROR("Invalid bounds raequested [" << bounds[0] << ", "
<< bounds[1] << ", " << bounds[2] << ", " << bounds[3] << ", "
<< bounds[4] << ", " << bounds[5] << "]")
return -1;
}

return 0;
}

// **************************************************************************
Expand Down Expand Up @@ -400,7 +409,7 @@ int validate_extent(unsigned long nx_max, unsigned long ny_max,
unsigned long nz_max, unsigned long *extent, bool verbose)
{
// validate x
if (extent[1] >= nx_max)
if ((extent[1] >= nx_max) || (extent[1] < extent[0]))
{
if (verbose)
{
Expand All @@ -412,7 +421,7 @@ int validate_extent(unsigned long nx_max, unsigned long ny_max,
}

// validate y
if (extent[3] >= ny_max)
if ((extent[3] >= ny_max) || (extent[3] < extent[2]))
{
if (verbose)
{
Expand All @@ -424,7 +433,7 @@ int validate_extent(unsigned long nx_max, unsigned long ny_max,
}

// validate z
if (extent[5] >= nz_max)
if ((extent[5] >= nz_max) || (extent[5] < extent[4]))
{
if (verbose)
{
Expand Down

0 comments on commit 088c08c

Please sign in to comment.