21#define FIX_UNUSED(X) (void) (X)
27const char *gengetopt_args_info_purpose =
"Two functionalities: 1. (-t) Resamples the velocities for all the integrable\nobjects in an OpenMD file from a Maxwell-Boltzmann distribution. 2. (-e) Scales\nthe total energy of all integrable objects in an OpenMD file to a desired total\nenergy.";
29const char *gengetopt_args_info_usage =
"Usage: thermalizer -oSTRING|--output=STRING [-h|--help] [-V|--version]\n [-iSTRING|--input=STRING] [-tDOUBLE|--temperature=DOUBLE]\n [-eDOUBLE|--energy=DOUBLE] [-cDOUBLE|--chargetemperature=DOUBLE]\n [FILES]...";
31const char *gengetopt_args_info_versiontext =
"";
33const char *gengetopt_args_info_description =
"";
35const char *gengetopt_args_info_help[] = {
36 " -h, --help Print help and exit",
37 " -V, --version Print version and exit",
38 " -i, --input=STRING Input file name",
39 " -o, --output=STRING Output file name (mandatory)",
40 "\n Group: thermalizer\n One of these is required",
41 " -t, --temperature=DOUBLE temperature (K)",
42 " -e, --energy=DOUBLE energy (kcal/mol)",
43 " -c, --chargetemperature=DOUBLE\n charge temperature (K)",
50} cmdline_parser_arg_type;
62cmdline_parser_required2 (
struct gengetopt_args_info *args_info,
const char *prog_name,
const char *additional_error);
65gengetopt_strdup (
const char *s);
83 FIX_UNUSED (args_info);
99 args_info->
help_help = gengetopt_args_info_help[0] ;
101 args_info->
input_help = gengetopt_args_info_help[2] ;
102 args_info->
output_help = gengetopt_args_info_help[3] ;
104 args_info->
energy_help = gengetopt_args_info_help[6] ;
110cmdline_parser_print_version (
void)
116 if (strlen(gengetopt_args_info_versiontext) > 0)
117 printf(
"\n%s\n", gengetopt_args_info_versiontext);
120static void print_help_common(
void) {
121 cmdline_parser_print_version ();
123 if (strlen(gengetopt_args_info_purpose) > 0)
124 printf(
"\n%s\n", gengetopt_args_info_purpose);
126 if (strlen(gengetopt_args_info_usage) > 0)
127 printf(
"\n%s\n", gengetopt_args_info_usage);
131 if (strlen(gengetopt_args_info_description) > 0)
132 printf(
"%s\n\n", gengetopt_args_info_description);
136cmdline_parser_print_help (
void)
140 while (gengetopt_args_info_help[i])
141 printf(
"%s\n", gengetopt_args_info_help[i++]);
147 clear_given (args_info);
148 clear_args (args_info);
149 init_args_info (args_info);
178free_string_field (
char **s)
192 free_string_field (&(args_info->
input_arg));
202 free (args_info->
inputs [i]);
207 clear_given (args_info);
212write_into_file(FILE *outfile,
const char *opt,
const char *arg,
const char *values[])
216 fprintf(outfile,
"%s=\"%s\"\n", opt, arg);
218 fprintf(outfile,
"%s\n", opt);
235 write_into_file(outfile,
"help", 0, 0 );
237 write_into_file(outfile,
"version", 0, 0 );
239 write_into_file(outfile,
"input", args_info->
input_orig, 0);
241 write_into_file(outfile,
"output", args_info->
output_orig, 0);
245 write_into_file(outfile,
"energy", args_info->
energy_orig, 0);
260 outfile = fopen(filename,
"w");
277 cmdline_parser_release (args_info);
282gengetopt_strdup (
const char *s)
288 result = (
char*)malloc(strlen(s) + 1);
289 if (result == (
char*)0)
322 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
324 if (result == EXIT_FAILURE)
345 result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
347 if (result == EXIT_FAILURE)
359 int result = EXIT_SUCCESS;
361 if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
362 result = EXIT_FAILURE;
364 if (result == EXIT_FAILURE)
374cmdline_parser_required2 (
struct gengetopt_args_info *args_info,
const char *prog_name,
const char *additional_error)
376 int error_occurred = 0;
377 FIX_UNUSED (additional_error);
382 fprintf (stderr,
"%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error :
""));
388 fprintf (stderr,
"%s: %d options of group thermalizer were given. One is required%s.\n", prog_name, args_info->
thermalizer_group_counter, (additional_error ? additional_error :
""));
395 return error_occurred;
453#ifndef required_argument
454#define required_argument 1
457#ifndef optional_argument
458#define optional_argument 2
461struct custom_getopt_data {
503static char *custom_optarg;
520static int custom_optind = 1;
526static int custom_opterr = 1;
532static int custom_optopt =
'?';
542static void exchange(
char **argv,
struct custom_getopt_data *d)
544 int bottom = d->first_nonopt;
545 int middle = d->last_nonopt;
546 int top = d->custom_optind;
555 while (top > middle && middle > bottom) {
556 if (top - middle > middle - bottom) {
558 int len = middle - bottom;
562 for (i = 0; i < len; i++) {
563 tem = argv[bottom + i];
565 argv[top - (middle - bottom) + i];
566 argv[top - (middle - bottom) + i] = tem;
572 int len = top - middle;
576 for (i = 0; i < len; i++) {
577 tem = argv[bottom + i];
578 argv[bottom + i] = argv[middle + i];
579 argv[middle + i] = tem;
586 d->first_nonopt += (d->custom_optind - d->last_nonopt);
587 d->last_nonopt = d->custom_optind;
591static void custom_getopt_initialize(
struct custom_getopt_data *d)
598 d->first_nonopt = d->last_nonopt = d->custom_optind;
603#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
606static int shuffle_argv(
int argc,
char *
const *argv,
const struct option *longopts,
607 struct custom_getopt_data *d)
613 if (d->last_nonopt > d->custom_optind)
614 d->last_nonopt = d->custom_optind;
615 if (d->first_nonopt > d->custom_optind)
616 d->first_nonopt = d->custom_optind;
621 if (d->first_nonopt != d->last_nonopt &&
622 d->last_nonopt != d->custom_optind)
623 exchange((
char **) argv, d);
624 else if (d->last_nonopt != d->custom_optind)
625 d->first_nonopt = d->custom_optind;
630 while (d->custom_optind < argc && NONOPTION_P)
632 d->last_nonopt = d->custom_optind;
638 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind],
"--")) {
640 if (d->first_nonopt != d->last_nonopt
641 && d->last_nonopt != d->custom_optind)
642 exchange((
char **) argv, d);
643 else if (d->first_nonopt == d->last_nonopt)
644 d->first_nonopt = d->custom_optind;
645 d->last_nonopt = argc;
646 d->custom_optind = argc;
652 if (d->custom_optind == argc) {
657 if (d->first_nonopt != d->last_nonopt)
658 d->custom_optind = d->first_nonopt;
666 d->custom_optarg = argv[d->custom_optind++];
673 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] ==
'-'));
687static int check_long_opt(
int argc,
char *
const *argv,
const char *optstring,
688 const struct option *longopts,
int *longind,
689 int print_errors,
struct custom_getopt_data *d)
692 const struct option *p;
693 const struct option *pfound = NULL;
699 for (nameend = d->nextchar; *nameend && *nameend !=
'='; nameend++)
703 for (p = longopts, option_index = 0; p->name; p++, option_index++)
704 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
705 if ((
unsigned int) (nameend - d->nextchar)
706 == (
unsigned int) strlen(p->name)) {
709 indfound = option_index;
712 }
else if (pfound == NULL) {
715 indfound = option_index;
716 }
else if (pfound->has_arg != p->has_arg
717 || pfound->flag != p->flag
718 || pfound->val != p->val)
722 if (ambig && !exact) {
725 "%s: option `%s' is ambiguous\n",
726 argv[0], argv[d->custom_optind]);
728 d->nextchar += strlen(d->nextchar);
730 d->custom_optopt = 0;
734 option_index = indfound;
737 if (pfound->has_arg != no_argument)
738 d->custom_optarg = nameend + 1;
741 if (argv[d->custom_optind - 1][1] ==
'-') {
743 fprintf(stderr,
"%s: option `--%s' doesn't allow an argument\n",
744 argv[0], pfound->name);
747 fprintf(stderr,
"%s: option `%c%s' doesn't allow an argument\n",
748 argv[0], argv[d->custom_optind - 1][0], pfound->name);
752 d->nextchar += strlen(d->nextchar);
753 d->custom_optopt = pfound->val;
756 }
else if (pfound->has_arg == required_argument) {
757 if (d->custom_optind < argc)
758 d->custom_optarg = argv[d->custom_optind++];
762 "%s: option `%s' requires an argument\n",
764 argv[d->custom_optind - 1]);
766 d->nextchar += strlen(d->nextchar);
767 d->custom_optopt = pfound->val;
768 return optstring[0] ==
':' ?
':' :
'?';
771 d->nextchar += strlen(d->nextchar);
773 *longind = option_index;
775 *(pfound->flag) = pfound->val;
786 if (argv[d->custom_optind][1] ==
'-') {
789 "%s: unrecognized option `--%s'\n",
790 argv[0], d->nextchar);
794 "%s: unrecognized option `%c%s'\n",
795 argv[0], argv[d->custom_optind][0],
799 d->nextchar = (
char *)
"";
801 d->custom_optopt = 0;
805static int check_short_opt(
int argc,
char *
const *argv,
const char *optstring,
806 int print_errors,
struct custom_getopt_data *d)
808 char c = *d->nextchar++;
809 const char *temp = strchr(optstring, c);
812 if (*d->nextchar ==
'\0')
814 if (!temp || c ==
':') {
816 fprintf(stderr,
"%s: invalid option -- %c\n", argv[0], c);
818 d->custom_optopt = c;
821 if (temp[1] ==
':') {
822 if (temp[2] ==
':') {
824 if (*d->nextchar !=
'\0') {
825 d->custom_optarg = d->nextchar;
828 d->custom_optarg = NULL;
832 if (*d->nextchar !=
'\0') {
833 d->custom_optarg = d->nextchar;
840 }
else if (d->custom_optind == argc) {
843 "%s: option requires an argument -- %c\n",
846 d->custom_optopt = c;
847 if (optstring[0] ==
':')
857 d->custom_optarg = argv[d->custom_optind++];
934static int getopt_internal_r(
int argc,
char *
const *argv,
const char *optstring,
935 const struct option *longopts,
int *longind,
936 struct custom_getopt_data *d)
938 int ret, print_errors = d->custom_opterr;
940 if (optstring[0] ==
':')
944 d->custom_optarg = NULL;
950 if (d->custom_optind == 0 || !d->initialized) {
951 if (d->custom_optind == 0)
952 d->custom_optind = 1;
953 custom_getopt_initialize(d);
955 if (d->nextchar == NULL || *d->nextchar ==
'\0') {
956 ret = shuffle_argv(argc, argv, longopts, d);
960 if (longopts && (argv[d->custom_optind][1] ==
'-' ))
961 return check_long_opt(argc, argv, optstring, longopts,
962 longind, print_errors, d);
963 return check_short_opt(argc, argv, optstring, print_errors, d);
966static int custom_getopt_internal(
int argc,
char *
const *argv,
const char *optstring,
967 const struct option *longopts,
int *longind)
971 static struct custom_getopt_data d;
973 d.custom_optind = custom_optind;
974 d.custom_opterr = custom_opterr;
975 result = getopt_internal_r(argc, argv, optstring, longopts,
977 custom_optind = d.custom_optind;
978 custom_optarg = d.custom_optarg;
979 custom_optopt = d.custom_optopt;
983static int custom_getopt_long (
int argc,
char *
const *argv,
const char *options,
984 const struct option *long_options,
int *opt_index)
986 return custom_getopt_internal(argc, argv, options, long_options,
991static char *package_name = 0;
1012int update_arg(
void *field,
char **orig_field,
1013 unsigned int *field_given,
unsigned int *prev_given,
1014 char *value,
const char *possible_values[],
1015 const char *default_value,
1016 cmdline_parser_arg_type arg_type,
1017 int check_ambiguity,
int override,
1018 int no_free,
int multiple_option,
1019 const char *long_opt,
char short_opt,
1020 const char *additional_error)
1022 char *stop_char = 0;
1023 const char *val = value;
1025 char **string_field;
1031 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1033 if (short_opt !=
'-')
1034 fprintf (stderr,
"%s: `--%s' (`-%c') option given more than once%s\n",
1035 package_name, long_opt, short_opt,
1036 (additional_error ? additional_error :
""));
1038 fprintf (stderr,
"%s: `--%s' option given more than once%s\n",
1039 package_name, long_opt,
1040 (additional_error ? additional_error :
""));
1044 FIX_UNUSED (default_value);
1046 if (field_given && *field_given && !
override)
1052 if (possible_values)
1053 val = possible_values[found];
1057 if (val) *((
double *)field) = strtod (val, &stop_char);
1061 string_field = (
char **)field;
1062 if (!no_free && *string_field)
1063 free (*string_field);
1064 *string_field = gengetopt_strdup (val);
1074 if (val && !(stop_char && *stop_char ==
'\0')) {
1075 fprintf(stderr,
"%s: invalid numeric value: %s\n", package_name, val);
1088 if (value && orig_field) {
1090 *orig_field = value;
1094 *orig_field = gengetopt_strdup (value);
1104cmdline_parser_internal (
1110 int error_occurred = 0;
1116 int check_ambiguity;
1123 package_name = argv[0];
1142 int option_index = 0;
1144 static struct option long_options[] = {
1145 {
"help", 0, NULL,
'h' },
1146 {
"version", 0, NULL,
'V' },
1147 {
"input", 1, NULL,
'i' },
1148 {
"output", 1, NULL,
'o' },
1149 {
"temperature", 1, NULL,
't' },
1150 {
"energy", 1, NULL,
'e' },
1151 {
"chargetemperature", 1, NULL,
'c' },
1155 custom_optarg = optarg;
1156 custom_optind = optind;
1157 custom_opterr = opterr;
1158 custom_optopt = optopt;
1160 c = custom_getopt_long (argc, argv,
"hVi:o:t:e:c:", long_options, &option_index);
1162 optarg = custom_optarg;
1163 optind = custom_optind;
1164 opterr = custom_opterr;
1165 optopt = custom_optopt;
1172 cmdline_parser_print_help ();
1173 cmdline_parser_free (&local_args_info);
1174 exit (EXIT_SUCCESS);
1177 cmdline_parser_print_version ();
1178 cmdline_parser_free (&local_args_info);
1179 exit (EXIT_SUCCESS);
1184 if (update_arg( (
void *)&(args_info->
input_arg),
1186 &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
1187 check_ambiguity,
override, 0, 0,
1196 if (update_arg( (
void *)&(args_info->
output_arg),
1198 &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
1199 check_ambiguity,
override, 0, 0,
1208 reset_group_thermalizer (args_info);
1213 &(local_args_info.temperature_given), optarg, 0, 0, ARG_DOUBLE,
1214 check_ambiguity,
override, 0, 0,
1223 reset_group_thermalizer (args_info);
1226 if (update_arg( (
void *)&(args_info->
energy_arg),
1228 &(local_args_info.energy_given), optarg, 0, 0, ARG_DOUBLE,
1229 check_ambiguity,
override, 0, 0,
1238 reset_group_thermalizer (args_info);
1243 &(local_args_info.chargetemperature_given), optarg, 0, 0, ARG_DOUBLE,
1244 check_ambiguity,
override, 0, 0,
1245 "chargetemperature",
'c',
1257 fprintf (stderr,
"%s: option unknown: %c%s\n",
CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error :
""));
1264 fprintf (stderr,
"%s: %d options of group thermalizer were given. One is required%s.\n", argv[0], args_info->
thermalizer_group_counter, (additional_error ? additional_error :
""));
1272 error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error);
1275 cmdline_parser_release (&local_args_info);
1277 if ( error_occurred )
1278 return (EXIT_FAILURE);
1283 int found_prog_name = 0;
1289 args_info->
inputs_num = argc - optind - found_prog_name;
1291 (
char **)(malloc ((args_info->
inputs_num)*
sizeof(
char *))) ;
1292 while (optind < argc)
1293 args_info->
inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1300 cmdline_parser_release (&local_args_info);
1301 return (EXIT_FAILURE);
#define CMDLINE_PARSER_VERSION
the program version
#define CMDLINE_PARSER_PACKAGE_NAME
the complete program name (used for help and version)
#define CMDLINE_PARSER_PACKAGE
the program name (used for printing errors)
The additional parameters to pass to parser functions.
int print_errors
whether getopt_long should print an error message for a bad option (default 1)
int check_required
whether to check that all required options were provided (default 1)
int check_ambiguity
whether to check for options already specified in the option structure gengetopt_args_info (default 0...
int initialize
whether to initialize the option structure gengetopt_args_info (default 1)
int override
whether to override possibly already present options (default 0)
Where the command line options are stored.
unsigned int output_given
Whether output was given.
char * output_orig
output file name original value given at command line.
const char * output_help
output file name help description.
char * temperature_orig
temperature (in Kelvin original value given at command line.
double chargetemperature_arg
charge temperature (K).
unsigned int chargetemperature_given
Whether chargetemperature was given.
unsigned inputs_num
unamed options number
char * chargetemperature_orig
charge temperature (K) original value given at command line.
const char * chargetemperature_help
charge temperature (K) help description.
unsigned int energy_given
Whether energy was given.
const char * help_help
Print help and exit help description.
char * output_arg
output file name.
char ** inputs
unamed options (options without names)
const char * temperature_help
temperature (in Kelvin help description.
char * input_arg
input dump file.
char * energy_orig
energy (kcal/mol) original value given at command line.
double temperature_arg
temperature (in Kelvin (default='300').
double energy_arg
energy (kcal/mol).
unsigned int temperature_given
Whether temperature was given.
unsigned int help_given
Whether help was given.
const char * energy_help
energy (kcal/mol) help description.
unsigned int input_given
Whether input was given.
unsigned int version_given
Whether version was given.
int thermalizer_group_counter
Counter for group thermalizer.
const char * version_help
Print version and exit help description.
char * input_orig
input dump file original value given at command line.
const char * input_help
input dump file help description.
The header file for the command line option parser generated by GNU Gengetopt version 2....
int cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
Save the contents of the option struct into an already open FILE stream.
int cmdline_parser(int argc, char **argv, struct gengetopt_args_info *args_info)
The command line parser.
int cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
Save the contents of the option struct into a (text) file.
int cmdline_parser2(int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
The command line parser (version with additional parameters - deprecated)
int cmdline_parser_required(struct gengetopt_args_info *args_info, const char *prog_name)
Checks that all the required options were specified.
struct cmdline_parser_params * cmdline_parser_params_create(void)
Allocates dynamically a cmdline_parser_params structure and initializes all its fields to their defau...
int cmdline_parser_ext(int argc, char **argv, struct gengetopt_args_info *args_info, struct cmdline_parser_params *params)
The command line parser (version with additional parameters)
void cmdline_parser_init(struct gengetopt_args_info *args_info)
Initializes the passed gengetopt_args_info structure's fields (also set default values for options th...
void cmdline_parser_free(struct gengetopt_args_info *args_info)
Deallocates the string fields of the gengetopt_args_info structure (but does not deallocate the struc...
void cmdline_parser_params_init(struct cmdline_parser_params *params)
Initializes all the fields a cmdline_parser_params structure to their default values.