ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-1.0/utils/Dump2XYZCmd.c
Revision: 1356
Committed: Mon Jul 19 21:58:37 2004 UTC (19 years, 11 months ago) by gezelter
Content type: text/plain
File size: 11755 byte(s)
Log Message:
*** empty log message ***

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