From 5bfcc11dee4a3cdbd2597c1b8044d4a04f3ed1c8 Mon Sep 17 00:00:00 2001 From: Robert Izzard <r.izzard@surrey.ac.uk> Date: Sun, 8 Sep 2019 22:41:54 +0100 Subject: [PATCH] bug fixed the ALPHA_ARGS : it's not really any quicker in practice, although if you run the same system many times, with the same stardata and preferences, it will be ~80% faster. In reality: stardata changes for each system, so don't bother. But I'll leave the code in there just in case it's useful to you; --- binary_c-config | 2 + src/binary_c_code_options.h | 6 +- src/binary_c_function_macros.h | 13 + src/binary_c_structures.h | 5 +- src/memory/free_store_contents.c | 2 +- src/memory/free_tmpstore.c | 48 ++-- src/setup/cmd_line_args.h | 21 +- src/setup/parse_arguments.c | 478 +++++++++++++++++-------------- 8 files changed, 323 insertions(+), 252 deletions(-) diff --git a/binary_c-config b/binary_c-config index 8a0426ef0..719f28abb 100755 --- a/binary_c-config +++ b/binary_c-config @@ -16,7 +16,9 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" BIN="$DIR/src/binary_c" if [[ ! -x "$BIN" ]];then + echo -e "\e[91m" echo "Looked for binary_c at $BIN but could not find an executable there :( Have you built binary_c? Is this config script located in the binary_c directory?" + echo -e "\e[39m" exit fi VER="$BIN version " diff --git a/src/binary_c_code_options.h b/src/binary_c_code_options.h index 6e4a5c3a2..0ca25e741 100644 --- a/src/binary_c_code_options.h +++ b/src/binary_c_code_options.h @@ -1091,9 +1091,11 @@ void Print_trace(void); * the cmd_line_args array to a set of data indexed by the * first character of each argument. Thus there is a little * memory cost, but it takes ~20% of the time to parse - * arguments. + * arguments IF structures (stardata and preferences) do not + * change. In a general run, these *can* change, so you + * don't buy any speed :( */ -#define ALPHA_ARGS +//#define ALPHA_ARGS #endif //BINARY_C_CODE_OPTIONS_H diff --git a/src/binary_c_function_macros.h b/src/binary_c_function_macros.h index e8f55b81b..e70e4f2f5 100644 --- a/src/binary_c_function_macros.h +++ b/src/binary_c_function_macros.h @@ -1499,5 +1499,18 @@ #define ASCII_lower_case(N) Boolean_((N)>96 && (N)<123) #define ASCII_letter(N) (ASCII_lower_case(N) || ASCII_upper_case(N)) +/* + * ASCII letters to integer index mapping, where a-z are 0-25, and + * A-Z are 26-51. + */ +#define ASCII_letter_to_index(A) \ + ({ \ + const unsigned int u = \ + ASCII_lower_case(arg[0])==TRUE ? 0 : 1; \ + const unsigned int offset = \ + (const unsigned int) u == 0 ? 'a' : 'A'; \ + (A) - offset + NUMBER_OF_LETTERS_IN_THE_ALPHABET * u; \ + }) + #endif // BINARY_C_FUNCTION_MACROS_H diff --git a/src/binary_c_structures.h b/src/binary_c_structures.h index 473603f7b..31b34c436 100644 --- a/src/binary_c_structures.h +++ b/src/binary_c_structures.h @@ -259,6 +259,7 @@ struct store_t { #ifdef BINT struct data_table_t * BINT_MS; #endif//BINT + Boolean built; Boolean debug_stopping; }; @@ -290,6 +291,8 @@ struct tmpstore_t { struct cmd_line_arg_t ** cmd_line_args_alpha; unsigned int * cmd_line_args_alpha_count; #endif//ALPHA_ARGS + unsigned int arg_count; + #ifdef KICK_CDF_TABLE struct data_table_t * cdf_table; #endif//KICK_CDF_TABLE @@ -358,8 +361,6 @@ struct tmpstore_t { double * comenv_lambda_data; double * Peters_grav_wave_merger_time_data; - - unsigned int arg_count; size_t raw_buffer_size; size_t raw_buffer_alloced; #ifdef DISCS diff --git a/src/memory/free_store_contents.c b/src/memory/free_store_contents.c index 7e95e8b72..9fec6e472 100644 --- a/src/memory/free_store_contents.c +++ b/src/memory/free_store_contents.c @@ -18,7 +18,7 @@ void free_store_contents(struct store_t * RESTRICT const store) #ifdef NUCSYN nucsyn_free_store_contents(store); #endif - + int kt; for(kt=0;kt<COLLISION_MATRIX_SIZE;kt++) { diff --git a/src/memory/free_tmpstore.c b/src/memory/free_tmpstore.c index 8b629bbb9..d8b7d8a6c 100644 --- a/src/memory/free_tmpstore.c +++ b/src/memory/free_tmpstore.c @@ -27,26 +27,7 @@ void free_tmpstore(struct tmpstore_t * RESTRICT const tmpstore) Tmp_free(batchstring2); Tmp_free(batchargs); #endif - { - /* - * Free command line arguments table - */ - int i; - for(i=0; i<tmpstore->arg_count; i++) - { - if(tmpstore->cmd_line_args[i].nargpairs > 0) - { - int j; - for(j=0; j<tmpstore->cmd_line_args[i].nargpairs; j++) - { - Tmp_free(cmd_line_args[i].argpairs[j].string); - } - } - Tmp_free(cmd_line_args[i].argpairs); - Tmp_free(cmd_line_args[i].pairs); - } - Tmp_free(cmd_line_args); - } + #ifdef NUCSYN #ifdef NUCSYN_STELLAR_POPULATIONS_ENSEMBLE Tmp_free(ensemble_type); @@ -92,17 +73,40 @@ void free_tmpstore(struct tmpstore_t * RESTRICT const tmpstore) Safe_free(tmpstore->rinterpolate_data); } + + { + /* + * Free command line arguments table + */ + int i; + for(i=0; i<tmpstore->arg_count; i++) + { + if(tmpstore->cmd_line_args[i].nargpairs > 0) + { + int j; + for(j=0; j<tmpstore->cmd_line_args[i].nargpairs; j++) + { + Tmp_free(cmd_line_args[i].argpairs[j].string); + } + } + Tmp_free(cmd_line_args[i].argpairs); + Tmp_free(cmd_line_args[i].pairs); + } + Tmp_free(cmd_line_args); + } + + #ifdef ALPHA_ARGS { unsigned int i; - for(i=0;i < ALPHA_ARGS_SIZE;i++) + for(i=0;i<ALPHA_ARGS_SIZE;i++) { Safe_free(tmpstore->cmd_line_args_alpha[i]); } Safe_free(tmpstore->cmd_line_args_alpha); Safe_free(tmpstore->cmd_line_args_alpha_count); } -#endif +#endif//ALPHA_ARGS /* * Free the memory in tmpstore, but don't set it diff --git a/src/setup/cmd_line_args.h b/src/setup/cmd_line_args.h index ce5e3e664..680933dbe 100644 --- a/src/setup/cmd_line_args.h +++ b/src/setup/cmd_line_args.h @@ -56,6 +56,11 @@ #define ARG_FLOAT_SCANF 14 #define ARG_UNSIGNED_INTEGER 15 +#define Arg_is_function_pointer(N) \ + ((N) == ARG_SUBROUTINE || \ + (N) == ARG_SUBROUTINE_RETURN_INT || \ + (N) == ARGV_SUBROUTINE_RETURN_FLOAT) + #define Argtypestring(A) \ ( \ (A)==ARG_FLOAT ? "Float" : \ @@ -157,7 +162,7 @@ struct arg_pair_t { char * string; - double value; /* NB ints can be cast in here, we rely on sizeof(double)>=sizeof(int) which is always true */ + double value; /* NB ints and Booleans can be cast in here, we rely on sizeof(double)>=Max(sizeof(Boolean),sizeof(int)) which is always true */ }; /* @@ -365,9 +370,8 @@ struct cmd_line_arg_t &set_metallicity, \ 1.0 \ } , \ -BATCHMODE_ARGS \ { \ - ARG_SECTION_STARS, \ + ARG_SECTION_STARS, \ "effective_metallicity", \ "This sets effective metallicity of stars. If not set, is just the same as metallicity. This \"effective\" metallicity is used in, say, mass-loss routines.", \ ARG_FLOAT, \ @@ -3581,17 +3585,8 @@ BATCHMODE_ARGS \ "False", \ &(stardata->preferences->speedtests), \ 1.0 \ - }, \ + } \ \ -{ /* this must come last! */ \ - 0, \ - NULL, \ - NULL, \ - ARG_NONE, \ - "Ignore", \ - NULL, \ - 1.0 \ - } diff --git a/src/setup/parse_arguments.c b/src/setup/parse_arguments.c index 6bf6eec5f..ce1eff8e8 100644 --- a/src/setup/parse_arguments.c +++ b/src/setup/parse_arguments.c @@ -4,13 +4,17 @@ #include "cmd_line_function_macros.h" #include "cmd_line_macro_pairs.h" + #ifdef ALPHA_ARGS #define Aprint(...) /* do nothing */ #endif//ALPHA_ARGS -static Boolean match_scanf(char * arg, - struct cmd_line_arg_t * cmd_line_arg, - int * offset_p); +/**************/ +static Boolean match_scanf(const char * const arg, + const struct cmd_line_arg_t * const cmd_line_arg, + size_t * const offset_p); +static void derived_arguments(struct stardata_t * const stardata); +/**************/ void parse_arguments(const int start, const int argc, @@ -25,170 +29,206 @@ void parse_arguments(const int start, * they are defined. If you want to add an argument, do it there * and rebuild. Do NOT change this function! * - * See also argument_setting_functions.c and batchmode.c + * If argv is non-NULL, we use it as a list of arguments + * to be parsed. * - * If argv is NULL, this is a call to set up our part - * of the tmpstore, after which we just return without parsing. + * If argv is NULL, we use it to set up the cmd_line_args + * array in tmpstore. This must be done for each system because + * it contains function pointers, and pointers inside + * preferences, star[0,1], model etc. which may have changed + * since the previous call. * - * Similarly, if stardata->tmpstore->cmd_line_args - * is NULL by argv is non-NULL, we set up the tmpstore, and then - * we parse the arguments. + * See also argument_setting_functions.c and batchmode.c */ - if(unlikely(argv==NULL || - stardata->tmpstore->cmd_line_args == NULL)) - { - /* make static table */ - struct tmpstore_t * tmpstore = stardata->tmpstore; - unsigned int arg_count = 0,i; - - // see cmd_line_args.h for master argument table - struct cmd_line_arg_t cmd_line_args2[] = - { CMD_LINE_ARGS }; - /* count the number of arguments (last's name NULL) */ - struct cmd_line_arg_t * p = cmd_line_args2; // struct counter - while(p++->name!=NULL) arg_count++; + Dprint("PARSE sizeof stardata %ld, store %ld, store = %p, cmd_line_args = %p\n", + (long int)sizeof(struct stardata_t), + (long int)sizeof(struct store_t), + stardata->tmpstore, + stardata->tmpstore->cmd_line_args); - /* clear macro pair counters */ - for(i=0;i<arg_count;i++) - { - cmd_line_args2[i].pairs = NULL; - cmd_line_args2[i].npairs = 0; - cmd_line_args2[i].argpairs = NULL; - cmd_line_args2[i].nargpairs = 0; - } + if(argv == NULL) + { + /* + * Make args table + */ + struct tmpstore_t * tmpstore = stardata->tmpstore; - /* add macro pairs */ - set_cmd_line_macro_pairs(stardata, - cmd_line_args2, - arg_count); + Dprint("ARGS setup in tmpstore %p\n",tmpstore); -#ifdef ALPHA_ARGS /* - * Allocate space for the alpha map: this is - * an array of pointers with index given by the - * a map from the first character to an index - * between 0 and 51 (inclusive). + * see cmd_line_args.h for master argument table */ - tmpstore->cmd_line_args_alpha = - Malloc(sizeof(struct cmd_line_arg_t *)*ALPHA_ARGS_SIZE); + { + /* + * Note that this array must be set up + * every time: it is not possible to defineit as + * const type because it contains pointers to the star + * and model structs, as well as function pointers, + * which can change from run to run. + */ + const struct cmd_line_arg_t cmd_line_args2[] = + { CMD_LINE_ARGS }; - /* - * Set all counts to zero - */ - tmpstore->cmd_line_args_alpha_count = - Calloc(ALPHA_ARGS_SIZE,sizeof(unsigned int)); + /* size of the cmd_line_args array */ + const size_t size = sizeof(cmd_line_args2); + + /* count the number of arguments (last's name NULL) */ + tmpstore->arg_count = size / sizeof(struct cmd_line_arg_t); - unsigned int u; - for(u=0; u<NUMBER_OF_ALPHABETICAL_CASES; u++) - { + /* allocate memory in the store for it */ + if(tmpstore->cmd_line_args == NULL) + { + tmpstore->cmd_line_args=Malloc(size); + Dprint("Allocated %zu bytes for tmpstore->cmd_line_args table at %p\n", + size, + tmpstore->cmd_line_args); + } + /* - * u = 0 -> lower case - * u = 1 -> upper case + * Copy the data */ - unsigned int a; - const unsigned int offset = - (const unsigned int) (u == 0 ? 'a' : 'A'); - for(a=0; a<NUMBER_OF_LETTERS_IN_THE_ALPHABET; a++) + memcpy(tmpstore->cmd_line_args, + cmd_line_args2, + size); + + unsigned int i; + for(i=0;i<tmpstore->arg_count;i++) { /* - * Hence the char that is the first letter - */ - const unsigned char c = offset + a; - const unsigned int index = a + u * NUMBER_OF_LETTERS_IN_THE_ALPHABET; - Aprint("allocate alpha structure %d (char %d = %c = %c)\n", - a, - (int)c, - offset+a, - c); - /* - * NULL the array (its index is zero, set by memset above) + * clear macro pair counters */ - tmpstore->cmd_line_args_alpha[index] = NULL; - + tmpstore->cmd_line_args[i].pairs = NULL; + tmpstore->cmd_line_args[i].npairs = 0; + tmpstore->cmd_line_args[i].argpairs = NULL; + tmpstore->cmd_line_args[i].nargpairs = 0; + } + + /* add macro pairs */ + set_cmd_line_macro_pairs(stardata, + tmpstore->cmd_line_args, + tmpstore->arg_count); + } + +#ifdef ALPHA_ARGS + if(tmpstore->cmd_line_args_alpha == NULL) + { + /* + * Allocate space for the alpha map: this is + * an array of pointers with index given by the + * a map from the first character to an index + * between 0 and 51 (inclusive). + */ + tmpstore->cmd_line_args_alpha = + Malloc(sizeof(struct cmd_line_arg_t *)*ALPHA_ARGS_SIZE); + + /* + * Set all counts to zero + */ + tmpstore->cmd_line_args_alpha_count = + Calloc(ALPHA_ARGS_SIZE,sizeof(unsigned int)); + + unsigned int u; + for(u=0; u<NUMBER_OF_ALPHABETICAL_CASES; u++) + { /* - * Loop over cmd_line_args2 to find the appropriate - * mapping + * u = 0 -> lower case + * u = 1 -> upper case */ - for(i=0;i<arg_count;i++) + unsigned int a; + const unsigned int offset = + (const unsigned int) (u == 0 ? 'a' : 'A'); + for(a=0; a<NUMBER_OF_LETTERS_IN_THE_ALPHABET; a++) { - if(cmd_line_args2[i].name[0] == c) + /* + * Hence the char that is the first letter + */ + const unsigned char c = offset + a; + const unsigned int index = a + u * NUMBER_OF_LETTERS_IN_THE_ALPHABET; + Aprint("allocate alpha structure %d (char %d = %c = %c)\n", + a, + (int)c, + offset+a, + c); + /* + * NULL the array (its index is zero, set by memset above) + */ + tmpstore->cmd_line_args_alpha[index] = NULL; + + /* + * Loop over cmd_line_args2 to find the appropriate + * mapping + */ + unsigned int i; + for(i=0;i<tmpstore->arg_count;i++) { - Aprint("mapped arg %s here\n", - cmd_line_args2[i].name); - /* - * Increase size - */ - tmpstore->cmd_line_args_alpha[index] = Realloc( - tmpstore->cmd_line_args_alpha[index], - sizeof(struct cmd_line_arg_t) * - (1+tmpstore->cmd_line_args_alpha_count[index])); + if(tmpstore->cmd_line_args[i].name[0] == c) + { + Aprint("mapped arg %s here\n", + tmpstore->cmd_line_args[i].name); + /* + * Increase size + */ + tmpstore->cmd_line_args_alpha[index] = Realloc( + tmpstore->cmd_line_args_alpha[index], + sizeof(struct cmd_line_arg_t) * + (1+tmpstore->cmd_line_args_alpha_count[index])); - /* - * Copy the arg data into the sublist - */ - memcpy(&tmpstore->cmd_line_args_alpha[index][tmpstore->cmd_line_args_alpha_count[index]], - &cmd_line_args2[i], - sizeof(struct cmd_line_arg_t)); + /* + * Copy the arg data into the sublist + */ + memcpy(&tmpstore->cmd_line_args_alpha[index][tmpstore->cmd_line_args_alpha_count[index]], + &tmpstore->cmd_line_args[i], + sizeof(struct cmd_line_arg_t)); - /* - * Expand count for the next item - */ - tmpstore->cmd_line_args_alpha_count[index]++; + /* + * Expand count for the next item + */ + tmpstore->cmd_line_args_alpha_count[index]++; - Aprint("new count[index=%d] %d\n", - index, - tmpstore->cmd_line_args_alpha_count[index]); + Aprint("new count[index=%d] %d\n", + index, + tmpstore->cmd_line_args_alpha_count[index]); + } } } } } #endif // ALPHA_ARGS - /* copy to tmpstore */ - Dprint("Allocate %zu bytes for cmd_line_args table\n", - sizeof(cmd_line_args2)); - if(tmpstore->cmd_line_args==NULL) - { - tmpstore->cmd_line_args=Malloc(sizeof(cmd_line_args2)); - } - memcpy(tmpstore->cmd_line_args, - cmd_line_args2, - sizeof(cmd_line_args2)); - tmpstore->arg_count = arg_count; +#undef ALPHA_ARGS Dprint("Arg table built : we have %d args (argc=%d)\n", tmpstore->arg_count,argc); } - - if(likely(argv != NULL)) + else { /* * Parse command line arguments */ - struct preferences_t * preferences MAYBE_UNUSED = stardata->preferences; struct cmd_line_arg_t *cmd_line_args = stardata->tmpstore->cmd_line_args; - /* - * loop over the arguments, looking for - * matches and acting accordingly - */ + #ifdef DEBUG_FAIL_ON_NAN - Boolean allow_debug_nan_was = stardata->preferences->allow_debug_nan; + const Boolean allow_debug_nan_was = stardata->preferences->allow_debug_nan; stardata->preferences->allow_debug_nan = TRUE; #endif #ifdef DEBUG_FAIL_ON_INF - Boolean allow_debug_inf_was = stardata->preferences->allow_debug_inf; + const Boolean allow_debug_inf_was = stardata->preferences->allow_debug_inf; stardata->preferences->allow_debug_inf = TRUE; #endif + + /* + * loop over the arguments, looking for + * matches and acting accordingly + */ int c; - for(c=start;c<argc;c++) + for(c=start; c<argc; c++) { Dprint("CMD LINE ARG %d/%d allow nan ? %d",c,argc,stardata->preferences->allow_debug_nan); Dprint(" is %s : process ",argv[c]); char * arg = (char*) argv[c]; /* ignore leading -- */ - if((arg[0]=='-') && (arg[1]=='-')) arg += 2; - + if((arg[0] == '-') && (arg[1] == '-')) arg += 2; #ifdef ALPHA_ARGS /* @@ -209,51 +249,53 @@ void parse_arguments(const int start, /* * First character is a letter: use the alpha map */ - const unsigned int u = ASCII_lower_case(arg[0])==TRUE ? 0 : 1; - const unsigned int offset = - (const unsigned int) u == 0 ? 'a' : 'A'; - const unsigned int index = - arg[0] - offset + NUMBER_OF_LETTERS_IN_THE_ALPHABET * u; + index = ASCII_letter_to_index(arg[0]); + /* + * Override the cmd_line_args and arg count with those + * for this starting letter + */ arg_count = stardata->tmpstore->cmd_line_args_alpha_count[index]; cmd_line_args = stardata->tmpstore->cmd_line_args_alpha[index]; - Aprint("Using alpha map for %c (offset %d) index %d : arg_count = %d\n", - arg[0],offset,index,arg_count); + Aprint("Using alpha map for %c : index %d : arg_count = %d\n", + arg[0],index,arg_count); } else { /* - * Not ASCII : use the whole store + * Not ASCII : use the big table + * (this shouldn't happen) */ arg_count = stardata->tmpstore->arg_count; cmd_line_args = stardata->tmpstore->cmd_line_args; } #else /* - * No map: check the whole cmd_line_args in tmpstore + * No map: check the whole cmd_line_args in store */ const int arg_count = stardata->tmpstore->arg_count; cmd_line_args = stardata->tmpstore->cmd_line_args; #endif//ALPHA_ARGS - - /* check this argument against all those in the list */ - int i,offset; - Boolean success=FALSE; - - for(i=0;i< -#ifndef ALPHA_ARGS - stardata->tmpstore-> -#endif//!ALPHA_ARGS - arg_count;i++) + /* + * check this argument against all those in the list + */ + unsigned int i; + size_t offset; + Boolean success = FALSE; + + for(i=0; i<arg_count; i++) { Dprint("compare \"%s\" and \"%s\"\n",arg,cmd_line_args[i].name); if( - Strings_equal(arg,cmd_line_args[i].name) + Strings_equal(arg, + cmd_line_args[i].name) || ((cmd_line_args[i].type == ARG_INTEGER_SCANF || cmd_line_args[i].type == ARG_FLOAT_SCANF) && - match_scanf(arg,&cmd_line_args[i],&offset) == TRUE) + match_scanf(arg, + &cmd_line_args[i], + &offset) == TRUE) ) { @@ -266,9 +308,9 @@ void parse_arguments(const int start, stardata->preferences->repeat ); - success=TRUE; + success = TRUE; - if(cmd_line_args[i].pointer==NULL) + if(cmd_line_args[i].pointer == NULL) { /* * If the pointer is NULL, ignore this @@ -277,10 +319,10 @@ void parse_arguments(const int start, * the appropriate subroutine, or * simply incrementing the counter (i.e. c++). */ - if(cmd_line_args[i].type==ARG_SUBROUTINE || - cmd_line_args[i].type==ARG_SUBROUTINE_RETURN_FLOAT || - cmd_line_args[i].type==ARG_SUBROUTINE_RETURN_INT || - cmd_line_args[i].type==BATCH_ARG_SUBROUTINE) + if(cmd_line_args[i].type == ARG_SUBROUTINE || + cmd_line_args[i].type == ARG_SUBROUTINE_RETURN_FLOAT || + cmd_line_args[i].type == ARG_SUBROUTINE_RETURN_INT || + cmd_line_args[i].type == BATCH_ARG_SUBROUTINE) { void (*func)(ARG_SUBROUTINE_DECLARATION); func = cmd_line_args[i].pointer; @@ -294,19 +336,22 @@ void parse_arguments(const int start, else { /* code to check if the next arg exists when it's required */ -#define Next_arg_check if(c+1>argc || argv[c+1]==NULL) \ +#define Next_arg_check \ + if(c+1>argc || argv[c+1] == NULL) \ { \ - Exit_binary_c(BINARY_C_SETUP_UNKNOWN_ARGUMENT, \ - "Exit because cmd line arg #%d \"%s\" requires a value which is not the next argument (c+1=%d argc=%d prev arg =\"%s\" next arg = \"%s\").", \ - c, \ - arg, \ - c+1, \ - argc, \ - argv[c==0?0:c-1], \ - (c<argc ? argv[c+1] : "NULL") \ + Exit_binary_c( \ + BINARY_C_SETUP_UNKNOWN_ARGUMENT, \ + "Exit because cmd line arg #%d \"%s\" requires a value which is not the next argument (c+1=%d argc=%d prev arg =\"%s\" next arg = \"%s\").", \ + c, \ + arg, \ + c+1, \ + argc, \ + argv[c == 0?0:c-1], \ + (c<argc ? argv[c+1] : "NULL") \ ); \ } - + + /* Act based on argument type */ switch(cmd_line_args[i].type) { @@ -368,24 +413,27 @@ void parse_arguments(const int start, /* Matched argument but no idea what to do with it */ Dprint( "Exit because argument type %d is unknown (check cmd_line_args.h at position %d)", - cmd_line_args[i].type,i); + cmd_line_args[i].type, + i); Exit_binary_c( BINARY_C_SETUP_UNKNOWN_ARGUMENT, "Exit because argument type %d is unknown (check cmd_line_args.h at position %d)", - cmd_line_args[i].type,i); + cmd_line_args[i].type, + i); } } - i = -#ifndef ALPHA_ARGS - stardata->tmpstore-> -#endif//!ALPHA_ARGS - arg_count + 1; /* matched : break out of i loop */ + /* + * Matched : break out of i loop + */ + break; } } - /* exit on error */ - if(success==FALSE) + /* + * exit on error : this should never happen! + */ + if(success == FALSE) { Dprint( "Exit because given cmd line arg \"%s\" (number %d) failed to match any known argument.", @@ -404,62 +452,23 @@ void parse_arguments(const int start, #ifdef DEBUG_FAIL_ON_NAN stardata->preferences->allow_debug_nan = allow_debug_nan_was; -#endif +#endif//DEBUG_FAIL_ON_NAN #ifdef DEBUG_FAIL_ON_INF stardata->preferences->allow_debug_inf = allow_debug_inf_was; -#endif +#endif//DEBUG_FAIL_ON_INF -/* - * Special cases - */ - if(Is_not_zero(stardata->star[0].mass) && - Is_not_zero(stardata->star[1].mass)) - { - if(Is_zero(stardata->common.orbit.period) && - Is_not_zero(stardata->common.orbit.separation)) - { - /* - * Period is set to zero, but separation is given. - * Hence calculate the initial period. - */ - stardata->common.orbit.period = - calculate_orbital_period(stardata); - } - else if(Is_not_zero(stardata->common.orbit.period)) - { - /* - * Update the separation here so that the "INITIAL" log is - * correct. (This is reset later anyway.) - */ - stardata->common.orbit.period /= YEAR_LENGTH_IN_DAYS; - stardata->common.orbit.separation = - calculate_orbital_separation(stardata); - stardata->common.orbit.period *= YEAR_LENGTH_IN_DAYS; - } - } - - -/* - * If we are using log times, choose the next max_evolution_time that - * correponds to an exact number of log timesteps - */ -#if defined NUCSYN && defined NUCSYN_YIELDS - if(stardata->preferences->yields_logtimes == TRUE) - { - stardata->model.max_evolution_time = - pow(10.0, - stardata->preferences->yields_logdt * - (1.0+(int)(log10(stardata->model.max_evolution_time)/stardata->preferences->yields_logdt))); - } -#endif // NUCSYN && NUCSYN_YIELDS + /* + * Derived variables cases + */ + derived_arguments(stardata); } } /********************************************************************/ -static Boolean match_scanf(char * arg, - struct cmd_line_arg_t * cmd_line_arg, - int * offset_p) +static Boolean match_scanf(const char * const arg, + const struct cmd_line_arg_t * const cmd_line_arg, + size_t * const offset_p) { if(sscanf(arg,cmd_line_arg->name,offset_p)) { @@ -476,7 +485,8 @@ static Boolean match_scanf(char * arg, unsigned int i; for(i=0; i<cmd_line_arg->nargpairs; i++) { - if(Strings_equal(arg,cmd_line_arg->argpairs[i].string)) + if(Strings_equal(arg, + cmd_line_arg->argpairs[i].string)) { /* * Matched : set the appropriate offset @@ -494,3 +504,47 @@ static Boolean match_scanf(char * arg, } } +static void derived_arguments(struct stardata_t * const stardata) +{ + if(Is_not_zero(stardata->star[0].mass) && + Is_not_zero(stardata->star[1].mass)) + { + if(Is_zero(stardata->common.orbit.period) && + Is_not_zero(stardata->common.orbit.separation)) + { + /* + * Period is set to zero, but separation is given. + * Hence calculate the initial period. + */ + stardata->common.orbit.period = + calculate_orbital_period(stardata); + } + else if(Is_not_zero(stardata->common.orbit.period)) + { + /* + * Update the separation here so that the "INITIAL" log is + * correct. (This is reset later anyway.) + */ + stardata->common.orbit.period /= YEAR_LENGTH_IN_DAYS; + stardata->common.orbit.separation = + calculate_orbital_separation(stardata); + stardata->common.orbit.period *= YEAR_LENGTH_IN_DAYS; + } + } + + /* + * If we are using log times, choose the next + * max_evolution_time that correponds to an + * exact number of log timesteps + */ +#if defined NUCSYN && defined NUCSYN_YIELDS + if(stardata->preferences->yields_logtimes == TRUE) + { + stardata->model.max_evolution_time = + pow(10.0, + stardata->preferences->yields_logdt * + (1.0+(int)(log10(stardata->model.max_evolution_time)/ + stardata->preferences->yields_logdt))); + } +#endif // NUCSYN && NUCSYN_YIELDS +} -- GitLab