mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 07:50:04 +00:00
Text product files
This commit is contained in:
parent
55d856a745
commit
e5c40b9eb5
7 changed files with 172 additions and 4 deletions
|
|
@ -1 +1 @@
|
||||||
Subproject commit c1d6d76c56f75d8f68b6d7dd8f223b0a199c6e36
|
Subproject commit 9d377550477ba00b9da3b594b838ba08d3ebcaaf
|
||||||
39
test/source/scwx/awips/text_product_file.test.cpp
Normal file
39
test/source/scwx/awips/text_product_file.test.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
#include <scwx/awips/text_product_file.hpp>
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <boost/log/trivial.hpp>
|
||||||
|
|
||||||
|
namespace scwx
|
||||||
|
{
|
||||||
|
namespace awips
|
||||||
|
{
|
||||||
|
|
||||||
|
static const std::string logPrefix_ = "[scwx::awips::text_product_file.test] ";
|
||||||
|
|
||||||
|
class TextProductValidFileTest : public testing::TestWithParam<std::string>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_P(TextProductValidFileTest, ValidFile)
|
||||||
|
{
|
||||||
|
TextProductFile file;
|
||||||
|
|
||||||
|
auto param = GetParam();
|
||||||
|
|
||||||
|
const std::string filename {std::string(SCWX_TEST_DATA_DIR) + param};
|
||||||
|
file.LoadFile(filename);
|
||||||
|
|
||||||
|
EXPECT_GT(file.message_count(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
|
TextProductFile,
|
||||||
|
TextProductValidFileTest,
|
||||||
|
testing::Values("/warnings/warnings_20210604_21.txt",
|
||||||
|
"/warnings/warnings_20210606_15.txt",
|
||||||
|
"/warnings/warnings_20210606_22-59.txt",
|
||||||
|
"/nexrad/level3/KLSX_NOUS63_FTMLSX_202201041404"));
|
||||||
|
|
||||||
|
} // namespace awips
|
||||||
|
} // namespace scwx
|
||||||
|
|
@ -7,12 +7,12 @@ namespace scwx
|
||||||
namespace wsr88d
|
namespace wsr88d
|
||||||
{
|
{
|
||||||
|
|
||||||
class ValidFileTest :
|
class Level3ValidFileTest :
|
||||||
public testing::TestWithParam<std::pair<int16_t, std::string>>
|
public testing::TestWithParam<std::pair<int16_t, std::string>>
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(ValidFileTest, ValidFile)
|
TEST_P(Level3ValidFileTest, ValidFile)
|
||||||
{
|
{
|
||||||
Level3File file;
|
Level3File file;
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ TEST_P(ValidFileTest, ValidFile)
|
||||||
|
|
||||||
INSTANTIATE_TEST_SUITE_P(
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
Level3File,
|
Level3File,
|
||||||
ValidFileTest,
|
Level3ValidFileTest,
|
||||||
testing::Values(
|
testing::Values(
|
||||||
std::pair<int16_t, std::string> {2, "KLSX_NXUS63_GSMLSX_202112110238"},
|
std::pair<int16_t, std::string> {2, "KLSX_NXUS63_GSMLSX_202112110238"},
|
||||||
std::pair<int16_t, std::string> {19, "KLSX_SDUS53_N0RLSX_202105041639"},
|
std::pair<int16_t, std::string> {19, "KLSX_SDUS53_N0RLSX_202105041639"},
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ find_package(BZip2)
|
||||||
find_package(GTest)
|
find_package(GTest)
|
||||||
|
|
||||||
set(SRC_MAIN source/scwx/wxtest.cpp)
|
set(SRC_MAIN source/scwx/wxtest.cpp)
|
||||||
|
set(SRC_AWIPS_TESTS source/scwx/awips/text_product_file.test.cpp)
|
||||||
set(SRC_COMMON_TESTS source/scwx/common/color_table.test.cpp)
|
set(SRC_COMMON_TESTS source/scwx/common/color_table.test.cpp)
|
||||||
set(SRC_QT_MANAGER_TESTS source/scwx/qt/manager/settings_manager.test.cpp)
|
set(SRC_QT_MANAGER_TESTS source/scwx/qt/manager/settings_manager.test.cpp)
|
||||||
set(SRC_UTIL_TESTS source/scwx/util/rangebuf.test.cpp
|
set(SRC_UTIL_TESTS source/scwx/util/rangebuf.test.cpp
|
||||||
|
|
@ -17,12 +18,14 @@ set(SRC_WSR88D_TESTS source/scwx/wsr88d/ar2v_file.test.cpp
|
||||||
source/scwx/wsr88d/level3_file.test.cpp)
|
source/scwx/wsr88d/level3_file.test.cpp)
|
||||||
|
|
||||||
add_executable(wxtest ${SRC_MAIN}
|
add_executable(wxtest ${SRC_MAIN}
|
||||||
|
${SRC_AWIPS_TESTS}
|
||||||
${SRC_COMMON_TESTS}
|
${SRC_COMMON_TESTS}
|
||||||
${SRC_QT_MANAGER_TESTS}
|
${SRC_QT_MANAGER_TESTS}
|
||||||
${SRC_UTIL_TESTS}
|
${SRC_UTIL_TESTS}
|
||||||
${SRC_WSR88D_TESTS})
|
${SRC_WSR88D_TESTS})
|
||||||
|
|
||||||
source_group("Source Files\\main" FILES ${SRC_MAIN})
|
source_group("Source Files\\main" FILES ${SRC_MAIN})
|
||||||
|
source_group("Source Files\\awips" FILES ${SRC_AWIPS_TESTS})
|
||||||
source_group("Source Files\\common" FILES ${SRC_COMMON_TESTS})
|
source_group("Source Files\\common" FILES ${SRC_COMMON_TESTS})
|
||||||
source_group("Source Files\\qt\\manager" FILES ${SRC_QT_MANAGER_TESTS})
|
source_group("Source Files\\qt\\manager" FILES ${SRC_QT_MANAGER_TESTS})
|
||||||
source_group("Source Files\\util" FILES ${SRC_UTIL_TESTS})
|
source_group("Source Files\\util" FILES ${SRC_UTIL_TESTS})
|
||||||
|
|
|
||||||
38
wxdata/include/scwx/awips/text_product_file.hpp
Normal file
38
wxdata/include/scwx/awips/text_product_file.hpp
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <scwx/awips/text_product_message.hpp>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace scwx
|
||||||
|
{
|
||||||
|
namespace awips
|
||||||
|
{
|
||||||
|
|
||||||
|
class TextProductFileImpl;
|
||||||
|
|
||||||
|
class TextProductFile
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit TextProductFile();
|
||||||
|
~TextProductFile();
|
||||||
|
|
||||||
|
TextProductFile(const TextProductFile&) = delete;
|
||||||
|
TextProductFile& operator=(const TextProductFile&) = delete;
|
||||||
|
|
||||||
|
TextProductFile(TextProductFile&&) noexcept;
|
||||||
|
TextProductFile& operator=(TextProductFile&&) noexcept;
|
||||||
|
|
||||||
|
size_t message_count() const;
|
||||||
|
std::shared_ptr<TextProductMessage> message(size_t i) const;
|
||||||
|
|
||||||
|
bool LoadFile(const std::string& filename);
|
||||||
|
bool LoadData(std::istream& is);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<TextProductFileImpl> p;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace awips
|
||||||
|
} // namespace scwx
|
||||||
86
wxdata/source/scwx/awips/text_product_file.cpp
Normal file
86
wxdata/source/scwx/awips/text_product_file.cpp
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
#include <scwx/awips/text_product_file.hpp>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <boost/log/trivial.hpp>
|
||||||
|
|
||||||
|
namespace scwx
|
||||||
|
{
|
||||||
|
namespace awips
|
||||||
|
{
|
||||||
|
|
||||||
|
static const std::string logPrefix_ = "[scwx::awips::text_product_file] ";
|
||||||
|
|
||||||
|
class TextProductFileImpl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit TextProductFileImpl() : messages_ {} {};
|
||||||
|
~TextProductFileImpl() = default;
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<TextProductMessage>> messages_;
|
||||||
|
};
|
||||||
|
|
||||||
|
TextProductFile::TextProductFile() : p(std::make_unique<TextProductFileImpl>())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
TextProductFile::~TextProductFile() = default;
|
||||||
|
|
||||||
|
TextProductFile::TextProductFile(TextProductFile&&) noexcept = default;
|
||||||
|
TextProductFile&
|
||||||
|
TextProductFile::operator=(TextProductFile&&) noexcept = default;
|
||||||
|
|
||||||
|
size_t TextProductFile::message_count() const
|
||||||
|
{
|
||||||
|
return p->messages_.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<TextProductMessage> TextProductFile::message(size_t i) const
|
||||||
|
{
|
||||||
|
return p->messages_[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TextProductFile::LoadFile(const std::string& filename)
|
||||||
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "LoadFile(" << filename << ")";
|
||||||
|
bool fileValid = true;
|
||||||
|
|
||||||
|
std::ifstream f(filename, std::ios_base::in | std::ios_base::binary);
|
||||||
|
if (!f.good())
|
||||||
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(warning)
|
||||||
|
<< logPrefix_ << "Could not open file for reading: " << filename;
|
||||||
|
fileValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileValid)
|
||||||
|
{
|
||||||
|
fileValid = LoadData(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TextProductFile::LoadData(std::istream& is)
|
||||||
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Loading Data";
|
||||||
|
|
||||||
|
while (!is.eof())
|
||||||
|
{
|
||||||
|
std::shared_ptr<TextProductMessage> message =
|
||||||
|
TextProductMessage::Create(is);
|
||||||
|
|
||||||
|
if (message != nullptr)
|
||||||
|
{
|
||||||
|
p->messages_.push_back(message);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return !p->messages_.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace awips
|
||||||
|
} // namespace scwx
|
||||||
|
|
@ -3,9 +3,11 @@ project(scwx-data)
|
||||||
find_package(Boost)
|
find_package(Boost)
|
||||||
|
|
||||||
set(HDR_AWIPS include/scwx/awips/message.hpp
|
set(HDR_AWIPS include/scwx/awips/message.hpp
|
||||||
|
include/scwx/awips/text_product_file.hpp
|
||||||
include/scwx/awips/text_product_message.hpp
|
include/scwx/awips/text_product_message.hpp
|
||||||
include/scwx/awips/wmo_header.hpp)
|
include/scwx/awips/wmo_header.hpp)
|
||||||
set(SRC_AWIPS source/scwx/awips/message.cpp
|
set(SRC_AWIPS source/scwx/awips/message.cpp
|
||||||
|
source/scwx/awips/text_product_file.cpp
|
||||||
source/scwx/awips/text_product_message.cpp
|
source/scwx/awips/text_product_message.cpp
|
||||||
source/scwx/awips/wmo_header.cpp)
|
source/scwx/awips/wmo_header.cpp)
|
||||||
set(HDR_COMMON include/scwx/common/characters.hpp
|
set(HDR_COMMON include/scwx/common/characters.hpp
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue