This commit is contained in:
Xavier Raynaud 2012-03-23 15:53:02 +01:00
commit 26f27daacd
2 changed files with 145 additions and 81 deletions

View File

@ -196,6 +196,72 @@ namespace {
return "CONTINUE"; // Last line in included file is a comment
}
inline bool readKeywordNew(std::istream& is, std::string& keyword)
{
char buf[9];
int i, j;
char c;
/* Clear buf */
for (i=0; i<9; ++i) {
buf[i] = '\0';
}
/* Read first character and check if it is uppercase*/
//buf[0] = fgetc(fp);
is.get(buf[0]);
if ( !isupper( buf[0] ) ) {
is.unget();
return false; /* NOT VALID CHARACTER */
}
/* Scan as much as possible possible keyword, 8 characters long */
i = 1;
is.get(c);
while ( (is.good()) &&
(c != EOF ) &&
(!isblank(c) ) &&
(isupper(c) || isdigit(c)) &&
(c != '\n' ) &&
(c != '/' ) &&
(i < 8 )) {
buf[i++] = c;
is.get(c);
}
/* Skip rest of line */
if (c != '\n'){
is.get(c);
while ( (is.good()) &&
(c != EOF ) &&
(c != '\n' )) {
is.get(c);
}
}
if(c == '\n') {
is.unget();
}
/* Find first non-uppercase or non-digit character */
for (i=0; i<8; ++i) {
if ( !(isupper(buf[i]) || isdigit(buf[i])) ) {
break;
}
}
/* Check if remaining characters are blank */
for (j = i; j<8; ++j) {
if(!isspace(buf[j]) && buf[j] != '\0') {
return false; /* CHARACTER AFTER SPACE OR INVALID CHARACTER */
}
buf[j] = '\0';
}
keyword = std::string(buf);
std::string::size_type end = keyword.find_last_of('\0');
if(end != keyword.npos)
keyword = keyword.substr(0, end+1);
return true;
}
} // anon namespace
@ -262,12 +328,14 @@ void EclipseGridParser::readImpl(istream& is)
map<string, tr1::shared_ptr<SpecialBase> >& specialmap = special_field_map_;
// Actually read the data
std::string keyword;
while (is.good()) {
is >> ignoreWhitespace;
while (!is.eof()) {
string keyword = readKeyword(is);
#ifdef VERBOSE
bool ok = readKeywordNew(is, keyword);
if (ok) {
//#ifdef VERBOSE
cout << "Keyword found: " << keyword << endl;
#endif
//#endif
FieldType type = classifyKeyword(keyword);
switch (type) {
case Integer:
@ -277,35 +345,28 @@ void EclipseGridParser::readImpl(istream& is)
readVectorData(is, floatmap[keyword]);
break;
case SpecialField: {
map<string, std::tr1::shared_ptr<SpecialBase> >::iterator pos =
specialmap.find(keyword);
if (pos == specialmap.end()) {
std::tr1::shared_ptr<SpecialBase> sb_ptr =
createSpecialField(is, keyword);
std::tr1::shared_ptr<SpecialBase> sb_ptr = createSpecialField(is, keyword);
if (sb_ptr) {
specialmap[keyword] = sb_ptr;
} else {
THROW("Could not create field " << keyword);
}
} else {
pos->second->read(is);
}
break;
}
case IgnoreWithData: {
ignored_fields_.insert(keyword);
is >> ignoreSlashLine;
#ifdef VERBOSE
cout << "(ignored)" << endl;
#endif
//is >> ignoreSlashLine;
//#ifdef VERBOSE
// cout << "(ignored)" << endl;
//#endif
break;
}
case IgnoreNoData: {
ignored_fields_.insert(keyword);
is >> ignoreLine;
#ifdef VERBOSE
cout << "(ignored)" << endl;
#endif
//is >> ignoreLine;
//#ifdef VERBOSE
// cout << "(ignored)" << endl;
//#endif
break;
}
case Include: {
@ -318,15 +379,20 @@ void EclipseGridParser::readImpl(istream& is)
THROW("Unable to open INCLUDEd file " << include_filename);
}
readImpl(include_is);
is >> ignoreSlashLine;
// is >> ignoreSlashLine;
break;
}
case Unknown:
default:
cerr << "Keyword " << keyword << " not recognized." << endl;
throw exception();
ignored_fields_.insert(keyword);
cout << "*** Warning: keyword " << keyword << " is unknown." << endl;
//is >> ignoreSlashLine;
//throw exception();
}
} else {
// if (!ok)
is >> ignoreLine;
}
is >> ignoreWhitespace;
}
#define VERBOSE_LIST_FIELDS 0
@ -478,7 +544,7 @@ const std::vector<int>& EclipseGridParser::getIntegerValue(const std::string& ke
map<string, vector<int> >::const_iterator it
= integer_field_map_.find(keyword);
if (it == integer_field_map_.end()) {
return empty_integer_field_;
THROW("No such field: " << keyword);
} else {
return it->second;
}
@ -491,7 +557,7 @@ const std::vector<double>& EclipseGridParser::getFloatingPointValue(const std::s
map<string, vector<double> >::const_iterator it
= floating_field_map_.find(keyword);
if (it == floating_field_map_.end()) {
return empty_floating_field_;
THROW("No such field: " << keyword);
} else {
return it->second;
}

View File

@ -186,8 +186,6 @@ private:
std::map<std::string, std::vector<double> > floating_field_map_;
std::map<std::string, std::tr1::shared_ptr<SpecialBase> > special_field_map_;
std::set<std::string> ignored_fields_;
std::vector<int> empty_integer_field_;
std::vector<double> empty_floating_field_;
std::tr1::shared_ptr<SpecialBase> empty_special_field_;
EclipseUnits units_;
};