grid_search.h 1.73 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
3
#ifndef _GRID_SEARCH_H_
#define _GRID_SEARCH_H_

4
#include <stdbool.h>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
5
#include <limits.h>
6
#include "kdtreelib/kdtree.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
7
#include "nearpt3c.h"
8

9
#define GS_NOT_FOUND  ULONG_MAX
Uwe Schulzweida's avatar
Uwe Schulzweida committed
10

Uwe Schulzweida's avatar
Uwe Schulzweida committed
11

12
enum T_GRIDSEARCH_METHOD_NN  {GS_FULL=1, GS_KDTREE, GS_KDSPH, GS_NEARPT3};
Uwe Schulzweida's avatar
Uwe Schulzweida committed
13

Uwe Schulzweida's avatar
Uwe Schulzweida committed
14
15
16
17
18
19
20
21
22
struct gsFull {
  unsigned n;
  const double *plons;
  const double *plats;
  float **pts;
};

struct gsNear {
  unsigned n;
23
24
  const double *plons;
  const double *plats;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
25
26
27
28
  Coord_T **pts;
  void *nearpt3;
};

29
struct gridsearch {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
30
  int method_nn;
31
32
  size_t n;
  size_t nx, ny;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
33

Uwe Schulzweida's avatar
Uwe Schulzweida committed
34
  struct gsNear *near;
35
  struct kdNode *kdt;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
36
37
  struct gsFull *full;

38
39
  double search_radius;

40
41
42
43
44
  // reg2d search
  double *reg2d_center_lon, *reg2d_center_lat;
  double *coslat, *sinlat;   // cosine, sine of grid lats (for distance)
  double *coslon, *sinlon;   // cosine, sine of grid lons (for distance)
};
Uwe Schulzweida's avatar
Uwe Schulzweida committed
45

46
47
48
struct gsknn {
  unsigned ndist;
  unsigned size;
49
  bool    *mask;
50
51
  size_t  *add;
  size_t  *tmpadd;
52
53
54
55
  double  *dist;
  double  *tmpdist;
};

56
struct gsknn *gridsearch_knn_new(size_t size);
57
void gridsearch_knn_delete(struct gsknn *knn);
58
size_t gridsearch_knn(struct gridsearch *gs, struct gsknn *knn, double plon, double plat);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
59

60
61
62
struct gridsearch *gridsearch_create_reg2d(bool lcyclic, size_t nx, size_t ny, const double *restrict lons, const double *restrict lats);
struct gridsearch *gridsearch_create(size_t n, const double *restrict lons, const double *restrict lats);
struct gridsearch *gridsearch_create_nn(size_t n, const double *restrict lons, const double *restrict lats);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
63
void gridsearch_delete(struct gridsearch *gs);
64
65
size_t gridsearch_nearest(struct gridsearch *gs, double lon, double lat, double *range);
struct pqueue *gridsearch_qnearest(struct gridsearch *gs, double lon, double lat, double *prange, size_t nnn);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
66
67

#endif