ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/dynamicProps/DynamicPropsCmd.cpp
Revision: 1953
Committed: Thu Dec 5 18:19:26 2013 UTC (11 years, 4 months ago) by gezelter
File size: 34671 byte(s)
Log Message:
Rewrote much of selection module, added a bond 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 1629 0
65     };
66    
67     typedef enum {ARG_NO
68     , ARG_STRING
69     , ARG_INT
70     } cmdline_parser_arg_type;
71    
72 chuckv 1098 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 gezelter 1629 cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
79     struct cmdline_parser_params *params, const char *additional_error);
80 chuckv 1098
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 gezelter 1915 args_info->nzbins_given = 0 ;
98 gezelter 1629 args_info->memory_given = 0 ;
99 gezelter 1811 args_info->selecorr_given = 0 ;
100 chuckv 1098 args_info->rcorr_given = 0 ;
101     args_info->vcorr_given = 0 ;
102     args_info->dcorr_given = 0 ;
103     args_info->lcorr_given = 0 ;
104 gezelter 1915 args_info->lcorrZ_given = 0 ;
105 gezelter 1934 args_info->cohZ_given = 0 ;
106 gezelter 1629 args_info->sdcorr_given = 0 ;
107 chuckv 1098 args_info->r_rcorr_given = 0 ;
108 chuckv 1112 args_info->thetacorr_given = 0 ;
109 xsun 1183 args_info->drcorr_given = 0 ;
110 chuckv 1245 args_info->helfandEcorr_given = 0 ;
111 gezelter 1629 args_info->momentum_given = 0 ;
112     args_info->stresscorr_given = 0 ;
113 gezelter 1953 args_info->bondcorr_given = 0 ;
114 chuckv 1098 args_info->dynamicProps_group_counter = 0 ;
115     }
116    
117     static
118     void clear_args (struct gengetopt_args_info *args_info)
119     {
120 gezelter 1629 FIX_UNUSED (args_info);
121 chuckv 1098 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 gezelter 1915 args_info->nzbins_arg = 100;
131     args_info->nzbins_orig = NULL;
132 gezelter 1629 args_info->memory_arg = gengetopt_strdup ("2G");
133     args_info->memory_orig = NULL;
134 chuckv 1098
135     }
136    
137 gezelter 1629 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 gezelter 1915 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 gezelter 1934 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 gezelter 1953 args_info->bondcorr_help = gengetopt_args_info_help[24] ;
166 gezelter 1629
167     }
168    
169 tim 320 void
170     cmdline_parser_print_version (void)
171     {
172 gezelter 1629 printf ("%s %s\n",
173     (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
174     CMDLINE_PARSER_VERSION);
175 tim 320 }
176    
177 gezelter 1629 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 tim 320 void
193     cmdline_parser_print_help (void)
194     {
195 gezelter 1629 int i = 0;
196     print_help_common();
197     while (gengetopt_args_info_help[i])
198     printf("%s\n", gengetopt_args_info_help[i++]);
199 tim 320 }
200    
201 chuckv 1098 void
202     cmdline_parser_init (struct gengetopt_args_info *args_info)
203     {
204     clear_given (args_info);
205     clear_args (args_info);
206 gezelter 1629 init_args_info (args_info);
207    
208     args_info->inputs = 0;
209     args_info->inputs_num = 0;
210 chuckv 1098 }
211 tim 320
212 gezelter 1629 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 chuckv 1098 static void
235 gezelter 1629 free_string_field (char **s)
236     {
237     if (*s)
238     {
239     free (*s);
240     *s = 0;
241     }
242     }
243    
244    
245     static void
246 chuckv 1098 cmdline_parser_release (struct gengetopt_args_info *args_info)
247     {
248 gezelter 1629 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 gezelter 1915 free_string_field (&(args_info->nzbins_orig));
259 gezelter 1629 free_string_field (&(args_info->memory_arg));
260     free_string_field (&(args_info->memory_orig));
261 chuckv 1098
262 gezelter 1629
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 chuckv 1098 {
292 gezelter 1629 fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
293     return EXIT_FAILURE;
294 chuckv 1098 }
295 gezelter 1629
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 gezelter 1915 if (args_info->nzbins_given)
311     write_into_file(outfile, "nzbins", args_info->nzbins_orig, 0);
312 gezelter 1629 if (args_info->memory_given)
313     write_into_file(outfile, "memory", args_info->memory_orig, 0);
314 gezelter 1811 if (args_info->selecorr_given)
315     write_into_file(outfile, "selecorr", 0, 0 );
316 gezelter 1629 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 gezelter 1915 if (args_info->lcorrZ_given)
325     write_into_file(outfile, "lcorrZ", 0, 0 );
326 gezelter 1934 if (args_info->cohZ_given)
327     write_into_file(outfile, "cohZ", 0, 0 );
328 gezelter 1629 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 gezelter 1953 if (args_info->bondcorr_given)
343     write_into_file(outfile, "bondcorr", 0, 0 );
344 chuckv 1098
345 gezelter 1629
346     i = EXIT_SUCCESS;
347     return i;
348 chuckv 1098 }
349 tim 320
350 chuckv 1098 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 gezelter 1629 i = cmdline_parser_dump(outfile, args_info);
365 chuckv 1098 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 gezelter 1629 /** @brief replacement of strdup, which is not standard */
377 tim 320 char *
378     gengetopt_strdup (const char *s)
379     {
380 gezelter 1629 char *result = 0;
381 chuckv 1098 if (!s)
382     return result;
383    
384     result = (char*)malloc(strlen(s) + 1);
385 tim 320 if (result == (char*)0)
386     return (char*)0;
387     strcpy(result, s);
388     return result;
389     }
390    
391 chuckv 1098 static void
392     reset_group_dynamicProps(struct gengetopt_args_info *args_info)
393 tim 320 {
394 chuckv 1098 if (! args_info->dynamicProps_group_counter)
395     return;
396 tim 320
397 gezelter 1811 args_info->selecorr_given = 0 ;
398 tim 320 args_info->rcorr_given = 0 ;
399     args_info->vcorr_given = 0 ;
400     args_info->dcorr_given = 0 ;
401 tim 876 args_info->lcorr_given = 0 ;
402 gezelter 1915 args_info->lcorrZ_given = 0 ;
403 gezelter 1934 args_info->cohZ_given = 0 ;
404 gezelter 1629 args_info->sdcorr_given = 0 ;
405 chuckv 1098 args_info->r_rcorr_given = 0 ;
406 chuckv 1112 args_info->thetacorr_given = 0 ;
407 xsun 1183 args_info->drcorr_given = 0 ;
408 chuckv 1245 args_info->helfandEcorr_given = 0 ;
409 gezelter 1629 args_info->momentum_given = 0 ;
410     args_info->stresscorr_given = 0 ;
411 gezelter 1953 args_info->bondcorr_given = 0 ;
412 chuckv 1098
413     args_info->dynamicProps_group_counter = 0;
414 tim 876 }
415 tim 320
416 chuckv 1098 int
417 gezelter 1629 cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
418 chuckv 1098 {
419     return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
420     }
421 tim 320
422 chuckv 1098 int
423 gezelter 1629 cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
424     struct cmdline_parser_params *params)
425 chuckv 1098 {
426     int result;
427 gezelter 1629 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
428 chuckv 1098
429 gezelter 1629 if (result == EXIT_FAILURE)
430     {
431     cmdline_parser_free (args_info);
432     exit (EXIT_FAILURE);
433     }
434    
435     return result;
436     }
437 chuckv 1098
438 gezelter 1629 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, &params, 0);
451    
452 chuckv 1098 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 gezelter 1629 if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
467 chuckv 1098 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 gezelter 1629 FIX_UNUSED (additional_error);
483 chuckv 1098
484 gezelter 1629 /* checks for required options */
485 chuckv 1098 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 gezelter 1629
491 chuckv 1098 if (args_info->dynamicProps_group_counter == 0)
492     {
493 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 : ""));
494 chuckv 1098 error = 1;
495     }
496    
497    
498 gezelter 1629 /* checks for dependences among options */
499    
500 chuckv 1098 return error;
501     }
502    
503 gezelter 1629
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 chuckv 1098 int
617 gezelter 1629 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 chuckv 1098 {
621     int c; /* Character of the parsed option. */
622    
623     int error = 0;
624     struct gengetopt_args_info local_args_info;
625 gezelter 1629
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 chuckv 1098
638     if (initialize)
639     cmdline_parser_init (args_info);
640    
641     cmdline_parser_init (&local_args_info);
642    
643 tim 320 optarg = 0;
644 gezelter 1629 optind = 0;
645     opterr = params->print_errors;
646 tim 320 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 tim 876 { "order", 1, NULL, 0 },
660 gezelter 1915 { "nzbins", 1, NULL, 'z' },
661 gezelter 1629 { "memory", 1, NULL, 'm' },
662 gezelter 1811 { "selecorr", 0, NULL, 's' },
663 tim 320 { "rcorr", 0, NULL, 'r' },
664     { "vcorr", 0, NULL, 'v' },
665     { "dcorr", 0, NULL, 'd' },
666 tim 876 { "lcorr", 0, NULL, 'l' },
667 gezelter 1915 { "lcorrZ", 0, NULL, 0 },
668 gezelter 1934 { "cohZ", 0, NULL, 0 },
669 gezelter 1811 { "sdcorr", 0, NULL, 'M' },
670 chuckv 1098 { "r_rcorr", 0, NULL, 0 },
671 chuckv 1112 { "thetacorr", 0, NULL, 0 },
672 xsun 1183 { "drcorr", 0, NULL, 0 },
673 chuckv 1245 { "helfandEcorr", 0, NULL, 0 },
674 gezelter 1629 { "momentum", 0, NULL, 'p' },
675     { "stresscorr", 0, NULL, 0 },
676 gezelter 1953 { "bondcorr", 0, NULL, 'b' },
677 gezelter 1629 { 0, 0, 0, 0 }
678 tim 320 };
679    
680 gezelter 1953 c = getopt_long (argc, argv, "hVi:o:z:m:srvdlMpb", long_options, &option_index);
681 tim 320
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 chuckv 1098 cmdline_parser_free (&local_args_info);
689 tim 320 exit (EXIT_SUCCESS);
690    
691     case 'V': /* Print version and exit. */
692     cmdline_parser_print_version ();
693 chuckv 1098 cmdline_parser_free (&local_args_info);
694 tim 320 exit (EXIT_SUCCESS);
695    
696     case 'i': /* input dump file. */
697 gezelter 1629
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 tim 320 break;
708     case 'o': /* output file name. */
709 gezelter 1629
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 tim 320 break;
720 gezelter 1915 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 gezelter 1629 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 gezelter 1811 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 tim 917 case 'r': /* rmsd. */
760 gezelter 1629
761 chuckv 1098 if (args_info->dynamicProps_group_counter && override)
762     reset_group_dynamicProps (args_info);
763     args_info->dynamicProps_group_counter += 1;
764 gezelter 1629
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 chuckv 1098 break;
774 tim 320 case 'v': /* velocity correlation function. */
775 gezelter 1629
776 chuckv 1098 if (args_info->dynamicProps_group_counter && override)
777     reset_group_dynamicProps (args_info);
778     args_info->dynamicProps_group_counter += 1;
779 gezelter 1629
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 chuckv 1098 break;
789 tim 320 case 'd': /* dipole correlation function. */
790 gezelter 1629
791 chuckv 1098 if (args_info->dynamicProps_group_counter && override)
792     reset_group_dynamicProps (args_info);
793     args_info->dynamicProps_group_counter += 1;
794 gezelter 1629
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 chuckv 1098 break;
804 tim 876 case 'l': /* Lengendre correlation function. */
805 gezelter 1629
806 chuckv 1098 if (args_info->dynamicProps_group_counter && override)
807     reset_group_dynamicProps (args_info);
808     args_info->dynamicProps_group_counter += 1;
809 gezelter 1629
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 chuckv 1098 break;
819 gezelter 1811 case 'M': /* System dipole correlation function. */
820 gezelter 1629
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 gezelter 1811 "sdcorr", 'M',
830 gezelter 1629 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 gezelter 1953 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 tim 320
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 tim 876 {
869 gezelter 1629
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 tim 876 }
880 tim 320 /* 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 tim 876 {
883 gezelter 1629
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 tim 876 }
894     /* Lengendre Polynomial Order. */
895     else if (strcmp (long_options[option_index].name, "order") == 0)
896     {
897 gezelter 1629
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 chuckv 1098 }
908 gezelter 1915 /* 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 gezelter 1934 /* 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 chuckv 1098 /* Radial rmsd. */
943     else if (strcmp (long_options[option_index].name, "r_rcorr") == 0)
944     {
945 gezelter 1629
946 chuckv 1098 if (args_info->dynamicProps_group_counter && override)
947     reset_group_dynamicProps (args_info);
948     args_info->dynamicProps_group_counter += 1;
949 gezelter 1629
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 tim 876 }
959 chuckv 1112 /* Angular rmsd. */
960     else if (strcmp (long_options[option_index].name, "thetacorr") == 0)
961     {
962 gezelter 1629
963 chuckv 1112 if (args_info->dynamicProps_group_counter && override)
964     reset_group_dynamicProps (args_info);
965     args_info->dynamicProps_group_counter += 1;
966 gezelter 1629
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 chuckv 1112 }
976 xsun 1183 /* Directional rmsd for particles with unit vectors. */
977     else if (strcmp (long_options[option_index].name, "drcorr") == 0)
978     {
979 gezelter 1629
980 xsun 1183 if (args_info->dynamicProps_group_counter && override)
981     reset_group_dynamicProps (args_info);
982     args_info->dynamicProps_group_counter += 1;
983 gezelter 1629
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 xsun 1183 }
993 chuckv 1245 /* Helfand moment for thermal conductvity. */
994     else if (strcmp (long_options[option_index].name, "helfandEcorr") == 0)
995     {
996 gezelter 1629
997 chuckv 1245 if (args_info->dynamicProps_group_counter && override)
998     reset_group_dynamicProps (args_info);
999     args_info->dynamicProps_group_counter += 1;
1000 gezelter 1629
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 chuckv 1245 }
1010 gezelter 1629 /* Stress tensor correlation function. */
1011     else if (strcmp (long_options[option_index].name, "stresscorr") == 0)
1012     {
1013 tim 876
1014 gezelter 1629 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 chuckv 1098 break;
1029 tim 320 case '?': /* Invalid option. */
1030     /* `getopt_long' already printed an error message. */
1031 chuckv 1098 goto failure;
1032 tim 320
1033     default: /* bug: option not considered. */
1034 chuckv 1098 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1035 tim 320 abort ();
1036     } /* switch */
1037     } /* while */
1038    
1039 chuckv 1098 if (args_info->dynamicProps_group_counter > 1)
1040 tim 320 {
1041 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 : ""));
1042 chuckv 1098 error = 1;
1043 tim 320 }
1044    
1045    
1046 chuckv 1098
1047     if (check_required)
1048 tim 320 {
1049 chuckv 1098 error += cmdline_parser_required2 (args_info, argv[0], additional_error);
1050 tim 320 }
1051    
1052 chuckv 1098 cmdline_parser_release (&local_args_info);
1053    
1054     if ( error )
1055     return (EXIT_FAILURE);
1056    
1057 gezelter 1629 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 tim 320 return 0;
1082 chuckv 1098
1083     failure:
1084    
1085     cmdline_parser_release (&local_args_info);
1086     return (EXIT_FAILURE);
1087 tim 320 }

Properties

Name Value
svn:keywords Author Id Revision Date