| 1 |
#include <iostream> |
| 2 |
#include <stdio.h> |
| 3 |
#include <stdlib.h> |
| 4 |
#include <string.h> |
| 5 |
#include <vector> |
| 6 |
|
| 7 |
#include "simError.h" |
| 8 |
#include "SimSetup.hpp" |
| 9 |
#include "SimInfo.hpp" |
| 10 |
#include "Atom.hpp" |
| 11 |
#include "Integrator.hpp" |
| 12 |
#include "Thermo.hpp" |
| 13 |
#include "ReadWrite.hpp" |
| 14 |
|
| 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[]){ |
| 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 |
int nBins; |
| 43 |
|
| 44 |
vector<PairCorrList> theList; |
| 45 |
pairCorrEnum pairType; |
| 46 |
|
| 47 |
char* pair1; |
| 48 |
char* pair2; |
| 49 |
|
| 50 |
char dumpName[2000]; |
| 51 |
char* endTest; |
| 52 |
int nameLength; |
| 53 |
int nFrames; |
| 54 |
char* inName; |
| 55 |
SimSetup* startMe; |
| 56 |
SimInfo* infoArray; |
| 57 |
DumpReader* reader; |
| 58 |
AllCorr theCorrs; |
| 59 |
|
| 60 |
// first things first, all of the initializations |
| 61 |
|
| 62 |
printf("Initializing stuff ....\n"); |
| 63 |
fflush(sdtout); |
| 64 |
srand48( 1337 ); // the random number generator. |
| 65 |
initSimError(); // the error handler |
| 66 |
|
| 67 |
outPrefix = NULL; |
| 68 |
inName = NULL; |
| 69 |
|
| 70 |
conversionError = false; |
| 71 |
optionError = false; |
| 72 |
|
| 73 |
havePrefix = false; |
| 74 |
haveMaxLength = false; |
| 75 |
|
| 76 |
maxLength = 1.0; |
| 77 |
nBins = 100; |
| 78 |
|
| 79 |
programName = argv[0]; /*save the program name in case we need it*/ |
| 80 |
|
| 81 |
for( i = 1; i < argC; i++){ |
| 82 |
|
| 83 |
if(argV[i][0] =='-'){ |
| 84 |
|
| 85 |
// parse the option |
| 86 |
|
| 87 |
if(argV[i][1] == '-' ){ |
| 88 |
|
| 89 |
// parse long word options |
| 90 |
|
| 91 |
if( !strcmp( argV[i], "--gofr" ) ){ |
| 92 |
|
| 93 |
i++; |
| 94 |
if( i>=argC ){ |
| 95 |
sprintf( painCave.errMsg, |
| 96 |
"\n" |
| 97 |
"not enough arguments for --gofr\n"); |
| 98 |
usage(); |
| 99 |
painCave.isFatal = 1; |
| 100 |
simError(); |
| 101 |
} |
| 102 |
pair1 = argV[i]; |
| 103 |
|
| 104 |
i++; |
| 105 |
if( i>=argC ){ |
| 106 |
sprintf( painCave.errMsg, |
| 107 |
"\n" |
| 108 |
"not enough arguments for --gofr\n"); |
| 109 |
usage(); |
| 110 |
painCave.isFatal = 1; |
| 111 |
simError(); |
| 112 |
} |
| 113 |
pair2 = argV[i]; |
| 114 |
|
| 115 |
pairType = gofr; |
| 116 |
theList.push_back(PairCorrList( pairType, pair1, pair2 )); |
| 117 |
} |
| 118 |
|
| 119 |
else if( !strcmp( argV[i], "--version") ){ |
| 120 |
|
| 121 |
printf("\n" |
| 122 |
"staticProps version %d.%d\n" |
| 123 |
"\n", |
| 124 |
VERSION_MAJOR, VERSION_MINOR ); |
| 125 |
exit(0); |
| 126 |
|
| 127 |
} |
| 128 |
|
| 129 |
else if( !strcmp( argV[i], "--help") ){ |
| 130 |
|
| 131 |
usage(); |
| 132 |
exit(0); |
| 133 |
} |
| 134 |
|
| 135 |
// anything else is an error |
| 136 |
|
| 137 |
else{ |
| 138 |
fprintf( stderr, |
| 139 |
"Invalid option \"%s\"\n", argV[i] ); |
| 140 |
usage(); |
| 141 |
exit(0); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
else{ |
| 146 |
|
| 147 |
// parse single character options |
| 148 |
|
| 149 |
done =0; |
| 150 |
j = 1; |
| 151 |
currentFlag = argV[i][j]; |
| 152 |
while( (currentFlag != '\0') && (!done) ){ |
| 153 |
|
| 154 |
switch(currentFlag){ |
| 155 |
|
| 156 |
case 'o': |
| 157 |
// -o <prefix> => the output prefix. |
| 158 |
|
| 159 |
j++; |
| 160 |
currentFlag = argV[i][j]; |
| 161 |
|
| 162 |
if( currentFlag != '\0' ) optionError = true; |
| 163 |
|
| 164 |
if( optionError ){ |
| 165 |
sprintf( painCave.errMsg, |
| 166 |
"\n" |
| 167 |
"The -o flag should end an option sequence.\n" |
| 168 |
" example: -r <outname> *NOT* -or <outname>\n" ); |
| 169 |
usage(); |
| 170 |
painCave.isFatal = 1; |
| 171 |
simError(); |
| 172 |
} |
| 173 |
|
| 174 |
i++; |
| 175 |
if( i>=argC ){ |
| 176 |
sprintf( painCave.errMsg, |
| 177 |
"\n" |
| 178 |
"not enough arguments for -o\n"); |
| 179 |
usage(); |
| 180 |
painCave.isFatal = 1; |
| 181 |
simError(); |
| 182 |
} |
| 183 |
|
| 184 |
outPrefix = argV[i]; |
| 185 |
if( outPrefix[0] == '-' ) optionError = true; |
| 186 |
|
| 187 |
if( optionError ){ |
| 188 |
sprintf( painCave.errMsg, |
| 189 |
"\n" |
| 190 |
"\"%s\" is not a valid out prefix/name.\n" |
| 191 |
"Out prefix/name should not begin with a dash.\n", |
| 192 |
outPrefix ); |
| 193 |
usage(); |
| 194 |
painCave.isFatal = 1; |
| 195 |
simError(); |
| 196 |
} |
| 197 |
|
| 198 |
havePrefix = true; |
| 199 |
done = true; |
| 200 |
break; |
| 201 |
|
| 202 |
case 'l': |
| 203 |
// -l <double> set <double> to the maxLength |
| 204 |
|
| 205 |
haveMaxLength = true; |
| 206 |
j++; |
| 207 |
currentFlag = argV[i][j]; |
| 208 |
|
| 209 |
if( currentFlag != '\0' ) optionError = true; |
| 210 |
|
| 211 |
if( optionError ){ |
| 212 |
sprintf( painCave.errMsg, |
| 213 |
"\n" |
| 214 |
"The -l flag should end an option sequence.\n" |
| 215 |
" example: -sl <double> *NOT* -ls <double>\n" ); |
| 216 |
usage(); |
| 217 |
painCave.isFatal = 1; |
| 218 |
simError(); |
| 219 |
} |
| 220 |
|
| 221 |
i++; |
| 222 |
if( i>=argC ){ |
| 223 |
sprintf( painCave.errMsg, |
| 224 |
"\n" |
| 225 |
"not enough arguments for -l\n"); |
| 226 |
usage(); |
| 227 |
painCave.isFatal = 1; |
| 228 |
simError(); |
| 229 |
} |
| 230 |
|
| 231 |
maxLength = strtod( argV[i], &conversionCheck); |
| 232 |
if( conversionCheck == argV[i] ) conversionError = true; |
| 233 |
if( *conversionCheck != '\0' ) conversionError = true; |
| 234 |
|
| 235 |
if( conversionError ){ |
| 236 |
sprintf( painCave.errMsg, |
| 237 |
"Error converting \"%s\" to a double for maxLength.\n", |
| 238 |
argV[i] ); |
| 239 |
usage(); |
| 240 |
painCave.isFatal = 1; |
| 241 |
simError(); |
| 242 |
} |
| 243 |
|
| 244 |
done = true; |
| 245 |
|
| 246 |
break; |
| 247 |
|
| 248 |
case 'n': |
| 249 |
// -n <int> set <int> to the nBins |
| 250 |
|
| 251 |
j++; |
| 252 |
currentFlag = argV[i][j]; |
| 253 |
|
| 254 |
if( currentFlag != '\0' ) optionError = true; |
| 255 |
|
| 256 |
if( optionError ){ |
| 257 |
sprintf( painCave.errMsg, |
| 258 |
"\n" |
| 259 |
"The -n flag should end an option sequence.\n" |
| 260 |
" example: -sn <int> *NOT* -ns <int>\n" ); |
| 261 |
usage(); |
| 262 |
painCave.isFatal = 1; |
| 263 |
simError(); |
| 264 |
} |
| 265 |
|
| 266 |
i++; |
| 267 |
if( i>=argC ){ |
| 268 |
sprintf( painCave.errMsg, |
| 269 |
"\n" |
| 270 |
"not enough arguments for -n\n"); |
| 271 |
usage(); |
| 272 |
painCave.isFatal = 1; |
| 273 |
simError(); |
| 274 |
} |
| 275 |
|
| 276 |
nBins = strtol( argV[i], &conversionCheck, 10 ); |
| 277 |
if( conversionCheck == argV[i] ) conversionError = true; |
| 278 |
if( *conversionCheck != '\0' ) conversionError = true; |
| 279 |
|
| 280 |
if( conversionError ){ |
| 281 |
sprintf( painCave.errMsg, |
| 282 |
"Error converting \"%s\" to an int for nBins.\n", |
| 283 |
argV[i] ); |
| 284 |
usage(); |
| 285 |
painCave.isFatal = 1; |
| 286 |
simError(); |
| 287 |
} |
| 288 |
|
| 289 |
if( nBins < 1 ){ |
| 290 |
sprintf( painCave.errMsg, |
| 291 |
"nBins error: nBins = %d is less than 1.\n", |
| 292 |
nBins ); |
| 293 |
usage(); |
| 294 |
painCave.isFatal = 1; |
| 295 |
simError(); |
| 296 |
} |
| 297 |
|
| 298 |
done = true; |
| 299 |
|
| 300 |
break; |
| 301 |
|
| 302 |
default: |
| 303 |
|
| 304 |
sprintf(painCave.errMsg, |
| 305 |
"\n" |
| 306 |
"Bad option \"-%c\"\n", currentFlag); |
| 307 |
usage(); |
| 308 |
painCave.isFatal = 1; |
| 309 |
simError(); |
| 310 |
} |
| 311 |
j++; |
| 312 |
currentFlag = argV[i][j]; |
| 313 |
} |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
else{ |
| 318 |
|
| 319 |
if( inName != NULL ){ |
| 320 |
sprintf( painCave.errMsg, |
| 321 |
"Error at \"%s\", program does not currently support\n" |
| 322 |
"more than one input bass file.\n" |
| 323 |
"\n", |
| 324 |
argV[i]); |
| 325 |
usage(); |
| 326 |
painCave.isFatal = 1; |
| 327 |
simError(); |
| 328 |
} |
| 329 |
|
| 330 |
inName = argV[i]; |
| 331 |
|
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
if( inName == NULL ){ |
| 336 |
sprintf( painCave.errMsg, |
| 337 |
"Error, bass file is needed to run.\n" ); |
| 338 |
usage(); |
| 339 |
painCave.isFatal = 1; |
| 340 |
simError(); |
| 341 |
} |
| 342 |
|
| 343 |
// make the dump name |
| 344 |
|
| 345 |
strcpy( dumpName, inName ); |
| 346 |
nameLength = strlen( dumpName ); |
| 347 |
endTest = &(dumpName[nameLength - 5]); |
| 348 |
if( !strcmp( endTest, ".bass" ) ){ |
| 349 |
strcpy( endTest, ".dump" ); |
| 350 |
} |
| 351 |
else if( !strcmp( endTest, ".BASS" ) ){ |
| 352 |
strcpy( endTest, ".dump" ); |
| 353 |
} |
| 354 |
else{ |
| 355 |
strcat( dumpName, ".dump" ); |
| 356 |
} |
| 357 |
|
| 358 |
// count the number of frames in the dump file. |
| 359 |
|
| 360 |
printf("Counting the number of frames in \"%s\"... ", dumpName ); |
| 361 |
fflush(stdout); |
| 362 |
|
| 363 |
reader = new DumpReader( dumpName ); |
| 364 |
nFrames = reader->getNframes(); |
| 365 |
|
| 366 |
printf("done.\n" |
| 367 |
"\tFound %d frames.\n" |
| 368 |
"\n", |
| 369 |
nFrames ); |
| 370 |
fflush(stdout); |
| 371 |
|
| 372 |
infoArray = new SimInfo[nFrames]; |
| 373 |
|
| 374 |
printf("Parsing the bass file, and initializing the " |
| 375 |
"Simulation Frames..." ); |
| 376 |
fflush(stdout); |
| 377 |
|
| 378 |
startMe = new SimSetup(); |
| 379 |
startMe->setSimInfo( infoArray, nFrames ); |
| 380 |
startMe->parseFile( inName ); |
| 381 |
startMe->createSim(); |
| 382 |
|
| 383 |
delete startMe; |
| 384 |
|
| 385 |
printf("done.\n"); |
| 386 |
fflush(stdout); |
| 387 |
|
| 388 |
printf("Initializing the pair correlations..." ); |
| 389 |
fflush(stdout); |
| 390 |
|
| 391 |
if(haveMaxLength) |
| 392 |
theCorrs.setMaxLength( maxLength ); |
| 393 |
|
| 394 |
theCorrs.setNbins( nBins ); |
| 395 |
theCorrs.setFrames( infoArray, nFrames, reader ); |
| 396 |
theCorrs.setPairCorrList( theList ); |
| 397 |
theCorrs.initCorrelations( outPrefix ); |
| 398 |
|
| 399 |
printf("done\n"); |
| 400 |
fflush(stdout); |
| 401 |
|
| 402 |
theCorrs.calcCorrelations(); |
| 403 |
|
| 404 |
return 0 ; |
| 405 |
} |
| 406 |
|
| 407 |
|
| 408 |
/*************************************************************************** |
| 409 |
* prints out the usage for the command line arguments, then exits. |
| 410 |
***************************************************************************/ |
| 411 |
|
| 412 |
void usage(){ |
| 413 |
(void)fprintf(stdout, |
| 414 |
"\n" |
| 415 |
"The proper usage is: %s [options] <input_file>\n" |
| 416 |
"\n" |
| 417 |
"Options:\n" |
| 418 |
"\n" |
| 419 |
" short:\n" |
| 420 |
" ------\n" |
| 421 |
" -o <name> The output prefix\n" |
| 422 |
" -n <nBins> Set the number of bins in the Histogram.\n" |
| 423 |
" *Defaults to 100\n" |
| 424 |
" -l <maxLength> set the maximum value of r\n" |
| 425 |
" *Defaults to 1/2 smallest length of first frame.\n" |
| 426 |
" -s Turn on separate output files\n" |
| 427 |
" *Defaults to single output file.\n" |
| 428 |
"\n" |
| 429 |
" long:\n" |
| 430 |
" -----\n" |
| 431 |
" --gofr <atom1> <atom2> g(r) for atom1 and atom2\n" |
| 432 |
" *note: \"_ALL_\" matches all atoms/n" |
| 433 |
" --version displays the version number\n" |
| 434 |
" --help displays this help message.\n" |
| 435 |
|
| 436 |
"\n" |
| 437 |
"\n", |
| 438 |
programName); |
| 439 |
} |