ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/nanoparticleBuilder/nanoparticleBuilderCmd.c
(Generate patch)

Comparing trunk/OOPSE-4/src/applications/nanoparticleBuilder/nanoparticleBuilderCmd.c (file contents):
Revision 3043 by chuckv, Tue Oct 11 21:57:22 2005 UTC vs.
Revision 3044 by chuckv, Fri Oct 13 20:16:59 2006 UTC

# Line 1 | Line 1
1   /*
2 <  File autogenerated by gengetopt version 2.13
2 >  File autogenerated by gengetopt version 2.15
3    generated with the following command:
4 <  gengetopt -u -F nanoparticleBuilderCmd
4 >  gengetopt -u -i nanoparticleBuilder.ggo -F nanoparticleBuilderCmd
5  
6    The developers of gengetopt consider the fixed text that goes in all
7    gengetopt output files to be in the public domain:
# Line 35 | Line 35 | struct ShellRadius_list
35   struct ShellRadius_list
36   {
37    double ShellRadius_arg;
38 +  char *ShellRadius_orig;
39    struct ShellRadius_list * next;
40   };
41  
42   struct molFraction_list
43   {
44    double molFraction_arg;
45 +  char *molFraction_orig;
46    struct molFraction_list * next;
47   };
48  
49   struct vacancyRadius_list
50   {
51    double vacancyRadius_arg;
52 +  char *vacancyRadius_orig;
53    struct vacancyRadius_list * next;
54   };
55  
# Line 59 | Line 62 | void clear_given (struct gengetopt_args_info *args_inf
62    args_info->help_given = 0 ;
63    args_info->version_given = 0 ;
64    args_info->output_given = 0 ;
62  args_info->latticetype_given = 0 ;
65    args_info->latticeCnst_given = 0 ;
66    args_info->radius_given = 0 ;
67    args_info->ShellRadius_given = 0 ;
# Line 72 | Line 74 | void clear_args (struct gengetopt_args_info *args_info
74   void clear_args (struct gengetopt_args_info *args_info)
75   {
76    args_info->output_arg = NULL;
77 <  args_info->latticetype_arg = gengetopt_strdup ("fcc");
77 >  args_info->output_orig = NULL;
78 >  args_info->latticeCnst_orig = NULL;
79 >  args_info->radius_orig = NULL;
80    args_info->ShellRadius_arg = NULL;
81 +  args_info->ShellRadius_orig = NULL;
82    args_info->molFraction_arg = NULL;
83 +  args_info->molFraction_orig = NULL;
84 +  args_info->vacancyPCT_orig = NULL;
85    args_info->vacancyRadius_arg = NULL;
86 +  args_info->vacancyRadius_orig = NULL;
87 +  
88   }
89  
90   void
# Line 93 | Line 102 | cmdline_parser_print_help (void)
102    printf("%s\n","  -h, --help                  Print help and exit");
103    printf("%s\n","  -V, --version               Print version and exit");
104    printf("%s\n","  -o, --output=STRING         Output file name");
96  printf("%s\n","      --latticetype=STRING    Lattice type string. Valid types are fcc,hcp,bcc. \n                                 (default=`fcc')");
105    printf("%s\n","      --latticeCnst=DOUBLE    Lattice spacing in Angstroms for cubic lattice.");
106    printf("%s\n","      --radius=DOUBLE         Nanoparticle radius in Angstroms");
107    printf("%s\n","      --ShellRadius=DOUBLE    Radius from the center of the particle to start a \n                                new shell in multi-component core-shell \n                                particle. Specified for each component > 1 in \n                                md file.");
# Line 113 | Line 121 | void
121    args_info->inputs_num = 0;
122   }
123  
124 < void
125 < cmdline_parser_free (struct gengetopt_args_info *args_info)
124 > static void
125 > cmdline_parser_release (struct gengetopt_args_info *args_info)
126   {
127    
128    unsigned int i;
# Line 123 | Line 131 | cmdline_parser_free (struct gengetopt_args_info *args_
131        free (args_info->output_arg); /* free previous argument */
132        args_info->output_arg = 0;
133      }
134 <  if (args_info->latticetype_arg)
134 >  if (args_info->output_orig)
135      {
136 <      free (args_info->latticetype_arg); /* free previous argument */
137 <      args_info->latticetype_arg = 0;
136 >      free (args_info->output_orig); /* free previous argument */
137 >      args_info->output_orig = 0;
138      }
139 +  if (args_info->latticeCnst_orig)
140 +    {
141 +      free (args_info->latticeCnst_orig); /* free previous argument */
142 +      args_info->latticeCnst_orig = 0;
143 +    }
144 +  if (args_info->radius_orig)
145 +    {
146 +      free (args_info->radius_orig); /* free previous argument */
147 +      args_info->radius_orig = 0;
148 +    }
149    if (args_info->ShellRadius_arg)
150      {
151 +      for (i = 0; i < args_info->ShellRadius_given; ++i)
152 +        {
153 +          if (args_info->ShellRadius_orig [i])
154 +            {
155 +              free (args_info->ShellRadius_orig [i]); /* free previous argument */
156 +              args_info->ShellRadius_orig [i] = 0;
157 +            }
158 +        }
159        free (args_info->ShellRadius_arg); /* free previous argument */
160        args_info->ShellRadius_arg = 0;
161 +      free (args_info->ShellRadius_orig); /* free previous argument */
162 +      args_info->ShellRadius_orig = 0;
163      }
164    if (args_info->molFraction_arg)
165      {
166 +      for (i = 0; i < args_info->molFraction_given; ++i)
167 +        {
168 +          if (args_info->molFraction_orig [i])
169 +            {
170 +              free (args_info->molFraction_orig [i]); /* free previous argument */
171 +              args_info->molFraction_orig [i] = 0;
172 +            }
173 +        }
174        free (args_info->molFraction_arg); /* free previous argument */
175        args_info->molFraction_arg = 0;
176 +      free (args_info->molFraction_orig); /* free previous argument */
177 +      args_info->molFraction_orig = 0;
178      }
179 +  if (args_info->vacancyPCT_orig)
180 +    {
181 +      free (args_info->vacancyPCT_orig); /* free previous argument */
182 +      args_info->vacancyPCT_orig = 0;
183 +    }
184    if (args_info->vacancyRadius_arg)
185      {
186 +      for (i = 0; i < args_info->vacancyRadius_given; ++i)
187 +        {
188 +          if (args_info->vacancyRadius_orig [i])
189 +            {
190 +              free (args_info->vacancyRadius_orig [i]); /* free previous argument */
191 +              args_info->vacancyRadius_orig [i] = 0;
192 +            }
193 +        }
194        free (args_info->vacancyRadius_arg); /* free previous argument */
195        args_info->vacancyRadius_arg = 0;
196 +      free (args_info->vacancyRadius_orig); /* free previous argument */
197 +      args_info->vacancyRadius_orig = 0;
198      }
199    
200    for (i = 0; i < args_info->inputs_num; ++i)
# Line 153 | Line 206 | cmdline_parser_free (struct gengetopt_args_info *args_
206    clear_given (args_info);
207   }
208  
209 + int
210 + cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
211 + {
212 +  FILE *outfile;
213 +  int i = 0;
214 +
215 +  outfile = fopen(filename, "w");
216 +
217 +  if (!outfile)
218 +    {
219 +      fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
220 +      return EXIT_FAILURE;
221 +    }
222 +
223 +  if (args_info->help_given) {
224 +    fprintf(outfile, "%s\n", "help");
225 +  }
226 +  if (args_info->version_given) {
227 +    fprintf(outfile, "%s\n", "version");
228 +  }
229 +  if (args_info->output_given) {
230 +    if (args_info->output_orig) {
231 +      fprintf(outfile, "%s=\"%s\"\n", "output", args_info->output_orig);
232 +    } else {
233 +      fprintf(outfile, "%s\n", "output");
234 +    }
235 +  }
236 +  if (args_info->latticeCnst_given) {
237 +    if (args_info->latticeCnst_orig) {
238 +      fprintf(outfile, "%s=\"%s\"\n", "latticeCnst", args_info->latticeCnst_orig);
239 +    } else {
240 +      fprintf(outfile, "%s\n", "latticeCnst");
241 +    }
242 +  }
243 +  if (args_info->radius_given) {
244 +    if (args_info->radius_orig) {
245 +      fprintf(outfile, "%s=\"%s\"\n", "radius", args_info->radius_orig);
246 +    } else {
247 +      fprintf(outfile, "%s\n", "radius");
248 +    }
249 +  }
250 +  if (args_info->ShellRadius_orig)
251 +    {
252 +      for (i = 0; i < args_info->ShellRadius_given; ++i)
253 +        {
254 +          if (args_info->ShellRadius_orig [i])
255 +            {
256 +              fprintf(outfile, "%s=\"%s\"\n", "ShellRadius", args_info->ShellRadius_orig [i]);
257 +            }
258 +        }
259 +    }
260 +  if (args_info->molFraction_orig)
261 +    {
262 +      for (i = 0; i < args_info->molFraction_given; ++i)
263 +        {
264 +          if (args_info->molFraction_orig [i])
265 +            {
266 +              fprintf(outfile, "%s=\"%s\"\n", "molFraction", args_info->molFraction_orig [i]);
267 +            }
268 +        }
269 +    }
270 +  if (args_info->vacancyPCT_given) {
271 +    if (args_info->vacancyPCT_orig) {
272 +      fprintf(outfile, "%s=\"%s\"\n", "vacancyPCT", args_info->vacancyPCT_orig);
273 +    } else {
274 +      fprintf(outfile, "%s\n", "vacancyPCT");
275 +    }
276 +  }
277 +  if (args_info->vacancyRadius_orig)
278 +    {
279 +      for (i = 0; i < args_info->vacancyRadius_given; ++i)
280 +        {
281 +          if (args_info->vacancyRadius_orig [i])
282 +            {
283 +              fprintf(outfile, "%s=\"%s\"\n", "vacancyRadius", args_info->vacancyRadius_orig [i]);
284 +            }
285 +        }
286 +    }
287 +  
288 +  fclose (outfile);
289 +
290 +  i = EXIT_SUCCESS;
291 +  return i;
292 + }
293 +
294 + void
295 + cmdline_parser_free (struct gengetopt_args_info *args_info)
296 + {
297 +  cmdline_parser_release (args_info);
298 + }
299 +
300 +
301   /* gengetopt_strdup() */
302   /* strdup.c replacement of strdup, which is not standard */
303   char *
# Line 299 | Line 444 | cmdline_parser_internal (int argc, char * const *argv,
444          { "help",       0, NULL, 'h' },
445          { "version",    0, NULL, 'V' },
446          { "output",     1, NULL, 'o' },
302        { "latticetype",        1, NULL, 0 },
447          { "latticeCnst",        1, NULL, 0 },
448          { "radius",     1, NULL, 0 },
449          { "ShellRadius",        1, NULL, 0 },
# Line 318 | Line 462 | cmdline_parser_internal (int argc, char * const *argv,
462          {
463          case 'h':       /* Print help and exit.  */
464            cmdline_parser_print_help ();
465 +          cmdline_parser_free (&local_args_info);
466            exit (EXIT_SUCCESS);
467  
468          case 'V':       /* Print version and exit.  */
469            cmdline_parser_print_version ();
470 +          cmdline_parser_free (&local_args_info);
471            exit (EXIT_SUCCESS);
472  
473          case 'o':       /* Output file name.  */
# Line 337 | Line 483 | cmdline_parser_internal (int argc, char * const *argv,
483            if (args_info->output_arg)
484              free (args_info->output_arg); /* free previous string */
485            args_info->output_arg = gengetopt_strdup (optarg);
486 +          if (args_info->output_orig)
487 +            free (args_info->output_orig); /* free previous string */
488 +          args_info->output_orig = gengetopt_strdup (optarg);
489            break;
490  
491  
492          case 0: /* Long option with no short option */
344          /* Lattice type string. Valid types are fcc,hcp,bcc..  */
345          if (strcmp (long_options[option_index].name, "latticetype") == 0)
346          {
347            if (local_args_info.latticetype_given)
348              {
349                fprintf (stderr, "%s: `--latticetype' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
350                goto failure;
351              }
352            if (args_info->latticetype_given && ! override)
353              continue;
354            local_args_info.latticetype_given = 1;
355            args_info->latticetype_given = 1;
356            if (args_info->latticetype_arg)
357              free (args_info->latticetype_arg); /* free previous string */
358            args_info->latticetype_arg = gengetopt_strdup (optarg);
359          }
493            /* Lattice spacing in Angstroms for cubic lattice..  */
494 <          else if (strcmp (long_options[option_index].name, "latticeCnst") == 0)
494 >          if (strcmp (long_options[option_index].name, "latticeCnst") == 0)
495            {
496              if (local_args_info.latticeCnst_given)
497                {
# Line 369 | Line 502 | cmdline_parser_internal (int argc, char * const *argv,
502                continue;
503              local_args_info.latticeCnst_given = 1;
504              args_info->latticeCnst_given = 1;
505 <            args_info->latticeCnst_arg = strtod (optarg, NULL);
505 >            args_info->latticeCnst_arg = strtod (optarg, &stop_char);
506 >            if (!(stop_char && *stop_char == '\0')) {
507 >              fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
508 >              goto failure;
509 >            }
510 >            if (args_info->latticeCnst_orig)
511 >              free (args_info->latticeCnst_orig); /* free previous string */
512 >            args_info->latticeCnst_orig = gengetopt_strdup (optarg);
513            }
514            /* Nanoparticle radius in Angstroms.  */
515            else if (strcmp (long_options[option_index].name, "radius") == 0)
# Line 383 | Line 523 | cmdline_parser_internal (int argc, char * const *argv,
523                continue;
524              local_args_info.radius_given = 1;
525              args_info->radius_given = 1;
526 <            args_info->radius_arg = strtod (optarg, NULL);
526 >            args_info->radius_arg = strtod (optarg, &stop_char);
527 >            if (!(stop_char && *stop_char == '\0')) {
528 >              fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
529 >              goto failure;
530 >            }
531 >            if (args_info->radius_orig)
532 >              free (args_info->radius_orig); /* free previous string */
533 >            args_info->radius_orig = gengetopt_strdup (optarg);
534            }
535            /* Radius from the center of the particle to start a new shell in multi-component core-shell particle. Specified for each component > 1 in md file..  */
536            else if (strcmp (long_options[option_index].name, "ShellRadius") == 0)
# Line 398 | Line 545 | cmdline_parser_internal (int argc, char * const *argv,
545                  ShellRadius_new = (struct ShellRadius_list *) malloc (sizeof (struct ShellRadius_list));
546                  ShellRadius_new->next = ShellRadius_list;
547                  ShellRadius_list = ShellRadius_new;
548 <                ShellRadius_new->ShellRadius_arg = strtod (multi_token, NULL);
549 <                free (multi_token);
548 >                ShellRadius_new->ShellRadius_arg = strtod (multi_token, &stop_char);
549 >                if (!(stop_char && *stop_char == '\0')) {
550 >                  fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], multi_token);
551 >                  goto failure;
552 >                }
553 >                ShellRadius_new->ShellRadius_orig = multi_token;
554            
555                  if (multi_next)
556                    {
# Line 425 | Line 576 | cmdline_parser_internal (int argc, char * const *argv,
576                  molFraction_new = (struct molFraction_list *) malloc (sizeof (struct molFraction_list));
577                  molFraction_new->next = molFraction_list;
578                  molFraction_list = molFraction_new;
579 <                molFraction_new->molFraction_arg = strtod (multi_token, NULL);
580 <                free (multi_token);
579 >                molFraction_new->molFraction_arg = strtod (multi_token, &stop_char);
580 >                if (!(stop_char && *stop_char == '\0')) {
581 >                  fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], multi_token);
582 >                  goto failure;
583 >                }
584 >                molFraction_new->molFraction_orig = multi_token;
585            
586                  if (multi_next)
587                    {
# Line 451 | Line 606 | cmdline_parser_internal (int argc, char * const *argv,
606                continue;
607              local_args_info.vacancyPCT_given = 1;
608              args_info->vacancyPCT_given = 1;
609 <            args_info->vacancyPCT_arg = strtod (optarg, NULL);
609 >            args_info->vacancyPCT_arg = strtod (optarg, &stop_char);
610 >            if (!(stop_char && *stop_char == '\0')) {
611 >              fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
612 >              goto failure;
613 >            }
614 >            if (args_info->vacancyPCT_orig)
615 >              free (args_info->vacancyPCT_orig); /* free previous string */
616 >            args_info->vacancyPCT_orig = gengetopt_strdup (optarg);
617            }
618            /* Radius arround core-shell where vacancies should be located..  */
619            else if (strcmp (long_options[option_index].name, "vacancyRadius") == 0)
# Line 466 | Line 628 | cmdline_parser_internal (int argc, char * const *argv,
628                  vacancyRadius_new = (struct vacancyRadius_list *) malloc (sizeof (struct vacancyRadius_list));
629                  vacancyRadius_new->next = vacancyRadius_list;
630                  vacancyRadius_list = vacancyRadius_new;
631 <                vacancyRadius_new->vacancyRadius_arg = strtod (multi_token, NULL);
632 <                free (multi_token);
631 >                vacancyRadius_new->vacancyRadius_arg = strtod (multi_token, &stop_char);
632 >                if (!(stop_char && *stop_char == '\0')) {
633 >                  fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], multi_token);
634 >                  goto failure;
635 >                }
636 >                vacancyRadius_new->vacancyRadius_orig = multi_token;
637            
638                  if (multi_next)
639                    {
# Line 497 | Line 663 | cmdline_parser_internal (int argc, char * const *argv,
663      {
664        struct ShellRadius_list *tmp;
665        args_info->ShellRadius_arg = (double *) realloc (args_info->ShellRadius_arg, (args_info->ShellRadius_given + local_args_info.ShellRadius_given) * sizeof (double));
666 +      args_info->ShellRadius_orig = (char **) realloc (args_info->ShellRadius_orig, (args_info->ShellRadius_given + local_args_info.ShellRadius_given) * sizeof (char *));
667        for (i = (local_args_info.ShellRadius_given - 1); i >= 0; --i)
668          {
669            tmp = ShellRadius_list;
670            args_info->ShellRadius_arg [i + args_info->ShellRadius_given] = ShellRadius_list->ShellRadius_arg;
671 +          args_info->ShellRadius_orig [i + args_info->ShellRadius_given] = ShellRadius_list->ShellRadius_orig;
672            ShellRadius_list = ShellRadius_list->next;
673            free (tmp);
674          }
# Line 510 | Line 678 | cmdline_parser_internal (int argc, char * const *argv,
678      {
679        struct molFraction_list *tmp;
680        args_info->molFraction_arg = (double *) realloc (args_info->molFraction_arg, (args_info->molFraction_given + local_args_info.molFraction_given) * sizeof (double));
681 +      args_info->molFraction_orig = (char **) realloc (args_info->molFraction_orig, (args_info->molFraction_given + local_args_info.molFraction_given) * sizeof (char *));
682        for (i = (local_args_info.molFraction_given - 1); i >= 0; --i)
683          {
684            tmp = molFraction_list;
685            args_info->molFraction_arg [i + args_info->molFraction_given] = molFraction_list->molFraction_arg;
686 +          args_info->molFraction_orig [i + args_info->molFraction_given] = molFraction_list->molFraction_orig;
687            molFraction_list = molFraction_list->next;
688            free (tmp);
689          }
# Line 523 | Line 693 | cmdline_parser_internal (int argc, char * const *argv,
693      {
694        struct vacancyRadius_list *tmp;
695        args_info->vacancyRadius_arg = (double *) realloc (args_info->vacancyRadius_arg, (args_info->vacancyRadius_given + local_args_info.vacancyRadius_given) * sizeof (double));
696 +      args_info->vacancyRadius_orig = (char **) realloc (args_info->vacancyRadius_orig, (args_info->vacancyRadius_given + local_args_info.vacancyRadius_given) * sizeof (char *));
697        for (i = (local_args_info.vacancyRadius_given - 1); i >= 0; --i)
698          {
699            tmp = vacancyRadius_list;
700            args_info->vacancyRadius_arg [i + args_info->vacancyRadius_given] = vacancyRadius_list->vacancyRadius_arg;
701 +          args_info->vacancyRadius_orig [i + args_info->vacancyRadius_given] = vacancyRadius_list->vacancyRadius_orig;
702            vacancyRadius_list = vacancyRadius_list->next;
703            free (tmp);
704          }
# Line 545 | Line 717 | cmdline_parser_internal (int argc, char * const *argv,
717        error += cmdline_parser_required2 (args_info, argv[0], additional_error);
718      }
719  
720 <  cmdline_parser_free (&local_args_info);
720 >  cmdline_parser_release (&local_args_info);
721  
722    if ( error )
723      return (EXIT_FAILURE);
# Line 570 | Line 742 | failure:
742        while (ShellRadius_list)
743          {
744            tmp = ShellRadius_list;
745 +          free (ShellRadius_list->ShellRadius_orig);
746            ShellRadius_list = ShellRadius_list->next;
747            free (tmp);
748          }
# Line 580 | Line 753 | failure:
753        while (molFraction_list)
754          {
755            tmp = molFraction_list;
756 +          free (molFraction_list->molFraction_orig);
757            molFraction_list = molFraction_list->next;
758            free (tmp);
759          }
# Line 590 | Line 764 | failure:
764        while (vacancyRadius_list)
765          {
766            tmp = vacancyRadius_list;
767 +          free (vacancyRadius_list->vacancyRadius_orig);
768            vacancyRadius_list = vacancyRadius_list->next;
769            free (tmp);
770          }
771      }
772    
773 <  cmdline_parser_free (&local_args_info);
773 >  cmdline_parser_release (&local_args_info);
774    return (EXIT_FAILURE);
775   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines