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