Line data Source code
1 : /* 2 : * Copyright (c) 2016 Sebastian Weber, Henri Menke. All rights reserved. 3 : * 4 : * This file is part of the pairinteraction library. 5 : * 6 : * The pairinteraction library is free software: you can redistribute it and/or modify 7 : * it under the terms of the GNU Lesser General Public License as published by 8 : * the Free Software Foundation, either version 3 of the License, or 9 : * (at your option) any later version. 10 : * 11 : * The pairinteraction library is distributed in the hope that it will be useful, 12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 : * GNU Lesser General Public License for more details. 15 : * 16 : * You should have received a copy of the GNU Lesser General Public License 17 : * along with the pairinteraction library. If not, see <http://www.gnu.org/licenses/>. 18 : */ 19 : #include "Interface.hpp" 20 : 21 : #include <iostream> 22 : #include <string> 23 : 24 0 : static void print_usage(std::ostream &os, int status) { 25 : os << "Usage:\n" 26 : " -? [ --help ] produce this help message\n" 27 : " -c [ --config ] arg Path to config JSON file\n" 28 : " -o [ --output ] arg Path to cache JSON file\n" 29 0 : " -t [ --type ] arg Type of calculation: arg = real|complex\n"; 30 0 : std::exit(status); 31 : } 32 : 33 2 : int main(int argc, char *argv[]) { 34 2 : if (argc == 1) { 35 0 : print_usage(std::cout, EXIT_SUCCESS); 36 : } 37 : 38 4 : std::string config, output, type; 39 : 40 2 : int optind = 1; 41 8 : while (optind < argc) { 42 6 : std::string opt = argv[optind]; 43 6 : if (opt == "-?" || opt == "--help") { 44 0 : print_usage(std::cout, EXIT_SUCCESS); 45 6 : } else if (opt == "-c" || opt == "--config") { 46 2 : ++optind; 47 2 : if (!(optind < argc)) { 48 0 : std::cerr << "Option " << opt << " requires an argument\n"; 49 0 : std::exit(EXIT_FAILURE); 50 : } 51 2 : config = argv[optind]; 52 4 : } else if (opt == "-o" || opt == "--output") { 53 2 : ++optind; 54 2 : if (!(optind < argc)) { 55 0 : std::cerr << "Option " << opt << " requires an argument\n"; 56 0 : std::exit(EXIT_FAILURE); 57 : } 58 2 : output = argv[optind]; 59 2 : } else if (opt == "-t" || opt == "--type") { 60 2 : ++optind; 61 2 : if (!(optind < argc)) { 62 0 : std::cerr << "Option " << opt << " requires an argument\n"; 63 0 : std::exit(EXIT_FAILURE); 64 : } 65 2 : type = argv[optind]; 66 : } else { 67 0 : std::cerr << "Unknown option: " << opt << "\n"; 68 0 : print_usage(std::cerr, EXIT_FAILURE); 69 : } 70 6 : ++optind; 71 : } 72 : 73 2 : if (config.empty()) { 74 0 : std::cerr << "Option --config is required\n"; 75 0 : std::exit(EXIT_FAILURE); 76 : } 77 : 78 2 : if (output.empty()) { 79 0 : std::cerr << "Option --output is required\n"; 80 0 : std::exit(EXIT_FAILURE); 81 : } 82 : 83 2 : if (type.empty()) { 84 0 : std::cerr << "Option --type is required\n"; 85 0 : std::exit(EXIT_FAILURE); 86 : } 87 : 88 2 : if (type == "complex") { 89 1 : return compute<std::complex<double>>(config, output); 90 1 : } else if (type == "real") { 91 1 : return compute<double>(config, output); 92 : } else { 93 0 : std::cerr << "Option --type can only be 'real' or 'complex' but is '" << type << "'\n"; 94 0 : std::exit(EXIT_FAILURE); 95 : } 96 : }