# | Line 1 | Line 1 | |
---|---|---|
1 | #define _FILE_OFFSET_BITS 64 | |
2 | ||
3 | + | #include <sys/types.h> |
4 | + | #include <sys/stat.h> |
5 | + | |
6 | #include <iostream> | |
7 | #include <cmath> | |
5 | – | #include <vector> |
8 | ||
9 | #include <stdio.h> | |
10 | #include <stdlib.h> | |
11 | #include <string.h> | |
10 | – | #include <unistd.h> |
11 | – | #include <sys/types.h> |
12 | – | #include <sys/stat.h> |
12 | ||
13 | + | |
14 | #include "ReadWrite.hpp" | |
15 | #include "simError.h" | |
16 | ||
# | Line 28 | Line 28 | namespace dumpRead{ | |
28 | void anonymousNodeDie( void ); | |
29 | #endif // is_mpi | |
30 | ||
31 | – | class FilePos{ |
32 | – | |
33 | – | public: |
34 | – | FilePos(){ myPos = NULL; } |
35 | – | FilePos( fpos_t* thePos ) { myPos = thePos; } |
36 | – | ~FilePos(){ if( myPos != NULL ) delete myPos; } |
37 | – | |
38 | – | FilePos &operator=(fpos_t *thePos){ myPos = thePos; return *this; } |
39 | – | |
40 | – | void setPos( fpos_t *thePos ){ myPos = thePos; } |
41 | – | fpos_t *getPos( void ){ return myPos; } |
42 | – | |
43 | – | private: |
44 | – | |
45 | – | fpos_t *myPos |
46 | – | |
47 | – | }; |
48 | – | |
49 | – | bool operator<(FilePos a, FilePos b){ |
50 | – | return (a.getPos())->__pos < (b.getPos())->__pos; } |
51 | – | |
52 | – | bool operator==(FilePos a, FilePos b){ |
53 | – | return (a.getPos())->__pos == (b.getPos())->__pos; } |
54 | – | |
55 | – | vector<FilePos> frameStart; |
31 | } | |
32 | ||
33 | using namespace dumpRead; | |
# | Line 61 | Line 36 | DumpReader :: DumpReader( char *in_name ){ | |
36 | DumpReader :: DumpReader( char *in_name ){ | |
37 | ||
38 | isScanned = false; | |
39 | + | headFP = new FilePos; |
40 | ||
41 | #ifdef IS_MPI | |
42 | if (worldRank == 0) { | |
# | Line 117 | Line 93 | void DumpReader::scanFile( void ){ | |
93 | char readBuffer[2000]; | |
94 | char* foo; | |
95 | fpos_t *currPos; | |
96 | + | double time; |
97 | ||
98 | + | FilePos *currFP; |
99 | + | |
100 | + | |
101 | #ifdef IS_MPI | |
102 | if( worldRank == 0 ){ | |
103 | #endif // is_mpi | |
# | Line 126 | Line 106 | void DumpReader::scanFile( void ){ | |
106 | ||
107 | currPos = new fpos_t; | |
108 | fgetpos( inFile, currPos ); | |
109 | < | fgets( readBuffer, sizeof( readBuffer ), in_file ); |
109 | > | fgets( readBuffer, sizeof( readBuffer ), inFile ); |
110 | lineNum++; | |
111 | < | if( feof( in_file ) ){ |
111 | > | if( feof( inFile ) ){ |
112 | sprintf( painCave.errMsg, | |
113 | "File \"%s\" ended unexpectedly at line %d\n", | |
114 | inName, | |
# | Line 137 | Line 117 | void DumpReader::scanFile( void ){ | |
117 | simError(); | |
118 | } | |
119 | ||
120 | < | while( !feof( in_file ) ){ |
121 | < | |
122 | < | frameStart.push_back( FilePos( currPos ) ); |
120 | > | nFrames = 0; |
121 | > | while( !feof( inFile ) ){ |
122 | > | |
123 | > | headFP->add( currPos ); |
124 | > | nFrames++; |
125 | > | |
126 | i = atoi(readBuffer); | |
127 | ||
128 | < | fgets( readBuffer, sizeof( readBuffer ), in_file ); |
128 | > | fgets( readBuffer, sizeof( readBuffer ), inFile ); |
129 | lineNum++; | |
130 | < | if( feof( in_file ) ){ |
130 | > | if( feof( inFile ) ){ |
131 | sprintf( painCave.errMsg, | |
132 | "File \"%s\" ended unexpectedly at line %d\n", | |
133 | inName, | |
# | Line 153 | Line 136 | void DumpReader::scanFile( void ){ | |
136 | simError(); | |
137 | } | |
138 | ||
139 | < | if(outTime){ |
140 | < | foo = strtok( readBuffer, " ,;\t" ); |
141 | < | time = atof( foo ); |
142 | < | } |
139 | > | // if(outTime){ |
140 | > | // foo = strtok( readBuffer, " ,;\t" ); |
141 | > | // time = atof( foo ); |
142 | > | // } |
143 | ||
144 | for(j=0; j<i; j++){ | |
145 | ||
146 | < | fgets( readBuffer, sizeof( readBuffer ), in_file ); |
146 | > | fgets( readBuffer, sizeof( readBuffer ), inFile ); |
147 | lineNum++; | |
148 | < | if( feof( in_file ) ){ |
148 | > | if( feof( inFile ) ){ |
149 | sprintf( painCave.errMsg, | |
150 | "File \"%s\" ended unexpectedly at line %d," | |
151 | " with atom %d\n", | |
# | Line 177 | Line 160 | void DumpReader::scanFile( void ){ | |
160 | ||
161 | currPos = new fpos_t; | |
162 | fgetpos( inFile, currPos ); | |
163 | < | fgets( readBuffer, sizeof( readBuffer ), in_file ); |
163 | > | fgets( readBuffer, sizeof( readBuffer ), inFile ); |
164 | lineNum++; | |
165 | } | |
166 | ||
167 | delete currPos; | |
185 | – | vectorSize = frameStart.size(); |
168 | rewind( inFile ); | |
169 | ||
170 | + | frameStart = new FilePos*[nFrames]; |
171 | + | currFP = headFP; |
172 | + | for(i=0; i<nFrames; i++){ |
173 | + | |
174 | + | currFP = currFP->getNext(); |
175 | + | if( currFP == NULL ){ |
176 | + | sprintf( painCave.errMsg, |
177 | + | "DumpReader error: scanFile FilePos mismatch at " |
178 | + | "nFrames = %d\n", |
179 | + | i ); |
180 | + | painCave.isFatal = 1; |
181 | + | simError(); |
182 | + | } |
183 | + | |
184 | + | frameStart[i] = currFP; |
185 | + | } |
186 | + | |
187 | + | isScanned = true; |
188 | + | |
189 | #ifdef IS_MPI | |
190 | } | |
191 | strcpy( checkPointMsg, "Successfully scanned DumpFile\n" ); | |
192 | MPIcheckPoint(); | |
193 | #endif // is_mpi | |
193 | – | |
194 | – | nFrames = vectorSize; |
195 | – | isScanned = true; |
194 | } | |
195 | ||
196 | void DumpReader :: readFrame( SimInfo* the_simnfo, int whichFrame){ | |
# | Line 220 | Line 218 | void DumpReader :: readSet( int whichFrame ){ | |
218 | int procIndex; | |
219 | double boxMat[9]; | |
220 | double theBoxMat3[3][3]; | |
221 | < | |
221 | > | double time; |
222 | > | |
223 | fpos_t *framePos; | |
224 | ||
225 | #ifndef IS_MPI | |
226 | ||
227 | < | framePos = startFrame[whichFrame].getPos(); |
227 | > | framePos = frameStart[whichFrame]->getPos(); |
228 | ||
229 | ||
230 | ||
# | Line 360 | Line 359 | void DumpReader :: readSet( int whichFrame ){ | |
359 | simError(); | |
360 | } | |
361 | ||
362 | < | MPI_Bcast(time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
362 | > | MPI_Bcast(&time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
363 | ||
364 | MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD ); | |
365 | ||
# | Line 416 | Line 415 | void DumpReader :: readSet( int whichFrame ){ | |
415 | ||
416 | } else { | |
417 | ||
418 | < | MPI_Bcast(time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
418 | > | MPI_Bcast(&time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
419 | MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD); | |
420 | ||
421 | done = 0; | |
# | Line 466 | Line 465 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
465 | ||
466 | char *foo; // the pointer to the current string token | |
467 | ||
468 | < | double rx, ry, rz; // position place holders |
469 | < | double vx, vy, vz; // velocity placeholders |
468 | > | double pos[3]; // position place holders |
469 | > | double vel[3]; // velocity placeholders |
470 | double q[4]; // the quaternions | |
471 | double jx, jy, jz; // angular velocity placeholders; | |
472 | double qSqr, qLength; // needed to normalize the quaternion vector. | |
# | Line 520 | Line 519 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
519 | inName, n_atoms, atomIndex ); | |
520 | return strdup( painCave.errMsg ); | |
521 | } | |
522 | < | rx = atof( foo ); |
522 | > | pos[0] = atof( foo ); |
523 | ||
524 | foo = strtok(NULL, " ,;\t"); | |
525 | if(foo == NULL){ | |
# | Line 530 | Line 529 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
529 | inName, n_atoms, atomIndex ); | |
530 | return strdup( painCave.errMsg ); | |
531 | } | |
532 | < | ry = atof( foo ); |
532 | > | pos[1] = atof( foo ); |
533 | ||
534 | foo = strtok(NULL, " ,;\t"); | |
535 | if(foo == NULL){ | |
# | Line 540 | Line 539 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
539 | inName, n_atoms, atomIndex ); | |
540 | return strdup( painCave.errMsg ); | |
541 | } | |
542 | < | rz = atof( foo ); |
542 | > | pos[2] = atof( foo ); |
543 | ||
544 | ||
545 | // get the velocities | |
# | Line 553 | Line 552 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
552 | inName, n_atoms, atomIndex ); | |
553 | return strdup( painCave.errMsg ); | |
554 | } | |
555 | < | vx = atof( foo ); |
555 | > | vel[0] = atof( foo ); |
556 | ||
557 | foo = strtok(NULL, " ,;\t"); | |
558 | if(foo == NULL){ | |
# | Line 563 | Line 562 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
562 | inName, n_atoms, atomIndex ); | |
563 | return strdup( painCave.errMsg ); | |
564 | } | |
565 | < | vy = atof( foo ); |
565 | > | vel[1] = atof( foo ); |
566 | ||
567 | foo = strtok(NULL, " ,;\t"); | |
568 | if(foo == NULL){ | |
# | Line 573 | Line 572 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
572 | inName, n_atoms, atomIndex ); | |
573 | return strdup( painCave.errMsg ); | |
574 | } | |
575 | < | vz = atof( foo ); |
575 | > | vel[2] = atof( foo ); |
576 | ||
577 | ||
578 | // get the quaternions | |
# | Line 674 | Line 673 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
673 | } | |
674 | ||
675 | // add the positions and velocities to the atom | |
677 | – | |
678 | – | atoms[atomIndex]->setX( rx ); |
679 | – | atoms[atomIndex]->setY( ry ); |
680 | – | atoms[atomIndex]->setZ( rz ); |
681 | – | |
682 | – | atoms[atomIndex]->set_vx( vx ); |
683 | – | atoms[atomIndex]->set_vy( vy ); |
684 | – | atoms[atomIndex]->set_vz( vz ); |
676 | ||
677 | + | atoms[atomIndex]->setPos( pos ); |
678 | + | atoms[atomIndex]->setVel( vel ); |
679 | + | |
680 | return NULL; | |
681 | } | |
682 | ||
683 | ||
684 | < | char* DumpReader::parseCommentLine(char* readLine, double time, |
684 | > | char* DumpReader::parseCommentLine(char* readLine, double &time, |
685 | double boxMat[9]){ | |
686 | ||
687 | char *foo; // the pointer to the current string token | |
# | Line 799 | Line 793 | char* DumpReader::parseCommentLine(char* readLine, dou | |
793 | ||
794 | // a couple of functions to let us escape the read loop | |
795 | ||
796 | < | void initFile::nodeZeroError( void ){ |
796 | > | void dumpRead::nodeZeroError( void ){ |
797 | int j, myStatus; | |
798 | ||
799 | myStatus = 0; | |
# | Line 814 | Line 808 | void initFile::nodeZeroError( void ){ | |
808 | ||
809 | } | |
810 | ||
811 | < | void initFile::anonymousNodeDie( void ){ |
811 | > | void dumpRead::anonymousNodeDie( void ){ |
812 | ||
813 | MPI_Finalize(); | |
814 | exit (0); |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |