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

File Contents

# User Rev Content
1 gezelter 2024 /*
2     File autogenerated by gengetopt version 2.22.4
3     generated with the following command:
4     gengetopt --file-name=SequentialPropsCmd --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:
8     we make no copyright claims on it.
9     */
10    
11     /* If we use autoconf. */
12     #ifdef HAVE_CONFIG_H
13     #include "config.h"
14     #endif
15    
16     #include <stdio.h>
17     #include <stdlib.h>
18     #include <string.h>
19    
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 "SequentialPropsCmd.h"
31    
32     const char *gengetopt_args_info_purpose = "";
33    
34     const char *gengetopt_args_info_usage = "Usage: SequentialProps [OPTIONS]... [FILES]...";
35    
36     const char *gengetopt_args_info_description = "";
37    
38     const char *gengetopt_args_info_help[] = {
39     " -h, --help Print help and exit",
40     " -V, --version Print version and exit",
41     " -i, --input=filename input dump file",
42     " -o, --output=filename output file name",
43     " --sele1=selection script select first stuntdouble set",
44     " --sele2=selection script select second stuntdouble set (if sele2 is not \n set, use script from sele1)",
45     " -n, --nbins=INT Number of bins (default=`100')",
46     "\n Group: sequentialProps\n an option of this group is required",
47     " -d, --density selection correlation function",
48     0
49     };
50    
51     typedef enum {ARG_NO
52     , ARG_STRING
53     , ARG_INT
54     } cmdline_parser_arg_type;
55    
56     static
57     void clear_given (struct gengetopt_args_info *args_info);
58     static
59     void clear_args (struct gengetopt_args_info *args_info);
60    
61     static int
62     cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
63     struct cmdline_parser_params *params, const char *additional_error);
64    
65     static int
66     cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
67    
68     static char *
69     gengetopt_strdup (const char *s);
70    
71     static
72     void clear_given (struct gengetopt_args_info *args_info)
73     {
74     args_info->help_given = 0 ;
75     args_info->version_given = 0 ;
76     args_info->input_given = 0 ;
77     args_info->output_given = 0 ;
78     args_info->sele1_given = 0 ;
79     args_info->sele2_given = 0 ;
80     args_info->nbins_given = 0 ;
81     args_info->density_given = 0 ;
82     args_info->sequentialProps_group_counter = 0 ;
83     }
84    
85     static
86     void clear_args (struct gengetopt_args_info *args_info)
87     {
88     FIX_UNUSED (args_info);
89     args_info->input_arg = NULL;
90     args_info->input_orig = NULL;
91     args_info->output_arg = NULL;
92     args_info->output_orig = NULL;
93     args_info->sele1_arg = NULL;
94     args_info->sele1_orig = NULL;
95     args_info->sele2_arg = NULL;
96     args_info->sele2_orig = NULL;
97     args_info->nbins_arg = 100;
98     args_info->nbins_orig = NULL;
99    
100     }
101    
102     static
103     void init_args_info(struct gengetopt_args_info *args_info)
104     {
105    
106    
107     args_info->help_help = gengetopt_args_info_help[0] ;
108     args_info->version_help = gengetopt_args_info_help[1] ;
109     args_info->input_help = gengetopt_args_info_help[2] ;
110     args_info->output_help = gengetopt_args_info_help[3] ;
111     args_info->sele1_help = gengetopt_args_info_help[4] ;
112     args_info->sele2_help = gengetopt_args_info_help[5] ;
113     args_info->nbins_help = gengetopt_args_info_help[6] ;
114     args_info->density_help = gengetopt_args_info_help[8] ;
115    
116     }
117    
118     void
119     cmdline_parser_print_version (void)
120     {
121     printf ("%s %s\n",
122     (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
123     CMDLINE_PARSER_VERSION);
124     }
125    
126     static void print_help_common(void) {
127     cmdline_parser_print_version ();
128    
129     if (strlen(gengetopt_args_info_purpose) > 0)
130     printf("\n%s\n", gengetopt_args_info_purpose);
131    
132     if (strlen(gengetopt_args_info_usage) > 0)
133     printf("\n%s\n", gengetopt_args_info_usage);
134    
135     printf("\n");
136    
137     if (strlen(gengetopt_args_info_description) > 0)
138     printf("%s\n\n", gengetopt_args_info_description);
139     }
140    
141     void
142     cmdline_parser_print_help (void)
143     {
144     int i = 0;
145     print_help_common();
146     while (gengetopt_args_info_help[i])
147     printf("%s\n", gengetopt_args_info_help[i++]);
148     }
149    
150     void
151     cmdline_parser_init (struct gengetopt_args_info *args_info)
152     {
153     clear_given (args_info);
154     clear_args (args_info);
155     init_args_info (args_info);
156    
157     args_info->inputs = 0;
158     args_info->inputs_num = 0;
159     }
160    
161     void
162     cmdline_parser_params_init(struct cmdline_parser_params *params)
163     {
164     if (params)
165     {
166     params->override = 0;
167     params->initialize = 1;
168     params->check_required = 1;
169     params->check_ambiguity = 0;
170     params->print_errors = 1;
171     }
172     }
173    
174     struct cmdline_parser_params *
175     cmdline_parser_params_create(void)
176     {
177     struct cmdline_parser_params *params =
178     (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
179     cmdline_parser_params_init(params);
180     return params;
181     }
182    
183     static void
184     free_string_field (char **s)
185     {
186     if (*s)
187     {
188     free (*s);
189     *s = 0;
190     }
191     }
192    
193    
194     static void
195     cmdline_parser_release (struct gengetopt_args_info *args_info)
196     {
197     unsigned int i;
198     free_string_field (&(args_info->input_arg));
199     free_string_field (&(args_info->input_orig));
200     free_string_field (&(args_info->output_arg));
201     free_string_field (&(args_info->output_orig));
202     free_string_field (&(args_info->sele1_arg));
203     free_string_field (&(args_info->sele1_orig));
204     free_string_field (&(args_info->sele2_arg));
205     free_string_field (&(args_info->sele2_orig));
206     free_string_field (&(args_info->nbins_orig));
207    
208    
209     for (i = 0; i < args_info->inputs_num; ++i)
210     free (args_info->inputs [i]);
211    
212     if (args_info->inputs_num)
213     free (args_info->inputs);
214    
215     clear_given (args_info);
216     }
217    
218    
219     static void
220     write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
221     {
222     FIX_UNUSED (values);
223     if (arg) {
224     fprintf(outfile, "%s=\"%s\"\n", opt, arg);
225     } else {
226     fprintf(outfile, "%s\n", opt);
227     }
228     }
229    
230    
231     int
232     cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
233     {
234     int i = 0;
235    
236     if (!outfile)
237     {
238     fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
239     return EXIT_FAILURE;
240     }
241    
242     if (args_info->help_given)
243     write_into_file(outfile, "help", 0, 0 );
244     if (args_info->version_given)
245     write_into_file(outfile, "version", 0, 0 );
246     if (args_info->input_given)
247     write_into_file(outfile, "input", args_info->input_orig, 0);
248     if (args_info->output_given)
249     write_into_file(outfile, "output", args_info->output_orig, 0);
250     if (args_info->sele1_given)
251     write_into_file(outfile, "sele1", args_info->sele1_orig, 0);
252     if (args_info->sele2_given)
253     write_into_file(outfile, "sele2", args_info->sele2_orig, 0);
254     if (args_info->nbins_given)
255     write_into_file(outfile, "nbins", args_info->nbins_orig, 0);
256     if (args_info->density_given)
257     write_into_file(outfile, "density", 0, 0 );
258    
259    
260     i = EXIT_SUCCESS;
261     return i;
262     }
263    
264     int
265     cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
266     {
267     FILE *outfile;
268     int i = 0;
269    
270     outfile = fopen(filename, "w");
271    
272     if (!outfile)
273     {
274     fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
275     return EXIT_FAILURE;
276     }
277    
278     i = cmdline_parser_dump(outfile, args_info);
279     fclose (outfile);
280    
281     return i;
282     }
283    
284     void
285     cmdline_parser_free (struct gengetopt_args_info *args_info)
286     {
287     cmdline_parser_release (args_info);
288     }
289    
290     /** @brief replacement of strdup, which is not standard */
291     char *
292     gengetopt_strdup (const char *s)
293     {
294     char *result = 0;
295     if (!s)
296     return result;
297    
298     result = (char*)malloc(strlen(s) + 1);
299     if (result == (char*)0)
300     return (char*)0;
301     strcpy(result, s);
302     return result;
303     }
304    
305     static void
306     reset_group_sequentialProps(struct gengetopt_args_info *args_info)
307     {
308     if (! args_info->sequentialProps_group_counter)
309     return;
310    
311     args_info->density_given = 0 ;
312    
313     args_info->sequentialProps_group_counter = 0;
314     }
315    
316     int
317     cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
318     {
319     return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
320     }
321    
322     int
323     cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
324     struct cmdline_parser_params *params)
325     {
326     int result;
327     result = cmdline_parser_internal (argc, argv, args_info, params, 0);
328    
329     if (result == EXIT_FAILURE)
330     {
331     cmdline_parser_free (args_info);
332     exit (EXIT_FAILURE);
333     }
334    
335     return result;
336     }
337    
338     int
339     cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
340     {
341     int result;
342     struct cmdline_parser_params params;
343    
344     params.override = override;
345     params.initialize = initialize;
346     params.check_required = check_required;
347     params.check_ambiguity = 0;
348     params.print_errors = 1;
349    
350     result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
351    
352     if (result == EXIT_FAILURE)
353     {
354     cmdline_parser_free (args_info);
355     exit (EXIT_FAILURE);
356     }
357    
358     return result;
359     }
360    
361     int
362     cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
363     {
364     int result = EXIT_SUCCESS;
365    
366     if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
367     result = EXIT_FAILURE;
368    
369     if (result == EXIT_FAILURE)
370     {
371     cmdline_parser_free (args_info);
372     exit (EXIT_FAILURE);
373     }
374    
375     return result;
376     }
377    
378     int
379     cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
380     {
381     int error = 0;
382     FIX_UNUSED (additional_error);
383    
384     /* checks for required options */
385     if (! args_info->input_given)
386     {
387     fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
388     error = 1;
389     }
390    
391     if (args_info->sequentialProps_group_counter == 0)
392     {
393     fprintf (stderr, "%s: %d options of group sequentialProps were given. One is required%s.\n", prog_name, args_info->sequentialProps_group_counter, (additional_error ? additional_error : ""));
394     error = 1;
395     }
396    
397    
398     /* checks for dependences among options */
399    
400     return error;
401     }
402    
403    
404     static char *package_name = 0;
405    
406     /**
407     * @brief updates an option
408     * @param field the generic pointer to the field to update
409     * @param orig_field the pointer to the orig field
410     * @param field_given the pointer to the number of occurrence of this option
411     * @param prev_given the pointer to the number of occurrence already seen
412     * @param value the argument for this option (if null no arg was specified)
413     * @param possible_values the possible values for this option (if specified)
414     * @param default_value the default value (in case the option only accepts fixed values)
415     * @param arg_type the type of this option
416     * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
417     * @param override @see cmdline_parser_params.override
418     * @param no_free whether to free a possible previous value
419     * @param multiple_option whether this is a multiple option
420     * @param long_opt the corresponding long option
421     * @param short_opt the corresponding short option (or '-' if none)
422     * @param additional_error possible further error specification
423     */
424     static
425     int update_arg(void *field, char **orig_field,
426     unsigned int *field_given, unsigned int *prev_given,
427     char *value, const char *possible_values[],
428     const char *default_value,
429     cmdline_parser_arg_type arg_type,
430     int check_ambiguity, int override,
431     int no_free, int multiple_option,
432     const char *long_opt, char short_opt,
433     const char *additional_error)
434     {
435     char *stop_char = 0;
436     const char *val = value;
437     int found;
438     char **string_field;
439     FIX_UNUSED (field);
440    
441     stop_char = 0;
442     found = 0;
443    
444     if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
445     {
446     if (short_opt != '-')
447     fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
448     package_name, long_opt, short_opt,
449     (additional_error ? additional_error : ""));
450     else
451     fprintf (stderr, "%s: `--%s' option given more than once%s\n",
452     package_name, long_opt,
453     (additional_error ? additional_error : ""));
454     return 1; /* failure */
455     }
456    
457     FIX_UNUSED (default_value);
458    
459     if (field_given && *field_given && ! override)
460     return 0;
461     if (prev_given)
462     (*prev_given)++;
463     if (field_given)
464     (*field_given)++;
465     if (possible_values)
466     val = possible_values[found];
467    
468     switch(arg_type) {
469     case ARG_INT:
470     if (val) *((int *)field) = strtol (val, &stop_char, 0);
471     break;
472     case ARG_STRING:
473     if (val) {
474     string_field = (char **)field;
475     if (!no_free && *string_field)
476     free (*string_field); /* free previous string */
477     *string_field = gengetopt_strdup (val);
478     }
479     break;
480     default:
481     break;
482     };
483    
484     /* check numeric conversion */
485     switch(arg_type) {
486     case ARG_INT:
487     if (val && !(stop_char && *stop_char == '\0')) {
488     fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
489     return 1; /* failure */
490     }
491     break;
492     default:
493     ;
494     };
495    
496     /* store the original value */
497     switch(arg_type) {
498     case ARG_NO:
499     break;
500     default:
501     if (value && orig_field) {
502     if (no_free) {
503     *orig_field = value;
504     } else {
505     if (*orig_field)
506     free (*orig_field); /* free previous string */
507     *orig_field = gengetopt_strdup (value);
508     }
509     }
510     };
511    
512     return 0; /* OK */
513     }
514    
515    
516     int
517     cmdline_parser_internal (
518     int argc, char **argv, struct gengetopt_args_info *args_info,
519     struct cmdline_parser_params *params, const char *additional_error)
520     {
521     int c; /* Character of the parsed option. */
522    
523     int error = 0;
524     struct gengetopt_args_info local_args_info;
525    
526     int override;
527     int initialize;
528     int check_required;
529     int check_ambiguity;
530    
531     package_name = argv[0];
532    
533     override = params->override;
534     initialize = params->initialize;
535     check_required = params->check_required;
536     check_ambiguity = params->check_ambiguity;
537    
538     if (initialize)
539     cmdline_parser_init (args_info);
540    
541     cmdline_parser_init (&local_args_info);
542    
543     optarg = 0;
544     optind = 0;
545     opterr = params->print_errors;
546     optopt = '?';
547    
548     while (1)
549     {
550     int option_index = 0;
551    
552     static struct option long_options[] = {
553     { "help", 0, NULL, 'h' },
554     { "version", 0, NULL, 'V' },
555     { "input", 1, NULL, 'i' },
556     { "output", 1, NULL, 'o' },
557     { "sele1", 1, NULL, 0 },
558     { "sele2", 1, NULL, 0 },
559     { "nbins", 1, NULL, 'n' },
560     { "density", 0, NULL, 'd' },
561     { 0, 0, 0, 0 }
562     };
563    
564     c = getopt_long (argc, argv, "hVi:o:n:d", long_options, &option_index);
565    
566     if (c == -1) break; /* Exit from `while (1)' loop. */
567    
568     switch (c)
569     {
570     case 'h': /* Print help and exit. */
571     cmdline_parser_print_help ();
572     cmdline_parser_free (&local_args_info);
573     exit (EXIT_SUCCESS);
574    
575     case 'V': /* Print version and exit. */
576     cmdline_parser_print_version ();
577     cmdline_parser_free (&local_args_info);
578     exit (EXIT_SUCCESS);
579    
580     case 'i': /* input dump file. */
581    
582    
583     if (update_arg( (void *)&(args_info->input_arg),
584     &(args_info->input_orig), &(args_info->input_given),
585     &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
586     check_ambiguity, override, 0, 0,
587     "input", 'i',
588     additional_error))
589     goto failure;
590    
591     break;
592     case 'o': /* output file name. */
593    
594    
595     if (update_arg( (void *)&(args_info->output_arg),
596     &(args_info->output_orig), &(args_info->output_given),
597     &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
598     check_ambiguity, override, 0, 0,
599     "output", 'o',
600     additional_error))
601     goto failure;
602    
603     break;
604     case 'n': /* Number of bins. */
605    
606    
607     if (update_arg( (void *)&(args_info->nbins_arg),
608     &(args_info->nbins_orig), &(args_info->nbins_given),
609     &(local_args_info.nbins_given), optarg, 0, "100", ARG_INT,
610     check_ambiguity, override, 0, 0,
611     "nbins", 'n',
612     additional_error))
613     goto failure;
614    
615     break;
616     case 'd': /* selection correlation function. */
617    
618     if (args_info->sequentialProps_group_counter && override)
619     reset_group_sequentialProps (args_info);
620     args_info->sequentialProps_group_counter += 1;
621    
622     if (update_arg( 0 ,
623     0 , &(args_info->density_given),
624     &(local_args_info.density_given), optarg, 0, 0, ARG_NO,
625     check_ambiguity, override, 0, 0,
626     "density", 'd',
627     additional_error))
628     goto failure;
629    
630     break;
631    
632     case 0: /* Long option with no short option */
633     /* select first stuntdouble set. */
634     if (strcmp (long_options[option_index].name, "sele1") == 0)
635     {
636    
637    
638     if (update_arg( (void *)&(args_info->sele1_arg),
639     &(args_info->sele1_orig), &(args_info->sele1_given),
640     &(local_args_info.sele1_given), optarg, 0, 0, ARG_STRING,
641     check_ambiguity, override, 0, 0,
642     "sele1", '-',
643     additional_error))
644     goto failure;
645    
646     }
647     /* select second stuntdouble set (if sele2 is not set, use script from sele1). */
648     else if (strcmp (long_options[option_index].name, "sele2") == 0)
649     {
650    
651    
652     if (update_arg( (void *)&(args_info->sele2_arg),
653     &(args_info->sele2_orig), &(args_info->sele2_given),
654     &(local_args_info.sele2_given), optarg, 0, 0, ARG_STRING,
655     check_ambiguity, override, 0, 0,
656     "sele2", '-',
657     additional_error))
658     goto failure;
659    
660     }
661    
662     break;
663     case '?': /* Invalid option. */
664     /* `getopt_long' already printed an error message. */
665     goto failure;
666    
667     default: /* bug: option not considered. */
668     fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
669     abort ();
670     } /* switch */
671     } /* while */
672    
673     if (args_info->sequentialProps_group_counter > 1)
674     {
675     fprintf (stderr, "%s: %d options of group sequentialProps were given. One is required%s.\n", argv[0], args_info->sequentialProps_group_counter, (additional_error ? additional_error : ""));
676     error = 1;
677     }
678    
679    
680    
681     if (check_required)
682     {
683     error += cmdline_parser_required2 (args_info, argv[0], additional_error);
684     }
685    
686     cmdline_parser_release (&local_args_info);
687    
688     if ( error )
689     return (EXIT_FAILURE);
690    
691     if (optind < argc)
692     {
693     int i = 0 ;
694     int found_prog_name = 0;
695     /* whether program name, i.e., argv[0], is in the remaining args
696     (this may happen with some implementations of getopt,
697     but surely not with the one included by gengetopt) */
698    
699     i = optind;
700     while (i < argc)
701     if (argv[i++] == argv[0]) {
702     found_prog_name = 1;
703     break;
704     }
705     i = 0;
706    
707     args_info->inputs_num = argc - optind - found_prog_name;
708     args_info->inputs =
709     (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
710     while (optind < argc)
711     if (argv[optind++] != argv[0])
712     args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
713     }
714    
715     return 0;
716    
717     failure:
718    
719     cmdline_parser_release (&local_args_info);
720     return (EXIT_FAILURE);
721     }

Properties

Name Value
svn:eol-style native