Replace windows path separators in GDFILE keyword
This commit is contained in:
@@ -28,7 +28,7 @@ class TestEclFile(unittest.TestCase):
|
|||||||
"PERMX","PERMY", "PERMZ","NTG","TRANX","TRANY","TRANZ","TABDIMS","TAB",
|
"PERMX","PERMY", "PERMZ","NTG","TRANX","TRANY","TRANZ","TABDIMS","TAB",
|
||||||
"ACTNUM","EQLNUM","FIPNUM","PVTNUM","SATNUM","TRANNNC"]
|
"ACTNUM","EQLNUM","FIPNUM","PVTNUM","SATNUM","TRANNNC"]
|
||||||
|
|
||||||
self.assertRaises(ValueError, EclFile, "/file/that/does_not_exists")
|
self.assertRaises(RuntimeError, EclFile, "/file/that/does_not_exists")
|
||||||
|
|
||||||
file2uf = EclFile(test_path("data/SPE9.INIT"), preload=False)
|
file2uf = EclFile(test_path("data/SPE9.INIT"), preload=False)
|
||||||
self.assertEqual(len(file2uf), 24)
|
self.assertEqual(len(file2uf), 24)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class TestEGrid(unittest.TestCase):
|
|||||||
|
|
||||||
def test_ijk_active_and_global_indices(self):
|
def test_ijk_active_and_global_indices(self):
|
||||||
|
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(RuntimeError):
|
||||||
EGrid("/file/that/does_not_exists")
|
EGrid("/file/that/does_not_exists")
|
||||||
|
|
||||||
grid1 = EGrid(test_path("data/9_EDITNNC.EGRID"))
|
grid1 = EGrid(test_path("data/9_EDITNNC.EGRID"))
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class TestEclFile(unittest.TestCase):
|
|||||||
('PROD', (2017, 7, 31), 942.0) ]
|
('PROD', (2017, 7, 31), 942.0) ]
|
||||||
|
|
||||||
|
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(RuntimeError):
|
||||||
ERft("/file/that/does_not_exists")
|
ERft("/file/that/does_not_exists")
|
||||||
|
|
||||||
rft1 = ERft(test_path("data/SPE1CASE1.RFT"))
|
rft1 = ERft(test_path("data/SPE1CASE1.RFT"))
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class TestEclFile(unittest.TestCase):
|
|||||||
|
|
||||||
def test_base_runs(self):
|
def test_base_runs(self):
|
||||||
|
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(RuntimeError):
|
||||||
ESmry("/file/that/does_not_exists")
|
ESmry("/file/that/does_not_exists")
|
||||||
|
|
||||||
smry1 = ESmry(test_path("data/SPE1CASE1.SMSPEC"))
|
smry1 = ESmry(test_path("data/SPE1CASE1.SMSPEC"))
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include <opm/io/eclipse/EclUtil.hpp>
|
#include <opm/io/eclipse/EclUtil.hpp>
|
||||||
#include <opm/common/ErrorMacros.hpp>
|
#include <opm/common/ErrorMacros.hpp>
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -39,10 +40,8 @@ namespace Opm { namespace EclIO {
|
|||||||
|
|
||||||
EclFile::EclFile(const std::string& filename, bool preload) : inputFilename(filename)
|
EclFile::EclFile(const std::string& filename, bool preload) : inputFilename(filename)
|
||||||
{
|
{
|
||||||
if (!fileExists(filename)){
|
if (!fileExists(filename))
|
||||||
std::string message="Could not open EclFile: " + filename;
|
throw std::runtime_error(fmt::format("Can not open EclFile: {}", filename));
|
||||||
OPM_THROW(std::invalid_argument, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::fstream fileH;
|
std::fstream fileH;
|
||||||
|
|
||||||
@@ -54,10 +53,8 @@ EclFile::EclFile(const std::string& filename, bool preload) : inputFilename(file
|
|||||||
fileH.open(filename, std::ios::in | std::ios::binary);
|
fileH.open(filename, std::ios::in | std::ios::binary);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fileH) {
|
if (!fileH)
|
||||||
std::string message="Could not open file: " + filename;
|
throw std::runtime_error(fmt::format("Can not open EclFile: {}", filename));
|
||||||
OPM_THROW(std::runtime_error, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
while (!isEOF(&fileH)) {
|
while (!isEOF(&fileH)) {
|
||||||
|
|||||||
@@ -498,9 +498,18 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum)
|
|||||||
const std::string& gdfile_arg = gdfile_kw.getRecord(0).getItem("filename").get<std::string>(0);
|
const std::string& gdfile_arg = gdfile_kw.getRecord(0).getItem("filename").get<std::string>(0);
|
||||||
std::string filename = deck.makeDeckPath(gdfile_arg);
|
std::string filename = deck.makeDeckPath(gdfile_arg);
|
||||||
|
|
||||||
Opm::EclIO::EclFile egridfile(filename);
|
std::unique_ptr<Opm::EclIO::EclFile> egridfile;
|
||||||
|
// Turns out some windows applications export .DATA files with relative
|
||||||
|
// GDFILE keywords with a windows formatted path, if open fails we give
|
||||||
|
// it one more try with the replacement '\'' -> '/'.
|
||||||
|
try {
|
||||||
|
egridfile = std::make_unique<Opm::EclIO::EclFile>(filename);
|
||||||
|
} catch (const std::runtime_error& ) {
|
||||||
|
std::replace(filename.begin(), filename.end(), '\\', '/');
|
||||||
|
egridfile = std::make_unique<Opm::EclIO::EclFile>(filename);
|
||||||
|
}
|
||||||
|
|
||||||
initGridFromEGridFile(egridfile, filename);
|
initGridFromEGridFile(*egridfile, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EclipseGrid::initCartesianGrid(const Deck& deck) {
|
void EclipseGrid::initCartesianGrid(const Deck& deck) {
|
||||||
|
|||||||
@@ -2547,7 +2547,7 @@ BOOST_AUTO_TEST_CASE(TEST_getCellCenters) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(LoadFromBinary) {
|
BOOST_AUTO_TEST_CASE(LoadFromBinary) {
|
||||||
BOOST_CHECK_THROW(Opm::EclipseGrid( "No/does/not/exist" ) , std::invalid_argument);
|
BOOST_CHECK_THROW(Opm::EclipseGrid( "No/does/not/exist" ) , std::runtime_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ BOOST_AUTO_TEST_CASE(TestEclFile_BINARY) {
|
|||||||
|
|
||||||
// check that exception is thrown when input file doesn't exist
|
// check that exception is thrown when input file doesn't exist
|
||||||
|
|
||||||
BOOST_CHECK_THROW(EclFile file1("DUMMY.DAT") , std::invalid_argument );
|
BOOST_CHECK_THROW(EclFile file1("DUMMY.DAT") , std::exception );
|
||||||
|
|
||||||
EclFile file1(testFile);
|
EclFile file1(testFile);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user