changed: log keyword location when parsing a table failed

This commit is contained in:
Arne Morten Kvarving 2022-06-13 12:13:50 +02:00
parent 3af1d464eb
commit 050540525f
2 changed files with 16 additions and 5 deletions

View File

@ -23,6 +23,8 @@
#include <opm/input/eclipse/EclipseState/Tables/TableSchema.hpp> #include <opm/input/eclipse/EclipseState/Tables/TableSchema.hpp>
#include <opm/input/eclipse/Deck/DeckItem.hpp> #include <opm/input/eclipse/Deck/DeckItem.hpp>
#include <fmt/format.h>
namespace Opm { namespace Opm {
SimpleTable::SimpleTable( TableSchema schema, const DeckItem& deckItem) : SimpleTable::SimpleTable( TableSchema schema, const DeckItem& deckItem) :
@ -85,9 +87,14 @@ namespace Opm {
void SimpleTable::init( const DeckItem& deckItem, double scaling_factor) { void SimpleTable::init( const DeckItem& deckItem, double scaling_factor) {
this->addColumns(); this->addColumns();
if ( (deckItem.data_size() % numColumns()) != 0) if ( (deckItem.data_size() % numColumns()) != 0) {
throw std::runtime_error("Number of columns in the data file is" throw std::runtime_error {
"inconsistent with the ones specified"); fmt::format("Number of input table elements ({}) is "
"not a multiple of table's specified number "
"of columns ({})",
deckItem.data_size(), this->numColumns())
};
}
size_t rows = deckItem.data_size() / numColumns(); size_t rows = deckItem.data_size() / numColumns();
for (size_t colIdx = 0; colIdx < numColumns(); ++colIdx) { for (size_t colIdx = 0; colIdx < numColumns(); ++colIdx) {

View File

@ -1562,8 +1562,12 @@ DensityTable make_density_table(const GravityTable& gravity) {
for (size_t tableIdx = 0; tableIdx < tableKeyword.size(); ++tableIdx) { for (size_t tableIdx = 0; tableIdx < tableKeyword.size(); ++tableIdx) {
const auto& dataItem = tableKeyword.getRecord( tableIdx ).getItem("DATA"); const auto& dataItem = tableKeyword.getRecord( tableIdx ).getItem("DATA");
if (dataItem.data_size() > 0) { if (dataItem.data_size() > 0) {
std::shared_ptr<TableType> table = std::make_shared<TableType>( dataItem, useJFunc() ); try {
container.addTable( tableIdx , table ); std::shared_ptr<TableType> table = std::make_shared<TableType>( dataItem, useJFunc() );
container.addTable( tableIdx , table );
} catch (const std::runtime_error& err) {
throw OpmInputError(err, tableKeyword.location());
}
} }
} }
} }