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