From 8a66144c9118f8df80eba28c5b363fac574194da Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@gmail.com> Date: Sat, 08 Mar 2014 18:25:18 +0000 Subject: [PATCH] Parsing command line arguments is still kind-of messy, but it workds for force-from-tape and reset-iteration-count --- src/main.c | 55 ++++++++++++++------------- src/initial_distribution.h | 4 + src/io.c | 3 + src/initial_distribution.c | 1 src/general.h | 23 ----------- src/io.h | 31 +++++++++++++++ 6 files changed, 66 insertions(+), 51 deletions(-) diff --git a/src/general.h b/src/general.h index 8da1878..3308faa 100644 --- a/src/general.h +++ b/src/general.h @@ -265,29 +265,6 @@ -typedef struct { - long int nshell; - long int ncxmax; - long int ncymax; - long int nczmax; - long int npoly; - long int nmono; - long int pswitch; - char *multiprocessing; - long int brezveze0; - long int brezveze1; - long int brezveze2; - ts_double xk0; - ts_double dmax; - ts_double stepsize; - ts_double kspring; - ts_double pressure; - long int iterations; - long int inititer; - long int mcsweeps; - long int quiet; -} ts_tape; - /* GLOBAL VARIABLES */ int quiet; diff --git a/src/initial_distribution.c b/src/initial_distribution.c index 4d5f565..7601f13 100644 --- a/src/initial_distribution.c +++ b/src/initial_distribution.c @@ -10,6 +10,7 @@ #include "initial_distribution.h" #include "energy.h" #include "poly.h" +#include "io.h" ts_vesicle *initial_distribution_dipyramid(ts_uint nshell, ts_uint ncmax1, ts_uint ncmax2, ts_uint ncmax3, ts_double stepsize){ ts_fprintf(stdout,"Starting initial_distribution on vesicle with %u shells!...\n",nshell); diff --git a/src/initial_distribution.h b/src/initial_distribution.h index ef07da9..20bbf18 100644 --- a/src/initial_distribution.h +++ b/src/initial_distribution.h @@ -1,6 +1,8 @@ +#include "io.h" + + /** @brief initial bond length */ #define A0 1.2 - /** @brief Creates initial distribution of vertices * diff --git a/src/io.c b/src/io.c index d1a2e3e..d4a9cc4 100644 --- a/src/io.c +++ b/src/io.c @@ -333,7 +333,8 @@ { static struct option long_options[] = { - {"force-from-tape", no_argument, &force_from_tape, 1}, + {"force-from-tape", no_argument, &(command_line_args.force_from_tape), 1}, + {"reset-iteration-count", no_argument, &(command_line_args.reset_iteration_count), 1}, {"tape", no_argument, 0, 't'}, {"output-file", required_argument, 0, 'o'}, {"directory", required_argument, 0, 'd'}, diff --git a/src/io.h b/src/io.h index 8f14b68..c8dfd17 100644 --- a/src/io.h +++ b/src/io.h @@ -9,6 +9,37 @@ char path[1024]; int force_from_tape; + +typedef struct { + long int nshell; + long int ncxmax; + long int ncymax; + long int nczmax; + long int npoly; + long int nmono; + long int pswitch; + char *multiprocessing; + long int brezveze0; + long int brezveze1; + long int brezveze2; + ts_double xk0; + ts_double dmax; + ts_double stepsize; + ts_double kspring; + ts_double pressure; + long int iterations; + long int inititer; + long int mcsweeps; + long int quiet; +} ts_tape; + +typedef struct{ + ts_int force_from_tape; + ts_int reset_iteration_count; +} ts_args; + +ts_args command_line_args; + ts_bool parse_args(int argc, char **argv); diff --git a/src/main.c b/src/main.c index 506bd37..a89cecf 100644 --- a/src/main.c +++ b/src/main.c @@ -21,33 +21,36 @@ int main(int argv, char *argc[]){ ts_vesicle *vesicle; ts_tape *tape; - ts_uint start_iteration=-1; - parse_args(argv,argc); - ts_fprintf(stdout,"\nStarting program...\n\n"); -if(force_from_tape){ -ts_fprintf(stdout,"****************************************************\n"); -ts_fprintf(stdout,"**** Reinitializing initial geometry from tape *****\n"); -ts_fprintf(stdout,"****************************************************\n\n"); -tape=parsetape("tape"); -vesicle=create_vesicle_from_tape(tape); -} else { + ts_uint start_iteration=0; + parse_args(argv,argc); // sets global variable command_line_args (defined in io.h) + ts_fprintf(stdout,"Starting program...\n\n"); + if(force_from_tape){ + ts_fprintf(stdout,"************************************************\n"); + ts_fprintf(stdout,"**** Generating initial geometry from tape *****\n"); + ts_fprintf(stdout,"************************************************\n\n"); + tape=parsetape("tape"); + vesicle=create_vesicle_from_tape(tape); + } else { -ts_fprintf(stdout,"**********************************************************************\n"); -ts_fprintf(stdout,"**** Recreating vesicle from dump file and continuing simulation *****\n"); -ts_fprintf(stdout,"**********************************************************************\n\n"); -tape=parsetape("tape"); -vesicle=restore_state(&start_iteration); + ts_fprintf(stdout,"**********************************************************************\n"); + ts_fprintf(stdout,"**** Recreating vesicle from dump file and continuing simulation *****\n"); + ts_fprintf(stdout,"**********************************************************************\n\n"); + tape=parsetape("tape"); + vesicle=restore_state(&start_iteration); -if(start_iteration>=tape->iterations){ - ts_fprintf(stdout, "Simulation already completed. if you want to rerun it try with --force-from-tape or --reset-iteration-count\n\n"); - return 0; -} -} + if(command_line_args.reset_iteration_count) start_iteration=0; + else start_iteration++; -run_simulation(vesicle, tape->mcsweeps, tape->inititer, tape->iterations, start_iteration+1); -write_master_xml_file("test.pvd"); -write_dout_fcompat_file(vesicle,"dout"); -vesicle_free(vesicle); -tape_free(tape); -return 0; //program finished perfectly ok. We return 0. + if(start_iteration>=tape->iterations){ + ts_fprintf(stdout, "Simulation already completed. if you want to rerun it try with --force-from-tape or --reset-iteration-count\n\n"); + return 0; + } + } + + run_simulation(vesicle, tape->mcsweeps, tape->inititer, tape->iterations, start_iteration); + write_master_xml_file("test.pvd"); + write_dout_fcompat_file(vesicle,"dout"); + vesicle_free(vesicle); + tape_free(tape); + return 0; //program finished perfectly ok. We return 0. } -- Gitblit v1.9.3