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 <cmath> |
5 |
< |
#include <vector> |
8 |
> |
#include <math.h> |
9 |
|
|
10 |
|
#include <stdio.h> |
11 |
|
#include <stdlib.h> |
12 |
|
#include <string.h> |
10 |
– |
#include <unistd.h> |
11 |
– |
#include <sys/types.h> |
12 |
– |
#include <sys/stat.h> |
13 |
|
|
14 |
+ |
|
15 |
|
#include "ReadWrite.hpp" |
16 |
|
#include "simError.h" |
17 |
|
|
29 |
|
void anonymousNodeDie( void ); |
30 |
|
#endif // is_mpi |
31 |
|
|
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; |
32 |
|
} |
33 |
|
|
34 |
|
using namespace dumpRead; |
35 |
|
|
36 |
|
|
37 |
< |
DumpReader :: DumpReader( char *in_name ){ |
37 |
> |
DumpReader :: DumpReader(const char *in_name ){ |
38 |
|
|
39 |
|
isScanned = false; |
40 |
+ |
headFP = new FilePos; |
41 |
|
|
42 |
|
#ifdef IS_MPI |
43 |
|
if (worldRank == 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 |
107 |
|
|
108 |
|
currPos = new fpos_t; |
109 |
|
fgetpos( inFile, currPos ); |
110 |
< |
fgets( readBuffer, sizeof( readBuffer ), in_file ); |
110 |
> |
fgets( readBuffer, sizeof( readBuffer ), inFile ); |
111 |
|
lineNum++; |
112 |
< |
if( feof( in_file ) ){ |
112 |
> |
if( feof( inFile ) ){ |
113 |
|
sprintf( painCave.errMsg, |
114 |
|
"File \"%s\" ended unexpectedly at line %d\n", |
115 |
|
inName, |
118 |
|
simError(); |
119 |
|
} |
120 |
|
|
121 |
< |
while( !feof( in_file ) ){ |
122 |
< |
|
123 |
< |
frameStart.push_back( FilePos( currPos ) ); |
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 ), in_file ); |
129 |
> |
fgets( readBuffer, sizeof( readBuffer ), inFile ); |
130 |
|
lineNum++; |
131 |
< |
if( feof( in_file ) ){ |
131 |
> |
if( feof( inFile ) ){ |
132 |
|
sprintf( painCave.errMsg, |
133 |
|
"File \"%s\" ended unexpectedly at line %d\n", |
134 |
|
inName, |
137 |
|
simError(); |
138 |
|
} |
139 |
|
|
140 |
< |
if(outTime){ |
141 |
< |
foo = strtok( readBuffer, " ,;\t" ); |
142 |
< |
time = atof( foo ); |
143 |
< |
} |
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 ), in_file ); |
147 |
> |
fgets( readBuffer, sizeof( readBuffer ), inFile ); |
148 |
|
lineNum++; |
149 |
< |
if( feof( in_file ) ){ |
149 |
> |
if( feof( inFile ) ){ |
150 |
|
sprintf( painCave.errMsg, |
151 |
|
"File \"%s\" ended unexpectedly at line %d," |
152 |
|
" with atom %d\n", |
161 |
|
|
162 |
|
currPos = new fpos_t; |
163 |
|
fgetpos( inFile, currPos ); |
164 |
< |
fgets( readBuffer, sizeof( readBuffer ), in_file ); |
164 |
> |
fgets( readBuffer, sizeof( readBuffer ), inFile ); |
165 |
|
lineNum++; |
166 |
|
} |
167 |
|
|
168 |
|
delete currPos; |
185 |
– |
vectorSize = frameStart.size(); |
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 |
193 |
– |
|
194 |
– |
nFrames = vectorSize; |
195 |
– |
isScanned = true; |
195 |
|
} |
196 |
|
|
197 |
|
void DumpReader :: readFrame( SimInfo* the_simnfo, int whichFrame){ |
219 |
|
int procIndex; |
220 |
|
double boxMat[9]; |
221 |
|
double theBoxMat3[3][3]; |
222 |
< |
|
222 |
> |
double time; |
223 |
> |
|
224 |
|
fpos_t *framePos; |
225 |
|
|
226 |
|
#ifndef IS_MPI |
227 |
|
|
228 |
< |
framePos = startFrame[whichFrame].getPos(); |
228 |
> |
framePos = frameStart[whichFrame]->getPos(); |
229 |
|
|
230 |
+ |
fsetpos(inFile, framePos); |
231 |
|
|
232 |
|
|
232 |
– |
|
233 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); |
234 |
|
if( eof_test == NULL ){ |
235 |
|
sprintf( painCave.errMsg, |
317 |
|
|
318 |
|
haveError = 0; |
319 |
|
if (worldRank == 0) { |
320 |
< |
|
320 |
> |
fsetpos(inFile, framePos); |
321 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); |
322 |
|
if( eof_test == NULL ){ |
323 |
|
sprintf( painCave.errMsg, |
360 |
|
simError(); |
361 |
|
} |
362 |
|
|
363 |
< |
MPI_Bcast(time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
363 |
> |
MPI_Bcast(&time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
364 |
|
|
365 |
|
MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
366 |
|
|
416 |
|
|
417 |
|
} else { |
418 |
|
|
419 |
< |
MPI_Bcast(time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
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; |
466 |
|
|
467 |
|
char *foo; // the pointer to the current string token |
468 |
|
|
469 |
< |
double rx, ry, rz; // position place holders |
470 |
< |
double vx, vy, vz; // velocity placeholders |
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. |
498 |
|
// set the string tokenizer |
499 |
|
|
500 |
|
foo = strtok(readLine, " ,;\t"); |
501 |
< |
|
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 |
< |
} |
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 |
|
|
520 |
|
inName, n_atoms, atomIndex ); |
521 |
|
return strdup( painCave.errMsg ); |
522 |
|
} |
523 |
< |
rx = atof( foo ); |
523 |
> |
pos[0] = atof( foo ); |
524 |
|
|
525 |
|
foo = strtok(NULL, " ,;\t"); |
526 |
|
if(foo == NULL){ |
530 |
|
inName, n_atoms, atomIndex ); |
531 |
|
return strdup( painCave.errMsg ); |
532 |
|
} |
533 |
< |
ry = atof( foo ); |
533 |
> |
pos[1] = atof( foo ); |
534 |
|
|
535 |
|
foo = strtok(NULL, " ,;\t"); |
536 |
|
if(foo == NULL){ |
540 |
|
inName, n_atoms, atomIndex ); |
541 |
|
return strdup( painCave.errMsg ); |
542 |
|
} |
543 |
< |
rz = atof( foo ); |
543 |
> |
pos[2] = atof( foo ); |
544 |
|
|
545 |
|
|
546 |
|
// get the velocities |
553 |
|
inName, n_atoms, atomIndex ); |
554 |
|
return strdup( painCave.errMsg ); |
555 |
|
} |
556 |
< |
vx = atof( foo ); |
556 |
> |
vel[0] = atof( foo ); |
557 |
|
|
558 |
|
foo = strtok(NULL, " ,;\t"); |
559 |
|
if(foo == NULL){ |
563 |
|
inName, n_atoms, atomIndex ); |
564 |
|
return strdup( painCave.errMsg ); |
565 |
|
} |
566 |
< |
vy = atof( foo ); |
566 |
> |
vel[1] = atof( foo ); |
567 |
|
|
568 |
|
foo = strtok(NULL, " ,;\t"); |
569 |
|
if(foo == NULL){ |
573 |
|
inName, n_atoms, atomIndex ); |
574 |
|
return strdup( painCave.errMsg ); |
575 |
|
} |
576 |
< |
vz = atof( foo ); |
576 |
> |
vel[2] = atof( foo ); |
577 |
|
|
578 |
|
|
579 |
|
// get the quaternions |
674 |
|
} |
675 |
|
|
676 |
|
// 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 ); |
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, |
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 |
|
|
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 |
|
|
850 |
|
|
851 |
|
// a couple of functions to let us escape the read loop |
852 |
|
|
853 |
< |
void initFile::nodeZeroError( void ){ |
853 |
> |
void dumpRead::nodeZeroError( void ){ |
854 |
|
int j, myStatus; |
855 |
|
|
856 |
|
myStatus = 0; |
865 |
|
|
866 |
|
} |
867 |
|
|
868 |
< |
void initFile::anonymousNodeDie( void ){ |
868 |
> |
void dumpRead::anonymousNodeDie( void ){ |
869 |
|
|
870 |
|
MPI_Finalize(); |
871 |
|
exit (0); |