ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/dynamicProps/DynamicPropsCmd.c
Revision: 3235
Committed: Tue Oct 2 12:05:25 2007 UTC (16 years, 9 months ago) by xsun
Content type: text/plain
File size: 22247 byte(s)
Log Message:
Added: Action Correlation function (for viscosity), Directional RCorr (for
non-spherical bodies)
Modified: LCorr (for multiple axes)

File Contents

# Content
1 /*
2 File autogenerated by gengetopt version 2.16
3 generated with the following command:
4 gengetopt -F DynamicPropsCmd
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 #include "getopt.h"
21
22 #include "DynamicPropsCmd.h"
23
24 static
25 void clear_given (struct gengetopt_args_info *args_info);
26 static
27 void clear_args (struct gengetopt_args_info *args_info);
28
29 static int
30 cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error);
31
32 static int
33 cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
34
35 static char *
36 gengetopt_strdup (const char *s);
37
38 static
39 void clear_given (struct gengetopt_args_info *args_info)
40 {
41 args_info->help_given = 0 ;
42 args_info->version_given = 0 ;
43 args_info->input_given = 0 ;
44 args_info->output_given = 0 ;
45 args_info->sele1_given = 0 ;
46 args_info->sele2_given = 0 ;
47 args_info->order_given = 0 ;
48 args_info->rcorr_given = 0 ;
49 args_info->vcorr_given = 0 ;
50 args_info->dcorr_given = 0 ;
51 args_info->lcorr_given = 0 ;
52 args_info->r_rcorr_given = 0 ;
53 args_info->thetacorr_given = 0 ;
54 args_info->actioncorr_given = 0 ;
55 args_info->drcorr_given = 0 ;
56 args_info->dynamicProps_group_counter = 0 ;
57 }
58
59 static
60 void clear_args (struct gengetopt_args_info *args_info)
61 {
62 args_info->input_arg = NULL;
63 args_info->input_orig = NULL;
64 args_info->output_arg = NULL;
65 args_info->output_orig = NULL;
66 args_info->sele1_arg = NULL;
67 args_info->sele1_orig = NULL;
68 args_info->sele2_arg = NULL;
69 args_info->sele2_orig = NULL;
70 args_info->order_orig = NULL;
71
72 }
73
74 void
75 cmdline_parser_print_version (void)
76 {
77 printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
78 }
79
80 void
81 cmdline_parser_print_help (void)
82 {
83 cmdline_parser_print_version ();
84 printf("\nUsage: DynamicProps [OPTIONS]...\n\n");
85 printf("%s\n"," -h, --help Print help and exit");
86 printf("%s\n"," -V, --version Print version and exit");
87 printf("%s\n"," -i, --input=filename input dump file");
88 printf("%s\n"," -o, --output=filename output file name");
89 printf("%s\n"," --sele1=selection script select first stuntdouble set");
90 printf("%s\n"," --sele2=selection script select second stuntdouble set (if sele2 is not \n set, use script from sele1)");
91 printf("%s\n"," --order=INT Lengendre Polynomial Order");
92 printf("%s\n","\n Group: dynamicProps\n an option of this group is required");
93 printf("%s\n"," -r, --rcorr rmsd");
94 printf("%s\n"," -v, --vcorr velocity correlation function");
95 printf("%s\n"," -d, --dcorr dipole correlation function");
96 printf("%s\n"," -l, --lcorr Lengendre correlation function");
97 printf("%s\n"," --r_rcorr Radial rmsd");
98 printf("%s\n"," --thetacorr Angular rmsd");
99 printf("%s\n"," --actioncorr Action correlation function");
100 printf("%s\n"," --drcorr Directional rmsd for particles with unit \n vectors");
101
102 }
103
104 void
105 cmdline_parser_init (struct gengetopt_args_info *args_info)
106 {
107 clear_given (args_info);
108 clear_args (args_info);
109 }
110
111 static void
112 cmdline_parser_release (struct gengetopt_args_info *args_info)
113 {
114
115 if (args_info->input_arg)
116 {
117 free (args_info->input_arg); /* free previous argument */
118 args_info->input_arg = 0;
119 }
120 if (args_info->input_orig)
121 {
122 free (args_info->input_orig); /* free previous argument */
123 args_info->input_orig = 0;
124 }
125 if (args_info->output_arg)
126 {
127 free (args_info->output_arg); /* free previous argument */
128 args_info->output_arg = 0;
129 }
130 if (args_info->output_orig)
131 {
132 free (args_info->output_orig); /* free previous argument */
133 args_info->output_orig = 0;
134 }
135 if (args_info->sele1_arg)
136 {
137 free (args_info->sele1_arg); /* free previous argument */
138 args_info->sele1_arg = 0;
139 }
140 if (args_info->sele1_orig)
141 {
142 free (args_info->sele1_orig); /* free previous argument */
143 args_info->sele1_orig = 0;
144 }
145 if (args_info->sele2_arg)
146 {
147 free (args_info->sele2_arg); /* free previous argument */
148 args_info->sele2_arg = 0;
149 }
150 if (args_info->sele2_orig)
151 {
152 free (args_info->sele2_orig); /* free previous argument */
153 args_info->sele2_orig = 0;
154 }
155 if (args_info->order_orig)
156 {
157 free (args_info->order_orig); /* free previous argument */
158 args_info->order_orig = 0;
159 }
160
161 clear_given (args_info);
162 }
163
164 int
165 cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
166 {
167 FILE *outfile;
168 int i = 0;
169
170 outfile = fopen(filename, "w");
171
172 if (!outfile)
173 {
174 fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
175 return EXIT_FAILURE;
176 }
177
178 if (args_info->help_given) {
179 fprintf(outfile, "%s\n", "help");
180 }
181 if (args_info->version_given) {
182 fprintf(outfile, "%s\n", "version");
183 }
184 if (args_info->input_given) {
185 if (args_info->input_orig) {
186 fprintf(outfile, "%s=\"%s\"\n", "input", args_info->input_orig);
187 } else {
188 fprintf(outfile, "%s\n", "input");
189 }
190 }
191 if (args_info->output_given) {
192 if (args_info->output_orig) {
193 fprintf(outfile, "%s=\"%s\"\n", "output", args_info->output_orig);
194 } else {
195 fprintf(outfile, "%s\n", "output");
196 }
197 }
198 if (args_info->sele1_given) {
199 if (args_info->sele1_orig) {
200 fprintf(outfile, "%s=\"%s\"\n", "sele1", args_info->sele1_orig);
201 } else {
202 fprintf(outfile, "%s\n", "sele1");
203 }
204 }
205 if (args_info->sele2_given) {
206 if (args_info->sele2_orig) {
207 fprintf(outfile, "%s=\"%s\"\n", "sele2", args_info->sele2_orig);
208 } else {
209 fprintf(outfile, "%s\n", "sele2");
210 }
211 }
212 if (args_info->order_given) {
213 if (args_info->order_orig) {
214 fprintf(outfile, "%s=\"%s\"\n", "order", args_info->order_orig);
215 } else {
216 fprintf(outfile, "%s\n", "order");
217 }
218 }
219 if (args_info->rcorr_given) {
220 fprintf(outfile, "%s\n", "rcorr");
221 }
222 if (args_info->vcorr_given) {
223 fprintf(outfile, "%s\n", "vcorr");
224 }
225 if (args_info->dcorr_given) {
226 fprintf(outfile, "%s\n", "dcorr");
227 }
228 if (args_info->lcorr_given) {
229 fprintf(outfile, "%s\n", "lcorr");
230 }
231 if (args_info->r_rcorr_given) {
232 fprintf(outfile, "%s\n", "r_rcorr");
233 }
234 if (args_info->thetacorr_given) {
235 fprintf(outfile, "%s\n", "thetacorr");
236 }
237 if (args_info->actioncorr_given) {
238 fprintf(outfile, "%s\n", "actioncorr");
239 }
240 if (args_info->drcorr_given) {
241 fprintf(outfile, "%s\n", "drcorr");
242 }
243
244 fclose (outfile);
245
246 i = EXIT_SUCCESS;
247 return i;
248 }
249
250 void
251 cmdline_parser_free (struct gengetopt_args_info *args_info)
252 {
253 cmdline_parser_release (args_info);
254 }
255
256
257 /* gengetopt_strdup() */
258 /* strdup.c replacement of strdup, which is not standard */
259 char *
260 gengetopt_strdup (const char *s)
261 {
262 char *result = NULL;
263 if (!s)
264 return result;
265
266 result = (char*)malloc(strlen(s) + 1);
267 if (result == (char*)0)
268 return (char*)0;
269 strcpy(result, s);
270 return result;
271 }
272
273 static void
274 reset_group_dynamicProps(struct gengetopt_args_info *args_info);
275
276 static void
277 reset_group_dynamicProps(struct gengetopt_args_info *args_info)
278 {
279 if (! args_info->dynamicProps_group_counter)
280 return;
281
282 args_info->rcorr_given = 0 ;
283 args_info->vcorr_given = 0 ;
284 args_info->dcorr_given = 0 ;
285 args_info->lcorr_given = 0 ;
286 args_info->r_rcorr_given = 0 ;
287 args_info->thetacorr_given = 0 ;
288 args_info->actioncorr_given = 0 ;
289 args_info->drcorr_given = 0 ;
290
291 args_info->dynamicProps_group_counter = 0;
292 }
293
294 int
295 cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
296 {
297 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
298 }
299
300 int
301 cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
302 {
303 int result;
304
305 result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
306
307 if (result == EXIT_FAILURE)
308 {
309 cmdline_parser_free (args_info);
310 exit (EXIT_FAILURE);
311 }
312
313 return result;
314 }
315
316 int
317 cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
318 {
319 int result = EXIT_SUCCESS;
320
321 if (cmdline_parser_required2(args_info, prog_name, NULL) > 0)
322 result = EXIT_FAILURE;
323
324 if (result == EXIT_FAILURE)
325 {
326 cmdline_parser_free (args_info);
327 exit (EXIT_FAILURE);
328 }
329
330 return result;
331 }
332
333 int
334 cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
335 {
336 int error = 0;
337
338 if (! args_info->input_given)
339 {
340 fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
341 error = 1;
342 }
343 if (args_info->dynamicProps_group_counter == 0)
344 {
345 fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required.%s\n", prog_name, args_info->dynamicProps_group_counter, (additional_error ? additional_error : ""));
346 error = 1;
347 }
348
349
350 return error;
351 }
352
353 int
354 cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error)
355 {
356 int c; /* Character of the parsed option. */
357
358 int error = 0;
359 struct gengetopt_args_info local_args_info;
360
361 if (initialize)
362 cmdline_parser_init (args_info);
363
364 cmdline_parser_init (&local_args_info);
365
366 optarg = 0;
367 optind = 0;
368 opterr = 1;
369 optopt = '?';
370
371 while (1)
372 {
373 int option_index = 0;
374 char *stop_char;
375
376 static struct option long_options[] = {
377 { "help", 0, NULL, 'h' },
378 { "version", 0, NULL, 'V' },
379 { "input", 1, NULL, 'i' },
380 { "output", 1, NULL, 'o' },
381 { "sele1", 1, NULL, 0 },
382 { "sele2", 1, NULL, 0 },
383 { "order", 1, NULL, 0 },
384 { "rcorr", 0, NULL, 'r' },
385 { "vcorr", 0, NULL, 'v' },
386 { "dcorr", 0, NULL, 'd' },
387 { "lcorr", 0, NULL, 'l' },
388 { "r_rcorr", 0, NULL, 0 },
389 { "thetacorr", 0, NULL, 0 },
390 { "actioncorr", 0, NULL, 0 },
391 { "drcorr", 0, NULL, 0 },
392 { NULL, 0, NULL, 0 }
393 };
394
395 stop_char = 0;
396 c = getopt_long (argc, argv, "hVi:o:rvdl", long_options, &option_index);
397
398 if (c == -1) break; /* Exit from `while (1)' loop. */
399
400 switch (c)
401 {
402 case 'h': /* Print help and exit. */
403 cmdline_parser_print_help ();
404 cmdline_parser_free (&local_args_info);
405 exit (EXIT_SUCCESS);
406
407 case 'V': /* Print version and exit. */
408 cmdline_parser_print_version ();
409 cmdline_parser_free (&local_args_info);
410 exit (EXIT_SUCCESS);
411
412 case 'i': /* input dump file. */
413 if (local_args_info.input_given)
414 {
415 fprintf (stderr, "%s: `--input' (`-i') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
416 goto failure;
417 }
418 if (args_info->input_given && ! override)
419 continue;
420 local_args_info.input_given = 1;
421 args_info->input_given = 1;
422 if (args_info->input_arg)
423 free (args_info->input_arg); /* free previous string */
424 args_info->input_arg = gengetopt_strdup (optarg);
425 if (args_info->input_orig)
426 free (args_info->input_orig); /* free previous string */
427 args_info->input_orig = gengetopt_strdup (optarg);
428 break;
429
430 case 'o': /* output file name. */
431 if (local_args_info.output_given)
432 {
433 fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
434 goto failure;
435 }
436 if (args_info->output_given && ! override)
437 continue;
438 local_args_info.output_given = 1;
439 args_info->output_given = 1;
440 if (args_info->output_arg)
441 free (args_info->output_arg); /* free previous string */
442 args_info->output_arg = gengetopt_strdup (optarg);
443 if (args_info->output_orig)
444 free (args_info->output_orig); /* free previous string */
445 args_info->output_orig = gengetopt_strdup (optarg);
446 break;
447
448 case 'r': /* rmsd. */
449 if (local_args_info.rcorr_given)
450 {
451 fprintf (stderr, "%s: `--rcorr' (`-r') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
452 goto failure;
453 }
454 if (args_info->rcorr_given && ! override)
455 continue;
456 local_args_info.rcorr_given = 1;
457 args_info->rcorr_given = 1;
458 if (args_info->dynamicProps_group_counter && override)
459 reset_group_dynamicProps (args_info);
460 args_info->dynamicProps_group_counter += 1;
461 break;
462
463 case 'v': /* velocity correlation function. */
464 if (local_args_info.vcorr_given)
465 {
466 fprintf (stderr, "%s: `--vcorr' (`-v') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
467 goto failure;
468 }
469 if (args_info->vcorr_given && ! override)
470 continue;
471 local_args_info.vcorr_given = 1;
472 args_info->vcorr_given = 1;
473 if (args_info->dynamicProps_group_counter && override)
474 reset_group_dynamicProps (args_info);
475 args_info->dynamicProps_group_counter += 1;
476 break;
477
478 case 'd': /* dipole correlation function. */
479 if (local_args_info.dcorr_given)
480 {
481 fprintf (stderr, "%s: `--dcorr' (`-d') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
482 goto failure;
483 }
484 if (args_info->dcorr_given && ! override)
485 continue;
486 local_args_info.dcorr_given = 1;
487 args_info->dcorr_given = 1;
488 if (args_info->dynamicProps_group_counter && override)
489 reset_group_dynamicProps (args_info);
490 args_info->dynamicProps_group_counter += 1;
491 break;
492
493 case 'l': /* Lengendre correlation function. */
494 if (local_args_info.lcorr_given)
495 {
496 fprintf (stderr, "%s: `--lcorr' (`-l') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
497 goto failure;
498 }
499 if (args_info->lcorr_given && ! override)
500 continue;
501 local_args_info.lcorr_given = 1;
502 args_info->lcorr_given = 1;
503 if (args_info->dynamicProps_group_counter && override)
504 reset_group_dynamicProps (args_info);
505 args_info->dynamicProps_group_counter += 1;
506 break;
507
508
509 case 0: /* Long option with no short option */
510 /* select first stuntdouble set. */
511 if (strcmp (long_options[option_index].name, "sele1") == 0)
512 {
513 if (local_args_info.sele1_given)
514 {
515 fprintf (stderr, "%s: `--sele1' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
516 goto failure;
517 }
518 if (args_info->sele1_given && ! override)
519 continue;
520 local_args_info.sele1_given = 1;
521 args_info->sele1_given = 1;
522 if (args_info->sele1_arg)
523 free (args_info->sele1_arg); /* free previous string */
524 args_info->sele1_arg = gengetopt_strdup (optarg);
525 if (args_info->sele1_orig)
526 free (args_info->sele1_orig); /* free previous string */
527 args_info->sele1_orig = gengetopt_strdup (optarg);
528 }
529 /* select second stuntdouble set (if sele2 is not set, use script from sele1). */
530 else if (strcmp (long_options[option_index].name, "sele2") == 0)
531 {
532 if (local_args_info.sele2_given)
533 {
534 fprintf (stderr, "%s: `--sele2' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
535 goto failure;
536 }
537 if (args_info->sele2_given && ! override)
538 continue;
539 local_args_info.sele2_given = 1;
540 args_info->sele2_given = 1;
541 if (args_info->sele2_arg)
542 free (args_info->sele2_arg); /* free previous string */
543 args_info->sele2_arg = gengetopt_strdup (optarg);
544 if (args_info->sele2_orig)
545 free (args_info->sele2_orig); /* free previous string */
546 args_info->sele2_orig = gengetopt_strdup (optarg);
547 }
548 /* Lengendre Polynomial Order. */
549 else if (strcmp (long_options[option_index].name, "order") == 0)
550 {
551 if (local_args_info.order_given)
552 {
553 fprintf (stderr, "%s: `--order' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
554 goto failure;
555 }
556 if (args_info->order_given && ! override)
557 continue;
558 local_args_info.order_given = 1;
559 args_info->order_given = 1;
560 args_info->order_arg = strtol (optarg, &stop_char, 0);
561 if (!(stop_char && *stop_char == '\0')) {
562 fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
563 goto failure;
564 }
565 if (args_info->order_orig)
566 free (args_info->order_orig); /* free previous string */
567 args_info->order_orig = gengetopt_strdup (optarg);
568 }
569 /* Radial rmsd. */
570 else if (strcmp (long_options[option_index].name, "r_rcorr") == 0)
571 {
572 if (local_args_info.r_rcorr_given)
573 {
574 fprintf (stderr, "%s: `--r_rcorr' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
575 goto failure;
576 }
577 if (args_info->r_rcorr_given && ! override)
578 continue;
579 local_args_info.r_rcorr_given = 1;
580 args_info->r_rcorr_given = 1;
581 if (args_info->dynamicProps_group_counter && override)
582 reset_group_dynamicProps (args_info);
583 args_info->dynamicProps_group_counter += 1;
584 break;
585 }
586 /* Angular rmsd. */
587 else if (strcmp (long_options[option_index].name, "thetacorr") == 0)
588 {
589 if (local_args_info.thetacorr_given)
590 {
591 fprintf (stderr, "%s: `--thetacorr' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
592 goto failure;
593 }
594 if (args_info->thetacorr_given && ! override)
595 continue;
596 local_args_info.thetacorr_given = 1;
597 args_info->thetacorr_given = 1;
598 if (args_info->dynamicProps_group_counter && override)
599 reset_group_dynamicProps (args_info);
600 args_info->dynamicProps_group_counter += 1;
601 break;
602 }
603 /* Action correlation function. */
604 else if (strcmp (long_options[option_index].name, "actioncorr") == 0)
605 {
606 if (local_args_info.actioncorr_given)
607 {
608 fprintf (stderr, "%s: `--actioncorr' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
609 goto failure;
610 }
611 if (args_info->actioncorr_given && ! override)
612 continue;
613 local_args_info.actioncorr_given = 1;
614 args_info->actioncorr_given = 1;
615 if (args_info->dynamicProps_group_counter && override)
616 reset_group_dynamicProps (args_info);
617 args_info->dynamicProps_group_counter += 1;
618 break;
619 }
620 /* Directional rmsd for particles with unit vectors. */
621 else if (strcmp (long_options[option_index].name, "drcorr") == 0)
622 {
623 if (local_args_info.drcorr_given)
624 {
625 fprintf (stderr, "%s: `--drcorr' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
626 goto failure;
627 }
628 if (args_info->drcorr_given && ! override)
629 continue;
630 local_args_info.drcorr_given = 1;
631 args_info->drcorr_given = 1;
632 if (args_info->dynamicProps_group_counter && override)
633 reset_group_dynamicProps (args_info);
634 args_info->dynamicProps_group_counter += 1;
635 break;
636 }
637
638 break;
639 case '?': /* Invalid option. */
640 /* `getopt_long' already printed an error message. */
641 goto failure;
642
643 default: /* bug: option not considered. */
644 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
645 abort ();
646 } /* switch */
647 } /* while */
648
649 if (args_info->dynamicProps_group_counter > 1)
650 {
651 fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required.%s\n", argv[0], args_info->dynamicProps_group_counter, (additional_error ? additional_error : ""));
652 error = 1;
653 }
654
655
656
657 if (check_required)
658 {
659 error += cmdline_parser_required2 (args_info, argv[0], additional_error);
660 }
661
662 cmdline_parser_release (&local_args_info);
663
664 if ( error )
665 return (EXIT_FAILURE);
666
667 return 0;
668
669 failure:
670
671 cmdline_parser_release (&local_args_info);
672 return (EXIT_FAILURE);
673 }