GCC Code Coverage Report


Directory: ./
File: src/main.cpp
Date: 2024-04-18 12:22:13
Exec Total Coverage
Lines: 0 40 0.0%
Functions: 0 1 0.0%
Branches: 0 10 0.0%

Line Branch Exec Source
1 #include "simulation.hpp"
2
3 #include <cstdlib>
4 #include <exception>
5 #include <getopt.h>
6
7 int main(int argc, char *argv[]) {
8 std::string outputPath = ""; // Will be handled by Output if empty string given
9 std::string configFile = "config.yaml";
10 std::string outputFormat = "H5MD";
11 int autosaveMinutes = 30;
12 bool graphics = false;
13 bool dryrun = false;
14
15 // Read arguments
16 int opt;
17 while (1) {
18 static struct option long_options[] = {
19 {"config", required_argument, NULL, 'c'},
20 {"output-path", required_argument, NULL, 'p'},
21 {"output-format", required_argument, NULL, 'f'},
22 {"autosave", required_argument, NULL, 's'},
23 {"graphics", no_argument, NULL, 'g'},
24 {"dry-run", no_argument, NULL, 'd'},
25 {"help", no_argument, NULL, 'h'},
26 {"version", no_argument, NULL, 'v'},
27 {NULL, 0, NULL, 0},
28 };
29 int option_index = 0;
30 opt = getopt_long(argc, argv, "c:p:f:s:gdhv", long_options, &option_index);
31 if (opt == -1) {
32 break;
33 }
34
35 switch (opt) {
36 case 'c': // --config
37 configFile = optarg;
38 break;
39 case 'p': // --output-path
40 outputPath = optarg;
41 break;
42 case 'f': // --output-format
43 outputFormat = optarg;
44 break;
45 case 's': // --output-format
46 autosaveMinutes = std::stoi(optarg);
47 break;
48 case 'g': // --graphics
49 graphics = true;
50 break;
51 case 'd': // --dry-run
52 dryrun = true;
53 std::clog << "WARNING: This will be a dry-run. Nothing will actually be simulated!"
54 << std::endl;
55 break;
56 case 'h': // --help
57 std::cout << "Usage:"
58 "\n-c/--config <config file>"
59 "\n\tsee config.template.yaml for reference"
60 "\n\tdefault: config.yaml"
61 "\n-p/--output-path <output path>"
62 "\n\tdefault: results/<timestamp> (YYYY_MM_DD-hh-mm-ss)"
63 "\n-f/--output-format {ASCII|H5MD}"
64 "\n\tdefault: H5MD"
65 "\n-g<framerate>/--graphics=<framerate>"
66 "\n\t(only available when built with graphics support)"
67 "\n\tdefault mode: no graphics"
68 "\n\tdefault framerate: 60"
69 "\n-d/--dry-run"
70 "\n-v/--version"
71 "\n-h/--help"
72 << std::endl;
73 return EXIT_SUCCESS;
74 case 'v': // --version
75 std::cout << programInfo();
76 std::cout << std::endl;
77 return EXIT_SUCCESS;
78 default:
79 std::clog << "ERROR: Invalid options given. Call program with -h for help." << std::endl;
80 return EXIT_FAILURE;
81 }
82 }
83
84 Simulation simulation(outputPath, outputFormat, autosaveMinutes, graphics);
85 int exitCode = simulation(configFile, dryrun);
86 return exitCode;
87 }
88