ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/dynamicProps/DynamicPropsCmd.cpp
Revision: 1939
Committed: Thu Oct 31 18:18:57 2013 UTC (11 years, 6 months ago) by gezelter
File size: 33786 byte(s)
Log Message:
Some fixes for MSVC compilation

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

Properties

Name Value
svn:keywords Author Id Revision Date