diff --git a/CMakeLists.txt b/CMakeLists.txt
index 49c944bf3..1490f2c2a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -161,6 +161,7 @@ if(ENABLE_ECL_INPUT)
examples/test_util/EclFilesComparator.cpp
examples/test_util/EclIntegrationTest.cpp
examples/test_util/EclRegressionTest.cpp
+ examples/test_util/EclUtil.cpp
examples/test_util/summaryComparator.cpp
examples/test_util/summaryIntegrationTest.cpp
examples/test_util/summaryRegressionTest.cpp)
diff --git a/examples/test_util/EclUtil.cpp b/examples/test_util/EclUtil.cpp
new file mode 100644
index 000000000..b0f6962b5
--- /dev/null
+++ b/examples/test_util/EclUtil.cpp
@@ -0,0 +1,127 @@
+/*
+ Copyright 2019 Equinor ASA.
+
+ This file is part of the Open Porous Media project (OPM).
+
+ OPM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OPM is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OPM. If not, see .
+ */
+
+#include "EclUtil.hpp"
+#include
+
+#include
+#include
+
+
+namespace EIOD = Opm::ecl;
+
+
+int Opm::ecl::flipEndianInt(int num)
+{
+ unsigned int tmp = __builtin_bswap32(num);
+ return static_cast(tmp);
+}
+
+
+float Opm::ecl::flipEndianFloat(float num)
+{
+ float value = num;
+
+ char* floatToConvert = reinterpret_cast(&value);
+ std::reverse(floatToConvert, floatToConvert+4);
+
+ return value;
+}
+
+
+double Opm::ecl::flipEndianDouble(double num)
+{
+ double value = num;
+
+ char* doubleToConvert = reinterpret_cast(&value);
+ std::reverse(doubleToConvert, doubleToConvert+8);
+
+ return value;
+}
+
+
+std::tuple Opm::ecl::block_size_data_binary(eclArrType arrType)
+{
+ using BlockSizeTuple = std::tuple;
+
+ switch (arrType) {
+ case EIOD::INTE:
+ return BlockSizeTuple{EIOD::sizeOfInte, EIOD::MaxBlockSizeInte};
+ break;
+ case EIOD::REAL:
+ return BlockSizeTuple{EIOD::sizeOfReal, EIOD::MaxBlockSizeReal};
+ break;
+ case EIOD::DOUB:
+ return BlockSizeTuple{EIOD::sizeOfDoub, EIOD::MaxBlockSizeDoub};
+ break;
+ case EIOD::LOGI:
+ return BlockSizeTuple{EIOD::sizeOfLogi, EIOD::MaxBlockSizeLogi};
+ break;
+ case EIOD::CHAR:
+ return BlockSizeTuple{EIOD::sizeOfChar, EIOD::MaxBlockSizeChar};
+ break;
+ case EIOD::MESS:
+ OPM_THROW(std::invalid_argument, "Type 'MESS' have no associated data");
+ break;
+ default:
+ OPM_THROW(std::invalid_argument, "Unknown field type");
+ break;
+ }
+}
+
+
+std::tuple Opm::ecl::block_size_data_formatted(EIOD::eclArrType arrType)
+{
+ using BlockSizeTuple = std::tuple;
+
+ switch (arrType) {
+ case EIOD::INTE:
+ return BlockSizeTuple{EIOD::MaxNumBlockInte, EIOD::numColumnsInte, EIOD::columnWidthInte};
+ break;
+ case EIOD::REAL:
+ return BlockSizeTuple{EIOD::MaxNumBlockReal,EIOD::numColumnsReal, EIOD::columnWidthReal};
+ break;
+ case EIOD::DOUB:
+ return BlockSizeTuple{EIOD::MaxNumBlockDoub,EIOD::numColumnsDoub, EIOD::columnWidthDoub};
+ break;
+ case EIOD::LOGI:
+ return BlockSizeTuple{EIOD::MaxNumBlockLogi,EIOD::numColumnsLogi, EIOD::columnWidthLogi};
+ break;
+ case EIOD::CHAR:
+ return BlockSizeTuple{EIOD::MaxNumBlockChar,EIOD::numColumnsChar, EIOD::columnWidthChar};
+ break;
+ case EIOD::MESS:
+ OPM_THROW(std::invalid_argument, "Type 'MESS' have no associated data") ;
+ break;
+ default:
+ OPM_THROW(std::invalid_argument, "Unknown field type");
+ break;
+ }
+}
+
+
+std::string Opm::ecl::trimr(const std::string &str1)
+{
+ if (str1 == " ") {
+ return "";
+ } else {
+ int p = str1.find_last_not_of(" ");
+
+ return str1.substr(0,p+1);
+ }
+}
diff --git a/examples/test_util/EclUtil.hpp b/examples/test_util/EclUtil.hpp
new file mode 100644
index 000000000..7ba26846c
--- /dev/null
+++ b/examples/test_util/EclUtil.hpp
@@ -0,0 +1,39 @@
+/*
+ Copyright 2019 Equinor ASA.
+
+ This file is part of the Open Porous Media project (OPM).
+
+ OPM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OPM is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OPM. If not, see .
+ */
+
+#ifndef ECL_UTIL_HPP
+#define ECL_UTIL_HPP
+
+#include
+#include
+
+
+namespace Opm {
+ namespace ecl {
+ int flipEndianInt(int num);
+ float flipEndianFloat(float num);
+ double flipEndianDouble(double num);
+
+ std::tuple block_size_data_binary(eclArrType arrType);
+ std::tuple block_size_data_formatted(eclArrType arrType);
+
+ std::string trimr(const std::string &str1);
+ }
+}
+
+#endif
diff --git a/examples/test_util/data/EclIOdata.hpp b/examples/test_util/data/EclIOdata.hpp
index bc9e14a3f..63f265dd0 100644
--- a/examples/test_util/data/EclIOdata.hpp
+++ b/examples/test_util/data/EclIOdata.hpp
@@ -32,6 +32,8 @@ namespace Opm {
enum eclArrType {
INTE, REAL, DOUB, CHAR, LOGI, MESS
};
+
+ // named constants related to binary file format
const unsigned int true_value = 0xffffffff;
const unsigned int false_value = 0x00000000;
@@ -48,6 +50,26 @@ namespace Opm {
const int MaxBlockSizeLogi = 4000; // Maximum block size for LOGI arrays in binary files
const int MaxBlockSizeChar = 840; // Maximum block size for CHAR arrays in binary files
+ // named constants related to formatted file file format
+
+ const int MaxNumBlockInte = 1000; // maximum number of Inte values in block => hard line shift
+ const int MaxNumBlockReal = 1000; // maximum number of Real values in block => hard line shift
+ const int MaxNumBlockDoub = 1000; // maximum number of Doub values in block => hard line shift
+ const int MaxNumBlockLogi = 1000; // maximum number of Logi values in block => hard line shift
+ const int MaxNumBlockChar = 105; // maximum number of Char values in block => hard line shift
+
+ const int numColumnsInte = 6; // number of columns for Inte values
+ const int numColumnsReal = 4; // number of columns for Real values
+ const int numColumnsDoub = 3; // number of columns for Doub values
+ const int numColumnsLogi = 25; // number of columns for Logi values
+ const int numColumnsChar = 7; // number of columns for Char values
+
+ const int columnWidthInte = 12; // number of characters fore each Inte Element
+ const int columnWidthReal = 17; // number of characters fore each Inte Element
+ const int columnWidthDoub = 23; // number of characters fore each Inte Element
+ const int columnWidthLogi = 3; // number of characters fore each Inte Element
+ const int columnWidthChar = 11; // number of characters fore each Inte Element
+
} // ecl
} // Opm