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

Verifygrid: optimized memory allocation.

parent 6dd17b92
......@@ -421,6 +421,12 @@ void verify_grid(int gridtype, int gridsize, int gridno, int ngrids, int ncorner
Free(center_point_array);
// used only actual_number_of_corners
int *marked_duplicate_indices = (int*) Malloc(ncorner*sizeof(int));
double *cell_corners_xyz_without_duplicates = (double*) Malloc(3*ncorner*sizeof(double));
double *cell_corners_xyz = (double*) Malloc(3*(ncorner+1)*sizeof(double));
double *cell_corners_plane_projection = (double*) Malloc(2*(ncorner+1)*sizeof(double));
/*
Latitude and longitude are spherical coordinates on a unit circle. Each such coordinate tuple is transformed into a triple of Cartesian coordinates in Euclidean space.
This is first done for the presumed center point of the cell and then for all the corners of the cell. LLtoXYZ is defined in clipping/geometry.h
......@@ -482,7 +488,6 @@ void verify_grid(int gridtype, int gridsize, int gridno, int ngrids, int ncorner
/* Checks if there are any duplicate vertices in the list of corners. Note that the last (additional) corner has not been set yet. */
int *marked_duplicate_indices = (int*) Malloc(actual_number_of_corners*sizeof(int));
for ( int i = 0; i < actual_number_of_corners; i++ ) marked_duplicate_indices[i] = 0;
int no_duplicates = 0;
......@@ -503,8 +508,6 @@ void verify_grid(int gridtype, int gridsize, int gridno, int ngrids, int ncorner
/* Writes the unique corner vertices in a new array. */
double *cell_corners_xyz_without_duplicates = (double*) Malloc(3*(actual_number_of_corners - no_duplicates)*sizeof(double));
int unique_corner_number = 0;
for ( int corner_no = 0; corner_no < actual_number_of_corners; corner_no++ )
......@@ -536,8 +539,6 @@ void verify_grid(int gridtype, int gridsize, int gridno, int ngrids, int ncorner
/* We are creating a closed polygon/cell by setting the additional last corner to be the same as the first one. */
double *cell_corners_xyz = (double*) Malloc(3*(actual_number_of_corners + 1)*sizeof(double));
for ( int corner_no = 0; corner_no < actual_number_of_corners; corner_no++ )
{
int off = corner_no * 3;
......@@ -554,8 +555,6 @@ void verify_grid(int gridtype, int gridsize, int gridno, int ngrids, int ncorner
/* The remaining two-dimensional coordinates are extracted into one array for all the cell's corners and into one array for the center point. */
double *cell_corners_plane_projection = (double*) Malloc(2*(actual_number_of_corners +1)*sizeof(double));
/* The following projection on the plane that two coordinate axes lie on changes the arrangement of
the polygon vertices if the coordinate to be ignored along the third axis is smaller than 0.
In this case, the result of the computation of the orientation of vertices needs to be inverted.
......@@ -631,12 +630,12 @@ void verify_grid(int gridtype, int gridsize, int gridno, int ngrids, int ncorner
printf(" %g/%g ", grid_corner_lon[cell_no * ncorner + corner_no], grid_corner_lat[cell_no * ncorner + corner_no]);
printf("\n");
}
}
Free(marked_duplicate_indices);
Free(cell_corners_plane_projection);
Free(cell_corners_xyz);
Free(cell_corners_xyz_without_duplicates);
Free(marked_duplicate_indices);
}
int no_nonunique_cells = gridsize - no_unique_center_points;
int no_nonconvex_cells = (int) gridsize - no_convex_cells;
......
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