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 
40  std::tuple<int, int> block_size_data_binary(eclArrType arrType);
41  std::tuple<int, int, int> block_size_data_formatted(eclArrType arrType);
42 
43  std::string trimr(const std::string &str1);
44 
45  uint64_t sizeOnDiskBinary(int64_t num, Opm::EclIO::eclArrType arrType, int elementSize);
46  uint64_t sizeOnDiskFormatted(const int64_t num, Opm::EclIO::eclArrType arrType, int elementSize);
47 
48  void readBinaryHeader(std::fstream& fileH, std::string& tmpStrName,
49  int& tmpSize, std::string& tmpStrType);
50 
51  void readBinaryHeader(std::fstream& fileH, std::string& arrName,
52  int64_t& size, Opm::EclIO::eclArrType &arrType, int& elementSize);
53 
54  void readFormattedHeader(std::fstream& fileH, std::string& arrName,
55  int64_t &num, Opm::EclIO::eclArrType &arrType, int& elementSize);
56 
57  template<typename T, typename T2>
58  std::vector<T> readBinaryArray(std::fstream& fileH, const int64_t size, Opm::EclIO::eclArrType type,
59  std::function<T(T2)>& flip, int elementSize);
60 
61  std::vector<int> readBinaryInteArray(std::fstream &fileH, const int64_t size);
62  std::vector<float> readBinaryRealArray(std::fstream& fileH, const int64_t size);
63  std::vector<double> readBinaryDoubArray(std::fstream& fileH, const int64_t size);
64  std::vector<bool> readBinaryLogiArray(std::fstream &fileH, const int64_t size);
65  std::vector<unsigned int> readBinaryRawLogiArray(std::fstream &fileH, const int64_t size);
66  std::vector<std::string> readBinaryCharArray(std::fstream& fileH, const int64_t size);
67  std::vector<std::string> readBinaryC0nnArray(std::fstream& fileH, const int64_t size, int elementSize);
68 
69  template<typename T>
70  std::vector<T> readFormattedArray(const std::string& file_str, const int size, int64_t fromPos,
71  std::function<T(const std::string&)>& process);
72 
73  std::vector<int> readFormattedInteArray(const std::string& file_str, const int64_t size, int64_t fromPos);
74 
75  std::vector<std::string> readFormattedCharArray(const std::string& file_str, const int64_t size,
76  int64_t fromPos, int elementSize);
77 
78  std::vector<float> readFormattedRealArray(const std::string& file_str, const int64_t size, int64_t fromPos);
79  std::vector<std::string> readFormattedRealRawStrings(const std::string& file_str, const int64_t size, int64_t fromPos);
80 
81  std::vector<bool> readFormattedLogiArray(const std::string& file_str, const int64_t size, int64_t fromPos);
82  std::vector<double> readFormattedDoubArray(const std::string& file_str, const int64_t size, int64_t fromPos);
83 
84 }} // namespace Opm::EclIO
85 
86 #endif // OPM_IO_ECLUTIL_HPP
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29