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