diff --git a/opm/io/eclipse/EclFile.hpp b/opm/io/eclipse/EclFile.hpp index 0d5136410..18eb6bb0c 100644 --- a/opm/io/eclipse/EclFile.hpp +++ b/opm/io/eclipse/EclFile.hpp @@ -35,7 +35,12 @@ namespace Opm { namespace EclIO { class EclFile { public: + struct Formatted { + bool value; + }; + explicit EclFile(const std::string& filename, bool preload = false); + EclFile(const std::string& filename, Formatted fmt, bool preload = false); bool formattedInput() const { return formatted; } void loadData(); // load all data @@ -114,6 +119,7 @@ private: void loadBinaryArray(std::fstream& fileH, std::size_t arrIndex); void loadFormattedArray(const std::string& fileStr, std::size_t arrIndex, int64_t fromPos); + void load(bool preload); std::vector get_bin_logi_raw_values(int arrIndex) const; std::vector get_fmt_real_raw_str_values(int arrIndex) const; diff --git a/src/opm/io/eclipse/EclFile.cpp b/src/opm/io/eclipse/EclFile.cpp index 2e5fa732a..5a733878e 100644 --- a/src/opm/io/eclipse/EclFile.cpp +++ b/src/opm/io/eclipse/EclFile.cpp @@ -38,23 +38,17 @@ namespace Opm { namespace EclIO { -EclFile::EclFile(const std::string& filename, bool preload) : inputFilename(filename) -{ - if (!fileExists(filename)) - throw std::runtime_error(fmt::format("Can not open EclFile: {}", filename)); - +void EclFile::load(bool preload) { std::fstream fileH; - formatted = isFormatted(filename); - if (formatted) { - fileH.open(filename, std::ios::in); + fileH.open(this->inputFilename, std::ios::in); } else { - fileH.open(filename, std::ios::in | std::ios::binary); + fileH.open(this->inputFilename, std::ios::in | std::ios::binary); } if (!fileH) - throw std::runtime_error(fmt::format("Can not open EclFile: {}", filename)); + throw std::runtime_error(fmt::format("Can not open EclFile: {}", this->inputFilename)); int n = 0; while (!isEOF(&fileH)) { @@ -103,6 +97,25 @@ EclFile::EclFile(const std::string& filename, bool preload) : inputFilename(file } +EclFile::EclFile(const std::string& filename, EclFile::Formatted fmt, bool preload) : + formatted(fmt.value), + inputFilename(filename) +{ + this->load(preload); +} + + +EclFile::EclFile(const std::string& filename, bool preload) : + inputFilename(filename) +{ + if (!fileExists(filename)) + throw std::runtime_error(fmt::format("Can not open EclFile: {}", filename)); + + formatted = isFormatted(filename); + this->load(preload); +} + + void EclFile::loadBinaryArray(std::fstream& fileH, std::size_t arrIndex) { fileH.seekg (ifStreamPos[arrIndex], fileH.beg);