#include #include #include "options.hpp" void print_usage(const std::string & invocation) { std::cerr << "Usage:" << std::endl; std::cerr << invocation << " " << usage_args << std::endl; } void print_help(const std::string & invocation) { print_usage(invocation); std::cerr << "FIXME: Write help." << std::endl; } 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 { std::cerr << "Missing argument to --laplacian." << std::endl; 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 { std::cerr << "Missing argument to --vals." << std::endl; 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 { std::cerr << "Missing argument to --vecs." << std::endl; print_usage(invocation); return 1; } } else { std::cout << "The argument \"" << arg << "\" will be dealt with by PETSc/SLEPc if they understand it. Otherwise it will be silently ignored." << std::endl; } } // Begin options validation. if (opts.infile.empty()) { std::cerr << "Missing Laplacian file." << std::endl; print_usage(invocation); return 1; } if (opts.outfile_vecs.empty()) { std::cerr << "Missing output eigenvectors file." << std::endl; print_usage(invocation); return 1; } if (opts.outfile_vals.empty()) { std::cerr << "Missing output eigenvalues file." << std::endl; print_usage(invocation); return 1; } // End validation. return 0; }