ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/commandLine/commandLine.c
Revision: 520
Committed: Mon May 5 22:01:36 2003 UTC (21 years, 2 months ago) by mmeineke
Content type: text/plain
File size: 3321 byte(s)
Log Message:
started some initial rewrite for the template.

File Contents

# User Rev Content
1 mmeineke 518 #include <stdio.h>
2     #include <stdlib.h>
3     #include <string.h>
4    
5    
6     char *program_name; /*the name of the program */
7     void usage(void);
8    
9     int main(argc, argv)
10     int argc;
11     char *argv[];
12     {
13     int i,j; // loop counters
14    
15 mmeineke 520 char *in_name = NULL; // name of the input file
16     char* out_prefix = NULL; // the output prefix
17     char current_flag; // used in parsing the flags
18 mmeineke 518 int done = 0; // multipurpose boolean
19 mmeineke 520 int have_prefix; // boolean for the output prefix
20 mmeineke 518
21 mmeineke 520
22     // here we set the name of the program need by the usage message
23     program_name = argv[0];
24    
25 mmeineke 518
26     for( i = 1; i < argc; i++){
27    
28     if(argv[i][0] =='-'){
29    
30     // parse the option
31    
32     if(argv[i][1] == '-' ){
33    
34     // parse long word options
35    
36     if( !strcmp( argv[i], "--GofR" ) ){
37     calcGofR = 1;
38     i++;
39     strcpy( gofR1, argv[i] );
40     i++;
41     strcpy( gofR2, argv[i] );
42     }
43    
44     else if( !strcmp( argv[i], "--CosCorr" ) ){
45     calcCosCorr = 1;
46     i++;
47     strcpy( cosCorr1, argv[i] );
48     i++;
49     strcpy( cosCorr2, argv[i] );
50     }
51    
52     else if( !strcmp( argv[i], "--MuCorr") ){
53     calcMuCorr = 1;
54     i++;
55     strcpy( muCorr, argv[i] );
56     }
57    
58     else if( !strcmp( argv[i], "--startFrame" ) ){
59     haveStartFrame = 1;
60     i++;
61     startFrame = atoi(argv[i]);
62     startFrame--;
63     }
64    
65     else if( !strcmp( argv[i], "--endFrame" ) ){
66     haveEndFrame = 1;
67     i++;
68     endFrame = atoi(argv[i]);
69     }
70    
71     else{
72     fprintf( stderr,
73     "Invalid option \"%s\"\n", argv[i] );
74     usage();
75     }
76     }
77    
78     else{
79    
80     // parse single character options
81    
82     done =0;
83     j = 1;
84     current_flag = argv[i][j];
85     while( (current_flag != '\0') && (!done) ){
86    
87     switch(current_flag){
88    
89     case 'o':
90     // -o <prefix> => the output prefix.
91    
92     i++;
93     out_prefix = argv[i];
94     have_prefix = 1;
95     done = 1;
96     break;
97    
98     case 'h':
99     // -h => give the usage
100    
101     usage();
102     break;
103    
104     case 'r':
105     // calculates the rmsd
106    
107     calcRMSD = 1;
108     break;
109    
110     case 'g':
111     // calculate all to all g(r)
112    
113     calcGofR = 1;
114     strcpy( gofR1, "all" );
115     strcpy( gofR2, "all" );
116     break;
117    
118     default:
119    
120     (void)fprintf(stderr, "Bad option \"-%c\"\n", current_flag);
121     usage();
122     }
123     j++;
124     current_flag = argv[i][j];
125     }
126     }
127     }
128    
129     else{
130    
131     if( in_name != NULL ){
132     fprintf( stderr,
133     "Error at \"%s\", program does not currently support\n"
134     "more than one input file.\n"
135     "\n",
136     argv[i]);
137     usage();
138     }
139    
140     in_name = argv[i];
141     }
142     }
143    
144     if(in_name == NULL){
145     usage();
146     }
147    
148     if( !have_prefix ) out_prefix = in_name;
149    
150     }
151    
152    
153     /***************************************************************************
154     * prints out the usage for the command line arguments, then exits.
155     ***************************************************************************/
156    
157     void usage(){
158     (void)fprintf(stdout,
159 mmeineke 520 "The proper usage is: %s [options] <input_file>\n"
160 mmeineke 518 "\n"
161     "Options:\n"
162     "\n"
163     " short:\n"
164     " ------\n"
165     " -h Display this message\n"
166 mmeineke 520 " -o <name> The output name/prefix\n"
167     " -r the r flag\n"
168     " -i <#> set number to <#>\n"
169 mmeineke 518
170     "\n"
171     " long:\n"
172     " -----\n"
173 mmeineke 520 " --flag1 <arg1> <arg2> does flag 1 for arg1 and 2\n"
174     " --flag2 <arg1> does flag 2 for arg1\n"
175     " --flag3 does flag 3\n"
176 mmeineke 518
177     "\n"
178     "\n",
179     program_name);
180     exit(8);
181     }