ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/hydrodynamics/HydroCmd.c
Revision: 2717
Committed: Mon Apr 17 21:49:12 2006 UTC (18 years, 3 months ago) by gezelter
Content type: text/plain
File size: 12880 byte(s)
Log Message:
Many performance improvements

File Contents

# User Rev Content
1 tim 2596 /*
2 gezelter 2717 File autogenerated by gengetopt version 2.16
3 tim 2596 generated with the following command:
4 gezelter 2717 gengetopt -F HydroCmd
5 tim 2596
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 2717 /* If we use autoconf. */
12     #ifdef HAVE_CONFIG_H
13     #include "config.h"
14     #endif
15 tim 2596
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 2717 static
25     void clear_given (struct gengetopt_args_info *args_info);
26     static
27     void clear_args (struct gengetopt_args_info *args_info);
28    
29     static int
30     cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error);
31    
32     static int
33     cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
34    
35     static char *
36     gengetopt_strdup (const char *s);
37    
38     static
39     void clear_given (struct gengetopt_args_info *args_info)
40     {
41     args_info->help_given = 0 ;
42     args_info->version_given = 0 ;
43     args_info->input_given = 0 ;
44     args_info->output_given = 0 ;
45     args_info->model_given = 0 ;
46     args_info->beads_given = 0 ;
47     }
48    
49     static
50     void clear_args (struct gengetopt_args_info *args_info)
51     {
52     args_info->input_arg = NULL;
53     args_info->input_orig = NULL;
54     args_info->output_arg = gengetopt_strdup ("hydro");
55     args_info->output_orig = NULL;
56     args_info->model_arg = NULL;
57     args_info->model_orig = NULL;
58     args_info->beads_flag = 0;
59    
60     }
61    
62 tim 2596 void
63     cmdline_parser_print_version (void)
64     {
65     printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
66     }
67    
68     void
69     cmdline_parser_print_help (void)
70     {
71     cmdline_parser_print_version ();
72 gezelter 2717 printf("\nUsage: Hydro [OPTIONS]...\n\n");
73     printf("%s\n"," -h, --help Print help and exit");
74     printf("%s\n"," -V, --version Print version and exit");
75     printf("%s\n"," -i, --input=filename input dump file");
76     printf("%s\n"," -o, --output=STRING output file prefix (default=`hydro')");
77     printf("%s\n"," --model=STRING hydrodynamics model (support RoughShell and BeadModel)");
78     printf("%s\n"," -b, --beads generate the beads only, hydrodynamics will be \n performed (default=off)");
79    
80 tim 2596 }
81    
82 gezelter 2717 void
83     cmdline_parser_init (struct gengetopt_args_info *args_info)
84     {
85     clear_given (args_info);
86     clear_args (args_info);
87     }
88 tim 2596
89 gezelter 2717 static void
90     cmdline_parser_release (struct gengetopt_args_info *args_info)
91     {
92    
93     if (args_info->input_arg)
94     {
95     free (args_info->input_arg); /* free previous argument */
96     args_info->input_arg = 0;
97     }
98     if (args_info->input_orig)
99     {
100     free (args_info->input_orig); /* free previous argument */
101     args_info->input_orig = 0;
102     }
103     if (args_info->output_arg)
104     {
105     free (args_info->output_arg); /* free previous argument */
106     args_info->output_arg = 0;
107     }
108     if (args_info->output_orig)
109     {
110     free (args_info->output_orig); /* free previous argument */
111     args_info->output_orig = 0;
112     }
113     if (args_info->model_arg)
114     {
115     free (args_info->model_arg); /* free previous argument */
116     args_info->model_arg = 0;
117     }
118     if (args_info->model_orig)
119     {
120     free (args_info->model_orig); /* free previous argument */
121     args_info->model_orig = 0;
122     }
123    
124     clear_given (args_info);
125     }
126 tim 2596
127 gezelter 2717 int
128     cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
129     {
130     FILE *outfile;
131     int i = 0;
132    
133     outfile = fopen(filename, "w");
134    
135     if (!outfile)
136     {
137     fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
138     return EXIT_FAILURE;
139     }
140    
141     if (args_info->help_given) {
142     fprintf(outfile, "%s\n", "help");
143     }
144     if (args_info->version_given) {
145     fprintf(outfile, "%s\n", "version");
146     }
147     if (args_info->input_given) {
148     if (args_info->input_orig) {
149     fprintf(outfile, "%s=\"%s\"\n", "input", args_info->input_orig);
150     } else {
151     fprintf(outfile, "%s\n", "input");
152     }
153     }
154     if (args_info->output_given) {
155     if (args_info->output_orig) {
156     fprintf(outfile, "%s=\"%s\"\n", "output", args_info->output_orig);
157     } else {
158     fprintf(outfile, "%s\n", "output");
159     }
160     }
161     if (args_info->model_given) {
162     if (args_info->model_orig) {
163     fprintf(outfile, "%s=\"%s\"\n", "model", args_info->model_orig);
164     } else {
165     fprintf(outfile, "%s\n", "model");
166     }
167     }
168     if (args_info->beads_given) {
169     fprintf(outfile, "%s\n", "beads");
170     }
171    
172     fclose (outfile);
173    
174     i = EXIT_SUCCESS;
175     return i;
176     }
177    
178     void
179     cmdline_parser_free (struct gengetopt_args_info *args_info)
180     {
181     cmdline_parser_release (args_info);
182     }
183    
184    
185 tim 2596 /* gengetopt_strdup() */
186     /* strdup.c replacement of strdup, which is not standard */
187     char *
188     gengetopt_strdup (const char *s)
189     {
190 gezelter 2717 char *result = NULL;
191     if (!s)
192     return result;
193    
194     result = (char*)malloc(strlen(s) + 1);
195 tim 2596 if (result == (char*)0)
196     return (char*)0;
197     strcpy(result, s);
198     return result;
199     }
200    
201     int
202     cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
203     {
204 gezelter 2717 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
205     }
206 tim 2596
207 gezelter 2717 int
208     cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
209     {
210     int result;
211    
212     result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
213    
214     if (result == EXIT_FAILURE)
215     {
216     cmdline_parser_free (args_info);
217     exit (EXIT_FAILURE);
218     }
219    
220     return result;
221 tim 2596 }
222    
223 gezelter 2717 int
224     cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
225     {
226     int result = EXIT_SUCCESS;
227 tim 2596
228 gezelter 2717 if (cmdline_parser_required2(args_info, prog_name, NULL) > 0)
229     result = EXIT_FAILURE;
230    
231     if (result == EXIT_FAILURE)
232     {
233     cmdline_parser_free (args_info);
234     exit (EXIT_FAILURE);
235     }
236    
237     return result;
238     }
239    
240     int
241     cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
242     {
243     int error = 0;
244    
245     if (! args_info->input_given)
246     {
247     fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
248     error = 1;
249     }
250     if (! args_info->model_given)
251     {
252     fprintf (stderr, "%s: '--model' option required%s\n", prog_name, (additional_error ? additional_error : ""));
253     error = 1;
254     }
255    
256     return error;
257     }
258    
259     int
260     cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error)
261     {
262     int c; /* Character of the parsed option. */
263    
264     int error = 0;
265     struct gengetopt_args_info local_args_info;
266    
267     if (initialize)
268     cmdline_parser_init (args_info);
269    
270     cmdline_parser_init (&local_args_info);
271     printf("\n%s\n", "\n+----------------------------------------------------------------------+ \n| ____ ____ ____ _____ ______ The OpenSource, Object-oriented | \n| / __ \\/ __ \\/ __ \\/ ___// ____/ Parallel Simulation Engine. | \n| / / / / / / / /_/ /\\__ \\/ __/ | \n| / /_/ / /_/ / ____/___/ / /___ Copyright 2004-2006 by the | \n| \\____/\\____/_/ /____/_____/ University of Notre Dame. | \n| | \n| http://www.oopse.org |\n| | \n| OOPSE is an OpenScience project. All source code is available for |\n| any use subject to only one condition: | \n| |\n| Any published work resulting from the use of this code must cite the | \n| following paper: M. A. Meineke, C. F. Vardeman II, T. Lin, | \n| C. J. Fennell, and J. D. Gezelter, | \n| J. Comput. Chem. 26, pp. 252-271 (2005). | \n+----------------------------------------------------------------------+");
272    
273 tim 2596 optarg = 0;
274 gezelter 2717 optind = 0;
275 tim 2596 opterr = 1;
276     optopt = '?';
277    
278     while (1)
279     {
280     int option_index = 0;
281     char *stop_char;
282    
283     static struct option long_options[] = {
284     { "help", 0, NULL, 'h' },
285     { "version", 0, NULL, 'V' },
286     { "input", 1, NULL, 'i' },
287     { "output", 1, NULL, 'o' },
288     { "model", 1, NULL, 0 },
289 tim 2675 { "beads", 0, NULL, 'b' },
290 tim 2596 { NULL, 0, NULL, 0 }
291     };
292    
293     stop_char = 0;
294 tim 2675 c = getopt_long (argc, argv, "hVi:o:b", long_options, &option_index);
295 tim 2596
296     if (c == -1) break; /* Exit from `while (1)' loop. */
297    
298     switch (c)
299     {
300     case 'h': /* Print help and exit. */
301     cmdline_parser_print_help ();
302 gezelter 2717 cmdline_parser_free (&local_args_info);
303 tim 2596 exit (EXIT_SUCCESS);
304    
305     case 'V': /* Print version and exit. */
306     cmdline_parser_print_version ();
307 gezelter 2717 cmdline_parser_free (&local_args_info);
308 tim 2596 exit (EXIT_SUCCESS);
309    
310     case 'i': /* input dump file. */
311 gezelter 2717 if (local_args_info.input_given)
312 tim 2596 {
313 gezelter 2717 fprintf (stderr, "%s: `--input' (`-i') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
314     goto failure;
315 tim 2596 }
316 gezelter 2717 if (args_info->input_given && ! override)
317     continue;
318     local_args_info.input_given = 1;
319 tim 2596 args_info->input_given = 1;
320 gezelter 2717 if (args_info->input_arg)
321     free (args_info->input_arg); /* free previous string */
322 tim 2596 args_info->input_arg = gengetopt_strdup (optarg);
323 gezelter 2717 if (args_info->input_orig)
324     free (args_info->input_orig); /* free previous string */
325     args_info->input_orig = gengetopt_strdup (optarg);
326 tim 2596 break;
327    
328     case 'o': /* output file prefix. */
329 gezelter 2717 if (local_args_info.output_given)
330 tim 2596 {
331 gezelter 2717 fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
332     goto failure;
333 tim 2596 }
334 gezelter 2717 if (args_info->output_given && ! override)
335     continue;
336     local_args_info.output_given = 1;
337 tim 2596 args_info->output_given = 1;
338     if (args_info->output_arg)
339 gezelter 2717 free (args_info->output_arg); /* free previous string */
340 tim 2596 args_info->output_arg = gengetopt_strdup (optarg);
341 gezelter 2717 if (args_info->output_orig)
342     free (args_info->output_orig); /* free previous string */
343     args_info->output_orig = gengetopt_strdup (optarg);
344 tim 2596 break;
345    
346 tim 2675 case 'b': /* generate the beads only, hydrodynamics will be performed. */
347 gezelter 2717 if (local_args_info.beads_given)
348 tim 2675 {
349 gezelter 2717 fprintf (stderr, "%s: `--beads' (`-b') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
350     goto failure;
351 tim 2675 }
352 gezelter 2717 if (args_info->beads_given && ! override)
353     continue;
354     local_args_info.beads_given = 1;
355 tim 2675 args_info->beads_given = 1;
356     args_info->beads_flag = !(args_info->beads_flag);
357     break;
358 tim 2596
359 tim 2675
360 tim 2596 case 0: /* Long option with no short option */
361     /* hydrodynamics model (support RoughShell and BeadModel). */
362 tim 2634 if (strcmp (long_options[option_index].name, "model") == 0)
363 tim 2596 {
364 gezelter 2717 if (local_args_info.model_given)
365 tim 2596 {
366 gezelter 2717 fprintf (stderr, "%s: `--model' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
367     goto failure;
368 tim 2596 }
369 gezelter 2717 if (args_info->model_given && ! override)
370     continue;
371     local_args_info.model_given = 1;
372 tim 2596 args_info->model_given = 1;
373 gezelter 2717 if (args_info->model_arg)
374     free (args_info->model_arg); /* free previous string */
375 tim 2596 args_info->model_arg = gengetopt_strdup (optarg);
376 gezelter 2717 if (args_info->model_orig)
377     free (args_info->model_orig); /* free previous string */
378     args_info->model_orig = gengetopt_strdup (optarg);
379 tim 2596 }
380    
381 gezelter 2717 break;
382 tim 2596 case '?': /* Invalid option. */
383     /* `getopt_long' already printed an error message. */
384 gezelter 2717 goto failure;
385 tim 2596
386     default: /* bug: option not considered. */
387 gezelter 2717 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
388 tim 2596 abort ();
389     } /* switch */
390     } /* while */
391    
392    
393 gezelter 2717
394     if (check_required)
395 tim 2596 {
396 gezelter 2717 error += cmdline_parser_required2 (args_info, argv[0], additional_error);
397 tim 2596 }
398    
399 gezelter 2717 cmdline_parser_release (&local_args_info);
400    
401     if ( error )
402     goto failure;
403    
404 tim 2596 return 0;
405 gezelter 2717
406     failure:
407    
408     cmdline_parser_print_help ();
409     cmdline_parser_release (&local_args_info);
410     return (EXIT_FAILURE);
411 tim 2596 }