ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/applications/nanoRodBuilder/nanorodBuilderCmd.c
Revision: 2164
Committed: Mon Apr 11 21:37:30 2005 UTC (19 years, 3 months ago) by chuckv
Content type: text/plain
File size: 11069 byte(s)
Log Message:
Importing nanoRodBuilder application (may not work yet).  ((Doesn't work yet.))
(((May never work....)))

File Contents

# User Rev Content
1 chuckv 2164 /*
2     File autogenerated by gengetopt version 2.12
3     generated with the following command:
4     gengetopt -u --file-name=nanorodBuilderCmd
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 "nanorodBuilderCmd.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 char *
33     gengetopt_strdup (const char *s);
34    
35     static
36     void clear_given (struct gengetopt_args_info *args_info)
37     {
38     args_info->help_given = 0 ;
39     args_info->version_given = 0 ;
40     args_info->output_given = 0 ;
41     args_info->latticetype_given = 0 ;
42     args_info->length_given = 0 ;
43     args_info->width_given = 0 ;
44     args_info->latticeCnst_given = 0 ;
45     args_info->genGeomview_given = 0 ;
46     }
47    
48     static
49     void clear_args (struct gengetopt_args_info *args_info)
50     {
51     args_info->output_arg = NULL;
52     args_info->latticetype_arg = gengetopt_strdup ("fcc");
53     }
54    
55     void
56     cmdline_parser_print_version (void)
57     {
58     printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
59     }
60    
61     void
62     cmdline_parser_print_help (void)
63     {
64     cmdline_parser_print_version ();
65     printf("\n"
66     "Purpose:\n"
67     " Builds penta-hexagonal nanorods and outputs a xyz input file\n"
68     "\n"
69     "Usage: %s [OPTIONS]... [FILES]...\n", CMDLINE_PARSER_PACKAGE);
70     printf("\n");
71     printf("%s\n"," -h, --help Print help and exit");
72     printf("%s\n"," -V, --version Print version and exit");
73     printf("%s\n"," -o, --output=STRING Output file name");
74     printf("%s\n"," --latticetype=STRING Lattice type string. Valid types are fcc,hcp,bcc. \n (default=`fcc')");
75     printf("%s\n"," --length=DOUBLE length of nanorod in Angstroms");
76     printf("%s\n"," --width=DOUBLE diameter of nanorod in Angstroms");
77     printf("%s\n"," --latticeCnst=DOUBLE lattice spacing in Angstrons for cubic lattice");
78     printf("%s\n"," --genGeomview=LONG generate a geomview file with the object geometry");
79     }
80    
81     void
82     cmdline_parser_init (struct gengetopt_args_info *args_info)
83     {
84     clear_given (args_info);
85     clear_args (args_info);
86    
87     args_info->inputs = NULL;
88     args_info->inputs_num = 0;
89     }
90    
91     void
92     cmdline_parser_free (struct gengetopt_args_info *args_info)
93     {
94    
95     int i;
96     if (args_info->output_arg)
97     {
98     free (args_info->output_arg); /* free previous argument */
99     args_info->output_arg = 0;
100     }
101     if (args_info->latticetype_arg)
102     {
103     free (args_info->latticetype_arg); /* free previous argument */
104     args_info->latticetype_arg = 0;
105     }
106    
107     for (i = 0; i < args_info->inputs_num; ++i)
108     free (args_info->inputs [i]);
109    
110     if (args_info->inputs_num)
111     free (args_info->inputs);
112    
113     clear_given (args_info);
114     }
115    
116    
117     /* gengetopt_strdup() */
118     /* strdup.c replacement of strdup, which is not standard */
119     char *
120     gengetopt_strdup (const char *s)
121     {
122     char *result = NULL;
123     if (!s)
124     return result;
125    
126     result = (char*)malloc(strlen(s) + 1);
127     if (result == (char*)0)
128     return (char*)0;
129     strcpy(result, s);
130     return result;
131     }
132    
133     int
134     cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
135     {
136     return cmdline_parser2 (argc, argv, args_info, 0, 1);
137     }
138    
139     int
140     cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize)
141     {
142     int result;
143    
144     result = cmdline_parser_internal (argc, argv, args_info, override, initialize, 1, NULL);
145    
146     if (result == EXIT_FAILURE)
147     {
148     cmdline_parser_free (args_info);
149     exit (EXIT_FAILURE);
150     }
151    
152     return result;
153     }
154    
155     int
156     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)
157     {
158     int c; /* Character of the parsed option. */
159     int error = 0;
160     struct gengetopt_args_info local_args_info;
161    
162     if (initialize)
163     cmdline_parser_init (args_info);
164    
165     cmdline_parser_init (&local_args_info);
166    
167     optarg = 0;
168     optind = 1;
169     opterr = 1;
170     optopt = '?';
171    
172     while (1)
173     {
174     int option_index = 0;
175     char *stop_char;
176    
177     static struct option long_options[] = {
178     { "help", 0, NULL, 'h' },
179     { "version", 0, NULL, 'V' },
180     { "output", 1, NULL, 'o' },
181     { "latticetype", 1, NULL, 0 },
182     { "length", 1, NULL, 0 },
183     { "width", 1, NULL, 0 },
184     { "latticeCnst", 1, NULL, 0 },
185     { "genGeomview", 1, NULL, 0 },
186     { NULL, 0, NULL, 0 }
187     };
188    
189     stop_char = 0;
190     c = getopt_long (argc, argv, "hVo:", long_options, &option_index);
191    
192     if (c == -1) break; /* Exit from `while (1)' loop. */
193    
194     switch (c)
195     {
196     case 'h': /* Print help and exit. */
197     cmdline_parser_print_help ();
198     exit (EXIT_SUCCESS);
199    
200     case 'V': /* Print version and exit. */
201     cmdline_parser_print_version ();
202     exit (EXIT_SUCCESS);
203    
204     case 'o': /* Output file name. */
205     if (local_args_info.output_given)
206     {
207     fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
208     goto failure;
209     }
210     if (args_info->output_given && ! override)
211     continue;
212     local_args_info.output_given = 1;
213     args_info->output_given = 1;
214     if (args_info->output_arg)
215     free (args_info->output_arg); /* free previous string */
216     args_info->output_arg = gengetopt_strdup (optarg);
217     break;
218    
219    
220     case 0: /* Long option with no short option */
221     /* Lattice type string. Valid types are fcc,hcp,bcc.. */
222     if (strcmp (long_options[option_index].name, "latticetype") == 0)
223     {
224     if (local_args_info.latticetype_given)
225     {
226     fprintf (stderr, "%s: `--latticetype' option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
227     goto failure;
228     }
229     if (args_info->latticetype_given && ! override)
230     continue;
231     local_args_info.latticetype_given = 1;
232     args_info->latticetype_given = 1;
233     if (args_info->latticetype_arg)
234     free (args_info->latticetype_arg); /* free previous string */
235     args_info->latticetype_arg = gengetopt_strdup (optarg);
236     }
237    
238     /* length of nanorod in Angstroms. */
239     else if (strcmp (long_options[option_index].name, "length") == 0)
240     {
241     if (local_args_info.length_given)
242     {
243     fprintf (stderr, "%s: `--length' option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
244     goto failure;
245     }
246     if (args_info->length_given && ! override)
247     continue;
248     local_args_info.length_given = 1;
249     args_info->length_given = 1;
250     args_info->length_arg = strtod (optarg, NULL);
251     }
252    
253     /* diameter of nanorod in Angstroms. */
254     else if (strcmp (long_options[option_index].name, "width") == 0)
255     {
256     if (local_args_info.width_given)
257     {
258     fprintf (stderr, "%s: `--width' option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
259     goto failure;
260     }
261     if (args_info->width_given && ! override)
262     continue;
263     local_args_info.width_given = 1;
264     args_info->width_given = 1;
265     args_info->width_arg = strtod (optarg, NULL);
266     }
267    
268     /* lattice spacing in Angstrons for cubic lattice. */
269     else if (strcmp (long_options[option_index].name, "latticeCnst") == 0)
270     {
271     if (local_args_info.latticeCnst_given)
272     {
273     fprintf (stderr, "%s: `--latticeCnst' option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
274     goto failure;
275     }
276     if (args_info->latticeCnst_given && ! override)
277     continue;
278     local_args_info.latticeCnst_given = 1;
279     args_info->latticeCnst_given = 1;
280     args_info->latticeCnst_arg = strtod (optarg, NULL);
281     }
282    
283     /* generate a geomview file with the object geometry. */
284     else if (strcmp (long_options[option_index].name, "genGeomview") == 0)
285     {
286     if (local_args_info.genGeomview_given)
287     {
288     fprintf (stderr, "%s: `--genGeomview' option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
289     goto failure;
290     }
291     if (args_info->genGeomview_given && ! override)
292     continue;
293     local_args_info.genGeomview_given = 1;
294     args_info->genGeomview_given = 1;
295     args_info->genGeomview_arg = strtol (optarg,&stop_char,0);
296     }
297    
298    
299     break;
300     case '?': /* Invalid option. */
301     /* `getopt_long' already printed an error message. */
302     goto failure;
303    
304     default: /* bug: option not considered. */
305     fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
306     abort ();
307     } /* switch */
308     } /* while */
309    
310    
311     cmdline_parser_free (&local_args_info);
312    
313     if (check_required)
314     {
315     if (! args_info->length_given)
316     {
317     fprintf (stderr, "%s: '--length' option required%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
318     error = 1;
319     }
320     if (! args_info->width_given)
321     {
322     fprintf (stderr, "%s: '--width' option required%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
323     error = 1;
324     }
325     if (! args_info->latticeCnst_given)
326     {
327     fprintf (stderr, "%s: '--latticeCnst' option required%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
328     error = 1;
329     }
330     }
331    
332    
333     if ( error )
334     return (EXIT_FAILURE);
335    
336     if (optind < argc)
337     {
338     int i = 0 ;
339    
340     args_info->inputs_num = argc - optind ;
341     args_info->inputs =
342     (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
343     while (optind < argc)
344     args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
345     }
346    
347     return 0;
348    
349     failure:
350     cmdline_parser_free (&local_args_info);
351     return (EXIT_FAILURE);
352     }