tadd command line arguments for help and version - slidergrid - grid of elastic… | |
git clone git://src.adamsgaard.dk/slidergrid | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 5d6e81a04a1e2fe6151185a4afeab15f67fc41b7 | |
parent f7efea53cfef992b109b9f461eecbd5d6fa0edac | |
Author: Anders Damsgaard <[email protected]> | |
Date: Wed, 16 Mar 2016 15:01:22 -0700 | |
add command line arguments for help and version | |
Diffstat: | |
M slidergrid/main.c | 53 ++++++++++++++++++++++++++++++ | |
M slidergrid/simulation.c | 29 +++++++++++++++-------------- | |
M slidergrid/simulation.h | 1 + | |
3 files changed, 69 insertions(+), 14 deletions(-) | |
--- | |
diff --git a/slidergrid/main.c b/slidergrid/main.c | |
t@@ -1,17 +1,70 @@ | |
#include <stdio.h> | |
#include <stdlib.h> | |
+#include <string.h> | |
#include "slider.h" | |
#include "grid.h" | |
#include "simulation.h" | |
+const char* VERSION = "beta-0.1"; | |
+ | |
+void print_usage(char* argv0) | |
+{ | |
+ printf("%s: simulate a grid of bonded sliders\n" | |
+ "webpage: https://github.com/anders-dc/slidergrid\n" | |
+ "usage: %s [OPTION[S]]\n" | |
+ "options:\n" | |
+ " -h, --help\t\tprint this information\n" | |
+ " -V, --version \tprint version information and exit\n" | |
+ , argv0, argv0); | |
+} | |
+ | |
+void print_version(char* argv0) | |
+{ | |
+ printf("%s: simulate a grid of bonded sliders\n" | |
+ "webpage: https://github.com/anders-dc/slidergrid\n" | |
+ "version: %s\n" | |
+ "author: Anders Damsgaard, [email protected]\n" | |
+ "This software is free software, see LICENSE for details.\n" | |
+ , argv0, VERSION); | |
+} | |
int main(int argc, char** argv) | |
{ | |
int i; | |
+ // default values of command-line flags | |
+ int verbose = 0; | |
+ | |
+ // parse command-line arguments | |
+ for (i=1; i<argc; i++) { | |
+ | |
+ if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { | |
+ print_usage(argv[0]); | |
+ return 0; | |
+ } | |
+ | |
+ if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) { | |
+ print_version(argv[0]); | |
+ return 0; | |
+ } | |
+ | |
+ | |
+ | |
+ } | |
+ | |
+ | |
+ | |
+ | |
+ | |
+ | |
+ | |
+ | |
// external function which defines the simulation setup and parameters | |
simulation sim = setup_simulation(); | |
+ if (verbose == 1) | |
+ sim.verbose = 1; | |
+ | |
// set initial values for the sliders | |
for (i=0; i<sim.N; i++) | |
initialize_slider_values(sim.sliders[i]); | |
diff --git a/slidergrid/simulation.c b/slidergrid/simulation.c | |
t@@ -3,6 +3,21 @@ | |
#include "slider.h" | |
#include "simulation.h" | |
+simulation create_simulation() | |
+{ | |
+ simulation sim; | |
+ sim.N = 0; | |
+ sim.time = 0.0; | |
+ sim.time_end = 0.0; | |
+ sim.dt = 0.1; | |
+ sim.iteration = 0; | |
+ sim.bond_length_limit = 0; | |
+ sim.id = "unnamed"; | |
+ sim.file_interval = 0.0; | |
+ sim.verbose = 0; | |
+ return sim; | |
+} | |
+ | |
int check_simulation_values(const simulation sim) | |
{ | |
int return_status = 0; | |
t@@ -63,20 +78,6 @@ int check_simulation_values(const simulation sim) | |
return return_status; | |
} | |
-simulation create_simulation() | |
-{ | |
- simulation sim; | |
- sim.N = 0; | |
- sim.time = 0.0; | |
- sim.time_end = 0.0; | |
- sim.dt = 0.1; | |
- sim.iteration = 0; | |
- sim.bond_length_limit = 0; | |
- sim.id = "unnamed"; | |
- sim.file_interval = 0.0; | |
- return sim; | |
-} | |
- | |
Float find_time_step(const slider* sliders, const int N, const Float safety) | |
{ | |
Float smallest_mass = 1.0e20; | |
diff --git a/slidergrid/simulation.h b/slidergrid/simulation.h | |
t@@ -13,6 +13,7 @@ typedef struct { | |
Float bond_length_limit; | |
char* id; | |
Float file_interval; | |
+ int verbose; | |
} simulation; | |
// create simulation with default values |