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

Properties

Name Value
svn:keywords Author Id Revision Date