| 1 | #define _LARGEFILE_SOURCE64 | 
| 2 | #define _FILE_OFFSET_BITS 64 | 
| 3 |  | 
| 4 | #include <sys/types.h> | 
| 5 | #include <sys/stat.h> | 
| 6 |  | 
| 7 | #include <iostream> | 
| 8 | #include <math.h> | 
| 9 |  | 
| 10 | #include <stdio.h> | 
| 11 | #include <stdlib.h> | 
| 12 | #include <string.h> | 
| 13 |  | 
| 14 |  | 
| 15 | #include "ReadWrite.hpp" | 
| 16 | #include "simError.h" | 
| 17 |  | 
| 18 | #ifdef IS_MPI | 
| 19 | #include <mpi.h> | 
| 20 | #include "mpiSimulation.hpp" | 
| 21 | #define TAKE_THIS_TAG_CHAR 0 | 
| 22 | #define TAKE_THIS_TAG_INT 1 | 
| 23 | #endif // is_mpi | 
| 24 |  | 
| 25 | namespace dumpRead{ | 
| 26 |  | 
| 27 | #ifdef IS_MPI | 
| 28 | void nodeZeroError( void ); | 
| 29 | void anonymousNodeDie( void ); | 
| 30 | #endif // is_mpi | 
| 31 |  | 
| 32 | } | 
| 33 |  | 
| 34 | using namespace dumpRead; | 
| 35 |  | 
| 36 |  | 
| 37 | DumpReader :: DumpReader(const char *in_name ){ | 
| 38 |  | 
| 39 | isScanned = false; | 
| 40 | headFP = new FilePos; | 
| 41 |  | 
| 42 | #ifdef IS_MPI | 
| 43 | if (worldRank == 0) { | 
| 44 | #endif | 
| 45 |  | 
| 46 | inFile = fopen(in_name, "r"); | 
| 47 | if(inFile == NULL){ | 
| 48 | sprintf(painCave.errMsg, | 
| 49 | "Cannot open file: %s\n", in_name); | 
| 50 | painCave.isFatal = 1; | 
| 51 | simError(); | 
| 52 | } | 
| 53 |  | 
| 54 | strcpy( inName, in_name); | 
| 55 | #ifdef IS_MPI | 
| 56 | } | 
| 57 | strcpy( checkPointMsg, "Dump file opened for reading successfully." ); | 
| 58 | MPIcheckPoint(); | 
| 59 | #endif | 
| 60 | return; | 
| 61 | } | 
| 62 |  | 
| 63 | DumpReader :: ~DumpReader( ){ | 
| 64 | #ifdef IS_MPI | 
| 65 | if (worldRank == 0) { | 
| 66 | #endif | 
| 67 | int error; | 
| 68 | error = fclose( inFile ); | 
| 69 | if( error ){ | 
| 70 | sprintf( painCave.errMsg, | 
| 71 | "Error closing %s\n", inName ); | 
| 72 | simError(); | 
| 73 | } | 
| 74 | #ifdef IS_MPI | 
| 75 | } | 
| 76 | strcpy( checkPointMsg, "Dump file closed successfully." ); | 
| 77 | MPIcheckPoint(); | 
| 78 | #endif | 
| 79 |  | 
| 80 | return; | 
| 81 | } | 
| 82 |  | 
| 83 | int DumpReader::getNframes( void ){ | 
| 84 |  | 
| 85 | if( !isScanned ) scanFile(); | 
| 86 | return nFrames; | 
| 87 | } | 
| 88 |  | 
| 89 | void DumpReader::scanFile( void ){ | 
| 90 |  | 
| 91 | int vectorSize; | 
| 92 | int i, j, k; | 
| 93 | int lineNum = 0; | 
| 94 | char readBuffer[2000]; | 
| 95 | char* foo; | 
| 96 | fpos_t *currPos; | 
| 97 | double time; | 
| 98 |  | 
| 99 | FilePos *currFP; | 
| 100 |  | 
| 101 |  | 
| 102 | #ifdef IS_MPI | 
| 103 | if( worldRank == 0 ){ | 
| 104 | #endif // is_mpi | 
| 105 |  | 
| 106 | rewind( inFile ); | 
| 107 |  | 
| 108 | currPos = new fpos_t; | 
| 109 | fgetpos( inFile, currPos ); | 
| 110 | fgets( readBuffer, sizeof( readBuffer ), inFile ); | 
| 111 | lineNum++; | 
| 112 | if( feof( inFile ) ){ | 
| 113 | sprintf( painCave.errMsg, | 
| 114 | "File \"%s\" ended unexpectedly at line %d\n", | 
| 115 | inName, | 
| 116 | lineNum ); | 
| 117 | painCave.isFatal = 1; | 
| 118 | simError(); | 
| 119 | } | 
| 120 |  | 
| 121 | nFrames = 0; | 
| 122 | while( !feof( inFile ) ){ | 
| 123 |  | 
| 124 | headFP->add( currPos ); | 
| 125 | nFrames++; | 
| 126 |  | 
| 127 | i = atoi(readBuffer); | 
| 128 |  | 
| 129 | fgets( readBuffer, sizeof( readBuffer ), inFile ); | 
| 130 | lineNum++; | 
| 131 | if( feof( inFile ) ){ | 
| 132 | sprintf( painCave.errMsg, | 
| 133 | "File \"%s\" ended unexpectedly at line %d\n", | 
| 134 | inName, | 
| 135 | lineNum ); | 
| 136 | painCave.isFatal = 1; | 
| 137 | simError(); | 
| 138 | } | 
| 139 |  | 
| 140 | //       if(outTime){ | 
| 141 | //      foo = strtok( readBuffer, " ,;\t" ); | 
| 142 | //      time = atof( foo ); | 
| 143 | //       } | 
| 144 |  | 
| 145 | for(j=0; j<i; j++){ | 
| 146 |  | 
| 147 | fgets( readBuffer, sizeof( readBuffer ), inFile ); | 
| 148 | lineNum++; | 
| 149 | if( feof( inFile ) ){ | 
| 150 | sprintf( painCave.errMsg, | 
| 151 | "File \"%s\" ended unexpectedly at line %d," | 
| 152 | " with atom %d\n", | 
| 153 | inName, | 
| 154 | lineNum, | 
| 155 | j ); | 
| 156 | painCave.isFatal = 1; | 
| 157 | simError(); | 
| 158 | } | 
| 159 |  | 
| 160 | } | 
| 161 |  | 
| 162 | currPos = new fpos_t; | 
| 163 | fgetpos( inFile, currPos ); | 
| 164 | fgets( readBuffer, sizeof( readBuffer ), inFile ); | 
| 165 | lineNum++; | 
| 166 | } | 
| 167 |  | 
| 168 | delete currPos; | 
| 169 | rewind( inFile ); | 
| 170 |  | 
| 171 | frameStart = new FilePos*[nFrames]; | 
| 172 | currFP = headFP; | 
| 173 | for(i=0; i<nFrames; i++){ | 
| 174 |  | 
| 175 | currFP = currFP->getNext(); | 
| 176 | if( currFP == NULL ){ | 
| 177 | sprintf( painCave.errMsg, | 
| 178 | "DumpReader error: scanFile FilePos mismatch at " | 
| 179 | "nFrames = %d\n", | 
| 180 | i ); | 
| 181 | painCave.isFatal = 1; | 
| 182 | simError(); | 
| 183 | } | 
| 184 |  | 
| 185 | frameStart[i] = currFP; | 
| 186 | } | 
| 187 |  | 
| 188 | isScanned = true; | 
| 189 |  | 
| 190 | #ifdef IS_MPI | 
| 191 | } | 
| 192 | strcpy( checkPointMsg, "Successfully scanned DumpFile\n" ); | 
| 193 | MPIcheckPoint(); | 
| 194 | #endif // is_mpi | 
| 195 | } | 
| 196 |  | 
| 197 | void DumpReader :: readFrame( SimInfo* the_simnfo, int whichFrame){ | 
| 198 |  | 
| 199 | simnfo = the_simnfo; | 
| 200 |  | 
| 201 | this->readSet( whichFrame ); | 
| 202 | } | 
| 203 |  | 
| 204 |  | 
| 205 |  | 
| 206 | void DumpReader :: readSet( int whichFrame ){ | 
| 207 |  | 
| 208 | int i, j, done, which_node, which_atom; // loop counter | 
| 209 |  | 
| 210 | const int BUFFERSIZE = 2000; // size of the read buffer | 
| 211 | int n_atoms; // the number of atoms | 
| 212 | char read_buffer[BUFFERSIZE]; //the line buffer for reading | 
| 213 | #ifdef IS_MPI | 
| 214 | char send_buffer[BUFFERSIZE]; | 
| 215 | #endif | 
| 216 |  | 
| 217 | char *eof_test; // ptr to see when we reach the end of the file | 
| 218 | char *parseErr; | 
| 219 | int procIndex; | 
| 220 | double boxMat[9]; | 
| 221 | double theBoxMat3[3][3]; | 
| 222 | double time; | 
| 223 |  | 
| 224 | fpos_t *framePos; | 
| 225 |  | 
| 226 | #ifndef IS_MPI | 
| 227 |  | 
| 228 | framePos = frameStart[whichFrame]->getPos(); | 
| 229 |  | 
| 230 | fsetpos(inFile, framePos); | 
| 231 |  | 
| 232 |  | 
| 233 | eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); | 
| 234 | if( eof_test == NULL ){ | 
| 235 | sprintf( painCave.errMsg, | 
| 236 | "DumpReader error: error reading 1st line of \"%s\"\n", | 
| 237 | inName ); | 
| 238 | painCave.isFatal = 1; | 
| 239 | simError(); | 
| 240 | } | 
| 241 |  | 
| 242 | n_atoms = atoi( read_buffer ); | 
| 243 |  | 
| 244 | Atom **atoms = simnfo->atoms; | 
| 245 | DirectionalAtom* dAtom; | 
| 246 |  | 
| 247 | if( n_atoms != simnfo->n_atoms ){ | 
| 248 | sprintf( painCave.errMsg, | 
| 249 | "DumpReader error. %s n_atoms, %d, " | 
| 250 | "does not match the BASS file's n_atoms, %d.\n", | 
| 251 | inName, n_atoms, simnfo->n_atoms ); | 
| 252 | painCave.isFatal = 1; | 
| 253 | simError(); | 
| 254 | } | 
| 255 |  | 
| 256 | //read the box mat from the comment line | 
| 257 |  | 
| 258 | eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); | 
| 259 | if(eof_test == NULL){ | 
| 260 | sprintf( painCave.errMsg, | 
| 261 | "error in reading commment in %s\n", inName); | 
| 262 | painCave.isFatal = 1; | 
| 263 | simError(); | 
| 264 | } | 
| 265 |  | 
| 266 | parseErr = parseCommentLine( read_buffer, time, boxMat ); | 
| 267 | if( parseErr != NULL ){ | 
| 268 | strcpy( painCave.errMsg, parseErr ); | 
| 269 | painCave.isFatal = 1; | 
| 270 | simError(); | 
| 271 | } | 
| 272 |  | 
| 273 | simnfo->setTime( time ); | 
| 274 |  | 
| 275 | for(i=0;i<3;i++) | 
| 276 | for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; | 
| 277 |  | 
| 278 |  | 
| 279 | simnfo->setBoxM( theBoxMat3 ); | 
| 280 |  | 
| 281 |  | 
| 282 | for( i=0; i < n_atoms; i++){ | 
| 283 |  | 
| 284 | eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); | 
| 285 | if(eof_test == NULL){ | 
| 286 | sprintf(painCave.errMsg, | 
| 287 | "error in reading file %s\n" | 
| 288 | "natoms  = %d; index = %d\n" | 
| 289 | "error reading the line from the file.\n", | 
| 290 | inName, n_atoms, i ); | 
| 291 | painCave.isFatal = 1; | 
| 292 | simError(); | 
| 293 | } | 
| 294 |  | 
| 295 |  | 
| 296 | parseErr = parseDumpLine( read_buffer, i ); | 
| 297 | if( parseErr != NULL ){ | 
| 298 | strcpy( painCave.errMsg, parseErr ); | 
| 299 | painCave.isFatal = 1; | 
| 300 | simError(); | 
| 301 | } | 
| 302 | } | 
| 303 |  | 
| 304 |  | 
| 305 | // MPI Section of code.......... | 
| 306 | #else //IS_MPI | 
| 307 |  | 
| 308 | // first thing first, suspend fatalities. | 
| 309 | painCave.isEventLoop = 1; | 
| 310 |  | 
| 311 | int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone | 
| 312 | int haveError; | 
| 313 |  | 
| 314 | MPI_Status istatus; | 
| 315 | int *AtomToProcMap = mpiSim->getAtomToProcMap(); | 
| 316 |  | 
| 317 |  | 
| 318 | haveError = 0; | 
| 319 | if (worldRank == 0) { | 
| 320 | fsetpos(inFile, framePos); | 
| 321 | eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); | 
| 322 | if( eof_test == NULL ){ | 
| 323 | sprintf( painCave.errMsg, | 
| 324 | "Error reading 1st line of %d \n ",inName); | 
| 325 | haveError = 1; | 
| 326 | simError(); | 
| 327 | } | 
| 328 |  | 
| 329 | n_atoms = atoi( read_buffer ); | 
| 330 |  | 
| 331 | Atom **atoms = simnfo->atoms; | 
| 332 | DirectionalAtom* dAtom; | 
| 333 |  | 
| 334 | // Check to see that the number of atoms in the intial configuration file is the | 
| 335 | // same as declared in simBass. | 
| 336 |  | 
| 337 | if( n_atoms != mpiSim->getTotAtoms() ){ | 
| 338 | sprintf( painCave.errMsg, | 
| 339 | "Initialize from File error. %s n_atoms, %d, " | 
| 340 | "does not match the BASS file's n_atoms, %d.\n", | 
| 341 | inName, n_atoms, simnfo->n_atoms ); | 
| 342 | haveError= 1; | 
| 343 | simError(); | 
| 344 | } | 
| 345 |  | 
| 346 | //read the time and boxMat from the comment line | 
| 347 |  | 
| 348 | eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); | 
| 349 | if(eof_test == NULL){ | 
| 350 | sprintf( painCave.errMsg, | 
| 351 | "error in reading commment in %s\n", inName); | 
| 352 | haveError = 1; | 
| 353 | simError(); | 
| 354 | } | 
| 355 |  | 
| 356 | parseErr = parseCommentLine( read_buffer, time, boxMat ); | 
| 357 | if( parseErr != NULL ){ | 
| 358 | strcpy( painCave.errMsg, parseErr ); | 
| 359 | haveError = 1; | 
| 360 | simError(); | 
| 361 | } | 
| 362 |  | 
| 363 | MPI_Bcast(&time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD ); | 
| 364 |  | 
| 365 | MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD ); | 
| 366 |  | 
| 367 | if(haveError) nodeZeroError(); | 
| 368 |  | 
| 369 | for (i=0 ; i < mpiSim->getTotAtoms(); i++) { | 
| 370 |  | 
| 371 | eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); | 
| 372 | if(eof_test == NULL){ | 
| 373 | sprintf(painCave.errMsg, | 
| 374 | "error in reading file %s\n" | 
| 375 | "natoms  = %d; index = %d\n" | 
| 376 | "error reading the line from the file.\n", | 
| 377 | inName, n_atoms, i ); | 
| 378 | haveError= 1; | 
| 379 | simError(); | 
| 380 | } | 
| 381 |  | 
| 382 | if(haveError) nodeZeroError(); | 
| 383 |  | 
| 384 | // Get the Node number which wants this atom: | 
| 385 | which_node = AtomToProcMap[i]; | 
| 386 | if (which_node == 0) { | 
| 387 | parseErr = parseDumpLine( read_buffer, i ); | 
| 388 | if( parseErr != NULL ){ | 
| 389 | strcpy( painCave.errMsg, parseErr ); | 
| 390 | haveError = 1; | 
| 391 | simError(); | 
| 392 | } | 
| 393 | if(haveError) nodeZeroError(); | 
| 394 | } | 
| 395 |  | 
| 396 | else { | 
| 397 |  | 
| 398 | myStatus = 1; | 
| 399 | MPI_Send(&myStatus, 1, MPI_INT, which_node, | 
| 400 | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); | 
| 401 | MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, | 
| 402 | TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); | 
| 403 | MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, | 
| 404 | MPI_COMM_WORLD); | 
| 405 | MPI_Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, | 
| 406 | MPI_COMM_WORLD, &istatus); | 
| 407 |  | 
| 408 | if(!myStatus) nodeZeroError(); | 
| 409 | } | 
| 410 | } | 
| 411 | myStatus = -1; | 
| 412 | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { | 
| 413 | MPI_Send( &myStatus, 1, MPI_INT, j, | 
| 414 | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); | 
| 415 | } | 
| 416 |  | 
| 417 | } else { | 
| 418 |  | 
| 419 | MPI_Bcast(&time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); | 
| 420 | MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD); | 
| 421 |  | 
| 422 | done = 0; | 
| 423 | while (!done) { | 
| 424 |  | 
| 425 | MPI_Recv(&myStatus, 1, MPI_INT, 0, | 
| 426 | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); | 
| 427 |  | 
| 428 | if(!myStatus) anonymousNodeDie(); | 
| 429 |  | 
| 430 | if(myStatus < 0) break; | 
| 431 |  | 
| 432 | MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, | 
| 433 | TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); | 
| 434 | MPI_Recv(&which_atom, 1, MPI_INT, 0, | 
| 435 | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); | 
| 436 |  | 
| 437 | myStatus = 1; | 
| 438 | parseErr = parseDumpLine( read_buffer, which_atom ); | 
| 439 | if( parseErr != NULL ){ | 
| 440 | strcpy( painCave.errMsg, parseErr ); | 
| 441 | myStatus = 0;; | 
| 442 | simError(); | 
| 443 | } | 
| 444 |  | 
| 445 | MPI_Send( &myStatus, 1, MPI_INT, 0, | 
| 446 | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); | 
| 447 |  | 
| 448 | } | 
| 449 | } | 
| 450 |  | 
| 451 | // last  thing last, enable  fatalities. | 
| 452 | painCave.isEventLoop = 0; | 
| 453 |  | 
| 454 | simnfo->setTime( time ); | 
| 455 |  | 
| 456 | for(i=0;i<3;i++) | 
| 457 | for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; | 
| 458 |  | 
| 459 | simnfo->setBoxM( theBoxMat3 ); | 
| 460 |  | 
| 461 |  | 
| 462 | #endif | 
| 463 | } | 
| 464 |  | 
| 465 | char* DumpReader::parseDumpLine(char* readLine, int globalIndex){ | 
| 466 |  | 
| 467 | char *foo; // the pointer to the current string token | 
| 468 |  | 
| 469 | double pos[3]; // position place holders | 
| 470 | double vel[3]; // velocity placeholders | 
| 471 | double q[4]; // the quaternions | 
| 472 | double jx, jy, jz; // angular velocity placeholders; | 
| 473 | double qSqr, qLength; // needed to normalize the quaternion vector. | 
| 474 |  | 
| 475 | Atom **atoms = simnfo->atoms; | 
| 476 | DirectionalAtom* dAtom; | 
| 477 |  | 
| 478 | int j, n_atoms, atomIndex; | 
| 479 |  | 
| 480 | #ifdef IS_MPI | 
| 481 | n_atoms = mpiSim->getTotAtoms(); | 
| 482 | atomIndex=-1; | 
| 483 | for (j=0; j < mpiSim->getMyNlocal(); j++) { | 
| 484 | if (atoms[j]->getGlobalIndex() == globalIndex) atomIndex = j; | 
| 485 | } | 
| 486 | if (atomIndex == -1) { | 
| 487 | sprintf( painCave.errMsg, | 
| 488 | "Initialize from file error. Atom at index %d " | 
| 489 | "in file %s does not exist on processor %d .\n", | 
| 490 | globalIndex, inName, mpiSim->getMyNode() ); | 
| 491 | return strdup( painCave.errMsg ); | 
| 492 | } | 
| 493 | #else | 
| 494 | n_atoms = simnfo->n_atoms; | 
| 495 | atomIndex = globalIndex; | 
| 496 | #endif // is_mpi | 
| 497 |  | 
| 498 | // set the string tokenizer | 
| 499 |  | 
| 500 | foo = strtok(readLine, " ,;\t"); | 
| 501 | atoms[atomIndex]->setType(foo); | 
| 502 | // check the atom name to the current atom | 
| 503 |  | 
| 504 | //if( strcmp( foo, atoms[atomIndex]->getType() ) ){ | 
| 505 | //  sprintf( painCave.errMsg, | 
| 506 | //    "Initialize from file error. Atom %s at index %d " | 
| 507 | //     "in file %s does not" | 
| 508 | //     " match the BASS atom %s.\n", | 
| 509 | //     foo, atomIndex, inName, atoms[atomIndex]->getType() ); | 
| 510 | //  return strdup( painCave.errMsg ); | 
| 511 | //} | 
| 512 |  | 
| 513 | // get the positions | 
| 514 |  | 
| 515 | foo = strtok(NULL, " ,;\t"); | 
| 516 | if(foo == NULL){ | 
| 517 | sprintf( painCave.errMsg, | 
| 518 | "error in reading postition x from %s\n" | 
| 519 | "natoms  = %d, index = %d\n", | 
| 520 | inName, n_atoms, atomIndex ); | 
| 521 | return strdup( painCave.errMsg ); | 
| 522 | } | 
| 523 | pos[0] = atof( foo ); | 
| 524 |  | 
| 525 | foo = strtok(NULL, " ,;\t"); | 
| 526 | if(foo == NULL){ | 
| 527 | sprintf( painCave.errMsg, | 
| 528 | "error in reading postition y from %s\n" | 
| 529 | "natoms  = %d, index = %d\n", | 
| 530 | inName, n_atoms, atomIndex ); | 
| 531 | return strdup( painCave.errMsg ); | 
| 532 | } | 
| 533 | pos[1] = atof( foo ); | 
| 534 |  | 
| 535 | foo = strtok(NULL, " ,;\t"); | 
| 536 | if(foo == NULL){ | 
| 537 | sprintf( painCave.errMsg, | 
| 538 | "error in reading postition z from %s\n" | 
| 539 | "natoms  = %d, index = %d\n", | 
| 540 | inName, n_atoms, atomIndex ); | 
| 541 | return strdup( painCave.errMsg ); | 
| 542 | } | 
| 543 | pos[2] = atof( foo ); | 
| 544 |  | 
| 545 |  | 
| 546 | // get the velocities | 
| 547 |  | 
| 548 | foo = strtok(NULL, " ,;\t"); | 
| 549 | if(foo == NULL){ | 
| 550 | sprintf( painCave.errMsg, | 
| 551 | "error in reading velocity x from %s\n" | 
| 552 | "natoms  = %d, index = %d\n", | 
| 553 | inName, n_atoms, atomIndex ); | 
| 554 | return strdup( painCave.errMsg ); | 
| 555 | } | 
| 556 | vel[0] = atof( foo ); | 
| 557 |  | 
| 558 | foo = strtok(NULL, " ,;\t"); | 
| 559 | if(foo == NULL){ | 
| 560 | sprintf( painCave.errMsg, | 
| 561 | "error in reading velocity y from %s\n" | 
| 562 | "natoms  = %d, index = %d\n", | 
| 563 | inName, n_atoms, atomIndex ); | 
| 564 | return strdup( painCave.errMsg ); | 
| 565 | } | 
| 566 | vel[1] = atof( foo ); | 
| 567 |  | 
| 568 | foo = strtok(NULL, " ,;\t"); | 
| 569 | if(foo == NULL){ | 
| 570 | sprintf( painCave.errMsg, | 
| 571 | "error in reading velocity z from %s\n" | 
| 572 | "natoms  = %d, index = %d\n", | 
| 573 | inName, n_atoms, atomIndex ); | 
| 574 | return strdup( painCave.errMsg ); | 
| 575 | } | 
| 576 | vel[2] = atof( foo ); | 
| 577 |  | 
| 578 |  | 
| 579 | // get the quaternions | 
| 580 |  | 
| 581 | if( atoms[atomIndex]->isDirectional() ){ | 
| 582 |  | 
| 583 | foo = strtok(NULL, " ,;\t"); | 
| 584 | if(foo == NULL){ | 
| 585 | sprintf(painCave.errMsg, | 
| 586 | "error in reading quaternion 0 from %s\n" | 
| 587 | "natoms  = %d, index = %d\n", | 
| 588 | inName, n_atoms, atomIndex ); | 
| 589 | return strdup( painCave.errMsg ); | 
| 590 | } | 
| 591 | q[0] = atof( foo ); | 
| 592 |  | 
| 593 | foo = strtok(NULL, " ,;\t"); | 
| 594 | if(foo == NULL){ | 
| 595 | sprintf( painCave.errMsg, | 
| 596 | "error in reading quaternion 1 from %s\n" | 
| 597 | "natoms  = %d, index = %d\n", | 
| 598 | inName, n_atoms, atomIndex ); | 
| 599 | return strdup( painCave.errMsg ); | 
| 600 | } | 
| 601 | q[1] = atof( foo ); | 
| 602 |  | 
| 603 | foo = strtok(NULL, " ,;\t"); | 
| 604 | if(foo == NULL){ | 
| 605 | sprintf( painCave.errMsg, | 
| 606 | "error in reading quaternion 2 from %s\n" | 
| 607 | "natoms  = %d, index = %d\n", | 
| 608 | inName, n_atoms, atomIndex ); | 
| 609 | return strdup( painCave.errMsg ); | 
| 610 | } | 
| 611 | q[2] = atof( foo ); | 
| 612 |  | 
| 613 | foo = strtok(NULL, " ,;\t"); | 
| 614 | if(foo == NULL){ | 
| 615 | sprintf( painCave.errMsg, | 
| 616 | "error in reading quaternion 3 from %s\n" | 
| 617 | "natoms  = %d, index = %d\n", | 
| 618 | inName, n_atoms, atomIndex ); | 
| 619 | return strdup( painCave.errMsg ); | 
| 620 | } | 
| 621 | q[3] = atof( foo ); | 
| 622 |  | 
| 623 | // get the angular velocities | 
| 624 |  | 
| 625 | foo = strtok(NULL, " ,;\t"); | 
| 626 | if(foo == NULL){ | 
| 627 | sprintf( painCave.errMsg, | 
| 628 | "error in reading angular momentum jx from %s\n" | 
| 629 | "natoms  = %d, index = %d\n", | 
| 630 | inName, n_atoms, atomIndex ); | 
| 631 | return strdup( painCave.errMsg ); | 
| 632 | } | 
| 633 | jx = atof( foo ); | 
| 634 |  | 
| 635 | foo = strtok(NULL, " ,;\t"); | 
| 636 | if(foo == NULL){ | 
| 637 | sprintf( painCave.errMsg, | 
| 638 | "error in reading angular momentum jy from %s\n" | 
| 639 | "natoms  = %d, index = %d\n", | 
| 640 | inName, n_atoms, atomIndex ); | 
| 641 | return strdup( painCave.errMsg ); | 
| 642 | } | 
| 643 | jy = atof(foo ); | 
| 644 |  | 
| 645 | foo = strtok(NULL, " ,;\t"); | 
| 646 | if(foo == NULL){ | 
| 647 | sprintf( painCave.errMsg, | 
| 648 | "error in reading angular momentum jz from %s\n" | 
| 649 | "natoms  = %d, index = %d\n", | 
| 650 | inName, n_atoms, atomIndex ); | 
| 651 | return strdup( painCave.errMsg ); | 
| 652 | } | 
| 653 | jz = atof( foo ); | 
| 654 |  | 
| 655 | dAtom = ( DirectionalAtom* )atoms[atomIndex]; | 
| 656 |  | 
| 657 | // check that the quaternion vector is normalized | 
| 658 |  | 
| 659 | qSqr = (q[0] * q[0]) + (q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3]); | 
| 660 |  | 
| 661 | qLength = sqrt( qSqr ); | 
| 662 | q[0] = q[0] / qLength; | 
| 663 | q[1] = q[1] / qLength; | 
| 664 | q[2] = q[2] / qLength; | 
| 665 | q[3] = q[3] / qLength; | 
| 666 |  | 
| 667 | dAtom->setQ( q ); | 
| 668 |  | 
| 669 | // add the angular velocities | 
| 670 |  | 
| 671 | dAtom->setJx( jx ); | 
| 672 | dAtom->setJy( jy ); | 
| 673 | dAtom->setJz( jz ); | 
| 674 | } | 
| 675 |  | 
| 676 | // add the positions and velocities to the atom | 
| 677 |  | 
| 678 | atoms[atomIndex]->setPos( pos ); | 
| 679 | atoms[atomIndex]->setVel( vel ); | 
| 680 |  | 
| 681 | return NULL; | 
| 682 | } | 
| 683 |  | 
| 684 |  | 
| 685 | char* DumpReader::parseCommentLine(char* readLine, double &time, | 
| 686 | double boxMat[9]){ | 
| 687 |  | 
| 688 | char *foo; // the pointer to the current string token | 
| 689 | int j; | 
| 690 | double chi, integralOfChidt; | 
| 691 | double eta[9]; | 
| 692 |  | 
| 693 | // set the string tokenizer | 
| 694 |  | 
| 695 | foo = strtok(readLine, " ,;\t"); | 
| 696 | if(foo == NULL){ | 
| 697 | sprintf( painCave.errMsg, | 
| 698 | "error in reading time from %s\n", | 
| 699 | inName ); | 
| 700 | return strdup( painCave.errMsg ); | 
| 701 | } | 
| 702 | time = atof( foo ); | 
| 703 |  | 
| 704 | // get the Hx vector | 
| 705 |  | 
| 706 | foo = strtok(NULL, " ,;\t"); | 
| 707 | if(foo == NULL){ | 
| 708 | sprintf( painCave.errMsg, | 
| 709 | "error in reading Hx[0] from %s\n", | 
| 710 | inName ); | 
| 711 | return strdup( painCave.errMsg ); | 
| 712 | } | 
| 713 | boxMat[0] = atof( foo ); | 
| 714 |  | 
| 715 | foo = strtok(NULL, " ,;\t"); | 
| 716 | if(foo == NULL){ | 
| 717 | sprintf( painCave.errMsg, | 
| 718 | "error in reading Hx[1] from %s\n", | 
| 719 | inName ); | 
| 720 | return strdup( painCave.errMsg ); | 
| 721 | } | 
| 722 | boxMat[1] = atof( foo ); | 
| 723 |  | 
| 724 | foo = strtok(NULL, " ,;\t"); | 
| 725 | if(foo == NULL){ | 
| 726 | sprintf( painCave.errMsg, | 
| 727 | "error in reading Hx[2] from %s\n", | 
| 728 | inName ); | 
| 729 | return strdup( painCave.errMsg ); | 
| 730 | } | 
| 731 | boxMat[2] = atof( foo ); | 
| 732 |  | 
| 733 | // get the Hy vector | 
| 734 |  | 
| 735 | foo = strtok(NULL, " ,;\t"); | 
| 736 | if(foo == NULL){ | 
| 737 | sprintf( painCave.errMsg, | 
| 738 | "error in reading Hy[0] from %s\n", | 
| 739 | inName ); | 
| 740 | return strdup( painCave.errMsg ); | 
| 741 | } | 
| 742 | boxMat[3] = atof( foo ); | 
| 743 |  | 
| 744 | foo = strtok(NULL, " ,;\t"); | 
| 745 | if(foo == NULL){ | 
| 746 | sprintf( painCave.errMsg, | 
| 747 | "error in reading Hy[1] from %s\n", | 
| 748 | inName ); | 
| 749 | return strdup( painCave.errMsg ); | 
| 750 | } | 
| 751 | boxMat[4] = atof( foo ); | 
| 752 |  | 
| 753 | foo = strtok(NULL, " ,;\t"); | 
| 754 | if(foo == NULL){ | 
| 755 | sprintf( painCave.errMsg, | 
| 756 | "error in reading Hy[2] from %s\n", | 
| 757 | inName ); | 
| 758 | return strdup( painCave.errMsg ); | 
| 759 | } | 
| 760 | boxMat[5] = atof( foo ); | 
| 761 |  | 
| 762 | // get the Hz vector | 
| 763 |  | 
| 764 | foo = strtok(NULL, " ,;\t"); | 
| 765 | if(foo == NULL){ | 
| 766 | sprintf( painCave.errMsg, | 
| 767 | "error in reading Hz[0] from %s\n", | 
| 768 | inName ); | 
| 769 | return strdup( painCave.errMsg ); | 
| 770 | } | 
| 771 | boxMat[6] = atof( foo ); | 
| 772 |  | 
| 773 | foo = strtok(NULL, " ,;\t"); | 
| 774 | if(foo == NULL){ | 
| 775 | sprintf( painCave.errMsg, | 
| 776 | "error in reading Hz[1] from %s\n", | 
| 777 | inName ); | 
| 778 | return strdup( painCave.errMsg ); | 
| 779 | } | 
| 780 | boxMat[7] = atof( foo ); | 
| 781 |  | 
| 782 | foo = strtok(NULL, " ,;\t"); | 
| 783 | if(foo == NULL){ | 
| 784 | sprintf( painCave.errMsg, | 
| 785 | "error in reading Hz[2] from %s\n", | 
| 786 | inName ); | 
| 787 | return strdup( painCave.errMsg ); | 
| 788 | } | 
| 789 | boxMat[8] = atof( foo ); | 
| 790 |  | 
| 791 | return NULL; | 
| 792 |  | 
| 793 | //get chi and integralOfChidt, they should appear by pair | 
| 794 | foo = strtok(NULL, " ,;\t\n"); | 
| 795 | if(foo != NULL){ | 
| 796 | chi = atof(foo); | 
| 797 |  | 
| 798 | foo = strtok(NULL, " ,;\t\n"); | 
| 799 | if(foo == NULL){ | 
| 800 | sprintf( painCave.errMsg, | 
| 801 | "chi and integralOfChidt should appear by pair in %s\n", inName ); | 
| 802 | return strdup( painCave.errMsg ); | 
| 803 | } | 
| 804 | integralOfChidt = atof( foo ); | 
| 805 |  | 
| 806 | //push chi and integralOfChidt into SimInfo::properties which can be | 
| 807 | //retrieved by integrator later | 
| 808 | DoubleData* chiValue = new DoubleData(); | 
| 809 | chiValue->setID(CHIVALUE_ID); | 
| 810 | chiValue->setData(chi); | 
| 811 | simnfo->addProperty(chiValue); | 
| 812 |  | 
| 813 | DoubleData* integralOfChidtValue = new DoubleData(); | 
| 814 | integralOfChidtValue->setID(INTEGRALOFCHIDT_ID); | 
| 815 | integralOfChidtValue->setData(integralOfChidt); | 
| 816 | simnfo->addProperty(integralOfChidtValue); | 
| 817 |  | 
| 818 | } | 
| 819 | else | 
| 820 | return NULL; | 
| 821 |  | 
| 822 | //get eta | 
| 823 | for(int i = 0 ; i < 9; i++){ | 
| 824 | foo = strtok(NULL, " ,;\t"); | 
| 825 | if(foo == NULL){ | 
| 826 | sprintf( painCave.errMsg, | 
| 827 | "error in reading eta[%d] from %s\n", i, inName ); | 
| 828 | return strdup( painCave.errMsg ); | 
| 829 | } | 
| 830 | eta[i] = atof( foo ); | 
| 831 | } | 
| 832 |  | 
| 833 | //push eta into SimInfo::properties which can be | 
| 834 | //retrieved by integrator later | 
| 835 | //simnfo->setBoxM( theBoxMat3 ); | 
| 836 | DoubleArrayData* etaValue = new DoubleArrayData(); | 
| 837 | etaValue->setID(ETAVALUE_ID); | 
| 838 | etaValue->setData(eta, 9); | 
| 839 | simnfo->addProperty(etaValue); | 
| 840 |  | 
| 841 |  | 
| 842 | return NULL; | 
| 843 |  | 
| 844 |  | 
| 845 |  | 
| 846 | } | 
| 847 |  | 
| 848 |  | 
| 849 | #ifdef IS_MPI | 
| 850 |  | 
| 851 | // a couple of functions to let us escape the read loop | 
| 852 |  | 
| 853 | void dumpRead::nodeZeroError( void ){ | 
| 854 | int j, myStatus; | 
| 855 |  | 
| 856 | myStatus = 0; | 
| 857 | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { | 
| 858 | MPI_Send( &myStatus, 1, MPI_INT, j, | 
| 859 | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); | 
| 860 | } | 
| 861 |  | 
| 862 |  | 
| 863 | MPI_Finalize(); | 
| 864 | exit (0); | 
| 865 |  | 
| 866 | } | 
| 867 |  | 
| 868 | void dumpRead::anonymousNodeDie( void ){ | 
| 869 |  | 
| 870 | MPI_Finalize(); | 
| 871 | exit (0); | 
| 872 | } | 
| 873 |  | 
| 874 | #endif //is_mpi |