-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathargparse.cpp
More file actions
63 lines (53 loc) · 1.73 KB
/
Copy pathargparse.cpp
File metadata and controls
63 lines (53 loc) · 1.73 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
// This program 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.
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#include "argparse.hpp"
#include <iostream>
#include <stdexcept>
#ifdef NEXT_MPI
#include <mpi.h>
#endif
namespace next {
Arguments parse_arguments(int argc, char** argv, int rank)
{
if (argc != 6) {
// Only rank 0 prints usage
if (rank == 0) {
std::cerr << "Usage: next <input.txt> <threads> <dt> <dump_interval> <vtk|vtu|hdf5>\n";
}
#ifdef NEXT_MPI
MPI_Finalize();
#endif
std::exit(1);
}
Arguments args;
args.input_file = argv[1];
args.threads = std::stoi(argv[2]);
args.dt = std::stod(argv[3]);
args.dump_interval = std::stod(argv[4]);
std::string fmt = argv[5];
if (fmt == "vtk") {
args.format = OutputFormat::VTK;
} else if (fmt == "vtu") {
args.format = OutputFormat::VTU;
} else if (fmt == "hdf5") {
args.format = OutputFormat::HDF5;
} else {
if (rank == 0) {
std::cerr << "Choose a file format: vtk, vtu, or hdf5\n";
}
#ifdef NEXT_MPI
MPI_Finalize();
#endif
std::exit(1);
}
return args;
}
} // namespace next