Skip to content

Commit

Permalink
Add debug print code for modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
mpartio committed May 31, 2024
1 parent b1b6673 commit 9a5528a
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion himan-lib/source/modifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ using namespace himan::numerical_functions;
const double DEFAULT_MAXIMUM = 1e38;
const double DEFAULT_MINIMUM = -1e38;

#define DEBUG_PRINT
#ifdef DEBUG_PRINT
#define DEBUG_MSG(str) if (itsIndex == 24122) { do { std::cout << ClassName() << " " << str << std::endl; } while (false); }
#else
#define DEBUG_MSG(str) do { } while ( false )
#endif

const int PP = 24122;
double ExactEdgeValue(double theHeight, double theValue, double thePreviousHeight, double thePreviousValue,
double theLimit)
{
Expand Down Expand Up @@ -798,6 +806,8 @@ void modifier_findheight_gt::Calculate(double theValue, double theHeight, double
const double lowerLimit = itsLowerHeight[itsIndex];
const double upperLimit = itsUpperHeight[itsIndex];

DEBUG_MSG(fmt::format("H:{:.2f} ({:.2f}) V:{:.2f} ({:.2f}) [{:.2f},{:.2f}] threshold: {:.2f}", theHeight,
thePreviousHeight, theValue, thePreviousValue, lowerLimit, upperLimit, findValue));
// Check if we have just entered or just leaving a height zone
if (EnteringHeightZone(theHeight, thePreviousHeight, lowerLimit))
{
Expand Down Expand Up @@ -859,6 +869,7 @@ void modifier_findheight_gt::Calculate(double theValue, double theHeight, double
itsOutOfBoundHeights[itsIndex] = true;
}
}
DEBUG_MSG(fmt::format("Entered area and got height: {}", Value()));
}
// In area
else if (diff > 0 && pdiff > 0)
Expand Down Expand Up @@ -903,6 +914,8 @@ void modifier_findheight_gt::Calculate(double theValue, double theHeight, double
itsOutOfBoundHeights[itsIndex] = true;
}
}

DEBUG_MSG(fmt::format("Left area and got height: {}", Value()));
}
}

Expand Down Expand Up @@ -931,20 +944,27 @@ void modifier_findheight_lt::Calculate(double theValue, double theHeight, double

const double lowerLimit = itsLowerHeight[itsIndex];
const double upperLimit = itsUpperHeight[itsIndex];
const bool P = (itsIndex == PP); // 19286);

DEBUG_MSG(fmt::format("H:{:.2f} ({:.2f}) V:{:.2f} ({:.2f}) [{:.2f},{:.2f}] threshold: {:.2f}", theHeight,
thePreviousHeight, theValue, thePreviousValue, lowerLimit, upperLimit, findValue));

if (EnteringHeightZone(theHeight, thePreviousHeight, lowerLimit))
{
thePreviousValue = ExactEdgeValue(theHeight, theValue, thePreviousHeight, thePreviousValue, lowerLimit);
thePreviousHeight = lowerLimit;

DEBUG_MSG(fmt::format("Entered height zone, current lower edge values are: V={:.2f}, H={:.2f}", thePreviousValue,
thePreviousHeight));
// Lower edge might be valid, check it before moving to check current height

const double diff = thePreviousValue - findValue;

if (diff < 0 && fabs(diff) > std::numeric_limits<double>::epsilon())
{
if (P)
fmt::print("Found when entered height zone: {:.2f}\n", thePreviousHeight);
itsFoundNValues[itsIndex] += 1;

if (itsFindNthValue == itsFoundNValues[itsIndex])
{
Value(thePreviousHeight);
Expand Down Expand Up @@ -992,6 +1012,8 @@ void modifier_findheight_lt::Calculate(double theValue, double theHeight, double
itsOutOfBoundHeights[itsIndex] = true;
}
}

DEBUG_MSG("Entered area and got height: " << Value());
}
// In area
else if (diff < 0 && pdiff < 0)
Expand Down Expand Up @@ -1036,6 +1058,8 @@ void modifier_findheight_lt::Calculate(double theValue, double theHeight, double
itsOutOfBoundHeights[itsIndex] = true;
}
}

DEBUG_MSG("Left area and got height: " << Value());
}
}

Expand Down

0 comments on commit 9a5528a

Please sign in to comment.