1 |
tim |
891 |
/* |
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 |
tim |
892 |
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(" --viscosity=DOUBLE viscosity of solvent\n"); |
43 |
|
|
printf(" --temperature=DOUBLE temperature of the system\n"); |
44 |
|
|
printf(" --sigma=DOUBLE diameter of beads(use with rough shell model)\n"); |
45 |
|
|
printf(" --model=STRING hydrodynamics model (support RoughShell and \n BeadModel)\n"); |
46 |
tim |
891 |
} |
47 |
|
|
|
48 |
|
|
|
49 |
|
|
static char *gengetopt_strdup (const char *s); |
50 |
|
|
|
51 |
|
|
/* gengetopt_strdup() */ |
52 |
|
|
/* strdup.c replacement of strdup, which is not standard */ |
53 |
|
|
char * |
54 |
|
|
gengetopt_strdup (const char *s) |
55 |
|
|
{ |
56 |
|
|
char *result = (char*)malloc(strlen(s) + 1); |
57 |
|
|
if (result == (char*)0) |
58 |
|
|
return (char*)0; |
59 |
|
|
strcpy(result, s); |
60 |
|
|
return result; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
int |
64 |
|
|
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) |
65 |
|
|
{ |
66 |
|
|
int c; /* Character of the parsed option. */ |
67 |
|
|
int missing_required_options = 0; |
68 |
|
|
|
69 |
|
|
args_info->help_given = 0 ; |
70 |
|
|
args_info->version_given = 0 ; |
71 |
|
|
args_info->input_given = 0 ; |
72 |
|
|
args_info->output_given = 0 ; |
73 |
|
|
args_info->viscosity_given = 0 ; |
74 |
tim |
892 |
args_info->temperature_given = 0 ; |
75 |
tim |
891 |
args_info->sigma_given = 0 ; |
76 |
|
|
args_info->model_given = 0 ; |
77 |
|
|
#define clear_args() { \ |
78 |
|
|
args_info->input_arg = NULL; \ |
79 |
|
|
args_info->output_arg = gengetopt_strdup("hydro") ;\ |
80 |
|
|
args_info->model_arg = NULL; \ |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
clear_args(); |
84 |
|
|
|
85 |
|
|
optarg = 0; |
86 |
|
|
optind = 1; |
87 |
|
|
opterr = 1; |
88 |
|
|
optopt = '?'; |
89 |
|
|
|
90 |
|
|
while (1) |
91 |
|
|
{ |
92 |
|
|
int option_index = 0; |
93 |
|
|
char *stop_char; |
94 |
|
|
|
95 |
|
|
static struct option long_options[] = { |
96 |
|
|
{ "help", 0, NULL, 'h' }, |
97 |
|
|
{ "version", 0, NULL, 'V' }, |
98 |
|
|
{ "input", 1, NULL, 'i' }, |
99 |
|
|
{ "output", 1, NULL, 'o' }, |
100 |
|
|
{ "viscosity", 1, NULL, 0 }, |
101 |
tim |
892 |
{ "temperature", 1, NULL, 0 }, |
102 |
tim |
891 |
{ "sigma", 1, NULL, 0 }, |
103 |
|
|
{ "model", 1, NULL, 0 }, |
104 |
|
|
{ NULL, 0, NULL, 0 } |
105 |
|
|
}; |
106 |
|
|
|
107 |
|
|
stop_char = 0; |
108 |
|
|
c = getopt_long (argc, argv, "hVi:o:", long_options, &option_index); |
109 |
|
|
|
110 |
|
|
if (c == -1) break; /* Exit from `while (1)' loop. */ |
111 |
|
|
|
112 |
|
|
switch (c) |
113 |
|
|
{ |
114 |
|
|
case 'h': /* Print help and exit. */ |
115 |
|
|
clear_args (); |
116 |
|
|
cmdline_parser_print_help (); |
117 |
|
|
exit (EXIT_SUCCESS); |
118 |
|
|
|
119 |
|
|
case 'V': /* Print version and exit. */ |
120 |
|
|
clear_args (); |
121 |
|
|
cmdline_parser_print_version (); |
122 |
|
|
exit (EXIT_SUCCESS); |
123 |
|
|
|
124 |
|
|
case 'i': /* input dump file. */ |
125 |
|
|
if (args_info->input_given) |
126 |
|
|
{ |
127 |
|
|
fprintf (stderr, "%s: `--input' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
128 |
|
|
clear_args (); |
129 |
|
|
exit (EXIT_FAILURE); |
130 |
|
|
} |
131 |
|
|
args_info->input_given = 1; |
132 |
|
|
args_info->input_arg = gengetopt_strdup (optarg); |
133 |
|
|
break; |
134 |
|
|
|
135 |
|
|
case 'o': /* output file prefix. */ |
136 |
|
|
if (args_info->output_given) |
137 |
|
|
{ |
138 |
|
|
fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
139 |
|
|
clear_args (); |
140 |
|
|
exit (EXIT_FAILURE); |
141 |
|
|
} |
142 |
|
|
args_info->output_given = 1; |
143 |
|
|
if (args_info->output_arg) |
144 |
|
|
free (args_info->output_arg); /* free default string */ |
145 |
|
|
args_info->output_arg = gengetopt_strdup (optarg); |
146 |
|
|
break; |
147 |
|
|
|
148 |
|
|
|
149 |
|
|
case 0: /* Long option with no short option */ |
150 |
|
|
/* viscosity of solvent. */ |
151 |
|
|
if (strcmp (long_options[option_index].name, "viscosity") == 0) |
152 |
|
|
{ |
153 |
|
|
if (args_info->viscosity_given) |
154 |
|
|
{ |
155 |
|
|
fprintf (stderr, "%s: `--viscosity' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
156 |
|
|
clear_args (); |
157 |
|
|
exit (EXIT_FAILURE); |
158 |
|
|
} |
159 |
|
|
args_info->viscosity_given = 1; |
160 |
|
|
args_info->viscosity_arg = strtod (optarg, NULL); |
161 |
|
|
break; |
162 |
|
|
} |
163 |
|
|
|
164 |
tim |
892 |
/* temperature of the system. */ |
165 |
|
|
else if (strcmp (long_options[option_index].name, "temperature") == 0) |
166 |
|
|
{ |
167 |
|
|
if (args_info->temperature_given) |
168 |
|
|
{ |
169 |
|
|
fprintf (stderr, "%s: `--temperature' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
170 |
|
|
clear_args (); |
171 |
|
|
exit (EXIT_FAILURE); |
172 |
|
|
} |
173 |
|
|
args_info->temperature_given = 1; |
174 |
|
|
args_info->temperature_arg = strtod (optarg, NULL); |
175 |
|
|
break; |
176 |
|
|
} |
177 |
|
|
|
178 |
tim |
891 |
/* diameter of beads(use with rough shell model). */ |
179 |
|
|
else if (strcmp (long_options[option_index].name, "sigma") == 0) |
180 |
|
|
{ |
181 |
|
|
if (args_info->sigma_given) |
182 |
|
|
{ |
183 |
|
|
fprintf (stderr, "%s: `--sigma' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
184 |
|
|
clear_args (); |
185 |
|
|
exit (EXIT_FAILURE); |
186 |
|
|
} |
187 |
|
|
args_info->sigma_given = 1; |
188 |
|
|
args_info->sigma_arg = strtod (optarg, NULL); |
189 |
|
|
break; |
190 |
|
|
} |
191 |
|
|
|
192 |
|
|
/* hydrodynamics model (support RoughShell and BeadModel). */ |
193 |
|
|
else if (strcmp (long_options[option_index].name, "model") == 0) |
194 |
|
|
{ |
195 |
|
|
if (args_info->model_given) |
196 |
|
|
{ |
197 |
|
|
fprintf (stderr, "%s: `--model' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
198 |
|
|
clear_args (); |
199 |
|
|
exit (EXIT_FAILURE); |
200 |
|
|
} |
201 |
|
|
args_info->model_given = 1; |
202 |
|
|
args_info->model_arg = gengetopt_strdup (optarg); |
203 |
|
|
break; |
204 |
|
|
} |
205 |
|
|
|
206 |
|
|
|
207 |
|
|
case '?': /* Invalid option. */ |
208 |
|
|
/* `getopt_long' already printed an error message. */ |
209 |
|
|
exit (EXIT_FAILURE); |
210 |
|
|
|
211 |
|
|
default: /* bug: option not considered. */ |
212 |
|
|
fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c); |
213 |
|
|
abort (); |
214 |
|
|
} /* switch */ |
215 |
|
|
} /* while */ |
216 |
|
|
|
217 |
|
|
|
218 |
|
|
if (! args_info->input_given) |
219 |
|
|
{ |
220 |
|
|
fprintf (stderr, "%s: '--input' ('-i') option required\n", CMDLINE_PARSER_PACKAGE); |
221 |
|
|
missing_required_options = 1; |
222 |
|
|
} |
223 |
|
|
if (! args_info->viscosity_given) |
224 |
|
|
{ |
225 |
|
|
fprintf (stderr, "%s: '--viscosity' option required\n", CMDLINE_PARSER_PACKAGE); |
226 |
|
|
missing_required_options = 1; |
227 |
|
|
} |
228 |
tim |
892 |
if (! args_info->temperature_given) |
229 |
|
|
{ |
230 |
|
|
fprintf (stderr, "%s: '--temperature' option required\n", CMDLINE_PARSER_PACKAGE); |
231 |
|
|
missing_required_options = 1; |
232 |
|
|
} |
233 |
tim |
891 |
if (! args_info->model_given) |
234 |
|
|
{ |
235 |
|
|
fprintf (stderr, "%s: '--model' option required\n", CMDLINE_PARSER_PACKAGE); |
236 |
|
|
missing_required_options = 1; |
237 |
|
|
} |
238 |
|
|
if ( missing_required_options ) |
239 |
|
|
exit (EXIT_FAILURE); |
240 |
|
|
|
241 |
|
|
return 0; |
242 |
|
|
} |