1 #ifndef REMAP_VARS_H
2 #define REMAP_VARS_H
3 
4 #include <cstdio>  // size_t
5 #include <array>
6 
7 #include "field.h"
8 
9 class RemapGradients
10 {
11 public:
12   Varray<double> grad_lat;
13   Varray<double> grad_lon;
14   Varray<double> grad_latlon;
15 
16   void
init(size_t size)17   init(size_t size)
18   {
19     grad_lat.resize(size);
20     grad_lon.resize(size);
21     grad_latlon.resize(size);
22   }
23 
RemapGradients(size_t size)24   RemapGradients(size_t size) { init(size); }
RemapGradients()25   RemapGradients() {}
26 };
27 
28 enum class RemapMethod
29 {
30   UNDEF,
31   BILINEAR,
32   BICUBIC,
33   DISTWGT,
34   CONSERV,
35   CONSERV_SCRIP
36 };
37 
38 enum class NormOpt
39 {
40   NONE,
41   DESTAREA,
42   FRACAREA
43 };
44 
45 struct RemapLink
46 {
47   bool option;
48   size_t max_links;
49   size_t num_blks;
50   Varray<size_t> num_links;
51   Varray2D<size_t> src_add;
52   Varray2D<size_t> dst_add;
53   Varray2D<size_t> w_index;
54 };
55 
56 struct RemapVars
57 {
58   bool sort_add;
59   bool pinit;               // true: if the pointers are initialized
60   RemapMethod mapType;      // identifier for remapping method
61   NormOpt normOpt;          // option for normalization (conserv only)
62   long links_per_value;
63   size_t max_links;         // current size of link arrays
64   size_t num_links;         // actual number of links for remapping
65   size_t num_wts;           // num of weights used in remapping
66   size_t resize_increment;  // default amount to increase array size
67 
68   Varray<size_t> src_cell_add;  // source grid address for each link
69   Varray<size_t> tgt_cell_add;  // target grid address for each link
70   Varray<double> wts;           // map weights for each link [max_links*num_wts]
71 
72   RemapLink links;
73 };
74 
75 void remap(Field &field2, double missval, size_t gridsize2, const RemapVars &rv, const Field &field1, RemapGradients &gradients);
76 void remap_laf(Field &field2, double missval, size_t gridsize2, const RemapVars &rv, const Field &field1);
77 void remap_avg(Field &field2, double missval, size_t gridsize2, const RemapVars &rv, const Field &field1);
78 void remap_vars_init(RemapMethod mapType, int remapOrder, RemapVars &rv);
79 void remap_vars_ensure_size(RemapVars &rv, size_t size);
80 void remap_vars_resize(RemapVars &rv, size_t size);
81 void remap_vars_reorder(RemapVars &rv);
82 void remap_vars_free(RemapVars &rv);
83 void remap_vars_check_weights(const RemapVars &rv);
84 
85 #endif /* REMAP_VARS_H */
86