opm-common
EclUtil.hpp
1 /*
2  Copyright 2019 Equinor ASA.
3 
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef OPM_IO_ECLUTIL_HPP
21 #define OPM_IO_ECLUTIL_HPP
22 
23 #include <opm/io/eclipse/EclIOdata.hpp>
24 
25 #include <cstdint>
26 #include <functional>
27 #include <string>
28 #include <tuple>
29 #include <vector>
30 
31 namespace Opm { namespace EclIO {
32 
33  int flipEndianInt(int num);
34  std::int64_t flipEndianLongInt(std::int64_t num);
35  float flipEndianFloat(float num);
36  double flipEndianDouble(double num);
37  bool isEOF(std::fstream* fileH);
38  bool fileExists(const std::string& filename);
39  bool isFormatted(const std::string& filename);
40  bool is_number(const std::string& numstr);
41 
47  int combineSummaryNumbers(const int n1, const int n2);
48 
51  std::tuple<int,int> splitSummaryNumber(const int n);
52 
53  std::tuple<int, int> block_size_data_binary(eclArrType arrType);
54  std::tuple<int, int, int> block_size_data_formatted(eclArrType arrType);
55 
56  std::string trimr(const std::string &str1);
57 
58  std::uint64_t sizeOnDiskBinary(std::int64_t num, Opm::EclIO::eclArrType arrType, int elementSize);
59  std::uint64_t sizeOnDiskFormatted(const std::int64_t num, Opm::EclIO::eclArrType arrType, int elementSize);
60 
61  void readBinaryHeader(std::fstream& fileH, std::string& tmpStrName,
62  int& tmpSize, std::string& tmpStrType);
63 
64  void readBinaryHeader(std::fstream& fileH, std::string& arrName,
65  std::int64_t& size, Opm::EclIO::eclArrType &arrType, int& elementSize);
66 
67  void readFormattedHeader(std::fstream& fileH, std::string& arrName,
68  std::int64_t &num, Opm::EclIO::eclArrType &arrType, int& elementSize);
69 
70  template<typename T, typename T2>
71  std::vector<T> readBinaryArray(std::fstream& fileH, const std::int64_t size, Opm::EclIO::eclArrType type,
72  std::function<T(T2)>& flip, int elementSize);
73 
74  std::vector<int> readBinaryInteArray(std::fstream &fileH, const std::int64_t size);
75  std::vector<float> readBinaryRealArray(std::fstream& fileH, const std::int64_t size);
76  std::vector<double> readBinaryDoubArray(std::fstream& fileH, const std::int64_t size);
77  std::vector<bool> readBinaryLogiArray(std::fstream &fileH, const std::int64_t size);
78  std::vector<unsigned int> readBinaryRawLogiArray(std::fstream &fileH, const std::int64_t size);
79  std::vector<std::string> readBinaryCharArray(std::fstream& fileH, const std::int64_t size);
80  std::vector<std::string> readBinaryC0nnArray(std::fstream& fileH, const std::int64_t size, int elementSize);
81 
82  template<typename T>
83  std::vector<T> readFormattedArray(const std::string& file_str, const int size, std::int64_t fromPos,
84  std::function<T(const std::string&)>& process);
85 
86  std::vector<int> readFormattedInteArray(const std::string& file_str, const std::int64_t size, std::int64_t fromPos);
87 
88  std::vector<std::string> readFormattedCharArray(const std::string& file_str, const std::int64_t size,
89  std::int64_t fromPos, int elementSize);
90 
91  std::vector<float> readFormattedRealArray(const std::string& file_str, const std::int64_t size, std::int64_t fromPos);
92  std::vector<std::string> readFormattedRealRawStrings(const std::string& file_str, const std::int64_t size, std::int64_t fromPos);
93 
94  std::vector<bool> readFormattedLogiArray(const std::string& file_str, const std::int64_t size, std::int64_t fromPos);
95  std::vector<double> readFormattedDoubArray(const std::string& file_str, const std::int64_t size, std::int64_t fromPos);
96 
97 }} // namespace Opm::EclIO
98 
99 #endif // OPM_IO_ECLUTIL_HPP
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30