ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/dump2Xyz/Dump2XYZCmd.cpp
Revision: 1871
Committed: Fri May 10 14:59:13 2013 UTC (11 years, 11 months ago) by gezelter
File size: 30449 byte(s)
Log Message:
Bugs in the FQ samples, fixed for Dump2XYZ to print out charges and electric fields

File Contents

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

Properties

Name Value
svn:keywords Author Id Revision Date