Commit 0d2e877d authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Refactor sort_add_and_4wgts().

parent 78f68252
......@@ -325,7 +325,7 @@ remapBilinear(RemapSearch &rsearch, const double *restrict src_array, double *re
{
// Successfully found iw,jw - compute weights
bilinearSetWeights(iw, jw, wgts);
sort_add_and_wgts(4, src_add, wgts);
sort_add_and_4wgts(src_add, wgts);
tgt_array[tgt_cell_add] = bilinearRemap(src_array, wgts, src_add);
}
else
......@@ -345,7 +345,7 @@ remapBilinear(RemapSearch &rsearch, const double *restrict src_array, double *re
{
tgt_grid->cell_frac[tgt_cell_add] = 1.;
renormalizeWeights(src_lats, wgts);
sort_add_and_wgts(4, src_add, wgts);
sort_add_and_4wgts(src_add, wgts);
tgt_array[tgt_cell_add] = bilinearRemap(src_array, wgts, src_add);
}
}
......
......@@ -73,6 +73,32 @@ sortAddweights4(Addweight4 *addweights)
std::qsort(addweights, 4, sizeof(Addweight4), qcompareAdds4);
}
void
sort_add_and_4wgts(size_t *src_add, double *wgts)
{
constexpr size_t numWeights = 4;
size_t n;
for (n = 1; n < numWeights; ++n)
if (src_add[n] < src_add[n - 1]) break;
if (n == numWeights) return;
std::array<Addweight, numWeights> addweights;
for (n = 0; n < numWeights; ++n)
{
addweights[n].add = src_add[n];
addweights[n].weight = wgts[n];
}
std::sort(addweights.begin(), addweights.end(), compareAdds);
for (n = 0; n < numWeights; ++n)
{
src_add[n] = addweights[n].add;
wgts[n] = addweights[n].weight;
}
}
void
sort_add_and_wgts(size_t numWeights, size_t *src_add, double *wgts)
{
......
......@@ -56,6 +56,7 @@ void storeWeightLinks4(size_t *srch_add, double weights[4][4], size_t cell_add,
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 *wgts);
void sort_add_and_4wgts(size_t *src_add, double *wgts);
void sort_add_and_wgts_bic(size_t *src_add, double (&wgts)[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