Remove unused data members

This commit is contained in:
shahramn 2024-10-24 16:08:27 +01:00
parent 9c83171076
commit 047c14ff82
12 changed files with 99 additions and 99 deletions

View File

@ -518,7 +518,6 @@ struct grib_nearest
{
grib_arguments* args; /** args of iterator */
grib_handle* h;
grib_context* context;
double* values;
size_t values_count;
grib_nearest_class* cclass;

View File

@ -322,7 +322,7 @@ int grib_nearest_find_generic(
if ((ret = grib_nearest_get_radius(h, &radiusInKm)) != GRIB_SUCCESS)
return ret;
neighbours = (PointStore*)grib_context_malloc(nearest->context, nvalues * sizeof(PointStore));
neighbours = (PointStore*)grib_context_malloc(h->context, nvalues * sizeof(PointStore));
for (i = 0; i < nvalues; ++i) {
neighbours[i].m_dist = 1e10; /* set all distances to large number to begin with */
neighbours[i].m_lat = 0;
@ -345,14 +345,14 @@ int grib_nearest_find_generic(
*out_lats_count = (int)nvalues;
if (*out_lats)
grib_context_free(nearest->context, *out_lats);
*out_lats = (double*)grib_context_malloc(nearest->context, nvalues * sizeof(double));
grib_context_free(h->context, *out_lats);
*out_lats = (double*)grib_context_malloc(h->context, nvalues * sizeof(double));
if (!*out_lats)
return GRIB_OUT_OF_MEMORY;
if (*out_lons)
grib_context_free(nearest->context, *out_lons);
*out_lons = (double*)grib_context_malloc(nearest->context, nvalues * sizeof(double));
grib_context_free(h->context, *out_lons);
*out_lons = (double*)grib_context_malloc(h->context, nvalues * sizeof(double));
if (!*out_lons)
return GRIB_OUT_OF_MEMORY;
@ -418,7 +418,7 @@ int grib_nearest_find_generic(
/* GRIB_NEAREST_SAME_XXX not yet implemented */
if (!*out_distances) {
*out_distances = (double*)grib_context_malloc(nearest->context, 4 * sizeof(double));
*out_distances = (double*)grib_context_malloc(h->context, 4 * sizeof(double));
}
(*out_distances)[0] = neighbours[0].m_dist;
(*out_distances)[1] = neighbours[1].m_dist;

View File

@ -81,16 +81,15 @@ static int init(grib_nearest* nearest, grib_handle* h, grib_arguments* args)
self->radius = grib_arguments_get_name(h, args, self->cargs++);
nearest->values = NULL;
nearest->context = h->context;
return ret;
}
static int destroy(grib_nearest* nearest)
{
grib_context* c = grib_context_get_default();
if (nearest->values)
grib_context_free(nearest->context, nearest->values);
grib_context_free(nearest->context, nearest);
grib_context_free(c, nearest->values);
grib_context_free(c, nearest);
return GRIB_SUCCESS;
}

View File

@ -124,11 +124,13 @@ static int find(grib_nearest* nearest, grib_handle* h,
static int destroy(grib_nearest* nearest)
{
grib_nearest_healpix* self = (grib_nearest_healpix*)nearest;
if (self->lats) grib_context_free(nearest->context, self->lats);
if (self->lons) grib_context_free(nearest->context, self->lons);
if (self->i) grib_context_free(nearest->context, self->i);
if (self->j) grib_context_free(nearest->context, self->j);
if (self->k) grib_context_free(nearest->context, self->k);
if (self->distances) grib_context_free(nearest->context, self->distances);
grib_context* c = grib_context_get_default();
if (self->lats) grib_context_free(c, self->lats);
if (self->lons) grib_context_free(c, self->lons);
if (self->i) grib_context_free(c, self->i);
if (self->j) grib_context_free(c, self->j);
if (self->k) grib_context_free(c, self->k);
if (self->distances) grib_context_free(c, self->distances);
return GRIB_SUCCESS;
}

View File

@ -122,11 +122,13 @@ static int find(grib_nearest* nearest, grib_handle* h,
static int destroy(grib_nearest* nearest)
{
grib_nearest_lambert_azimuthal_equal_area* self = (grib_nearest_lambert_azimuthal_equal_area*)nearest;
if (self->lats) grib_context_free(nearest->context, self->lats);
if (self->lons) grib_context_free(nearest->context, self->lons);
if (self->i) grib_context_free(nearest->context, self->i);
if (self->j) grib_context_free(nearest->context, self->j);
if (self->k) grib_context_free(nearest->context, self->k);
if (self->distances) grib_context_free(nearest->context, self->distances);
grib_context* c = grib_context_get_default();
if (self->lats) grib_context_free(c, self->lats);
if (self->lons) grib_context_free(c, self->lons);
if (self->i) grib_context_free(c, self->i);
if (self->j) grib_context_free(c, self->j);
if (self->k) grib_context_free(c, self->k);
if (self->distances) grib_context_free(c, self->distances);
return GRIB_SUCCESS;
}

View File

@ -122,11 +122,13 @@ static int find(grib_nearest* nearest, grib_handle* h,
static int destroy(grib_nearest* nearest)
{
grib_nearest_lambert_conformal* self = (grib_nearest_lambert_conformal*)nearest;
if (self->lats) grib_context_free(nearest->context, self->lats);
if (self->lons) grib_context_free(nearest->context, self->lons);
if (self->i) grib_context_free(nearest->context, self->i);
if (self->j) grib_context_free(nearest->context, self->j);
if (self->k) grib_context_free(nearest->context, self->k);
if (self->distances) grib_context_free(nearest->context, self->distances);
grib_context* c = grib_context_get_default();
if (self->lats) grib_context_free(c, self->lats);
if (self->lons) grib_context_free(c, self->lons);
if (self->i) grib_context_free(c, self->i);
if (self->j) grib_context_free(c, self->j);
if (self->k) grib_context_free(c, self->k);
if (self->distances) grib_context_free(c, self->distances);
return GRIB_SUCCESS;
}

View File

@ -98,7 +98,7 @@ static int init(grib_nearest* nearest, grib_handle* h, grib_arguments* args)
self->j = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t));
if (!self->j)
return GRIB_OUT_OF_MEMORY;
self->k = (size_t*)grib_context_malloc(nearest->context, 4 * sizeof(size_t));
self->k = (size_t*)grib_context_malloc(h->context, 4 * sizeof(size_t));
if (!self->k)
return GRIB_OUT_OF_MEMORY;
@ -195,15 +195,15 @@ static int find_global(grib_nearest* nearest, grib_handle* h,
self->lats_count = n;
if (self->lats)
grib_context_free(nearest->context, self->lats);
self->lats = (double*)grib_context_malloc(nearest->context,
grib_context_free(h->context, self->lats);
self->lats = (double*)grib_context_malloc(h->context,
self->lats_count * sizeof(double));
if (!self->lats)
return GRIB_OUT_OF_MEMORY;
if (self->lons)
grib_context_free(nearest->context, self->lons);
self->lons = (double*)grib_context_malloc(nearest->context,
grib_context_free(h->context, self->lons);
self->lons = (double*)grib_context_malloc(h->context,
nearest->values_count * sizeof(double));
if (!self->lons)
return GRIB_OUT_OF_MEMORY;
@ -300,7 +300,7 @@ static int find_global(grib_nearest* nearest, grib_handle* h,
}
if (!self->distances)
self->distances = (double*)grib_context_malloc(nearest->context, 4 * sizeof(double));
self->distances = (double*)grib_context_malloc(h->context, 4 * sizeof(double));
if (!self->distances)
return GRIB_OUT_OF_MEMORY;
@ -420,16 +420,17 @@ static int find_global(grib_nearest* nearest, grib_handle* h,
static int destroy(grib_nearest* nearest)
{
grib_nearest_latlon_reduced* self = (grib_nearest_latlon_reduced*)nearest;
grib_context* c = grib_context_get_default();
if (self->lats)
grib_context_free(nearest->context, self->lats);
grib_context_free(c, self->lats);
if (self->lons)
grib_context_free(nearest->context, self->lons);
grib_context_free(c, self->lons);
if (self->j)
grib_context_free(nearest->context, self->j);
grib_context_free(c, self->j);
if (self->k)
grib_context_free(nearest->context, self->k);
grib_context_free(c, self->k);
if (self->distances)
grib_context_free(nearest->context, self->distances);
grib_context_free(c, self->distances);
return GRIB_SUCCESS;
}

View File

@ -124,11 +124,13 @@ static int find(grib_nearest* nearest, grib_handle* h,
static int destroy(grib_nearest* nearest)
{
grib_nearest_mercator* self = (grib_nearest_mercator*)nearest;
if (self->lats) grib_context_free(nearest->context, self->lats);
if (self->lons) grib_context_free(nearest->context, self->lons);
if (self->i) grib_context_free(nearest->context, self->i);
if (self->j) grib_context_free(nearest->context, self->j);
if (self->k) grib_context_free(nearest->context, self->k);
if (self->distances) grib_context_free(nearest->context, self->distances);
grib_context* c = grib_context_get_default();
if (self->lats) grib_context_free(c, self->lats);
if (self->lons) grib_context_free(c, self->lons);
if (self->i) grib_context_free(c, self->i);
if (self->j) grib_context_free(c, self->j);
if (self->k) grib_context_free(c, self->k);
if (self->distances) grib_context_free(c, self->distances);
return GRIB_SUCCESS;
}

View File

@ -122,11 +122,13 @@ static int find(grib_nearest* nearest, grib_handle* h,
static int destroy(grib_nearest* nearest)
{
grib_nearest_polar_stereographic* self = (grib_nearest_polar_stereographic*)nearest;
if (self->lats) grib_context_free(nearest->context, self->lats);
if (self->lons) grib_context_free(nearest->context, self->lons);
if (self->i) grib_context_free(nearest->context, self->i);
if (self->j) grib_context_free(nearest->context, self->j);
if (self->k) grib_context_free(nearest->context, self->k);
if (self->distances) grib_context_free(nearest->context, self->distances);
grib_context* c = grib_context_get_default();
if (self->lats) grib_context_free(c, self->lats);
if (self->lons) grib_context_free(c, self->lons);
if (self->i) grib_context_free(c, self->i);
if (self->j) grib_context_free(c, self->j);
if (self->k) grib_context_free(c, self->k);
if (self->distances) grib_context_free(c, self->distances);
return GRIB_SUCCESS;
}

View File

@ -106,7 +106,7 @@ static int init(grib_nearest* nearest, grib_handle* h, grib_arguments* args)
self->rotated = -1;
if (!self->j)
return GRIB_OUT_OF_MEMORY;
self->k = (size_t*)grib_context_malloc(nearest->context, NUM_NEIGHBOURS * sizeof(size_t));
self->k = (size_t*)grib_context_malloc(h->context, NUM_NEIGHBOURS * sizeof(size_t));
if (!self->k)
return GRIB_OUT_OF_MEMORY;
grib_get_long(h, "global", &self->global);
@ -251,16 +251,14 @@ static int find_global(grib_nearest* nearest, grib_handle* h,
self->lats_count = n;
if (self->lats)
grib_context_free(nearest->context, self->lats);
self->lats = (double*)grib_context_malloc(nearest->context,
self->lats_count * sizeof(double));
grib_context_free(h->context, self->lats);
self->lats = (double*)grib_context_malloc(h->context, self->lats_count * sizeof(double));
if (!self->lats)
return GRIB_OUT_OF_MEMORY;
if (self->lons)
grib_context_free(nearest->context, self->lons);
self->lons = (double*)grib_context_malloc(nearest->context,
nearest->values_count * sizeof(double));
grib_context_free(h->context, self->lons);
self->lons = (double*)grib_context_malloc(h->context, nearest->values_count * sizeof(double));
if (!self->lons)
return GRIB_OUT_OF_MEMORY;
@ -321,12 +319,11 @@ static int find_global(grib_nearest* nearest, grib_handle* h,
}
if (!self->distances)
self->distances = (double*)grib_context_malloc(nearest->context, NUM_NEIGHBOURS * sizeof(double));
self->distances = (double*)grib_context_malloc(h->context, NUM_NEIGHBOURS * sizeof(double));
if (!self->distances)
return GRIB_OUT_OF_MEMORY;
grib_binary_search(self->lats, ilat - 1, inlat,
&(self->j[0]), &(self->j[1]));
grib_binary_search(self->lats, ilat - 1, inlat, &(self->j[0]), &(self->j[1]));
plsize = self->lats_count;
if ((err = grib_get_size(h, self->pl, &plsize)) != GRIB_SUCCESS)
@ -522,16 +519,13 @@ static int find_global(grib_nearest* nearest, grib_handle* h,
static int destroy(grib_nearest* nearest)
{
grib_nearest_reduced* self = (grib_nearest_reduced*)nearest;
if (self->lats)
grib_context_free(nearest->context, self->lats);
if (self->lons)
grib_context_free(nearest->context, self->lons);
if (self->j)
grib_context_free(nearest->context, self->j);
if (self->k)
grib_context_free(nearest->context, self->k);
if (self->distances)
grib_context_free(nearest->context, self->distances);
grib_context* c = grib_context_get_default();
if (self->lats) grib_context_free(c, self->lats);
if (self->lons) grib_context_free(c, self->lons);
if (self->j) grib_context_free(c, self->j);
if (self->k) grib_context_free(c, self->k);
if (self->distances) grib_context_free(c, self->distances);
return GRIB_SUCCESS;
}

View File

@ -128,6 +128,7 @@ static int find(grib_nearest* nearest, grib_handle* h,
double lat = 0, lon = 0;
const bool is_rotated = is_rotated_grid(h);
double angleOfRotation = 0, southPoleLat = 0, southPoleLon = 0;
grib_context* c = h->context;
while (inlon < 0)
inlon += 360;
@ -194,16 +195,14 @@ static int find(grib_nearest* nearest, grib_handle* h,
self->lats_count = n;
if (self->lats)
grib_context_free(nearest->context, self->lats);
self->lats = (double*)grib_context_malloc(nearest->context,
self->lats_count * sizeof(double));
grib_context_free(c, self->lats);
self->lats = (double*)grib_context_malloc(c, self->lats_count * sizeof(double));
if (!self->lats)
return GRIB_OUT_OF_MEMORY;
if (self->lons)
grib_context_free(nearest->context, self->lons);
self->lons = (double*)grib_context_malloc(nearest->context,
self->lons_count * sizeof(double));
grib_context_free(c, self->lons);
self->lons = (double*)grib_context_malloc(c, self->lons_count * sizeof(double));
if (!self->lons)
return GRIB_OUT_OF_MEMORY;
@ -289,9 +288,9 @@ static int find(grib_nearest* nearest, grib_handle* h,
&(self->i[0]), &(self->i[1]));
if (!self->distances)
self->distances = (double*)grib_context_malloc(nearest->context, NUM_NEIGHBOURS * sizeof(double));
self->distances = (double*)grib_context_malloc(c, NUM_NEIGHBOURS * sizeof(double));
if (!self->k)
self->k = (size_t*)grib_context_malloc(nearest->context, NUM_NEIGHBOURS * sizeof(size_t));
self->k = (size_t*)grib_context_malloc(c, NUM_NEIGHBOURS * sizeof(size_t));
kk = 0;
for (jj = 0; jj < 2; jj++) {
for (ii = 0; ii < 2; ii++) {
@ -310,7 +309,7 @@ static int find(grib_nearest* nearest, grib_handle* h,
* First unpack all the values into an array. Then when we need the 4 points
* we just index into this array so no need to call grib_get_double_element_internal
*
* if (nearest->values) grib_context_free(nearest->context,nearest->values);
* if (nearest->values) grib_context_free(c,nearest->values);
* nearest->values = grib_context_malloc(h->context,nvalues*sizeof(double));
* if (!nearest->values) return GRIB_OUT_OF_MEMORY;
* ret = grib_get_double_array(h, self->values_key, nearest->values ,&nvalues);
@ -362,17 +361,13 @@ static int find(grib_nearest* nearest, grib_handle* h,
static int destroy(grib_nearest* nearest)
{
grib_nearest_regular* self = (grib_nearest_regular*)nearest;
if (self->lats)
grib_context_free(nearest->context, self->lats);
if (self->lons)
grib_context_free(nearest->context, self->lons);
if (self->i)
grib_context_free(nearest->context, self->i);
if (self->j)
grib_context_free(nearest->context, self->j);
if (self->k)
grib_context_free(nearest->context, self->k);
if (self->distances)
grib_context_free(nearest->context, self->distances);
grib_context* c = grib_context_get_default();
if (self->lats) grib_context_free(c, self->lats);
if (self->lons) grib_context_free(c, self->lons);
if (self->i) grib_context_free(c, self->i);
if (self->j) grib_context_free(c, self->j);
if (self->k) grib_context_free(c, self->k);
if (self->distances) grib_context_free(c, self->distances);
return GRIB_SUCCESS;
}

View File

@ -122,11 +122,13 @@ static int find(grib_nearest* nearest, grib_handle* h,
static int destroy(grib_nearest* nearest)
{
grib_nearest_space_view* self = (grib_nearest_space_view*)nearest;
if (self->lats) grib_context_free(nearest->context, self->lats);
if (self->lons) grib_context_free(nearest->context, self->lons);
if (self->i) grib_context_free(nearest->context, self->i);
if (self->j) grib_context_free(nearest->context, self->j);
if (self->k) grib_context_free(nearest->context, self->k);
if (self->distances) grib_context_free(nearest->context, self->distances);
grib_context* c = grib_context_get_default();
if (self->lats) grib_context_free(c, self->lats);
if (self->lons) grib_context_free(c, self->lons);
if (self->i) grib_context_free(c, self->i);
if (self->j) grib_context_free(c, self->j);
if (self->k) grib_context_free(c, self->k);
if (self->distances) grib_context_free(c, self->distances);
return GRIB_SUCCESS;
}