-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathmain.cpp
More file actions
81 lines (63 loc) · 1.91 KB
/
Copy pathmain.cpp
File metadata and controls
81 lines (63 loc) · 1.91 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
// MAIN PROGRAM FOR GEMINI3D
#include <iostream>
#include <vector>
#include <sstream>
#include <cstring>
#include <exception>
#include <filesystem>
static_assert(__cpp_lib_filesystem, "C++17 <filesystem> required");
namespace fs = std::filesystem;
#include <mpi.h>
#include "gemini3d.h"
#include "ffilesystem.h"
int main(int argc, char **argv) {
struct params s;
int myid;
int ierr = MPI_Init(&argc, &argv);
// CLI
if (argc < 2) {
help_gemini_bin();
MPI_Finalize();
return EXIT_FAILURE;
}
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-help") == 0) {
help_gemini_bin();
MPI_Finalize();
return EXIT_SUCCESS;
}
// simulation directory
fs::path out_dir(Ffs::expanduser(argv[1]));
if(! fs::is_directory(out_dir))
throw std::runtime_error("Gemini3D simulation output directory does not exist: " + out_dir.string());
// we don't have a C++ parser for Fortran namelist files,
// so read the namelist file directly in Fortran as usual.
s.fortran_nml = true;
// Prepare Gemini3D struct
std::strcpy(s.out_dir, out_dir.generic_string().c_str());
s.fortran_cli = false;
s.debug = false;
s.dryrun = false;
int lid2in = -1, lid3in = -1;
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
for (int i = 2; i < argc; i++) {
if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "-debug") == 0) s.debug = true;
if (strcmp(argv[i], "-dryrun") == 0) s.dryrun = true;
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
help_gemini_bin();
MPI_Finalize();
return EXIT_SUCCESS;
}
if (strcmp(argv[i], "-manual_grid") == 0) {
if (argc < i+1) {
MPI_Finalize();
throw std::runtime_error("-manual_grid lid2in lid3in");
}
lid2in = atoi(argv[i]);
lid3in = atoi(argv[i+1]);
}
}
gemini_main(&s, &lid2in, &lid3in);
if(MPI_Finalize())
throw std::runtime_error("MPI_Finalize failed");
return EXIT_SUCCESS;
}