ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/hydrodynamics/HydroCmd.c
Revision: 2675
Committed: Wed Mar 29 18:09:26 2006 UTC (18 years, 3 months ago) by tim
Content type: text/plain
File size: 5743 byte(s)
Log Message:
(1) RoughShell Model is working; (20)Adding a new option into Hydro which allows user to generate the beads only

File Contents

# Content
1 /*
2 File autogenerated by gengetopt version 2.11
3 generated with the following command:
4 /home/maul/gezelter/tim/program/gengetopt-2.11/src/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
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15
16 /* If we use autoconf. */
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include "getopt.h"
22
23 #include "HydroCmd.h"
24
25 void
26 cmdline_parser_print_version (void)
27 {
28 printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
29 }
30
31 void
32 cmdline_parser_print_help (void)
33 {
34 cmdline_parser_print_version ();
35 printf("\n"
36 "Usage: %s [OPTIONS]...\n", CMDLINE_PARSER_PACKAGE);
37 printf("\n");
38 printf(" -h, --help Print help and exit\n");
39 printf(" -V, --version Print version and exit\n");
40 printf(" -i, --input=filename input dump file\n");
41 printf(" -o, --output=STRING output file prefix (default=`hydro')\n");
42 printf(" --model=STRING hydrodynamics model (support RoughShell and BeadModel)\n");
43 printf(" -b, --beads generate the beads only, hydrodynamics will be \n performed (default=off)\n");
44 }
45
46
47 static char *gengetopt_strdup (const char *s);
48
49 /* gengetopt_strdup() */
50 /* strdup.c replacement of strdup, which is not standard */
51 char *
52 gengetopt_strdup (const char *s)
53 {
54 char *result = (char*)malloc(strlen(s) + 1);
55 if (result == (char*)0)
56 return (char*)0;
57 strcpy(result, s);
58 return result;
59 }
60
61 int
62 cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
63 {
64 int c; /* Character of the parsed option. */
65 int missing_required_options = 0;
66
67 args_info->help_given = 0 ;
68 args_info->version_given = 0 ;
69 args_info->input_given = 0 ;
70 args_info->output_given = 0 ;
71 args_info->model_given = 0 ;
72 args_info->beads_given = 0 ;
73 #define clear_args() { \
74 args_info->input_arg = NULL; \
75 args_info->output_arg = gengetopt_strdup("hydro") ;\
76 args_info->model_arg = NULL; \
77 args_info->beads_flag = 0;\
78 }
79
80 clear_args();
81
82 optarg = 0;
83 optind = 1;
84 opterr = 1;
85 optopt = '?';
86
87 while (1)
88 {
89 int option_index = 0;
90 char *stop_char;
91
92 static struct option long_options[] = {
93 { "help", 0, NULL, 'h' },
94 { "version", 0, NULL, 'V' },
95 { "input", 1, NULL, 'i' },
96 { "output", 1, NULL, 'o' },
97 { "model", 1, NULL, 0 },
98 { "beads", 0, NULL, 'b' },
99 { NULL, 0, NULL, 0 }
100 };
101
102 stop_char = 0;
103 c = getopt_long (argc, argv, "hVi:o:b", long_options, &option_index);
104
105 if (c == -1) break; /* Exit from `while (1)' loop. */
106
107 switch (c)
108 {
109 case 'h': /* Print help and exit. */
110 clear_args ();
111 cmdline_parser_print_help ();
112 exit (EXIT_SUCCESS);
113
114 case 'V': /* Print version and exit. */
115 clear_args ();
116 cmdline_parser_print_version ();
117 exit (EXIT_SUCCESS);
118
119 case 'i': /* input dump file. */
120 if (args_info->input_given)
121 {
122 fprintf (stderr, "%s: `--input' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE);
123 clear_args ();
124 exit (EXIT_FAILURE);
125 }
126 args_info->input_given = 1;
127 args_info->input_arg = gengetopt_strdup (optarg);
128 break;
129
130 case 'o': /* output file prefix. */
131 if (args_info->output_given)
132 {
133 fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE);
134 clear_args ();
135 exit (EXIT_FAILURE);
136 }
137 args_info->output_given = 1;
138 if (args_info->output_arg)
139 free (args_info->output_arg); /* free default string */
140 args_info->output_arg = gengetopt_strdup (optarg);
141 break;
142
143 case 'b': /* generate the beads only, hydrodynamics will be performed. */
144 if (args_info->beads_given)
145 {
146 fprintf (stderr, "%s: `--beads' (`-b') option given more than once\n", CMDLINE_PARSER_PACKAGE);
147 clear_args ();
148 exit (EXIT_FAILURE);
149 }
150 args_info->beads_given = 1;
151 args_info->beads_flag = !(args_info->beads_flag);
152 break;
153
154
155 case 0: /* Long option with no short option */
156 /* hydrodynamics model (support RoughShell and BeadModel). */
157 if (strcmp (long_options[option_index].name, "model") == 0)
158 {
159 if (args_info->model_given)
160 {
161 fprintf (stderr, "%s: `--model' option given more than once\n", CMDLINE_PARSER_PACKAGE);
162 clear_args ();
163 exit (EXIT_FAILURE);
164 }
165 args_info->model_given = 1;
166 args_info->model_arg = gengetopt_strdup (optarg);
167 break;
168 }
169
170
171 case '?': /* Invalid option. */
172 /* `getopt_long' already printed an error message. */
173 exit (EXIT_FAILURE);
174
175 default: /* bug: option not considered. */
176 fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c);
177 abort ();
178 } /* switch */
179 } /* while */
180
181
182 if (! args_info->input_given)
183 {
184 fprintf (stderr, "%s: '--input' ('-i') option required\n", CMDLINE_PARSER_PACKAGE);
185 missing_required_options = 1;
186 }
187 if (! args_info->model_given)
188 {
189 fprintf (stderr, "%s: '--model' option required\n", CMDLINE_PARSER_PACKAGE);
190 missing_required_options = 1;
191 }
192 if ( missing_required_options )
193 exit (EXIT_FAILURE);
194
195 return 0;
196 }