ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/dynamicProps/DynamicPropsCmd.cpp
Revision: 2003
Committed: Sun Jun 1 19:28:44 2014 UTC (10 years, 11 months ago) by gezelter
File size: 35606 byte(s)
Log Message:
Added Frequency Fluctuation Correlation Function

File Contents

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

Properties

Name Value
svn:keywords Author Id Revision Date