OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
SequentialPropsCmd.cpp
1/*
2 File autogenerated by gengetopt version 2.22.6
3 generated with the following command:
4 gengetopt --no-handle-error --include-getopt --show-required --unamed-opts --file-name=SequentialPropsCmd --c-extension=cpp --header-extension=hpp
5
6 The developers of gengetopt consider the fixed text that goes in all
7 gengetopt output files to be in the public domain:
8 we make no copyright claims on it.
9*/
10
11/* If we use autoconf. */
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19
20#ifndef FIX_UNUSED
21#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
22#endif
23
24
26
27const char *gengetopt_args_info_purpose = "Computes a time history of static properties from a dump file.";
28
29const char *gengetopt_args_info_usage = "Usage: SequentialProps [OPTIONS]... [FILES]...";
30
31const char *gengetopt_args_info_versiontext = "";
32
33const char *gengetopt_args_info_description = "";
34
35const char *gengetopt_args_info_help[] = {
36 " -h, --help Print help and exit",
37 " -V, --version Print version and exit",
38 " -i, --input=filename input dump file (mandatory)",
39 " -o, --output=filename output file name",
40 " --sele1=selection script select first stuntdouble set",
41 " --sele2=selection script select second stuntdouble set (if sele2 is not\n set, use script from sele1)",
42 " -b, --nbins=INT number of bins (general purpose)\n (default=`100')",
43 " --nbins_z=INT number of bins in z axis (default=`100')",
44 " -x, --centroidX=DOUBLE Location of droplet centroid in x",
45 " -y, --centroidY=DOUBLE Location of droplet centroid in y",
46 " -z, --referenceZ=DOUBLE Reference z-height of solid surface",
47 " -r, --dropletR=DOUBLE Droplet radius in angstroms",
48 " --threshDens=DOUBLE Threshold Density in g/cm^3",
49 " --bufferLength=DOUBLE Buffer length in angstroms",
50 " --rcut=DOUBLE cutoff radius (rcut)",
51 "\n Group: sequentialProps\n an option of this group is required",
52 " -c, --com selection center of mass",
53 " -v, --comvel selection center of mass velocity",
54 " --ca1 contact angle of selection (using center of\n mass)",
55 " --ca2 contact angle of selection (using density\n profile)",
56 " --gcn Generalized Coordinate Number",
57 " -t, --testequi Temperature using all componets of linear and\n angular momentum",
58 0
59};
60
61typedef enum {ARG_NO
62 , ARG_STRING
63 , ARG_INT
64 , ARG_DOUBLE
65} cmdline_parser_arg_type;
66
67static
68void clear_given (struct gengetopt_args_info *args_info);
69static
70void clear_args (struct gengetopt_args_info *args_info);
71
72static int
73cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
74 struct cmdline_parser_params *params, const char *additional_error);
75
76static int
77cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
78
79static char *
80gengetopt_strdup (const char *s);
81
82static
83void clear_given (struct gengetopt_args_info *args_info)
84{
85 args_info->help_given = 0 ;
86 args_info->version_given = 0 ;
87 args_info->input_given = 0 ;
88 args_info->output_given = 0 ;
89 args_info->sele1_given = 0 ;
90 args_info->sele2_given = 0 ;
91 args_info->nbins_given = 0 ;
92 args_info->nbins_z_given = 0 ;
93 args_info->centroidX_given = 0 ;
94 args_info->centroidY_given = 0 ;
95 args_info->referenceZ_given = 0 ;
96 args_info->dropletR_given = 0 ;
97 args_info->threshDens_given = 0 ;
98 args_info->bufferLength_given = 0 ;
99 args_info->rcut_given = 0 ;
100 args_info->com_given = 0 ;
101 args_info->comvel_given = 0 ;
102 args_info->ca1_given = 0 ;
103 args_info->ca2_given = 0 ;
104 args_info->gcn_given = 0 ;
105 args_info->testequi_given = 0 ;
106 args_info->sequentialProps_group_counter = 0 ;
107}
108
109static
110void clear_args (struct gengetopt_args_info *args_info)
111{
112 FIX_UNUSED (args_info);
113 args_info->input_arg = NULL;
114 args_info->input_orig = NULL;
115 args_info->output_arg = NULL;
116 args_info->output_orig = NULL;
117 args_info->sele1_arg = NULL;
118 args_info->sele1_orig = NULL;
119 args_info->sele2_arg = NULL;
120 args_info->sele2_orig = NULL;
121 args_info->nbins_arg = 100;
122 args_info->nbins_orig = NULL;
123 args_info->nbins_z_arg = 100;
124 args_info->nbins_z_orig = NULL;
125 args_info->centroidX_orig = NULL;
126 args_info->centroidY_orig = NULL;
127 args_info->referenceZ_orig = NULL;
128 args_info->dropletR_orig = NULL;
129 args_info->threshDens_orig = NULL;
130 args_info->bufferLength_orig = NULL;
131 args_info->rcut_orig = NULL;
132
133}
134
135static
136void init_args_info(struct gengetopt_args_info *args_info)
137{
138
139
140 args_info->help_help = gengetopt_args_info_help[0] ;
141 args_info->version_help = gengetopt_args_info_help[1] ;
142 args_info->input_help = gengetopt_args_info_help[2] ;
143 args_info->output_help = gengetopt_args_info_help[3] ;
144 args_info->sele1_help = gengetopt_args_info_help[4] ;
145 args_info->sele2_help = gengetopt_args_info_help[5] ;
146 args_info->nbins_help = gengetopt_args_info_help[6] ;
147 args_info->nbins_z_help = gengetopt_args_info_help[7] ;
148 args_info->centroidX_help = gengetopt_args_info_help[8] ;
149 args_info->centroidY_help = gengetopt_args_info_help[9] ;
150 args_info->referenceZ_help = gengetopt_args_info_help[10] ;
151 args_info->dropletR_help = gengetopt_args_info_help[11] ;
152 args_info->threshDens_help = gengetopt_args_info_help[12] ;
153 args_info->bufferLength_help = gengetopt_args_info_help[13] ;
154 args_info->rcut_help = gengetopt_args_info_help[14] ;
155 args_info->com_help = gengetopt_args_info_help[16] ;
156 args_info->comvel_help = gengetopt_args_info_help[17] ;
157 args_info->ca1_help = gengetopt_args_info_help[18] ;
158 args_info->ca2_help = gengetopt_args_info_help[19] ;
159 args_info->gcn_help = gengetopt_args_info_help[20] ;
160 args_info->testequi_help = gengetopt_args_info_help[21] ;
161
162}
163
164void
165cmdline_parser_print_version (void)
166{
167 printf ("%s %s\n",
170
171 if (strlen(gengetopt_args_info_versiontext) > 0)
172 printf("\n%s\n", gengetopt_args_info_versiontext);
173}
174
175static void print_help_common(void) {
176 cmdline_parser_print_version ();
177
178 if (strlen(gengetopt_args_info_purpose) > 0)
179 printf("\n%s\n", gengetopt_args_info_purpose);
180
181 if (strlen(gengetopt_args_info_usage) > 0)
182 printf("\n%s\n", gengetopt_args_info_usage);
183
184 printf("\n");
185
186 if (strlen(gengetopt_args_info_description) > 0)
187 printf("%s\n\n", gengetopt_args_info_description);
188}
189
190void
191cmdline_parser_print_help (void)
192{
193 int i = 0;
194 print_help_common();
195 while (gengetopt_args_info_help[i])
196 printf("%s\n", gengetopt_args_info_help[i++]);
197}
198
199void
200cmdline_parser_init (struct gengetopt_args_info *args_info)
201{
202 clear_given (args_info);
203 clear_args (args_info);
204 init_args_info (args_info);
205
206 args_info->inputs = 0;
207 args_info->inputs_num = 0;
208}
209
210void
211cmdline_parser_params_init(struct cmdline_parser_params *params)
212{
213 if (params)
214 {
215 params->override = 0;
216 params->initialize = 1;
217 params->check_required = 1;
218 params->check_ambiguity = 0;
219 params->print_errors = 1;
220 }
221}
222
225{
226 struct cmdline_parser_params *params =
227 (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
229 return params;
230}
231
232static void
233free_string_field (char **s)
234{
235 if (*s)
236 {
237 free (*s);
238 *s = 0;
239 }
240}
241
242
243static void
244cmdline_parser_release (struct gengetopt_args_info *args_info)
245{
246 unsigned int i;
247 free_string_field (&(args_info->input_arg));
248 free_string_field (&(args_info->input_orig));
249 free_string_field (&(args_info->output_arg));
250 free_string_field (&(args_info->output_orig));
251 free_string_field (&(args_info->sele1_arg));
252 free_string_field (&(args_info->sele1_orig));
253 free_string_field (&(args_info->sele2_arg));
254 free_string_field (&(args_info->sele2_orig));
255 free_string_field (&(args_info->nbins_orig));
256 free_string_field (&(args_info->nbins_z_orig));
257 free_string_field (&(args_info->centroidX_orig));
258 free_string_field (&(args_info->centroidY_orig));
259 free_string_field (&(args_info->referenceZ_orig));
260 free_string_field (&(args_info->dropletR_orig));
261 free_string_field (&(args_info->threshDens_orig));
262 free_string_field (&(args_info->bufferLength_orig));
263 free_string_field (&(args_info->rcut_orig));
264
265
266 for (i = 0; i < args_info->inputs_num; ++i)
267 free (args_info->inputs [i]);
268
269 if (args_info->inputs_num)
270 free (args_info->inputs);
271
272 clear_given (args_info);
273}
274
275
276static void
277write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
278{
279 FIX_UNUSED (values);
280 if (arg) {
281 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
282 } else {
283 fprintf(outfile, "%s\n", opt);
284 }
285}
286
287
288int
289cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
290{
291 int i = 0;
292
293 if (!outfile)
294 {
295 fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
296 return EXIT_FAILURE;
297 }
298
299 if (args_info->help_given)
300 write_into_file(outfile, "help", 0, 0 );
301 if (args_info->version_given)
302 write_into_file(outfile, "version", 0, 0 );
303 if (args_info->input_given)
304 write_into_file(outfile, "input", args_info->input_orig, 0);
305 if (args_info->output_given)
306 write_into_file(outfile, "output", args_info->output_orig, 0);
307 if (args_info->sele1_given)
308 write_into_file(outfile, "sele1", args_info->sele1_orig, 0);
309 if (args_info->sele2_given)
310 write_into_file(outfile, "sele2", args_info->sele2_orig, 0);
311 if (args_info->nbins_given)
312 write_into_file(outfile, "nbins", args_info->nbins_orig, 0);
313 if (args_info->nbins_z_given)
314 write_into_file(outfile, "nbins_z", args_info->nbins_z_orig, 0);
315 if (args_info->centroidX_given)
316 write_into_file(outfile, "centroidX", args_info->centroidX_orig, 0);
317 if (args_info->centroidY_given)
318 write_into_file(outfile, "centroidY", args_info->centroidY_orig, 0);
319 if (args_info->referenceZ_given)
320 write_into_file(outfile, "referenceZ", args_info->referenceZ_orig, 0);
321 if (args_info->dropletR_given)
322 write_into_file(outfile, "dropletR", args_info->dropletR_orig, 0);
323 if (args_info->threshDens_given)
324 write_into_file(outfile, "threshDens", args_info->threshDens_orig, 0);
325 if (args_info->bufferLength_given)
326 write_into_file(outfile, "bufferLength", args_info->bufferLength_orig, 0);
327 if (args_info->rcut_given)
328 write_into_file(outfile, "rcut", args_info->rcut_orig, 0);
329 if (args_info->com_given)
330 write_into_file(outfile, "com", 0, 0 );
331 if (args_info->comvel_given)
332 write_into_file(outfile, "comvel", 0, 0 );
333 if (args_info->ca1_given)
334 write_into_file(outfile, "ca1", 0, 0 );
335 if (args_info->ca2_given)
336 write_into_file(outfile, "ca2", 0, 0 );
337 if (args_info->gcn_given)
338 write_into_file(outfile, "gcn", 0, 0 );
339 if (args_info->testequi_given)
340 write_into_file(outfile, "testequi", 0, 0 );
341
342
343 i = EXIT_SUCCESS;
344 return i;
345}
346
347int
348cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
349{
350 FILE *outfile;
351 int i = 0;
352
353 outfile = fopen(filename, "w");
354
355 if (!outfile)
356 {
357 fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
358 return EXIT_FAILURE;
359 }
360
361 i = cmdline_parser_dump(outfile, args_info);
362 fclose (outfile);
363
364 return i;
365}
366
367void
369{
370 cmdline_parser_release (args_info);
371}
372
373/** @brief replacement of strdup, which is not standard */
374char *
375gengetopt_strdup (const char *s)
376{
377 char *result = 0;
378 if (!s)
379 return result;
380
381 result = (char*)malloc(strlen(s) + 1);
382 if (result == (char*)0)
383 return (char*)0;
384 strcpy(result, s);
385 return result;
386}
387
388static void
389reset_group_sequentialProps(struct gengetopt_args_info *args_info)
390{
391 if (! args_info->sequentialProps_group_counter)
392 return;
393
394 args_info->com_given = 0 ;
395 args_info->comvel_given = 0 ;
396 args_info->ca1_given = 0 ;
397 args_info->ca2_given = 0 ;
398 args_info->gcn_given = 0 ;
399 args_info->testequi_given = 0 ;
400
401 args_info->sequentialProps_group_counter = 0;
402}
403
404int
405cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
406{
407 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
408}
409
410int
411cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
412 struct cmdline_parser_params *params)
413{
414 int result;
415 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
416
417 return result;
418}
419
420int
421cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
422{
423 int result;
424 struct cmdline_parser_params params;
425
426 params.override = override;
427 params.initialize = initialize;
429 params.check_ambiguity = 0;
430 params.print_errors = 1;
431
432 result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
433
434 return result;
435}
436
437int
438cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
439{
440 int result = EXIT_SUCCESS;
441
442 if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
443 result = EXIT_FAILURE;
444
445 return result;
446}
447
448int
449cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
450{
451 int error_occurred = 0;
452 FIX_UNUSED (additional_error);
453
454 /* checks for required options */
455 if (! args_info->input_given)
456 {
457 fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
458 error_occurred = 1;
459 }
460
461 if (args_info->sequentialProps_group_counter == 0)
462 {
463 fprintf (stderr, "%s: %d options of group sequentialProps were given. One is required%s.\n", prog_name, args_info->sequentialProps_group_counter, (additional_error ? additional_error : ""));
464 error_occurred = 1;
465 }
466
467
468 /* checks for dependences among options */
469
470 return error_occurred;
471}
472
473/*
474 * Extracted from the glibc source tree, version 2.3.6
475 *
476 * Licensed under the GPL as per the whole glibc source tree.
477 *
478 * This file was modified so that getopt_long can be called
479 * many times without risking previous memory to be spoiled.
480 *
481 * Modified by Andre Noll and Lorenzo Bettini for use in
482 * GNU gengetopt generated files.
483 *
484 */
485
486/*
487 * we must include anything we need since this file is not thought to be
488 * inserted in a file already using getopt.h
489 *
490 * Lorenzo
491 */
492
493struct option
494{
495 const char *name;
496 /* has_arg can't be an enum because some compilers complain about
497 type mismatches in all the code that assumes it is an int. */
498 int has_arg;
499 int *flag;
500 int val;
501};
502
503/* This version of `getopt' appears to the caller like standard Unix `getopt'
504 but it behaves differently for the user, since it allows the user
505 to intersperse the options with the other arguments.
506
507 As `getopt' works, it permutes the elements of ARGV so that,
508 when it is done, all the options precede everything else. Thus
509 all application programs are extended to handle flexible argument order.
510*/
511/*
512 If the field `flag' is not NULL, it points to a variable that is set
513 to the value given in the field `val' when the option is found, but
514 left unchanged if the option is not found.
515
516 To have a long-named option do something other than set an `int' to
517 a compiled-in constant, such as set a value from `custom_optarg', set the
518 option's `flag' field to zero and its `val' field to a nonzero
519 value (the equivalent single-letter option character, if there is
520 one). For long options that have a zero `flag' field, `getopt'
521 returns the contents of the `val' field. */
522
523/* Names for the values of the `has_arg' field of `struct option'. */
524#ifndef no_argument
525#define no_argument 0
526#endif
527
528#ifndef required_argument
529#define required_argument 1
530#endif
531
532#ifndef optional_argument
533#define optional_argument 2
534#endif
535
536struct custom_getopt_data {
537 /*
538 * These have exactly the same meaning as the corresponding global variables,
539 * except that they are used for the reentrant versions of getopt.
540 */
541 int custom_optind;
542 int custom_opterr;
543 int custom_optopt;
544 char *custom_optarg;
545
546 /* True if the internal members have been initialized. */
547 int initialized;
548
549 /*
550 * The next char to be scanned in the option-element in which the last option
551 * character we returned was found. This allows us to pick up the scan where
552 * we left off. If this is zero, or a null string, it means resume the scan by
553 * advancing to the next ARGV-element.
554 */
555 char *nextchar;
556
557 /*
558 * Describe the part of ARGV that contains non-options that have been skipped.
559 * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
560 * the index after the last of them.
561 */
562 int first_nonopt;
563 int last_nonopt;
564};
565
566/*
567 * the variables optarg, optind, opterr and optopt are renamed with
568 * the custom_ prefix so that they don't interfere with getopt ones.
569 *
570 * Moreover they're static so they are visible only from within the
571 * file where this very file will be included.
572 */
573
574/*
575 * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an
576 * option that takes an argument, the argument value is returned here.
577 */
578static char *custom_optarg;
579
580/*
581 * Index in ARGV of the next element to be scanned. This is used for
582 * communication to and from the caller and for communication between
583 * successive calls to `custom_getopt'.
584 *
585 * On entry to `custom_getopt', 1 means this is the first call; initialize.
586 *
587 * When `custom_getopt' returns -1, this is the index of the first of the non-option
588 * elements that the caller should itself scan.
589 *
590 * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
591 * has been scanned so far.
592 *
593 * 1003.2 says this must be 1 before any call.
594 */
595static int custom_optind = 1;
596
597/*
598 * Callers store zero here to inhibit the error message for unrecognized
599 * options.
600 */
601static int custom_opterr = 1;
602
603/*
604 * Set to an option character which was unrecognized. This must be initialized
605 * on some systems to avoid linking in the system's own getopt implementation.
606 */
607static int custom_optopt = '?';
608
609/*
610 * Exchange two adjacent subsequences of ARGV. One subsequence is elements
611 * [first_nonopt,last_nonopt) which contains all the non-options that have been
612 * skipped so far. The other is elements [last_nonopt,custom_optind), which contains
613 * all the options processed since those non-options were skipped.
614 * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
615 * indices of the non-options in ARGV after they are moved.
616 */
617static void exchange(char **argv, struct custom_getopt_data *d)
618{
619 int bottom = d->first_nonopt;
620 int middle = d->last_nonopt;
621 int top = d->custom_optind;
622 char *tem;
623
624 /*
625 * Exchange the shorter segment with the far end of the longer segment.
626 * That puts the shorter segment into the right place. It leaves the
627 * longer segment in the right place overall, but it consists of two
628 * parts that need to be swapped next.
629 */
630 while (top > middle && middle > bottom) {
631 if (top - middle > middle - bottom) {
632 /* Bottom segment is the short one. */
633 int len = middle - bottom;
634 int i;
635
636 /* Swap it with the top part of the top segment. */
637 for (i = 0; i < len; i++) {
638 tem = argv[bottom + i];
639 argv[bottom + i] =
640 argv[top - (middle - bottom) + i];
641 argv[top - (middle - bottom) + i] = tem;
642 }
643 /* Exclude the moved bottom segment from further swapping. */
644 top -= len;
645 } else {
646 /* Top segment is the short one. */
647 int len = top - middle;
648 int i;
649
650 /* Swap it with the bottom part of the bottom segment. */
651 for (i = 0; i < len; i++) {
652 tem = argv[bottom + i];
653 argv[bottom + i] = argv[middle + i];
654 argv[middle + i] = tem;
655 }
656 /* Exclude the moved top segment from further swapping. */
657 bottom += len;
658 }
659 }
660 /* Update records for the slots the non-options now occupy. */
661 d->first_nonopt += (d->custom_optind - d->last_nonopt);
662 d->last_nonopt = d->custom_optind;
663}
664
665/* Initialize the internal data when the first call is made. */
666static void custom_getopt_initialize(struct custom_getopt_data *d)
667{
668 /*
669 * Start processing options with ARGV-element 1 (since ARGV-element 0
670 * is the program name); the sequence of previously skipped non-option
671 * ARGV-elements is empty.
672 */
673 d->first_nonopt = d->last_nonopt = d->custom_optind;
674 d->nextchar = NULL;
675 d->initialized = 1;
676}
677
678#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
679
680/* return: zero: continue, nonzero: return given value to user */
681static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
682 struct custom_getopt_data *d)
683{
684 /*
685 * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
686 * moved back by the user (who may also have changed the arguments).
687 */
688 if (d->last_nonopt > d->custom_optind)
689 d->last_nonopt = d->custom_optind;
690 if (d->first_nonopt > d->custom_optind)
691 d->first_nonopt = d->custom_optind;
692 /*
693 * If we have just processed some options following some
694 * non-options, exchange them so that the options come first.
695 */
696 if (d->first_nonopt != d->last_nonopt &&
697 d->last_nonopt != d->custom_optind)
698 exchange((char **) argv, d);
699 else if (d->last_nonopt != d->custom_optind)
700 d->first_nonopt = d->custom_optind;
701 /*
702 * Skip any additional non-options and extend the range of
703 * non-options previously skipped.
704 */
705 while (d->custom_optind < argc && NONOPTION_P)
706 d->custom_optind++;
707 d->last_nonopt = d->custom_optind;
708 /*
709 * The special ARGV-element `--' means premature end of options. Skip
710 * it like a null option, then exchange with previous non-options as if
711 * it were an option, then skip everything else like a non-option.
712 */
713 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
714 d->custom_optind++;
715 if (d->first_nonopt != d->last_nonopt
716 && d->last_nonopt != d->custom_optind)
717 exchange((char **) argv, d);
718 else if (d->first_nonopt == d->last_nonopt)
719 d->first_nonopt = d->custom_optind;
720 d->last_nonopt = argc;
721 d->custom_optind = argc;
722 }
723 /*
724 * If we have done all the ARGV-elements, stop the scan and back over
725 * any non-options that we skipped and permuted.
726 */
727 if (d->custom_optind == argc) {
728 /*
729 * Set the next-arg-index to point at the non-options that we
730 * previously skipped, so the caller will digest them.
731 */
732 if (d->first_nonopt != d->last_nonopt)
733 d->custom_optind = d->first_nonopt;
734 return -1;
735 }
736 /*
737 * If we have come to a non-option and did not permute it, either stop
738 * the scan or describe it to the caller and pass it by.
739 */
740 if (NONOPTION_P) {
741 d->custom_optarg = argv[d->custom_optind++];
742 return 1;
743 }
744 /*
745 * We have found another option-ARGV-element. Skip the initial
746 * punctuation.
747 */
748 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
749 return 0;
750}
751
752/*
753 * Check whether the ARGV-element is a long option.
754 *
755 * If there's a long option "fubar" and the ARGV-element is "-fu", consider
756 * that an abbreviation of the long option, just like "--fu", and not "-f" with
757 * arg "u".
758 *
759 * This distinction seems to be the most useful approach.
760 *
761 */
762static int check_long_opt(int argc, char *const *argv, const char *optstring,
763 const struct option *longopts, int *longind,
764 int print_errors, struct custom_getopt_data *d)
765{
766 char *nameend;
767 const struct option *p;
768 const struct option *pfound = NULL;
769 int exact = 0;
770 int ambig = 0;
771 int indfound = -1;
772 int option_index;
773
774 for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
775 /* Do nothing. */ ;
776
777 /* Test all long options for either exact match or abbreviated matches */
778 for (p = longopts, option_index = 0; p->name; p++, option_index++)
779 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
780 if ((unsigned int) (nameend - d->nextchar)
781 == (unsigned int) strlen(p->name)) {
782 /* Exact match found. */
783 pfound = p;
784 indfound = option_index;
785 exact = 1;
786 break;
787 } else if (pfound == NULL) {
788 /* First nonexact match found. */
789 pfound = p;
790 indfound = option_index;
791 } else if (pfound->has_arg != p->has_arg
792 || pfound->flag != p->flag
793 || pfound->val != p->val)
794 /* Second or later nonexact match found. */
795 ambig = 1;
796 }
797 if (ambig && !exact) {
798 if (print_errors) {
799 fprintf(stderr,
800 "%s: option `%s' is ambiguous\n",
801 argv[0], argv[d->custom_optind]);
802 }
803 d->nextchar += strlen(d->nextchar);
804 d->custom_optind++;
805 d->custom_optopt = 0;
806 return '?';
807 }
808 if (pfound) {
809 option_index = indfound;
810 d->custom_optind++;
811 if (*nameend) {
812 if (pfound->has_arg != no_argument)
813 d->custom_optarg = nameend + 1;
814 else {
815 if (print_errors) {
816 if (argv[d->custom_optind - 1][1] == '-') {
817 /* --option */
818 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
819 argv[0], pfound->name);
820 } else {
821 /* +option or -option */
822 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
823 argv[0], argv[d->custom_optind - 1][0], pfound->name);
824 }
825
826 }
827 d->nextchar += strlen(d->nextchar);
828 d->custom_optopt = pfound->val;
829 return '?';
830 }
831 } else if (pfound->has_arg == required_argument) {
832 if (d->custom_optind < argc)
833 d->custom_optarg = argv[d->custom_optind++];
834 else {
835 if (print_errors) {
836 fprintf(stderr,
837 "%s: option `%s' requires an argument\n",
838 argv[0],
839 argv[d->custom_optind - 1]);
840 }
841 d->nextchar += strlen(d->nextchar);
842 d->custom_optopt = pfound->val;
843 return optstring[0] == ':' ? ':' : '?';
844 }
845 }
846 d->nextchar += strlen(d->nextchar);
847 if (longind != NULL)
848 *longind = option_index;
849 if (pfound->flag) {
850 *(pfound->flag) = pfound->val;
851 return 0;
852 }
853 return pfound->val;
854 }
855 /*
856 * Can't find it as a long option. If this is not getopt_long_only, or
857 * the option starts with '--' or is not a valid short option, then
858 * it's an error. Otherwise interpret it as a short option.
859 */
860 if (print_errors) {
861 if (argv[d->custom_optind][1] == '-') {
862 /* --option */
863 fprintf(stderr,
864 "%s: unrecognized option `--%s'\n",
865 argv[0], d->nextchar);
866 } else {
867 /* +option or -option */
868 fprintf(stderr,
869 "%s: unrecognized option `%c%s'\n",
870 argv[0], argv[d->custom_optind][0],
871 d->nextchar);
872 }
873 }
874 d->nextchar = (char *) "";
875 d->custom_optind++;
876 d->custom_optopt = 0;
877 return '?';
878}
879
880static int check_short_opt(int argc, char *const *argv, const char *optstring,
881 int print_errors, struct custom_getopt_data *d)
882{
883 char c = *d->nextchar++;
884 const char *temp = strchr(optstring, c);
885
886 /* Increment `custom_optind' when we start to process its last character. */
887 if (*d->nextchar == '\0')
888 ++d->custom_optind;
889 if (!temp || c == ':') {
890 if (print_errors)
891 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
892
893 d->custom_optopt = c;
894 return '?';
895 }
896 if (temp[1] == ':') {
897 if (temp[2] == ':') {
898 /* This is an option that accepts an argument optionally. */
899 if (*d->nextchar != '\0') {
900 d->custom_optarg = d->nextchar;
901 d->custom_optind++;
902 } else
903 d->custom_optarg = NULL;
904 d->nextchar = NULL;
905 } else {
906 /* This is an option that requires an argument. */
907 if (*d->nextchar != '\0') {
908 d->custom_optarg = d->nextchar;
909 /*
910 * If we end this ARGV-element by taking the
911 * rest as an arg, we must advance to the next
912 * element now.
913 */
914 d->custom_optind++;
915 } else if (d->custom_optind == argc) {
916 if (print_errors) {
917 fprintf(stderr,
918 "%s: option requires an argument -- %c\n",
919 argv[0], c);
920 }
921 d->custom_optopt = c;
922 if (optstring[0] == ':')
923 c = ':';
924 else
925 c = '?';
926 } else
927 /*
928 * We already incremented `custom_optind' once;
929 * increment it again when taking next ARGV-elt
930 * as argument.
931 */
932 d->custom_optarg = argv[d->custom_optind++];
933 d->nextchar = NULL;
934 }
935 }
936 return c;
937}
938
939/*
940 * Scan elements of ARGV for option characters given in OPTSTRING.
941 *
942 * If an element of ARGV starts with '-', and is not exactly "-" or "--",
943 * then it is an option element. The characters of this element
944 * (aside from the initial '-') are option characters. If `getopt'
945 * is called repeatedly, it returns successively each of the option characters
946 * from each of the option elements.
947 *
948 * If `getopt' finds another option character, it returns that character,
949 * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
950 * resume the scan with the following option character or ARGV-element.
951 *
952 * If there are no more option characters, `getopt' returns -1.
953 * Then `custom_optind' is the index in ARGV of the first ARGV-element
954 * that is not an option. (The ARGV-elements have been permuted
955 * so that those that are not options now come last.)
956 *
957 * OPTSTRING is a string containing the legitimate option characters.
958 * If an option character is seen that is not listed in OPTSTRING,
959 * return '?' after printing an error message. If you set `custom_opterr' to
960 * zero, the error message is suppressed but we still return '?'.
961 *
962 * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
963 * so the following text in the same ARGV-element, or the text of the following
964 * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that
965 * wants an optional arg; if there is text in the current ARGV-element,
966 * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
967 *
968 * If OPTSTRING starts with `-' or `+', it requests different methods of
969 * handling the non-option ARGV-elements.
970 * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
971 *
972 * Long-named options begin with `--' instead of `-'.
973 * Their names may be abbreviated as long as the abbreviation is unique
974 * or is an exact match for some defined option. If they have an
975 * argument, it follows the option name in the same ARGV-element, separated
976 * from the option name by a `=', or else the in next ARGV-element.
977 * When `getopt' finds a long-named option, it returns 0 if that option's
978 * `flag' field is nonzero, the value of the option's `val' field
979 * if the `flag' field is zero.
980 *
981 * The elements of ARGV aren't really const, because we permute them.
982 * But we pretend they're const in the prototype to be compatible
983 * with other systems.
984 *
985 * LONGOPTS is a vector of `struct option' terminated by an
986 * element containing a name which is zero.
987 *
988 * LONGIND returns the index in LONGOPT of the long-named option found.
989 * It is only valid when a long-named option has been found by the most
990 * recent call.
991 *
992 * Return the option character from OPTS just read. Return -1 when there are
993 * no more options. For unrecognized options, or options missing arguments,
994 * `custom_optopt' is set to the option letter, and '?' is returned.
995 *
996 * The OPTS string is a list of characters which are recognized option letters,
997 * optionally followed by colons, specifying that that letter takes an
998 * argument, to be placed in `custom_optarg'.
999 *
1000 * If a letter in OPTS is followed by two colons, its argument is optional.
1001 * This behavior is specific to the GNU `getopt'.
1002 *
1003 * The argument `--' causes premature termination of argument scanning,
1004 * explicitly telling `getopt' that there are no more options. If OPTS begins
1005 * with `--', then non-option arguments are treated as arguments to the option
1006 * '\0'. This behavior is specific to the GNU `getopt'.
1007 */
1008
1009static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
1010 const struct option *longopts, int *longind,
1011 struct custom_getopt_data *d)
1012{
1013 int ret, print_errors = d->custom_opterr;
1014
1015 if (optstring[0] == ':')
1016 print_errors = 0;
1017 if (argc < 1)
1018 return -1;
1019 d->custom_optarg = NULL;
1020
1021 /*
1022 * This is a big difference with GNU getopt, since optind == 0
1023 * means initialization while here 1 means first call.
1024 */
1025 if (d->custom_optind == 0 || !d->initialized) {
1026 if (d->custom_optind == 0)
1027 d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */
1028 custom_getopt_initialize(d);
1029 }
1030 if (d->nextchar == NULL || *d->nextchar == '\0') {
1031 ret = shuffle_argv(argc, argv, longopts, d);
1032 if (ret)
1033 return ret;
1034 }
1035 if (longopts && (argv[d->custom_optind][1] == '-' ))
1036 return check_long_opt(argc, argv, optstring, longopts,
1037 longind, print_errors, d);
1038 return check_short_opt(argc, argv, optstring, print_errors, d);
1039}
1040
1041static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1042 const struct option *longopts, int *longind)
1043{
1044 int result;
1045 /* Keep a global copy of all internal members of d */
1046 static struct custom_getopt_data d;
1047
1048 d.custom_optind = custom_optind;
1049 d.custom_opterr = custom_opterr;
1050 result = getopt_internal_r(argc, argv, optstring, longopts,
1051 longind, &d);
1052 custom_optind = d.custom_optind;
1053 custom_optarg = d.custom_optarg;
1054 custom_optopt = d.custom_optopt;
1055 return result;
1056}
1057
1058static int custom_getopt_long (int argc, char *const *argv, const char *options,
1059 const struct option *long_options, int *opt_index)
1060{
1061 return custom_getopt_internal(argc, argv, options, long_options,
1062 opt_index);
1063}
1064
1065
1066static char *package_name = 0;
1067
1068/**
1069 * @brief updates an option
1070 * @param field the generic pointer to the field to update
1071 * @param orig_field the pointer to the orig field
1072 * @param field_given the pointer to the number of occurrence of this option
1073 * @param prev_given the pointer to the number of occurrence already seen
1074 * @param value the argument for this option (if null no arg was specified)
1075 * @param possible_values the possible values for this option (if specified)
1076 * @param default_value the default value (in case the option only accepts fixed values)
1077 * @param arg_type the type of this option
1078 * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
1079 * @param override @see cmdline_parser_params.override
1080 * @param no_free whether to free a possible previous value
1081 * @param multiple_option whether this is a multiple option
1082 * @param long_opt the corresponding long option
1083 * @param short_opt the corresponding short option (or '-' if none)
1084 * @param additional_error possible further error specification
1085 */
1086static
1087int update_arg(void *field, char **orig_field,
1088 unsigned int *field_given, unsigned int *prev_given,
1089 char *value, const char *possible_values[],
1090 const char *default_value,
1091 cmdline_parser_arg_type arg_type,
1092 int check_ambiguity, int override,
1093 int no_free, int multiple_option,
1094 const char *long_opt, char short_opt,
1095 const char *additional_error)
1096{
1097 char *stop_char = 0;
1098 const char *val = value;
1099 int found;
1100 char **string_field;
1101 FIX_UNUSED (field);
1102
1103 stop_char = 0;
1104 found = 0;
1105
1106 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1107 {
1108 if (short_opt != '-')
1109 fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
1110 package_name, long_opt, short_opt,
1111 (additional_error ? additional_error : ""));
1112 else
1113 fprintf (stderr, "%s: `--%s' option given more than once%s\n",
1114 package_name, long_opt,
1115 (additional_error ? additional_error : ""));
1116 return 1; /* failure */
1117 }
1118
1119 FIX_UNUSED (default_value);
1120
1121 if (field_given && *field_given && ! override)
1122 return 0;
1123 if (prev_given)
1124 (*prev_given)++;
1125 if (field_given)
1126 (*field_given)++;
1127 if (possible_values)
1128 val = possible_values[found];
1129
1130 switch(arg_type) {
1131 case ARG_INT:
1132 if (val) *((int *)field) = strtol (val, &stop_char, 0);
1133 break;
1134 case ARG_DOUBLE:
1135 if (val) *((double *)field) = strtod (val, &stop_char);
1136 break;
1137 case ARG_STRING:
1138 if (val) {
1139 string_field = (char **)field;
1140 if (!no_free && *string_field)
1141 free (*string_field); /* free previous string */
1142 *string_field = gengetopt_strdup (val);
1143 }
1144 break;
1145 default:
1146 break;
1147 };
1148
1149 /* check numeric conversion */
1150 switch(arg_type) {
1151 case ARG_INT:
1152 case ARG_DOUBLE:
1153 if (val && !(stop_char && *stop_char == '\0')) {
1154 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1155 return 1; /* failure */
1156 }
1157 break;
1158 default:
1159 ;
1160 };
1161
1162 /* store the original value */
1163 switch(arg_type) {
1164 case ARG_NO:
1165 break;
1166 default:
1167 if (value && orig_field) {
1168 if (no_free) {
1169 *orig_field = value;
1170 } else {
1171 if (*orig_field)
1172 free (*orig_field); /* free previous string */
1173 *orig_field = gengetopt_strdup (value);
1174 }
1175 }
1176 };
1177
1178 return 0; /* OK */
1179}
1180
1181
1182int
1183cmdline_parser_internal (
1184 int argc, char **argv, struct gengetopt_args_info *args_info,
1185 struct cmdline_parser_params *params, const char *additional_error)
1186{
1187 int c; /* Character of the parsed option. */
1188
1189 int error_occurred = 0;
1190 struct gengetopt_args_info local_args_info;
1191
1192 int override;
1193 int initialize;
1194 int check_required;
1195 int check_ambiguity;
1196
1197 char *optarg;
1198 int optind;
1199 int opterr;
1200 int optopt;
1201
1202 package_name = argv[0];
1203
1204 override = params->override;
1205 initialize = params->initialize;
1206 check_required = params->check_required;
1207 check_ambiguity = params->check_ambiguity;
1208
1209 if (initialize)
1210 cmdline_parser_init (args_info);
1211
1212 cmdline_parser_init (&local_args_info);
1213
1214 optarg = 0;
1215 optind = 0;
1216 opterr = params->print_errors;
1217 optopt = '?';
1218
1219 while (1)
1220 {
1221 int option_index = 0;
1222
1223 static struct option long_options[] = {
1224 { "help", 0, NULL, 'h' },
1225 { "version", 0, NULL, 'V' },
1226 { "input", 1, NULL, 'i' },
1227 { "output", 1, NULL, 'o' },
1228 { "sele1", 1, NULL, 0 },
1229 { "sele2", 1, NULL, 0 },
1230 { "nbins", 1, NULL, 'b' },
1231 { "nbins_z", 1, NULL, 0 },
1232 { "centroidX", 1, NULL, 'x' },
1233 { "centroidY", 1, NULL, 'y' },
1234 { "referenceZ", 1, NULL, 'z' },
1235 { "dropletR", 1, NULL, 'r' },
1236 { "threshDens", 1, NULL, 0 },
1237 { "bufferLength", 1, NULL, 0 },
1238 { "rcut", 1, NULL, 0 },
1239 { "com", 0, NULL, 'c' },
1240 { "comvel", 0, NULL, 'v' },
1241 { "ca1", 0, NULL, 0 },
1242 { "ca2", 0, NULL, 0 },
1243 { "gcn", 0, NULL, 0 },
1244 { "testequi", 0, NULL, 't' },
1245 { 0, 0, 0, 0 }
1246 };
1247
1248 custom_optarg = optarg;
1249 custom_optind = optind;
1250 custom_opterr = opterr;
1251 custom_optopt = optopt;
1252
1253 c = custom_getopt_long (argc, argv, "hVi:o:b:x:y:z:r:cvt", long_options, &option_index);
1254
1255 optarg = custom_optarg;
1256 optind = custom_optind;
1257 opterr = custom_opterr;
1258 optopt = custom_optopt;
1259
1260 if (c == -1) break; /* Exit from `while (1)' loop. */
1261
1262 switch (c)
1263 {
1264 case 'h': /* Print help and exit. */
1265 cmdline_parser_print_help ();
1266 cmdline_parser_free (&local_args_info);
1267 exit (EXIT_SUCCESS);
1268
1269 case 'V': /* Print version and exit. */
1270 cmdline_parser_print_version ();
1271 cmdline_parser_free (&local_args_info);
1272 exit (EXIT_SUCCESS);
1273
1274 case 'i': /* input dump file. */
1275
1276
1277 if (update_arg( (void *)&(args_info->input_arg),
1278 &(args_info->input_orig), &(args_info->input_given),
1279 &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
1280 check_ambiguity, override, 0, 0,
1281 "input", 'i',
1282 additional_error))
1283 goto failure;
1284
1285 break;
1286 case 'o': /* output file name. */
1287
1288
1289 if (update_arg( (void *)&(args_info->output_arg),
1290 &(args_info->output_orig), &(args_info->output_given),
1291 &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
1292 check_ambiguity, override, 0, 0,
1293 "output", 'o',
1294 additional_error))
1295 goto failure;
1296
1297 break;
1298 case 'b': /* number of bins (general purpose). */
1299
1300
1301 if (update_arg( (void *)&(args_info->nbins_arg),
1302 &(args_info->nbins_orig), &(args_info->nbins_given),
1303 &(local_args_info.nbins_given), optarg, 0, "100", ARG_INT,
1304 check_ambiguity, override, 0, 0,
1305 "nbins", 'b',
1306 additional_error))
1307 goto failure;
1308
1309 break;
1310 case 'x': /* Location of droplet centroid in x. */
1311
1312
1313 if (update_arg( (void *)&(args_info->centroidX_arg),
1314 &(args_info->centroidX_orig), &(args_info->centroidX_given),
1315 &(local_args_info.centroidX_given), optarg, 0, 0, ARG_DOUBLE,
1316 check_ambiguity, override, 0, 0,
1317 "centroidX", 'x',
1318 additional_error))
1319 goto failure;
1320
1321 break;
1322 case 'y': /* Location of droplet centroid in y. */
1323
1324
1325 if (update_arg( (void *)&(args_info->centroidY_arg),
1326 &(args_info->centroidY_orig), &(args_info->centroidY_given),
1327 &(local_args_info.centroidY_given), optarg, 0, 0, ARG_DOUBLE,
1328 check_ambiguity, override, 0, 0,
1329 "centroidY", 'y',
1330 additional_error))
1331 goto failure;
1332
1333 break;
1334 case 'z': /* Reference z-height of solid surface. */
1335
1336
1337 if (update_arg( (void *)&(args_info->referenceZ_arg),
1338 &(args_info->referenceZ_orig), &(args_info->referenceZ_given),
1339 &(local_args_info.referenceZ_given), optarg, 0, 0, ARG_DOUBLE,
1340 check_ambiguity, override, 0, 0,
1341 "referenceZ", 'z',
1342 additional_error))
1343 goto failure;
1344
1345 break;
1346 case 'r': /* Droplet radius in angstroms. */
1347
1348
1349 if (update_arg( (void *)&(args_info->dropletR_arg),
1350 &(args_info->dropletR_orig), &(args_info->dropletR_given),
1351 &(local_args_info.dropletR_given), optarg, 0, 0, ARG_DOUBLE,
1352 check_ambiguity, override, 0, 0,
1353 "dropletR", 'r',
1354 additional_error))
1355 goto failure;
1356
1357 break;
1358 case 'c': /* selection center of mass. */
1359
1360 if (args_info->sequentialProps_group_counter && override)
1361 reset_group_sequentialProps (args_info);
1362 args_info->sequentialProps_group_counter += 1;
1363
1364 if (update_arg( 0 ,
1365 0 , &(args_info->com_given),
1366 &(local_args_info.com_given), optarg, 0, 0, ARG_NO,
1367 check_ambiguity, override, 0, 0,
1368 "com", 'c',
1369 additional_error))
1370 goto failure;
1371
1372 break;
1373 case 'v': /* selection center of mass velocity. */
1374
1375 if (args_info->sequentialProps_group_counter && override)
1376 reset_group_sequentialProps (args_info);
1377 args_info->sequentialProps_group_counter += 1;
1378
1379 if (update_arg( 0 ,
1380 0 , &(args_info->comvel_given),
1381 &(local_args_info.comvel_given), optarg, 0, 0, ARG_NO,
1382 check_ambiguity, override, 0, 0,
1383 "comvel", 'v',
1384 additional_error))
1385 goto failure;
1386
1387 break;
1388 case 't': /* Temperature using all componets of linear and angular momentum. */
1389
1390 if (args_info->sequentialProps_group_counter && override)
1391 reset_group_sequentialProps (args_info);
1392 args_info->sequentialProps_group_counter += 1;
1393
1394 if (update_arg( 0 ,
1395 0 , &(args_info->testequi_given),
1396 &(local_args_info.testequi_given), optarg, 0, 0, ARG_NO,
1397 check_ambiguity, override, 0, 0,
1398 "testequi", 't',
1399 additional_error))
1400 goto failure;
1401
1402 break;
1403
1404 case 0: /* Long option with no short option */
1405 /* select first stuntdouble set. */
1406 if (strcmp (long_options[option_index].name, "sele1") == 0)
1407 {
1408
1409
1410 if (update_arg( (void *)&(args_info->sele1_arg),
1411 &(args_info->sele1_orig), &(args_info->sele1_given),
1412 &(local_args_info.sele1_given), optarg, 0, 0, ARG_STRING,
1413 check_ambiguity, override, 0, 0,
1414 "sele1", '-',
1415 additional_error))
1416 goto failure;
1417
1418 }
1419 /* select second stuntdouble set (if sele2 is not set, use script from sele1). */
1420 else if (strcmp (long_options[option_index].name, "sele2") == 0)
1421 {
1422
1423
1424 if (update_arg( (void *)&(args_info->sele2_arg),
1425 &(args_info->sele2_orig), &(args_info->sele2_given),
1426 &(local_args_info.sele2_given), optarg, 0, 0, ARG_STRING,
1427 check_ambiguity, override, 0, 0,
1428 "sele2", '-',
1429 additional_error))
1430 goto failure;
1431
1432 }
1433 /* number of bins in z axis. */
1434 else if (strcmp (long_options[option_index].name, "nbins_z") == 0)
1435 {
1436
1437
1438 if (update_arg( (void *)&(args_info->nbins_z_arg),
1439 &(args_info->nbins_z_orig), &(args_info->nbins_z_given),
1440 &(local_args_info.nbins_z_given), optarg, 0, "100", ARG_INT,
1441 check_ambiguity, override, 0, 0,
1442 "nbins_z", '-',
1443 additional_error))
1444 goto failure;
1445
1446 }
1447 /* Threshold Density in g/cm^3. */
1448 else if (strcmp (long_options[option_index].name, "threshDens") == 0)
1449 {
1450
1451
1452 if (update_arg( (void *)&(args_info->threshDens_arg),
1453 &(args_info->threshDens_orig), &(args_info->threshDens_given),
1454 &(local_args_info.threshDens_given), optarg, 0, 0, ARG_DOUBLE,
1455 check_ambiguity, override, 0, 0,
1456 "threshDens", '-',
1457 additional_error))
1458 goto failure;
1459
1460 }
1461 /* Buffer length in angstroms. */
1462 else if (strcmp (long_options[option_index].name, "bufferLength") == 0)
1463 {
1464
1465
1466 if (update_arg( (void *)&(args_info->bufferLength_arg),
1467 &(args_info->bufferLength_orig), &(args_info->bufferLength_given),
1468 &(local_args_info.bufferLength_given), optarg, 0, 0, ARG_DOUBLE,
1469 check_ambiguity, override, 0, 0,
1470 "bufferLength", '-',
1471 additional_error))
1472 goto failure;
1473
1474 }
1475 /* cutoff radius (rcut). */
1476 else if (strcmp (long_options[option_index].name, "rcut") == 0)
1477 {
1478
1479
1480 if (update_arg( (void *)&(args_info->rcut_arg),
1481 &(args_info->rcut_orig), &(args_info->rcut_given),
1482 &(local_args_info.rcut_given), optarg, 0, 0, ARG_DOUBLE,
1483 check_ambiguity, override, 0, 0,
1484 "rcut", '-',
1485 additional_error))
1486 goto failure;
1487
1488 }
1489 /* contact angle of selection (using center of mass). */
1490 else if (strcmp (long_options[option_index].name, "ca1") == 0)
1491 {
1492
1493 if (args_info->sequentialProps_group_counter && override)
1494 reset_group_sequentialProps (args_info);
1495 args_info->sequentialProps_group_counter += 1;
1496
1497 if (update_arg( 0 ,
1498 0 , &(args_info->ca1_given),
1499 &(local_args_info.ca1_given), optarg, 0, 0, ARG_NO,
1500 check_ambiguity, override, 0, 0,
1501 "ca1", '-',
1502 additional_error))
1503 goto failure;
1504
1505 }
1506 /* contact angle of selection (using density profile). */
1507 else if (strcmp (long_options[option_index].name, "ca2") == 0)
1508 {
1509
1510 if (args_info->sequentialProps_group_counter && override)
1511 reset_group_sequentialProps (args_info);
1512 args_info->sequentialProps_group_counter += 1;
1513
1514 if (update_arg( 0 ,
1515 0 , &(args_info->ca2_given),
1516 &(local_args_info.ca2_given), optarg, 0, 0, ARG_NO,
1517 check_ambiguity, override, 0, 0,
1518 "ca2", '-',
1519 additional_error))
1520 goto failure;
1521
1522 }
1523 /* Generalized Coordinate Number. */
1524 else if (strcmp (long_options[option_index].name, "gcn") == 0)
1525 {
1526
1527 if (args_info->sequentialProps_group_counter && override)
1528 reset_group_sequentialProps (args_info);
1529 args_info->sequentialProps_group_counter += 1;
1530
1531 if (update_arg( 0 ,
1532 0 , &(args_info->gcn_given),
1533 &(local_args_info.gcn_given), optarg, 0, 0, ARG_NO,
1534 check_ambiguity, override, 0, 0,
1535 "gcn", '-',
1536 additional_error))
1537 goto failure;
1538
1539 }
1540
1541 break;
1542 case '?': /* Invalid option. */
1543 /* `getopt_long' already printed an error message. */
1544 goto failure;
1545
1546 default: /* bug: option not considered. */
1547 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1548 abort ();
1549 } /* switch */
1550 } /* while */
1551
1552 if (args_info->sequentialProps_group_counter > 1)
1553 {
1554 fprintf (stderr, "%s: %d options of group sequentialProps were given. One is required%s.\n", argv[0], args_info->sequentialProps_group_counter, (additional_error ? additional_error : ""));
1555 error_occurred = 1;
1556 }
1557
1558
1559
1560 if (check_required)
1561 {
1562 error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error);
1563 }
1564
1565 cmdline_parser_release (&local_args_info);
1566
1567 if ( error_occurred )
1568 return (EXIT_FAILURE);
1569
1570 if (optind < argc)
1571 {
1572 int i = 0 ;
1573 int found_prog_name = 0;
1574 /* whether program name, i.e., argv[0], is in the remaining args
1575 (this may happen with some implementations of getopt,
1576 but surely not with the one included by gengetopt) */
1577
1578
1579 args_info->inputs_num = argc - optind - found_prog_name;
1580 args_info->inputs =
1581 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
1582 while (optind < argc)
1583 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1584 }
1585
1586 return 0;
1587
1588failure:
1589
1590 cmdline_parser_release (&local_args_info);
1591 return (EXIT_FAILURE);
1592}
#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 header file for the command line option parser generated by GNU Gengetopt version 2....
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 comvel_given
Whether comvel was given.
char * sele2_arg
select second stuntdouble set (if sele2 is not set, use script from sele1).
char * nbins_orig
Number of bins original value given at command line.
const char * comvel_help
selection center of mass velocity help description.
unsigned int output_given
Whether output was given.
double centroidX_arg
Location of droplet centroid in x.
unsigned int referenceZ_given
Whether referenceZ was given.
const char * rcut_help
cutoff radius (angstroms) help description.
unsigned int dropletR_given
Whether dropletR was given.
unsigned int threshDens_given
Whether threshDens was given.
char * output_orig
output file name original value given at command line.
const char * output_help
output file name help description.
const char * nbins_help
Number of bins help description.
const char * ca1_help
contact angle of selection (using center of mass) help description.
double bufferLength_arg
Buffer length in angstroms.
char * referenceZ_orig
Reference z-height of solid surface original value given at command line.
const char * sele1_help
select first stuntdouble set help description.
char * bufferLength_orig
Buffer length in angstroms original value given at command line.
double referenceZ_arg
Reference z-height of solid surface.
const char * sele2_help
select second stuntdouble set (if sele2 is not set, use script from sele1) help description.
unsigned inputs_num
unamed options number
const char * gcn_help
Generalized Coordinate Number help description.
unsigned int ca2_given
Whether ca2 was given.
const char * ca2_help
contact angle of selection (using density profile) help description.
const char * referenceZ_help
Reference z-height of solid surface help description.
const char * help_help
Print help and exit help description.
char * threshDens_orig
Threshold Density in g/cm^3 original value given at command line.
char * output_arg
output file name.
unsigned int centroidY_given
Whether centroidY was given.
const char * centroidX_help
Location of droplet centroid in x help description.
const char * threshDens_help
Threshold Density in g/cm^3 help description.
char ** inputs
unamed options (options without names)
const char * centroidY_help
Location of droplet centroid in y help description.
const char * com_help
selection center of mass help description.
unsigned int testequi_given
Whether testequi was given.
char * input_arg
input dump file.
char * nbins_z_orig
number of bins in z axis original value given at command line.
int nbins_z_arg
number of bins in z axis (default='100').
unsigned int sele1_given
Whether sele1 was given.
unsigned int gcn_given
Whether gcn was given.
char * dropletR_orig
Droplet radius in angstroms original value given at command line.
unsigned int com_given
Whether com was given.
double rcut_arg
cutoff radius (angstroms).
int sequentialProps_group_counter
Counter for group sequentialProps.
char * sele2_orig
select second stuntdouble set (if sele2 is not set, use script from sele1) original value given at co...
char * sele1_orig
select first stuntdouble set original value given at command line.
unsigned int ca1_given
Whether ca1 was given.
char * centroidX_orig
Location of droplet centroid in x original value given at command line.
char * sele1_arg
select first stuntdouble set.
double centroidY_arg
Location of droplet centroid in y.
const char * bufferLength_help
Buffer length in angstroms help description.
unsigned int rcut_given
Whether rcut was given.
unsigned int bufferLength_given
Whether bufferLength was given.
unsigned int help_given
Whether help was given.
const char * dropletR_help
Droplet radius in angstroms help description.
double threshDens_arg
Threshold Density in g/cm^3.
unsigned int input_given
Whether input was given.
int nbins_arg
Number of bins (default='100').
const char * testequi_help
Temperature using all componets of linear and angular momentum help description.
unsigned int centroidX_given
Whether centroidX was given.
unsigned int version_given
Whether version was given.
unsigned int sele2_given
Whether sele2 was given.
const char * version_help
Print version and exit help description.
char * centroidY_orig
Location of droplet centroid in y original value given at command line.
char * input_orig
input dump file original value given at command line.
unsigned int nbins_given
Whether nbins was given.
const char * nbins_z_help
number of bins in z axis help description.
double dropletR_arg
Droplet radius in angstroms.
unsigned int nbins_z_given
Whether nbins_z was given.
char * rcut_orig
cutoff radius (angstroms) original value given at command line.
const char * input_help
input dump file help description.
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.