ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/dump2Xyz/Dump2XYZCmd.cpp
Revision: 1655
Committed: Mon Oct 3 20:32:45 2011 UTC (13 years, 7 months ago) by gezelter
File size: 29617 byte(s)
Log Message:
Replacing most of the C-code with C++ code, and migrating the config.h
file into the PROJECT_BINARY_DIR so that we can have multiple builds
on the same architecture.

File Contents

# Content
1 /*
2 File autogenerated by gengetopt version 2.22.4
3 generated with the following command:
4 gengetopt -F Dump2XYZCmd -u
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 #include <getopt.h>
25
26 #include "Dump2XYZCmd.h"
27
28 const char *gengetopt_args_info_purpose = "";
29
30 const char *gengetopt_args_info_usage = "Usage: Dump2XYZ [OPTIONS]... [FILES]...";
31
32 const char *gengetopt_args_info_description = "";
33
34 const char *gengetopt_args_info_help[] = {
35 " -h, --help Print help and exit",
36 " -V, --version Print version and exit",
37 " -i, --input=filename input dump file",
38 " -o, --output=filename output file name",
39 " -n, --frame=INT print every n frame (default=`1')",
40 " -w, --water skip the the waters (default=off)",
41 " -m, --periodicBox map to the periodic box (default=off)",
42 " -z, --zconstraint replace the atom types of zconstraint molecules \n (default=off)",
43 " -r, --rigidbody add a pseudo COM atom to rigidbody \n (default=off)",
44 " -t, --watertype replace the atom type of water model \n (default=on)",
45 " -s, --selection=selection script\n general selection syntax",
46 " --originsele=selection script\n select origin",
47 " --refsele=selection script\n select reference",
48 " --repeatX=INT The number of images to repeat in the x \n direction (default=`0')",
49 " --repeatY=INT The number of images to repeat in the y \n direction (default=`0')",
50 " --repeatZ=INT The number of images to repeat in the z \n direction (default=`0')",
51 " -b, --basetype Convert to base atom type (default=off)",
52 " -v, --velocities Print velocities in xyz file (default=off)",
53 " -f, --forces Print forces xyz file (default=off)",
54 " -u, --vectors Print vectors (dipoles, etc) in xyz file \n (default=off)",
55 " -c, --charges Print charges in xyz file (default=off)",
56 0
57 };
58
59 typedef enum {ARG_NO
60 , ARG_FLAG
61 , ARG_STRING
62 , ARG_INT
63 } cmdline_parser_arg_type;
64
65 static
66 void clear_given (struct gengetopt_args_info *args_info);
67 static
68 void clear_args (struct gengetopt_args_info *args_info);
69
70 static int
71 cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
72 struct cmdline_parser_params *params, const char *additional_error);
73
74 static int
75 cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
76
77 static char *
78 gengetopt_strdup (const char *s);
79
80 static
81 void clear_given (struct gengetopt_args_info *args_info)
82 {
83 args_info->help_given = 0 ;
84 args_info->version_given = 0 ;
85 args_info->input_given = 0 ;
86 args_info->output_given = 0 ;
87 args_info->frame_given = 0 ;
88 args_info->water_given = 0 ;
89 args_info->periodicBox_given = 0 ;
90 args_info->zconstraint_given = 0 ;
91 args_info->rigidbody_given = 0 ;
92 args_info->watertype_given = 0 ;
93 args_info->selection_given = 0 ;
94 args_info->originsele_given = 0 ;
95 args_info->refsele_given = 0 ;
96 args_info->repeatX_given = 0 ;
97 args_info->repeatY_given = 0 ;
98 args_info->repeatZ_given = 0 ;
99 args_info->basetype_given = 0 ;
100 args_info->velocities_given = 0 ;
101 args_info->forces_given = 0 ;
102 args_info->vectors_given = 0 ;
103 args_info->charges_given = 0 ;
104 }
105
106 static
107 void clear_args (struct gengetopt_args_info *args_info)
108 {
109 FIX_UNUSED (args_info);
110 args_info->input_arg = NULL;
111 args_info->input_orig = NULL;
112 args_info->output_arg = NULL;
113 args_info->output_orig = NULL;
114 args_info->frame_arg = 1;
115 args_info->frame_orig = NULL;
116 args_info->water_flag = 0;
117 args_info->periodicBox_flag = 0;
118 args_info->zconstraint_flag = 0;
119 args_info->rigidbody_flag = 0;
120 args_info->watertype_flag = 1;
121 args_info->selection_arg = NULL;
122 args_info->selection_orig = NULL;
123 args_info->originsele_arg = NULL;
124 args_info->originsele_orig = NULL;
125 args_info->refsele_arg = NULL;
126 args_info->refsele_orig = NULL;
127 args_info->repeatX_arg = 0;
128 args_info->repeatX_orig = NULL;
129 args_info->repeatY_arg = 0;
130 args_info->repeatY_orig = NULL;
131 args_info->repeatZ_arg = 0;
132 args_info->repeatZ_orig = NULL;
133 args_info->basetype_flag = 0;
134 args_info->velocities_flag = 0;
135 args_info->forces_flag = 0;
136 args_info->vectors_flag = 0;
137 args_info->charges_flag = 0;
138
139 }
140
141 static
142 void init_args_info(struct gengetopt_args_info *args_info)
143 {
144
145
146 args_info->help_help = gengetopt_args_info_help[0] ;
147 args_info->version_help = gengetopt_args_info_help[1] ;
148 args_info->input_help = gengetopt_args_info_help[2] ;
149 args_info->output_help = gengetopt_args_info_help[3] ;
150 args_info->frame_help = gengetopt_args_info_help[4] ;
151 args_info->water_help = gengetopt_args_info_help[5] ;
152 args_info->periodicBox_help = gengetopt_args_info_help[6] ;
153 args_info->zconstraint_help = gengetopt_args_info_help[7] ;
154 args_info->rigidbody_help = gengetopt_args_info_help[8] ;
155 args_info->watertype_help = gengetopt_args_info_help[9] ;
156 args_info->selection_help = gengetopt_args_info_help[10] ;
157 args_info->originsele_help = gengetopt_args_info_help[11] ;
158 args_info->refsele_help = gengetopt_args_info_help[12] ;
159 args_info->repeatX_help = gengetopt_args_info_help[13] ;
160 args_info->repeatY_help = gengetopt_args_info_help[14] ;
161 args_info->repeatZ_help = gengetopt_args_info_help[15] ;
162 args_info->basetype_help = gengetopt_args_info_help[16] ;
163 args_info->velocities_help = gengetopt_args_info_help[17] ;
164 args_info->forces_help = gengetopt_args_info_help[18] ;
165 args_info->vectors_help = gengetopt_args_info_help[19] ;
166 args_info->charges_help = gengetopt_args_info_help[20] ;
167
168 }
169
170 void
171 cmdline_parser_print_version (void)
172 {
173 printf ("%s %s\n",
174 (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
175 CMDLINE_PARSER_VERSION);
176 }
177
178 static void print_help_common(void) {
179 cmdline_parser_print_version ();
180
181 if (strlen(gengetopt_args_info_purpose) > 0)
182 printf("\n%s\n", gengetopt_args_info_purpose);
183
184 if (strlen(gengetopt_args_info_usage) > 0)
185 printf("\n%s\n", gengetopt_args_info_usage);
186
187 printf("\n");
188
189 if (strlen(gengetopt_args_info_description) > 0)
190 printf("%s\n\n", gengetopt_args_info_description);
191 }
192
193 void
194 cmdline_parser_print_help (void)
195 {
196 int i = 0;
197 print_help_common();
198 while (gengetopt_args_info_help[i])
199 printf("%s\n", gengetopt_args_info_help[i++]);
200 }
201
202 void
203 cmdline_parser_init (struct gengetopt_args_info *args_info)
204 {
205 clear_given (args_info);
206 clear_args (args_info);
207 init_args_info (args_info);
208
209 args_info->inputs = 0;
210 args_info->inputs_num = 0;
211 }
212
213 void
214 cmdline_parser_params_init(struct cmdline_parser_params *params)
215 {
216 if (params)
217 {
218 params->override = 0;
219 params->initialize = 1;
220 params->check_required = 1;
221 params->check_ambiguity = 0;
222 params->print_errors = 1;
223 }
224 }
225
226 struct cmdline_parser_params *
227 cmdline_parser_params_create(void)
228 {
229 struct cmdline_parser_params *params =
230 (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
231 cmdline_parser_params_init(params);
232 return params;
233 }
234
235 static void
236 free_string_field (char **s)
237 {
238 if (*s)
239 {
240 free (*s);
241 *s = 0;
242 }
243 }
244
245
246 static void
247 cmdline_parser_release (struct gengetopt_args_info *args_info)
248 {
249 unsigned int i;
250 free_string_field (&(args_info->input_arg));
251 free_string_field (&(args_info->input_orig));
252 free_string_field (&(args_info->output_arg));
253 free_string_field (&(args_info->output_orig));
254 free_string_field (&(args_info->frame_orig));
255 free_string_field (&(args_info->selection_arg));
256 free_string_field (&(args_info->selection_orig));
257 free_string_field (&(args_info->originsele_arg));
258 free_string_field (&(args_info->originsele_orig));
259 free_string_field (&(args_info->refsele_arg));
260 free_string_field (&(args_info->refsele_orig));
261 free_string_field (&(args_info->repeatX_orig));
262 free_string_field (&(args_info->repeatY_orig));
263 free_string_field (&(args_info->repeatZ_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
276 static void
277 write_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
288 int
289 cmdline_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->frame_given)
308 write_into_file(outfile, "frame", args_info->frame_orig, 0);
309 if (args_info->water_given)
310 write_into_file(outfile, "water", 0, 0 );
311 if (args_info->periodicBox_given)
312 write_into_file(outfile, "periodicBox", 0, 0 );
313 if (args_info->zconstraint_given)
314 write_into_file(outfile, "zconstraint", 0, 0 );
315 if (args_info->rigidbody_given)
316 write_into_file(outfile, "rigidbody", 0, 0 );
317 if (args_info->watertype_given)
318 write_into_file(outfile, "watertype", 0, 0 );
319 if (args_info->selection_given)
320 write_into_file(outfile, "selection", args_info->selection_orig, 0);
321 if (args_info->originsele_given)
322 write_into_file(outfile, "originsele", args_info->originsele_orig, 0);
323 if (args_info->refsele_given)
324 write_into_file(outfile, "refsele", args_info->refsele_orig, 0);
325 if (args_info->repeatX_given)
326 write_into_file(outfile, "repeatX", args_info->repeatX_orig, 0);
327 if (args_info->repeatY_given)
328 write_into_file(outfile, "repeatY", args_info->repeatY_orig, 0);
329 if (args_info->repeatZ_given)
330 write_into_file(outfile, "repeatZ", args_info->repeatZ_orig, 0);
331 if (args_info->basetype_given)
332 write_into_file(outfile, "basetype", 0, 0 );
333 if (args_info->velocities_given)
334 write_into_file(outfile, "velocities", 0, 0 );
335 if (args_info->forces_given)
336 write_into_file(outfile, "forces", 0, 0 );
337 if (args_info->vectors_given)
338 write_into_file(outfile, "vectors", 0, 0 );
339 if (args_info->charges_given)
340 write_into_file(outfile, "charges", 0, 0 );
341
342
343 i = EXIT_SUCCESS;
344 return i;
345 }
346
347 int
348 cmdline_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
367 void
368 cmdline_parser_free (struct gengetopt_args_info *args_info)
369 {
370 cmdline_parser_release (args_info);
371 }
372
373 /** @brief replacement of strdup, which is not standard */
374 char *
375 gengetopt_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
388 int
389 cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
390 {
391 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
392 }
393
394 int
395 cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
396 struct cmdline_parser_params *params)
397 {
398 int result;
399 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
400
401 if (result == EXIT_FAILURE)
402 {
403 cmdline_parser_free (args_info);
404 exit (EXIT_FAILURE);
405 }
406
407 return result;
408 }
409
410 int
411 cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
412 {
413 int result;
414 struct cmdline_parser_params params;
415
416 params.override = override;
417 params.initialize = initialize;
418 params.check_required = check_required;
419 params.check_ambiguity = 0;
420 params.print_errors = 1;
421
422 result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
423
424 if (result == EXIT_FAILURE)
425 {
426 cmdline_parser_free (args_info);
427 exit (EXIT_FAILURE);
428 }
429
430 return result;
431 }
432
433 int
434 cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
435 {
436 int result = EXIT_SUCCESS;
437
438 if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
439 result = EXIT_FAILURE;
440
441 if (result == EXIT_FAILURE)
442 {
443 cmdline_parser_free (args_info);
444 exit (EXIT_FAILURE);
445 }
446
447 return result;
448 }
449
450 int
451 cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
452 {
453 int error = 0;
454 FIX_UNUSED (additional_error);
455
456 /* checks for required options */
457 if (! args_info->input_given)
458 {
459 fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
460 error = 1;
461 }
462
463
464 /* checks for dependences among options */
465
466 return error;
467 }
468
469
470 static char *package_name = 0;
471
472 /**
473 * @brief updates an option
474 * @param field the generic pointer to the field to update
475 * @param orig_field the pointer to the orig field
476 * @param field_given the pointer to the number of occurrence of this option
477 * @param prev_given the pointer to the number of occurrence already seen
478 * @param value the argument for this option (if null no arg was specified)
479 * @param possible_values the possible values for this option (if specified)
480 * @param default_value the default value (in case the option only accepts fixed values)
481 * @param arg_type the type of this option
482 * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
483 * @param override @see cmdline_parser_params.override
484 * @param no_free whether to free a possible previous value
485 * @param multiple_option whether this is a multiple option
486 * @param long_opt the corresponding long option
487 * @param short_opt the corresponding short option (or '-' if none)
488 * @param additional_error possible further error specification
489 */
490 static
491 int update_arg(void *field, char **orig_field,
492 unsigned int *field_given, unsigned int *prev_given,
493 char *value, const char *possible_values[],
494 const char *default_value,
495 cmdline_parser_arg_type arg_type,
496 int check_ambiguity, int override,
497 int no_free, int multiple_option,
498 const char *long_opt, char short_opt,
499 const char *additional_error)
500 {
501 char *stop_char = 0;
502 const char *val = value;
503 int found;
504 char **string_field;
505 FIX_UNUSED (field);
506
507 stop_char = 0;
508 found = 0;
509
510 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
511 {
512 if (short_opt != '-')
513 fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
514 package_name, long_opt, short_opt,
515 (additional_error ? additional_error : ""));
516 else
517 fprintf (stderr, "%s: `--%s' option given more than once%s\n",
518 package_name, long_opt,
519 (additional_error ? additional_error : ""));
520 return 1; /* failure */
521 }
522
523 FIX_UNUSED (default_value);
524
525 if (field_given && *field_given && ! override)
526 return 0;
527 if (prev_given)
528 (*prev_given)++;
529 if (field_given)
530 (*field_given)++;
531 if (possible_values)
532 val = possible_values[found];
533
534 switch(arg_type) {
535 case ARG_FLAG:
536 *((int *)field) = !*((int *)field);
537 break;
538 case ARG_INT:
539 if (val) *((int *)field) = strtol (val, &stop_char, 0);
540 break;
541 case ARG_STRING:
542 if (val) {
543 string_field = (char **)field;
544 if (!no_free && *string_field)
545 free (*string_field); /* free previous string */
546 *string_field = gengetopt_strdup (val);
547 }
548 break;
549 default:
550 break;
551 };
552
553 /* check numeric conversion */
554 switch(arg_type) {
555 case ARG_INT:
556 if (val && !(stop_char && *stop_char == '\0')) {
557 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
558 return 1; /* failure */
559 }
560 break;
561 default:
562 ;
563 };
564
565 /* store the original value */
566 switch(arg_type) {
567 case ARG_NO:
568 case ARG_FLAG:
569 break;
570 default:
571 if (value && orig_field) {
572 if (no_free) {
573 *orig_field = value;
574 } else {
575 if (*orig_field)
576 free (*orig_field); /* free previous string */
577 *orig_field = gengetopt_strdup (value);
578 }
579 }
580 };
581
582 return 0; /* OK */
583 }
584
585
586 int
587 cmdline_parser_internal (
588 int argc, char **argv, struct gengetopt_args_info *args_info,
589 struct cmdline_parser_params *params, const char *additional_error)
590 {
591 int c; /* Character of the parsed option. */
592
593 int error = 0;
594 struct gengetopt_args_info local_args_info;
595
596 int override;
597 int initialize;
598 int check_required;
599 int check_ambiguity;
600
601 package_name = argv[0];
602
603 override = params->override;
604 initialize = params->initialize;
605 check_required = params->check_required;
606 check_ambiguity = params->check_ambiguity;
607
608 if (initialize)
609 cmdline_parser_init (args_info);
610
611 cmdline_parser_init (&local_args_info);
612
613 optarg = 0;
614 optind = 0;
615 opterr = params->print_errors;
616 optopt = '?';
617
618 while (1)
619 {
620 int option_index = 0;
621
622 static struct option long_options[] = {
623 { "help", 0, NULL, 'h' },
624 { "version", 0, NULL, 'V' },
625 { "input", 1, NULL, 'i' },
626 { "output", 1, NULL, 'o' },
627 { "frame", 1, NULL, 'n' },
628 { "water", 0, NULL, 'w' },
629 { "periodicBox", 0, NULL, 'm' },
630 { "zconstraint", 0, NULL, 'z' },
631 { "rigidbody", 0, NULL, 'r' },
632 { "watertype", 0, NULL, 't' },
633 { "selection", 1, NULL, 's' },
634 { "originsele", 1, NULL, 0 },
635 { "refsele", 1, NULL, 0 },
636 { "repeatX", 1, NULL, 0 },
637 { "repeatY", 1, NULL, 0 },
638 { "repeatZ", 1, NULL, 0 },
639 { "basetype", 0, NULL, 'b' },
640 { "velocities", 0, NULL, 'v' },
641 { "forces", 0, NULL, 'f' },
642 { "vectors", 0, NULL, 'u' },
643 { "charges", 0, NULL, 'c' },
644 { 0, 0, 0, 0 }
645 };
646
647 c = getopt_long (argc, argv, "hVi:o:n:wmzrts:bvfuc", long_options, &option_index);
648
649 if (c == -1) break; /* Exit from `while (1)' loop. */
650
651 switch (c)
652 {
653 case 'h': /* Print help and exit. */
654 cmdline_parser_print_help ();
655 cmdline_parser_free (&local_args_info);
656 exit (EXIT_SUCCESS);
657
658 case 'V': /* Print version and exit. */
659 cmdline_parser_print_version ();
660 cmdline_parser_free (&local_args_info);
661 exit (EXIT_SUCCESS);
662
663 case 'i': /* input dump file. */
664
665
666 if (update_arg( (void *)&(args_info->input_arg),
667 &(args_info->input_orig), &(args_info->input_given),
668 &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
669 check_ambiguity, override, 0, 0,
670 "input", 'i',
671 additional_error))
672 goto failure;
673
674 break;
675 case 'o': /* output file name. */
676
677
678 if (update_arg( (void *)&(args_info->output_arg),
679 &(args_info->output_orig), &(args_info->output_given),
680 &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
681 check_ambiguity, override, 0, 0,
682 "output", 'o',
683 additional_error))
684 goto failure;
685
686 break;
687 case 'n': /* print every n frame. */
688
689
690 if (update_arg( (void *)&(args_info->frame_arg),
691 &(args_info->frame_orig), &(args_info->frame_given),
692 &(local_args_info.frame_given), optarg, 0, "1", ARG_INT,
693 check_ambiguity, override, 0, 0,
694 "frame", 'n',
695 additional_error))
696 goto failure;
697
698 break;
699 case 'w': /* skip the the waters. */
700
701
702 if (update_arg((void *)&(args_info->water_flag), 0, &(args_info->water_given),
703 &(local_args_info.water_given), optarg, 0, 0, ARG_FLAG,
704 check_ambiguity, override, 1, 0, "water", 'w',
705 additional_error))
706 goto failure;
707
708 break;
709 case 'm': /* map to the periodic box. */
710
711
712 if (update_arg((void *)&(args_info->periodicBox_flag), 0, &(args_info->periodicBox_given),
713 &(local_args_info.periodicBox_given), optarg, 0, 0, ARG_FLAG,
714 check_ambiguity, override, 1, 0, "periodicBox", 'm',
715 additional_error))
716 goto failure;
717
718 break;
719 case 'z': /* replace the atom types of zconstraint molecules. */
720
721
722 if (update_arg((void *)&(args_info->zconstraint_flag), 0, &(args_info->zconstraint_given),
723 &(local_args_info.zconstraint_given), optarg, 0, 0, ARG_FLAG,
724 check_ambiguity, override, 1, 0, "zconstraint", 'z',
725 additional_error))
726 goto failure;
727
728 break;
729 case 'r': /* add a pseudo COM atom to rigidbody. */
730
731
732 if (update_arg((void *)&(args_info->rigidbody_flag), 0, &(args_info->rigidbody_given),
733 &(local_args_info.rigidbody_given), optarg, 0, 0, ARG_FLAG,
734 check_ambiguity, override, 1, 0, "rigidbody", 'r',
735 additional_error))
736 goto failure;
737
738 break;
739 case 't': /* replace the atom type of water model. */
740
741
742 if (update_arg((void *)&(args_info->watertype_flag), 0, &(args_info->watertype_given),
743 &(local_args_info.watertype_given), optarg, 0, 0, ARG_FLAG,
744 check_ambiguity, override, 1, 0, "watertype", 't',
745 additional_error))
746 goto failure;
747
748 break;
749 case 's': /* general selection syntax. */
750
751
752 if (update_arg( (void *)&(args_info->selection_arg),
753 &(args_info->selection_orig), &(args_info->selection_given),
754 &(local_args_info.selection_given), optarg, 0, 0, ARG_STRING,
755 check_ambiguity, override, 0, 0,
756 "selection", 's',
757 additional_error))
758 goto failure;
759
760 break;
761 case 'b': /* Convert to base atom type. */
762
763
764 if (update_arg((void *)&(args_info->basetype_flag), 0, &(args_info->basetype_given),
765 &(local_args_info.basetype_given), optarg, 0, 0, ARG_FLAG,
766 check_ambiguity, override, 1, 0, "basetype", 'b',
767 additional_error))
768 goto failure;
769
770 break;
771 case 'v': /* Print velocities in xyz file. */
772
773
774 if (update_arg((void *)&(args_info->velocities_flag), 0, &(args_info->velocities_given),
775 &(local_args_info.velocities_given), optarg, 0, 0, ARG_FLAG,
776 check_ambiguity, override, 1, 0, "velocities", 'v',
777 additional_error))
778 goto failure;
779
780 break;
781 case 'f': /* Print forces xyz file. */
782
783
784 if (update_arg((void *)&(args_info->forces_flag), 0, &(args_info->forces_given),
785 &(local_args_info.forces_given), optarg, 0, 0, ARG_FLAG,
786 check_ambiguity, override, 1, 0, "forces", 'f',
787 additional_error))
788 goto failure;
789
790 break;
791 case 'u': /* Print vectors (dipoles, etc) in xyz file. */
792
793
794 if (update_arg((void *)&(args_info->vectors_flag), 0, &(args_info->vectors_given),
795 &(local_args_info.vectors_given), optarg, 0, 0, ARG_FLAG,
796 check_ambiguity, override, 1, 0, "vectors", 'u',
797 additional_error))
798 goto failure;
799
800 break;
801 case 'c': /* Print charges in xyz file. */
802
803
804 if (update_arg((void *)&(args_info->charges_flag), 0, &(args_info->charges_given),
805 &(local_args_info.charges_given), optarg, 0, 0, ARG_FLAG,
806 check_ambiguity, override, 1, 0, "charges", 'c',
807 additional_error))
808 goto failure;
809
810 break;
811
812 case 0: /* Long option with no short option */
813 /* select origin. */
814 if (strcmp (long_options[option_index].name, "originsele") == 0)
815 {
816
817
818 if (update_arg( (void *)&(args_info->originsele_arg),
819 &(args_info->originsele_orig), &(args_info->originsele_given),
820 &(local_args_info.originsele_given), optarg, 0, 0, ARG_STRING,
821 check_ambiguity, override, 0, 0,
822 "originsele", '-',
823 additional_error))
824 goto failure;
825
826 }
827 /* select reference. */
828 else if (strcmp (long_options[option_index].name, "refsele") == 0)
829 {
830
831
832 if (update_arg( (void *)&(args_info->refsele_arg),
833 &(args_info->refsele_orig), &(args_info->refsele_given),
834 &(local_args_info.refsele_given), optarg, 0, 0, ARG_STRING,
835 check_ambiguity, override, 0, 0,
836 "refsele", '-',
837 additional_error))
838 goto failure;
839
840 }
841 /* The number of images to repeat in the x direction. */
842 else if (strcmp (long_options[option_index].name, "repeatX") == 0)
843 {
844
845
846 if (update_arg( (void *)&(args_info->repeatX_arg),
847 &(args_info->repeatX_orig), &(args_info->repeatX_given),
848 &(local_args_info.repeatX_given), optarg, 0, "0", ARG_INT,
849 check_ambiguity, override, 0, 0,
850 "repeatX", '-',
851 additional_error))
852 goto failure;
853
854 }
855 /* The number of images to repeat in the y direction. */
856 else if (strcmp (long_options[option_index].name, "repeatY") == 0)
857 {
858
859
860 if (update_arg( (void *)&(args_info->repeatY_arg),
861 &(args_info->repeatY_orig), &(args_info->repeatY_given),
862 &(local_args_info.repeatY_given), optarg, 0, "0", ARG_INT,
863 check_ambiguity, override, 0, 0,
864 "repeatY", '-',
865 additional_error))
866 goto failure;
867
868 }
869 /* The number of images to repeat in the z direction. */
870 else if (strcmp (long_options[option_index].name, "repeatZ") == 0)
871 {
872
873
874 if (update_arg( (void *)&(args_info->repeatZ_arg),
875 &(args_info->repeatZ_orig), &(args_info->repeatZ_given),
876 &(local_args_info.repeatZ_given), optarg, 0, "0", ARG_INT,
877 check_ambiguity, override, 0, 0,
878 "repeatZ", '-',
879 additional_error))
880 goto failure;
881
882 }
883
884 break;
885 case '?': /* Invalid option. */
886 /* `getopt_long' already printed an error message. */
887 goto failure;
888
889 default: /* bug: option not considered. */
890 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
891 abort ();
892 } /* switch */
893 } /* while */
894
895
896
897 if (check_required)
898 {
899 error += cmdline_parser_required2 (args_info, argv[0], additional_error);
900 }
901
902 cmdline_parser_release (&local_args_info);
903
904 if ( error )
905 return (EXIT_FAILURE);
906
907 if (optind < argc)
908 {
909 int i = 0 ;
910 int found_prog_name = 0;
911 /* whether program name, i.e., argv[0], is in the remaining args
912 (this may happen with some implementations of getopt,
913 but surely not with the one included by gengetopt) */
914
915 i = optind;
916 while (i < argc)
917 if (argv[i++] == argv[0]) {
918 found_prog_name = 1;
919 break;
920 }
921 i = 0;
922
923 args_info->inputs_num = argc - optind - found_prog_name;
924 args_info->inputs =
925 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
926 while (optind < argc)
927 if (argv[optind++] != argv[0])
928 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
929 }
930
931 return 0;
932
933 failure:
934
935 cmdline_parser_release (&local_args_info);
936 return (EXIT_FAILURE);
937 }

Properties

Name Value
svn:keywords Author Id Revision Date