From 704b9e03b99dd224e14499e9adf9b905bb0e1a4d Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Tue, 28 Feb 2023 22:01:42 -0600 Subject: [PATCH] Support TIME...MOT...LOC with motion between 0-255 knots NWSI 10-1701 specified 0-99 knots is valid, but sometimes text products are published with a larger value --- .../scwx/awips/coded_time_motion_location.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/wxdata/source/scwx/awips/coded_time_motion_location.cpp b/wxdata/source/scwx/awips/coded_time_motion_location.cpp index f5b5a4ab..5144e90a 100644 --- a/wxdata/source/scwx/awips/coded_time_motion_location.cpp +++ b/wxdata/source/scwx/awips/coded_time_motion_location.cpp @@ -39,7 +39,7 @@ CodedTimeMotionLocation::CodedTimeMotionLocation() : CodedTimeMotionLocation::~CodedTimeMotionLocation() = default; CodedTimeMotionLocation::CodedTimeMotionLocation( - CodedTimeMotionLocation&&) noexcept = default; + CodedTimeMotionLocation&&) noexcept = default; CodedTimeMotionLocation& CodedTimeMotionLocation::operator=( CodedTimeMotionLocation&&) noexcept = default; @@ -140,12 +140,23 @@ bool CodedTimeMotionLocation::Parse(const StringRange& lines, // Speed: KT std::string speed = tokenList.at(3); - if (speed.size() >= 3 && speed.size() <= 4 && speed.ends_with("KT")) + if (speed.size() >= 3 && speed.size() <= 5 && speed.ends_with("KT")) { try { - p->speed_ = static_cast( - std::stoul(speed.substr(0, speed.size() - 2))); + // NWSI 10-1701 specifies a valid speed range of 0-99 knots. + // However, sometimes text products are published with a larger + // value. Instead, allow a value up to 255 knots. + auto parsedSpeed = std::stoul(speed.substr(0, speed.size() - 2)); + if (parsedSpeed <= 255u) + { + p->speed_ = static_cast(parsedSpeed); + } + else + { + logger_->warn("Invalid speed: \"{}\"", speed); + dataValid = false; + } } catch (const std::exception& ex) {