ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/dynamicProps/DynamicPropsCmd.cpp
Revision: 2024
Committed: Thu Oct 16 19:13:51 2014 UTC (10 years, 6 months ago) by gezelter
File size: 37612 byte(s)
Log Message:
Added Radial and Z-projected velocity autocorrelation functions
Started to add SequentialProps program
Mucking about with angular restraint potentials

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

Properties

Name Value
svn:keywords Author Id Revision Date