ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/StaticPropsCmd.cpp
Revision: 1413
Committed: Mon Mar 22 19:21:22 2010 UTC (15 years, 1 month ago) by gezelter
Content type: text/plain
Original Path: trunk/src/applications/staticProps/StaticPropsCmd.c
File size: 48474 byte(s)
Log Message:
Adding a progress bar, and pAngle staticProps

File Contents

# User Rev Content
1 tim 310 /*
2 gezelter 1390 File autogenerated by gengetopt version 2.22
3 tim 310 generated with the following command:
4 gezelter 1413 gengetopt -F StaticPropsCmd -u
5 tim 310
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 gezelter 929 /* If we use autoconf. */
12     #ifdef HAVE_CONFIG_H
13     #include "config.h"
14     #endif
15 tim 310
16     #include <stdio.h>
17     #include <stdlib.h>
18     #include <string.h>
19    
20     #include "getopt.h"
21    
22 tim 311 #include "StaticPropsCmd.h"
23 tim 310
24 chuckv 1128 const char *gengetopt_args_info_purpose = "";
25    
26 gezelter 1413 const char *gengetopt_args_info_usage = "Usage: StaticProps [OPTIONS]... [FILES]...";
27 chuckv 1128
28     const char *gengetopt_args_info_description = "";
29    
30     const char *gengetopt_args_info_help[] = {
31     " -h, --help Print help and exit",
32     " -V, --version Print version and exit",
33     " -i, --input=filename input dump file",
34     " -o, --output=filename output file name",
35     " -n, --step=INT process every n frame (default=`1')",
36     " -b, --nbins=INT number of bins (general purpose) \n (default=`100')",
37     " -x, --nbins_x=INT number of bins in x axis (default=`100')",
38     " -y, --nbins_y=INT number of bins in y axis (default=`100')",
39     " -a, --nanglebins=INT number of bins for cos(angle) (default=`50')",
40     " --length=DOUBLE maximum length (Defaults to 1/2 smallest length \n of first frame)",
41     " -c, --rcut=DOUBLE cutoff radius (rcut)",
42     " -z, --zoffset=DOUBLE Where to set the zero for the slab_density \n calculation (default=`0')",
43     " --sele1=selection script select the first stuntdouble set",
44     " --sele2=selection script select the second stuntdouble set",
45     " --sele3=selection script select the third stuntdouble set",
46     " --refsele=selection script\n select reference (use and only use with --gxyz)",
47 gezelter 1390 " --comsele=selection script\n select stunt doubles for center-of-mass \n reference point",
48 chuckv 1128 " --molname=STRING molecule name",
49     " --begin=INT begin internal index",
50     " --end=INT end internal index",
51     " --radius=DOUBLE nanoparticle radius",
52     "\n Group: staticProps\n an option of this group is required",
53     " --bo bond order parameter (--rcut must be specified)",
54     " --bor bond order parameter as a function of radius \n (--rcut must be specified)",
55 chuckv 1180 " --bad N(theta) bond angle density within (--rcut must \n be specified)",
56 chuckv 1128 " -g, --gofr g(r)",
57 xsun 1213 " --gofz g(z)",
58 chuckv 1128 " --r_theta g(r, cos(theta))",
59     " --r_omega g(r, cos(omega))",
60     " --theta_omega g(cos(theta), cos(omega))",
61     " --gxyz g(x, y, z)",
62     " -p, --p2 p2 order parameter (--sele1 and --sele2 must be \n specified)",
63     " --rp2 rp2 order parameter (--sele1 and --sele2 must \n be specified)",
64     " -s, --scd scd order parameter (either --sele1, --sele2, \n --sele3 are specified or --molname, --begin, \n --end are specified)",
65     " -d, --density density plot",
66     " --slab_density slab density",
67 gezelter 1413 " --p_angle p(cos(theta))",
68 chuckv 1128 " --hxy hxy",
69     " --rho_r rho of R",
70 chuckv 1180 " --hullvol hull volume of nanoparticle",
71 chuckv 1128 0
72     };
73    
74 gezelter 1390 typedef enum {ARG_NO
75     , ARG_STRING
76     , ARG_INT
77     , ARG_DOUBLE
78     } cmdline_parser_arg_type;
79    
80 gezelter 929 static
81     void clear_given (struct gengetopt_args_info *args_info);
82     static
83     void clear_args (struct gengetopt_args_info *args_info);
84    
85     static int
86 gezelter 1390 cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info,
87     struct cmdline_parser_params *params, const char *additional_error);
88 gezelter 929
89     static int
90     cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
91    
92     static char *
93     gengetopt_strdup (const char *s);
94    
95     static
96     void clear_given (struct gengetopt_args_info *args_info)
97     {
98     args_info->help_given = 0 ;
99     args_info->version_given = 0 ;
100     args_info->input_given = 0 ;
101     args_info->output_given = 0 ;
102     args_info->step_given = 0 ;
103 gezelter 1041 args_info->nbins_given = 0 ;
104 xsun 955 args_info->nbins_x_given = 0 ;
105     args_info->nbins_y_given = 0 ;
106 gezelter 929 args_info->nanglebins_given = 0 ;
107     args_info->length_given = 0 ;
108 gezelter 1039 args_info->rcut_given = 0 ;
109 gezelter 929 args_info->zoffset_given = 0 ;
110     args_info->sele1_given = 0 ;
111     args_info->sele2_given = 0 ;
112     args_info->sele3_given = 0 ;
113     args_info->refsele_given = 0 ;
114 gezelter 1390 args_info->comsele_given = 0 ;
115 gezelter 929 args_info->molname_given = 0 ;
116     args_info->begin_given = 0 ;
117     args_info->end_given = 0 ;
118 chuckv 1091 args_info->radius_given = 0 ;
119 gezelter 1039 args_info->bo_given = 0 ;
120 chuckv 1128 args_info->bor_given = 0 ;
121 chuckv 1180 args_info->bad_given = 0 ;
122 gezelter 929 args_info->gofr_given = 0 ;
123 xsun 1213 args_info->gofz_given = 0 ;
124 gezelter 929 args_info->r_theta_given = 0 ;
125     args_info->r_omega_given = 0 ;
126     args_info->theta_omega_given = 0 ;
127     args_info->gxyz_given = 0 ;
128     args_info->p2_given = 0 ;
129 xsun 980 args_info->rp2_given = 0 ;
130 gezelter 929 args_info->scd_given = 0 ;
131     args_info->density_given = 0 ;
132     args_info->slab_density_given = 0 ;
133 gezelter 1413 args_info->p_angle_given = 0 ;
134 xsun 955 args_info->hxy_given = 0 ;
135 chuckv 1091 args_info->rho_r_given = 0 ;
136 chuckv 1180 args_info->hullvol_given = 0 ;
137 gezelter 929 args_info->staticProps_group_counter = 0 ;
138     }
139    
140     static
141     void clear_args (struct gengetopt_args_info *args_info)
142     {
143     args_info->input_arg = NULL;
144     args_info->input_orig = NULL;
145     args_info->output_arg = NULL;
146     args_info->output_orig = NULL;
147     args_info->step_arg = 1;
148     args_info->step_orig = NULL;
149 gezelter 1041 args_info->nbins_arg = 100;
150     args_info->nbins_orig = NULL;
151 xsun 955 args_info->nbins_x_arg = 100;
152     args_info->nbins_x_orig = NULL;
153     args_info->nbins_y_arg = 100;
154     args_info->nbins_y_orig = NULL;
155 gezelter 929 args_info->nanglebins_arg = 50;
156     args_info->nanglebins_orig = NULL;
157     args_info->length_orig = NULL;
158 gezelter 1039 args_info->rcut_orig = NULL;
159 gezelter 929 args_info->zoffset_arg = 0;
160     args_info->zoffset_orig = NULL;
161     args_info->sele1_arg = NULL;
162     args_info->sele1_orig = NULL;
163     args_info->sele2_arg = NULL;
164     args_info->sele2_orig = NULL;
165     args_info->sele3_arg = NULL;
166     args_info->sele3_orig = NULL;
167     args_info->refsele_arg = NULL;
168     args_info->refsele_orig = NULL;
169 gezelter 1390 args_info->comsele_arg = NULL;
170     args_info->comsele_orig = NULL;
171 gezelter 929 args_info->molname_arg = NULL;
172     args_info->molname_orig = NULL;
173     args_info->begin_orig = NULL;
174     args_info->end_orig = NULL;
175 chuckv 1091 args_info->radius_orig = NULL;
176 gezelter 929
177     }
178    
179 chuckv 1128 static
180     void init_args_info(struct gengetopt_args_info *args_info)
181     {
182 gezelter 1390
183    
184 chuckv 1128 args_info->help_help = gengetopt_args_info_help[0] ;
185     args_info->version_help = gengetopt_args_info_help[1] ;
186     args_info->input_help = gengetopt_args_info_help[2] ;
187     args_info->output_help = gengetopt_args_info_help[3] ;
188     args_info->step_help = gengetopt_args_info_help[4] ;
189     args_info->nbins_help = gengetopt_args_info_help[5] ;
190     args_info->nbins_x_help = gengetopt_args_info_help[6] ;
191     args_info->nbins_y_help = gengetopt_args_info_help[7] ;
192     args_info->nanglebins_help = gengetopt_args_info_help[8] ;
193     args_info->length_help = gengetopt_args_info_help[9] ;
194     args_info->rcut_help = gengetopt_args_info_help[10] ;
195     args_info->zoffset_help = gengetopt_args_info_help[11] ;
196     args_info->sele1_help = gengetopt_args_info_help[12] ;
197     args_info->sele2_help = gengetopt_args_info_help[13] ;
198     args_info->sele3_help = gengetopt_args_info_help[14] ;
199     args_info->refsele_help = gengetopt_args_info_help[15] ;
200 gezelter 1390 args_info->comsele_help = gengetopt_args_info_help[16] ;
201     args_info->molname_help = gengetopt_args_info_help[17] ;
202     args_info->begin_help = gengetopt_args_info_help[18] ;
203     args_info->end_help = gengetopt_args_info_help[19] ;
204     args_info->radius_help = gengetopt_args_info_help[20] ;
205     args_info->bo_help = gengetopt_args_info_help[22] ;
206     args_info->bor_help = gengetopt_args_info_help[23] ;
207     args_info->bad_help = gengetopt_args_info_help[24] ;
208     args_info->gofr_help = gengetopt_args_info_help[25] ;
209     args_info->gofz_help = gengetopt_args_info_help[26] ;
210     args_info->r_theta_help = gengetopt_args_info_help[27] ;
211     args_info->r_omega_help = gengetopt_args_info_help[28] ;
212     args_info->theta_omega_help = gengetopt_args_info_help[29] ;
213     args_info->gxyz_help = gengetopt_args_info_help[30] ;
214     args_info->p2_help = gengetopt_args_info_help[31] ;
215     args_info->rp2_help = gengetopt_args_info_help[32] ;
216     args_info->scd_help = gengetopt_args_info_help[33] ;
217     args_info->density_help = gengetopt_args_info_help[34] ;
218     args_info->slab_density_help = gengetopt_args_info_help[35] ;
219 gezelter 1413 args_info->p_angle_help = gengetopt_args_info_help[36] ;
220     args_info->hxy_help = gengetopt_args_info_help[37] ;
221     args_info->rho_r_help = gengetopt_args_info_help[38] ;
222     args_info->hullvol_help = gengetopt_args_info_help[39] ;
223 chuckv 1128
224     }
225    
226 tim 310 void
227     cmdline_parser_print_version (void)
228     {
229     printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
230     }
231    
232 gezelter 1390 static void print_help_common(void) {
233 tim 310 cmdline_parser_print_version ();
234 chuckv 1128
235     if (strlen(gengetopt_args_info_purpose) > 0)
236     printf("\n%s\n", gengetopt_args_info_purpose);
237    
238 gezelter 1390 if (strlen(gengetopt_args_info_usage) > 0)
239     printf("\n%s\n", gengetopt_args_info_usage);
240 chuckv 1128
241 gezelter 1390 printf("\n");
242    
243 chuckv 1128 if (strlen(gengetopt_args_info_description) > 0)
244     printf("%s\n", gengetopt_args_info_description);
245 gezelter 1390 }
246 chuckv 1128
247 gezelter 1390 void
248     cmdline_parser_print_help (void)
249     {
250     int i = 0;
251     print_help_common();
252 chuckv 1128 while (gengetopt_args_info_help[i])
253     printf("%s\n", gengetopt_args_info_help[i++]);
254 tim 310 }
255    
256 gezelter 929 void
257     cmdline_parser_init (struct gengetopt_args_info *args_info)
258     {
259     clear_given (args_info);
260     clear_args (args_info);
261 chuckv 1128 init_args_info (args_info);
262 gezelter 1413
263     args_info->inputs = NULL;
264     args_info->inputs_num = 0;
265 gezelter 1390 }
266 chuckv 1128
267 gezelter 1390 void
268     cmdline_parser_params_init(struct cmdline_parser_params *params)
269     {
270     if (params)
271     {
272     params->override = 0;
273     params->initialize = 1;
274     params->check_required = 1;
275     params->check_ambiguity = 0;
276     params->print_errors = 1;
277     }
278 gezelter 929 }
279 tim 310
280 gezelter 1390 struct cmdline_parser_params *
281     cmdline_parser_params_create(void)
282     {
283     struct cmdline_parser_params *params =
284     (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
285     cmdline_parser_params_init(params);
286     return params;
287     }
288    
289 gezelter 929 static void
290 gezelter 1390 free_string_field (char **s)
291 gezelter 929 {
292 gezelter 1390 if (*s)
293 gezelter 929 {
294 gezelter 1390 free (*s);
295     *s = 0;
296 gezelter 929 }
297 gezelter 1390 }
298    
299    
300     static void
301     cmdline_parser_release (struct gengetopt_args_info *args_info)
302     {
303 gezelter 1413 unsigned int i;
304 gezelter 1390 free_string_field (&(args_info->input_arg));
305     free_string_field (&(args_info->input_orig));
306     free_string_field (&(args_info->output_arg));
307     free_string_field (&(args_info->output_orig));
308     free_string_field (&(args_info->step_orig));
309     free_string_field (&(args_info->nbins_orig));
310     free_string_field (&(args_info->nbins_x_orig));
311     free_string_field (&(args_info->nbins_y_orig));
312     free_string_field (&(args_info->nanglebins_orig));
313     free_string_field (&(args_info->length_orig));
314     free_string_field (&(args_info->rcut_orig));
315     free_string_field (&(args_info->zoffset_orig));
316     free_string_field (&(args_info->sele1_arg));
317     free_string_field (&(args_info->sele1_orig));
318     free_string_field (&(args_info->sele2_arg));
319     free_string_field (&(args_info->sele2_orig));
320     free_string_field (&(args_info->sele3_arg));
321     free_string_field (&(args_info->sele3_orig));
322     free_string_field (&(args_info->refsele_arg));
323     free_string_field (&(args_info->refsele_orig));
324     free_string_field (&(args_info->comsele_arg));
325     free_string_field (&(args_info->comsele_orig));
326     free_string_field (&(args_info->molname_arg));
327     free_string_field (&(args_info->molname_orig));
328     free_string_field (&(args_info->begin_orig));
329     free_string_field (&(args_info->end_orig));
330     free_string_field (&(args_info->radius_orig));
331 gezelter 929
332 chuckv 1128
333 gezelter 1413 for (i = 0; i < args_info->inputs_num; ++i)
334     free (args_info->inputs [i]);
335 gezelter 1390
336 gezelter 1413 if (args_info->inputs_num)
337     free (args_info->inputs);
338    
339 gezelter 929 clear_given (args_info);
340     }
341 tim 310
342 gezelter 1390
343     static void
344     write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
345     {
346     if (arg) {
347     fprintf(outfile, "%s=\"%s\"\n", opt, arg);
348     } else {
349     fprintf(outfile, "%s\n", opt);
350     }
351     }
352    
353    
354 gezelter 929 int
355 gezelter 1390 cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
356     {
357     int i = 0;
358    
359     if (!outfile)
360     {
361     fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
362     return EXIT_FAILURE;
363     }
364    
365     if (args_info->help_given)
366     write_into_file(outfile, "help", 0, 0 );
367     if (args_info->version_given)
368     write_into_file(outfile, "version", 0, 0 );
369     if (args_info->input_given)
370     write_into_file(outfile, "input", args_info->input_orig, 0);
371     if (args_info->output_given)
372     write_into_file(outfile, "output", args_info->output_orig, 0);
373     if (args_info->step_given)
374     write_into_file(outfile, "step", args_info->step_orig, 0);
375     if (args_info->nbins_given)
376     write_into_file(outfile, "nbins", args_info->nbins_orig, 0);
377     if (args_info->nbins_x_given)
378     write_into_file(outfile, "nbins_x", args_info->nbins_x_orig, 0);
379     if (args_info->nbins_y_given)
380     write_into_file(outfile, "nbins_y", args_info->nbins_y_orig, 0);
381     if (args_info->nanglebins_given)
382     write_into_file(outfile, "nanglebins", args_info->nanglebins_orig, 0);
383     if (args_info->length_given)
384     write_into_file(outfile, "length", args_info->length_orig, 0);
385     if (args_info->rcut_given)
386     write_into_file(outfile, "rcut", args_info->rcut_orig, 0);
387     if (args_info->zoffset_given)
388     write_into_file(outfile, "zoffset", args_info->zoffset_orig, 0);
389     if (args_info->sele1_given)
390     write_into_file(outfile, "sele1", args_info->sele1_orig, 0);
391     if (args_info->sele2_given)
392     write_into_file(outfile, "sele2", args_info->sele2_orig, 0);
393     if (args_info->sele3_given)
394     write_into_file(outfile, "sele3", args_info->sele3_orig, 0);
395     if (args_info->refsele_given)
396     write_into_file(outfile, "refsele", args_info->refsele_orig, 0);
397     if (args_info->comsele_given)
398     write_into_file(outfile, "comsele", args_info->comsele_orig, 0);
399     if (args_info->molname_given)
400     write_into_file(outfile, "molname", args_info->molname_orig, 0);
401     if (args_info->begin_given)
402     write_into_file(outfile, "begin", args_info->begin_orig, 0);
403     if (args_info->end_given)
404     write_into_file(outfile, "end", args_info->end_orig, 0);
405     if (args_info->radius_given)
406     write_into_file(outfile, "radius", args_info->radius_orig, 0);
407     if (args_info->bo_given)
408     write_into_file(outfile, "bo", 0, 0 );
409     if (args_info->bor_given)
410     write_into_file(outfile, "bor", 0, 0 );
411     if (args_info->bad_given)
412     write_into_file(outfile, "bad", 0, 0 );
413     if (args_info->gofr_given)
414     write_into_file(outfile, "gofr", 0, 0 );
415     if (args_info->gofz_given)
416     write_into_file(outfile, "gofz", 0, 0 );
417     if (args_info->r_theta_given)
418     write_into_file(outfile, "r_theta", 0, 0 );
419     if (args_info->r_omega_given)
420     write_into_file(outfile, "r_omega", 0, 0 );
421     if (args_info->theta_omega_given)
422     write_into_file(outfile, "theta_omega", 0, 0 );
423     if (args_info->gxyz_given)
424     write_into_file(outfile, "gxyz", 0, 0 );
425     if (args_info->p2_given)
426     write_into_file(outfile, "p2", 0, 0 );
427     if (args_info->rp2_given)
428     write_into_file(outfile, "rp2", 0, 0 );
429     if (args_info->scd_given)
430     write_into_file(outfile, "scd", 0, 0 );
431     if (args_info->density_given)
432     write_into_file(outfile, "density", 0, 0 );
433     if (args_info->slab_density_given)
434     write_into_file(outfile, "slab_density", 0, 0 );
435 gezelter 1413 if (args_info->p_angle_given)
436     write_into_file(outfile, "p_angle", 0, 0 );
437 gezelter 1390 if (args_info->hxy_given)
438     write_into_file(outfile, "hxy", 0, 0 );
439     if (args_info->rho_r_given)
440     write_into_file(outfile, "rho_r", 0, 0 );
441     if (args_info->hullvol_given)
442     write_into_file(outfile, "hullvol", 0, 0 );
443    
444    
445     i = EXIT_SUCCESS;
446     return i;
447     }
448    
449     int
450 gezelter 929 cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
451     {
452     FILE *outfile;
453     int i = 0;
454    
455     outfile = fopen(filename, "w");
456    
457     if (!outfile)
458     {
459     fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
460     return EXIT_FAILURE;
461     }
462    
463 gezelter 1390 i = cmdline_parser_dump(outfile, args_info);
464 gezelter 929 fclose (outfile);
465    
466     return i;
467     }
468    
469     void
470     cmdline_parser_free (struct gengetopt_args_info *args_info)
471     {
472     cmdline_parser_release (args_info);
473     }
474    
475 gezelter 1390 /** @brief replacement of strdup, which is not standard */
476 tim 310 char *
477     gengetopt_strdup (const char *s)
478     {
479 gezelter 929 char *result = NULL;
480     if (!s)
481     return result;
482    
483     result = (char*)malloc(strlen(s) + 1);
484 tim 310 if (result == (char*)0)
485     return (char*)0;
486     strcpy(result, s);
487     return result;
488     }
489    
490 gezelter 929 static void
491     reset_group_staticProps(struct gengetopt_args_info *args_info)
492 tim 310 {
493 gezelter 929 if (! args_info->staticProps_group_counter)
494     return;
495 tim 310
496 gezelter 1039 args_info->bo_given = 0 ;
497 chuckv 1128 args_info->bor_given = 0 ;
498 chuckv 1180 args_info->bad_given = 0 ;
499 tim 310 args_info->gofr_given = 0 ;
500 xsun 1213 args_info->gofz_given = 0 ;
501 tim 310 args_info->r_theta_given = 0 ;
502     args_info->r_omega_given = 0 ;
503     args_info->theta_omega_given = 0 ;
504 tim 369 args_info->gxyz_given = 0 ;
505 tim 543 args_info->p2_given = 0 ;
506 xsun 980 args_info->rp2_given = 0 ;
507 tim 544 args_info->scd_given = 0 ;
508 tim 545 args_info->density_given = 0 ;
509 tim 840 args_info->slab_density_given = 0 ;
510 gezelter 1413 args_info->p_angle_given = 0 ;
511 xsun 967 args_info->hxy_given = 0 ;
512 chuckv 1091 args_info->rho_r_given = 0 ;
513 chuckv 1180 args_info->hullvol_given = 0 ;
514 gezelter 929
515     args_info->staticProps_group_counter = 0;
516 tim 543 }
517 tim 310
518 gezelter 929 int
519     cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
520     {
521     return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
522     }
523 tim 310
524 gezelter 929 int
525 gezelter 1390 cmdline_parser_ext (int argc, char * const *argv, struct gengetopt_args_info *args_info,
526     struct cmdline_parser_params *params)
527     {
528     int result;
529     result = cmdline_parser_internal (argc, argv, args_info, params, NULL);
530    
531     if (result == EXIT_FAILURE)
532     {
533     cmdline_parser_free (args_info);
534     exit (EXIT_FAILURE);
535     }
536    
537     return result;
538     }
539    
540     int
541 gezelter 929 cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
542     {
543     int result;
544 gezelter 1390 struct cmdline_parser_params params;
545    
546     params.override = override;
547     params.initialize = initialize;
548     params.check_required = check_required;
549     params.check_ambiguity = 0;
550     params.print_errors = 1;
551 gezelter 929
552 gezelter 1390 result = cmdline_parser_internal (argc, argv, args_info, &params, NULL);
553 gezelter 929
554     if (result == EXIT_FAILURE)
555     {
556     cmdline_parser_free (args_info);
557     exit (EXIT_FAILURE);
558     }
559    
560     return result;
561     }
562    
563     int
564     cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
565     {
566     int result = EXIT_SUCCESS;
567    
568     if (cmdline_parser_required2(args_info, prog_name, NULL) > 0)
569     result = EXIT_FAILURE;
570    
571     if (result == EXIT_FAILURE)
572     {
573     cmdline_parser_free (args_info);
574     exit (EXIT_FAILURE);
575     }
576    
577     return result;
578     }
579    
580     int
581     cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
582     {
583     int error = 0;
584    
585 chuckv 1128 /* checks for required options */
586 gezelter 929 if (! args_info->input_given)
587     {
588     fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
589     error = 1;
590     }
591 chuckv 1128
592 gezelter 929 if (args_info->staticProps_group_counter == 0)
593     {
594     fprintf (stderr, "%s: %d options of group staticProps were given. One is required.%s\n", prog_name, args_info->staticProps_group_counter, (additional_error ? additional_error : ""));
595     error = 1;
596     }
597    
598    
599 chuckv 1128 /* checks for dependences among options */
600    
601 gezelter 929 return error;
602     }
603    
604 gezelter 1390
605     static char *package_name = 0;
606    
607     /**
608     * @brief updates an option
609     * @param field the generic pointer to the field to update
610     * @param orig_field the pointer to the orig field
611     * @param field_given the pointer to the number of occurrence of this option
612     * @param prev_given the pointer to the number of occurrence already seen
613     * @param value the argument for this option (if null no arg was specified)
614     * @param possible_values the possible values for this option (if specified)
615     * @param default_value the default value (in case the option only accepts fixed values)
616     * @param arg_type the type of this option
617     * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
618     * @param override @see cmdline_parser_params.override
619     * @param no_free whether to free a possible previous value
620     * @param multiple_option whether this is a multiple option
621     * @param long_opt the corresponding long option
622     * @param short_opt the corresponding short option (or '-' if none)
623     * @param additional_error possible further error specification
624     */
625     static
626     int update_arg(void *field, char **orig_field,
627     unsigned int *field_given, unsigned int *prev_given,
628     char *value, char *possible_values[], const char *default_value,
629     cmdline_parser_arg_type arg_type,
630     int check_ambiguity, int override,
631     int no_free, int multiple_option,
632     const char *long_opt, char short_opt,
633     const char *additional_error)
634     {
635     char *stop_char = 0;
636     const char *val = value;
637     int found;
638     char **string_field;
639    
640     stop_char = 0;
641     found = 0;
642    
643     if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
644     {
645     if (short_opt != '-')
646     fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
647     package_name, long_opt, short_opt,
648     (additional_error ? additional_error : ""));
649     else
650     fprintf (stderr, "%s: `--%s' option given more than once%s\n",
651     package_name, long_opt,
652     (additional_error ? additional_error : ""));
653     return 1; /* failure */
654     }
655    
656    
657     if (field_given && *field_given && ! override)
658     return 0;
659     if (prev_given)
660     (*prev_given)++;
661     if (field_given)
662     (*field_given)++;
663     if (possible_values)
664     val = possible_values[found];
665    
666     switch(arg_type) {
667     case ARG_INT:
668     if (val) *((int *)field) = strtol (val, &stop_char, 0);
669     break;
670     case ARG_DOUBLE:
671     if (val) *((double *)field) = strtod (val, &stop_char);
672     break;
673     case ARG_STRING:
674     if (val) {
675     string_field = (char **)field;
676     if (!no_free && *string_field)
677     free (*string_field); /* free previous string */
678     *string_field = gengetopt_strdup (val);
679     }
680     break;
681     default:
682     break;
683     };
684    
685     /* check numeric conversion */
686     switch(arg_type) {
687     case ARG_INT:
688     case ARG_DOUBLE:
689     if (val && !(stop_char && *stop_char == '\0')) {
690     fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
691     return 1; /* failure */
692     }
693     break;
694     default:
695     ;
696     };
697    
698     /* store the original value */
699     switch(arg_type) {
700     case ARG_NO:
701     break;
702     default:
703     if (value && orig_field) {
704     if (no_free) {
705     *orig_field = value;
706     } else {
707     if (*orig_field)
708     free (*orig_field); /* free previous string */
709     *orig_field = gengetopt_strdup (value);
710     }
711     }
712     };
713    
714     return 0; /* OK */
715     }
716    
717    
718 gezelter 929 int
719 gezelter 1390 cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info,
720     struct cmdline_parser_params *params, const char *additional_error)
721 gezelter 929 {
722     int c; /* Character of the parsed option. */
723    
724     int error = 0;
725     struct gengetopt_args_info local_args_info;
726 gezelter 1390
727     int override;
728     int initialize;
729     int check_required;
730     int check_ambiguity;
731    
732     package_name = argv[0];
733    
734     override = params->override;
735     initialize = params->initialize;
736     check_required = params->check_required;
737     check_ambiguity = params->check_ambiguity;
738 gezelter 929
739     if (initialize)
740     cmdline_parser_init (args_info);
741    
742     cmdline_parser_init (&local_args_info);
743    
744 tim 310 optarg = 0;
745 chuckv 1128 optind = 0;
746 gezelter 1390 opterr = params->print_errors;
747 tim 310 optopt = '?';
748    
749     while (1)
750     {
751     int option_index = 0;
752    
753     static struct option long_options[] = {
754     { "help", 0, NULL, 'h' },
755     { "version", 0, NULL, 'V' },
756     { "input", 1, NULL, 'i' },
757     { "output", 1, NULL, 'o' },
758 tim 311 { "step", 1, NULL, 'n' },
759 gezelter 1041 { "nbins", 1, NULL, 'b' },
760 xsun 967 { "nbins_x", 1, NULL, 'x' },
761     { "nbins_y", 1, NULL, 'y' },
762 tim 310 { "nanglebins", 1, NULL, 'a' },
763 gezelter 1039 { "length", 1, NULL, 0 },
764     { "rcut", 1, NULL, 'c' },
765 gezelter 929 { "zoffset", 1, NULL, 'z' },
766 tim 310 { "sele1", 1, NULL, 0 },
767     { "sele2", 1, NULL, 0 },
768 tim 544 { "sele3", 1, NULL, 0 },
769 tim 369 { "refsele", 1, NULL, 0 },
770 gezelter 1390 { "comsele", 1, NULL, 0 },
771 tim 544 { "molname", 1, NULL, 0 },
772     { "begin", 1, NULL, 0 },
773     { "end", 1, NULL, 0 },
774 chuckv 1091 { "radius", 1, NULL, 0 },
775 gezelter 1041 { "bo", 0, NULL, 0 },
776 chuckv 1128 { "bor", 0, NULL, 0 },
777 chuckv 1180 { "bad", 0, NULL, 0 },
778 gezelter 1039 { "gofr", 0, NULL, 'g' },
779 xsun 1213 { "gofz", 0, NULL, 0 },
780 tim 310 { "r_theta", 0, NULL, 0 },
781     { "r_omega", 0, NULL, 0 },
782     { "theta_omega", 0, NULL, 0 },
783 tim 369 { "gxyz", 0, NULL, 0 },
784 gezelter 1039 { "p2", 0, NULL, 'p' },
785 xsun 980 { "rp2", 0, NULL, 0 },
786 gezelter 1039 { "scd", 0, NULL, 's' },
787     { "density", 0, NULL, 'd' },
788 tim 840 { "slab_density", 0, NULL, 0 },
789 gezelter 1413 { "p_angle", 0, NULL, 0 },
790 xsun 955 { "hxy", 0, NULL, 0 },
791 chuckv 1091 { "rho_r", 0, NULL, 0 },
792 chuckv 1180 { "hullvol", 0, NULL, 0 },
793 tim 310 { NULL, 0, NULL, 0 }
794     };
795    
796 gezelter 1052 c = getopt_long (argc, argv, "hVi:o:n:b:x:y:a:c:z:gpsd", long_options, &option_index);
797 tim 310
798     if (c == -1) break; /* Exit from `while (1)' loop. */
799    
800     switch (c)
801     {
802     case 'h': /* Print help and exit. */
803     cmdline_parser_print_help ();
804 gezelter 929 cmdline_parser_free (&local_args_info);
805 tim 310 exit (EXIT_SUCCESS);
806    
807     case 'V': /* Print version and exit. */
808     cmdline_parser_print_version ();
809 gezelter 929 cmdline_parser_free (&local_args_info);
810 tim 310 exit (EXIT_SUCCESS);
811    
812     case 'i': /* input dump file. */
813 gezelter 1390
814    
815     if (update_arg( (void *)&(args_info->input_arg),
816     &(args_info->input_orig), &(args_info->input_given),
817     &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
818     check_ambiguity, override, 0, 0,
819     "input", 'i',
820     additional_error))
821     goto failure;
822    
823 tim 310 break;
824     case 'o': /* output file name. */
825 gezelter 1390
826    
827     if (update_arg( (void *)&(args_info->output_arg),
828     &(args_info->output_orig), &(args_info->output_given),
829     &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
830     check_ambiguity, override, 0, 0,
831     "output", 'o',
832     additional_error))
833     goto failure;
834    
835 tim 310 break;
836 tim 311 case 'n': /* process every n frame. */
837 gezelter 1390
838    
839     if (update_arg( (void *)&(args_info->step_arg),
840     &(args_info->step_orig), &(args_info->step_given),
841     &(local_args_info.step_given), optarg, 0, "1", ARG_INT,
842     check_ambiguity, override, 0, 0,
843     "step", 'n',
844     additional_error))
845 gezelter 929 goto failure;
846 gezelter 1390
847 tim 310 break;
848 gezelter 1041 case 'b': /* number of bins (general purpose). */
849 gezelter 1390
850    
851     if (update_arg( (void *)&(args_info->nbins_arg),
852     &(args_info->nbins_orig), &(args_info->nbins_given),
853     &(local_args_info.nbins_given), optarg, 0, "100", ARG_INT,
854     check_ambiguity, override, 0, 0,
855     "nbins", 'b',
856     additional_error))
857 gezelter 929 goto failure;
858 gezelter 1390
859 tim 310 break;
860 xsun 955 case 'x': /* number of bins in x axis. */
861 gezelter 1390
862    
863     if (update_arg( (void *)&(args_info->nbins_x_arg),
864     &(args_info->nbins_x_orig), &(args_info->nbins_x_given),
865     &(local_args_info.nbins_x_given), optarg, 0, "100", ARG_INT,
866     check_ambiguity, override, 0, 0,
867     "nbins_x", 'x',
868     additional_error))
869 xsun 955 goto failure;
870 gezelter 1390
871 xsun 955 break;
872     case 'y': /* number of bins in y axis. */
873 gezelter 1390
874    
875     if (update_arg( (void *)&(args_info->nbins_y_arg),
876     &(args_info->nbins_y_orig), &(args_info->nbins_y_given),
877     &(local_args_info.nbins_y_given), optarg, 0, "100", ARG_INT,
878     check_ambiguity, override, 0, 0,
879     "nbins_y", 'y',
880     additional_error))
881 xsun 955 goto failure;
882 gezelter 1390
883 xsun 955 break;
884 tim 310 case 'a': /* number of bins for cos(angle). */
885 gezelter 1390
886    
887     if (update_arg( (void *)&(args_info->nanglebins_arg),
888     &(args_info->nanglebins_orig), &(args_info->nanglebins_given),
889     &(local_args_info.nanglebins_given), optarg, 0, "50", ARG_INT,
890     check_ambiguity, override, 0, 0,
891     "nanglebins", 'a',
892     additional_error))
893 gezelter 929 goto failure;
894 gezelter 1390
895 tim 310 break;
896 gezelter 1039 case 'c': /* cutoff radius (rcut). */
897 gezelter 1390
898    
899     if (update_arg( (void *)&(args_info->rcut_arg),
900     &(args_info->rcut_orig), &(args_info->rcut_given),
901     &(local_args_info.rcut_given), optarg, 0, 0, ARG_DOUBLE,
902     check_ambiguity, override, 0, 0,
903     "rcut", 'c',
904     additional_error))
905 gezelter 1039 goto failure;
906 gezelter 1390
907 gezelter 1039 break;
908 gezelter 929 case 'z': /* Where to set the zero for the slab_density calculation. */
909 gezelter 1390
910    
911     if (update_arg( (void *)&(args_info->zoffset_arg),
912     &(args_info->zoffset_orig), &(args_info->zoffset_given),
913     &(local_args_info.zoffset_given), optarg, 0, "0", ARG_DOUBLE,
914     check_ambiguity, override, 0, 0,
915     "zoffset", 'z',
916     additional_error))
917 gezelter 929 goto failure;
918 gezelter 1390
919 gezelter 929 break;
920 gezelter 1039 case 'g': /* g(r). */
921 gezelter 1390
922 gezelter 1039 if (args_info->staticProps_group_counter && override)
923     reset_group_staticProps (args_info);
924     args_info->staticProps_group_counter += 1;
925 gezelter 1390
926     if (update_arg( 0 ,
927     0 , &(args_info->gofr_given),
928     &(local_args_info.gofr_given), optarg, 0, 0, ARG_NO,
929     check_ambiguity, override, 0, 0,
930     "gofr", 'g',
931     additional_error))
932     goto failure;
933    
934 gezelter 1039 break;
935     case 'p': /* p2 order parameter (--sele1 and --sele2 must be specified). */
936 gezelter 1390
937 gezelter 1039 if (args_info->staticProps_group_counter && override)
938     reset_group_staticProps (args_info);
939     args_info->staticProps_group_counter += 1;
940 gezelter 1390
941     if (update_arg( 0 ,
942     0 , &(args_info->p2_given),
943     &(local_args_info.p2_given), optarg, 0, 0, ARG_NO,
944     check_ambiguity, override, 0, 0,
945     "p2", 'p',
946     additional_error))
947     goto failure;
948    
949 gezelter 1039 break;
950     case 's': /* scd order parameter (either --sele1, --sele2, --sele3 are specified or --molname, --begin, --end are specified). */
951 gezelter 1390
952 gezelter 1039 if (args_info->staticProps_group_counter && override)
953     reset_group_staticProps (args_info);
954     args_info->staticProps_group_counter += 1;
955 gezelter 1390
956     if (update_arg( 0 ,
957     0 , &(args_info->scd_given),
958     &(local_args_info.scd_given), optarg, 0, 0, ARG_NO,
959     check_ambiguity, override, 0, 0,
960     "scd", 's',
961     additional_error))
962     goto failure;
963    
964 gezelter 1039 break;
965     case 'd': /* density plot. */
966 gezelter 1390
967 gezelter 1039 if (args_info->staticProps_group_counter && override)
968     reset_group_staticProps (args_info);
969     args_info->staticProps_group_counter += 1;
970 gezelter 1390
971     if (update_arg( 0 ,
972     0 , &(args_info->density_given),
973     &(local_args_info.density_given), optarg, 0, 0, ARG_NO,
974     check_ambiguity, override, 0, 0,
975     "density", 'd',
976     additional_error))
977     goto failure;
978    
979 gezelter 1039 break;
980    
981 tim 310 case 0: /* Long option with no short option */
982 gezelter 1039 /* maximum length (Defaults to 1/2 smallest length of first frame). */
983     if (strcmp (long_options[option_index].name, "length") == 0)
984     {
985 gezelter 1390
986    
987     if (update_arg( (void *)&(args_info->length_arg),
988     &(args_info->length_orig), &(args_info->length_given),
989     &(local_args_info.length_given), optarg, 0, 0, ARG_DOUBLE,
990     check_ambiguity, override, 0, 0,
991     "length", '-',
992     additional_error))
993 gezelter 1039 goto failure;
994 gezelter 1390
995 gezelter 1039 }
996 tim 544 /* select the first stuntdouble set. */
997 gezelter 1039 else if (strcmp (long_options[option_index].name, "sele1") == 0)
998 tim 543 {
999 gezelter 1390
1000    
1001     if (update_arg( (void *)&(args_info->sele1_arg),
1002     &(args_info->sele1_orig), &(args_info->sele1_given),
1003     &(local_args_info.sele1_given), optarg, 0, 0, ARG_STRING,
1004     check_ambiguity, override, 0, 0,
1005     "sele1", '-',
1006     additional_error))
1007     goto failure;
1008    
1009 tim 543 }
1010 tim 544 /* select the second stuntdouble set. */
1011 tim 310 else if (strcmp (long_options[option_index].name, "sele2") == 0)
1012 tim 543 {
1013 gezelter 1390
1014    
1015     if (update_arg( (void *)&(args_info->sele2_arg),
1016     &(args_info->sele2_orig), &(args_info->sele2_given),
1017     &(local_args_info.sele2_given), optarg, 0, 0, ARG_STRING,
1018     check_ambiguity, override, 0, 0,
1019     "sele2", '-',
1020     additional_error))
1021     goto failure;
1022    
1023 tim 543 }
1024 tim 544 /* select the third stuntdouble set. */
1025     else if (strcmp (long_options[option_index].name, "sele3") == 0)
1026     {
1027 gezelter 1390
1028    
1029     if (update_arg( (void *)&(args_info->sele3_arg),
1030     &(args_info->sele3_orig), &(args_info->sele3_given),
1031     &(local_args_info.sele3_given), optarg, 0, 0, ARG_STRING,
1032     check_ambiguity, override, 0, 0,
1033     "sele3", '-',
1034     additional_error))
1035     goto failure;
1036    
1037 tim 544 }
1038 tim 369 /* select reference (use and only use with --gxyz). */
1039     else if (strcmp (long_options[option_index].name, "refsele") == 0)
1040 tim 543 {
1041 gezelter 1390
1042    
1043     if (update_arg( (void *)&(args_info->refsele_arg),
1044     &(args_info->refsele_orig), &(args_info->refsele_given),
1045     &(local_args_info.refsele_given), optarg, 0, 0, ARG_STRING,
1046     check_ambiguity, override, 0, 0,
1047     "refsele", '-',
1048     additional_error))
1049     goto failure;
1050    
1051 tim 543 }
1052 gezelter 1390 /* select stunt doubles for center-of-mass reference point. */
1053     else if (strcmp (long_options[option_index].name, "comsele") == 0)
1054     {
1055    
1056    
1057     if (update_arg( (void *)&(args_info->comsele_arg),
1058     &(args_info->comsele_orig), &(args_info->comsele_given),
1059     &(local_args_info.comsele_given), optarg, 0, 0, ARG_STRING,
1060     check_ambiguity, override, 0, 0,
1061     "comsele", '-',
1062     additional_error))
1063     goto failure;
1064    
1065     }
1066 tim 544 /* molecule name. */
1067     else if (strcmp (long_options[option_index].name, "molname") == 0)
1068     {
1069 gezelter 1390
1070    
1071     if (update_arg( (void *)&(args_info->molname_arg),
1072     &(args_info->molname_orig), &(args_info->molname_given),
1073     &(local_args_info.molname_given), optarg, 0, 0, ARG_STRING,
1074     check_ambiguity, override, 0, 0,
1075     "molname", '-',
1076     additional_error))
1077     goto failure;
1078    
1079 tim 544 }
1080 gezelter 1039 /* begin internal index. */
1081 tim 544 else if (strcmp (long_options[option_index].name, "begin") == 0)
1082     {
1083 gezelter 1390
1084    
1085     if (update_arg( (void *)&(args_info->begin_arg),
1086     &(args_info->begin_orig), &(args_info->begin_given),
1087     &(local_args_info.begin_given), optarg, 0, 0, ARG_INT,
1088     check_ambiguity, override, 0, 0,
1089     "begin", '-',
1090     additional_error))
1091 gezelter 929 goto failure;
1092 gezelter 1390
1093 tim 544 }
1094     /* end internal index. */
1095     else if (strcmp (long_options[option_index].name, "end") == 0)
1096     {
1097 gezelter 1390
1098    
1099     if (update_arg( (void *)&(args_info->end_arg),
1100     &(args_info->end_orig), &(args_info->end_given),
1101     &(local_args_info.end_given), optarg, 0, 0, ARG_INT,
1102     check_ambiguity, override, 0, 0,
1103     "end", '-',
1104     additional_error))
1105 gezelter 929 goto failure;
1106 gezelter 1390
1107 tim 544 }
1108 chuckv 1091 /* nanoparticle radius. */
1109     else if (strcmp (long_options[option_index].name, "radius") == 0)
1110     {
1111 gezelter 1390
1112    
1113     if (update_arg( (void *)&(args_info->radius_arg),
1114     &(args_info->radius_orig), &(args_info->radius_given),
1115     &(local_args_info.radius_given), optarg, 0, 0, ARG_DOUBLE,
1116     check_ambiguity, override, 0, 0,
1117     "radius", '-',
1118     additional_error))
1119 chuckv 1091 goto failure;
1120 gezelter 1390
1121 chuckv 1091 }
1122 chuckv 1128 /* bond order parameter (--rcut must be specified). */
1123 gezelter 1041 else if (strcmp (long_options[option_index].name, "bo") == 0)
1124     {
1125 gezelter 1390
1126 gezelter 1041 if (args_info->staticProps_group_counter && override)
1127     reset_group_staticProps (args_info);
1128     args_info->staticProps_group_counter += 1;
1129 gezelter 1390
1130     if (update_arg( 0 ,
1131     0 , &(args_info->bo_given),
1132     &(local_args_info.bo_given), optarg, 0, 0, ARG_NO,
1133     check_ambiguity, override, 0, 0,
1134     "bo", '-',
1135     additional_error))
1136     goto failure;
1137    
1138 gezelter 1041 }
1139 chuckv 1128 /* bond order parameter as a function of radius (--rcut must be specified). */
1140     else if (strcmp (long_options[option_index].name, "bor") == 0)
1141     {
1142 gezelter 1390
1143 chuckv 1128 if (args_info->staticProps_group_counter && override)
1144     reset_group_staticProps (args_info);
1145     args_info->staticProps_group_counter += 1;
1146 gezelter 1390
1147     if (update_arg( 0 ,
1148     0 , &(args_info->bor_given),
1149     &(local_args_info.bor_given), optarg, 0, 0, ARG_NO,
1150     check_ambiguity, override, 0, 0,
1151     "bor", '-',
1152     additional_error))
1153     goto failure;
1154    
1155 chuckv 1128 }
1156 chuckv 1180 /* N(theta) bond angle density within (--rcut must be specified). */
1157     else if (strcmp (long_options[option_index].name, "bad") == 0)
1158     {
1159 gezelter 1390
1160 chuckv 1180 if (args_info->staticProps_group_counter && override)
1161     reset_group_staticProps (args_info);
1162     args_info->staticProps_group_counter += 1;
1163 gezelter 1390
1164     if (update_arg( 0 ,
1165     0 , &(args_info->bad_given),
1166     &(local_args_info.bad_given), optarg, 0, 0, ARG_NO,
1167     check_ambiguity, override, 0, 0,
1168     "bad", '-',
1169     additional_error))
1170     goto failure;
1171    
1172 chuckv 1180 }
1173 xsun 1213 /* g(z). */
1174     else if (strcmp (long_options[option_index].name, "gofz") == 0)
1175     {
1176 gezelter 1390
1177 xsun 1213 if (args_info->staticProps_group_counter && override)
1178     reset_group_staticProps (args_info);
1179     args_info->staticProps_group_counter += 1;
1180 gezelter 1390
1181     if (update_arg( 0 ,
1182     0 , &(args_info->gofz_given),
1183     &(local_args_info.gofz_given), optarg, 0, 0, ARG_NO,
1184     check_ambiguity, override, 0, 0,
1185     "gofz", '-',
1186     additional_error))
1187     goto failure;
1188    
1189 xsun 1213 }
1190 tim 310 /* g(r, cos(theta)). */
1191     else if (strcmp (long_options[option_index].name, "r_theta") == 0)
1192 tim 543 {
1193 gezelter 1390
1194 gezelter 929 if (args_info->staticProps_group_counter && override)
1195     reset_group_staticProps (args_info);
1196     args_info->staticProps_group_counter += 1;
1197 gezelter 1390
1198     if (update_arg( 0 ,
1199     0 , &(args_info->r_theta_given),
1200     &(local_args_info.r_theta_given), optarg, 0, 0, ARG_NO,
1201     check_ambiguity, override, 0, 0,
1202     "r_theta", '-',
1203     additional_error))
1204     goto failure;
1205    
1206 tim 543 }
1207 tim 310 /* g(r, cos(omega)). */
1208     else if (strcmp (long_options[option_index].name, "r_omega") == 0)
1209 tim 543 {
1210 gezelter 1390
1211 gezelter 929 if (args_info->staticProps_group_counter && override)
1212     reset_group_staticProps (args_info);
1213     args_info->staticProps_group_counter += 1;
1214 gezelter 1390
1215     if (update_arg( 0 ,
1216     0 , &(args_info->r_omega_given),
1217     &(local_args_info.r_omega_given), optarg, 0, 0, ARG_NO,
1218     check_ambiguity, override, 0, 0,
1219     "r_omega", '-',
1220     additional_error))
1221     goto failure;
1222    
1223 tim 543 }
1224 tim 310 /* g(cos(theta), cos(omega)). */
1225     else if (strcmp (long_options[option_index].name, "theta_omega") == 0)
1226 tim 543 {
1227 gezelter 1390
1228 gezelter 929 if (args_info->staticProps_group_counter && override)
1229     reset_group_staticProps (args_info);
1230     args_info->staticProps_group_counter += 1;
1231 gezelter 1390
1232     if (update_arg( 0 ,
1233     0 , &(args_info->theta_omega_given),
1234     &(local_args_info.theta_omega_given), optarg, 0, 0, ARG_NO,
1235     check_ambiguity, override, 0, 0,
1236     "theta_omega", '-',
1237     additional_error))
1238     goto failure;
1239    
1240 tim 543 }
1241 tim 310 /* g(x, y, z). */
1242 tim 369 else if (strcmp (long_options[option_index].name, "gxyz") == 0)
1243 tim 543 {
1244 gezelter 1390
1245 gezelter 929 if (args_info->staticProps_group_counter && override)
1246     reset_group_staticProps (args_info);
1247     args_info->staticProps_group_counter += 1;
1248 gezelter 1390
1249     if (update_arg( 0 ,
1250     0 , &(args_info->gxyz_given),
1251     &(local_args_info.gxyz_given), optarg, 0, 0, ARG_NO,
1252     check_ambiguity, override, 0, 0,
1253     "gxyz", '-',
1254     additional_error))
1255     goto failure;
1256    
1257 tim 543 }
1258 xsun 980 /* rp2 order parameter (--sele1 and --sele2 must be specified). */
1259     else if (strcmp (long_options[option_index].name, "rp2") == 0)
1260     {
1261 gezelter 1390
1262 xsun 980 if (args_info->staticProps_group_counter && override)
1263     reset_group_staticProps (args_info);
1264     args_info->staticProps_group_counter += 1;
1265 gezelter 1390
1266     if (update_arg( 0 ,
1267     0 , &(args_info->rp2_given),
1268     &(local_args_info.rp2_given), optarg, 0, 0, ARG_NO,
1269     check_ambiguity, override, 0, 0,
1270     "rp2", '-',
1271     additional_error))
1272     goto failure;
1273    
1274 xsun 980 }
1275 gezelter 1039 /* slab density. */
1276 tim 840 else if (strcmp (long_options[option_index].name, "slab_density") == 0)
1277     {
1278 gezelter 1390
1279 gezelter 929 if (args_info->staticProps_group_counter && override)
1280     reset_group_staticProps (args_info);
1281     args_info->staticProps_group_counter += 1;
1282 gezelter 1390
1283     if (update_arg( 0 ,
1284     0 , &(args_info->slab_density_given),
1285     &(local_args_info.slab_density_given), optarg, 0, 0, ARG_NO,
1286     check_ambiguity, override, 0, 0,
1287     "slab_density", '-',
1288     additional_error))
1289     goto failure;
1290    
1291 tim 840 }
1292 gezelter 1413 /* p(cos(theta)). */
1293     else if (strcmp (long_options[option_index].name, "p_angle") == 0)
1294     {
1295    
1296     if (args_info->staticProps_group_counter && override)
1297     reset_group_staticProps (args_info);
1298     args_info->staticProps_group_counter += 1;
1299    
1300     if (update_arg( 0 ,
1301     0 , &(args_info->p_angle_given),
1302     &(local_args_info.p_angle_given), optarg, 0, 0, ARG_NO,
1303     check_ambiguity, override, 0, 0,
1304     "p_angle", '-',
1305     additional_error))
1306     goto failure;
1307    
1308     }
1309 gezelter 1039 /* hxy. */
1310 xsun 955 else if (strcmp (long_options[option_index].name, "hxy") == 0)
1311     {
1312 gezelter 1390
1313 xsun 955 if (args_info->staticProps_group_counter && override)
1314     reset_group_staticProps (args_info);
1315     args_info->staticProps_group_counter += 1;
1316 gezelter 1390
1317     if (update_arg( 0 ,
1318     0 , &(args_info->hxy_given),
1319     &(local_args_info.hxy_given), optarg, 0, 0, ARG_NO,
1320     check_ambiguity, override, 0, 0,
1321     "hxy", '-',
1322     additional_error))
1323     goto failure;
1324    
1325 xsun 955 }
1326 chuckv 1091 /* rho of R. */
1327     else if (strcmp (long_options[option_index].name, "rho_r") == 0)
1328     {
1329 gezelter 1390
1330 chuckv 1091 if (args_info->staticProps_group_counter && override)
1331     reset_group_staticProps (args_info);
1332     args_info->staticProps_group_counter += 1;
1333 gezelter 1390
1334     if (update_arg( 0 ,
1335     0 , &(args_info->rho_r_given),
1336     &(local_args_info.rho_r_given), optarg, 0, 0, ARG_NO,
1337     check_ambiguity, override, 0, 0,
1338     "rho_r", '-',
1339     additional_error))
1340     goto failure;
1341    
1342 chuckv 1091 }
1343 chuckv 1180 /* hull volume of nanoparticle. */
1344     else if (strcmp (long_options[option_index].name, "hullvol") == 0)
1345     {
1346 gezelter 1390
1347 chuckv 1180 if (args_info->staticProps_group_counter && override)
1348     reset_group_staticProps (args_info);
1349     args_info->staticProps_group_counter += 1;
1350 gezelter 1390
1351     if (update_arg( 0 ,
1352     0 , &(args_info->hullvol_given),
1353     &(local_args_info.hullvol_given), optarg, 0, 0, ARG_NO,
1354     check_ambiguity, override, 0, 0,
1355     "hullvol", '-',
1356     additional_error))
1357     goto failure;
1358    
1359 chuckv 1180 }
1360 tim 840
1361 gezelter 929 break;
1362 tim 310 case '?': /* Invalid option. */
1363     /* `getopt_long' already printed an error message. */
1364 gezelter 929 goto failure;
1365 tim 310
1366     default: /* bug: option not considered. */
1367 gezelter 929 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1368 tim 310 abort ();
1369     } /* switch */
1370     } /* while */
1371    
1372 gezelter 929 if (args_info->staticProps_group_counter > 1)
1373 tim 310 {
1374 gezelter 929 fprintf (stderr, "%s: %d options of group staticProps were given. One is required.%s\n", argv[0], args_info->staticProps_group_counter, (additional_error ? additional_error : ""));
1375     error = 1;
1376 tim 310 }
1377    
1378    
1379 gezelter 929
1380     if (check_required)
1381 tim 310 {
1382 gezelter 929 error += cmdline_parser_required2 (args_info, argv[0], additional_error);
1383 tim 310 }
1384    
1385 gezelter 929 cmdline_parser_release (&local_args_info);
1386    
1387     if ( error )
1388     return (EXIT_FAILURE);
1389    
1390 gezelter 1413 if (optind < argc)
1391     {
1392     int i = 0 ;
1393     int found_prog_name = 0;
1394     /* whether program name, i.e., argv[0], is in the remaining args
1395     (this may happen with some implementations of getopt,
1396     but surely not with the one included by gengetopt) */
1397    
1398     i = optind;
1399     while (i < argc)
1400     if (argv[i++] == argv[0]) {
1401     found_prog_name = 1;
1402     break;
1403     }
1404     i = 0;
1405    
1406     args_info->inputs_num = argc - optind - found_prog_name;
1407     args_info->inputs =
1408     (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
1409     while (optind < argc)
1410     if (argv[optind++] != argv[0])
1411     args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
1412     }
1413    
1414 tim 310 return 0;
1415 gezelter 929
1416     failure:
1417    
1418     cmdline_parser_release (&local_args_info);
1419     return (EXIT_FAILURE);
1420 tim 310 }