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