ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/dynamicProps/DynamicPropsCmd.cpp
(Generate patch)

Comparing:
trunk/src/applications/dynamicProps/DynamicPropsCmd.c (file contents), Revision 1213 by xsun, Wed Jan 23 21:21:50 2008 UTC vs.
trunk/src/applications/dynamicProps/DynamicPropsCmd.cpp (file contents), Revision 1879 by gezelter, Sun Jun 16 15:15:42 2013 UTC

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

Comparing:
trunk/src/applications/dynamicProps/DynamicPropsCmd.c (property svn:keywords), Revision 1213 by xsun, Wed Jan 23 21:21:50 2008 UTC vs.
trunk/src/applications/dynamicProps/DynamicPropsCmd.cpp (property svn:keywords), Revision 1879 by gezelter, Sun Jun 16 15:15:42 2013 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines