ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/hydrodynamics/HydroCmd.cpp
Revision: 1851
Committed: Wed Feb 20 15:46:34 2013 UTC (12 years, 2 months ago) by gezelter
File size: 18835 byte(s)
Log Message:
Space typos

File Contents

# User Rev Content
1 tim 891 /*
2 gezelter 1630 File autogenerated by gengetopt version 2.22.4
3 tim 891 generated with the following command:
4 gezelter 1832 gengetopt --file-name=HydroCmd --unamed-opts
5 tim 891
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 gezelter 938 /* If we use autoconf. */
12     #ifdef HAVE_CONFIG_H
13     #include "config.h"
14     #endif
15 tim 891
16     #include <stdio.h>
17     #include <stdlib.h>
18     #include <string.h>
19    
20 gezelter 1630 #ifndef FIX_UNUSED
21     #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
22     #endif
23 tim 891
24 gezelter 1798 #ifdef WIN32
25     #include "utils/wingetopt.h"
26     #else
27 gezelter 1630 #include <getopt.h>
28 gezelter 1798 #endif
29 gezelter 1630
30 tim 891 #include "HydroCmd.h"
31    
32 gezelter 1851 const char *gengetopt_args_info_purpose = "\n+--------------------------------------------------------------------------+\n| ____ __ ___ ____ |\n| / __ \\____ ___ ____ / |/ // __ \\ The Open Molecular Dynamics |\n| / / / / __ \\/ _ \\/ __ \\ / /|_/ // / / / Engine (formerly OOPSE). |\n| / /_/ / /_/ / __/ / / // / / // /_/ / |\n| \\____/ .___/\\___/_/ /_//_/ /_//_____/ Copyright 2004-2013 by the |\n| /_/ University of Notre Dame. |\n| |\n| http://www.openmd.net |\n| |\n| OpenMD is an OpenScience project. All source code is available for |\n| any use whatsoever under a BSD-style license. |\n| |\n| Support OpenScience! If you use OpenMD or its source code in your |\n| research, please cite the appropriate papers when you publish your |\n| work. Good starting points are: |\n| |\n| [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |\n| [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |\n| [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |\n| [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |\n| [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |\n| [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012). |\n+--------------------------------------------------------------------------+";
33 gezelter 1390
34 gezelter 1630 const char *gengetopt_args_info_usage = "Usage: Hydro [OPTIONS]... [FILES]...";
35 gezelter 1390
36     const char *gengetopt_args_info_description = "";
37    
38     const char *gengetopt_args_info_help[] = {
39     " -h, --help Print help and exit",
40     " -V, --version Print version and exit",
41     " -i, --input=filename input MetaData (md) file",
42     " -o, --output=STRING output file prefix (default=`hydro')",
43     " --model=STRING hydrodynamics model (supports RoughShell and BeadModel)",
44     " -b, --beads generate the beads only, hydrodynamics will be \n performed (default=off)",
45     0
46     };
47    
48     typedef enum {ARG_NO
49     , ARG_FLAG
50     , ARG_STRING
51     } cmdline_parser_arg_type;
52    
53 gezelter 938 static
54     void clear_given (struct gengetopt_args_info *args_info);
55     static
56     void clear_args (struct gengetopt_args_info *args_info);
57    
58     static int
59 gezelter 1630 cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
60 gezelter 1390 struct cmdline_parser_params *params, const char *additional_error);
61 gezelter 938
62     static int
63     cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
64    
65     static char *
66     gengetopt_strdup (const char *s);
67    
68     static
69     void clear_given (struct gengetopt_args_info *args_info)
70     {
71     args_info->help_given = 0 ;
72     args_info->version_given = 0 ;
73     args_info->input_given = 0 ;
74     args_info->output_given = 0 ;
75     args_info->model_given = 0 ;
76     args_info->beads_given = 0 ;
77     }
78    
79     static
80     void clear_args (struct gengetopt_args_info *args_info)
81     {
82 gezelter 1630 FIX_UNUSED (args_info);
83 gezelter 938 args_info->input_arg = NULL;
84     args_info->input_orig = NULL;
85     args_info->output_arg = gengetopt_strdup ("hydro");
86     args_info->output_orig = NULL;
87     args_info->model_arg = NULL;
88     args_info->model_orig = NULL;
89     args_info->beads_flag = 0;
90    
91     }
92    
93 gezelter 1390 static
94     void init_args_info(struct gengetopt_args_info *args_info)
95     {
96    
97    
98     args_info->help_help = gengetopt_args_info_help[0] ;
99     args_info->version_help = gengetopt_args_info_help[1] ;
100     args_info->input_help = gengetopt_args_info_help[2] ;
101     args_info->output_help = gengetopt_args_info_help[3] ;
102     args_info->model_help = gengetopt_args_info_help[4] ;
103     args_info->beads_help = gengetopt_args_info_help[5] ;
104    
105     }
106    
107 tim 891 void
108     cmdline_parser_print_version (void)
109     {
110 gezelter 1630 printf ("%s %s\n",
111     (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
112     CMDLINE_PARSER_VERSION);
113 tim 891 }
114    
115 gezelter 1390 static void print_help_common(void) {
116     cmdline_parser_print_version ();
117    
118     if (strlen(gengetopt_args_info_purpose) > 0)
119     printf("\n%s\n", gengetopt_args_info_purpose);
120    
121     if (strlen(gengetopt_args_info_usage) > 0)
122     printf("\n%s\n", gengetopt_args_info_usage);
123    
124     printf("\n");
125    
126     if (strlen(gengetopt_args_info_description) > 0)
127 gezelter 1630 printf("%s\n\n", gengetopt_args_info_description);
128 gezelter 1390 }
129    
130 tim 891 void
131     cmdline_parser_print_help (void)
132     {
133 gezelter 1390 int i = 0;
134     print_help_common();
135     while (gengetopt_args_info_help[i])
136     printf("%s\n", gengetopt_args_info_help[i++]);
137 tim 891 }
138    
139 gezelter 938 void
140     cmdline_parser_init (struct gengetopt_args_info *args_info)
141     {
142     clear_given (args_info);
143     clear_args (args_info);
144 gezelter 1390 init_args_info (args_info);
145 gezelter 1630
146     args_info->inputs = 0;
147     args_info->inputs_num = 0;
148 gezelter 938 }
149 tim 891
150 gezelter 1390 void
151     cmdline_parser_params_init(struct cmdline_parser_params *params)
152     {
153     if (params)
154     {
155     params->override = 0;
156     params->initialize = 1;
157     params->check_required = 1;
158     params->check_ambiguity = 0;
159     params->print_errors = 1;
160     }
161     }
162    
163     struct cmdline_parser_params *
164     cmdline_parser_params_create(void)
165     {
166     struct cmdline_parser_params *params =
167     (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
168     cmdline_parser_params_init(params);
169     return params;
170     }
171    
172 gezelter 938 static void
173 gezelter 1390 free_string_field (char **s)
174     {
175     if (*s)
176     {
177     free (*s);
178     *s = 0;
179     }
180     }
181    
182    
183     static void
184 gezelter 938 cmdline_parser_release (struct gengetopt_args_info *args_info)
185     {
186 gezelter 1630 unsigned int i;
187 gezelter 1390 free_string_field (&(args_info->input_arg));
188     free_string_field (&(args_info->input_orig));
189     free_string_field (&(args_info->output_arg));
190     free_string_field (&(args_info->output_orig));
191     free_string_field (&(args_info->model_arg));
192     free_string_field (&(args_info->model_orig));
193 gezelter 938
194 gezelter 1390
195 gezelter 1630 for (i = 0; i < args_info->inputs_num; ++i)
196     free (args_info->inputs [i]);
197 gezelter 1390
198 gezelter 1630 if (args_info->inputs_num)
199     free (args_info->inputs);
200    
201 gezelter 1390 clear_given (args_info);
202     }
203    
204    
205     static void
206 gezelter 1630 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
207 gezelter 1390 {
208 gezelter 1630 FIX_UNUSED (values);
209 gezelter 1390 if (arg) {
210     fprintf(outfile, "%s=\"%s\"\n", opt, arg);
211     } else {
212     fprintf(outfile, "%s\n", opt);
213     }
214     }
215    
216    
217     int
218     cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
219     {
220     int i = 0;
221    
222     if (!outfile)
223 gezelter 938 {
224 gezelter 1390 fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
225     return EXIT_FAILURE;
226 gezelter 938 }
227 gezelter 1390
228     if (args_info->help_given)
229     write_into_file(outfile, "help", 0, 0 );
230     if (args_info->version_given)
231     write_into_file(outfile, "version", 0, 0 );
232     if (args_info->input_given)
233     write_into_file(outfile, "input", args_info->input_orig, 0);
234     if (args_info->output_given)
235     write_into_file(outfile, "output", args_info->output_orig, 0);
236     if (args_info->model_given)
237     write_into_file(outfile, "model", args_info->model_orig, 0);
238     if (args_info->beads_given)
239     write_into_file(outfile, "beads", 0, 0 );
240 gezelter 938
241 gezelter 1390
242     i = EXIT_SUCCESS;
243     return i;
244 gezelter 938 }
245 tim 891
246 gezelter 938 int
247     cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
248     {
249     FILE *outfile;
250     int i = 0;
251    
252     outfile = fopen(filename, "w");
253    
254     if (!outfile)
255     {
256     fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
257     return EXIT_FAILURE;
258     }
259    
260 gezelter 1390 i = cmdline_parser_dump(outfile, args_info);
261 gezelter 938 fclose (outfile);
262    
263     return i;
264     }
265    
266     void
267     cmdline_parser_free (struct gengetopt_args_info *args_info)
268     {
269     cmdline_parser_release (args_info);
270     }
271    
272 gezelter 1390 /** @brief replacement of strdup, which is not standard */
273 tim 891 char *
274     gengetopt_strdup (const char *s)
275     {
276 gezelter 1630 char *result = 0;
277 gezelter 938 if (!s)
278     return result;
279    
280     result = (char*)malloc(strlen(s) + 1);
281 tim 891 if (result == (char*)0)
282     return (char*)0;
283     strcpy(result, s);
284     return result;
285     }
286    
287     int
288 gezelter 1630 cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
289 tim 891 {
290 gezelter 938 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
291     }
292 tim 891
293 gezelter 938 int
294 gezelter 1630 cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
295 gezelter 1390 struct cmdline_parser_params *params)
296     {
297     int result;
298 gezelter 1630 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
299 gezelter 1390
300     if (result == EXIT_FAILURE)
301     {
302     cmdline_parser_free (args_info);
303     exit (EXIT_FAILURE);
304     }
305    
306     return result;
307     }
308    
309     int
310 gezelter 1630 cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
311 gezelter 938 {
312     int result;
313 gezelter 1390 struct cmdline_parser_params params;
314    
315     params.override = override;
316     params.initialize = initialize;
317     params.check_required = check_required;
318     params.check_ambiguity = 0;
319     params.print_errors = 1;
320 gezelter 938
321 gezelter 1630 result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
322 gezelter 938
323     if (result == EXIT_FAILURE)
324     {
325     cmdline_parser_free (args_info);
326     exit (EXIT_FAILURE);
327     }
328    
329     return result;
330 tim 891 }
331    
332 gezelter 938 int
333     cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
334     {
335     int result = EXIT_SUCCESS;
336 tim 891
337 gezelter 1630 if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
338 gezelter 938 result = EXIT_FAILURE;
339    
340     if (result == EXIT_FAILURE)
341     {
342     cmdline_parser_free (args_info);
343     exit (EXIT_FAILURE);
344     }
345    
346     return result;
347     }
348    
349     int
350     cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
351     {
352     int error = 0;
353 gezelter 1630 FIX_UNUSED (additional_error);
354 gezelter 938
355 gezelter 1390 /* checks for required options */
356 gezelter 938 if (! args_info->input_given)
357     {
358     fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
359     error = 1;
360     }
361 gezelter 1390
362 gezelter 938 if (! args_info->model_given)
363     {
364     fprintf (stderr, "%s: '--model' option required%s\n", prog_name, (additional_error ? additional_error : ""));
365     error = 1;
366     }
367 gezelter 1390
368    
369     /* checks for dependences among options */
370 gezelter 938
371     return error;
372     }
373    
374 gezelter 1390
375     static char *package_name = 0;
376    
377     /**
378     * @brief updates an option
379     * @param field the generic pointer to the field to update
380     * @param orig_field the pointer to the orig field
381     * @param field_given the pointer to the number of occurrence of this option
382     * @param prev_given the pointer to the number of occurrence already seen
383     * @param value the argument for this option (if null no arg was specified)
384     * @param possible_values the possible values for this option (if specified)
385     * @param default_value the default value (in case the option only accepts fixed values)
386     * @param arg_type the type of this option
387     * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
388     * @param override @see cmdline_parser_params.override
389     * @param no_free whether to free a possible previous value
390     * @param multiple_option whether this is a multiple option
391     * @param long_opt the corresponding long option
392     * @param short_opt the corresponding short option (or '-' if none)
393     * @param additional_error possible further error specification
394     */
395     static
396     int update_arg(void *field, char **orig_field,
397     unsigned int *field_given, unsigned int *prev_given,
398 gezelter 1630 char *value, const char *possible_values[],
399     const char *default_value,
400 gezelter 1390 cmdline_parser_arg_type arg_type,
401     int check_ambiguity, int override,
402     int no_free, int multiple_option,
403     const char *long_opt, char short_opt,
404     const char *additional_error)
405     {
406     char *stop_char = 0;
407     const char *val = value;
408     int found;
409     char **string_field;
410 gezelter 1630 FIX_UNUSED (field);
411 gezelter 1390
412     stop_char = 0;
413     found = 0;
414    
415     if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
416     {
417     if (short_opt != '-')
418     fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
419     package_name, long_opt, short_opt,
420     (additional_error ? additional_error : ""));
421     else
422     fprintf (stderr, "%s: `--%s' option given more than once%s\n",
423     package_name, long_opt,
424     (additional_error ? additional_error : ""));
425     return 1; /* failure */
426     }
427    
428 gezelter 1630 FIX_UNUSED (default_value);
429 gezelter 1390
430     if (field_given && *field_given && ! override)
431     return 0;
432     if (prev_given)
433     (*prev_given)++;
434     if (field_given)
435     (*field_given)++;
436     if (possible_values)
437     val = possible_values[found];
438    
439     switch(arg_type) {
440     case ARG_FLAG:
441     *((int *)field) = !*((int *)field);
442     break;
443     case ARG_STRING:
444     if (val) {
445     string_field = (char **)field;
446     if (!no_free && *string_field)
447     free (*string_field); /* free previous string */
448     *string_field = gengetopt_strdup (val);
449     }
450     break;
451     default:
452     break;
453     };
454    
455    
456     /* store the original value */
457     switch(arg_type) {
458     case ARG_NO:
459     case ARG_FLAG:
460     break;
461     default:
462     if (value && orig_field) {
463     if (no_free) {
464     *orig_field = value;
465     } else {
466     if (*orig_field)
467     free (*orig_field); /* free previous string */
468     *orig_field = gengetopt_strdup (value);
469     }
470     }
471     };
472    
473     return 0; /* OK */
474     }
475    
476    
477 gezelter 938 int
478 gezelter 1630 cmdline_parser_internal (
479     int argc, char **argv, struct gengetopt_args_info *args_info,
480 gezelter 1390 struct cmdline_parser_params *params, const char *additional_error)
481 gezelter 938 {
482     int c; /* Character of the parsed option. */
483    
484     int error = 0;
485     struct gengetopt_args_info local_args_info;
486 gezelter 1390
487     int override;
488     int initialize;
489     int check_required;
490     int check_ambiguity;
491    
492     package_name = argv[0];
493    
494     override = params->override;
495     initialize = params->initialize;
496     check_required = params->check_required;
497     check_ambiguity = params->check_ambiguity;
498 gezelter 938
499     if (initialize)
500     cmdline_parser_init (args_info);
501    
502     cmdline_parser_init (&local_args_info);
503    
504 tim 891 optarg = 0;
505 gezelter 938 optind = 0;
506 gezelter 1390 opterr = params->print_errors;
507 tim 891 optopt = '?';
508    
509     while (1)
510     {
511     int option_index = 0;
512    
513     static struct option long_options[] = {
514     { "help", 0, NULL, 'h' },
515     { "version", 0, NULL, 'V' },
516     { "input", 1, NULL, 'i' },
517     { "output", 1, NULL, 'o' },
518     { "model", 1, NULL, 0 },
519 tim 921 { "beads", 0, NULL, 'b' },
520 gezelter 1630 { 0, 0, 0, 0 }
521 tim 891 };
522    
523 tim 921 c = getopt_long (argc, argv, "hVi:o:b", long_options, &option_index);
524 tim 891
525     if (c == -1) break; /* Exit from `while (1)' loop. */
526    
527     switch (c)
528     {
529     case 'h': /* Print help and exit. */
530     cmdline_parser_print_help ();
531 gezelter 938 cmdline_parser_free (&local_args_info);
532 tim 891 exit (EXIT_SUCCESS);
533    
534     case 'V': /* Print version and exit. */
535     cmdline_parser_print_version ();
536 gezelter 938 cmdline_parser_free (&local_args_info);
537 tim 891 exit (EXIT_SUCCESS);
538    
539 xsun 1177 case 'i': /* input MetaData (md) file. */
540 gezelter 1390
541    
542     if (update_arg( (void *)&(args_info->input_arg),
543     &(args_info->input_orig), &(args_info->input_given),
544     &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
545     check_ambiguity, override, 0, 0,
546     "input", 'i',
547     additional_error))
548     goto failure;
549    
550 tim 891 break;
551     case 'o': /* output file prefix. */
552 gezelter 1390
553    
554     if (update_arg( (void *)&(args_info->output_arg),
555     &(args_info->output_orig), &(args_info->output_given),
556     &(local_args_info.output_given), optarg, 0, "hydro", ARG_STRING,
557     check_ambiguity, override, 0, 0,
558     "output", 'o',
559     additional_error))
560     goto failure;
561    
562 tim 891 break;
563 tim 921 case 'b': /* generate the beads only, hydrodynamics will be performed. */
564 gezelter 1390
565    
566     if (update_arg((void *)&(args_info->beads_flag), 0, &(args_info->beads_given),
567     &(local_args_info.beads_given), optarg, 0, 0, ARG_FLAG,
568     check_ambiguity, override, 1, 0, "beads", 'b',
569     additional_error))
570     goto failure;
571    
572 tim 921 break;
573 tim 891
574     case 0: /* Long option with no short option */
575 xsun 1177 /* hydrodynamics model (supports RoughShell and BeadModel). */
576 tim 906 if (strcmp (long_options[option_index].name, "model") == 0)
577 tim 891 {
578 gezelter 1390
579    
580     if (update_arg( (void *)&(args_info->model_arg),
581     &(args_info->model_orig), &(args_info->model_given),
582     &(local_args_info.model_given), optarg, 0, 0, ARG_STRING,
583     check_ambiguity, override, 0, 0,
584     "model", '-',
585     additional_error))
586     goto failure;
587    
588 tim 891 }
589    
590 gezelter 938 break;
591 tim 891 case '?': /* Invalid option. */
592     /* `getopt_long' already printed an error message. */
593 gezelter 938 goto failure;
594 tim 891
595     default: /* bug: option not considered. */
596 gezelter 938 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
597 tim 891 abort ();
598     } /* switch */
599     } /* while */
600    
601    
602 gezelter 938
603     if (check_required)
604 tim 891 {
605 gezelter 938 error += cmdline_parser_required2 (args_info, argv[0], additional_error);
606 tim 891 }
607    
608 gezelter 938 cmdline_parser_release (&local_args_info);
609    
610     if ( error )
611 xsun 1177 return (EXIT_FAILURE);
612 gezelter 938
613 gezelter 1630 if (optind < argc)
614     {
615     int i = 0 ;
616     int found_prog_name = 0;
617     /* whether program name, i.e., argv[0], is in the remaining args
618     (this may happen with some implementations of getopt,
619     but surely not with the one included by gengetopt) */
620    
621     i = optind;
622     while (i < argc)
623     if (argv[i++] == argv[0]) {
624     found_prog_name = 1;
625     break;
626     }
627     i = 0;
628    
629     args_info->inputs_num = argc - optind - found_prog_name;
630     args_info->inputs =
631     (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
632     while (optind < argc)
633     if (argv[optind++] != argv[0])
634     args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
635     }
636    
637 tim 891 return 0;
638 gezelter 938
639     failure:
640    
641     cmdline_parser_release (&local_args_info);
642     return (EXIT_FAILURE);
643 tim 891 }

Properties

Name Value
svn:keywords Author Id Revision Date