Commit aaa4096b authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Renamed wgts to weights.

parent d8afcd61
......@@ -27,7 +27,7 @@
// bicubic interpolation
static void
bicubicSetWeights(double iw, double jw, double (&wgts)[4][4])
bicubicSetWeights(double iw, double jw, double (&weights)[4][4])
{
const auto iw1 = iw*iw*(iw-1.);
const auto iw2 = iw*(iw-1.)*(iw-1.);
......@@ -36,22 +36,22 @@ bicubicSetWeights(double iw, double jw, double (&wgts)[4][4])
const auto jw2 = jw*(jw-1.)*(jw-1.);
const auto jw3 = jw*jw*(3.-2.*jw);
// clang-format off
wgts[0][0] = (1.-jw3) * (1.-iw3);
wgts[1][0] = (1.-jw3) * iw3;
wgts[2][0] = jw3 * iw3;
wgts[3][0] = jw3 * (1.-iw3);
wgts[0][1] = (1.-jw3) * iw2;
wgts[1][1] = (1.-jw3) * iw1;
wgts[2][1] = jw3 * iw1;
wgts[3][1] = jw3 * iw2;
wgts[0][2] = jw2 * (1.-iw3);
wgts[1][2] = jw2 * iw3;
wgts[2][2] = jw1 * iw3;
wgts[3][2] = jw1 * (1.-iw3);
wgts[0][3] = jw2 * iw2;
wgts[1][3] = jw2 * iw1;
wgts[2][3] = jw1 * iw1;
wgts[3][3] = jw1 * iw2;
weights[0][0] = (1.-jw3) * (1.-iw3);
weights[1][0] = (1.-jw3) * iw3;
weights[2][0] = jw3 * iw3;
weights[3][0] = jw3 * (1.-iw3);
weights[0][1] = (1.-jw3) * iw2;
weights[1][1] = (1.-jw3) * iw1;
weights[2][1] = jw3 * iw1;
weights[3][1] = jw3 * iw2;
weights[0][2] = jw2 * (1.-iw3);
weights[1][2] = jw2 * iw3;
weights[2][2] = jw1 * iw3;
weights[3][2] = jw1 * (1.-iw3);
weights[0][3] = jw2 * iw2;
weights[1][3] = jw2 * iw1;
weights[2][3] = jw1 * iw1;
weights[3][3] = jw1 * iw2;
// clang-format on
}
......@@ -59,14 +59,14 @@ template <typename T>
int num_src_points(const Varray<T> &mask, const size_t (&src_add)[4], double (&src_lats)[4]);
static void
renormalizeWeights(const double (&src_lats)[4], double (&wgts)[4][4])
renormalizeWeights(const double (&src_lats)[4], double (&weights)[4][4])
{
double sum_wgts = 0.0; // sum of weights for normalization
for (unsigned n = 0; n < 4; ++n) sum_wgts += std::fabs(src_lats[n]);
for (unsigned n = 0; n < 4; ++n) wgts[n][0] = std::fabs(src_lats[n]) / sum_wgts;
for (unsigned n = 0; n < 4; ++n) wgts[n][1] = 0.;
for (unsigned n = 0; n < 4; ++n) wgts[n][2] = 0.;
for (unsigned n = 0; n < 4; ++n) wgts[n][3] = 0.;
double sum_weights = 0.0; // sum of weights for normalization
for (unsigned n = 0; n < 4; ++n) sum_weights += std::fabs(src_lats[n]);
for (unsigned n = 0; n < 4; ++n) weights[n][0] = std::fabs(src_lats[n]) / sum_weights;
for (unsigned n = 0; n < 4; ++n) weights[n][1] = 0.;
for (unsigned n = 0; n < 4; ++n) weights[n][2] = 0.;
for (unsigned n = 0; n < 4; ++n) weights[n][3] = 0.;
}
static void
......@@ -82,7 +82,7 @@ bicubicWarning()
}
static double
bicubicRemap(const double *restrict src_array, const double (&wgts)[4][4], const size_t (&src_add)[4], const RemapGradients &gradients)
bicubicRemap(const double *restrict src_array, const double (&weights)[4][4], const size_t (&src_add)[4], const RemapGradients &gradients)
{
const auto &glat = gradients.grad_lat;
const auto &glon = gradients.grad_lon;
......@@ -90,8 +90,8 @@ bicubicRemap(const double *restrict src_array, const double (&wgts)[4][4], const
double tgt_point = 0.;
for (unsigned n = 0; n < 4; ++n)
tgt_point += src_array[src_add[n]] * wgts[n][0] + glat[src_add[n]] * wgts[n][1] + glon[src_add[n]] * wgts[n][2]
+ glatlon[src_add[n]] * wgts[n][3];
tgt_point += src_array[src_add[n]] * weights[n][0] + glat[src_add[n]] * weights[n][1] + glon[src_add[n]] * weights[n][2]
+ glatlon[src_add[n]] * weights[n][3];
return tgt_point;
}
......@@ -148,7 +148,7 @@ remapBicubicWeights(RemapSearch &rsearch, RemapVars &rv)
size_t src_add[4]; // address for the four source points
double src_lats[4]; // latitudes of four bilinear corners
double src_lons[4]; // longitudes of four bilinear corners
double wgts[4][4]; // bicubic weights for four corners
double weights[4][4]; // bicubic weights for four corners
// Find nearest square of grid points on source grid
auto search_result = remapSearchSquare(rsearch, llpoint, src_add, src_lats, src_lons);
......@@ -169,8 +169,8 @@ remapBicubicWeights(RemapSearch &rsearch, RemapVars &rv)
if (remapFindWeights(llpoint, src_lons, src_lats, &iw, &jw))
{
// Successfully found iw,jw - compute weights
bicubicSetWeights(iw, jw, wgts);
store_weightlinks_bicubic(src_add, wgts, tgt_cell_add, weightLinks);
bicubicSetWeights(iw, jw, weights);
store_weightlinks_bicubic(src_add, weights, tgt_cell_add, weightLinks);
}
else
{
......@@ -186,8 +186,8 @@ remapBicubicWeights(RemapSearch &rsearch, RemapVars &rv)
if (num_src_points(src_grid->mask, src_add, src_lats) > 0)
{
tgt_grid->cell_frac[tgt_cell_add] = 1.;
renormalizeWeights(src_lats, wgts);
store_weightlinks_bicubic(src_add, wgts, tgt_cell_add, weightLinks);
renormalizeWeights(src_lats, weights);
store_weightlinks_bicubic(src_add, weights, tgt_cell_add, weightLinks);
}
}
}
......@@ -260,7 +260,7 @@ remapBicubic(RemapSearch &rsearch, const double *restrict src_array, double *res
size_t src_add[4]; // address for the four source points
double src_lats[4]; // latitudes of four bilinear corners
double src_lons[4]; // longitudes of four bilinear corners
double wgts[4][4]; // bicubic weights for four corners
double weights[4][4]; // bicubic weights for four corners
// Find nearest square of grid points on source grid
auto search_result = remapSearchSquare(rsearch, llpoint, src_add, src_lats, src_lons);
......@@ -281,9 +281,9 @@ remapBicubic(RemapSearch &rsearch, const double *restrict src_array, double *res
if (remapFindWeights(llpoint, src_lons, src_lats, &iw, &jw))
{
// Successfully found iw,jw - compute weights
bicubicSetWeights(iw, jw, wgts);
sort_add_and_wgts_bicubic(src_add, wgts);
tgt_array[tgt_cell_add] = bicubicRemap(src_array, wgts, src_add, gradients);
bicubicSetWeights(iw, jw, weights);
sort_add_and_weights_bicubic(src_add, weights);
tgt_array[tgt_cell_add] = bicubicRemap(src_array, weights, src_add, gradients);
}
else
{
......@@ -299,9 +299,9 @@ remapBicubic(RemapSearch &rsearch, const double *restrict src_array, double *res
if (num_src_points(src_grid_mask, src_add, src_lats) > 0)
{
tgt_grid->cell_frac[tgt_cell_add] = 1.;
renormalizeWeights(src_lats, wgts);
sort_add_and_wgts_bicubic(src_add, wgts);
tgt_array[tgt_cell_add] = bicubicRemap(src_array, wgts, src_add, gradients);
renormalizeWeights(src_lats, weights);
sort_add_and_weights_bicubic(src_add, weights);
tgt_array[tgt_cell_add] = bicubicRemap(src_array, weights, src_add, gradients);
}
}
}
......
......@@ -93,13 +93,13 @@ remapFindWeights(const LonLatPoint &llpoint, const double (&src_lons)[4], const
}
static void
bilinearSetWeights(double iw, double jw, double (&wgts)[4])
bilinearSetWeights(double iw, double jw, double (&weights)[4])
{
// clang-format off
wgts[0] = (1.-iw) * (1.-jw);
wgts[1] = iw * (1.-jw);
wgts[2] = iw * jw;
wgts[3] = (1.-iw) * jw;
weights[0] = (1.-iw) * (1.-jw);
weights[1] = iw * (1.-jw);
weights[2] = iw * jw;
weights[3] = (1.-iw) * jw;
// clang-format on
}
......@@ -125,11 +125,11 @@ template int num_src_points(const Varray<uint8_t> &mask, const size_t (&src_add)
template int num_src_points(const Varray<int> &mask, const size_t (&src_add)[4], double (&src_lats)[4]);
static void
renormalizeWeights(const double (&src_lats)[4], double (&wgts)[4])
renormalizeWeights(const double (&src_lats)[4], double (&weights)[4])
{
double sum_wgts = 0.0; // sum of weights for normalization
for (unsigned n = 0; n < 4; ++n) sum_wgts += std::fabs(src_lats[n]);
for (unsigned n = 0; n < 4; ++n) wgts[n] = std::fabs(src_lats[n]) / sum_wgts;
double sum_weights = 0.0; // sum of weights for normalization
for (unsigned n = 0; n < 4; ++n) sum_weights += std::fabs(src_lats[n]);
for (unsigned n = 0; n < 4; ++n) weights[n] = std::fabs(src_lats[n]) / sum_weights;
}
static void
......@@ -145,12 +145,12 @@ bilinearWarning()
}
static inline double
bilinearRemap(const double *restrict src_array, const double (&wgts)[4], const size_t (&src_add)[4])
bilinearRemap(const double *restrict src_array, const double (&weights)[4], const size_t (&src_add)[4])
{
// *tgt_point = 0.;
// for (unsigned n = 0; n < 4; ++n) *tgt_point += src_array[src_add[n]]*wgts[n];
return src_array[src_add[0]] * wgts[0] + src_array[src_add[1]] * wgts[1] + src_array[src_add[2]] * wgts[2]
+ src_array[src_add[3]] * wgts[3];
// for (unsigned n = 0; n < 4; ++n) *tgt_point += src_array[src_add[n]]*weights[n];
return src_array[src_add[0]] * weights[0] + src_array[src_add[1]] * weights[1] + src_array[src_add[2]] * weights[2]
+ src_array[src_add[3]] * weights[3];
}
// This routine computes the weights for a bilinear interpolation.
......@@ -199,7 +199,7 @@ remapBilinearWeights(RemapSearch &rsearch, RemapVars &rv)
size_t src_add[4]; // address for the four source points
double src_lats[4]; // latitudes of four bilinear corners
double src_lons[4]; // longitudes of four bilinear corners
double wgts[4]; // bilinear weights for four corners
double weights[4]; // bilinear weights for four corners
// Find nearest square of grid points on source grid
auto search_result = remapSearchSquare(rsearch, llpoint, src_add, src_lats, src_lons);
......@@ -220,8 +220,8 @@ remapBilinearWeights(RemapSearch &rsearch, RemapVars &rv)
if (remapFindWeights(llpoint, src_lons, src_lats, &iw, &jw))
{
// Successfully found iw,jw - compute weights
bilinearSetWeights(iw, jw, wgts);
store_weightlinks(0, 4, src_add, wgts, tgt_cell_add, weightLinks);
bilinearSetWeights(iw, jw, weights);
store_weightlinks(0, 4, src_add, weights, tgt_cell_add, weightLinks);
}
else
{
......@@ -239,8 +239,8 @@ remapBilinearWeights(RemapSearch &rsearch, RemapVars &rv)
if (num_src_points(src_grid->mask, src_add, src_lats) > 0)
{
tgt_grid->cell_frac[tgt_cell_add] = 1.;
renormalizeWeights(src_lats, wgts);
store_weightlinks(0, 4, src_add, wgts, tgt_cell_add, weightLinks);
renormalizeWeights(src_lats, weights);
store_weightlinks(0, 4, src_add, weights, tgt_cell_add, weightLinks);
}
}
}
......@@ -303,7 +303,7 @@ remapBilinear(RemapSearch &rsearch, const double *restrict src_array, double *re
size_t src_add[4]; // address for the four source points
double src_lats[4]; // latitudes of four bilinear corners
double src_lons[4]; // longitudes of four bilinear corners
double wgts[4]; // bilinear weights for four corners
double weights[4]; // bilinear weights for four corners
// Find nearest square of grid points on source grid
auto search_result = remapSearchSquare(rsearch, llpoint, src_add, src_lats, src_lons);
......@@ -324,9 +324,9 @@ remapBilinear(RemapSearch &rsearch, const double *restrict src_array, double *re
if (remapFindWeights(llpoint, src_lons, src_lats, &iw, &jw))
{
// Successfully found iw,jw - compute weights
bilinearSetWeights(iw, jw, wgts);
sort_add_and_4wgts(src_add, wgts);
tgt_array[tgt_cell_add] = bilinearRemap(src_array, wgts, src_add);
bilinearSetWeights(iw, jw, weights);
sort_add_and_4weights(src_add, weights);
tgt_array[tgt_cell_add] = bilinearRemap(src_array, weights, src_add);
}
else
{
......@@ -344,9 +344,9 @@ remapBilinear(RemapSearch &rsearch, const double *restrict src_array, double *re
if (num_src_points(src_grid_mask, src_add, src_lats) > 0)
{
tgt_grid->cell_frac[tgt_cell_add] = 1.;
renormalizeWeights(src_lats, wgts);
sort_add_and_4wgts(src_add, wgts);
tgt_array[tgt_cell_add] = bilinearRemap(src_array, wgts, src_add);
renormalizeWeights(src_lats, weights);
sort_add_and_4weights(src_add, weights);
tgt_array[tgt_cell_add] = bilinearRemap(src_array, weights, src_add);
}
}
}
......
......@@ -758,10 +758,10 @@ remapConservWeights(RemapSearch &rsearch, RemapVars &rv)
} // remapConservWeights
static double
conservRemap(const double *restrict src_array, size_t num_weights, const Varray<double> &wgts, const std::vector<size_t> &src_add)
conservRemap(const double *restrict src_array, size_t num_weights, const Varray<double> &weights, const std::vector<size_t> &src_add)
{
double tgt_point = 0.;
for (size_t i = 0; i < num_weights; ++i) tgt_point += src_array[src_add[i]] * wgts[i];
for (size_t i = 0; i < num_weights; ++i) tgt_point += src_array[src_add[i]] * weights[i];
return tgt_point;
}
......@@ -948,7 +948,7 @@ remapConserv(NormOpt normOpt, RemapSearch &rsearch, const double *restrict src_a
if (num_weights)
{
sort_add_and_wgts(num_weights, srch_add[ompthID].data(), partial_weights.data());
sort_add_and_weights(num_weights, srch_add[ompthID].data(), partial_weights.data());
// Normalize weights using destination area if requested
remapNormalizeWeights(normOpt, tgt_area, tgt_grid->cell_frac[tgt_cell_add], num_weights, partial_weights.data());
tgt_array[tgt_cell_add] = conservRemap(src_array, num_weights, partial_weights, srch_add[ompthID]);
......
......@@ -74,7 +74,7 @@ sortAddweights4(Addweight4 *addweights)
}
void
sort_add_and_4wgts(size_t *src_add, double *weights)
sort_add_and_4weights(size_t *src_add, double *weights)
{
constexpr size_t numWeights = 4;
size_t n;
......@@ -100,7 +100,7 @@ sort_add_and_4wgts(size_t *src_add, double *weights)
}
void
sort_add_and_wgts(size_t numWeights, size_t *src_add, double *weights)
sort_add_and_weights(size_t numWeights, size_t *src_add, double *weights)
{
size_t n;
for (n = 1; n < numWeights; ++n)
......@@ -128,7 +128,7 @@ sort_add_and_wgts(size_t numWeights, size_t *src_add, double *weights)
}
void
sort_add_and_wgts_bicubic(size_t *src_add, double (&weights)[4][4])
sort_add_and_weights_bicubic(size_t *src_add, double (&weights)[4][4])
{
constexpr size_t numWeights = 4;
size_t n;
......@@ -205,7 +205,6 @@ void
weightLinksToRemapLinks(int lalloc, size_t gridSize, std::vector<WeightLinks> &weightLinks, RemapVars &rv)
{
size_t nlinks = 0;
for (size_t i = 0; i < gridSize; ++i)
{
if (weightLinks[i].nlinks)
......@@ -266,7 +265,6 @@ void
weightLinks4ToRemapLinks(size_t gridSize, std::vector<WeightLinks4> &weightLinks, RemapVars &rv)
{
size_t nlinks = 0;
for (size_t i = 0; i < gridSize; ++i)
{
if (weightLinks[i].nlinks)
......
......@@ -55,8 +55,8 @@ void store_weightlinks(int lalloc, size_t numWeights, size_t *srch_add, double *
void store_weightlinks_bicubic(size_t *srch_add, double (&weights)[4][4], size_t cell_add, std::vector<WeightLinks4> &weightLinks);
void weightLinksToRemapLinks(int lalloc, size_t gridSize, std::vector<WeightLinks> &weightLinks, RemapVars &rv);
void weightLinks4ToRemapLinks(size_t gridSize, std::vector<WeightLinks4> &weightLinks, RemapVars &rv);
void sort_add_and_wgts(size_t numWeights, size_t *src_add, double *weights);
void sort_add_and_4wgts(size_t *src_add, double *weights);
void sort_add_and_wgts_bicubic(size_t *src_add, double (&weights)[4][4]);
void sort_add_and_weights(size_t numWeights, size_t *src_add, double *weights);
void sort_add_and_4weights(size_t *src_add, double *weights);
void sort_add_and_weights_bicubic(size_t *src_add, double (&weights)[4][4]);
#endif /* REMAP_STORE_LINK */
Markdown is supported
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