ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/hydrodynamics/HydroCmd.cpp
Revision: 1465
Committed: Fri Jul 9 23:08:25 2010 UTC (14 years, 10 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

# Content
1 /*
2 File autogenerated by gengetopt version 2.22
3 generated with the following command:
4 gengetopt -F HydroCmd
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 "HydroCmd.h"
23
24 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 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 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
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 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 void
99 cmdline_parser_print_version (void)
100 {
101 printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
102 }
103
104 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 void
120 cmdline_parser_print_help (void)
121 {
122 int i = 0;
123 print_help_common();
124 while (gengetopt_args_info_help[i])
125 printf("%s\n", gengetopt_args_info_help[i++]);
126 }
127
128 void
129 cmdline_parser_init (struct gengetopt_args_info *args_info)
130 {
131 clear_given (args_info);
132 clear_args (args_info);
133 init_args_info (args_info);
134 }
135
136 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 static void
159 free_string_field (char **s)
160 {
161 if (*s)
162 {
163 free (*s);
164 *s = 0;
165 }
166 }
167
168
169 static void
170 cmdline_parser_release (struct gengetopt_args_info *args_info)
171 {
172
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
180
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 {
204 fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
205 return EXIT_FAILURE;
206 }
207
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
221
222 i = EXIT_SUCCESS;
223 return i;
224 }
225
226 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 i = cmdline_parser_dump(outfile, args_info);
241 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 /** @brief replacement of strdup, which is not standard */
253 char *
254 gengetopt_strdup (const char *s)
255 {
256 char *result = NULL;
257 if (!s)
258 return result;
259
260 result = (char*)malloc(strlen(s) + 1);
261 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 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
271 }
272
273 int
274 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 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 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
301 result = cmdline_parser_internal (argc, argv, args_info, &params, NULL);
302
303 if (result == EXIT_FAILURE)
304 {
305 cmdline_parser_free (args_info);
306 exit (EXIT_FAILURE);
307 }
308
309 return result;
310 }
311
312 int
313 cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
314 {
315 int result = EXIT_SUCCESS;
316
317 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 /* checks for required options */
335 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
341 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
347
348 /* checks for dependences among options */
349
350 return error;
351 }
352
353
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 int
454 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 {
457 int c; /* Character of the parsed option. */
458
459 int error = 0;
460 struct gengetopt_args_info local_args_info;
461
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
474 if (initialize)
475 cmdline_parser_init (args_info);
476
477 cmdline_parser_init (&local_args_info);
478
479 optarg = 0;
480 optind = 0;
481 opterr = params->print_errors;
482 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 { "beads", 0, NULL, 'b' },
495 { NULL, 0, NULL, 0 }
496 };
497
498 c = getopt_long (argc, argv, "hVi:o:b", long_options, &option_index);
499
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 cmdline_parser_free (&local_args_info);
507 exit (EXIT_SUCCESS);
508
509 case 'V': /* Print version and exit. */
510 cmdline_parser_print_version ();
511 cmdline_parser_free (&local_args_info);
512 exit (EXIT_SUCCESS);
513
514 case 'i': /* input MetaData (md) file. */
515
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 break;
526 case 'o': /* output file prefix. */
527
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 break;
538 case 'b': /* generate the beads only, hydrodynamics will be performed. */
539
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 break;
548
549 case 0: /* Long option with no short option */
550 /* hydrodynamics model (supports RoughShell and BeadModel). */
551 if (strcmp (long_options[option_index].name, "model") == 0)
552 {
553
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 }
564
565 break;
566 case '?': /* Invalid option. */
567 /* `getopt_long' already printed an error message. */
568 goto failure;
569
570 default: /* bug: option not considered. */
571 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
572 abort ();
573 } /* switch */
574 } /* while */
575
576
577
578 if (check_required)
579 {
580 error += cmdline_parser_required2 (args_info, argv[0], additional_error);
581 }
582
583 cmdline_parser_release (&local_args_info);
584
585 if ( error )
586 return (EXIT_FAILURE);
587
588 return 0;
589
590 failure:
591
592 cmdline_parser_release (&local_args_info);
593 return (EXIT_FAILURE);
594 }

Properties

Name Value
svn:keywords Author Id Revision Date