forked from OPM/opm-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharraylist.cpp
153 lines (119 loc) · 4.44 KB
/
arraylist.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
/*
Copyright 2021 Equinor ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iomanip>
#include <iostream>
#include <tuple>
#include <getopt.h>
#include <filesystem>
#include <sstream>
#include <opm/io/eclipse/EclFile.hpp>
#include <opm/io/eclipse/ERst.hpp>
using EclEntry = Opm::EclIO::EclFile::EclEntry;
static void printHelp() {
std::cout << "Usage: arraylist [OPTIONS] ECL_FILE_NAME"<<std::endl
<< "\nList all arrays found in an EclFile specified on the command line. \n\n"
<< "\nThe program has one option which will only work on unified restart files:\n\n"
<< "-h Print help and exit.\n"
<< "-r List array for a specific report time step number. Option only valid for a unified restart file. \n\n";
}
void print_array_list(const std::vector<EclEntry>& array_list, const std::vector<int>& element_size)
{
for (size_t n = 0; n < array_list.size(); n++ ){
auto array = array_list[n];
std::string name = std::get<0> ( array );
Opm::EclIO::eclArrType array_type = std::get<1> ( array );;
int64_t size = std::get<2> ( array );
std::string type_str;
switch ( array_type ) {
case Opm::EclIO::INTE:
type_str = "INTE";
break;
case Opm::EclIO::REAL:
type_str = "REAL";
break;
case Opm::EclIO::DOUB:
type_str = "DOUB";
break;
case Opm::EclIO::LOGI:
type_str = "LOGI";
break;
case Opm::EclIO::CHAR:
type_str = "CHAR";
break;
case Opm::EclIO::C0NN:
type_str = "C0NN";
break;
case Opm::EclIO::MESS:
type_str = "MESS";
break;
default:
throw std::runtime_error("unexpected array type" );
}
if ((type_str == "C0NN") && (element_size.size() > 0)) {
std::ostringstream ss;
ss << "C" << std::setw(3) << std::setfill('0') << element_size[n];
type_str = ss.str();
}
std::cout << std::left << std::setw ( 8 ) << name << " ";
std::cout << std::right << std::setw ( 10 ) << size << " ";
std::cout << type_str << std::endl;
}
}
int main(int argc, char **argv) {
int c = 0;
int reportStepNumber = -1;
bool specificReportStepNumber = false;
while ((c = getopt(argc, argv, "hr:")) != -1) {
switch (c) {
case 'h':
printHelp();
return 0;
case 'r':
specificReportStepNumber = true;
reportStepNumber = atoi(optarg);
break;
default:
return EXIT_FAILURE;
}
}
int argOffset = optind;
if(argOffset >= argc)
{
std::cerr<<"Eclipse file name is missing. Please provide it "
<<"as the last argument."<<std::endl<<std::endl;
printHelp();
return EXIT_FAILURE;
}
std::filesystem::path filename(argv[argOffset]);
std::string ext = filename.extension().string();
std::vector<EclEntry> array_list;
std::vector<int> element_size;
if ((specificReportStepNumber) and (ext == ".UNRST")){
Opm::EclIO::ERst rstfile(filename);
if (!rstfile.hasReportStepNumber(reportStepNumber)){
std::string message = "report step number " + std::to_string(reportStepNumber) + " not found ";
message = message + " in restart file " + filename.string();
std::cout << message << std::endl;
exit(1);
}
array_list = rstfile.listOfRstArrays(reportStepNumber);
} else {
Opm::EclIO::EclFile eclfile(filename);
array_list = eclfile.getList();
element_size = eclfile.getElementSizeList();
}
print_array_list(array_list, element_size);
return 0;
}