Stride Reference Manual  1.0
run/main.cpp
Go to the documentation of this file.
1 /*
2  * This is free software: you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * any later version.
6  * The software is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  * You should have received a copy of the GNU General Public License
11  * along with the software. If not, see <http://www.gnu.org/licenses/>.
12  *
13  * Copyright 2015, Willem L, Kuylen E, Stijven S & Broeckhove J
14  */
15 
21 #include <vector>
22 #include <string>
23 
24 #include <tclap/CmdLine.h>
25 
26 #include "Runner.h"
27 
28 using namespace std;
29 using namespace stride;
30 using namespace run;
31 using namespace TCLAP;
32 
33 int main(int argc, char** argv) {
34  int exit_status = EXIT_SUCCESS;
35  try {
36  Runner::setup();
37 
38  // Parse command line.
39  CmdLine cmd("stride", ' ', "2.0", false);
40  ValueArg<string> config_file_Arg("c", "config", "Config File", false,
41  "", "filename", cmd);
42  ValueArg<unsigned int> timestamp_replay_Arg("t", "timestamp", "Replay from Timestamp", false,
43  0, "integer", cmd);
44  ValueArg<string> simulator_mode_Arg("m", "mode", "Simulator Mode (initial/extend/replay/extract)", false,
45  "initial", "mode", cmd);
46  ValueArg<string> hdf5_file_Arg("f", "hdf5_file", "HDF5 file (only used for mode 'extract')", false,
47  "", "filename", cmd);
48  MultiArg<string> overrides_Arg("o", "override", "Override the configuration", false,
49  "string", cmd);
50  cmd.parse(argc, argv);
51 
52  auto run_mode = SimulatorRunMode::getRunMode(simulator_mode_Arg.getValue());
53  if (run_mode != RunMode::Extract and config_file_Arg.getValue() == "") {
54  cout << "All modes except 'extract' require a configuration file (-c flag)." << endl;
55  return EXIT_FAILURE;
56  }
57 
58  if (run_mode == RunMode::Extract) {
59  if (hdf5_file_Arg.getValue() == "") {
60  cout << "'extract' mode requires a file (-f flag)" << endl;
61  return EXIT_FAILURE;
62  }
63 
64  // TODO: where to write this?
65  Hdf5Loader::extractConfigs(hdf5_file_Arg.getValue());
66  } else {
67  Runner runner(overrides_Arg.getValue(), config_file_Arg.getValue(), run_mode,
68  timestamp_replay_Arg.getValue());
69  runner.printInfo();
70  runner.initSimulators();
71  runner.run();
72  }
73  } catch (exception& e) {
74  exit_status = EXIT_FAILURE;
75  cerr << endl << "Exception: " << e.what() << endl;
76  } catch (...) {
77  exit_status = EXIT_FAILURE;
78  cerr << endl << "Unknown exception thrown." << endl;
79  }
80 
81  return exit_status;
82 }
Helper for parsing the config, and starting the simulators.
Definition: Runner.h:39
Time Dependent Person DataType.
Definition: NoBehaviour.h:17
STL namespace.
int main(int argc, char **argv)
Definition: run/main.cpp:33