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