Commit d14c47bb authored by Uwe Schulzweida's avatar Uwe Schulzweida

get_no_unique_center_points(): simplify if statement.

parent 28d6cf00
...@@ -339,31 +339,25 @@ print_header(int gridtype, size_t gridsize, size_t nx, int gridno, int ngrids) ...@@ -339,31 +339,25 @@ print_header(int gridtype, size_t gridsize, size_t nx, int gridno, int ngrids)
} }
static size_t static size_t
get_no_unique_center_points(size_t gridsize, size_t nx, const Varray<double> &center_point_array) get_no_unique_center_points(size_t gridsize, size_t nx, const Varray<double> &center_point)
{ {
size_t no_unique_center_points = 1; size_t no_unique_center_points = 1;
for (size_t cell_no = 0; cell_no < gridsize - 1; cell_no++) for (size_t cell_no = 0; cell_no < gridsize - 1; cell_no++)
{ {
if (std::fabs(center_point_array[cell_no * 2 + 0] - center_point_array[(cell_no + 1) * 2 + 0]) < eps) 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_point_array[cell_no * 2 + 1] - center_point_array[(cell_no + 1) * 2 + 1]) < eps) if (Options::cdoVerbose)
{ {
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);
fprintf(stdout, "Duplicate point [lon=%.5g lat=%.5g] was found in cell no %zu", if (nx) printIndex2D(cell_no, nx);
center_point_array[cell_no * 2 + 0], center_point_array[cell_no * 2 + 1], cell_no + 1); fprintf(stdout, "\n");
if (nx) printIndex2D(cell_no, nx);
fprintf(stdout, "\n");
}
continue;
} }
else
no_unique_center_points += 1;
} }
else else
{ {
no_unique_center_points += 1; no_unique_center_points++;
} }
} }
...@@ -373,15 +367,15 @@ get_no_unique_center_points(size_t gridsize, size_t nx, const Varray<double> &ce ...@@ -373,15 +367,15 @@ get_no_unique_center_points(size_t gridsize, size_t nx, const Varray<double> &ce
void set_cell_corners_xyz(int ncorner, const double *cell_corners_lon, const double *cell_corners_lat, Varray<Point3D> &cell_corners_xyz) void set_cell_corners_xyz(int ncorner, const double *cell_corners_lon, const double *cell_corners_lat, Varray<Point3D> &cell_corners_xyz)
{ {
double corner_coordinates[3]; double corner_coordinates[3];
for (int corner_no = 0; corner_no < ncorner; corner_no++) for (int k = 0; k < ncorner; k++)
{ {
// Conversion of corner spherical coordinates to Cartesian coordinates. // Conversion of corner spherical coordinates to Cartesian coordinates.
gcLLtoXYZ(cell_corners_lon[corner_no], cell_corners_lat[corner_no], corner_coordinates); gcLLtoXYZ(cell_corners_lon[k], cell_corners_lat[k], corner_coordinates);
// The components of the result vector are appended to the list of cell corner coordinates. // The components of the result vector are appended to the list of cell corner coordinates.
cell_corners_xyz[corner_no].X = corner_coordinates[0]; cell_corners_xyz[k].X = corner_coordinates[0];
cell_corners_xyz[corner_no].Y = corner_coordinates[1]; cell_corners_xyz[k].Y = corner_coordinates[1];
cell_corners_xyz[corner_no].Z = corner_coordinates[2]; cell_corners_xyz[k].Z = corner_coordinates[2];
} }
} }
...@@ -398,27 +392,18 @@ void set_center_point_plane_projection(int coordinate_to_ignore, const Point3D & ...@@ -398,27 +392,18 @@ void set_center_point_plane_projection(int coordinate_to_ignore, const Point3D &
} }
void set_cell_corners_plane_projection(int coordinate_to_ignore, int ncorner, const Varray<Point3D> &cell_corners_xyz, void set_cell_corners_plane_projection(int coordinate_to_ignore, int ncorner, const Varray<Point3D> &cell_corners_xyz,
Varray<Point> &cell_corners_plane_projection) Varray<Point> &cell_corners_plane)
{ {
switch (coordinate_to_ignore) switch (coordinate_to_ignore)
{ {
case 1: case 1:
for (int corner_no = 0; corner_no <= ncorner; corner_no++) for (int k = 0; k <= ncorner; k++) cell_corners_plane[k] = Point {cell_corners_xyz[k].Y, cell_corners_xyz[k].Z};
{
cell_corners_plane_projection[corner_no] = Point {cell_corners_xyz[corner_no].Y, cell_corners_xyz[corner_no].Z};
}
break; break;
case 2: case 2:
for (int corner_no = 0; corner_no <= ncorner; corner_no++) for (int k = 0; k <= ncorner; k++) cell_corners_plane[k] = Point {cell_corners_xyz[k].Z, cell_corners_xyz[k].X};
{
cell_corners_plane_projection[corner_no] = Point {cell_corners_xyz[corner_no].Z, cell_corners_xyz[corner_no].X};
}
break; break;
case 3: case 3:
for (int corner_no = 0; corner_no <= ncorner; corner_no++) for (int k = 0; k <= ncorner; k++) cell_corners_plane[k] = Point {cell_corners_xyz[k].X, cell_corners_xyz[k].Y};
{
cell_corners_plane_projection[corner_no] = Point {cell_corners_xyz[corner_no].X, cell_corners_xyz[corner_no].Y};
}
break; break;
} }
} }
...@@ -427,11 +412,11 @@ int get_actual_number_of_corners(int ncorner, const Varray<Point3D> &cell_corner ...@@ -427,11 +412,11 @@ int get_actual_number_of_corners(int ncorner, const Varray<Point3D> &cell_corner
{ {
auto actual_number_of_corners = ncorner; auto actual_number_of_corners = ncorner;
for (int corner_no = ncorner - 1; corner_no > 0; corner_no--) for (int k = ncorner - 1; k > 0; k--)
{ {
if (IS_EQUAL(cell_corners_xyz_open_cell[corner_no].X, cell_corners_xyz_open_cell[corner_no - 1].X) if (IS_EQUAL(cell_corners_xyz_open_cell[k].X, cell_corners_xyz_open_cell[k - 1].X)
&& IS_EQUAL(cell_corners_xyz_open_cell[corner_no].Y, cell_corners_xyz_open_cell[corner_no - 1].Y) && IS_EQUAL(cell_corners_xyz_open_cell[k].Y, cell_corners_xyz_open_cell[k - 1].Y)
&& IS_EQUAL(cell_corners_xyz_open_cell[corner_no].Z, cell_corners_xyz_open_cell[corner_no - 1].Z)) && IS_EQUAL(cell_corners_xyz_open_cell[k].Z, cell_corners_xyz_open_cell[k - 1].Z))
actual_number_of_corners--; actual_number_of_corners--;
else else
break; break;
...@@ -452,7 +437,7 @@ int get_no_duplicates(int actual_number_of_corners, const Varray<Point3D> &cell_ ...@@ -452,7 +437,7 @@ int get_no_duplicates(int actual_number_of_corners, const Varray<Point3D> &cell_
&& std::fabs(cell_corners_xyz_open_cell[i].Y - cell_corners_xyz_open_cell[j].Y) < eps && std::fabs(cell_corners_xyz_open_cell[i].Y - cell_corners_xyz_open_cell[j].Y) < eps
&& std::fabs(cell_corners_xyz_open_cell[i].Z - cell_corners_xyz_open_cell[j].Z) < eps) && std::fabs(cell_corners_xyz_open_cell[i].Z - cell_corners_xyz_open_cell[j].Z) < eps)
{ {
no_duplicates += 1; no_duplicates++;
marked_duplicate_indices[j] = true; marked_duplicate_indices[j] = true;
} }
...@@ -464,11 +449,11 @@ void copy_unique_corners(int actual_number_of_corners, const Varray<Point3D> &ce ...@@ -464,11 +449,11 @@ void copy_unique_corners(int actual_number_of_corners, const Varray<Point3D> &ce
{ {
int unique_corner_number = 0; int unique_corner_number = 0;
for (int corner_no = 0; corner_no < actual_number_of_corners; corner_no++) for (int k = 0; k < actual_number_of_corners; k++)
{ {
if (marked_duplicate_indices[corner_no] == false) if (marked_duplicate_indices[k] == false)
{ {
cell_corners_xyz_without_duplicates[unique_corner_number] = cell_corners_xyz_open_cell[corner_no]; cell_corners_xyz_without_duplicates[unique_corner_number] = cell_corners_xyz_open_cell[k];
unique_corner_number++; unique_corner_number++;
} }
} }
...@@ -541,16 +526,16 @@ verify_grid(size_t gridsize, size_t nx, int ncorner, ...@@ -541,16 +526,16 @@ verify_grid(size_t gridsize, size_t nx, int ncorner,
center_point_xyz.Z = center_coordinates[2]; center_point_xyz.Z = center_coordinates[2];
double corner_coordinates[3]; double corner_coordinates[3];
for (int corner_no = 0; corner_no < ncorner; corner_no++) for (int k = 0; k < ncorner; k++)
{ {
// Conversion of corner spherical coordinates to Cartesian coordinates. // Conversion of corner spherical coordinates to Cartesian coordinates.
gcLLtoXYZdeg(grid_corner_lon[cell_no * ncorner + corner_no], grid_corner_lat[cell_no * ncorner + corner_no], gcLLtoXYZdeg(grid_corner_lon[cell_no * ncorner + k], grid_corner_lat[cell_no * ncorner + k],
corner_coordinates); corner_coordinates);
// The components of the result vector are appended to the list of cell corner coordinates. // The components of the result vector are appended to the list of cell corner coordinates.
cell_corners_xyz_open_cell[corner_no].X = corner_coordinates[0]; cell_corners_xyz_open_cell[k].X = corner_coordinates[0];
cell_corners_xyz_open_cell[corner_no].Y = corner_coordinates[1]; cell_corners_xyz_open_cell[k].Y = corner_coordinates[1];
cell_corners_xyz_open_cell[corner_no].Z = corner_coordinates[2]; cell_corners_xyz_open_cell[k].Z = corner_coordinates[2];
} }
/* /*
...@@ -692,8 +677,8 @@ verify_grid(size_t gridsize, size_t nx, int ncorner, ...@@ -692,8 +677,8 @@ verify_grid(size_t gridsize, size_t nx, int ncorner,
if (Options::cdoVerbose && winding_number == 0) if (Options::cdoVerbose && winding_number == 0)
{ {
fprintf(stdout, "Center point [lon=%.5g lat=%.5g] outside bounds [", grid_center_lon[cell_no], grid_center_lat[cell_no]); fprintf(stdout, "Center point [lon=%.5g lat=%.5g] outside bounds [", grid_center_lon[cell_no], grid_center_lat[cell_no]);
for (int corner_no = 0; corner_no < ncorner; corner_no++) for (int k = 0; k < ncorner; k++)
fprintf(stdout, " %.5g/%.5g", grid_corner_lon[cell_no * ncorner + corner_no], grid_corner_lat[cell_no * ncorner + corner_no]); fprintf(stdout, " %.5g/%.5g", grid_corner_lon[cell_no * ncorner + k], grid_corner_lat[cell_no * ncorner + k]);
fprintf(stdout, "] in cell no %zu", cell_no + 1); fprintf(stdout, "] in cell no %zu", cell_no + 1);
if (nx) printIndex2D(cell_no, nx); if (nx) printIndex2D(cell_no, nx);
fprintf(stdout, "\n"); fprintf(stdout, "\n");
......
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