Commit b9fbc76f authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

get_no_unique_center_points(): refactored.

parent d14c47bb
......@@ -339,18 +339,22 @@ print_header(int gridtype, size_t gridsize, size_t nx, int gridno, int ngrids)
}
static size_t
get_no_unique_center_points(size_t gridsize, size_t nx, const Varray<double> &center_point)
get_no_unique_center_points(size_t gridsize, size_t nx, const Varray<double> &grid_center_lon, const Varray<double> &grid_center_lat)
{
// For performing the first test, an array of all center point coordinates is built.
Varray<double> center_points(gridsize * 2);
create_sorted_point_array(gridsize, grid_center_lon, grid_center_lat, center_points);
size_t no_unique_center_points = 1;
for (size_t cell_no = 0; cell_no < gridsize - 1; cell_no++)
{
if (std::fabs(center_point[cell_no * 2 + 0] - center_point[(cell_no + 1) * 2 + 0]) < eps &&
std::fabs(center_point[cell_no * 2 + 1] - center_point[(cell_no + 1) * 2 + 1]) < eps)
if (std::fabs(center_points[cell_no * 2 + 0] - center_points[(cell_no + 1) * 2 + 0]) < eps &&
std::fabs(center_points[cell_no * 2 + 1] - center_points[(cell_no + 1) * 2 + 1]) < eps)
{
if (Options::cdoVerbose)
{
fprintf(stdout, "Duplicate point [lon=%.5g lat=%.5g] was found in cell no %zu",
center_point[cell_no * 2 + 0], center_point[cell_no * 2 + 1], cell_no + 1);
center_points[cell_no * 2 + 0], center_points[cell_no * 2 + 1], cell_no + 1);
if (nx) printIndex2D(cell_no, nx);
fprintf(stdout, "\n");
}
......@@ -467,14 +471,12 @@ verify_grid(size_t gridsize, size_t nx, int ncorner,
/*
First, this function performs the following test:
1) it tests whether there are duplicate cells in the given grid by
comparing their center point
1) it tests whether there are duplicate cells in the given grid by comparing their center point
Additionally, on each cell of a given grid:
2) it tests whether all cells are convex and all cell bounds have the same
orientation, i.e. the corners of the cell are in clockwise or
counterclockwise order
2) it tests whether all cells are convex and all cell bounds have the same orientation,
i.e. the corners of the cell are in clockwise or counterclockwise order
3) it tests whether the center point is within the bounds of the cell
......@@ -494,14 +496,8 @@ verify_grid(size_t gridsize, size_t nx, int ncorner,
std::vector<int> no_cells_with_a_specific_no_of_corners(ncorner, 0);
// For performing the first test, an array of all center point coordinates is built.
Varray<double> center_point_array(gridsize * 2);
create_sorted_point_array(gridsize, grid_center_lon, grid_center_lat, center_point_array);
// Now checking for the number of unique center point coordinates.
const auto no_unique_center_points = get_no_unique_center_points(gridsize, nx, center_point_array);
// Checking for the number of unique center point coordinates.
const auto no_unique_center_points = get_no_unique_center_points(gridsize, nx, grid_center_lon, grid_center_lat);
// used only actual_number_of_corners
std::vector<bool> marked_duplicate_indices(ncorner);
......
Markdown is supported
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