EclOutput.hpp
Go to the documentation of this file.
1/*
2 Copyright 2019 Statoil 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#ifndef OPM_IO_ECLOUTPUT_HPP
19#define OPM_IO_ECLOUTPUT_HPP
20
21#include <fstream>
22#include <ios>
23#include <string>
24#include <typeinfo>
25#include <vector>
26
29#include <iostream>
30
31namespace Opm { namespace EclIO { namespace OutputStream {
32 class Restart;
34}}}
35
36namespace Opm { namespace EclIO {
37
39{
40public:
41 EclOutput(const std::string& filename,
42 const bool formatted,
43 const std::ios_base::openmode mode = std::ios::out);
44
45 template<typename T>
46 void write(const std::string& name,
47 const std::vector<T>& data)
48 {
49 eclArrType arrType = MESS;
50 int element_size = 4;
51
52 if (typeid(T) == typeid(int))
53 arrType = INTE;
54 else if (typeid(T) == typeid(float))
55 arrType = REAL;
56 else if (typeid(T) == typeid(double)){
57 arrType = DOUB;
58 element_size = 8;
59 } else if (typeid(T) == typeid(bool))
60 arrType = LOGI;
61 else if (typeid(T) == typeid(char))
62 arrType = MESS;
63
64 if (isFormatted)
65 {
66 writeFormattedHeader(name, data.size(), arrType, element_size);
67 if (arrType != MESS)
68 writeFormattedArray(data);
69 }
70 else
71 {
72 writeBinaryHeader(name, data.size(), arrType, element_size);
73 if (arrType != MESS)
74 writeBinaryArray(data);
75 }
76 }
77
78 // when this function is used array type will be assumed C0NN (not CHAR).
79 // Also in cases where element size is 8 or less, element size will be 8.
80
81 void write(const std::string& name, const std::vector<std::string>& data, int element_size);
82
83 void message(const std::string& msg);
85
86 void set_ix() { ix_standard = true; }
87
90
91private:
92 void writeBinaryHeader(const std::string& arrName, int64_t size, eclArrType arrType, int element_size);
93
94 template <typename T>
95 void writeBinaryArray(const std::vector<T>& data);
96
97 void writeBinaryCharArray(const std::vector<std::string>& data, int element_size);
98 void writeBinaryCharArray(const std::vector<PaddedOutputString<8>>& data);
99
100 void writeFormattedHeader(const std::string& arrName, int size, eclArrType arrType, int element_size);
101
102 template <typename T>
103 void writeFormattedArray(const std::vector<T>& data);
104
105 void writeFormattedCharArray(const std::vector<std::string>& data, int element_size);
106 void writeFormattedCharArray(const std::vector<PaddedOutputString<8>>& data);
107
108 void writeArrayType(const eclArrType arrType);
109 std::string make_real_string_ecl(float value) const;
110 std::string make_real_string_ix(float value) const;
111 std::string make_doub_string_ecl(double value) const;
112 std::string make_doub_string_ix(double value) const;
113
114 bool isFormatted, ix_standard;
115 std::ofstream ofileH;
116};
117
118
119template<>
120void EclOutput::write<std::string>(const std::string& name,
121 const std::vector<std::string>& data);
122
123template <>
124void EclOutput::write<PaddedOutputString<8>>
125 (const std::string& name,
126 const std::vector<PaddedOutputString<8>>& data);
127
128}} // namespace Opm::EclIO
129
130#endif // OPM_IO_ECLOUTPUT_HPP
const char *const name
Definition: cJSON.h:258
const char *const string
Definition: cJSON.h:170
Definition: EclOutput.hpp:39
EclOutput(const std::string &filename, const bool formatted, const std::ios_base::openmode mode=std::ios::out)
void write(const std::string &name, const std::vector< T > &data)
Definition: EclOutput.hpp:46
void set_ix()
Definition: EclOutput.hpp:86
void message(const std::string &msg)
void write(const std::string &name, const std::vector< std::string > &data, int element_size)
File manager for restart output streams.
Definition: OutputStream.hpp:136
Definition: OutputStream.hpp:364
eclArrType
Definition: EclIOdata.hpp:28
@ MESS
Definition: EclIOdata.hpp:29
@ DOUB
Definition: EclIOdata.hpp:29
@ LOGI
Definition: EclIOdata.hpp:29
@ INTE
Definition: EclIOdata.hpp:29
@ REAL
Definition: EclIOdata.hpp:29
bool isFormatted(const std::string &filename)
Definition: A.hpp:4
T value(details::expression_node< T > *n)
Definition: exprtk.hpp:12955
static std::string data()
Definition: exprtk.hpp:40022