--- trunk/src/applications/staticProps/StaticPropsCmd.c 2005/05/27 21:11:24 545 +++ trunk/src/applications/staticProps/StaticPropsCmd.c 2006/05/12 21:34:43 955 @@ -1,27 +1,109 @@ /* - File autogenerated by gengetopt version 2.11 + File autogenerated by gengetopt version 2.16 generated with the following command: - /home/maul/gezelter/tim/bin/gengetopt -i StaticProps.ggo -F StaticPropsCmd + gengetopt -F StaticPropsCmd The developers of gengetopt consider the fixed text that goes in all gengetopt output files to be in the public domain: we make no copyright claims on it. */ - -#include -#include -#include - /* If we use autoconf. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include +#include +#include + #include "getopt.h" #include "StaticPropsCmd.h" +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); + +static int +cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); + +static char * +gengetopt_strdup (const char *s); + +static +void clear_given (struct gengetopt_args_info *args_info) +{ + args_info->help_given = 0 ; + args_info->version_given = 0 ; + args_info->input_given = 0 ; + args_info->output_given = 0 ; + args_info->step_given = 0 ; + args_info->nrbins_given = 0 ; + args_info->nbins_x_given = 0 ; + args_info->nbins_y_given = 0 ; + args_info->nanglebins_given = 0 ; + args_info->length_given = 0 ; + args_info->zoffset_given = 0 ; + args_info->sele1_given = 0 ; + args_info->sele2_given = 0 ; + args_info->sele3_given = 0 ; + args_info->refsele_given = 0 ; + args_info->molname_given = 0 ; + args_info->begin_given = 0 ; + args_info->end_given = 0 ; + args_info->gofr_given = 0 ; + args_info->r_theta_given = 0 ; + args_info->r_omega_given = 0 ; + args_info->theta_omega_given = 0 ; + args_info->gxyz_given = 0 ; + args_info->p2_given = 0 ; + args_info->scd_given = 0 ; + args_info->density_given = 0 ; + args_info->slab_density_given = 0 ; + args_info->hxy_given = 0 ; + args_info->staticProps_group_counter = 0 ; +} + +static +void clear_args (struct gengetopt_args_info *args_info) +{ + args_info->input_arg = NULL; + args_info->input_orig = NULL; + args_info->output_arg = NULL; + args_info->output_orig = NULL; + args_info->step_arg = 1; + args_info->step_orig = NULL; + args_info->nrbins_arg = 100; + args_info->nrbins_orig = NULL; + args_info->nbins_x_arg = 100; + args_info->nbins_x_orig = NULL; + args_info->nbins_y_arg = 100; + args_info->nbins_y_orig = NULL; + args_info->nanglebins_arg = 50; + args_info->nanglebins_orig = NULL; + args_info->length_orig = NULL; + args_info->zoffset_arg = 0; + args_info->zoffset_orig = NULL; + args_info->sele1_arg = NULL; + args_info->sele1_orig = NULL; + args_info->sele2_arg = NULL; + args_info->sele2_orig = NULL; + args_info->sele3_arg = NULL; + args_info->sele3_orig = NULL; + args_info->refsele_arg = NULL; + args_info->refsele_orig = NULL; + args_info->molname_arg = NULL; + args_info->molname_orig = NULL; + args_info->begin_orig = NULL; + args_info->end_orig = NULL; + +} + void cmdline_parser_print_version (void) { @@ -32,74 +114,370 @@ cmdline_parser_print_help (void) cmdline_parser_print_help (void) { cmdline_parser_print_version (); - printf("\n" - "Usage: %s [OPTIONS]...\n", CMDLINE_PARSER_PACKAGE); - printf("\n"); - printf(" -h, --help Print help and exit\n"); - printf(" -V, --version Print version and exit\n"); - printf(" -i, --input=filename input dump file\n"); - printf(" -o, --output=filename output file name\n"); - printf(" -n, --step=INT process every n frame (default=`1')\n"); - printf(" -r, --nrbins=INT number of bins for distance (default=`100')\n"); - printf(" -a, --nanglebins=INT number of bins for cos(angle) (default=\n `50')\n"); - printf(" -l, --length=DOUBLE maximum length (Defaults to 1/2 smallest \n length of first frame)\n"); - printf(" --sele1=selection script select the first stuntdouble set\n"); - printf(" --sele2=selection script select the second stuntdouble set\n"); - printf(" --sele3=selection script select the third stuntdouble set\n"); - printf(" --refsele=selection script select reference (use and only use with \n --gxyz)\n"); - printf(" --molname=STRING molecule name\n"); - printf(" --begin=INT begin interanl index\n"); - printf(" --end=INT end internal index\n"); - printf("\n"); - printf(" Group: staticProps an option of this group is required\n"); - printf(" --gofr g(r)\n"); - printf(" --r_theta g(r, cos(theta))\n"); - printf(" --r_omega g(r, cos(omega))\n"); - printf(" --theta_omega g(cos(theta), cos(omega))\n"); - printf(" --gxyz g(x, y, z)\n"); - printf(" --p2 p2 order parameter (--sele1 and --sele2 must \n be specified)\n"); - printf(" --scd scd order parameter(either --sele1, --sele2, \n --sele3 are specified or --molname, \n --begin, --end are specified)\n"); - printf(" --density density plot (--sele1 must be specified)\n"); + printf("\nUsage: StaticProps [OPTIONS]...\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"," -n, --step=INT process every n frame (default=`1')"); + printf("%s\n"," -x, --nbins_x=INT number of bins in x axis (default=`100')"); + printf("%s\n"," -y , --nbins_y=INT number of bins in y axis (default=`100')"); + printf("%s\n"," -r, --nrbins=INT number of bins for distance (default=`100')"); + printf("%s\n"," -a, --nanglebins=INT number of bins for cos(angle) (default=`50')"); + printf("%s\n"," -l, --length=DOUBLE maximum length (Defaults to 1/2 smallest length \n of first frame)"); + printf("%s\n"," -z, --zoffset=DOUBLE Where to set the zero for the slab_density \n calculation (default=`0')"); + printf("%s\n"," --sele1=selection script select the first stuntdouble set"); + printf("%s\n"," --sele2=selection script select the second stuntdouble set"); + printf("%s\n"," --sele3=selection script select the third stuntdouble set"); + printf("%s\n"," --refsele=selection script\n select reference (use and only use with --gxyz)"); + printf("%s\n"," --molname=STRING molecule name"); + printf("%s\n"," --begin=INT begin interanl index"); + printf("%s\n"," --end=INT end internal index"); + printf("%s\n","\n Group: staticProps\n an option of this group is required"); + printf("%s\n"," --gofr g(r)"); + printf("%s\n"," --r_theta g(r, cos(theta))"); + printf("%s\n"," --r_omega g(r, cos(omega))"); + printf("%s\n"," --theta_omega g(cos(theta), cos(omega))"); + printf("%s\n"," --gxyz g(x, y, z)"); + printf("%s\n"," --p2 p2 order parameter (--sele1 and --sele2 must be \n specified)"); + printf("%s\n"," --scd scd order parameter(either --sele1, --sele2, \n --sele3 are specified or --molname, --begin, \n --end are specified)"); + printf("%s\n"," --density density plot (--sele1 must be specified)"); + printf("%s\n"," --slab_density slab density (--sele1 must be specified)"); + printf("%s\n"," --hxy hxy (--sele1 must be specified)"); + } +void +cmdline_parser_init (struct gengetopt_args_info *args_info) +{ + clear_given (args_info); + clear_args (args_info); +} -static char *gengetopt_strdup (const char *s); +static void +cmdline_parser_release (struct gengetopt_args_info *args_info) +{ + + if (args_info->input_arg) + { + free (args_info->input_arg); /* free previous argument */ + args_info->input_arg = 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->step_orig) + { + free (args_info->step_orig); /* free previous argument */ + args_info->step_orig = 0; + } + if (args_info->nrbins_orig) + { + free (args_info->nrbins_orig); /* free previous argument */ + args_info->nrbins_orig = 0; + } + if (args_info->nbins_x_orig) + { + free (args_info->nbins_x_orig); /* free previous argument */ + args_info->nbins_x_orig = 0; + } + if (args_info->nbins_y_orig) + { + free (args_info->nbins_y_orig); /* free previous argument */ + args_info->nbins_y_orig = 0; + } + + if (args_info->nanglebins_orig) + { + free (args_info->nanglebins_orig); /* free previous argument */ + args_info->nanglebins_orig = 0; + } + if (args_info->length_orig) + { + free (args_info->length_orig); /* free previous argument */ + args_info->length_orig = 0; + } + if (args_info->zoffset_orig) + { + free (args_info->zoffset_orig); /* free previous argument */ + args_info->zoffset_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->sele3_arg) + { + free (args_info->sele3_arg); /* free previous argument */ + args_info->sele3_arg = 0; + } + if (args_info->sele3_orig) + { + free (args_info->sele3_orig); /* free previous argument */ + args_info->sele3_orig = 0; + } + if (args_info->refsele_arg) + { + free (args_info->refsele_arg); /* free previous argument */ + args_info->refsele_arg = 0; + } + if (args_info->refsele_orig) + { + free (args_info->refsele_orig); /* free previous argument */ + args_info->refsele_orig = 0; + } + if (args_info->molname_arg) + { + free (args_info->molname_arg); /* free previous argument */ + args_info->molname_arg = 0; + } + if (args_info->molname_orig) + { + free (args_info->molname_orig); /* free previous argument */ + args_info->molname_orig = 0; + } + if (args_info->begin_orig) + { + free (args_info->begin_orig); /* free previous argument */ + args_info->begin_orig = 0; + } + if (args_info->end_orig) + { + free (args_info->end_orig); /* free previous argument */ + args_info->end_orig = 0; + } + + clear_given (args_info); +} + +int +cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) +{ + FILE *outfile; + int i = 0; + + outfile = fopen(filename, "w"); + + if (!outfile) + { + fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); + 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->step_given) { + if (args_info->step_orig) { + fprintf(outfile, "%s=\"%s\"\n", "step", args_info->step_orig); + } else { + fprintf(outfile, "%s\n", "step"); + } + } + if (args_info->nrbins_given) { + if (args_info->nrbins_orig) { + fprintf(outfile, "%s=\"%s\"\n", "nrbins", args_info->nrbins_orig); + } else { + fprintf(outfile, "%s\n", "nrbins"); + } + } + if (args_info->nbins_x_given) { + if (args_info->nbins_x_orig) { + fprintf(outfile, "%s=\"%s\"\n", "nbins_x", args_info->nbins_x_orig); + } else { + fprintf(outfile, "%s\n", "nbins_x"); + } + } + if (args_info->nbins_y_given) { + if (args_info->nbins_y_orig) { + fprintf(outfile, "%s=\"%s\"\n", "nbins_y", args_info->nbins_y_orig); + } else { + fprintf(outfile, "%s\n", "nbins_y"); + } + } + if (args_info->nanglebins_given) { + if (args_info->nanglebins_orig) { + fprintf(outfile, "%s=\"%s\"\n", "nanglebins", args_info->nanglebins_orig); + } else { + fprintf(outfile, "%s\n", "nanglebins"); + } + } + if (args_info->length_given) { + if (args_info->length_orig) { + fprintf(outfile, "%s=\"%s\"\n", "length", args_info->length_orig); + } else { + fprintf(outfile, "%s\n", "length"); + } + } + if (args_info->zoffset_given) { + if (args_info->zoffset_orig) { + fprintf(outfile, "%s=\"%s\"\n", "zoffset", args_info->zoffset_orig); + } else { + fprintf(outfile, "%s\n", "zoffset"); + } + } + 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->sele3_given) { + if (args_info->sele3_orig) { + fprintf(outfile, "%s=\"%s\"\n", "sele3", args_info->sele3_orig); + } else { + fprintf(outfile, "%s\n", "sele3"); + } + } + if (args_info->refsele_given) { + if (args_info->refsele_orig) { + fprintf(outfile, "%s=\"%s\"\n", "refsele", args_info->refsele_orig); + } else { + fprintf(outfile, "%s\n", "refsele"); + } + } + if (args_info->molname_given) { + if (args_info->molname_orig) { + fprintf(outfile, "%s=\"%s\"\n", "molname", args_info->molname_orig); + } else { + fprintf(outfile, "%s\n", "molname"); + } + } + if (args_info->begin_given) { + if (args_info->begin_orig) { + fprintf(outfile, "%s=\"%s\"\n", "begin", args_info->begin_orig); + } else { + fprintf(outfile, "%s\n", "begin"); + } + } + if (args_info->end_given) { + if (args_info->end_orig) { + fprintf(outfile, "%s=\"%s\"\n", "end", args_info->end_orig); + } else { + fprintf(outfile, "%s\n", "end"); + } + } + if (args_info->gofr_given) { + fprintf(outfile, "%s\n", "gofr"); + } + if (args_info->r_theta_given) { + fprintf(outfile, "%s\n", "r_theta"); + } + if (args_info->r_omega_given) { + fprintf(outfile, "%s\n", "r_omega"); + } + if (args_info->theta_omega_given) { + fprintf(outfile, "%s\n", "theta_omega"); + } + if (args_info->gxyz_given) { + fprintf(outfile, "%s\n", "gxyz"); + } + if (args_info->p2_given) { + fprintf(outfile, "%s\n", "p2"); + } + if (args_info->scd_given) { + fprintf(outfile, "%s\n", "scd"); + } + if (args_info->density_given) { + fprintf(outfile, "%s\n", "density"); + } + if (args_info->slab_density_given) { + fprintf(outfile, "%s\n", "slab_density"); + } + if (args_info->hxy_given) { + fprintf(outfile, "%s\n", "hxy"); + } + fclose (outfile); + i = EXIT_SUCCESS; + return i; +} + +void +cmdline_parser_free (struct gengetopt_args_info *args_info) +{ + cmdline_parser_release (args_info); +} + + /* gengetopt_strdup() */ /* strdup.c replacement of strdup, which is not standard */ char * gengetopt_strdup (const char *s) { - char *result = (char*)malloc(strlen(s) + 1); + char *result = NULL; + if (!s) + return result; + + result = (char*)malloc(strlen(s) + 1); if (result == (char*)0) return (char*)0; strcpy(result, s); return result; } -int -cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) +static void +reset_group_staticProps(struct gengetopt_args_info *args_info); + +static void +reset_group_staticProps(struct gengetopt_args_info *args_info) { - int c; /* Character of the parsed option. */ - int missing_required_options = 0; - int staticProps_group_counter = 0; + if (! args_info->staticProps_group_counter) + return; - - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->input_given = 0 ; - args_info->output_given = 0 ; - args_info->step_given = 0 ; - args_info->nrbins_given = 0 ; - args_info->nanglebins_given = 0 ; - args_info->length_given = 0 ; - args_info->sele1_given = 0 ; - args_info->sele2_given = 0 ; - args_info->sele3_given = 0 ; - args_info->refsele_given = 0 ; - args_info->molname_given = 0 ; - args_info->begin_given = 0 ; - args_info->end_given = 0 ; args_info->gofr_given = 0 ; args_info->r_theta_given = 0 ; args_info->r_omega_given = 0 ; @@ -108,23 +486,86 @@ cmdline_parser (int argc, char * const *argv, struct g args_info->p2_given = 0 ; args_info->scd_given = 0 ; args_info->density_given = 0 ; -#define clear_args() { \ - args_info->input_arg = NULL; \ - args_info->output_arg = NULL; \ - args_info->step_arg = 1 ;\ - args_info->nrbins_arg = 100 ;\ - args_info->nanglebins_arg = 50 ;\ - args_info->sele1_arg = NULL; \ - args_info->sele2_arg = NULL; \ - args_info->sele3_arg = NULL; \ - args_info->refsele_arg = NULL; \ - args_info->molname_arg = NULL; \ + args_info->slab_density_given = 0 ; + args_info->hxy_given= 0 ; + + args_info->staticProps_group_counter = 0; } - clear_args(); +int +cmdline_parser (int argc, char * const *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) +{ + int result; + + 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_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) +{ + int result = EXIT_SUCCESS; + + if (cmdline_parser_required2(args_info, prog_name, NULL) > 0) + result = EXIT_FAILURE; + + if (result == EXIT_FAILURE) + { + cmdline_parser_free (args_info); + exit (EXIT_FAILURE); + } + + return result; +} + +int +cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) +{ + int error = 0; + + 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->staticProps_group_counter == 0) + { + fprintf (stderr, "%s: %d options of group staticProps were given. One is required.%s\n", prog_name, args_info->staticProps_group_counter, (additional_error ? additional_error : "")); + error = 1; + } + + + return error; +} + +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) +{ + int c; /* Character of the parsed option. */ + + int error = 0; + struct gengetopt_args_info local_args_info; + + if (initialize) + cmdline_parser_init (args_info); + + cmdline_parser_init (&local_args_info); + optarg = 0; - optind = 1; + optind = 0; opterr = 1; optopt = '?'; @@ -142,6 +583,7 @@ cmdline_parser (int argc, char * const *argv, struct g { "nrbins", 1, NULL, 'r' }, { "nanglebins", 1, NULL, 'a' }, { "length", 1, NULL, 'l' }, + { "zoffset", 1, NULL, 'z' }, { "sele1", 1, NULL, 0 }, { "sele2", 1, NULL, 0 }, { "sele3", 1, NULL, 0 }, @@ -157,329 +599,547 @@ cmdline_parser (int argc, char * const *argv, struct g { "p2", 0, NULL, 0 }, { "scd", 0, NULL, 0 }, { "density", 0, NULL, 0 }, + { "slab_density", 0, NULL, 0 }, + { "hxy", 0, NULL, 0 }, { NULL, 0, NULL, 0 } }; stop_char = 0; - c = getopt_long (argc, argv, "hVi:o:n:r:a:l:", long_options, &option_index); + c = getopt_long (argc, argv, "hVi:o:n:r:a:l:z:", long_options, &option_index); if (c == -1) break; /* Exit from `while (1)' loop. */ switch (c) { case 'h': /* Print help and exit. */ - clear_args (); cmdline_parser_print_help (); + cmdline_parser_free (&local_args_info); exit (EXIT_SUCCESS); case 'V': /* Print version and exit. */ - clear_args (); cmdline_parser_print_version (); + cmdline_parser_free (&local_args_info); exit (EXIT_SUCCESS); case 'i': /* input dump file. */ - if (args_info->input_given) + if (local_args_info.input_given) { - fprintf (stderr, "%s: `--input' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + 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); break; case 'o': /* output file name. */ - if (args_info->output_given) + if (local_args_info.output_given) { - fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + 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); break; case 'n': /* process every n frame. */ - if (args_info->step_given) + if (local_args_info.step_given) { - fprintf (stderr, "%s: `--step' (`-n') option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--step' (`-n') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->step_given && ! override) + continue; + local_args_info.step_given = 1; args_info->step_given = 1; - args_info->step_arg = strtol (optarg,&stop_char,0); + args_info->step_arg = strtol (optarg, &stop_char, 0); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + goto failure; + } + if (args_info->step_orig) + free (args_info->step_orig); /* free previous string */ + args_info->step_orig = gengetopt_strdup (optarg); break; case 'r': /* number of bins for distance. */ - if (args_info->nrbins_given) + if (local_args_info.nrbins_given) { - fprintf (stderr, "%s: `--nrbins' (`-r') option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--nrbins' (`-r') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->nrbins_given && ! override) + continue; + local_args_info.nrbins_given = 1; args_info->nrbins_given = 1; - args_info->nrbins_arg = strtol (optarg,&stop_char,0); + args_info->nrbins_arg = strtol (optarg, &stop_char, 0); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + goto failure; + } + if (args_info->nrbins_orig) + free (args_info->nrbins_orig); /* free previous string */ + args_info->nrbins_orig = gengetopt_strdup (optarg); break; + case 'x': /* number of bins in x axis. */ + if (local_args_info.nbins_x_given) + { + fprintf (stderr, "%s: `--nbins_x' (`-r') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->nbins_x_given && ! override) + continue; + local_args_info.nbins_x_given = 1; + args_info->nbins_x_given = 1; + args_info->nbins_x_arg = strtol (optarg, &stop_char, 0); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + goto failure; + } + if (args_info->nbins_x_orig) + free (args_info->nbins_x_orig); /* free previous string */ + args_info->nbins_x_orig = gengetopt_strdup (optarg); + break; + + case 'y': /* number of bins in y axis. */ + if (local_args_info.nbins_y_given) + { + fprintf (stderr, "%s: `--nbins_y' (`-r') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->nbins_y_given && ! override) + continue; + local_args_info.nbins_y_given = 1; + args_info->nbins_y_given = 1; + args_info->nbins_y_arg = strtol (optarg, &stop_char, 0); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + goto failure; + } + if (args_info->nbins_y_orig) + free (args_info->nbins_y_orig); /* free previous string */ + args_info->nbins_y_orig = gengetopt_strdup (optarg); + break; + case 'a': /* number of bins for cos(angle). */ - if (args_info->nanglebins_given) + if (local_args_info.nanglebins_given) { - fprintf (stderr, "%s: `--nanglebins' (`-a') option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--nanglebins' (`-a') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->nanglebins_given && ! override) + continue; + local_args_info.nanglebins_given = 1; args_info->nanglebins_given = 1; - args_info->nanglebins_arg = strtol (optarg,&stop_char,0); + args_info->nanglebins_arg = strtol (optarg, &stop_char, 0); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + goto failure; + } + if (args_info->nanglebins_orig) + free (args_info->nanglebins_orig); /* free previous string */ + args_info->nanglebins_orig = gengetopt_strdup (optarg); break; case 'l': /* maximum length (Defaults to 1/2 smallest length of first frame). */ - if (args_info->length_given) + if (local_args_info.length_given) { - fprintf (stderr, "%s: `--length' (`-l') option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--length' (`-l') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->length_given && ! override) + continue; + local_args_info.length_given = 1; args_info->length_given = 1; - args_info->length_arg = strtod (optarg, NULL); + args_info->length_arg = strtod (optarg, &stop_char); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + goto failure; + } + if (args_info->length_orig) + free (args_info->length_orig); /* free previous string */ + args_info->length_orig = gengetopt_strdup (optarg); break; + case 'z': /* Where to set the zero for the slab_density calculation. */ + if (local_args_info.zoffset_given) + { + fprintf (stderr, "%s: `--zoffset' (`-z') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->zoffset_given && ! override) + continue; + local_args_info.zoffset_given = 1; + args_info->zoffset_given = 1; + args_info->zoffset_arg = strtod (optarg, &stop_char); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + goto failure; + } + if (args_info->zoffset_orig) + free (args_info->zoffset_orig); /* free previous string */ + args_info->zoffset_orig = gengetopt_strdup (optarg); + break; + case 0: /* Long option with no short option */ /* select the first stuntdouble set. */ if (strcmp (long_options[option_index].name, "sele1") == 0) { - if (args_info->sele1_given) + if (local_args_info.sele1_given) { - fprintf (stderr, "%s: `--sele1' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + 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); - break; + if (args_info->sele1_orig) + free (args_info->sele1_orig); /* free previous string */ + args_info->sele1_orig = gengetopt_strdup (optarg); } - /* select the second stuntdouble set. */ else if (strcmp (long_options[option_index].name, "sele2") == 0) { - if (args_info->sele2_given) + if (local_args_info.sele2_given) { - fprintf (stderr, "%s: `--sele2' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + 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); - break; + if (args_info->sele2_orig) + free (args_info->sele2_orig); /* free previous string */ + args_info->sele2_orig = gengetopt_strdup (optarg); } - /* select the third stuntdouble set. */ else if (strcmp (long_options[option_index].name, "sele3") == 0) { - if (args_info->sele3_given) + if (local_args_info.sele3_given) { - fprintf (stderr, "%s: `--sele3' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--sele3' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->sele3_given && ! override) + continue; + local_args_info.sele3_given = 1; args_info->sele3_given = 1; + if (args_info->sele3_arg) + free (args_info->sele3_arg); /* free previous string */ args_info->sele3_arg = gengetopt_strdup (optarg); - break; + if (args_info->sele3_orig) + free (args_info->sele3_orig); /* free previous string */ + args_info->sele3_orig = gengetopt_strdup (optarg); } - /* select reference (use and only use with --gxyz). */ else if (strcmp (long_options[option_index].name, "refsele") == 0) { - if (args_info->refsele_given) + if (local_args_info.refsele_given) { - fprintf (stderr, "%s: `--refsele' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--refsele' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->refsele_given && ! override) + continue; + local_args_info.refsele_given = 1; args_info->refsele_given = 1; + if (args_info->refsele_arg) + free (args_info->refsele_arg); /* free previous string */ args_info->refsele_arg = gengetopt_strdup (optarg); - break; + if (args_info->refsele_orig) + free (args_info->refsele_orig); /* free previous string */ + args_info->refsele_orig = gengetopt_strdup (optarg); } - /* molecule name. */ else if (strcmp (long_options[option_index].name, "molname") == 0) { - if (args_info->molname_given) + if (local_args_info.molname_given) { - fprintf (stderr, "%s: `--molname' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--molname' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->molname_given && ! override) + continue; + local_args_info.molname_given = 1; args_info->molname_given = 1; + if (args_info->molname_arg) + free (args_info->molname_arg); /* free previous string */ args_info->molname_arg = gengetopt_strdup (optarg); - break; + if (args_info->molname_orig) + free (args_info->molname_orig); /* free previous string */ + args_info->molname_orig = gengetopt_strdup (optarg); } - /* begin interanl index. */ else if (strcmp (long_options[option_index].name, "begin") == 0) { - if (args_info->begin_given) + if (local_args_info.begin_given) { - fprintf (stderr, "%s: `--begin' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--begin' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->begin_given && ! override) + continue; + local_args_info.begin_given = 1; args_info->begin_given = 1; - args_info->begin_arg = strtol (optarg,&stop_char,0); - break; + args_info->begin_arg = strtol (optarg, &stop_char, 0); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + goto failure; + } + if (args_info->begin_orig) + free (args_info->begin_orig); /* free previous string */ + args_info->begin_orig = gengetopt_strdup (optarg); } - /* end internal index. */ else if (strcmp (long_options[option_index].name, "end") == 0) { - if (args_info->end_given) + if (local_args_info.end_given) { - fprintf (stderr, "%s: `--end' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--end' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->end_given && ! override) + continue; + local_args_info.end_given = 1; args_info->end_given = 1; - args_info->end_arg = strtol (optarg,&stop_char,0); - break; + args_info->end_arg = strtol (optarg, &stop_char, 0); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + goto failure; + } + if (args_info->end_orig) + free (args_info->end_orig); /* free previous string */ + args_info->end_orig = gengetopt_strdup (optarg); } - /* g(r). */ else if (strcmp (long_options[option_index].name, "gofr") == 0) { - if (args_info->gofr_given) + if (local_args_info.gofr_given) { - fprintf (stderr, "%s: `--gofr' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--gofr' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } - args_info->gofr_given = 1; staticProps_group_counter += 1; - + if (args_info->gofr_given && ! override) + continue; + local_args_info.gofr_given = 1; + args_info->gofr_given = 1; + if (args_info->staticProps_group_counter && override) + reset_group_staticProps (args_info); + args_info->staticProps_group_counter += 1; break; } - /* g(r, cos(theta)). */ else if (strcmp (long_options[option_index].name, "r_theta") == 0) { - if (args_info->r_theta_given) + if (local_args_info.r_theta_given) { - fprintf (stderr, "%s: `--r_theta' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--r_theta' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } - args_info->r_theta_given = 1; staticProps_group_counter += 1; - + if (args_info->r_theta_given && ! override) + continue; + local_args_info.r_theta_given = 1; + args_info->r_theta_given = 1; + if (args_info->staticProps_group_counter && override) + reset_group_staticProps (args_info); + args_info->staticProps_group_counter += 1; break; } - /* g(r, cos(omega)). */ else if (strcmp (long_options[option_index].name, "r_omega") == 0) { - if (args_info->r_omega_given) + if (local_args_info.r_omega_given) { - fprintf (stderr, "%s: `--r_omega' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--r_omega' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } - args_info->r_omega_given = 1; staticProps_group_counter += 1; - + if (args_info->r_omega_given && ! override) + continue; + local_args_info.r_omega_given = 1; + args_info->r_omega_given = 1; + if (args_info->staticProps_group_counter && override) + reset_group_staticProps (args_info); + args_info->staticProps_group_counter += 1; break; } - /* g(cos(theta), cos(omega)). */ else if (strcmp (long_options[option_index].name, "theta_omega") == 0) { - if (args_info->theta_omega_given) + if (local_args_info.theta_omega_given) { - fprintf (stderr, "%s: `--theta_omega' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--theta_omega' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } - args_info->theta_omega_given = 1; staticProps_group_counter += 1; - + if (args_info->theta_omega_given && ! override) + continue; + local_args_info.theta_omega_given = 1; + args_info->theta_omega_given = 1; + if (args_info->staticProps_group_counter && override) + reset_group_staticProps (args_info); + args_info->staticProps_group_counter += 1; break; } - /* g(x, y, z). */ else if (strcmp (long_options[option_index].name, "gxyz") == 0) { - if (args_info->gxyz_given) + if (local_args_info.gxyz_given) { - fprintf (stderr, "%s: `--gxyz' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--gxyz' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } - args_info->gxyz_given = 1; staticProps_group_counter += 1; - + if (args_info->gxyz_given && ! override) + continue; + local_args_info.gxyz_given = 1; + args_info->gxyz_given = 1; + if (args_info->staticProps_group_counter && override) + reset_group_staticProps (args_info); + args_info->staticProps_group_counter += 1; break; } - /* p2 order parameter (--sele1 and --sele2 must be specified). */ else if (strcmp (long_options[option_index].name, "p2") == 0) { - if (args_info->p2_given) + if (local_args_info.p2_given) { - fprintf (stderr, "%s: `--p2' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--p2' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } - args_info->p2_given = 1; staticProps_group_counter += 1; - + if (args_info->p2_given && ! override) + continue; + local_args_info.p2_given = 1; + args_info->p2_given = 1; + if (args_info->staticProps_group_counter && override) + reset_group_staticProps (args_info); + args_info->staticProps_group_counter += 1; break; } - /* scd order parameter(either --sele1, --sele2, --sele3 are specified or --molname, --begin, --end are specified). */ else if (strcmp (long_options[option_index].name, "scd") == 0) { - if (args_info->scd_given) + if (local_args_info.scd_given) { - fprintf (stderr, "%s: `--scd' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--scd' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } - args_info->scd_given = 1; staticProps_group_counter += 1; - + if (args_info->scd_given && ! override) + continue; + local_args_info.scd_given = 1; + args_info->scd_given = 1; + if (args_info->staticProps_group_counter && override) + reset_group_staticProps (args_info); + args_info->staticProps_group_counter += 1; break; } - /* density plot (--sele1 must be specified). */ else if (strcmp (long_options[option_index].name, "density") == 0) { - if (args_info->density_given) + if (local_args_info.density_given) { - fprintf (stderr, "%s: `--density' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--density' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } - args_info->density_given = 1; staticProps_group_counter += 1; - + if (args_info->density_given && ! override) + continue; + local_args_info.density_given = 1; + args_info->density_given = 1; + if (args_info->staticProps_group_counter && override) + reset_group_staticProps (args_info); + args_info->staticProps_group_counter += 1; break; } + /* slab density (--sele1 must be specified). */ + else if (strcmp (long_options[option_index].name, "slab_density") == 0) + { + if (local_args_info.slab_density_given) + { + fprintf (stderr, "%s: `--slab_density' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->slab_density_given && ! override) + continue; + local_args_info.slab_density_given = 1; + args_info->slab_density_given = 1; + if (args_info->staticProps_group_counter && override) + reset_group_staticProps (args_info); + args_info->staticProps_group_counter += 1; + break; + } + /* hxy (--sele1 must be specified). */ + else if (strcmp (long_options[option_index].name, "hxy") == 0) + { + if (local_args_info.hxy_given) + { + fprintf (stderr, "%s: `--hxy' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->hxy_given && ! override) + continue; + local_args_info.hxy_given = 1; + args_info->hxy_given = 1; + if (args_info->staticProps_group_counter && override) + reset_group_staticProps (args_info); + args_info->staticProps_group_counter += 1; + break; + } - + break; case '?': /* Invalid option. */ /* `getopt_long' already printed an error message. */ - exit (EXIT_FAILURE); + goto failure; default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c); + fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); abort (); } /* switch */ } /* while */ - if ( staticProps_group_counter != 1) + if (args_info->staticProps_group_counter > 1) { - fprintf (stderr, "%s: %d options of group staticProps were given. One is required\n", CMDLINE_PARSER_PACKAGE, staticProps_group_counter); - missing_required_options = 1; + fprintf (stderr, "%s: %d options of group staticProps were given. One is required.%s\n", argv[0], args_info->staticProps_group_counter, (additional_error ? additional_error : "")); + error = 1; } - if (! args_info->input_given) + + if (check_required) { - fprintf (stderr, "%s: '--input' ('-i') option required\n", CMDLINE_PARSER_PACKAGE); - missing_required_options = 1; + error += cmdline_parser_required2 (args_info, argv[0], additional_error); } - if ( missing_required_options ) - exit (EXIT_FAILURE); + cmdline_parser_release (&local_args_info); + + if ( error ) + return (EXIT_FAILURE); + return 0; + +failure: + + cmdline_parser_release (&local_args_info); + return (EXIT_FAILURE); }