remap_vars.h 2.15 KB
Newer Older
1
2
3
#ifndef REMAP_VARS_H
#define REMAP_VARS_H

Uwe Schulzweida's avatar
Uwe Schulzweida committed
4
#include <cstdio>  // size_t
5
#include <array>
6

7
class RemapGradients
Uwe Schulzweida's avatar
Uwe Schulzweida committed
8
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
9
public:
10
11
12
  Varray<double> grad_lat;
  Varray<double> grad_lon;
  Varray<double> grad_latlon;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
13

Uwe Schulzweida's avatar
Uwe Schulzweida committed
14
15
16
17
18
19
20
  void
  init(size_t size)
  {
    grad_lat.resize(size);
    grad_lon.resize(size);
    grad_latlon.resize(size);
  }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
21

22
23
  RemapGradients(size_t size) { init(size); }
  RemapGradients() {}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
24
};
25

26
enum class RemapMethod
27
28
29
30
31
32
{
  UNDEF,
  BILINEAR,
  BICUBIC,
  DISTWGT,
  CONSERV,
33
  CONSERV_SCRIP
34
35
};

36
enum class NormOpt
37
38
39
40
41
42
{
  NONE,
  DESTAREA,
  FRACAREA
};

43
struct RemapLink
44
45
46
47
{
  bool option;
  size_t max_links;
  size_t num_blks;
48
49
50
51
  Varray<size_t> num_links;
  Varray2D<size_t> src_add;
  Varray2D<size_t> dst_add;
  Varray2D<size_t> w_index;
52
};
53

54
struct RemapVars
55
56
{
  bool sort_add;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
57
58
59
  bool pinit;           // true: if the pointers are initialized
  RemapMethod mapType;  // identifier for remapping method
  NormOpt normOpt;      // option for normalization (conserv only)
60
  long links_per_value;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
61
62
63
64
  size_t max_links;         // current size of link arrays
  size_t num_links;         // actual number of links for remapping
  size_t num_wts;           // num of weights used in remapping
  size_t resize_increment;  // default amount to increase array size
Uwe Schulzweida's avatar
Uwe Schulzweida committed
65

Uwe Schulzweida's avatar
Uwe Schulzweida committed
66
67
68
  Varray<size_t> src_cell_add;  // source grid address for each link
  Varray<size_t> tgt_cell_add;  // target grid address for each link
  Varray<double> wts;           // map weights for each link [max_links*num_wts]
69

70
  RemapLink links;
71
72
};

Uwe Schulzweida's avatar
Uwe Schulzweida committed
73
void remap(double *dst_array, double missval, size_t dst_size, const RemapVars &rv, const double *src_array,
74
           RemapGradients &gradients);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
75
void remap_laf(double *dst_array, double missval, size_t dst_size, const RemapVars &rv, const double *src_array);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
76
void remap_avg(double *dst_array, double missval, size_t dst_size, const RemapVars &rv, const double *src_array);
77
void remapVarsInit(RemapMethod mapType, int remapOrder, RemapVars &rv);
78
79
80
81
82
void remapVarsEnsureSize(RemapVars &rv, size_t size);
void remapVarsResize(RemapVars &rv, size_t size);
void remapVarsReorder(RemapVars &rv);
void remapVarsFree(RemapVars &rv);
void remapVarsCheckWeights(const RemapVars &rv);
83
84

#endif /* REMAP_VARS_H */