Commit acd13a4c authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Cleaning up warnings and nomenclature in radixmath/interpolate.cc.

parent adf7b11d
Pipeline #35933 failed with stages
in 10 minutes and 33 seconds
......@@ -2,8 +2,8 @@
#include "radixbug/bug.hh"
#include <algorithm> // std::min
#include <cmath>
#include <algorithm> // std::min
namespace radix
{
......@@ -29,16 +29,16 @@ std::vector<T> interpolateValues(const std::vector<T> &baseValues,
// Ensure pressure and other vector are same length for interpolation
if (baseValues.size() != valuesToInterpolate.size())
{
radix_line("Error! Pressure vector is not same size ("
radix_line("Error! baseValues vector is not same size ("
<< baseValues.size() << ") as vector to interpolate ("
<< valuesToInterpolate.size() << ") - can't use to interpolate");
return std::vector<T>();
}
// Ensure we have no missing values in the pressure dataset
for (T pressure : baseValues)
// Ensure we have no missing values in the baseValue dataset
for (T value : baseValues)
{
if (pressure == missingValue)
if (std::fabs(value - missingValue) < T(1e-16))
{
radix_line("Error! Base vector contains missing ("
<< missingValue << ") values - can't use to interpolate");
......@@ -51,7 +51,7 @@ std::vector<T> interpolateValues(const std::vector<T> &baseValues,
bool foundFirst = false;
for (size_t i = 0; i < valuesToInterpolate.size(); ++i)
{
if (valuesToInterpolate[i] != missingValue)
if (std::fabs(valuesToInterpolate[i] - missingValue) > T(1e-16))
{
if (!foundFirst)
{
......@@ -80,10 +80,10 @@ std::vector<T> interpolateValues(const std::vector<T> &baseValues,
{
// Search for a missing value
size_t lastGood = i - 1;
if (valuesToInterpolate[i] == missingValue)
if (std::fabs(valuesToInterpolate[i] - missingValue) < T(1e-16))
{
// Get the next good value
while (valuesToInterpolate[i] == missingValue)
while (std::fabs(valuesToInterpolate[i] - missingValue) < T(1e-16))
{
i++;
}
......@@ -94,7 +94,7 @@ std::vector<T> interpolateValues(const std::vector<T> &baseValues,
T lastGoodValue = valuesToInterpolate[lastGood],
nextGoodValue = valuesToInterpolate[nextGood];
if (circular && fabs(lastGoodValue - nextGoodValue) > 180.0)
if (circular && std::fabs(lastGoodValue - nextGoodValue) > T(180.0))
{
radix_line(
" Circular interpolation with distance > 180 "
......@@ -116,7 +116,7 @@ std::vector<T> interpolateValues(const std::vector<T> &baseValues,
if (circular)
{
interpolatedValues[j] = fmod(interpolatedValues[j], 360.0);
interpolatedValues[j] = std::fmod(interpolatedValues[j], T(360.0));
}
}
}
......@@ -225,18 +225,18 @@ std::vector<T> interpolateToOtherBaseValues(
T lastGoodValue = initialInterpolatedValues[lowerBaseIndex],
nextGoodValue = initialInterpolatedValues[higherBaseIndex];
if (circular && fabs(lastGoodValue - nextGoodValue) > 180.0)
if (circular && std::fabs(lastGoodValue - nextGoodValue) > T(180.0))
{
radix_line(
" Circular interpolation with distance > 180 "
"degrees: performing correction");
if (lastGoodValue < nextGoodValue)
{
lastGoodValue += 360.0;
lastGoodValue += T(360.0);
}
else
{
nextGoodValue += 360.0;
nextGoodValue += T(360.0);
}
}
......@@ -257,7 +257,8 @@ std::vector<T> interpolateToOtherBaseValues(
if (circular)
{
finalInterpolatedValues[i] = fmod(finalInterpolatedValues[i], 360.0);
finalInterpolatedValues[i] =
std::fmod(finalInterpolatedValues[i], T(360.0));
}
// radix_line("interp: previous " << lastGoodValue << ", next "
// << nextGoodValue << ", result "
......@@ -267,16 +268,16 @@ std::vector<T> interpolateToOtherBaseValues(
radix_line("Interpolation to new base values complete");
radix_block(
radix(" Initial base values: ");
for (float f
for (T f
: baseValues) { radix(" " << f); } radix_line("");
radix(" Initial interpolated values: ");
for (float f
for (T f
: initialInterpolatedValues) { radix(" " << f); } radix_line("");
radix(" New base values: ");
for (float f
for (T f
: newBaseValues) { radix(" " << f); } radix_line("");
radix(" Final interpolated values: ");
for (float f
for (T f
: finalInterpolatedValues) { radix(" " << f); } radix_line(""););
return finalInterpolatedValues;
......
......@@ -14,13 +14,13 @@ namespace radix
template <typename T>
std::vector<T> RADIX_PUBLIC interpolateValues(
const std::vector<T> &baseValues, const std::vector<T> &valuesToInterpolate,
const bool circular = false, const T missingValue = -9999.f);
const bool circular = false, const T missingValue = T(-9999));
template <typename T>
std::vector<T> RADIX_PUBLIC interpolateToOtherBaseValues(
const std::vector<T> &baseValues, const std::vector<T> &newBaseValues,
const std::vector<T> &valuesToInterpolate, const bool circular = false,
const T missingValues = -9999.f);
const T missingValues = T(-9999));
} // namespace radix
......
Supports Markdown
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