-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPetrelInterface.cpp
More file actions
242 lines (218 loc) · 6.55 KB
/
Copy pathPetrelInterface.cpp
File metadata and controls
242 lines (218 loc) · 6.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/**
* \file
* \author Thomas Fischer
* \date 2010-02-16
* \brief Implementation of the PetrelInterface class.
*
* \copyright
* Copyright (c) 2012-2015, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
* @file PetrelInterface.cpp
* @date 2010-02-16
* @author Thomas Fischer
*/
#include "PetrelInterface.h"
#include <fstream>
#include <logog/include/logog.hpp>
#include "BaseLib/StringTools.h"
#include "GeoLib/StationBorehole.h"
#include "GeoLib/GEOObjects.h"
namespace FileIO
{
PetrelInterface::PetrelInterface(std::list<std::string> &sfc_fnames,
std::list<std::string> &well_path_fnames,
std::string &unique_model_name, GeoLib::GEOObjects* geo_obj) :
_unique_name(unique_model_name), pnt_vec(new std::vector<GeoLib::Point*>),
well_vec(new std::vector<GeoLib::Point*>), ply_vec(new std::vector<GeoLib::Polyline*>)
{
for (std::list<std::string>::const_iterator it(sfc_fnames.begin()); it
!= sfc_fnames.end(); ++it)
{
INFO("PetrelInterface::PetrelInterface(): open surface file.");
std::ifstream in((*it).c_str());
if (in)
{
INFO("PetrelInterface::PetrelInterface(): \tdone.");
readPetrelSurface(in);
in.close();
}
else
WARN("PetrelInterface::PetrelInterface(): \tCould not open file %s.",
it->c_str());
}
for (std::list<std::string>::const_iterator it(well_path_fnames.begin()); it
!= well_path_fnames.end(); ++it)
{
INFO("PetrelInterface::PetrelInterface(): open well path file.");
std::ifstream in((*it).c_str());
if (in)
{
INFO("PetrelInterface::PetrelInterface(): \tdone.");
readPetrelWellTrace(in);
in.close();
}
else
WARN("PetrelInterface::PetrelInterface(): \tCould not open well path file %s.", it->c_str());
}
// store data in GEOObject
geo_obj->addPointVec(std::unique_ptr<std::vector<GeoLib::Point*>>(pnt_vec),
_unique_name);
if (well_vec->size() > 0)
geo_obj->addStationVec(
std::unique_ptr<std::vector<GeoLib::Point*>>(well_vec),
_unique_name);
if (ply_vec->size() > 0)
geo_obj->addPolylineVec(
std::unique_ptr<std::vector<GeoLib::Polyline*>>(ply_vec),
_unique_name);
}
PetrelInterface::~PetrelInterface()
{}
void PetrelInterface::readPetrelSurface(std::istream &in)
{
char buffer[MAX_COLS_PER_ROW];
in.getline(buffer, MAX_COLS_PER_ROW);
std::string line(buffer);
if (line.find("# Petrel Points with attributes") != std::string::npos)
{
// read header
// read Version string
in.getline(buffer, MAX_COLS_PER_ROW);
line = buffer;
// read string BEGIN HEADER
in.getline(buffer, MAX_COLS_PER_ROW);
line = buffer;
in.getline(buffer, MAX_COLS_PER_ROW);
line = buffer;
while (line.find("END HEADER") == std::string::npos)
{
in.getline(buffer, MAX_COLS_PER_ROW);
line = buffer;
}
// read points
std::size_t idx(pnt_vec->size());
while (in)
{
pnt_vec->push_back(new GeoLib::Point);
in >> *((*pnt_vec)[idx]);
if (!in)
{
delete (*pnt_vec)[idx];
pnt_vec->pop_back();
}
else
idx++;
}
} else
WARN("PetrelInterface::readPetrelSurface(): problem reading petrel points from line\n\"%s\".",
line.c_str());
}
void PetrelInterface::readPetrelWellTrace(std::istream &in)
{
char buffer[MAX_COLS_PER_ROW];
in.getline(buffer, MAX_COLS_PER_ROW);
std::string line(buffer);
if (line.find("# WELL TRACE FROM PETREL") != std::string::npos)
{
// read header
// read well name
in.getline(buffer, MAX_COLS_PER_ROW);
line = buffer;
std::list<std::string> str_list(BaseLib::splitString(line, ' '));
std::list<std::string>::const_iterator it(str_list.begin());
while (it != str_list.end()) {
INFO("PetrelInterface::readPetrelWellTrace(): well name: %s.", it->c_str());
++it;
}
// read well head x coordinate
in.getline(buffer, MAX_COLS_PER_ROW);
line = buffer;
str_list = BaseLib::splitString(line, ' ');
it = str_list.begin();
while (it != str_list.end()) {
INFO("PetrelInterface::readPetrelWellTrace(): well head x coord: %s.", it->c_str());
++it;
}
it = (str_list.end())--;
--it;
char* buf;
double well_head_x(strtod((*it).c_str(), &buf));
// read well head y coordinate
in.getline(buffer, MAX_COLS_PER_ROW);
line = buffer;
str_list = BaseLib::splitString(line, ' ');
it = str_list.begin();
while (it != str_list.end()) {
INFO("PetrelInterface::readPetrelWellTrace(): well head y coord: %s.", it->c_str());
++it;
}
it = (str_list.end())--;
--it;
double well_head_y(strtod((*it).c_str(), &buf));
// read well KB
in.getline(buffer, MAX_COLS_PER_ROW);
line = buffer;
str_list = BaseLib::splitString(line, ' ');
it = str_list.begin();
while (it != str_list.end()) {
INFO("PetrelInterface::readPetrelWellTrace(): well kb entry: %s.", it->c_str());
++it;
}
it = (str_list.end())--;
--it;
double well_kb(strtod((*it).c_str(), &buf));
INFO("PetrelInterface::readPetrelWellTrace(): %f, %f, %f.",
well_head_x,
well_head_y,
well_kb);
well_vec->push_back(new GeoLib::StationBorehole(well_head_x, well_head_y, well_kb));
// read well type
in.getline(buffer, MAX_COLS_PER_ROW);
// std::string type(*((str_list.end())--));
readPetrelWellTraceData(in);
}
}
void PetrelInterface::readPetrelWellTraceData(std::istream &in)
{
char buffer[MAX_COLS_PER_ROW];
in.getline(buffer, MAX_COLS_PER_ROW);
std::string line(buffer);
// read yet another header line
in.getline(buffer, MAX_COLS_PER_ROW);
line = buffer;
while (line.substr(0, 1).compare("#") == 0)
{
in.getline(buffer, MAX_COLS_PER_ROW);
line = buffer;
}
// read column information
std::list<std::string> str_list = BaseLib::splitString(line, ' ');
std::list<std::string>::const_iterator it = str_list.begin();
while (it != str_list.end()) {
INFO("PetrelInterface::readPetrelWellTraceData(): column information: %s.", it->c_str());
++it;
}
// read points
double md, x, y, z, tvd, dx, dy, azim, incl, dls;
in.getline(buffer, MAX_COLS_PER_ROW);
line = buffer;
while (in)
{
if (line.size() > 1 && line.substr(0, 1).compare("#") != 0)
{
std::stringstream stream(line);
stream >> md;
stream >> x >> y >> z;
// pnt_vec->push_back (new GeoLib::Point (x,y,z));
static_cast<GeoLib::StationBorehole*> ((*well_vec)[well_vec->size() - 1])->addSoilLayer(
x, y, z, "unknown");
stream >> tvd >> dx >> dy >> azim >> incl >> dls;
}
in.getline(buffer, MAX_COLS_PER_ROW);
line = buffer;
}
}
} // end namespace FileIO