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
|
#include <string>
#include <petscmat.h>
#include "options.hpp"
void print_usage(const std::string & invocation)
{
PetscPrintf(PETSC_COMM_WORLD, "Usage:\n");
PetscPrintf(PETSC_COMM_WORLD, "%s %s\n", invocation.c_str(), usage_args.c_str());
}
void print_help(const std::string & invocation)
{
print_usage(invocation);
PetscPrintf(PETSC_COMM_WORLD, "FIXME: Write help.\n");
}
int parse_opts(int argc, char ** argv, Options & opts)
{
std::string invocation(argv[0]);
for (int i = 1; i < argc; ++i)
{
std::string arg(argv[i]);
if (arg == std::string("-h") || arg == std::string("--help"))
{
print_help(invocation);
return 2;
}
else if (arg == std::string("-l") || arg == std::string("--laplacian"))
{
if (i+1 < argc && argv[i+1][0] != '-')
opts.infile = std::string(argv[++i]);
else
{
PetscPrintf(PETSC_COMM_WORLD, "Missing argument to --laplacian.\n");
print_usage(invocation);
return 1;
}
}
else if (arg == std::string("--vals"))
{
if (i+1 < argc && argv[i+1][0] != '-')
opts.outfile_vals = std::string(argv[++i]);
else
{
PetscPrintf(PETSC_COMM_WORLD, "Missing argument to --vals.\n");
print_usage(invocation);
return 1;
}
}
else if (arg == std::string("--vecs"))
{
if (i+1 < argc && argv[i+1][0] != '-')
opts.outfile_vecs = std::string(argv[++i]);
else
{
PetscPrintf(PETSC_COMM_WORLD, "Missing argument to --vecs.\n");
print_usage(invocation);
return 1;
}
}
else
{
PetscPrintf(PETSC_COMM_WORLD, "The argument %s will be dealt with by PETSc/SLEPc if they understand it. Otherwise it will be silently ignored.\n", arg.c_str());
}
}
// Begin options validation.
if (opts.infile.empty())
{
PetscPrintf(PETSC_COMM_WORLD, "Missing Laplacian file.\n");
print_usage(invocation);
return 1;
}
if (opts.outfile_vecs.empty())
{
PetscPrintf(PETSC_COMM_WORLD, "Missing output eigenvectors file.\n");
print_usage(invocation);
return 1;
}
if (opts.outfile_vals.empty())
{
PetscPrintf(PETSC_COMM_WORLD, "Missing output eigenvalues file.\n");
print_usage(invocation);
return 1;
}
// End validation.
return 0;
}
|