ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/dynamicProps/DynamicPropsCmd.c
Revision: 3322
Committed: Wed Jan 23 21:21:50 2008 UTC (16 years, 5 months ago) by xsun
Content type: text/plain
File size: 22490 byte(s)
Log Message:
fixed a few correlation functions

File Contents

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