Commit 7826b4b2 authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

removed dmemory.h from grid_point_search, added deconstructor to ...

removed dmemory.h from grid_point_search, added deconstructor to  GridPointSearch Struct, destruction/freeing of search_container now sets the pointer to nullptr, destructor checks if search_container is nullptr
parent 1bb348fe
Pipeline #4436 passed with stages
in 16 minutes and 4 seconds
......@@ -23,7 +23,6 @@
#include "process_int.h"
#include "cdo_math.h"
#include "cdo_options.h"
#include "dmemory.h"
#include "grid_point_search.h"
#include <mpim_grid.h>
#include "kdtreelib/kdtree.h"
......@@ -97,7 +96,8 @@ struct PointCloud
// bool kdtree_get_bbox(BBOX& /* bb */) const { return false; }
};
using nfTree_t = nanoflann::KDTreeSingleIndexAdaptor<nanoflann::L2_Simple_Adaptor<double, PointCloud<double>>, PointCloud<double>, 3>;
using nfTree_t
= nanoflann::KDTreeSingleIndexAdaptor<nanoflann::L2_Simple_Adaptor<double, PointCloud<double>>, PointCloud<double>, 3>;
static double
cdoDefaultDefaultRadius(void)
......@@ -131,7 +131,8 @@ gridPointSearchExtrapolate(GridPointSearch &gps)
}
void
gridPointSearchCreateReg2d(GridPointSearch &gps, bool xIsCyclic, size_t dims[2], const Varray<double> &lons, const Varray<double> &lats)
gridPointSearchCreateReg2d(GridPointSearch &gps, bool xIsCyclic, size_t dims[2], const Varray<double> &lons,
const Varray<double> &lats)
{
gps.is_cyclic = xIsCyclic;
gps.is_reg2d = true;
......@@ -312,6 +313,8 @@ gps_destroy_kdtree(void *search_container)
{
auto kdt = (kdTree_t *) search_container;
if (kdt) kd_destroyTree(kdt);
search_container = nullptr;
}
static void
......@@ -322,18 +325,20 @@ gps_destroy_full(void *search_container)
{
if (full->pts)
{
Free(full->pts[0]);
Free(full->pts);
free(full->pts[0]);
free(full->pts);
}
Free(full);
free(full);
}
search_container = nullptr;
}
static void
gps_destroy_spherepart(void *search_container)
{
yac_delete_point_sphere_part_search((point_sphere_part_search *) search_container);
search_container = nullptr;
}
static void *
......@@ -341,10 +346,10 @@ gps_create_full(size_t n, const Varray<double> &lons, const Varray<double> &lats
{
if (Options::cdoVerbose) cdoPrint("Init full grid search: n=%zu", n);
auto full = (gpsFull *) Calloc(1, sizeof(gpsFull));
auto full = (gpsFull *) calloc(1, sizeof(gpsFull));
double **p = (double **) Malloc(n * sizeof(double *));
p[0] = (double *) Malloc(3 * n * sizeof(double));
double **p = (double **) malloc(n * sizeof(double *));
p[0] = (double *) malloc(3 * n * sizeof(double));
for (size_t i = 1; i < n; i++) p[i] = p[0] + i * 3;
#ifdef HAVE_OPENMP4
......@@ -364,7 +369,8 @@ gps_create_full(size_t n, const Varray<double> &lons, const Varray<double> &lats
}
void
gridPointSearchCreate(GridPointSearch &gps, bool xIsCyclic, size_t dims[2], size_t n, const Varray<double> &lons, const Varray<double> &lats)
gridPointSearchCreate(GridPointSearch &gps, bool xIsCyclic, size_t dims[2], size_t n, const Varray<double> &lons,
const Varray<double> &lats)
{
gps.is_cyclic = xIsCyclic;
gps.is_curve = n != 1 && n == dims[0] * dims[1];
......@@ -652,7 +658,7 @@ gps_qnearest_kdtree(GridPointSearch &gps, double lon, double lat, double searchR
{
index = p->node->index;
sqrDist = p->dist_sq;
Free(p); // Free the result node taken from the heap
free(p); // Free the result node taken from the heap
if (sqrDist < sqrDistMax)
{
......@@ -661,8 +667,8 @@ gps_qnearest_kdtree(GridPointSearch &gps, double lon, double lat, double searchR
nadds++;
}
}
Free(result->d); // free the heap
Free(result); // and free the heap information structure
free(result->d); // free the heap
free(result); // and free the heap information structure
}
}
......@@ -670,7 +676,8 @@ gps_qnearest_kdtree(GridPointSearch &gps, double lon, double lat, double searchR
}
static size_t
gps_qnearest_nanoflann(const GridPointSearch &gps, double lon, double lat, double searchRadius, size_t nnn, size_t *adds, double *dist)
gps_qnearest_nanoflann(const GridPointSearch &gps, double lon, double lat, double searchRadius, size_t nnn, size_t *adds,
double *dist)
{
size_t nadds = 0;
......@@ -776,7 +783,8 @@ gridPointSearchQnearest(GridPointSearch &gps, double lon, double lat, size_t nnn
}
size_t
gridPointSearchDistanceQnearest(GridPointSearch &gps, double searchRadius, double lon, double lat, size_t nnn, size_t *adds, double *dist)
gridPointSearchDistanceQnearest(GridPointSearch &gps, double searchRadius, double lon, double lat, size_t nnn, size_t *adds,
double *dist)
{
size_t nadds = 0;
......@@ -808,3 +816,11 @@ gridPointSearchDistanceQnearest(GridPointSearch &gps, double searchRadius, doubl
return nadds;
}
GridPointSearch::~GridPointSearch()
{
if (search_container != nullptr)
{
cdoWarning("search_container was not freed or not set to nullptr after free");
}
}
......@@ -70,6 +70,7 @@ struct GridPointSearch
void *pointcloud = nullptr;
double (*coordinates_xyz)[3];
~GridPointSearch();
};
void gridSearchPoint(GridPointSearch &gps, double plon, double plat, knnWeightsType &knnWeights);
......
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