Fixed a bug when keywords had trailing spaces. Now trimming right side of string.
This commit is contained in:
9
docs/observations.txt
Normal file
9
docs/observations.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
Strange structure, records not equally long. Defaults?
|
||||
|
||||
EQUALS
|
||||
SWL 0.10 / Connate water saturation
|
||||
SWU 1.0 / Maximum water saturation
|
||||
SGCR 0.10 / Critical gas saturation
|
||||
SOWCR 0.2 / Residual oil saturation after water-flood
|
||||
SOGCR 0.1 / Residual oil sat. after gas-flood
|
||||
/
|
||||
@@ -32,6 +32,14 @@ namespace Opm {
|
||||
return m_keywordRawData.size();
|
||||
}
|
||||
|
||||
void KeywordRawData::getListOfKeywords(std::list<std::string>& keywords) {
|
||||
keywords.clear();
|
||||
std::list< std::pair< std::string, std::list<std::string > > >::iterator iterator;
|
||||
for (iterator = m_keywordRawData.begin(); iterator != m_keywordRawData.end(); iterator++) {
|
||||
keywords.push_back(iterator->first);
|
||||
}
|
||||
}
|
||||
|
||||
KeywordRawData::~KeywordRawData() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace Opm {
|
||||
public:
|
||||
KeywordRawData();
|
||||
void addKeywordDataBlob(const std::string& keyword, const std::list<std::string>& blob);
|
||||
void getListOfKeywords(std::list<std::string>& keywords);
|
||||
int numberOfKeywords();
|
||||
virtual ~KeywordRawData();
|
||||
private:
|
||||
|
||||
@@ -60,6 +60,10 @@ namespace Opm {
|
||||
return m_keywordRawData -> numberOfKeywords();
|
||||
}
|
||||
|
||||
void Parser::getListOfKeywords(std::list<std::string>& list) {
|
||||
m_keywordRawData->getListOfKeywords(list);
|
||||
}
|
||||
|
||||
void Parser::createKeywordAndRawData(std::ifstream& inputstream) {
|
||||
EclipseDeck deck;
|
||||
std::string line;
|
||||
@@ -68,16 +72,17 @@ namespace Opm {
|
||||
while (std::getline(inputstream, line)) {
|
||||
if (isKeyword(line)) {
|
||||
if (currentKeyword != "") {
|
||||
m_keywordRawData->addKeywordDataBlob(line, currentDataBlob);
|
||||
m_keywordRawData->addKeywordDataBlob(currentKeyword, currentDataBlob);
|
||||
}
|
||||
currentDataBlob = std::list<std::string>();
|
||||
currentKeyword = line;
|
||||
} else {
|
||||
addDataToBlob(line, currentDataBlob);
|
||||
if (currentKeyword != "")
|
||||
addDataToBlob(line, currentDataBlob);
|
||||
}
|
||||
}
|
||||
if (currentKeyword != "") {
|
||||
m_keywordRawData->addKeywordDataBlob(line, currentDataBlob);
|
||||
m_keywordRawData->addKeywordDataBlob(currentKeyword, currentDataBlob);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +115,8 @@ namespace Opm {
|
||||
throw std::runtime_error("Unable to compile regular expression for keyword! Expression: " + keywordRegex);
|
||||
}
|
||||
|
||||
status = regexec(&re, line.c_str(), 1, &rm, 0);
|
||||
std::string trimmedRight = boost::trim_right_copy(line);
|
||||
status = regexec(&re, trimmedRight.c_str(), 1, &rm, 0);
|
||||
regfree(&re);
|
||||
|
||||
if (status == 0) {
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace Opm {
|
||||
void parse();
|
||||
void parse(const std::string &path);
|
||||
int getNumberOfKeywords();
|
||||
void getListOfKeywords(std::list<std::string>& list);
|
||||
virtual ~Parser();
|
||||
private:
|
||||
std::string m_dataFilePath;
|
||||
|
||||
@@ -66,6 +66,7 @@ BOOST_AUTO_TEST_CASE(ParseFileWithOneKeyword) {
|
||||
BOOST_REQUIRE_EQUAL(2, parser.getNumberOfKeywords());
|
||||
}
|
||||
|
||||
//NOTE: needs statoil dataset
|
||||
BOOST_AUTO_TEST_CASE(ParseFileWithManyKeywords) {
|
||||
boost::filesystem::path multipleKeywordFile("testdata/gurbat_trimmed.DATA");
|
||||
|
||||
@@ -73,3 +74,22 @@ BOOST_AUTO_TEST_CASE(ParseFileWithManyKeywords) {
|
||||
parser.parse();
|
||||
BOOST_REQUIRE_EQUAL(18, parser.getNumberOfKeywords());
|
||||
}
|
||||
|
||||
//NOTE: needs statoil dataset
|
||||
BOOST_AUTO_TEST_CASE(ParseFullTestFile) {
|
||||
boost::filesystem::path multipleKeywordFile("testdata/ECLIPSE.DATA");
|
||||
|
||||
Parser parser(multipleKeywordFile.string());
|
||||
parser.parse();
|
||||
BOOST_REQUIRE_EQUAL(73, parser.getNumberOfKeywords());
|
||||
std::list<std::string> keywords;
|
||||
parser.getListOfKeywords(keywords);
|
||||
BOOST_REQUIRE_EQUAL((unsigned int)73, keywords.size());
|
||||
|
||||
// std::ofstream file("keywords.out");
|
||||
// std::list<std::string>::iterator iterator;
|
||||
// for (iterator = keywords.begin(); iterator != keywords.end(); ++iterator) {
|
||||
// file << *iterator << std::endl;
|
||||
// }
|
||||
// file.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user