-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoopProjectFile.cpp
356 lines (298 loc) · 14.3 KB
/
LoopProjectFile.cpp
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#include "LoopProjectFile.h"
namespace LoopProjectFile {
LoopProjectFileResponse CreateBasicFile(std::string filename)
{
LoopProjectFileResponse resp = {0,""};
struct stat buffer;
if (stat(filename.c_str(), &buffer) == 0) {
resp = createErrorMsg(1,"File " + filename + " already exists");
}
netCDF::NcFile file(filename, netCDF::NcFile::replace, netCDF::NcFile::nc4);
if (file.isNull()) {
resp = createErrorMsg(1,"ERROR: Failure to open netCDF file " + filename);
} else {
LoopVersion::SetVersion(&file);
}
return resp;
}
bool OpenProjectFile(std::string filename, netCDF::NcFile& file, bool readOnly, bool verbose)
{
if (verbose) std::cout << "Accessing file named: " << filename << std::endl;
struct stat buffer;
if (stat(filename.c_str(),&buffer) != 0) {
if (verbose) std::cout << "File " << filename << " does not exist" << std::endl;
return true;
} else {
file.open(filename,
(readOnly?netCDF::NcFile::read : netCDF::NcFile::write),
netCDF::NcFile::nc4);
if (file.isNull()) {
return true;
}
}
return false;
}
void CloseProjectFile(netCDF::NcFile* file)
{
try {
if (!file->isNull() && file->isRootGroup()) file->close();
else std::cout << "Trying to close an invalid or already closed project file" << std::endl;
} catch (netCDF::exceptions::NcHdfErr &e) {
std::cout << e.what() << std::endl;
}
}
bool CheckFileValid(std::string filename, bool verbose)
{
bool valid = true;
netCDF::NcFile file;
if (!OpenProjectFile(filename, file, verbose)) {
if (verbose) std::cout << "Checking validity of loop project file " << filename << std::endl;
std::vector<int> xyzGridSize;
valid = LoopVersion::CheckVersionValid(&file,verbose);
valid = LoopExtents::CheckExtentsValid(&file,xyzGridSize,verbose);
valid = DataCollection::CheckDataCollectionValid(&file,verbose);
valid = ExtractedInformation::CheckExtractedInformationValid(&file,verbose);
valid = StructuralModels::CheckStructuralModelsValid(&file,xyzGridSize,verbose);
valid = GeophysicalModels::CheckGeophysicalModelsValid(&file,xyzGridSize,verbose);
valid = UncertaintyModels::CheckUncertaintyModelsValid(&file,xyzGridSize,verbose);
} else {
valid = false;
}
return valid;
}
LoopProjectFileResponse SetVersion(std::string filename, bool verbose)
{
LoopProjectFileResponse resp;
netCDF::NcFile file;
if (!OpenProjectFile(filename, file, false, verbose)) {
resp = LoopVersion::SetVersion(&file, verbose);
CloseProjectFile(&file);
} else {
std::cout << "Failure to open project file " << filename << std::endl;
}
return resp;
}
LoopVersion GetVersion(std::string filename, bool verbose)
{
LoopVersion version;
netCDF::NcFile file;
if (!OpenProjectFile(filename, file, true, verbose)) {
version = LoopVersion::GetVersion(&file, verbose);
CloseProjectFile(&file);
} else {
std::cout << "Failure to open project file " << filename << std::endl;
}
return version;
}
/*****************************************************************************/
/* FUNCTION MACROS USED TO STREAMLINE GETTER/SETTER FUNCTIONS */
/* ***SHOULD CHANGE TO TEMPLATES*** */
/*****************************************************************************/
#define LPF_OPEN_RUN(FILENAME,FUNCTION,CONTAINER,READONLY,VERBOSE) \
{\
LoopProjectFileResponse resp = {0,""};\
netCDF::NcFile file;\
if (!OpenProjectFile(FILENAME, file, READONLY, VERBOSE)) {\
resp = FUNCTION(&file, CONTAINER, VERBOSE);\
} else {\
std::cout << "Failure to open project file " << filename << std::endl;\
}\
return resp;\
}
#define LPF_OPEN_RUN_WITH_SHAPE(FILENAME,FUNCTION,CONTAINER,SHAPE,INDEX,READONLY,VERBOSE) \
{\
LoopProjectFileResponse resp = {0,""};\
netCDF::NcFile file;\
if (!OpenProjectFile(FILENAME, file, READONLY, VERBOSE)) {\
resp = FUNCTION(&file, CONTAINER, SHAPE, INDEX, VERBOSE);\
} else {\
std::cout << "Failure to open project file " << filename << std::endl;\
}\
return resp;\
}
/*****************************************************************************/
LoopProjectFileResponse GetExtents(std::string filename, LoopExtents& data, bool verbose)
{
LPF_OPEN_RUN(filename, LoopExtents::GetExtents, data, true, verbose);
}
LoopProjectFileResponse GetDataCollectionConfiguration(std::string filename, DataCollectionConfiguration& data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::GetDataCollectionConfiguration, data, true, verbose);
}
LoopProjectFileResponse GetDataCollectionSources(std::string filename, DataCollectionSources& data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::GetDataCollectionSources, data, true, verbose);
}
LoopProjectFileResponse GetStructuralModelsConfiguration(std::string filename, StructuralModelsConfiguration& data, bool verbose)
{
LPF_OPEN_RUN(filename, StructuralModels::GetStructuralModelsConfiguration, data, true, verbose);
}
LoopProjectFileResponse GetFaultObservations(std::string filename, std::vector<FaultObservation> &data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::GetFaultObservations, data, true, verbose);
}
LoopProjectFileResponse GetFoldObservations(std::string filename, std::vector<FoldObservation> &data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::GetFoldObservations, data, true, verbose);
}
LoopProjectFileResponse GetFoliationObservations(std::string filename, std::vector<FoliationObservation> &data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::GetFoliationObservations, data, true, verbose);
}
LoopProjectFileResponse GetDiscontinuityObservations(std::string filename, std::vector<DiscontinuityObservation> &data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::GetDiscontinuityObservations, data, true, verbose);
}
LoopProjectFileResponse GetStratigraphicObservations(std::string filename, std::vector<StratigraphicObservation> &data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::GetStratigraphicObservations, data, true, verbose);
}
LoopProjectFileResponse GetContacts(std::string filename, std::vector<ContactObservation> &data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::GetContactObservations, data, true, verbose);
}
LoopProjectFileResponse GetDrillholeObservations(std::string filename, std::vector<DrillholeObservation> &data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::GetDrillholeObservations, data, true, verbose);
}
LoopProjectFileResponse GetDrillholeProperites(std::string filename, std::vector<DrillholeProperty> &data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::GetDrillholeProperties, data, true, verbose);
}
LoopProjectFileResponse GetDrillholeSurveys(std::string filename, std::vector<DrillholeSurvey> &data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::GetDrillholeSurveys, data, true, verbose);
}
LoopProjectFileResponse GetFaultEvents(std::string filename, std::vector<FaultEvent> &data, bool verbose)
{
LPF_OPEN_RUN(filename, ExtractedInformation::GetFaultEvents, data, true, verbose);
}
LoopProjectFileResponse GetFoldEvents(std::string filename, std::vector<FoldEvent> &data, bool verbose)
{
LPF_OPEN_RUN(filename, ExtractedInformation::GetFoldEvents, data, true, verbose);
}
LoopProjectFileResponse GetFoliationEvents(std::string filename, std::vector<FoliationEvent> &data, bool verbose)
{
LPF_OPEN_RUN(filename, ExtractedInformation::GetFoliationEvents, data, true, verbose);
}
LoopProjectFileResponse GetDiscontinuityEvents(std::string filename, std::vector<DiscontinuityEvent> &data, bool verbose)
{
LPF_OPEN_RUN(filename, ExtractedInformation::GetDiscontinuityEvents, data, true, verbose);
}
LoopProjectFileResponse GetStratigraphicLayers(std::string filename, std::vector<StratigraphicLayer> &data, bool verbose)
{
LPF_OPEN_RUN(filename, ExtractedInformation::GetStratigraphicLayers, data, true, verbose);
}
LoopProjectFileResponse GetEventRelationships(std::string filename, std::vector<EventRelationship> &data, bool verbose)
{
LPF_OPEN_RUN(filename, ExtractedInformation::GetEventRelationships, data, true, verbose);
}
LoopProjectFileResponse GetDrillholeDescriptions(std::string filename, std::vector<DrillholeDescription> &data, bool verbose)
{
LPF_OPEN_RUN(filename, ExtractedInformation::GetDrillholeDescriptions, data, true, verbose);
}
LoopProjectFileResponse GetStructuralModel(std::string filename, std::vector<float> &data, std::vector<int> &dataShape, int index, bool verbose)
{
LPF_OPEN_RUN_WITH_SHAPE(filename, StructuralModels::GetStructuralModel, data, dataShape, index, true, verbose);
}
LoopProjectFileResponse GetGeophysicalModel(std::string filename, std::vector<float> &data, std::vector<int> &dataShape, int index, bool verbose)
{
LPF_OPEN_RUN_WITH_SHAPE(filename, GeophysicalModels::GetGeophysicalModel, data, dataShape, index, true, verbose);
}
LoopProjectFileResponse GetUncertaintyModel(std::string filename, std::vector<float> &data, std::vector<int> &dataShape, int index, bool verbose)
{
LPF_OPEN_RUN_WITH_SHAPE(filename, UncertaintyModels::GetUncertaintyModel, data, dataShape, index, true, verbose);
}
LoopProjectFileResponse SetExtents(std::string filename, LoopExtents data, bool verbose)
{
LPF_OPEN_RUN(filename, LoopExtents::SetExtents, data, false, verbose);
}
LoopProjectFileResponse SetDataCollectionConfiguration(std::string filename, DataCollectionConfiguration data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::SetDataCollectionConfiguration, data, false, verbose);
}
LoopProjectFileResponse SetDataCollectionSources(std::string filename, DataCollectionSources data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::SetDataCollectionSources, data, false, verbose);
}
LoopProjectFileResponse SetStructuralModelsConfiguration(std::string filename, StructuralModelsConfiguration data, bool verbose)
{
LPF_OPEN_RUN(filename, StructuralModels::SetStructuralModelsConfiguration, data, false, verbose);
}
LoopProjectFileResponse SetFaultObservations(std::string filename, std::vector<FaultObservation> data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::SetFaultObservations, data, false, verbose);
}
LoopProjectFileResponse SetFoldObservations(std::string filename, std::vector<FoldObservation> data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::SetFoldObservations, data, false, verbose);
}
LoopProjectFileResponse SetFoliationObservations(std::string filename, std::vector<FoliationObservation> data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::SetFoliationObservations, data, false, verbose);
}
LoopProjectFileResponse SetDiscontinuityObservations(std::string filename, std::vector<DiscontinuityObservation> data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::SetDiscontinuityObservations, data, false, verbose);
}
LoopProjectFileResponse SetStratigraphicObservations(std::string filename, std::vector<StratigraphicObservation> data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::SetStratigraphicObservations, data, false, verbose);
}
LoopProjectFileResponse SetContacts(std::string filename, std::vector<ContactObservation> data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::SetContactObservations, data, false, verbose);
}
LoopProjectFileResponse SetDrillholeObservations(std::string filename, std::vector<DrillholeObservation> data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::SetDrillholeObservations, data, false, verbose);
}
LoopProjectFileResponse SetDrillholeProperties(std::string filename, std::vector<DrillholeProperty> data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::SetDrillholeProperties, data, false, verbose);
}
LoopProjectFileResponse SetDrillholeSurveys(std::string filename, std::vector<DrillholeSurvey> data, bool verbose)
{
LPF_OPEN_RUN(filename, DataCollection::SetDrillholeSurveys, data, false, verbose);
}
LoopProjectFileResponse SetFaultEvents(std::string filename, std::vector<FaultEvent> data, bool verbose)
{
LPF_OPEN_RUN(filename, ExtractedInformation::SetFaultEvents, data, false, verbose);
}
LoopProjectFileResponse SetFoldEvents(std::string filename, std::vector<FoldEvent> data, bool verbose)
{
LPF_OPEN_RUN(filename, ExtractedInformation::SetFoldEvents, data, false, verbose);
}
LoopProjectFileResponse SetFoliationEvents(std::string filename, std::vector<FoliationEvent> data, bool verbose)
{
LPF_OPEN_RUN(filename, ExtractedInformation::SetFoliationEvents, data, false, verbose);
}
LoopProjectFileResponse SetDiscontinuityEvents(std::string filename, std::vector<DiscontinuityEvent> data, bool verbose)
{
LPF_OPEN_RUN(filename, ExtractedInformation::SetDiscontinuityEvents, data, false, verbose);
}
LoopProjectFileResponse SetStratigraphicLayers(std::string filename, std::vector<StratigraphicLayer> data, bool verbose)
{
LPF_OPEN_RUN(filename, ExtractedInformation::SetStratigraphicLayers, data, false, verbose);
}
LoopProjectFileResponse SetEventRelationships(std::string filename, std::vector<EventRelationship> data, bool verbose)
{
LPF_OPEN_RUN(filename, ExtractedInformation::SetEventRelationships, data, false, verbose);
}
LoopProjectFileResponse SetDrillholeDescriptions(std::string filename, std::vector<DrillholeDescription> data, bool verbose)
{
LPF_OPEN_RUN(filename, ExtractedInformation::SetDrillholeDescriptions, data, false, verbose);
}
LoopProjectFileResponse SetStructuralModel(std::string filename, std::vector<float> data, std::vector<int> dataShape, int index, bool verbose)
{
LPF_OPEN_RUN_WITH_SHAPE(filename, StructuralModels::SetStructuralModel, data, dataShape, index, false, verbose);
}
LoopProjectFileResponse SetGeophysicalModel(std::string filename, std::vector<float> data, std::vector<int> dataShape, int index, bool verbose)
{
LPF_OPEN_RUN_WITH_SHAPE(filename, GeophysicalModels::SetGeophysicalModel, data, dataShape, index, false, verbose);
}
LoopProjectFileResponse SetUncertaintyModel(std::string filename, std::vector<float> data, std::vector<int> dataShape, int index, bool verbose)
{
LPF_OPEN_RUN_WITH_SHAPE(filename, UncertaintyModels::SetUncertaintyModel, data, dataShape, index, false, verbose);
}
} // namespace LoopProjectFile