ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/applications/dump2Xyz/Dump2XYZCmd.c
Revision: 2204
Committed: Fri Apr 15 22:04:00 2005 UTC (19 years, 3 months ago) by gezelter
Content type: text/plain
File size: 12051 byte(s)
Log Message:
xemacs has been drafted to perform our indentation services

File Contents

# Content
1 /*
2 File autogenerated by gengetopt version 2.11
3 generated with the following command:
4 /home/maul/gezelter/tim/bin/gengetopt -F 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(" -w, --water skip the the waters (default=off)\n");
44 printf(" -m, --periodicBox map to the periodic box (default=off)\n");
45 printf(" -z, --zconstraint replace the atom types of zconstraint \n molecules (default=off)\n");
46 printf(" -r, --rigidbody add a pseudo COM atom to rigidbody \n (default=off)\n");
47 printf(" -t, --watertype replace the atom type of water model \n (default=on)\n");
48 printf(" -s, --selection=selection script general selection syntax\n");
49 printf(" --originsele=selection script select origin\n");
50 printf(" --refsele=selection script select reference\n");
51 printf(" --repeatX=INT The number of images to repeat in the x \n direction (default=`0')\n");
52 printf(" --repeatY=INT The number of images to repeat in the y \n direction (default=`0')\n");
53 printf(" --repeatZ=INT The number of images to repeat in the z \n direction (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 missing_required_options = 0;
76
77 args_info->help_given = 0 ;
78 args_info->version_given = 0 ;
79 args_info->input_given = 0 ;
80 args_info->output_given = 0 ;
81 args_info->frame_given = 0 ;
82 args_info->water_given = 0 ;
83 args_info->periodicBox_given = 0 ;
84 args_info->zconstraint_given = 0 ;
85 args_info->rigidbody_given = 0 ;
86 args_info->watertype_given = 0 ;
87 args_info->selection_given = 0 ;
88 args_info->originsele_given = 0 ;
89 args_info->refsele_given = 0 ;
90 args_info->repeatX_given = 0 ;
91 args_info->repeatY_given = 0 ;
92 args_info->repeatZ_given = 0 ;
93 #define clear_args() { \
94 args_info->input_arg = NULL; \
95 args_info->output_arg = NULL; \
96 args_info->frame_arg = 1 ; \
97 args_info->water_flag = 0; \
98 args_info->periodicBox_flag = 0; \
99 args_info->zconstraint_flag = 0; \
100 args_info->rigidbody_flag = 0; \
101 args_info->watertype_flag = 1; \
102 args_info->selection_arg = NULL; \
103 args_info->originsele_arg = NULL; \
104 args_info->refsele_arg = NULL; \
105 args_info->repeatX_arg = 0 ; \
106 args_info->repeatY_arg = 0 ; \
107 args_info->repeatZ_arg = 0 ; \
108 }
109
110 clear_args();
111
112 optarg = 0;
113 optind = 1;
114 opterr = 1;
115 optopt = '?';
116
117 while (1)
118 {
119 int option_index = 0;
120 char *stop_char;
121
122 static struct option long_options[] = {
123 { "help", 0, NULL, 'h' },
124 { "version", 0, NULL, 'V' },
125 { "input", 1, NULL, 'i' },
126 { "output", 1, NULL, 'o' },
127 { "frame", 1, NULL, 'n' },
128 { "water", 0, NULL, 'w' },
129 { "periodicBox", 0, NULL, 'm' },
130 { "zconstraint", 0, NULL, 'z' },
131 { "rigidbody", 0, NULL, 'r' },
132 { "watertype", 0, NULL, 't' },
133 { "selection", 1, NULL, 's' },
134 { "originsele", 1, NULL, 0 },
135 { "refsele", 1, NULL, 0 },
136 { "repeatX", 1, NULL, 0 },
137 { "repeatY", 1, NULL, 0 },
138 { "repeatZ", 1, NULL, 0 },
139 { NULL, 0, NULL, 0 }
140 };
141
142 stop_char = 0;
143 c = getopt_long (argc, argv, "hVi:o:n:wmzrts:", long_options, &option_index);
144
145 if (c == -1) break; /* Exit from `while (1)' loop. */
146
147 switch (c)
148 {
149 case 'h': /* Print help and exit. */
150 clear_args ();
151 cmdline_parser_print_help ();
152 exit (EXIT_SUCCESS);
153
154 case 'V': /* Print version and exit. */
155 clear_args ();
156 cmdline_parser_print_version ();
157 exit (EXIT_SUCCESS);
158
159 case 'i': /* input dump file. */
160 if (args_info->input_given)
161 {
162 fprintf (stderr, "%s: `--input' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE);
163 clear_args ();
164 exit (EXIT_FAILURE);
165 }
166 args_info->input_given = 1;
167 args_info->input_arg = gengetopt_strdup (optarg);
168 break;
169
170 case 'o': /* output file name. */
171 if (args_info->output_given)
172 {
173 fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE);
174 clear_args ();
175 exit (EXIT_FAILURE);
176 }
177 args_info->output_given = 1;
178 args_info->output_arg = gengetopt_strdup (optarg);
179 break;
180
181 case 'n': /* print every n frame. */
182 if (args_info->frame_given)
183 {
184 fprintf (stderr, "%s: `--frame' (`-n') option given more than once\n", CMDLINE_PARSER_PACKAGE);
185 clear_args ();
186 exit (EXIT_FAILURE);
187 }
188 args_info->frame_given = 1;
189 args_info->frame_arg = strtol (optarg,&stop_char,0);
190 break;
191
192 case 'w': /* skip the the waters. */
193 if (args_info->water_given)
194 {
195 fprintf (stderr, "%s: `--water' (`-w') option given more than once\n", CMDLINE_PARSER_PACKAGE);
196 clear_args ();
197 exit (EXIT_FAILURE);
198 }
199 args_info->water_given = 1;
200 args_info->water_flag = !(args_info->water_flag);
201 break;
202
203 case 'm': /* map to the periodic box. */
204 if (args_info->periodicBox_given)
205 {
206 fprintf (stderr, "%s: `--periodicBox' (`-m') option given more than once\n", CMDLINE_PARSER_PACKAGE);
207 clear_args ();
208 exit (EXIT_FAILURE);
209 }
210 args_info->periodicBox_given = 1;
211 args_info->periodicBox_flag = !(args_info->periodicBox_flag);
212 break;
213
214 case 'z': /* replace the atom types of zconstraint molecules. */
215 if (args_info->zconstraint_given)
216 {
217 fprintf (stderr, "%s: `--zconstraint' (`-z') option given more than once\n", CMDLINE_PARSER_PACKAGE);
218 clear_args ();
219 exit (EXIT_FAILURE);
220 }
221 args_info->zconstraint_given = 1;
222 args_info->zconstraint_flag = !(args_info->zconstraint_flag);
223 break;
224
225 case 'r': /* add a pseudo COM atom to rigidbody. */
226 if (args_info->rigidbody_given)
227 {
228 fprintf (stderr, "%s: `--rigidbody' (`-r') option given more than once\n", CMDLINE_PARSER_PACKAGE);
229 clear_args ();
230 exit (EXIT_FAILURE);
231 }
232 args_info->rigidbody_given = 1;
233 args_info->rigidbody_flag = !(args_info->rigidbody_flag);
234 break;
235
236 case 't': /* replace the atom type of water model. */
237 if (args_info->watertype_given)
238 {
239 fprintf (stderr, "%s: `--watertype' (`-t') option given more than once\n", CMDLINE_PARSER_PACKAGE);
240 clear_args ();
241 exit (EXIT_FAILURE);
242 }
243 args_info->watertype_given = 1;
244 args_info->watertype_flag = !(args_info->watertype_flag);
245 break;
246
247 case 's': /* general selection syntax. */
248 if (args_info->selection_given)
249 {
250 fprintf (stderr, "%s: `--selection' (`-s') option given more than once\n", CMDLINE_PARSER_PACKAGE);
251 clear_args ();
252 exit (EXIT_FAILURE);
253 }
254 args_info->selection_given = 1;
255 args_info->selection_arg = gengetopt_strdup (optarg);
256 break;
257
258
259 case 0: /* Long option with no short option */
260 /* select origin. */
261 if (strcmp (long_options[option_index].name, "originsele") == 0)
262 {
263 if (args_info->originsele_given)
264 {
265 fprintf (stderr, "%s: `--originsele' option given more than once\n", CMDLINE_PARSER_PACKAGE);
266 clear_args ();
267 exit (EXIT_FAILURE);
268 }
269 args_info->originsele_given = 1;
270 args_info->originsele_arg = gengetopt_strdup (optarg);
271 break;
272 }
273
274 /* select reference. */
275 else if (strcmp (long_options[option_index].name, "refsele") == 0)
276 {
277 if (args_info->refsele_given)
278 {
279 fprintf (stderr, "%s: `--refsele' option given more than once\n", CMDLINE_PARSER_PACKAGE);
280 clear_args ();
281 exit (EXIT_FAILURE);
282 }
283 args_info->refsele_given = 1;
284 args_info->refsele_arg = gengetopt_strdup (optarg);
285 break;
286 }
287
288 /* The number of images to repeat in the x direction. */
289 else if (strcmp (long_options[option_index].name, "repeatX") == 0)
290 {
291 if (args_info->repeatX_given)
292 {
293 fprintf (stderr, "%s: `--repeatX' option given more than once\n", CMDLINE_PARSER_PACKAGE);
294 clear_args ();
295 exit (EXIT_FAILURE);
296 }
297 args_info->repeatX_given = 1;
298 args_info->repeatX_arg = strtol (optarg,&stop_char,0);
299 break;
300 }
301
302 /* The number of images to repeat in the y direction. */
303 else if (strcmp (long_options[option_index].name, "repeatY") == 0)
304 {
305 if (args_info->repeatY_given)
306 {
307 fprintf (stderr, "%s: `--repeatY' option given more than once\n", CMDLINE_PARSER_PACKAGE);
308 clear_args ();
309 exit (EXIT_FAILURE);
310 }
311 args_info->repeatY_given = 1;
312 args_info->repeatY_arg = strtol (optarg,&stop_char,0);
313 break;
314 }
315
316 /* The number of images to repeat in the z direction. */
317 else if (strcmp (long_options[option_index].name, "repeatZ") == 0)
318 {
319 if (args_info->repeatZ_given)
320 {
321 fprintf (stderr, "%s: `--repeatZ' option given more than once\n", CMDLINE_PARSER_PACKAGE);
322 clear_args ();
323 exit (EXIT_FAILURE);
324 }
325 args_info->repeatZ_given = 1;
326 args_info->repeatZ_arg = strtol (optarg,&stop_char,0);
327 break;
328 }
329
330
331 case '?': /* Invalid option. */
332 /* `getopt_long' already printed an error message. */
333 exit (EXIT_FAILURE);
334
335 default: /* bug: option not considered. */
336 fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c);
337 abort ();
338 } /* switch */
339 } /* while */
340
341
342 if (! args_info->input_given)
343 {
344 fprintf (stderr, "%s: '--input' ('-i') option required\n", CMDLINE_PARSER_PACKAGE);
345 missing_required_options = 1;
346 }
347 if ( missing_required_options )
348 exit (EXIT_FAILURE);
349
350 return 0;
351 }