1 |
/* |
2 |
File autogenerated by gengetopt version 2.22.4 |
3 |
generated with the following command: |
4 |
gengetopt --file-name=DynamicPropsCmd --unamed-opts |
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 |
#ifndef FIX_UNUSED |
21 |
#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ |
22 |
#endif |
23 |
|
24 |
#ifdef WIN32 |
25 |
#include "utils/wingetopt.h" |
26 |
#else |
27 |
#include <getopt.h> |
28 |
#endif |
29 |
|
30 |
#include "DynamicPropsCmd.h" |
31 |
|
32 |
const char *gengetopt_args_info_purpose = ""; |
33 |
|
34 |
const char *gengetopt_args_info_usage = "Usage: DynamicProps [OPTIONS]... [FILES]..."; |
35 |
|
36 |
const char *gengetopt_args_info_description = ""; |
37 |
|
38 |
const char *gengetopt_args_info_help[] = { |
39 |
" -h, --help Print help and exit", |
40 |
" -V, --version Print version and exit", |
41 |
" -i, --input=filename input dump file", |
42 |
" -o, --output=filename output file name", |
43 |
" --sele1=selection script select first stuntdouble set", |
44 |
" --sele2=selection script select second stuntdouble set (if sele2 is not \n set, use script from sele1)", |
45 |
" --order=INT Lengendre Polynomial Order", |
46 |
" -z, --nzbins=INT Number of Z bins (default=`100')", |
47 |
" -m, --memory=memory specification\n Available memory (defaults to 2G) \n (default=`2G')", |
48 |
"\n Group: dynamicProps\n an option of this group is required", |
49 |
" -s, --selecorr selection correlation function", |
50 |
" -r, --rcorr rmsd", |
51 |
" -v, --vcorr velocity correlation function", |
52 |
" -d, --dcorr dipole correlation function", |
53 |
" -l, --lcorr Lengendre correlation function", |
54 |
" --lcorrZ Lengendre correlation function binned by Z", |
55 |
" --cohZ Lengendre correlation function for OH bond \n vectors binned by Z", |
56 |
" -M, --sdcorr System dipole correlation function", |
57 |
" --r_rcorr Radial rmsd", |
58 |
" --thetacorr Angular rmsd", |
59 |
" --drcorr Directional rmsd for particles with unit \n vectors", |
60 |
" --helfandEcorr Helfand moment for thermal conductvity", |
61 |
" -p, --momentum Helfand momentum for viscosity", |
62 |
" --stresscorr Stress tensor correlation function", |
63 |
" -b, --bondcorr Bond extension correlation function", |
64 |
0 |
65 |
}; |
66 |
|
67 |
typedef enum {ARG_NO |
68 |
, ARG_STRING |
69 |
, ARG_INT |
70 |
} cmdline_parser_arg_type; |
71 |
|
72 |
static |
73 |
void clear_given (struct gengetopt_args_info *args_info); |
74 |
static |
75 |
void clear_args (struct gengetopt_args_info *args_info); |
76 |
|
77 |
static int |
78 |
cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, |
79 |
struct cmdline_parser_params *params, const char *additional_error); |
80 |
|
81 |
static int |
82 |
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); |
83 |
|
84 |
static char * |
85 |
gengetopt_strdup (const char *s); |
86 |
|
87 |
static |
88 |
void clear_given (struct gengetopt_args_info *args_info) |
89 |
{ |
90 |
args_info->help_given = 0 ; |
91 |
args_info->version_given = 0 ; |
92 |
args_info->input_given = 0 ; |
93 |
args_info->output_given = 0 ; |
94 |
args_info->sele1_given = 0 ; |
95 |
args_info->sele2_given = 0 ; |
96 |
args_info->order_given = 0 ; |
97 |
args_info->nzbins_given = 0 ; |
98 |
args_info->memory_given = 0 ; |
99 |
args_info->selecorr_given = 0 ; |
100 |
args_info->rcorr_given = 0 ; |
101 |
args_info->vcorr_given = 0 ; |
102 |
args_info->dcorr_given = 0 ; |
103 |
args_info->lcorr_given = 0 ; |
104 |
args_info->lcorrZ_given = 0 ; |
105 |
args_info->cohZ_given = 0 ; |
106 |
args_info->sdcorr_given = 0 ; |
107 |
args_info->r_rcorr_given = 0 ; |
108 |
args_info->thetacorr_given = 0 ; |
109 |
args_info->drcorr_given = 0 ; |
110 |
args_info->helfandEcorr_given = 0 ; |
111 |
args_info->momentum_given = 0 ; |
112 |
args_info->stresscorr_given = 0 ; |
113 |
args_info->bondcorr_given = 0 ; |
114 |
args_info->dynamicProps_group_counter = 0 ; |
115 |
} |
116 |
|
117 |
static |
118 |
void clear_args (struct gengetopt_args_info *args_info) |
119 |
{ |
120 |
FIX_UNUSED (args_info); |
121 |
args_info->input_arg = NULL; |
122 |
args_info->input_orig = NULL; |
123 |
args_info->output_arg = NULL; |
124 |
args_info->output_orig = NULL; |
125 |
args_info->sele1_arg = NULL; |
126 |
args_info->sele1_orig = NULL; |
127 |
args_info->sele2_arg = NULL; |
128 |
args_info->sele2_orig = NULL; |
129 |
args_info->order_orig = NULL; |
130 |
args_info->nzbins_arg = 100; |
131 |
args_info->nzbins_orig = NULL; |
132 |
args_info->memory_arg = gengetopt_strdup ("2G"); |
133 |
args_info->memory_orig = NULL; |
134 |
|
135 |
} |
136 |
|
137 |
static |
138 |
void init_args_info(struct gengetopt_args_info *args_info) |
139 |
{ |
140 |
|
141 |
|
142 |
args_info->help_help = gengetopt_args_info_help[0] ; |
143 |
args_info->version_help = gengetopt_args_info_help[1] ; |
144 |
args_info->input_help = gengetopt_args_info_help[2] ; |
145 |
args_info->output_help = gengetopt_args_info_help[3] ; |
146 |
args_info->sele1_help = gengetopt_args_info_help[4] ; |
147 |
args_info->sele2_help = gengetopt_args_info_help[5] ; |
148 |
args_info->order_help = gengetopt_args_info_help[6] ; |
149 |
args_info->nzbins_help = gengetopt_args_info_help[7] ; |
150 |
args_info->memory_help = gengetopt_args_info_help[8] ; |
151 |
args_info->selecorr_help = gengetopt_args_info_help[10] ; |
152 |
args_info->rcorr_help = gengetopt_args_info_help[11] ; |
153 |
args_info->vcorr_help = gengetopt_args_info_help[12] ; |
154 |
args_info->dcorr_help = gengetopt_args_info_help[13] ; |
155 |
args_info->lcorr_help = gengetopt_args_info_help[14] ; |
156 |
args_info->lcorrZ_help = gengetopt_args_info_help[15] ; |
157 |
args_info->cohZ_help = gengetopt_args_info_help[16] ; |
158 |
args_info->sdcorr_help = gengetopt_args_info_help[17] ; |
159 |
args_info->r_rcorr_help = gengetopt_args_info_help[18] ; |
160 |
args_info->thetacorr_help = gengetopt_args_info_help[19] ; |
161 |
args_info->drcorr_help = gengetopt_args_info_help[20] ; |
162 |
args_info->helfandEcorr_help = gengetopt_args_info_help[21] ; |
163 |
args_info->momentum_help = gengetopt_args_info_help[22] ; |
164 |
args_info->stresscorr_help = gengetopt_args_info_help[23] ; |
165 |
args_info->bondcorr_help = gengetopt_args_info_help[24] ; |
166 |
|
167 |
} |
168 |
|
169 |
void |
170 |
cmdline_parser_print_version (void) |
171 |
{ |
172 |
printf ("%s %s\n", |
173 |
(strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), |
174 |
CMDLINE_PARSER_VERSION); |
175 |
} |
176 |
|
177 |
static void print_help_common(void) { |
178 |
cmdline_parser_print_version (); |
179 |
|
180 |
if (strlen(gengetopt_args_info_purpose) > 0) |
181 |
printf("\n%s\n", gengetopt_args_info_purpose); |
182 |
|
183 |
if (strlen(gengetopt_args_info_usage) > 0) |
184 |
printf("\n%s\n", gengetopt_args_info_usage); |
185 |
|
186 |
printf("\n"); |
187 |
|
188 |
if (strlen(gengetopt_args_info_description) > 0) |
189 |
printf("%s\n\n", gengetopt_args_info_description); |
190 |
} |
191 |
|
192 |
void |
193 |
cmdline_parser_print_help (void) |
194 |
{ |
195 |
int i = 0; |
196 |
print_help_common(); |
197 |
while (gengetopt_args_info_help[i]) |
198 |
printf("%s\n", gengetopt_args_info_help[i++]); |
199 |
} |
200 |
|
201 |
void |
202 |
cmdline_parser_init (struct gengetopt_args_info *args_info) |
203 |
{ |
204 |
clear_given (args_info); |
205 |
clear_args (args_info); |
206 |
init_args_info (args_info); |
207 |
|
208 |
args_info->inputs = 0; |
209 |
args_info->inputs_num = 0; |
210 |
} |
211 |
|
212 |
void |
213 |
cmdline_parser_params_init(struct cmdline_parser_params *params) |
214 |
{ |
215 |
if (params) |
216 |
{ |
217 |
params->override = 0; |
218 |
params->initialize = 1; |
219 |
params->check_required = 1; |
220 |
params->check_ambiguity = 0; |
221 |
params->print_errors = 1; |
222 |
} |
223 |
} |
224 |
|
225 |
struct cmdline_parser_params * |
226 |
cmdline_parser_params_create(void) |
227 |
{ |
228 |
struct cmdline_parser_params *params = |
229 |
(struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); |
230 |
cmdline_parser_params_init(params); |
231 |
return params; |
232 |
} |
233 |
|
234 |
static void |
235 |
free_string_field (char **s) |
236 |
{ |
237 |
if (*s) |
238 |
{ |
239 |
free (*s); |
240 |
*s = 0; |
241 |
} |
242 |
} |
243 |
|
244 |
|
245 |
static void |
246 |
cmdline_parser_release (struct gengetopt_args_info *args_info) |
247 |
{ |
248 |
unsigned int i; |
249 |
free_string_field (&(args_info->input_arg)); |
250 |
free_string_field (&(args_info->input_orig)); |
251 |
free_string_field (&(args_info->output_arg)); |
252 |
free_string_field (&(args_info->output_orig)); |
253 |
free_string_field (&(args_info->sele1_arg)); |
254 |
free_string_field (&(args_info->sele1_orig)); |
255 |
free_string_field (&(args_info->sele2_arg)); |
256 |
free_string_field (&(args_info->sele2_orig)); |
257 |
free_string_field (&(args_info->order_orig)); |
258 |
free_string_field (&(args_info->nzbins_orig)); |
259 |
free_string_field (&(args_info->memory_arg)); |
260 |
free_string_field (&(args_info->memory_orig)); |
261 |
|
262 |
|
263 |
for (i = 0; i < args_info->inputs_num; ++i) |
264 |
free (args_info->inputs [i]); |
265 |
|
266 |
if (args_info->inputs_num) |
267 |
free (args_info->inputs); |
268 |
|
269 |
clear_given (args_info); |
270 |
} |
271 |
|
272 |
|
273 |
static void |
274 |
write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) |
275 |
{ |
276 |
FIX_UNUSED (values); |
277 |
if (arg) { |
278 |
fprintf(outfile, "%s=\"%s\"\n", opt, arg); |
279 |
} else { |
280 |
fprintf(outfile, "%s\n", opt); |
281 |
} |
282 |
} |
283 |
|
284 |
|
285 |
int |
286 |
cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) |
287 |
{ |
288 |
int i = 0; |
289 |
|
290 |
if (!outfile) |
291 |
{ |
292 |
fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); |
293 |
return EXIT_FAILURE; |
294 |
} |
295 |
|
296 |
if (args_info->help_given) |
297 |
write_into_file(outfile, "help", 0, 0 ); |
298 |
if (args_info->version_given) |
299 |
write_into_file(outfile, "version", 0, 0 ); |
300 |
if (args_info->input_given) |
301 |
write_into_file(outfile, "input", args_info->input_orig, 0); |
302 |
if (args_info->output_given) |
303 |
write_into_file(outfile, "output", args_info->output_orig, 0); |
304 |
if (args_info->sele1_given) |
305 |
write_into_file(outfile, "sele1", args_info->sele1_orig, 0); |
306 |
if (args_info->sele2_given) |
307 |
write_into_file(outfile, "sele2", args_info->sele2_orig, 0); |
308 |
if (args_info->order_given) |
309 |
write_into_file(outfile, "order", args_info->order_orig, 0); |
310 |
if (args_info->nzbins_given) |
311 |
write_into_file(outfile, "nzbins", args_info->nzbins_orig, 0); |
312 |
if (args_info->memory_given) |
313 |
write_into_file(outfile, "memory", args_info->memory_orig, 0); |
314 |
if (args_info->selecorr_given) |
315 |
write_into_file(outfile, "selecorr", 0, 0 ); |
316 |
if (args_info->rcorr_given) |
317 |
write_into_file(outfile, "rcorr", 0, 0 ); |
318 |
if (args_info->vcorr_given) |
319 |
write_into_file(outfile, "vcorr", 0, 0 ); |
320 |
if (args_info->dcorr_given) |
321 |
write_into_file(outfile, "dcorr", 0, 0 ); |
322 |
if (args_info->lcorr_given) |
323 |
write_into_file(outfile, "lcorr", 0, 0 ); |
324 |
if (args_info->lcorrZ_given) |
325 |
write_into_file(outfile, "lcorrZ", 0, 0 ); |
326 |
if (args_info->cohZ_given) |
327 |
write_into_file(outfile, "cohZ", 0, 0 ); |
328 |
if (args_info->sdcorr_given) |
329 |
write_into_file(outfile, "sdcorr", 0, 0 ); |
330 |
if (args_info->r_rcorr_given) |
331 |
write_into_file(outfile, "r_rcorr", 0, 0 ); |
332 |
if (args_info->thetacorr_given) |
333 |
write_into_file(outfile, "thetacorr", 0, 0 ); |
334 |
if (args_info->drcorr_given) |
335 |
write_into_file(outfile, "drcorr", 0, 0 ); |
336 |
if (args_info->helfandEcorr_given) |
337 |
write_into_file(outfile, "helfandEcorr", 0, 0 ); |
338 |
if (args_info->momentum_given) |
339 |
write_into_file(outfile, "momentum", 0, 0 ); |
340 |
if (args_info->stresscorr_given) |
341 |
write_into_file(outfile, "stresscorr", 0, 0 ); |
342 |
if (args_info->bondcorr_given) |
343 |
write_into_file(outfile, "bondcorr", 0, 0 ); |
344 |
|
345 |
|
346 |
i = EXIT_SUCCESS; |
347 |
return i; |
348 |
} |
349 |
|
350 |
int |
351 |
cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) |
352 |
{ |
353 |
FILE *outfile; |
354 |
int i = 0; |
355 |
|
356 |
outfile = fopen(filename, "w"); |
357 |
|
358 |
if (!outfile) |
359 |
{ |
360 |
fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); |
361 |
return EXIT_FAILURE; |
362 |
} |
363 |
|
364 |
i = cmdline_parser_dump(outfile, args_info); |
365 |
fclose (outfile); |
366 |
|
367 |
return i; |
368 |
} |
369 |
|
370 |
void |
371 |
cmdline_parser_free (struct gengetopt_args_info *args_info) |
372 |
{ |
373 |
cmdline_parser_release (args_info); |
374 |
} |
375 |
|
376 |
/** @brief replacement of strdup, which is not standard */ |
377 |
char * |
378 |
gengetopt_strdup (const char *s) |
379 |
{ |
380 |
char *result = 0; |
381 |
if (!s) |
382 |
return result; |
383 |
|
384 |
result = (char*)malloc(strlen(s) + 1); |
385 |
if (result == (char*)0) |
386 |
return (char*)0; |
387 |
strcpy(result, s); |
388 |
return result; |
389 |
} |
390 |
|
391 |
static void |
392 |
reset_group_dynamicProps(struct gengetopt_args_info *args_info) |
393 |
{ |
394 |
if (! args_info->dynamicProps_group_counter) |
395 |
return; |
396 |
|
397 |
args_info->selecorr_given = 0 ; |
398 |
args_info->rcorr_given = 0 ; |
399 |
args_info->vcorr_given = 0 ; |
400 |
args_info->dcorr_given = 0 ; |
401 |
args_info->lcorr_given = 0 ; |
402 |
args_info->lcorrZ_given = 0 ; |
403 |
args_info->cohZ_given = 0 ; |
404 |
args_info->sdcorr_given = 0 ; |
405 |
args_info->r_rcorr_given = 0 ; |
406 |
args_info->thetacorr_given = 0 ; |
407 |
args_info->drcorr_given = 0 ; |
408 |
args_info->helfandEcorr_given = 0 ; |
409 |
args_info->momentum_given = 0 ; |
410 |
args_info->stresscorr_given = 0 ; |
411 |
args_info->bondcorr_given = 0 ; |
412 |
|
413 |
args_info->dynamicProps_group_counter = 0; |
414 |
} |
415 |
|
416 |
int |
417 |
cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) |
418 |
{ |
419 |
return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); |
420 |
} |
421 |
|
422 |
int |
423 |
cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, |
424 |
struct cmdline_parser_params *params) |
425 |
{ |
426 |
int result; |
427 |
result = cmdline_parser_internal (argc, argv, args_info, params, 0); |
428 |
|
429 |
if (result == EXIT_FAILURE) |
430 |
{ |
431 |
cmdline_parser_free (args_info); |
432 |
exit (EXIT_FAILURE); |
433 |
} |
434 |
|
435 |
return result; |
436 |
} |
437 |
|
438 |
int |
439 |
cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) |
440 |
{ |
441 |
int result; |
442 |
struct cmdline_parser_params params; |
443 |
|
444 |
params.override = override; |
445 |
params.initialize = initialize; |
446 |
params.check_required = check_required; |
447 |
params.check_ambiguity = 0; |
448 |
params.print_errors = 1; |
449 |
|
450 |
result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); |
451 |
|
452 |
if (result == EXIT_FAILURE) |
453 |
{ |
454 |
cmdline_parser_free (args_info); |
455 |
exit (EXIT_FAILURE); |
456 |
} |
457 |
|
458 |
return result; |
459 |
} |
460 |
|
461 |
int |
462 |
cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) |
463 |
{ |
464 |
int result = EXIT_SUCCESS; |
465 |
|
466 |
if (cmdline_parser_required2(args_info, prog_name, 0) > 0) |
467 |
result = EXIT_FAILURE; |
468 |
|
469 |
if (result == EXIT_FAILURE) |
470 |
{ |
471 |
cmdline_parser_free (args_info); |
472 |
exit (EXIT_FAILURE); |
473 |
} |
474 |
|
475 |
return result; |
476 |
} |
477 |
|
478 |
int |
479 |
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) |
480 |
{ |
481 |
int error = 0; |
482 |
FIX_UNUSED (additional_error); |
483 |
|
484 |
/* checks for required options */ |
485 |
if (! args_info->input_given) |
486 |
{ |
487 |
fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); |
488 |
error = 1; |
489 |
} |
490 |
|
491 |
if (args_info->dynamicProps_group_counter == 0) |
492 |
{ |
493 |
fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required%s.\n", prog_name, args_info->dynamicProps_group_counter, (additional_error ? additional_error : "")); |
494 |
error = 1; |
495 |
} |
496 |
|
497 |
|
498 |
/* checks for dependences among options */ |
499 |
|
500 |
return error; |
501 |
} |
502 |
|
503 |
|
504 |
static char *package_name = 0; |
505 |
|
506 |
/** |
507 |
* @brief updates an option |
508 |
* @param field the generic pointer to the field to update |
509 |
* @param orig_field the pointer to the orig field |
510 |
* @param field_given the pointer to the number of occurrence of this option |
511 |
* @param prev_given the pointer to the number of occurrence already seen |
512 |
* @param value the argument for this option (if null no arg was specified) |
513 |
* @param possible_values the possible values for this option (if specified) |
514 |
* @param default_value the default value (in case the option only accepts fixed values) |
515 |
* @param arg_type the type of this option |
516 |
* @param check_ambiguity @see cmdline_parser_params.check_ambiguity |
517 |
* @param override @see cmdline_parser_params.override |
518 |
* @param no_free whether to free a possible previous value |
519 |
* @param multiple_option whether this is a multiple option |
520 |
* @param long_opt the corresponding long option |
521 |
* @param short_opt the corresponding short option (or '-' if none) |
522 |
* @param additional_error possible further error specification |
523 |
*/ |
524 |
static |
525 |
int update_arg(void *field, char **orig_field, |
526 |
unsigned int *field_given, unsigned int *prev_given, |
527 |
char *value, const char *possible_values[], |
528 |
const char *default_value, |
529 |
cmdline_parser_arg_type arg_type, |
530 |
int check_ambiguity, int override, |
531 |
int no_free, int multiple_option, |
532 |
const char *long_opt, char short_opt, |
533 |
const char *additional_error) |
534 |
{ |
535 |
char *stop_char = 0; |
536 |
const char *val = value; |
537 |
int found; |
538 |
char **string_field; |
539 |
FIX_UNUSED (field); |
540 |
|
541 |
stop_char = 0; |
542 |
found = 0; |
543 |
|
544 |
if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) |
545 |
{ |
546 |
if (short_opt != '-') |
547 |
fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", |
548 |
package_name, long_opt, short_opt, |
549 |
(additional_error ? additional_error : "")); |
550 |
else |
551 |
fprintf (stderr, "%s: `--%s' option given more than once%s\n", |
552 |
package_name, long_opt, |
553 |
(additional_error ? additional_error : "")); |
554 |
return 1; /* failure */ |
555 |
} |
556 |
|
557 |
FIX_UNUSED (default_value); |
558 |
|
559 |
if (field_given && *field_given && ! override) |
560 |
return 0; |
561 |
if (prev_given) |
562 |
(*prev_given)++; |
563 |
if (field_given) |
564 |
(*field_given)++; |
565 |
if (possible_values) |
566 |
val = possible_values[found]; |
567 |
|
568 |
switch(arg_type) { |
569 |
case ARG_INT: |
570 |
if (val) *((int *)field) = strtol (val, &stop_char, 0); |
571 |
break; |
572 |
case ARG_STRING: |
573 |
if (val) { |
574 |
string_field = (char **)field; |
575 |
if (!no_free && *string_field) |
576 |
free (*string_field); /* free previous string */ |
577 |
*string_field = gengetopt_strdup (val); |
578 |
} |
579 |
break; |
580 |
default: |
581 |
break; |
582 |
}; |
583 |
|
584 |
/* check numeric conversion */ |
585 |
switch(arg_type) { |
586 |
case ARG_INT: |
587 |
if (val && !(stop_char && *stop_char == '\0')) { |
588 |
fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); |
589 |
return 1; /* failure */ |
590 |
} |
591 |
break; |
592 |
default: |
593 |
; |
594 |
}; |
595 |
|
596 |
/* store the original value */ |
597 |
switch(arg_type) { |
598 |
case ARG_NO: |
599 |
break; |
600 |
default: |
601 |
if (value && orig_field) { |
602 |
if (no_free) { |
603 |
*orig_field = value; |
604 |
} else { |
605 |
if (*orig_field) |
606 |
free (*orig_field); /* free previous string */ |
607 |
*orig_field = gengetopt_strdup (value); |
608 |
} |
609 |
} |
610 |
}; |
611 |
|
612 |
return 0; /* OK */ |
613 |
} |
614 |
|
615 |
|
616 |
int |
617 |
cmdline_parser_internal ( |
618 |
int argc, char **argv, struct gengetopt_args_info *args_info, |
619 |
struct cmdline_parser_params *params, const char *additional_error) |
620 |
{ |
621 |
int c; /* Character of the parsed option. */ |
622 |
|
623 |
int error = 0; |
624 |
struct gengetopt_args_info local_args_info; |
625 |
|
626 |
int override; |
627 |
int initialize; |
628 |
int check_required; |
629 |
int check_ambiguity; |
630 |
|
631 |
package_name = argv[0]; |
632 |
|
633 |
override = params->override; |
634 |
initialize = params->initialize; |
635 |
check_required = params->check_required; |
636 |
check_ambiguity = params->check_ambiguity; |
637 |
|
638 |
if (initialize) |
639 |
cmdline_parser_init (args_info); |
640 |
|
641 |
cmdline_parser_init (&local_args_info); |
642 |
|
643 |
optarg = 0; |
644 |
optind = 0; |
645 |
opterr = params->print_errors; |
646 |
optopt = '?'; |
647 |
|
648 |
while (1) |
649 |
{ |
650 |
int option_index = 0; |
651 |
|
652 |
static struct option long_options[] = { |
653 |
{ "help", 0, NULL, 'h' }, |
654 |
{ "version", 0, NULL, 'V' }, |
655 |
{ "input", 1, NULL, 'i' }, |
656 |
{ "output", 1, NULL, 'o' }, |
657 |
{ "sele1", 1, NULL, 0 }, |
658 |
{ "sele2", 1, NULL, 0 }, |
659 |
{ "order", 1, NULL, 0 }, |
660 |
{ "nzbins", 1, NULL, 'z' }, |
661 |
{ "memory", 1, NULL, 'm' }, |
662 |
{ "selecorr", 0, NULL, 's' }, |
663 |
{ "rcorr", 0, NULL, 'r' }, |
664 |
{ "vcorr", 0, NULL, 'v' }, |
665 |
{ "dcorr", 0, NULL, 'd' }, |
666 |
{ "lcorr", 0, NULL, 'l' }, |
667 |
{ "lcorrZ", 0, NULL, 0 }, |
668 |
{ "cohZ", 0, NULL, 0 }, |
669 |
{ "sdcorr", 0, NULL, 'M' }, |
670 |
{ "r_rcorr", 0, NULL, 0 }, |
671 |
{ "thetacorr", 0, NULL, 0 }, |
672 |
{ "drcorr", 0, NULL, 0 }, |
673 |
{ "helfandEcorr", 0, NULL, 0 }, |
674 |
{ "momentum", 0, NULL, 'p' }, |
675 |
{ "stresscorr", 0, NULL, 0 }, |
676 |
{ "bondcorr", 0, NULL, 'b' }, |
677 |
{ 0, 0, 0, 0 } |
678 |
}; |
679 |
|
680 |
c = getopt_long (argc, argv, "hVi:o:z:m:srvdlMpb", long_options, &option_index); |
681 |
|
682 |
if (c == -1) break; /* Exit from `while (1)' loop. */ |
683 |
|
684 |
switch (c) |
685 |
{ |
686 |
case 'h': /* Print help and exit. */ |
687 |
cmdline_parser_print_help (); |
688 |
cmdline_parser_free (&local_args_info); |
689 |
exit (EXIT_SUCCESS); |
690 |
|
691 |
case 'V': /* Print version and exit. */ |
692 |
cmdline_parser_print_version (); |
693 |
cmdline_parser_free (&local_args_info); |
694 |
exit (EXIT_SUCCESS); |
695 |
|
696 |
case 'i': /* input dump file. */ |
697 |
|
698 |
|
699 |
if (update_arg( (void *)&(args_info->input_arg), |
700 |
&(args_info->input_orig), &(args_info->input_given), |
701 |
&(local_args_info.input_given), optarg, 0, 0, ARG_STRING, |
702 |
check_ambiguity, override, 0, 0, |
703 |
"input", 'i', |
704 |
additional_error)) |
705 |
goto failure; |
706 |
|
707 |
break; |
708 |
case 'o': /* output file name. */ |
709 |
|
710 |
|
711 |
if (update_arg( (void *)&(args_info->output_arg), |
712 |
&(args_info->output_orig), &(args_info->output_given), |
713 |
&(local_args_info.output_given), optarg, 0, 0, ARG_STRING, |
714 |
check_ambiguity, override, 0, 0, |
715 |
"output", 'o', |
716 |
additional_error)) |
717 |
goto failure; |
718 |
|
719 |
break; |
720 |
case 'z': /* Number of Z bins. */ |
721 |
|
722 |
|
723 |
if (update_arg( (void *)&(args_info->nzbins_arg), |
724 |
&(args_info->nzbins_orig), &(args_info->nzbins_given), |
725 |
&(local_args_info.nzbins_given), optarg, 0, "100", ARG_INT, |
726 |
check_ambiguity, override, 0, 0, |
727 |
"nzbins", 'z', |
728 |
additional_error)) |
729 |
goto failure; |
730 |
|
731 |
break; |
732 |
case 'm': /* Available memory (defaults to 2G). */ |
733 |
|
734 |
|
735 |
if (update_arg( (void *)&(args_info->memory_arg), |
736 |
&(args_info->memory_orig), &(args_info->memory_given), |
737 |
&(local_args_info.memory_given), optarg, 0, "2G", ARG_STRING, |
738 |
check_ambiguity, override, 0, 0, |
739 |
"memory", 'm', |
740 |
additional_error)) |
741 |
goto failure; |
742 |
|
743 |
break; |
744 |
case 's': /* selection correlation function. */ |
745 |
|
746 |
if (args_info->dynamicProps_group_counter && override) |
747 |
reset_group_dynamicProps (args_info); |
748 |
args_info->dynamicProps_group_counter += 1; |
749 |
|
750 |
if (update_arg( 0 , |
751 |
0 , &(args_info->selecorr_given), |
752 |
&(local_args_info.selecorr_given), optarg, 0, 0, ARG_NO, |
753 |
check_ambiguity, override, 0, 0, |
754 |
"selecorr", 's', |
755 |
additional_error)) |
756 |
goto failure; |
757 |
|
758 |
break; |
759 |
case 'r': /* rmsd. */ |
760 |
|
761 |
if (args_info->dynamicProps_group_counter && override) |
762 |
reset_group_dynamicProps (args_info); |
763 |
args_info->dynamicProps_group_counter += 1; |
764 |
|
765 |
if (update_arg( 0 , |
766 |
0 , &(args_info->rcorr_given), |
767 |
&(local_args_info.rcorr_given), optarg, 0, 0, ARG_NO, |
768 |
check_ambiguity, override, 0, 0, |
769 |
"rcorr", 'r', |
770 |
additional_error)) |
771 |
goto failure; |
772 |
|
773 |
break; |
774 |
case 'v': /* velocity correlation function. */ |
775 |
|
776 |
if (args_info->dynamicProps_group_counter && override) |
777 |
reset_group_dynamicProps (args_info); |
778 |
args_info->dynamicProps_group_counter += 1; |
779 |
|
780 |
if (update_arg( 0 , |
781 |
0 , &(args_info->vcorr_given), |
782 |
&(local_args_info.vcorr_given), optarg, 0, 0, ARG_NO, |
783 |
check_ambiguity, override, 0, 0, |
784 |
"vcorr", 'v', |
785 |
additional_error)) |
786 |
goto failure; |
787 |
|
788 |
break; |
789 |
case 'd': /* dipole correlation function. */ |
790 |
|
791 |
if (args_info->dynamicProps_group_counter && override) |
792 |
reset_group_dynamicProps (args_info); |
793 |
args_info->dynamicProps_group_counter += 1; |
794 |
|
795 |
if (update_arg( 0 , |
796 |
0 , &(args_info->dcorr_given), |
797 |
&(local_args_info.dcorr_given), optarg, 0, 0, ARG_NO, |
798 |
check_ambiguity, override, 0, 0, |
799 |
"dcorr", 'd', |
800 |
additional_error)) |
801 |
goto failure; |
802 |
|
803 |
break; |
804 |
case 'l': /* Lengendre correlation function. */ |
805 |
|
806 |
if (args_info->dynamicProps_group_counter && override) |
807 |
reset_group_dynamicProps (args_info); |
808 |
args_info->dynamicProps_group_counter += 1; |
809 |
|
810 |
if (update_arg( 0 , |
811 |
0 , &(args_info->lcorr_given), |
812 |
&(local_args_info.lcorr_given), optarg, 0, 0, ARG_NO, |
813 |
check_ambiguity, override, 0, 0, |
814 |
"lcorr", 'l', |
815 |
additional_error)) |
816 |
goto failure; |
817 |
|
818 |
break; |
819 |
case 'M': /* System dipole correlation function. */ |
820 |
|
821 |
if (args_info->dynamicProps_group_counter && override) |
822 |
reset_group_dynamicProps (args_info); |
823 |
args_info->dynamicProps_group_counter += 1; |
824 |
|
825 |
if (update_arg( 0 , |
826 |
0 , &(args_info->sdcorr_given), |
827 |
&(local_args_info.sdcorr_given), optarg, 0, 0, ARG_NO, |
828 |
check_ambiguity, override, 0, 0, |
829 |
"sdcorr", 'M', |
830 |
additional_error)) |
831 |
goto failure; |
832 |
|
833 |
break; |
834 |
case 'p': /* Helfand momentum for viscosity. */ |
835 |
|
836 |
if (args_info->dynamicProps_group_counter && override) |
837 |
reset_group_dynamicProps (args_info); |
838 |
args_info->dynamicProps_group_counter += 1; |
839 |
|
840 |
if (update_arg( 0 , |
841 |
0 , &(args_info->momentum_given), |
842 |
&(local_args_info.momentum_given), optarg, 0, 0, ARG_NO, |
843 |
check_ambiguity, override, 0, 0, |
844 |
"momentum", 'p', |
845 |
additional_error)) |
846 |
goto failure; |
847 |
|
848 |
break; |
849 |
case 'b': /* Bond extension correlation function. */ |
850 |
|
851 |
if (args_info->dynamicProps_group_counter && override) |
852 |
reset_group_dynamicProps (args_info); |
853 |
args_info->dynamicProps_group_counter += 1; |
854 |
|
855 |
if (update_arg( 0 , |
856 |
0 , &(args_info->bondcorr_given), |
857 |
&(local_args_info.bondcorr_given), optarg, 0, 0, ARG_NO, |
858 |
check_ambiguity, override, 0, 0, |
859 |
"bondcorr", 'b', |
860 |
additional_error)) |
861 |
goto failure; |
862 |
|
863 |
break; |
864 |
|
865 |
case 0: /* Long option with no short option */ |
866 |
/* select first stuntdouble set. */ |
867 |
if (strcmp (long_options[option_index].name, "sele1") == 0) |
868 |
{ |
869 |
|
870 |
|
871 |
if (update_arg( (void *)&(args_info->sele1_arg), |
872 |
&(args_info->sele1_orig), &(args_info->sele1_given), |
873 |
&(local_args_info.sele1_given), optarg, 0, 0, ARG_STRING, |
874 |
check_ambiguity, override, 0, 0, |
875 |
"sele1", '-', |
876 |
additional_error)) |
877 |
goto failure; |
878 |
|
879 |
} |
880 |
/* select second stuntdouble set (if sele2 is not set, use script from sele1). */ |
881 |
else if (strcmp (long_options[option_index].name, "sele2") == 0) |
882 |
{ |
883 |
|
884 |
|
885 |
if (update_arg( (void *)&(args_info->sele2_arg), |
886 |
&(args_info->sele2_orig), &(args_info->sele2_given), |
887 |
&(local_args_info.sele2_given), optarg, 0, 0, ARG_STRING, |
888 |
check_ambiguity, override, 0, 0, |
889 |
"sele2", '-', |
890 |
additional_error)) |
891 |
goto failure; |
892 |
|
893 |
} |
894 |
/* Lengendre Polynomial Order. */ |
895 |
else if (strcmp (long_options[option_index].name, "order") == 0) |
896 |
{ |
897 |
|
898 |
|
899 |
if (update_arg( (void *)&(args_info->order_arg), |
900 |
&(args_info->order_orig), &(args_info->order_given), |
901 |
&(local_args_info.order_given), optarg, 0, 0, ARG_INT, |
902 |
check_ambiguity, override, 0, 0, |
903 |
"order", '-', |
904 |
additional_error)) |
905 |
goto failure; |
906 |
|
907 |
} |
908 |
/* Lengendre correlation function binned by Z. */ |
909 |
else if (strcmp (long_options[option_index].name, "lcorrZ") == 0) |
910 |
{ |
911 |
|
912 |
if (args_info->dynamicProps_group_counter && override) |
913 |
reset_group_dynamicProps (args_info); |
914 |
args_info->dynamicProps_group_counter += 1; |
915 |
|
916 |
if (update_arg( 0 , |
917 |
0 , &(args_info->lcorrZ_given), |
918 |
&(local_args_info.lcorrZ_given), optarg, 0, 0, ARG_NO, |
919 |
check_ambiguity, override, 0, 0, |
920 |
"lcorrZ", '-', |
921 |
additional_error)) |
922 |
goto failure; |
923 |
|
924 |
} |
925 |
/* Lengendre correlation function for OH bond vectors binned by Z. */ |
926 |
else if (strcmp (long_options[option_index].name, "cohZ") == 0) |
927 |
{ |
928 |
|
929 |
if (args_info->dynamicProps_group_counter && override) |
930 |
reset_group_dynamicProps (args_info); |
931 |
args_info->dynamicProps_group_counter += 1; |
932 |
|
933 |
if (update_arg( 0 , |
934 |
0 , &(args_info->cohZ_given), |
935 |
&(local_args_info.cohZ_given), optarg, 0, 0, ARG_NO, |
936 |
check_ambiguity, override, 0, 0, |
937 |
"cohZ", '-', |
938 |
additional_error)) |
939 |
goto failure; |
940 |
|
941 |
} |
942 |
/* Radial rmsd. */ |
943 |
else if (strcmp (long_options[option_index].name, "r_rcorr") == 0) |
944 |
{ |
945 |
|
946 |
if (args_info->dynamicProps_group_counter && override) |
947 |
reset_group_dynamicProps (args_info); |
948 |
args_info->dynamicProps_group_counter += 1; |
949 |
|
950 |
if (update_arg( 0 , |
951 |
0 , &(args_info->r_rcorr_given), |
952 |
&(local_args_info.r_rcorr_given), optarg, 0, 0, ARG_NO, |
953 |
check_ambiguity, override, 0, 0, |
954 |
"r_rcorr", '-', |
955 |
additional_error)) |
956 |
goto failure; |
957 |
|
958 |
} |
959 |
/* Angular rmsd. */ |
960 |
else if (strcmp (long_options[option_index].name, "thetacorr") == 0) |
961 |
{ |
962 |
|
963 |
if (args_info->dynamicProps_group_counter && override) |
964 |
reset_group_dynamicProps (args_info); |
965 |
args_info->dynamicProps_group_counter += 1; |
966 |
|
967 |
if (update_arg( 0 , |
968 |
0 , &(args_info->thetacorr_given), |
969 |
&(local_args_info.thetacorr_given), optarg, 0, 0, ARG_NO, |
970 |
check_ambiguity, override, 0, 0, |
971 |
"thetacorr", '-', |
972 |
additional_error)) |
973 |
goto failure; |
974 |
|
975 |
} |
976 |
/* Directional rmsd for particles with unit vectors. */ |
977 |
else if (strcmp (long_options[option_index].name, "drcorr") == 0) |
978 |
{ |
979 |
|
980 |
if (args_info->dynamicProps_group_counter && override) |
981 |
reset_group_dynamicProps (args_info); |
982 |
args_info->dynamicProps_group_counter += 1; |
983 |
|
984 |
if (update_arg( 0 , |
985 |
0 , &(args_info->drcorr_given), |
986 |
&(local_args_info.drcorr_given), optarg, 0, 0, ARG_NO, |
987 |
check_ambiguity, override, 0, 0, |
988 |
"drcorr", '-', |
989 |
additional_error)) |
990 |
goto failure; |
991 |
|
992 |
} |
993 |
/* Helfand moment for thermal conductvity. */ |
994 |
else if (strcmp (long_options[option_index].name, "helfandEcorr") == 0) |
995 |
{ |
996 |
|
997 |
if (args_info->dynamicProps_group_counter && override) |
998 |
reset_group_dynamicProps (args_info); |
999 |
args_info->dynamicProps_group_counter += 1; |
1000 |
|
1001 |
if (update_arg( 0 , |
1002 |
0 , &(args_info->helfandEcorr_given), |
1003 |
&(local_args_info.helfandEcorr_given), optarg, 0, 0, ARG_NO, |
1004 |
check_ambiguity, override, 0, 0, |
1005 |
"helfandEcorr", '-', |
1006 |
additional_error)) |
1007 |
goto failure; |
1008 |
|
1009 |
} |
1010 |
/* Stress tensor correlation function. */ |
1011 |
else if (strcmp (long_options[option_index].name, "stresscorr") == 0) |
1012 |
{ |
1013 |
|
1014 |
if (args_info->dynamicProps_group_counter && override) |
1015 |
reset_group_dynamicProps (args_info); |
1016 |
args_info->dynamicProps_group_counter += 1; |
1017 |
|
1018 |
if (update_arg( 0 , |
1019 |
0 , &(args_info->stresscorr_given), |
1020 |
&(local_args_info.stresscorr_given), optarg, 0, 0, ARG_NO, |
1021 |
check_ambiguity, override, 0, 0, |
1022 |
"stresscorr", '-', |
1023 |
additional_error)) |
1024 |
goto failure; |
1025 |
|
1026 |
} |
1027 |
|
1028 |
break; |
1029 |
case '?': /* Invalid option. */ |
1030 |
/* `getopt_long' already printed an error message. */ |
1031 |
goto failure; |
1032 |
|
1033 |
default: /* bug: option not considered. */ |
1034 |
fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); |
1035 |
abort (); |
1036 |
} /* switch */ |
1037 |
} /* while */ |
1038 |
|
1039 |
if (args_info->dynamicProps_group_counter > 1) |
1040 |
{ |
1041 |
fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required%s.\n", argv[0], args_info->dynamicProps_group_counter, (additional_error ? additional_error : "")); |
1042 |
error = 1; |
1043 |
} |
1044 |
|
1045 |
|
1046 |
|
1047 |
if (check_required) |
1048 |
{ |
1049 |
error += cmdline_parser_required2 (args_info, argv[0], additional_error); |
1050 |
} |
1051 |
|
1052 |
cmdline_parser_release (&local_args_info); |
1053 |
|
1054 |
if ( error ) |
1055 |
return (EXIT_FAILURE); |
1056 |
|
1057 |
if (optind < argc) |
1058 |
{ |
1059 |
int i = 0 ; |
1060 |
int found_prog_name = 0; |
1061 |
/* whether program name, i.e., argv[0], is in the remaining args |
1062 |
(this may happen with some implementations of getopt, |
1063 |
but surely not with the one included by gengetopt) */ |
1064 |
|
1065 |
i = optind; |
1066 |
while (i < argc) |
1067 |
if (argv[i++] == argv[0]) { |
1068 |
found_prog_name = 1; |
1069 |
break; |
1070 |
} |
1071 |
i = 0; |
1072 |
|
1073 |
args_info->inputs_num = argc - optind - found_prog_name; |
1074 |
args_info->inputs = |
1075 |
(char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; |
1076 |
while (optind < argc) |
1077 |
if (argv[optind++] != argv[0]) |
1078 |
args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ; |
1079 |
} |
1080 |
|
1081 |
return 0; |
1082 |
|
1083 |
failure: |
1084 |
|
1085 |
cmdline_parser_release (&local_args_info); |
1086 |
return (EXIT_FAILURE); |
1087 |
} |