diff --git a/opm/io/eclipse/OutputStream.hpp b/opm/io/eclipse/OutputStream.hpp index 906e4ffa7..04e57379e 100644 --- a/opm/io/eclipse/OutputStream.hpp +++ b/opm/io/eclipse/OutputStream.hpp @@ -276,6 +276,87 @@ namespace Opm { namespace EclIO { namespace OutputStream { const std::vector& data); }; + /// File manager for RFT output streams + class RFT + { + public: + struct OpenExisting { bool set; }; + + /// Constructor. + /// + /// Opens file stream for writing. + /// + /// \param[in] rset Output directory and base name of output stream. + /// + /// \param[in] fmt Whether or not to create formatted output files. + /// + /// \param[in] existing Whether or not to open an existing output file. + explicit RFT(const ResultSet& rset, + const Formatted& fmt, + const OpenExisting& existing); + + ~RFT(); + + RFT(const RFT& rhs) = delete; + RFT(RFT&& rhs); + + RFT& operator=(const RFT& rhs) = delete; + RFT& operator=(RFT&& rhs); + + /// Write integer data to underlying output stream. + /// + /// \param[in] kw Name of output vector (keyword). + /// + /// \param[in] data Output values. + void write(const std::string& kw, + const std::vector& data); + + /// Write single precision floating point data to underlying + /// output stream. + /// + /// \param[in] kw Name of output vector (keyword). + /// + /// \param[in] data Output values. + void write(const std::string& kw, + const std::vector& data); + + /// Write padded character data (8 characters per string) + /// to underlying output stream. + /// + /// \param[in] kw Name of output vector (keyword). + /// + /// \param[in] data Output values. + void write(const std::string& kw, + const std::vector>& data); + + private: + /// Init file output stream. + std::unique_ptr stream_; + + /// Open output stream. + /// + /// Writes to \c stream_. + /// + /// \param[in] fname Filename of new output stream. + /// + /// \param[in] formatted Whether or not to create a + /// formatted output file. + /// + /// \param[in] existing Whether or not to open an + /// existing output file (mode ios_base::app). + void open(const std::string& fname, + const bool formatted, + const bool existing); + + /// Access writable output stream. + EclOutput& stream(); + + /// Implementation function for public \c write overload set. + template + void writeImpl(const std::string& kw, + const std::vector& data); + }; + /// Derive filename corresponding to output stream of particular result /// set, with user-specified file extension. /// diff --git a/src/opm/io/eclipse/OutputStream.cpp b/src/opm/io/eclipse/OutputStream.cpp index 8595a4527..0eb7f2861 100644 --- a/src/opm/io/eclipse/OutputStream.cpp +++ b/src/opm/io/eclipse/OutputStream.cpp @@ -59,6 +59,11 @@ namespace { return ext.str(); } + + std::string rft(const bool formatted) + { + return formatted ? "FRFT" : "RFT"; + } } // namespace FileExtension namespace Open @@ -128,6 +133,31 @@ namespace { }; } } // namespace Restart + + namespace Rft + { + std::unique_ptr + writeNew(const std::string& filename, + const bool isFmt) + { + return std::unique_ptr { + new Opm::EclIO::EclOutput { + filename, isFmt, std::ios_base::out + } + }; + } + + std::unique_ptr + writeExisting(const std::string& filename, + const bool isFmt) + { + return std::unique_ptr { + new Opm::EclIO::EclOutput { + filename, isFmt, std::ios_base::app + } + }; + } + } // namespace Rft } // namespace Open } // Anonymous namespace @@ -396,6 +426,84 @@ namespace Opm { namespace EclIO { namespace OutputStream { }}} +// ===================================================================== + +Opm::EclIO::OutputStream::RFT:: +RFT(const ResultSet& rset, + const Formatted& fmt, + const OpenExisting& existing) +{ + const auto fname = outputFileName(rset, FileExtension::rft(fmt.set)); + + this->open(fname, fmt.set, existing.set); +} + +Opm::EclIO::OutputStream::RFT::~RFT() +{} + +Opm::EclIO::OutputStream::RFT::RFT(RFT&& rhs) + : stream_{ std::move(rhs.stream_) } +{} + +Opm::EclIO::OutputStream::RFT& +Opm::EclIO::OutputStream::RFT::operator=(RFT&& rhs) +{ + this->stream_ = std::move(rhs.stream_); + + return *this; +} + +void +Opm::EclIO::OutputStream::RFT:: +write(const std::string& kw, const std::vector& data) +{ + this->writeImpl(kw, data); +} + +void +Opm::EclIO::OutputStream::RFT:: +write(const std::string& kw, const std::vector& data) +{ + this->writeImpl(kw, data); +} + +void +Opm::EclIO::OutputStream::RFT:: +write(const std::string& kw, + const std::vector>& data) +{ + this->writeImpl(kw, data); +} + +void +Opm::EclIO::OutputStream::RFT:: +open(const std::string& fname, + const bool formatted, + const bool existing) +{ + this->stream_ = existing + ? Open::Rft::writeExisting(fname, formatted) + : Open::Rft::writeNew (fname, formatted); +} + +Opm::EclIO::EclOutput& +Opm::EclIO::OutputStream::RFT::stream() +{ + return *this->stream_; +} + +namespace Opm { namespace EclIO { namespace OutputStream { + + template + void RFT::writeImpl(const std::string& kw, + const std::vector& data) + { + this->stream().write(kw, data); + } + +}}} // namespace Opm::EclIO::OutputStream + +// ===================================================================== std::string Opm::EclIO::OutputStream::outputFileName(const ResultSet& rsetDescriptor, diff --git a/tests/test_OutputStream.cpp b/tests/test_OutputStream.cpp index 3043a58f3..23eeee292 100644 --- a/tests/test_OutputStream.cpp +++ b/tests/test_OutputStream.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -1085,3 +1086,647 @@ BOOST_AUTO_TEST_CASE(Formatted_Separate) } BOOST_AUTO_TEST_SUITE_END() // Class_Restart + +// ========================================================================== + +BOOST_AUTO_TEST_SUITE(Class_RFT) + +BOOST_AUTO_TEST_CASE(Unformatted_New) +{ + using Char8 = ::Opm::EclIO::PaddedOutputString<8>; + + const auto rset = RSet("CASE"); + const auto fmt = ::Opm::EclIO::OutputStream::Formatted{ false }; + const auto exist = ::Opm::EclIO::OutputStream::RFT::OpenExisting{ false }; + + { + auto rft = ::Opm::EclIO::OutputStream::RFT { + rset, fmt, exist + }; + + rft.write("I", std::vector {1, 7, 2, 9}); + rft.write("S", std::vector {3.1f, 4.1f, 59.265f}); + rft.write("Z", std::vector { + Char8{" Hello "}, Char8{" World "} + }); + } + + { + const auto fname = ::Opm::EclIO::OutputStream:: + outputFileName(rset, "RFT"); + + auto rft = ::Opm::EclIO::EclFile{fname}; + + BOOST_CHECK(rft.hasKey("I")); + BOOST_CHECK(rft.hasKey("S")); + BOOST_CHECK(rft.hasKey("Z")); + BOOST_CHECK(!rft.hasKey("C")); + + { + const auto vectors = rft.getList(); + const auto expect_vectors = std::vector{ + Opm::EclIO::EclFile::EclEntry{"I", Opm::EclIO::eclArrType::INTE, 4}, + Opm::EclIO::EclFile::EclEntry{"S", Opm::EclIO::eclArrType::REAL, 3}, + Opm::EclIO::EclFile::EclEntry{"Z", Opm::EclIO::eclArrType::CHAR, 2}, + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(vectors.begin(), vectors.end(), + expect_vectors.begin(), + expect_vectors.end()); + } + + rft.loadData(); + + { + const auto& I = rft.get("I"); + const auto expect_I = std::vector{ 1, 7, 2, 9 }; + BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(), + expect_I.begin(), + expect_I.end()); + } + + { + const auto& S = rft.get("S"); + const auto expect_S = std::vector{ + 3.1f, 4.1f, 59.265f, + }; + + check_is_close(S, expect_S); + } + + { + const auto& Z = rft.get("Z"); + const auto expect_Z = std::vector{ + " Hello", " World" // Trailing blanks trimmed + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(), + expect_Z.begin(), expect_Z.end()); + } + } + + { + auto rft = ::Opm::EclIO::OutputStream::RFT { + rset, fmt, exist + }; + + rft.write("I2", std::vector {11, 22, 33}); + rft.write("S2", std::vector {2.71f, 828.1f, 8.218f}); + rft.write("Z2", std::vector { + Char8{"Good B"}, Char8{" ye"}, Char8{ "W0rlD" }, + }); + } + + { + const auto fname = ::Opm::EclIO::OutputStream:: + outputFileName(rset, "RFT"); + + auto rft = ::Opm::EclIO::EclFile{fname}; + + BOOST_CHECK(!rft.hasKey("I")); + BOOST_CHECK(!rft.hasKey("S")); + BOOST_CHECK(!rft.hasKey("Z")); + + BOOST_CHECK(rft.hasKey("I2")); + BOOST_CHECK(rft.hasKey("S2")); + BOOST_CHECK(rft.hasKey("Z2")); + + { + const auto vectors = rft.getList(); + const auto expect_vectors = std::vector{ + Opm::EclIO::EclFile::EclEntry{"I2", Opm::EclIO::eclArrType::INTE, 3}, + Opm::EclIO::EclFile::EclEntry{"S2", Opm::EclIO::eclArrType::REAL, 3}, + Opm::EclIO::EclFile::EclEntry{"Z2", Opm::EclIO::eclArrType::CHAR, 3}, + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(vectors.begin(), vectors.end(), + expect_vectors.begin(), + expect_vectors.end()); + } + + rft.loadData(); + + { + const auto& I = rft.get("I2"); + const auto expect_I = std::vector{ 11, 22, 33 }; + BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(), + expect_I.begin(), + expect_I.end()); + } + + { + const auto& S = rft.get("S2"); + const auto expect_S = std::vector{ + 2.71f, 828.1f, 8.218f, + }; + + check_is_close(S, expect_S); + } + + { + const auto& Z = rft.get("Z2"); + const auto expect_Z = std::vector{ + "Good B", " ye", "W0rlD" + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(), + expect_Z.begin(), expect_Z.end()); + } + } +} + +BOOST_AUTO_TEST_CASE(Unformatted_Existing) +{ + using Char8 = ::Opm::EclIO::PaddedOutputString<8>; + + const auto rset = RSet("CASE"); + const auto fmt = ::Opm::EclIO::OutputStream::Formatted{ false }; + const auto exist = ::Opm::EclIO::OutputStream::RFT::OpenExisting{ true }; + + { + auto rft = ::Opm::EclIO::OutputStream::RFT { + rset, fmt, exist + }; + + rft.write("I", std::vector {1, 7, 2, 9}); + rft.write("S", std::vector {3.1f, 4.1f, 59.265f}); + rft.write("Z", std::vector { + Char8{" Hello "}, Char8{" World "} + }); + } + + { + const auto fname = ::Opm::EclIO::OutputStream:: + outputFileName(rset, "RFT"); + + auto rft = ::Opm::EclIO::EclFile{fname}; + + BOOST_CHECK(rft.hasKey("I")); + BOOST_CHECK(rft.hasKey("S")); + BOOST_CHECK(rft.hasKey("Z")); + + BOOST_CHECK(!rft.hasKey("C")); + + { + const auto vectors = rft.getList(); + const auto expect_vectors = std::vector{ + Opm::EclIO::EclFile::EclEntry{"I", Opm::EclIO::eclArrType::INTE, 4}, + Opm::EclIO::EclFile::EclEntry{"S", Opm::EclIO::eclArrType::REAL, 3}, + Opm::EclIO::EclFile::EclEntry{"Z", Opm::EclIO::eclArrType::CHAR, 2}, + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(vectors.begin(), vectors.end(), + expect_vectors.begin(), + expect_vectors.end()); + } + + rft.loadData(); + + { + const auto& I = rft.get("I"); + const auto expect_I = std::vector{ 1, 7, 2, 9 }; + BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(), + expect_I.begin(), + expect_I.end()); + } + + { + const auto& S = rft.get("S"); + const auto expect_S = std::vector{ + 3.1f, 4.1f, 59.265f, + }; + + check_is_close(S, expect_S); + } + + { + const auto& Z = rft.get("Z"); + const auto expect_Z = std::vector{ + " Hello", " World" // Trailing blanks trimmed + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(), + expect_Z.begin(), expect_Z.end()); + } + } + + { + auto rft = ::Opm::EclIO::OutputStream::RFT { + rset, fmt, exist + }; + + rft.write("I2", std::vector {11, 22, 33}); + rft.write("S2", std::vector {2.71f, 828.1f, 8.218f}); + rft.write("Z2", std::vector { + Char8{"Good B"}, Char8{" ye"}, Char8{ "W0rlD" }, + }); + } + + { + const auto fname = ::Opm::EclIO::OutputStream:: + outputFileName(rset, "RFT"); + + auto rft = ::Opm::EclIO::EclFile{fname}; + + BOOST_CHECK(rft.hasKey("I")); + BOOST_CHECK(rft.hasKey("S")); + BOOST_CHECK(rft.hasKey("Z")); + BOOST_CHECK(rft.hasKey("I2")); + BOOST_CHECK(rft.hasKey("S2")); + BOOST_CHECK(rft.hasKey("Z2")); + + BOOST_CHECK(!rft.hasKey("C")); + + { + const auto vectors = rft.getList(); + const auto expect_vectors = std::vector{ + Opm::EclIO::EclFile::EclEntry{"I", Opm::EclIO::eclArrType::INTE, 4}, + Opm::EclIO::EclFile::EclEntry{"S", Opm::EclIO::eclArrType::REAL, 3}, + Opm::EclIO::EclFile::EclEntry{"Z", Opm::EclIO::eclArrType::CHAR, 2}, + Opm::EclIO::EclFile::EclEntry{"I2", Opm::EclIO::eclArrType::INTE, 3}, + Opm::EclIO::EclFile::EclEntry{"S2", Opm::EclIO::eclArrType::REAL, 3}, + Opm::EclIO::EclFile::EclEntry{"Z2", Opm::EclIO::eclArrType::CHAR, 3}, + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(vectors.begin(), vectors.end(), + expect_vectors.begin(), + expect_vectors.end()); + } + + rft.loadData(); + + { + const auto& I = rft.get("I"); + const auto expect_I = std::vector{ 1, 7, 2, 9 }; + BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(), + expect_I.begin(), + expect_I.end()); + } + + { + const auto& S = rft.get("S"); + const auto expect_S = std::vector{ + 3.1f, 4.1f, 59.265f, + }; + + check_is_close(S, expect_S); + } + + { + const auto& Z = rft.get("Z"); + const auto expect_Z = std::vector{ + " Hello", " World" // Trailing blanks trimmed + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(), + expect_Z.begin(), expect_Z.end()); + } + { + const auto& I = rft.get("I2"); + const auto expect_I = std::vector{ 11, 22, 33 }; + BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(), + expect_I.begin(), + expect_I.end()); + } + + { + const auto& S = rft.get("S2"); + const auto expect_S = std::vector{ + 2.71f, 828.1f, 8.218f, + }; + + check_is_close(S, expect_S); + } + + { + const auto& Z = rft.get("Z2"); + const auto expect_Z = std::vector{ + "Good B", " ye", "W0rlD" + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(), + expect_Z.begin(), expect_Z.end()); + } + } +} + +BOOST_AUTO_TEST_CASE(Formatted_New) +{ + using Char8 = ::Opm::EclIO::PaddedOutputString<8>; + + const auto rset = RSet("CASE"); + const auto fmt = ::Opm::EclIO::OutputStream::Formatted{ true }; + const auto exist = ::Opm::EclIO::OutputStream::RFT::OpenExisting{ false }; + + { + auto rft = ::Opm::EclIO::OutputStream::RFT { + rset, fmt, exist + }; + + rft.write("I", std::vector {1, 7, 2, 9}); + rft.write("S", std::vector {3.1f, 4.1f, 59.265f}); + rft.write("Z", std::vector { + Char8{" Hello "}, Char8{" World "} + }); + } + + { + const auto fname = ::Opm::EclIO::OutputStream:: + outputFileName(rset, "FRFT"); + + auto rft = ::Opm::EclIO::EclFile{fname}; + + BOOST_CHECK(rft.hasKey("I")); + BOOST_CHECK(rft.hasKey("S")); + BOOST_CHECK(rft.hasKey("Z")); + BOOST_CHECK(!rft.hasKey("C")); + + { + const auto vectors = rft.getList(); + const auto expect_vectors = std::vector{ + Opm::EclIO::EclFile::EclEntry{"I", Opm::EclIO::eclArrType::INTE, 4}, + Opm::EclIO::EclFile::EclEntry{"S", Opm::EclIO::eclArrType::REAL, 3}, + Opm::EclIO::EclFile::EclEntry{"Z", Opm::EclIO::eclArrType::CHAR, 2}, + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(vectors.begin(), vectors.end(), + expect_vectors.begin(), + expect_vectors.end()); + } + + rft.loadData(); + + { + const auto& I = rft.get("I"); + const auto expect_I = std::vector{ 1, 7, 2, 9 }; + BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(), + expect_I.begin(), + expect_I.end()); + } + + { + const auto& S = rft.get("S"); + const auto expect_S = std::vector{ + 3.1f, 4.1f, 59.265f, + }; + + check_is_close(S, expect_S); + } + + { + const auto& Z = rft.get("Z"); + const auto expect_Z = std::vector{ + " Hello", " World" // Trailing blanks trimmed + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(), + expect_Z.begin(), expect_Z.end()); + } + } + + { + auto rft = ::Opm::EclIO::OutputStream::RFT { + rset, fmt, exist + }; + + rft.write("I2", std::vector {11, 22, 33}); + rft.write("S2", std::vector {2.71f, 828.1f, 8.218f}); + rft.write("Z2", std::vector { + Char8{"Good B"}, Char8{" ye"}, Char8{ "W0rlD" }, + }); + } + + { + const auto fname = ::Opm::EclIO::OutputStream:: + outputFileName(rset, "FRFT"); + + auto rft = ::Opm::EclIO::EclFile{fname}; + + BOOST_CHECK(!rft.hasKey("I")); + BOOST_CHECK(!rft.hasKey("S")); + BOOST_CHECK(!rft.hasKey("Z")); + + BOOST_CHECK(rft.hasKey("I2")); + BOOST_CHECK(rft.hasKey("S2")); + BOOST_CHECK(rft.hasKey("Z2")); + + { + const auto vectors = rft.getList(); + const auto expect_vectors = std::vector{ + Opm::EclIO::EclFile::EclEntry{"I2", Opm::EclIO::eclArrType::INTE, 3}, + Opm::EclIO::EclFile::EclEntry{"S2", Opm::EclIO::eclArrType::REAL, 3}, + Opm::EclIO::EclFile::EclEntry{"Z2", Opm::EclIO::eclArrType::CHAR, 3}, + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(vectors.begin(), vectors.end(), + expect_vectors.begin(), + expect_vectors.end()); + } + + rft.loadData(); + + { + const auto& I = rft.get("I2"); + const auto expect_I = std::vector{ 11, 22, 33 }; + BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(), + expect_I.begin(), + expect_I.end()); + } + + { + const auto& S = rft.get("S2"); + const auto expect_S = std::vector{ + 2.71f, 828.1f, 8.218f, + }; + + check_is_close(S, expect_S); + } + + { + const auto& Z = rft.get("Z2"); + const auto expect_Z = std::vector{ + "Good B", " ye", "W0rlD" + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(), + expect_Z.begin(), expect_Z.end()); + } + } +} + +BOOST_AUTO_TEST_CASE(Formatted_Existing) +{ + using Char8 = ::Opm::EclIO::PaddedOutputString<8>; + + const auto rset = RSet("CASE"); + const auto fmt = ::Opm::EclIO::OutputStream::Formatted{ true }; + const auto exist = ::Opm::EclIO::OutputStream::RFT::OpenExisting{ true }; + + { + auto rft = ::Opm::EclIO::OutputStream::RFT { + rset, fmt, exist + }; + + rft.write("I", std::vector {1, 7, 2, 9}); + rft.write("S", std::vector {3.1f, 4.1f, 59.265f}); + rft.write("Z", std::vector { + Char8{" Hello "}, Char8{" World "} + }); + } + + { + const auto fname = ::Opm::EclIO::OutputStream:: + outputFileName(rset, "FRFT"); + + auto rft = ::Opm::EclIO::EclFile{fname}; + + BOOST_CHECK(rft.hasKey("I")); + BOOST_CHECK(rft.hasKey("S")); + BOOST_CHECK(rft.hasKey("Z")); + + BOOST_CHECK(!rft.hasKey("C")); + + { + const auto vectors = rft.getList(); + const auto expect_vectors = std::vector{ + Opm::EclIO::EclFile::EclEntry{"I", Opm::EclIO::eclArrType::INTE, 4}, + Opm::EclIO::EclFile::EclEntry{"S", Opm::EclIO::eclArrType::REAL, 3}, + Opm::EclIO::EclFile::EclEntry{"Z", Opm::EclIO::eclArrType::CHAR, 2}, + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(vectors.begin(), vectors.end(), + expect_vectors.begin(), + expect_vectors.end()); + } + + rft.loadData(); + + { + const auto& I = rft.get("I"); + const auto expect_I = std::vector{ 1, 7, 2, 9 }; + BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(), + expect_I.begin(), + expect_I.end()); + } + + { + const auto& S = rft.get("S"); + const auto expect_S = std::vector{ + 3.1f, 4.1f, 59.265f, + }; + + check_is_close(S, expect_S); + } + + { + const auto& Z = rft.get("Z"); + const auto expect_Z = std::vector{ + " Hello", " World" // Trailing blanks trimmed + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(), + expect_Z.begin(), expect_Z.end()); + } + } + + { + auto rft = ::Opm::EclIO::OutputStream::RFT { + rset, fmt, exist + }; + + rft.write("I2", std::vector {11, 22, 33}); + rft.write("S2", std::vector {2.71f, 828.1f, 8.218f}); + rft.write("Z2", std::vector { + Char8{"Good B"}, Char8{" ye"}, Char8{ "W0rlD" }, + }); + } + + { + const auto fname = ::Opm::EclIO::OutputStream:: + outputFileName(rset, "FRFT"); + + auto rft = ::Opm::EclIO::EclFile{fname}; + + BOOST_CHECK(rft.hasKey("I")); + BOOST_CHECK(rft.hasKey("S")); + BOOST_CHECK(rft.hasKey("Z")); + BOOST_CHECK(rft.hasKey("I2")); + BOOST_CHECK(rft.hasKey("S2")); + BOOST_CHECK(rft.hasKey("Z2")); + + BOOST_CHECK(!rft.hasKey("C")); + + { + const auto vectors = rft.getList(); + const auto expect_vectors = std::vector{ + Opm::EclIO::EclFile::EclEntry{"I", Opm::EclIO::eclArrType::INTE, 4}, + Opm::EclIO::EclFile::EclEntry{"S", Opm::EclIO::eclArrType::REAL, 3}, + Opm::EclIO::EclFile::EclEntry{"Z", Opm::EclIO::eclArrType::CHAR, 2}, + Opm::EclIO::EclFile::EclEntry{"I2", Opm::EclIO::eclArrType::INTE, 3}, + Opm::EclIO::EclFile::EclEntry{"S2", Opm::EclIO::eclArrType::REAL, 3}, + Opm::EclIO::EclFile::EclEntry{"Z2", Opm::EclIO::eclArrType::CHAR, 3}, + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(vectors.begin(), vectors.end(), + expect_vectors.begin(), + expect_vectors.end()); + } + + rft.loadData(); + + { + const auto& I = rft.get("I"); + const auto expect_I = std::vector{ 1, 7, 2, 9 }; + BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(), + expect_I.begin(), + expect_I.end()); + } + + { + const auto& S = rft.get("S"); + const auto expect_S = std::vector{ + 3.1f, 4.1f, 59.265f, + }; + + check_is_close(S, expect_S); + } + + { + const auto& Z = rft.get("Z"); + const auto expect_Z = std::vector{ + " Hello", " World" // Trailing blanks trimmed + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(), + expect_Z.begin(), expect_Z.end()); + } + { + const auto& I = rft.get("I2"); + const auto expect_I = std::vector{ 11, 22, 33 }; + BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(), + expect_I.begin(), + expect_I.end()); + } + + { + const auto& S = rft.get("S2"); + const auto expect_S = std::vector{ + 2.71f, 828.1f, 8.218f, + }; + + check_is_close(S, expect_S); + } + + { + const auto& Z = rft.get("Z2"); + const auto expect_Z = std::vector{ + "Good B", " ye", "W0rlD" + }; + + BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(), + expect_Z.begin(), expect_Z.end()); + } + } +} + +BOOST_AUTO_TEST_SUITE_END() // Class_RFT