ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-1.0/utils/Dump2XYZCmd.c
Revision: 1334
Committed: Fri Jul 16 18:58:03 2004 UTC (19 years, 11 months ago) by gezelter
Content type: text/plain
File size: 11754 byte(s)
Log Message:
Initial import of OOPSE-1.0 source tree

File Contents

# User Rev Content
1 gezelter 1334 /*
2     File autogenerated by gengetopt version 2.11
3     generated with the following command:
4     /home/maul/gezelter/tim/program/gengetopt-2.11/src/gengetopt --file-name=Dump2XYZCmd
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    
12     #include <stdio.h>
13     #include <stdlib.h>
14     #include <string.h>
15    
16     /* If we use autoconf. */
17     #ifdef HAVE_CONFIG_H
18     #include "config.h"
19     #endif
20    
21     #include "getopt.h"
22    
23     #include "Dump2XYZCmd.h"
24    
25     void
26     cmdline_parser_print_version (void)
27     {
28     printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
29     }
30    
31     void
32     cmdline_parser_print_help (void)
33     {
34     cmdline_parser_print_version ();
35     printf("\n"
36     "Usage: %s [OPTIONS]...\n", CMDLINE_PARSER_PACKAGE);
37     printf("\n");
38     printf(" -h, --help Print help and exit\n");
39     printf(" -V, --version Print version and exit\n");
40     printf(" -i, --input=filename input dump file\n");
41     printf(" -o, --output=filename output file name\n");
42     printf(" -n, --frame=INT print every n frame (default=`1')\n");
43     printf(" -d, --dipole print the dipole moments (default=off)\n");
44     printf(" -w, --water skip the the waters (default=off)\n");
45     printf(" -m, --periodicBox map to the periodic box (default=off)\n");
46     printf(" -z, --zconstraint replace the atom types of zconstraint molecules \n (default=off)\n");
47     printf(" -r, --rigidbody add a pseudo COM atom to rigidbody (default=off)\n");
48     printf(" -t, --watertype replace the atom type of water model (default=on)\n");
49     printf(" -s, --ignore=atomtype ignore the atom types\n");
50     printf(" --repeatX=INT The number of images to repeat in the x direction \n (default=`0')\n");
51     printf(" --repeatY=INT The number of images to repeat in the y direction \n (default=`0')\n");
52     printf(" --repeatZ=INT The number of images to repeat in the z direction \n (default=`0')\n");
53     }
54    
55    
56     static char *gengetopt_strdup (const char *s);
57    
58     /* gengetopt_strdup() */
59     /* strdup.c replacement of strdup, which is not standard */
60     char *
61     gengetopt_strdup (const char *s)
62     {
63     char *result = (char*)malloc(strlen(s) + 1);
64     if (result == (char*)0)
65     return (char*)0;
66     strcpy(result, s);
67     return result;
68     }
69    
70     int
71     cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
72     {
73     int c; /* Character of the parsed option. */
74     int i; /* Counter */
75     struct ignore_list
76     {
77     char * ignore_arg;
78     struct ignore_list * next;
79     };
80     struct ignore_list * ignore_list = NULL,* ignore_new = NULL;
81    
82     int missing_required_options = 0;
83    
84     args_info->help_given = 0 ;
85     args_info->version_given = 0 ;
86     args_info->input_given = 0 ;
87     args_info->output_given = 0 ;
88     args_info->frame_given = 0 ;
89     args_info->dipole_given = 0 ;
90     args_info->water_given = 0 ;
91     args_info->periodicBox_given = 0 ;
92     args_info->zconstraint_given = 0 ;
93     args_info->rigidbody_given = 0 ;
94     args_info->watertype_given = 0 ;
95     args_info->ignore_given = 0 ;
96     args_info->repeatX_given = 0 ;
97     args_info->repeatY_given = 0 ;
98     args_info->repeatZ_given = 0 ;
99     #define clear_args() { \
100     args_info->input_arg = NULL; \
101     args_info->output_arg = NULL; \
102     args_info->frame_arg = 1 ;\
103     args_info->dipole_flag = 0;\
104     args_info->water_flag = 0;\
105     args_info->periodicBox_flag = 0;\
106     args_info->zconstraint_flag = 0;\
107     args_info->rigidbody_flag = 0;\
108     args_info->watertype_flag = 1;\
109     args_info->ignore_arg = NULL; \
110     args_info->repeatX_arg = 0 ;\
111     args_info->repeatY_arg = 0 ;\
112     args_info->repeatZ_arg = 0 ;\
113     }
114    
115     clear_args();
116    
117     optarg = 0;
118     optind = 1;
119     opterr = 1;
120     optopt = '?';
121    
122     while (1)
123     {
124     int option_index = 0;
125     char *stop_char;
126    
127     static struct option long_options[] = {
128     { "help", 0, NULL, 'h' },
129     { "version", 0, NULL, 'V' },
130     { "input", 1, NULL, 'i' },
131     { "output", 1, NULL, 'o' },
132     { "frame", 1, NULL, 'n' },
133     { "dipole", 0, NULL, 'd' },
134     { "water", 0, NULL, 'w' },
135     { "periodicBox", 0, NULL, 'm' },
136     { "zconstraint", 0, NULL, 'z' },
137     { "rigidbody", 0, NULL, 'r' },
138     { "watertype", 0, NULL, 't' },
139     { "ignore", 1, NULL, 's' },
140     { "repeatX", 1, NULL, 0 },
141     { "repeatY", 1, NULL, 0 },
142     { "repeatZ", 1, NULL, 0 },
143     { NULL, 0, NULL, 0 }
144     };
145    
146     stop_char = 0;
147     c = getopt_long (argc, argv, "hVi:o:n:dwmzrts:", long_options, &option_index);
148    
149     if (c == -1) break; /* Exit from `while (1)' loop. */
150    
151     switch (c)
152     {
153     case 'h': /* Print help and exit. */
154     clear_args ();
155     cmdline_parser_print_help ();
156     exit (EXIT_SUCCESS);
157    
158     case 'V': /* Print version and exit. */
159     clear_args ();
160     cmdline_parser_print_version ();
161     exit (EXIT_SUCCESS);
162    
163     case 'i': /* input dump file. */
164     if (args_info->input_given)
165     {
166     fprintf (stderr, "%s: `--input' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE);
167     clear_args ();
168     exit (EXIT_FAILURE);
169     }
170     args_info->input_given = 1;
171     args_info->input_arg = gengetopt_strdup (optarg);
172     break;
173    
174     case 'o': /* output file name. */
175     if (args_info->output_given)
176     {
177     fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE);
178     clear_args ();
179     exit (EXIT_FAILURE);
180     }
181     args_info->output_given = 1;
182     args_info->output_arg = gengetopt_strdup (optarg);
183     break;
184    
185     case 'n': /* print every n frame. */
186     if (args_info->frame_given)
187     {
188     fprintf (stderr, "%s: `--frame' (`-n') option given more than once\n", CMDLINE_PARSER_PACKAGE);
189     clear_args ();
190     exit (EXIT_FAILURE);
191     }
192     args_info->frame_given = 1;
193     args_info->frame_arg = strtol (optarg,&stop_char,0);
194     break;
195    
196     case 'd': /* print the dipole moments. */
197     if (args_info->dipole_given)
198     {
199     fprintf (stderr, "%s: `--dipole' (`-d') option given more than once\n", CMDLINE_PARSER_PACKAGE);
200     clear_args ();
201     exit (EXIT_FAILURE);
202     }
203     args_info->dipole_given = 1;
204     args_info->dipole_flag = !(args_info->dipole_flag);
205     break;
206    
207     case 'w': /* skip the the waters. */
208     if (args_info->water_given)
209     {
210     fprintf (stderr, "%s: `--water' (`-w') option given more than once\n", CMDLINE_PARSER_PACKAGE);
211     clear_args ();
212     exit (EXIT_FAILURE);
213     }
214     args_info->water_given = 1;
215     args_info->water_flag = !(args_info->water_flag);
216     break;
217    
218     case 'm': /* map to the periodic box. */
219     if (args_info->periodicBox_given)
220     {
221     fprintf (stderr, "%s: `--periodicBox' (`-m') option given more than once\n", CMDLINE_PARSER_PACKAGE);
222     clear_args ();
223     exit (EXIT_FAILURE);
224     }
225     args_info->periodicBox_given = 1;
226     args_info->periodicBox_flag = !(args_info->periodicBox_flag);
227     break;
228    
229     case 'z': /* replace the atom types of zconstraint molecules. */
230     if (args_info->zconstraint_given)
231     {
232     fprintf (stderr, "%s: `--zconstraint' (`-z') option given more than once\n", CMDLINE_PARSER_PACKAGE);
233     clear_args ();
234     exit (EXIT_FAILURE);
235     }
236     args_info->zconstraint_given = 1;
237     args_info->zconstraint_flag = !(args_info->zconstraint_flag);
238     break;
239    
240     case 'r': /* add a pseudo COM atom to rigidbody. */
241     if (args_info->rigidbody_given)
242     {
243     fprintf (stderr, "%s: `--rigidbody' (`-r') option given more than once\n", CMDLINE_PARSER_PACKAGE);
244     clear_args ();
245     exit (EXIT_FAILURE);
246     }
247     args_info->rigidbody_given = 1;
248     args_info->rigidbody_flag = !(args_info->rigidbody_flag);
249     break;
250    
251     case 't': /* replace the atom type of water model. */
252     if (args_info->watertype_given)
253     {
254     fprintf (stderr, "%s: `--watertype' (`-t') option given more than once\n", CMDLINE_PARSER_PACKAGE);
255     clear_args ();
256     exit (EXIT_FAILURE);
257     }
258     args_info->watertype_given = 1;
259     args_info->watertype_flag = !(args_info->watertype_flag);
260     break;
261    
262     case 's': /* ignore the atom types. */
263     args_info->ignore_given++;
264     ignore_new = (struct ignore_list *) malloc (sizeof (struct ignore_list));
265     ignore_new->next = ignore_list;
266     ignore_list = ignore_new;
267     ignore_new->ignore_arg = gengetopt_strdup (optarg);
268     break;
269    
270    
271     case 0: /* Long option with no short option */
272     /* The number of images to repeat in the x direction. */
273     if (strcmp (long_options[option_index].name, "repeatX") == 0)
274     {
275     if (args_info->repeatX_given)
276     {
277     fprintf (stderr, "%s: `--repeatX' option given more than once\n", CMDLINE_PARSER_PACKAGE);
278     clear_args ();
279     exit (EXIT_FAILURE);
280     }
281     args_info->repeatX_given = 1;
282     args_info->repeatX_arg = strtol (optarg,&stop_char,0);
283     break;
284     }
285    
286     /* The number of images to repeat in the y direction. */
287     else if (strcmp (long_options[option_index].name, "repeatY") == 0)
288     {
289     if (args_info->repeatY_given)
290     {
291     fprintf (stderr, "%s: `--repeatY' option given more than once\n", CMDLINE_PARSER_PACKAGE);
292     clear_args ();
293     exit (EXIT_FAILURE);
294     }
295     args_info->repeatY_given = 1;
296     args_info->repeatY_arg = strtol (optarg,&stop_char,0);
297     break;
298     }
299    
300     /* The number of images to repeat in the z direction. */
301     else if (strcmp (long_options[option_index].name, "repeatZ") == 0)
302     {
303     if (args_info->repeatZ_given)
304     {
305     fprintf (stderr, "%s: `--repeatZ' option given more than once\n", CMDLINE_PARSER_PACKAGE);
306     clear_args ();
307     exit (EXIT_FAILURE);
308     }
309     args_info->repeatZ_given = 1;
310     args_info->repeatZ_arg = strtol (optarg,&stop_char,0);
311     break;
312     }
313    
314    
315     case '?': /* Invalid option. */
316     /* `getopt_long' already printed an error message. */
317     exit (EXIT_FAILURE);
318    
319     default: /* bug: option not considered. */
320     fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c);
321     abort ();
322     } /* switch */
323     } /* while */
324    
325    
326     if (! args_info->input_given)
327     {
328     fprintf (stderr, "%s: '--input' ('-i') option required\n", CMDLINE_PARSER_PACKAGE);
329     missing_required_options = 1;
330     }
331     if ( missing_required_options )
332     exit (EXIT_FAILURE);
333    
334     if (args_info->ignore_given)
335     {
336     args_info->ignore_arg = (char * *) malloc (args_info->ignore_given * sizeof (char *));
337     for (i = 0; i < args_info->ignore_given; i++)
338     {
339     args_info->ignore_arg [i] = ignore_list->ignore_arg;
340     ignore_list = ignore_list->next;
341     }
342     }
343    
344     return 0;
345     }