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

File Contents

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

Properties

Name Value
svn:keywords Author Id Revision Date