--- trunk/src/applications/dynamicProps/DynamicPropsCmd.c 2007/01/03 20:47:00 1112 +++ trunk/src/applications/dynamicProps/DynamicPropsCmd.cpp 2013/07/29 17:55:17 1915 @@ -1,7 +1,7 @@ /* - File autogenerated by gengetopt version 2.15 + File autogenerated by gengetopt version 2.22.4 generated with the following command: - gengetopt -u -i DynamicProps.ggo -F DynamicPropsCmd + gengetopt --file-name=DynamicPropsCmd --unamed-opts The developers of gengetopt consider the fixed text that goes in all gengetopt output files to be in the public domain: @@ -17,17 +17,60 @@ #include #include -#include "getopt.h" +#ifndef FIX_UNUSED +#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ +#endif +#include + #include "DynamicPropsCmd.h" +const char *gengetopt_args_info_purpose = ""; + +const char *gengetopt_args_info_usage = "Usage: DynamicProps [OPTIONS]... [FILES]..."; + +const char *gengetopt_args_info_description = ""; + +const char *gengetopt_args_info_help[] = { + " -h, --help Print help and exit", + " -V, --version Print version and exit", + " -i, --input=filename input dump file", + " -o, --output=filename output file name", + " --sele1=selection script select first stuntdouble set", + " --sele2=selection script select second stuntdouble set (if sele2 is not \n set, use script from sele1)", + " --order=INT Lengendre Polynomial Order", + " -z, --nzbins=INT Number of Z bins (default=`100')", + " -m, --memory=memory specification\n Available memory (defaults to 2G) \n (default=`2G')", + "\n Group: dynamicProps\n an option of this group is required", + " -s, --selecorr selection correlation function", + " -r, --rcorr rmsd", + " -v, --vcorr velocity correlation function", + " -d, --dcorr dipole correlation function", + " -l, --lcorr Lengendre correlation function", + " --lcorrZ Lengendre correlation function binned by Z", + " -M, --sdcorr System dipole correlation function", + " --r_rcorr Radial rmsd", + " --thetacorr Angular rmsd", + " --drcorr Directional rmsd for particles with unit \n vectors", + " --helfandEcorr Helfand moment for thermal conductvity", + " -p, --momentum Helfand momentum for viscosity", + " --stresscorr Stress tensor correlation function", + 0 +}; + +typedef enum {ARG_NO + , ARG_STRING + , ARG_INT +} cmdline_parser_arg_type; + static void clear_given (struct gengetopt_args_info *args_info); static void clear_args (struct gengetopt_args_info *args_info); static int -cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error); +cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params, const char *additional_error); static int cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); @@ -45,18 +88,28 @@ void clear_given (struct gengetopt_args_info *args_inf args_info->sele1_given = 0 ; args_info->sele2_given = 0 ; args_info->order_given = 0 ; + args_info->nzbins_given = 0 ; + args_info->memory_given = 0 ; + args_info->selecorr_given = 0 ; args_info->rcorr_given = 0 ; args_info->vcorr_given = 0 ; args_info->dcorr_given = 0 ; args_info->lcorr_given = 0 ; + args_info->lcorrZ_given = 0 ; + args_info->sdcorr_given = 0 ; args_info->r_rcorr_given = 0 ; args_info->thetacorr_given = 0 ; + args_info->drcorr_given = 0 ; + args_info->helfandEcorr_given = 0 ; + args_info->momentum_given = 0 ; + args_info->stresscorr_given = 0 ; args_info->dynamicProps_group_counter = 0 ; } static void clear_args (struct gengetopt_args_info *args_info) { + FIX_UNUSED (args_info); args_info->input_arg = NULL; args_info->input_orig = NULL; args_info->output_arg = NULL; @@ -66,35 +119,73 @@ void clear_args (struct gengetopt_args_info *args_info args_info->sele2_arg = NULL; args_info->sele2_orig = NULL; args_info->order_orig = NULL; + args_info->nzbins_arg = 100; + args_info->nzbins_orig = NULL; + args_info->memory_arg = gengetopt_strdup ("2G"); + args_info->memory_orig = NULL; } +static +void init_args_info(struct gengetopt_args_info *args_info) +{ + + + args_info->help_help = gengetopt_args_info_help[0] ; + args_info->version_help = gengetopt_args_info_help[1] ; + args_info->input_help = gengetopt_args_info_help[2] ; + args_info->output_help = gengetopt_args_info_help[3] ; + args_info->sele1_help = gengetopt_args_info_help[4] ; + args_info->sele2_help = gengetopt_args_info_help[5] ; + args_info->order_help = gengetopt_args_info_help[6] ; + args_info->nzbins_help = gengetopt_args_info_help[7] ; + args_info->memory_help = gengetopt_args_info_help[8] ; + args_info->selecorr_help = gengetopt_args_info_help[10] ; + args_info->rcorr_help = gengetopt_args_info_help[11] ; + args_info->vcorr_help = gengetopt_args_info_help[12] ; + args_info->dcorr_help = gengetopt_args_info_help[13] ; + args_info->lcorr_help = gengetopt_args_info_help[14] ; + args_info->lcorrZ_help = gengetopt_args_info_help[15] ; + args_info->sdcorr_help = gengetopt_args_info_help[16] ; + args_info->r_rcorr_help = gengetopt_args_info_help[17] ; + args_info->thetacorr_help = gengetopt_args_info_help[18] ; + args_info->drcorr_help = gengetopt_args_info_help[19] ; + args_info->helfandEcorr_help = gengetopt_args_info_help[20] ; + args_info->momentum_help = gengetopt_args_info_help[21] ; + args_info->stresscorr_help = gengetopt_args_info_help[22] ; + +} + void cmdline_parser_print_version (void) { - printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION); + printf ("%s %s\n", + (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), + CMDLINE_PARSER_VERSION); } +static void print_help_common(void) { + cmdline_parser_print_version (); + + if (strlen(gengetopt_args_info_purpose) > 0) + printf("\n%s\n", gengetopt_args_info_purpose); + + if (strlen(gengetopt_args_info_usage) > 0) + printf("\n%s\n", gengetopt_args_info_usage); + + printf("\n"); + + if (strlen(gengetopt_args_info_description) > 0) + printf("%s\n\n", gengetopt_args_info_description); +} + void cmdline_parser_print_help (void) { - cmdline_parser_print_version (); - printf("\nUsage: DynamicProps [OPTIONS]... [FILES]...\n\n"); - printf("%s\n"," -h, --help Print help and exit"); - printf("%s\n"," -V, --version Print version and exit"); - printf("%s\n"," -i, --input=filename input dump file"); - printf("%s\n"," -o, --output=filename output file name"); - printf("%s\n"," --sele1=selection script select first stuntdouble set"); - printf("%s\n"," --sele2=selection script select second stuntdouble set (if sele2 is not \n set, use script from sele1)"); - printf("%s\n"," --order=INT Lengendre Polynomial Order"); - printf("%s\n","\n Group: dynamicProps\n an option of this group is required"); - printf("%s\n"," -r, --rcorr rmsd"); - printf("%s\n"," -v, --vcorr velocity correlation function"); - printf("%s\n"," -d, --dcorr dipole correlation function"); - printf("%s\n"," -l, --lcorr Lengendre correlation function"); - printf("%s\n"," --r_rcorr Radial rmsd"); - printf("%s\n"," --thetacorr Angular rmsd"); - + int i = 0; + print_help_common(); + while (gengetopt_args_info_help[i]) + printf("%s\n", gengetopt_args_info_help[i++]); } void @@ -102,72 +193,147 @@ cmdline_parser_init (struct gengetopt_args_info *args_ { clear_given (args_info); clear_args (args_info); + init_args_info (args_info); - args_info->inputs = NULL; + args_info->inputs = 0; args_info->inputs_num = 0; } +void +cmdline_parser_params_init(struct cmdline_parser_params *params) +{ + if (params) + { + params->override = 0; + params->initialize = 1; + params->check_required = 1; + params->check_ambiguity = 0; + params->print_errors = 1; + } +} + +struct cmdline_parser_params * +cmdline_parser_params_create(void) +{ + struct cmdline_parser_params *params = + (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); + cmdline_parser_params_init(params); + return params; +} + static void -cmdline_parser_release (struct gengetopt_args_info *args_info) +free_string_field (char **s) { - - unsigned int i; - if (args_info->input_arg) + if (*s) { - free (args_info->input_arg); /* free previous argument */ - args_info->input_arg = 0; + free (*s); + *s = 0; } - if (args_info->input_orig) - { - free (args_info->input_orig); /* free previous argument */ - args_info->input_orig = 0; - } - if (args_info->output_arg) - { - free (args_info->output_arg); /* free previous argument */ - args_info->output_arg = 0; - } - if (args_info->output_orig) - { - free (args_info->output_orig); /* free previous argument */ - args_info->output_orig = 0; - } - if (args_info->sele1_arg) - { - free (args_info->sele1_arg); /* free previous argument */ - args_info->sele1_arg = 0; - } - if (args_info->sele1_orig) - { - free (args_info->sele1_orig); /* free previous argument */ - args_info->sele1_orig = 0; - } - if (args_info->sele2_arg) - { - free (args_info->sele2_arg); /* free previous argument */ - args_info->sele2_arg = 0; - } - if (args_info->sele2_orig) - { - free (args_info->sele2_orig); /* free previous argument */ - args_info->sele2_orig = 0; - } - if (args_info->order_orig) - { - free (args_info->order_orig); /* free previous argument */ - args_info->order_orig = 0; - } +} + + +static void +cmdline_parser_release (struct gengetopt_args_info *args_info) +{ + unsigned int i; + free_string_field (&(args_info->input_arg)); + free_string_field (&(args_info->input_orig)); + free_string_field (&(args_info->output_arg)); + free_string_field (&(args_info->output_orig)); + free_string_field (&(args_info->sele1_arg)); + free_string_field (&(args_info->sele1_orig)); + free_string_field (&(args_info->sele2_arg)); + free_string_field (&(args_info->sele2_orig)); + free_string_field (&(args_info->order_orig)); + free_string_field (&(args_info->nzbins_orig)); + free_string_field (&(args_info->memory_arg)); + free_string_field (&(args_info->memory_orig)); + for (i = 0; i < args_info->inputs_num; ++i) free (args_info->inputs [i]); - + if (args_info->inputs_num) free (args_info->inputs); - + clear_given (args_info); } + +static void +write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) +{ + FIX_UNUSED (values); + if (arg) { + fprintf(outfile, "%s=\"%s\"\n", opt, arg); + } else { + fprintf(outfile, "%s\n", opt); + } +} + + int +cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) +{ + int i = 0; + + if (!outfile) + { + fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); + return EXIT_FAILURE; + } + + if (args_info->help_given) + write_into_file(outfile, "help", 0, 0 ); + if (args_info->version_given) + write_into_file(outfile, "version", 0, 0 ); + if (args_info->input_given) + write_into_file(outfile, "input", args_info->input_orig, 0); + if (args_info->output_given) + write_into_file(outfile, "output", args_info->output_orig, 0); + if (args_info->sele1_given) + write_into_file(outfile, "sele1", args_info->sele1_orig, 0); + if (args_info->sele2_given) + write_into_file(outfile, "sele2", args_info->sele2_orig, 0); + if (args_info->order_given) + write_into_file(outfile, "order", args_info->order_orig, 0); + if (args_info->nzbins_given) + write_into_file(outfile, "nzbins", args_info->nzbins_orig, 0); + if (args_info->memory_given) + write_into_file(outfile, "memory", args_info->memory_orig, 0); + if (args_info->selecorr_given) + write_into_file(outfile, "selecorr", 0, 0 ); + if (args_info->rcorr_given) + write_into_file(outfile, "rcorr", 0, 0 ); + if (args_info->vcorr_given) + write_into_file(outfile, "vcorr", 0, 0 ); + if (args_info->dcorr_given) + write_into_file(outfile, "dcorr", 0, 0 ); + if (args_info->lcorr_given) + write_into_file(outfile, "lcorr", 0, 0 ); + if (args_info->lcorrZ_given) + write_into_file(outfile, "lcorrZ", 0, 0 ); + if (args_info->sdcorr_given) + write_into_file(outfile, "sdcorr", 0, 0 ); + if (args_info->r_rcorr_given) + write_into_file(outfile, "r_rcorr", 0, 0 ); + if (args_info->thetacorr_given) + write_into_file(outfile, "thetacorr", 0, 0 ); + if (args_info->drcorr_given) + write_into_file(outfile, "drcorr", 0, 0 ); + if (args_info->helfandEcorr_given) + write_into_file(outfile, "helfandEcorr", 0, 0 ); + if (args_info->momentum_given) + write_into_file(outfile, "momentum", 0, 0 ); + if (args_info->stresscorr_given) + write_into_file(outfile, "stresscorr", 0, 0 ); + + + i = EXIT_SUCCESS; + return i; +} + +int cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) { FILE *outfile; @@ -181,69 +347,9 @@ cmdline_parser_file_save(const char *filename, struct return EXIT_FAILURE; } - if (args_info->help_given) { - fprintf(outfile, "%s\n", "help"); - } - if (args_info->version_given) { - fprintf(outfile, "%s\n", "version"); - } - if (args_info->input_given) { - if (args_info->input_orig) { - fprintf(outfile, "%s=\"%s\"\n", "input", args_info->input_orig); - } else { - fprintf(outfile, "%s\n", "input"); - } - } - if (args_info->output_given) { - if (args_info->output_orig) { - fprintf(outfile, "%s=\"%s\"\n", "output", args_info->output_orig); - } else { - fprintf(outfile, "%s\n", "output"); - } - } - if (args_info->sele1_given) { - if (args_info->sele1_orig) { - fprintf(outfile, "%s=\"%s\"\n", "sele1", args_info->sele1_orig); - } else { - fprintf(outfile, "%s\n", "sele1"); - } - } - if (args_info->sele2_given) { - if (args_info->sele2_orig) { - fprintf(outfile, "%s=\"%s\"\n", "sele2", args_info->sele2_orig); - } else { - fprintf(outfile, "%s\n", "sele2"); - } - } - if (args_info->order_given) { - if (args_info->order_orig) { - fprintf(outfile, "%s=\"%s\"\n", "order", args_info->order_orig); - } else { - fprintf(outfile, "%s\n", "order"); - } - } - if (args_info->rcorr_given) { - fprintf(outfile, "%s\n", "rcorr"); - } - if (args_info->vcorr_given) { - fprintf(outfile, "%s\n", "vcorr"); - } - if (args_info->dcorr_given) { - fprintf(outfile, "%s\n", "dcorr"); - } - if (args_info->lcorr_given) { - fprintf(outfile, "%s\n", "lcorr"); - } - if (args_info->r_rcorr_given) { - fprintf(outfile, "%s\n", "r_rcorr"); - } - if (args_info->thetacorr_given) { - fprintf(outfile, "%s\n", "thetacorr"); - } - + i = cmdline_parser_dump(outfile, args_info); fclose (outfile); - i = EXIT_SUCCESS; return i; } @@ -253,13 +359,11 @@ cmdline_parser_free (struct gengetopt_args_info *args_ cmdline_parser_release (args_info); } - -/* gengetopt_strdup() */ -/* strdup.c replacement of strdup, which is not standard */ +/** @brief replacement of strdup, which is not standard */ char * gengetopt_strdup (const char *s) { - char *result = NULL; + char *result = 0; if (!s) return result; @@ -271,37 +375,64 @@ static void } static void -reset_group_dynamicProps(struct gengetopt_args_info *args_info); - -static void reset_group_dynamicProps(struct gengetopt_args_info *args_info) { if (! args_info->dynamicProps_group_counter) return; + args_info->selecorr_given = 0 ; args_info->rcorr_given = 0 ; args_info->vcorr_given = 0 ; args_info->dcorr_given = 0 ; args_info->lcorr_given = 0 ; + args_info->lcorrZ_given = 0 ; + args_info->sdcorr_given = 0 ; args_info->r_rcorr_given = 0 ; args_info->thetacorr_given = 0 ; + args_info->drcorr_given = 0 ; + args_info->helfandEcorr_given = 0 ; + args_info->momentum_given = 0 ; + args_info->stresscorr_given = 0 ; args_info->dynamicProps_group_counter = 0; } int -cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) +cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) { return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); } int -cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) +cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params) { int result; + result = cmdline_parser_internal (argc, argv, args_info, params, 0); - result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL); + if (result == EXIT_FAILURE) + { + cmdline_parser_free (args_info); + exit (EXIT_FAILURE); + } + + return result; +} +int +cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) +{ + int result; + struct cmdline_parser_params params; + + params.override = override; + params.initialize = initialize; + params.check_required = check_required; + params.check_ambiguity = 0; + params.print_errors = 1; + + result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); + if (result == EXIT_FAILURE) { cmdline_parser_free (args_info); @@ -316,7 +447,7 @@ cmdline_parser_required (struct gengetopt_args_info *a { int result = EXIT_SUCCESS; - if (cmdline_parser_required2(args_info, prog_name, NULL) > 0) + if (cmdline_parser_required2(args_info, prog_name, 0) > 0) result = EXIT_FAILURE; if (result == EXIT_FAILURE) @@ -332,29 +463,161 @@ cmdline_parser_required2 (struct gengetopt_args_info * cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) { int error = 0; + FIX_UNUSED (additional_error); + /* checks for required options */ if (! args_info->input_given) { fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); error = 1; } + if (args_info->dynamicProps_group_counter == 0) { - fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required.%s\n", prog_name, args_info->dynamicProps_group_counter, (additional_error ? additional_error : "")); + fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required%s.\n", prog_name, args_info->dynamicProps_group_counter, (additional_error ? additional_error : "")); error = 1; } + /* checks for dependences among options */ + return error; } + +static char *package_name = 0; + +/** + * @brief updates an option + * @param field the generic pointer to the field to update + * @param orig_field the pointer to the orig field + * @param field_given the pointer to the number of occurrence of this option + * @param prev_given the pointer to the number of occurrence already seen + * @param value the argument for this option (if null no arg was specified) + * @param possible_values the possible values for this option (if specified) + * @param default_value the default value (in case the option only accepts fixed values) + * @param arg_type the type of this option + * @param check_ambiguity @see cmdline_parser_params.check_ambiguity + * @param override @see cmdline_parser_params.override + * @param no_free whether to free a possible previous value + * @param multiple_option whether this is a multiple option + * @param long_opt the corresponding long option + * @param short_opt the corresponding short option (or '-' if none) + * @param additional_error possible further error specification + */ +static +int update_arg(void *field, char **orig_field, + unsigned int *field_given, unsigned int *prev_given, + char *value, const char *possible_values[], + const char *default_value, + cmdline_parser_arg_type arg_type, + int check_ambiguity, int override, + int no_free, int multiple_option, + const char *long_opt, char short_opt, + const char *additional_error) +{ + char *stop_char = 0; + const char *val = value; + int found; + char **string_field; + FIX_UNUSED (field); + + stop_char = 0; + found = 0; + + if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) + { + if (short_opt != '-') + fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", + package_name, long_opt, short_opt, + (additional_error ? additional_error : "")); + else + fprintf (stderr, "%s: `--%s' option given more than once%s\n", + package_name, long_opt, + (additional_error ? additional_error : "")); + return 1; /* failure */ + } + + FIX_UNUSED (default_value); + + if (field_given && *field_given && ! override) + return 0; + if (prev_given) + (*prev_given)++; + if (field_given) + (*field_given)++; + if (possible_values) + val = possible_values[found]; + + switch(arg_type) { + case ARG_INT: + if (val) *((int *)field) = strtol (val, &stop_char, 0); + break; + case ARG_STRING: + if (val) { + string_field = (char **)field; + if (!no_free && *string_field) + free (*string_field); /* free previous string */ + *string_field = gengetopt_strdup (val); + } + break; + default: + break; + }; + + /* check numeric conversion */ + switch(arg_type) { + case ARG_INT: + if (val && !(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); + return 1; /* failure */ + } + break; + default: + ; + }; + + /* store the original value */ + switch(arg_type) { + case ARG_NO: + break; + default: + if (value && orig_field) { + if (no_free) { + *orig_field = value; + } else { + if (*orig_field) + free (*orig_field); /* free previous string */ + *orig_field = gengetopt_strdup (value); + } + } + }; + + return 0; /* OK */ +} + + int -cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error) +cmdline_parser_internal ( + int argc, char **argv, struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params, const char *additional_error) { int c; /* Character of the parsed option. */ int error = 0; struct gengetopt_args_info local_args_info; + + int override; + int initialize; + int check_required; + int check_ambiguity; + + package_name = argv[0]; + + override = params->override; + initialize = params->initialize; + check_required = params->check_required; + check_ambiguity = params->check_ambiguity; if (initialize) cmdline_parser_init (args_info); @@ -362,14 +625,13 @@ cmdline_parser_internal (int argc, char * const *argv, cmdline_parser_init (&local_args_info); optarg = 0; - optind = 1; - opterr = 1; + optind = 0; + opterr = params->print_errors; optopt = '?'; while (1) { int option_index = 0; - char *stop_char; static struct option long_options[] = { { "help", 0, NULL, 'h' }, @@ -379,17 +641,25 @@ cmdline_parser_internal (int argc, char * const *argv, { "sele1", 1, NULL, 0 }, { "sele2", 1, NULL, 0 }, { "order", 1, NULL, 0 }, + { "nzbins", 1, NULL, 'z' }, + { "memory", 1, NULL, 'm' }, + { "selecorr", 0, NULL, 's' }, { "rcorr", 0, NULL, 'r' }, { "vcorr", 0, NULL, 'v' }, { "dcorr", 0, NULL, 'd' }, { "lcorr", 0, NULL, 'l' }, + { "lcorrZ", 0, NULL, 0 }, + { "sdcorr", 0, NULL, 'M' }, { "r_rcorr", 0, NULL, 0 }, { "thetacorr", 0, NULL, 0 }, - { NULL, 0, NULL, 0 } + { "drcorr", 0, NULL, 0 }, + { "helfandEcorr", 0, NULL, 0 }, + { "momentum", 0, NULL, 'p' }, + { "stresscorr", 0, NULL, 0 }, + { 0, 0, 0, 0 } }; - stop_char = 0; - c = getopt_long (argc, argv, "hVi:o:rvdl", long_options, &option_index); + c = getopt_long (argc, argv, "hVi:o:z:m:srvdlMp", long_options, &option_index); if (c == -1) break; /* Exit from `while (1)' loop. */ @@ -406,197 +676,305 @@ cmdline_parser_internal (int argc, char * const *argv, exit (EXIT_SUCCESS); case 'i': /* input dump file. */ - if (local_args_info.input_given) - { - fprintf (stderr, "%s: `--input' (`-i') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); - goto failure; - } - if (args_info->input_given && ! override) - continue; - local_args_info.input_given = 1; - args_info->input_given = 1; - if (args_info->input_arg) - free (args_info->input_arg); /* free previous string */ - args_info->input_arg = gengetopt_strdup (optarg); - if (args_info->input_orig) - free (args_info->input_orig); /* free previous string */ - args_info->input_orig = gengetopt_strdup (optarg); + + + if (update_arg( (void *)&(args_info->input_arg), + &(args_info->input_orig), &(args_info->input_given), + &(local_args_info.input_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "input", 'i', + additional_error)) + goto failure; + break; - case 'o': /* output file name. */ - if (local_args_info.output_given) - { - fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); - goto failure; - } - if (args_info->output_given && ! override) - continue; - local_args_info.output_given = 1; - args_info->output_given = 1; - if (args_info->output_arg) - free (args_info->output_arg); /* free previous string */ - args_info->output_arg = gengetopt_strdup (optarg); - if (args_info->output_orig) - free (args_info->output_orig); /* free previous string */ - args_info->output_orig = gengetopt_strdup (optarg); + + + if (update_arg( (void *)&(args_info->output_arg), + &(args_info->output_orig), &(args_info->output_given), + &(local_args_info.output_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "output", 'o', + additional_error)) + goto failure; + break; - + case 'z': /* Number of Z bins. */ + + + if (update_arg( (void *)&(args_info->nzbins_arg), + &(args_info->nzbins_orig), &(args_info->nzbins_given), + &(local_args_info.nzbins_given), optarg, 0, "100", ARG_INT, + check_ambiguity, override, 0, 0, + "nzbins", 'z', + additional_error)) + goto failure; + + break; + case 'm': /* Available memory (defaults to 2G). */ + + + if (update_arg( (void *)&(args_info->memory_arg), + &(args_info->memory_orig), &(args_info->memory_given), + &(local_args_info.memory_given), optarg, 0, "2G", ARG_STRING, + check_ambiguity, override, 0, 0, + "memory", 'm', + additional_error)) + goto failure; + + break; + case 's': /* selection correlation function. */ + + if (args_info->dynamicProps_group_counter && override) + reset_group_dynamicProps (args_info); + args_info->dynamicProps_group_counter += 1; + + if (update_arg( 0 , + 0 , &(args_info->selecorr_given), + &(local_args_info.selecorr_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "selecorr", 's', + additional_error)) + goto failure; + + break; case 'r': /* rmsd. */ - if (local_args_info.rcorr_given) - { - fprintf (stderr, "%s: `--rcorr' (`-r') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); - goto failure; - } - if (args_info->rcorr_given && ! override) - continue; - local_args_info.rcorr_given = 1; - args_info->rcorr_given = 1; + if (args_info->dynamicProps_group_counter && override) reset_group_dynamicProps (args_info); args_info->dynamicProps_group_counter += 1; + + if (update_arg( 0 , + 0 , &(args_info->rcorr_given), + &(local_args_info.rcorr_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "rcorr", 'r', + additional_error)) + goto failure; + break; - case 'v': /* velocity correlation function. */ - if (local_args_info.vcorr_given) - { - fprintf (stderr, "%s: `--vcorr' (`-v') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); - goto failure; - } - if (args_info->vcorr_given && ! override) - continue; - local_args_info.vcorr_given = 1; - args_info->vcorr_given = 1; + if (args_info->dynamicProps_group_counter && override) reset_group_dynamicProps (args_info); args_info->dynamicProps_group_counter += 1; + + if (update_arg( 0 , + 0 , &(args_info->vcorr_given), + &(local_args_info.vcorr_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "vcorr", 'v', + additional_error)) + goto failure; + break; - case 'd': /* dipole correlation function. */ - if (local_args_info.dcorr_given) - { - fprintf (stderr, "%s: `--dcorr' (`-d') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); - goto failure; - } - if (args_info->dcorr_given && ! override) - continue; - local_args_info.dcorr_given = 1; - args_info->dcorr_given = 1; + if (args_info->dynamicProps_group_counter && override) reset_group_dynamicProps (args_info); args_info->dynamicProps_group_counter += 1; + + if (update_arg( 0 , + 0 , &(args_info->dcorr_given), + &(local_args_info.dcorr_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "dcorr", 'd', + additional_error)) + goto failure; + break; - case 'l': /* Lengendre correlation function. */ - if (local_args_info.lcorr_given) - { - fprintf (stderr, "%s: `--lcorr' (`-l') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); - goto failure; - } - if (args_info->lcorr_given && ! override) - continue; - local_args_info.lcorr_given = 1; - args_info->lcorr_given = 1; + if (args_info->dynamicProps_group_counter && override) reset_group_dynamicProps (args_info); args_info->dynamicProps_group_counter += 1; + + if (update_arg( 0 , + 0 , &(args_info->lcorr_given), + &(local_args_info.lcorr_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "lcorr", 'l', + additional_error)) + goto failure; + break; + case 'M': /* System dipole correlation function. */ + + if (args_info->dynamicProps_group_counter && override) + reset_group_dynamicProps (args_info); + args_info->dynamicProps_group_counter += 1; + + if (update_arg( 0 , + 0 , &(args_info->sdcorr_given), + &(local_args_info.sdcorr_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "sdcorr", 'M', + additional_error)) + goto failure; + + break; + case 'p': /* Helfand momentum for viscosity. */ + + if (args_info->dynamicProps_group_counter && override) + reset_group_dynamicProps (args_info); + args_info->dynamicProps_group_counter += 1; + + if (update_arg( 0 , + 0 , &(args_info->momentum_given), + &(local_args_info.momentum_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "momentum", 'p', + additional_error)) + goto failure; + + break; - case 0: /* Long option with no short option */ /* select first stuntdouble set. */ if (strcmp (long_options[option_index].name, "sele1") == 0) { - if (local_args_info.sele1_given) - { - fprintf (stderr, "%s: `--sele1' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); - goto failure; - } - if (args_info->sele1_given && ! override) - continue; - local_args_info.sele1_given = 1; - args_info->sele1_given = 1; - if (args_info->sele1_arg) - free (args_info->sele1_arg); /* free previous string */ - args_info->sele1_arg = gengetopt_strdup (optarg); - if (args_info->sele1_orig) - free (args_info->sele1_orig); /* free previous string */ - args_info->sele1_orig = gengetopt_strdup (optarg); + + + if (update_arg( (void *)&(args_info->sele1_arg), + &(args_info->sele1_orig), &(args_info->sele1_given), + &(local_args_info.sele1_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "sele1", '-', + additional_error)) + goto failure; + } /* select second stuntdouble set (if sele2 is not set, use script from sele1). */ else if (strcmp (long_options[option_index].name, "sele2") == 0) { - if (local_args_info.sele2_given) - { - fprintf (stderr, "%s: `--sele2' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); - goto failure; - } - if (args_info->sele2_given && ! override) - continue; - local_args_info.sele2_given = 1; - args_info->sele2_given = 1; - if (args_info->sele2_arg) - free (args_info->sele2_arg); /* free previous string */ - args_info->sele2_arg = gengetopt_strdup (optarg); - if (args_info->sele2_orig) - free (args_info->sele2_orig); /* free previous string */ - args_info->sele2_orig = gengetopt_strdup (optarg); + + + if (update_arg( (void *)&(args_info->sele2_arg), + &(args_info->sele2_orig), &(args_info->sele2_given), + &(local_args_info.sele2_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "sele2", '-', + additional_error)) + goto failure; + } /* Lengendre Polynomial Order. */ else if (strcmp (long_options[option_index].name, "order") == 0) { - if (local_args_info.order_given) - { - fprintf (stderr, "%s: `--order' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); - goto failure; - } - if (args_info->order_given && ! override) - continue; - local_args_info.order_given = 1; - args_info->order_given = 1; - args_info->order_arg = strtol (optarg, &stop_char, 0); - if (!(stop_char && *stop_char == '\0')) { - fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + + + if (update_arg( (void *)&(args_info->order_arg), + &(args_info->order_orig), &(args_info->order_given), + &(local_args_info.order_given), optarg, 0, 0, ARG_INT, + check_ambiguity, override, 0, 0, + "order", '-', + additional_error)) goto failure; - } - if (args_info->order_orig) - free (args_info->order_orig); /* free previous string */ - args_info->order_orig = gengetopt_strdup (optarg); + } + /* Lengendre correlation function binned by Z. */ + else if (strcmp (long_options[option_index].name, "lcorrZ") == 0) + { + + if (args_info->dynamicProps_group_counter && override) + reset_group_dynamicProps (args_info); + args_info->dynamicProps_group_counter += 1; + + if (update_arg( 0 , + 0 , &(args_info->lcorrZ_given), + &(local_args_info.lcorrZ_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "lcorrZ", '-', + additional_error)) + goto failure; + + } /* Radial rmsd. */ else if (strcmp (long_options[option_index].name, "r_rcorr") == 0) { - if (local_args_info.r_rcorr_given) - { - fprintf (stderr, "%s: `--r_rcorr' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); - goto failure; - } - if (args_info->r_rcorr_given && ! override) - continue; - local_args_info.r_rcorr_given = 1; - args_info->r_rcorr_given = 1; + if (args_info->dynamicProps_group_counter && override) reset_group_dynamicProps (args_info); args_info->dynamicProps_group_counter += 1; - break; + + if (update_arg( 0 , + 0 , &(args_info->r_rcorr_given), + &(local_args_info.r_rcorr_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "r_rcorr", '-', + additional_error)) + goto failure; + } /* Angular rmsd. */ else if (strcmp (long_options[option_index].name, "thetacorr") == 0) { - if (local_args_info.thetacorr_given) - { - fprintf (stderr, "%s: `--thetacorr' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); - goto failure; - } - if (args_info->thetacorr_given && ! override) - continue; - local_args_info.thetacorr_given = 1; - args_info->thetacorr_given = 1; + if (args_info->dynamicProps_group_counter && override) reset_group_dynamicProps (args_info); args_info->dynamicProps_group_counter += 1; - break; + + if (update_arg( 0 , + 0 , &(args_info->thetacorr_given), + &(local_args_info.thetacorr_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "thetacorr", '-', + additional_error)) + goto failure; + } + /* Directional rmsd for particles with unit vectors. */ + else if (strcmp (long_options[option_index].name, "drcorr") == 0) + { + if (args_info->dynamicProps_group_counter && override) + reset_group_dynamicProps (args_info); + args_info->dynamicProps_group_counter += 1; + + if (update_arg( 0 , + 0 , &(args_info->drcorr_given), + &(local_args_info.drcorr_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "drcorr", '-', + additional_error)) + goto failure; + + } + /* Helfand moment for thermal conductvity. */ + else if (strcmp (long_options[option_index].name, "helfandEcorr") == 0) + { + + if (args_info->dynamicProps_group_counter && override) + reset_group_dynamicProps (args_info); + args_info->dynamicProps_group_counter += 1; + + if (update_arg( 0 , + 0 , &(args_info->helfandEcorr_given), + &(local_args_info.helfandEcorr_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "helfandEcorr", '-', + additional_error)) + goto failure; + + } + /* Stress tensor correlation function. */ + else if (strcmp (long_options[option_index].name, "stresscorr") == 0) + { + + if (args_info->dynamicProps_group_counter && override) + reset_group_dynamicProps (args_info); + args_info->dynamicProps_group_counter += 1; + + if (update_arg( 0 , + 0 , &(args_info->stresscorr_given), + &(local_args_info.stresscorr_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "stresscorr", '-', + additional_error)) + goto failure; + + } + break; case '?': /* Invalid option. */ /* `getopt_long' already printed an error message. */ @@ -610,7 +988,7 @@ cmdline_parser_internal (int argc, char * const *argv, if (args_info->dynamicProps_group_counter > 1) { - fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required.%s\n", argv[0], args_info->dynamicProps_group_counter, (additional_error ? additional_error : "")); + fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required%s.\n", argv[0], args_info->dynamicProps_group_counter, (additional_error ? additional_error : "")); error = 1; } @@ -629,12 +1007,25 @@ cmdline_parser_internal (int argc, char * const *argv, if (optind < argc) { int i = 0 ; + int found_prog_name = 0; + /* whether program name, i.e., argv[0], is in the remaining args + (this may happen with some implementations of getopt, + but surely not with the one included by gengetopt) */ - args_info->inputs_num = argc - optind ; + i = optind; + while (i < argc) + if (argv[i++] == argv[0]) { + found_prog_name = 1; + break; + } + i = 0; + + args_info->inputs_num = argc - optind - found_prog_name; args_info->inputs = (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; while (optind < argc) - args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; + if (argv[optind++] != argv[0]) + args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ; } return 0;