OGS
PetrelInterface.cpp
Go to the documentation of this file.
1 
18 #include "PetrelInterface.h"
19 
20 #include <fstream>
21 
22 #include "BaseLib/Logging.h"
23 #include "BaseLib/StringTools.h"
24 #include "GeoLib/GEOObjects.h"
25 #include "GeoLib/StationBorehole.h"
26 
27 namespace FileIO
28 {
29 PetrelInterface::PetrelInterface(std::list<std::string>& sfc_fnames,
30  std::list<std::string>& well_path_fnames,
31  std::string& unique_model_name,
32  GeoLib::GEOObjects* geo_obj)
33  : _unique_name(unique_model_name),
34  pnt_vec(new std::vector<GeoLib::Point*>),
35  well_vec(new std::vector<GeoLib::Point*>),
36  ply_vec(new std::vector<GeoLib::Polyline*>)
37 {
38  for (std::list<std::string>::const_iterator it(sfc_fnames.begin());
39  it != sfc_fnames.end();
40  ++it)
41  {
42  INFO("PetrelInterface::PetrelInterface(): open surface file.");
43  std::ifstream in((*it).c_str());
44  if (in)
45  {
46  INFO("PetrelInterface::PetrelInterface(): \tdone.");
48  in.close();
49  }
50  else
51  {
52  WARN(
53  "PetrelInterface::PetrelInterface(): \tCould not open file "
54  "{:s}.",
55  it->c_str());
56  }
57  }
58 
59  for (std::list<std::string>::const_iterator it(well_path_fnames.begin());
60  it != well_path_fnames.end();
61  ++it)
62  {
63  INFO("PetrelInterface::PetrelInterface(): open well path file.");
64  std::ifstream in((*it).c_str());
65  if (in)
66  {
67  INFO("PetrelInterface::PetrelInterface(): \tdone.");
69  in.close();
70  }
71  else
72  {
73  WARN(
74  "PetrelInterface::PetrelInterface(): \tCould not open well "
75  "path file {:s}.",
76  it->c_str());
77  }
78  }
79 
80  // store data in GEOObject
81  geo_obj->addPointVec(std::unique_ptr<std::vector<GeoLib::Point*>>(pnt_vec),
82  _unique_name);
83  if (!well_vec->empty())
84  {
85  geo_obj->addStationVec(
86  std::unique_ptr<std::vector<GeoLib::Point*>>(well_vec),
87  _unique_name);
88  }
89  if (!ply_vec->empty())
90  {
91  geo_obj->addPolylineVec(
92  std::unique_ptr<std::vector<GeoLib::Polyline*>>(ply_vec),
93  _unique_name);
94  }
95 }
96 
97 void PetrelInterface::readPetrelSurface(std::istream& in)
98 {
99  char buffer[MAX_COLS_PER_ROW];
100  in.getline(buffer, MAX_COLS_PER_ROW);
101  std::string line(buffer);
102 
103  if (line.find("# Petrel Points with attributes") != std::string::npos)
104  {
105  // read header
106  // read Version string
107  in.getline(buffer, MAX_COLS_PER_ROW);
108  // read string BEGIN HEADER
109  in.getline(buffer, MAX_COLS_PER_ROW);
110 
111  in.getline(buffer, MAX_COLS_PER_ROW);
112  line = buffer;
113  while (line.find("END HEADER") == std::string::npos)
114  {
115  in.getline(buffer, MAX_COLS_PER_ROW);
116  line = buffer;
117  }
118 
119  // read points
120  std::size_t idx(pnt_vec->size());
121  while (in)
122  {
123  pnt_vec->push_back(new GeoLib::Point);
124  in >> *((*pnt_vec)[idx]);
125  if (!in)
126  {
127  delete (*pnt_vec)[idx];
128  pnt_vec->pop_back();
129  }
130  else
131  {
132  idx++;
133  }
134  }
135  }
136  else
137  {
138  WARN(
139  "PetrelInterface::readPetrelSurface(): problem reading petrel "
140  "points from line\n'{:s}'.",
141  line);
142  }
143 }
144 
146 {
147  char buffer[MAX_COLS_PER_ROW];
148  in.getline(buffer, MAX_COLS_PER_ROW);
149  std::string line(buffer);
150 
151  if (line.find("# WELL TRACE FROM PETREL") != std::string::npos)
152  {
153  // read header
154  // read well name
155  in.getline(buffer, MAX_COLS_PER_ROW);
156  line = buffer;
157  std::list<std::string> str_list(BaseLib::splitString(line, ' '));
158  std::list<std::string>::const_iterator it(str_list.begin());
159  while (it != str_list.end())
160  {
161  INFO("PetrelInterface::readPetrelWellTrace(): well name: {:s}.",
162  it->c_str());
163  ++it;
164  }
165 
166  // read well head x coordinate
167  in.getline(buffer, MAX_COLS_PER_ROW);
168  line = buffer;
169  str_list = BaseLib::splitString(line, ' ');
170  it = str_list.begin();
171  while (it != str_list.end())
172  {
173  INFO(
174  "PetrelInterface::readPetrelWellTrace(): well head x coord: "
175  "{:s}.",
176  it->c_str());
177  ++it;
178  }
179  it = (str_list.end())--;
180  --it;
181  char* buf;
182  double well_head_x(strtod((*it).c_str(), &buf));
183 
184  // read well head y coordinate
185  in.getline(buffer, MAX_COLS_PER_ROW);
186  line = buffer;
187  str_list = BaseLib::splitString(line, ' ');
188  it = str_list.begin();
189  while (it != str_list.end())
190  {
191  INFO(
192  "PetrelInterface::readPetrelWellTrace(): well head y coord: "
193  "{:s}.",
194  it->c_str());
195  ++it;
196  }
197  it = (str_list.end())--;
198  --it;
199  double well_head_y(strtod((*it).c_str(), &buf));
200 
201  // read well KB
202  in.getline(buffer, MAX_COLS_PER_ROW);
203  line = buffer;
204  str_list = BaseLib::splitString(line, ' ');
205  it = str_list.begin();
206  while (it != str_list.end())
207  {
208  INFO("PetrelInterface::readPetrelWellTrace(): well kb entry: {:s}.",
209  it->c_str());
210  ++it;
211  }
212  it = (str_list.end())--;
213  --it;
214  double well_kb(strtod((*it).c_str(), &buf));
215 
216  INFO("PetrelInterface::readPetrelWellTrace(): {:f}, {:f}, {:f}.",
217  well_head_x,
218  well_head_y,
219  well_kb);
220  double const depth = 0.0;
221  std::string const borehole_name = "";
222  int const date = 0;
223  well_vec->push_back(new GeoLib::StationBorehole(
224  well_head_x, well_head_y, well_kb, depth, borehole_name, date));
225 
226  // read well type
227  in.getline(buffer, MAX_COLS_PER_ROW);
228  // std::string type(*((str_list.end())--));
229 
231  }
232 }
233 
235 {
236  char buffer[MAX_COLS_PER_ROW];
237  in.getline(buffer, MAX_COLS_PER_ROW);
238  std::string line(buffer);
239 
240  // read yet another header line
241  in.getline(buffer, MAX_COLS_PER_ROW);
242  line = buffer;
243  while (line[0] == '#')
244  {
245  in.getline(buffer, MAX_COLS_PER_ROW);
246  line = buffer;
247  }
248 
249  // read column information
250  std::list<std::string> str_list = BaseLib::splitString(line, ' ');
251  auto it = str_list.begin();
252  while (it != str_list.end())
253  {
254  INFO(
255  "PetrelInterface::readPetrelWellTraceData(): column information: "
256  "{:s}.",
257  it->c_str());
258  ++it;
259  }
260 
261  // read points
262  double md;
263  double x;
264  double y;
265  double z;
266  double tvd;
267  double dx;
268  double dy;
269  double azim;
270  double incl;
271  double dls;
272  in.getline(buffer, MAX_COLS_PER_ROW);
273  line = buffer;
274  while (in)
275  {
276  if (line.size() > 1 && line[0] != '#')
277  {
278  std::stringstream stream(line);
279  stream >> md;
280  stream >> x >> y >> z;
281  // pnt_vec->push_back (new GeoLib::Point (x,y,z));
282  static_cast<GeoLib::StationBorehole*>(
283  (*well_vec)[well_vec->size() - 1])
284  ->addSoilLayer(x, y, z, "unknown");
285  stream >> tvd >> dx >> dy >> azim >> incl >> dls;
286  }
287  in.getline(buffer, MAX_COLS_PER_ROW);
288  line = buffer;
289  }
290 }
291 } // end namespace FileIO
Definition of the GEOObjects class.
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
void WARN(char const *fmt, Args const &... args)
Definition: Logging.h:37
Definition of the PetrelInterface class.
Definition of the StationBorehole class.
Definition of string helper functions.
void readPetrelSurface(std::istream &in)
std::vector< GeoLib::Point * > * pnt_vec
std::vector< GeoLib::Point * > * well_vec
void readPetrelWellTrace(std::istream &in)
void readPetrelWellTraceData(std::istream &in)
static const std::size_t MAX_COLS_PER_ROW
std::vector< GeoLib::Polyline * > * ply_vec
PetrelInterface(std::list< std::string > &sfc_fnames, std::list< std::string > &well_path_fnames, std::string &unique_model_name, GeoLib::GEOObjects *geo_obj)
Container class for geometric objects.
Definition: GEOObjects.h:61
void addStationVec(std::unique_ptr< std::vector< Point * >> stations, std::string &name)
Adds a vector of stations with the given name and colour to GEOObjects.
Definition: GEOObjects.cpp:122
void addPointVec(std::unique_ptr< std::vector< Point * >> points, std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> pnt_id_name_map=nullptr, double eps=std::sqrt(std::numeric_limits< double >::epsilon()))
Definition: GEOObjects.cpp:51
void addPolylineVec(std::unique_ptr< std::vector< Polyline * >> lines, const std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> ply_names=nullptr)
Definition: GEOObjects.cpp:150
A borehole as a geometric object.
std::vector< std::string > splitString(std::string const &str)
Definition: StringTools.cpp:28
TemplateElement< PointRule1 > Point
Definition: Point.h:20