ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/props/staticProps.cpp
(Generate patch)

Comparing trunk/OOPSE/props/staticProps.cpp (file contents):
Revision 794 by mmeineke, Thu Aug 28 16:59:58 2003 UTC vs.
Revision 795 by mmeineke, Thu Oct 2 22:06:53 2003 UTC

# Line 1 | Line 1
1   #include <iostream>
2 < #include <fstream>
3 < #include <cstdlib>
4 < #include <cmath>
5 < #include <cstring>
2 > #include <stdio.h>
3 > #include <stdlib.h>
4 > #include <string.h>
5 > #include <vector>
6  
7   #include "simError.h"
8   #include "SimSetup.hpp"
# Line 12 | Line 12
12   #include "Thermo.hpp"
13   #include "ReadWrite.hpp"
14  
15 < char* program_name;
15 > #include "PairCorrList.hpp"
16 > #include "AllCorr.hpp"
17 >
18 > #define VERSION_MAJOR 0
19 > #define VERSION_MINOR 1
20 >
21 > char *programName; /*the name of the program */
22 > void usage(void);
23   using namespace std;
24  
25 < int main(int argc,char* argv[]){
25 > int main(int argC,char* argV[]){
26    
27 +  int i,j; // loop counters
28 +
29 +  char* outPrefix; // the output prefix
30 +
31 +  char* conversionCheck;
32 +  bool conversionError;
33 +  bool optionError;
34 +
35 +  char currentFlag; // used in parsing the flags
36 +  bool done = false; // multipurpose boolean
37 +  bool havePrefix; // boolean for the output prefix  
38 +
39 +  bool haveMaxLength;
40 +  double maxLength;
41 +  
42 +  vector<PairCorrList> theList;
43 +  pairCorrEnum pairType;
44 +  
45 +  char* pair1;
46 +  char* pair2;
47 +
48    char dumpName[2000];
49    char* endTest;
50    int nameLength;
51    int nFrames;
52 <  char* in_name;
52 >  char* inName;
53    SimSetup* startMe;
54    SimInfo* infoArray;
55    DumpReader* reader;
56 +  AllCorr theCorrs;
57    
29
30  
58    // first things first, all of the initializations
59  
60    printf("Initializing stuff ....\n");
61    fflush(sdtout);
62    srand48( 1337 );          // the random number generator.
63    initSimError();           // the error handler
64 +
65 +  outPrefix = NULL;
66 +  inName = NULL;
67    
68 <  program_name = argv[0]; /*save the program name in case we need it*/
69 <  if( argc < 2 ){
68 >  conversionError = false;
69 >  optionError = false;
70 >
71 >  havePrefix = false;
72 >  haveMaxLength = false;
73 >  
74 >  maxLength = 1.0;
75 >
76 >  programName = argv[0]; /*save the program name in case we need it*/
77 >
78 >  for( i = 1; i < argC; i++){
79 >    
80 >    if(argV[i][0] =='-'){
81 >
82 >      // parse the option
83 >      
84 >      if(argV[i][1] == '-' ){
85 >
86 >        // parse long word options
87 >        
88 >        if( !strcmp( argV[i], "--gofr" ) ){
89 >          
90 >          i++;
91 >          if( i>=argC ){
92 >            sprintf( painCave.errMsg,
93 >                     "\n"
94 >                     "not enough arguments for --gofr\n");
95 >            usage();
96 >            painCave.isFatal = 1;
97 >            simError();
98 >          }      
99 >          pair1 = argV[i];
100 >
101 >          i++;
102 >          if( i>=argC ){
103 >            sprintf( painCave.errMsg,
104 >                     "\n"
105 >                     "not enough arguments for --gofr\n");
106 >            usage();
107 >            painCave.isFatal = 1;
108 >            simError();
109 >          }      
110 >          pair2 = argV[i];
111 >
112 >          pairType = gofr;
113 >          theList.push_back(PairCorrList( pairType, pair1, pair2 ));
114 >        }
115 >
116 >        else if( !strcmp( argV[i], "--version") ){
117 >          
118 >          printf("\n"
119 >                 "staticProps version %d.%d\n"
120 >                 "\n",
121 >                 VERSION_MAJOR, VERSION_MINOR );
122 >          exit(0);
123 >          
124 >        }
125 >
126 >        else if( !strcmp( argV[i], "--help") ){
127 >          
128 >          usage();
129 >          exit(0);
130 >        }
131 >        
132 >        // anything else is an error
133 >
134 >        else{
135 >          fprintf( stderr,
136 >                   "Invalid option \"%s\"\n", argV[i] );
137 >          usage();
138 >          exit(0);
139 >        }
140 >      }
141 >      
142 >      else{
143 >        
144 >        // parse single character options
145 >        
146 >        done =0;
147 >        j = 1;
148 >        currentFlag = argV[i][j];
149 >        while( (currentFlag != '\0') && (!done) ){
150 >          
151 >          switch(currentFlag){
152 >
153 >          case 'o':
154 >            // -o <prefix> => the output prefix.
155 >
156 >            j++;
157 >            currentFlag = argV[i][j];
158 >              
159 >            if( currentFlag != '\0' ) optionError = true;
160 >            
161 >            if( optionError ){
162 >              sprintf( painCave.errMsg,
163 >                       "\n"
164 >                       "The -o flag should end an option sequence.\n"
165 >                       "   example: -r <outname> *NOT* -or <outname>\n" );
166 >              usage();
167 >              painCave.isFatal = 1;
168 >              simError();
169 >            }
170 >              
171 >            i++;
172 >            if( i>=argC ){
173 >              sprintf( painCave.errMsg,
174 >                       "\n"
175 >                       "not enough arguments for -o\n");
176 >              usage();
177 >              painCave.isFatal = 1;
178 >              simError();
179 >            }    
180 >            
181 >            outPrefix = argV[i];
182 >            if( outPrefix[0] == '-' ) optionError = true;
183 >                
184 >            if( optionError ){
185 >              sprintf( painCave.errMsg,
186 >                       "\n"
187 >                       "\"%s\" is not a valid out prefix/name.\n"
188 >                       "Out prefix/name should not begin with a dash.\n",
189 >                       outPrefix );
190 >              usage();
191 >              painCave.isFatal = 1;
192 >              simError();
193 >            }
194 >            
195 >            havePrefix = true;
196 >            done = true;
197 >            break;
198 >
199 >          case 'l':
200 >            // -l <double>    set <double> to the maxLength
201 >
202 >            haveMaxLength = true;
203 >            j++;
204 >            currentFlag = argV[i][j];
205 >              
206 >            if( currentFlag != '\0' ) optionError = true;
207 >            
208 >            if( optionError ){
209 >              sprintf( painCave.errMsg,
210 >                       "\n"
211 >                       "The -i flag should end an option sequence.\n"
212 >                       "   example: -ri <int> *NOT* -ir <int>\n" );
213 >              usage();
214 >              painCave.isFatal = 1;
215 >              simError();
216 >            }
217 >
218 >            i++;
219 >            if( i>=argC ){
220 >              sprintf( painCave.errMsg,
221 >                       "\n"
222 >                       "not enough arguments for -i\n");
223 >              usage();
224 >              painCave.isFatal = 1;
225 >              simError();
226 >            }    
227 >
228 >            maxLength = strtod( argV[i], &conversionCheck, 10 );
229 >            if( conversionCheck == argV[i] ) conversionError = true;
230 >            if( *conversionCheck != '\0' ) conversionError = true;
231 >            
232 >            if( conversionError ){
233 >              sprintf( painCave.errMsg,
234 >                       "Error converting \"%s\" to a double for maxLength.\n",
235 >                       argV[i] );
236 >              usage();
237 >              painCave.isFatal = 1;
238 >              simError();
239 >            }
240 >            
241 >            done = true;
242 >
243 >            break;
244 >
245 >          default:
246 >
247 >            sprintf(painCave.errMsg,
248 >                    "\n"
249 >                    "Bad option \"-%c\"\n", currentFlag);
250 >            usage();
251 >            painCave.isFatal = 1;
252 >            simError();
253 >          }
254 >          j++;
255 >          currentFlag = argV[i][j];
256 >        }
257 >      }
258 >    }
259 >
260 >    else{
261 >      
262 >      if( inName != NULL ){
263 >        sprintf( painCave.errMsg,
264 >                 "Error at \"%s\", program does not currently support\n"
265 >                 "more than one input bass file.\n"
266 >                 "\n",
267 >                 argV[i]);
268 >        usage();
269 >        painCave.isFatal = 1;
270 >        simError();
271 >      }
272 >      
273 >      inName = argV[i];
274 >      
275 >    }
276 >  }  
277 >  
278 >  if( inName == NULL ){
279      sprintf( painCave.errMsg,
280               "Error, bass file is needed to run.\n" );
281 +    usage();
282      painCave.isFatal = 1;
283      simError();
284    }
285  
46  in_name = argv[1];
47
286    // make the dump name
287    
288 <  strcpy( dumpName, in_name );
288 >  strcpy( dumpName, inName );
289    nameLength = strlen( dumpName );
290    endTest = &(dumpName[nameLength - 5]);
291    if( !strcmp( endTest, ".bass" ) ){
# Line 57 | Line 295 | int main(int argc,char* argv[]){
295      strcpy( endTest, ".dump" );
296    }
297    else{
298 <    endTest = &(dumpName[nameLength - 4]);
61 <    if( !strcmp( endTest, ".bss" ) ){
62 <      strcpy( endTest, ".dump" );
63 <    }
64 <    else if( !strcmp( endTest, ".mdl" ) ){
65 <      strcpy( endTest, ".dump" );
66 <    }
67 <    else{
68 <      strcat( dumpName, ".dump" );
69 <    }
298 >    strcat( dumpName, ".dump" );
299    }
300  
301    // count the number of frames in the dump file.
# Line 91 | Line 320 | int main(int argc,char* argv[]){
320    
321    startMe = new SimSetup();
322    startMe->setSimInfo( infoArray, nFrames );
323 <  startMe->parseFile( in_name );
323 >  startMe->parseFile( inName );
324    startMe->createSim();
325  
326    delete startMe;
# Line 99 | Line 328 | int main(int argc,char* argv[]){
328    printf("done.\n");
329    fflush(stdout);
330  
331 +  printf("Initializing the pair correlations..." );
332 +  fflush(stdout);
333 +  
334 +  theCorrs.setCorrList( theList );
335 +  theCorrs.setFrames( infoArray, nFrames, reader );
336 +  theCorrs.initCorrelations( outPrefix );
337  
338 +  printf("done\n");
339 +  fflush(stdout);
340 +
341 +  theCorrs.calcCorrelations();
342 +  
343    return 0 ;
344   }
345  
346 +
347 + /***************************************************************************
348 + * prints out the usage for the command line arguments, then exits.
349 + ***************************************************************************/
350 +
351 + void usage(){
352 +  (void)fprintf(stdout,
353 +                "\n"
354 +                "The proper usage is: %s [options] <input_file>\n"
355 +                "\n"
356 +                "Options:\n"
357 +                "\n"
358 +                "   short:\n"
359 +                "   ------\n"
360 +                "   -o <name>       The output prefix\n"
361 +                "   -l <maxLength>  set the maximum value of r\n"
362 +                "                     *Defaults to 1/2 smallest length of first frame.\n"
363 +                "   -s              Turn on separate output files\n"
364 +                "                     *Defaults to single output file.\n"
365 +                "\n"
366 +                "   long:\n"
367 +                "   -----\n"
368 +                "   --gofr <atom1> <atom2>    g(r) for atom1 and atom2\n"
369 +                "                                *note: \"_ALL_\" matches all atoms/n"
370 +                "   --version                 displays the version number\n"
371 +                "   --help                    displays this help message.\n"
372 +                
373 +                "\n"
374 +                "\n",
375 +                programName);
376 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines