OGS
PetrelInterface.cpp
Go to the documentation of this file.
1
14#include "PetrelInterface.h"
15
16#include <fstream>
17
18#include "BaseLib/Logging.h"
19#include "BaseLib/StringTools.h"
20#include "GeoLib/GEOObjects.h"
22
23namespace FileIO
24{
25PetrelInterface::PetrelInterface(std::list<std::string> const& sfc_fnames,
26 std::list<std::string> const& well_path_fnames,
27 std::string& unique_model_name,
28 GeoLib::GEOObjects* geo_obj)
29 : _unique_name(unique_model_name)
30{
31 for (auto const& surface_fname : sfc_fnames)
32 {
33 INFO("PetrelInterface::PetrelInterface(): open surface file.");
34 std::ifstream in(surface_fname);
35 if (in)
36 {
37 INFO("PetrelInterface::PetrelInterface(): \tdone.");
39 in.close();
40 }
41 else
42 {
43 WARN(
44 "PetrelInterface::PetrelInterface(): \tCould not open file "
45 "{:s}.",
46 surface_fname);
47 }
48 }
49
50 for (auto const& well_path_fname : well_path_fnames)
51 {
52 INFO("PetrelInterface::PetrelInterface(): open well path file.");
53 std::ifstream in(well_path_fname);
54 if (in)
55 {
56 INFO("PetrelInterface::PetrelInterface(): \tdone.");
58 in.close();
59 }
60 else
61 {
62 WARN(
63 "PetrelInterface::PetrelInterface(): \tCould not open well "
64 "path file {:s}.",
65 well_path_fname);
66 }
67 }
68
69 // move data to GEOObject
70 geo_obj->addPointVec(std::move(pnt_vec), _unique_name);
71 if (!well_vec.empty())
72 {
73 geo_obj->addStationVec(std::move(well_vec), _unique_name);
74 }
75}
76
77static std::string readLine(std::istream& in)
78{
79 std::string line;
80 std::getline(in, line);
81 return line;
82}
83
84static std::list<std::string> split(std::string const& line)
85{
86 return BaseLib::splitString(line, ' ');
87}
88
90{
91 std::string line = readLine(in);
92
93 if (line.find("# Petrel Points with attributes") != std::string::npos)
94 {
95 // read header
96 // read Version string
97 readLine(in);
98 // read string BEGIN HEADER
99 readLine(in);
100
101 line = readLine(in);
102 while (line.find("END HEADER") == std::string::npos)
103 {
104 line = readLine(in);
105 }
106
107 // read points
108 while (in)
109 {
110 auto point = std::make_unique<GeoLib::Point>();
111 in >> (*point)[0] >> (*point)[1] >> (*point)[2];
112 if (in)
113 {
114 pnt_vec.push_back(point.release());
115 }
116 }
117 }
118 else
119 {
120 WARN(
121 "PetrelInterface::readPetrelSurface(): problem reading petrel "
122 "points from line\n'{:s}'.",
123 line);
124 }
125}
126
127static void printListInfo(const std::list<std::string>& str_list,
128 std::string_view const prefix,
129 std::string_view const message)
130{
131 for (auto const& str : str_list)
132 {
133 INFO("PetrelInterface::{:s}(): {:s}: {:s}.", prefix, message, str);
134 }
135}
136
137static double getLastNumberFromList(const std::list<std::string>& str_list)
138{
139 return std::stod(*(--str_list.end()));
140}
141
143{
144 std::string line = readLine(in);
145
146 if (line.find("# WELL TRACE FROM PETREL") == std::string::npos)
147 {
148 return;
149 }
150
151 auto printInfo = [](auto const& list, std::string_view const message)
152 { printListInfo(list, "readPetrelWellTrace", message); };
153
154 {
155 // read header
156 // read well name
157 printInfo(split(readLine(in)), "well name");
158
159 // read well head x coordinate
160 auto str_list = split(readLine(in));
161 printInfo(str_list, "well head x coord");
162 double const well_head_x = getLastNumberFromList(str_list);
163
164 // read well head y coordinate
165 str_list = split(readLine(in));
166 printInfo(str_list, "well head y coord");
167 double const well_head_y = getLastNumberFromList(str_list);
168
169 // read well KB
170 str_list = split(readLine(in));
171 printInfo(str_list, "well kb entry");
172 double const well_kb = getLastNumberFromList(str_list);
173
174 INFO("PetrelInterface::readPetrelWellTrace(): {:f}, {:f}, {:f}.",
175 well_head_x,
176 well_head_y,
177 well_kb);
178 double const depth = 0.0;
179 std::string const borehole_name = "";
180 int const date = 0;
181 well_vec.push_back(new GeoLib::StationBorehole(
182 well_head_x, well_head_y, well_kb, depth, borehole_name, date));
183
184 // read well type
185 readLine(in);
186 // std::string type(*((str_list.end())--));
187
189 }
190}
191
193{
194 readLine(in);
195
196 // read yet another header line
197 std::string line = readLine(in);
198 while (line[0] == '#')
199 {
200 line = readLine(in);
201 }
202
203 // read column information
204 printListInfo(split(line), "readPetrelWellTraceData", "column information");
205
206 // read points
207 double md;
208 double x;
209 double y;
210 double z;
211 double tvd;
212 double dx;
213 double dy;
214 double azim;
215 double incl;
216 double dls;
217 line = readLine(in);
218 while (in)
219 {
220 if (line.size() > 1 && line[0] != '#')
221 {
222 std::stringstream stream(line);
223 stream >> md;
224 stream >> x >> y >> z;
225 // pnt_vec->push_back (new GeoLib::Point (x,y,z));
226 static_cast<GeoLib::StationBorehole*>(well_vec.back())
227 ->addSoilLayer(x, y, z, "unknown");
228 stream >> tvd >> dx >> dy >> azim >> incl >> dls;
229 }
230 line = readLine(in);
231 }
232}
233} // end namespace FileIO
Definition of the GEOObjects class.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
Definition of the PetrelInterface class.
Definition of the StationBorehole class.
Definition of string helper functions.
std::vector< GeoLib::Point * > pnt_vec
void readPetrelSurfacePoints(std::istream &in)
void readPetrelWellTrace(std::istream &in)
void readPetrelWellTraceData(std::istream &in)
PetrelInterface(std::list< std::string > const &sfc_fnames, std::list< std::string > const &well_path_fnames, std::string &unique_model_name, GeoLib::GEOObjects *geo_obj)
std::vector< GeoLib::Point * > well_vec
Container class for geometric objects.
Definition GEOObjects.h:57
void addPointVec(std::vector< Point * > &&points, std::string &name, PointVec::NameIdMap &&pnt_id_name_map, double const eps=std::sqrt(std::numeric_limits< double >::epsilon()))
void addStationVec(std::vector< Point * > &&stations, std::string &name)
Adds a vector of stations with the given name and colour to GEOObjects.
A borehole as a geometric object.
std::vector< std::string > splitString(std::string const &str)
static void printListInfo(const std::list< std::string > &str_list, std::string_view const prefix, std::string_view const message)
static std::string readLine(std::istream &in)
static double getLastNumberFromList(const std::list< std::string > &str_list)
static std::list< std::string > split(std::string const &line)