ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/dump2Xyz/Dump2XYZCmd.cpp
Revision: 1465
Committed: Fri Jul 9 23:08:25 2010 UTC (15 years ago) by chuckv
Content type: text/plain
Original Path: branches/development/src/applications/dump2Xyz/Dump2XYZCmd.c
File size: 29325 byte(s)
Log Message:
Creating busticated version of OpenMD

File Contents

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

Properties

Name Value
svn:keywords Author Id Revision Date