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 |
195 |
+ |
} |
196 |
|
|
197 |
< |
nFrames = vectorSize; |
198 |
< |
isScanned = true; |
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 :: getFrame( SimInfo* the_simnfo, int whichFrame){ |
206 |
> |
void DumpReader :: readSet( int whichFrame ){ |
207 |
|
|
208 |
|
int i, j, done, which_node, which_atom; // loop counter |
209 |
|
|
219 |
|
int procIndex; |
220 |
|
double boxMat[9]; |
221 |
|
double theBoxMat3[3][3]; |
222 |
< |
|
217 |
< |
simnfo = the_simnfo; |
222 |
> |
double time; |
223 |
|
|
224 |
+ |
fpos_t *framePos; |
225 |
+ |
framePos = frameStart[whichFrame]->getPos(); |
226 |
+ |
|
227 |
|
#ifndef IS_MPI |
228 |
+ |
|
229 |
+ |
fsetpos(inFile, framePos); |
230 |
+ |
|
231 |
+ |
|
232 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); |
233 |
|
if( eof_test == NULL ){ |
234 |
|
sprintf( painCave.errMsg, |
316 |
|
|
317 |
|
haveError = 0; |
318 |
|
if (worldRank == 0) { |
319 |
< |
|
319 |
> |
fsetpos(inFile, framePos); |
320 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); |
321 |
|
if( eof_test == NULL ){ |
322 |
|
sprintf( painCave.errMsg, |
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 |
|
|
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; |
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 |
470 |
< |
double q[4]; // the quaternions |
471 |
< |
double jx, jy, jz; // angular velocity placeholders; |
468 |
> |
double pos[3]; // position place holders |
469 |
> |
double vel[3]; // velocity placeholders |
470 |
> |
double q[4]; // the quaternions |
471 |
> |
double ji[3]; // angular velocity placeholders; |
472 |
|
double qSqr, qLength; // needed to normalize the quaternion vector. |
473 |
|
|
474 |
|
Atom **atoms = simnfo->atoms; |
497 |
|
// set the string tokenizer |
498 |
|
|
499 |
|
foo = strtok(readLine, " ,;\t"); |
500 |
< |
|
500 |
> |
atoms[atomIndex]->setType(foo); |
501 |
|
// check the atom name to the current atom |
502 |
|
|
503 |
< |
if( strcmp( foo, atoms[atomIndex]->getType() ) ){ |
504 |
< |
sprintf( painCave.errMsg, |
505 |
< |
"Initialize from file error. Atom %s at index %d " |
506 |
< |
"in file %s does not" |
507 |
< |
" match the BASS atom %s.\n", |
508 |
< |
foo, atomIndex, inName, atoms[atomIndex]->getType() ); |
509 |
< |
return strdup( painCave.errMsg ); |
510 |
< |
} |
503 |
> |
//if( strcmp( foo, atoms[atomIndex]->getType() ) ){ |
504 |
> |
// sprintf( painCave.errMsg, |
505 |
> |
// "Initialize from file error. Atom %s at index %d " |
506 |
> |
// "in file %s does not" |
507 |
> |
// " match the BASS atom %s.\n", |
508 |
> |
// foo, atomIndex, inName, atoms[atomIndex]->getType() ); |
509 |
> |
// return strdup( painCave.errMsg ); |
510 |
> |
//} |
511 |
|
|
512 |
|
// get the positions |
513 |
|
|
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){ |
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){ |
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 |
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){ |
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){ |
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 |
629 |
|
inName, n_atoms, atomIndex ); |
630 |
|
return strdup( painCave.errMsg ); |
631 |
|
} |
632 |
< |
jx = atof( foo ); |
632 |
> |
ji[0] = atof( foo ); |
633 |
|
|
634 |
|
foo = strtok(NULL, " ,;\t"); |
635 |
|
if(foo == NULL){ |
639 |
|
inName, n_atoms, atomIndex ); |
640 |
|
return strdup( painCave.errMsg ); |
641 |
|
} |
642 |
< |
jy = atof(foo ); |
642 |
> |
ji[1] = atof(foo ); |
643 |
|
|
644 |
|
foo = strtok(NULL, " ,;\t"); |
645 |
|
if(foo == NULL){ |
649 |
|
inName, n_atoms, atomIndex ); |
650 |
|
return strdup( painCave.errMsg ); |
651 |
|
} |
652 |
< |
jz = atof( foo ); |
652 |
> |
ji[2] = atof( foo ); |
653 |
|
|
654 |
|
dAtom = ( DirectionalAtom* )atoms[atomIndex]; |
655 |
|
|
667 |
|
|
668 |
|
// add the angular velocities |
669 |
|
|
670 |
< |
dAtom->setJx( jx ); |
659 |
< |
dAtom->setJy( jy ); |
660 |
< |
dAtom->setJz( jz ); |
670 |
> |
dAtom->setJ( ji ); |
671 |
|
} |
672 |
|
|
673 |
|
// add the positions and velocities to the atom |
664 |
– |
|
665 |
– |
atoms[atomIndex]->setX( rx ); |
666 |
– |
atoms[atomIndex]->setY( ry ); |
667 |
– |
atoms[atomIndex]->setZ( rz ); |
668 |
– |
|
669 |
– |
atoms[atomIndex]->set_vx( vx ); |
670 |
– |
atoms[atomIndex]->set_vy( vy ); |
671 |
– |
atoms[atomIndex]->set_vz( vz ); |
674 |
|
|
675 |
+ |
atoms[atomIndex]->setPos( pos ); |
676 |
+ |
atoms[atomIndex]->setVel( vel ); |
677 |
+ |
|
678 |
|
return NULL; |
679 |
|
} |
680 |
|
|
681 |
|
|
682 |
< |
char* DumpReader::parseCommentLine(char* readLine, double time, |
682 |
> |
char* DumpReader::parseCommentLine(char* readLine, double &time, |
683 |
|
double boxMat[9]){ |
684 |
|
|
685 |
|
char *foo; // the pointer to the current string token |
686 |
|
int j; |
687 |
+ |
double chi, integralOfChidt; |
688 |
+ |
double eta[9]; |
689 |
|
|
690 |
|
// set the string tokenizer |
691 |
|
|
786 |
|
boxMat[8] = atof( foo ); |
787 |
|
|
788 |
|
return NULL; |
789 |
+ |
|
790 |
+ |
//get chi and integralOfChidt, they should appear by pair |
791 |
+ |
foo = strtok(NULL, " ,;\t\n"); |
792 |
+ |
if(foo != NULL){ |
793 |
+ |
chi = atof(foo); |
794 |
+ |
|
795 |
+ |
foo = strtok(NULL, " ,;\t\n"); |
796 |
+ |
if(foo == NULL){ |
797 |
+ |
sprintf( painCave.errMsg, |
798 |
+ |
"chi and integralOfChidt should appear by pair in %s\n", inName ); |
799 |
+ |
return strdup( painCave.errMsg ); |
800 |
+ |
} |
801 |
+ |
integralOfChidt = atof( foo ); |
802 |
+ |
|
803 |
+ |
//push chi and integralOfChidt into SimInfo::properties which can be |
804 |
+ |
//retrieved by integrator later |
805 |
+ |
DoubleData* chiValue = new DoubleData(); |
806 |
+ |
chiValue->setID(CHIVALUE_ID); |
807 |
+ |
chiValue->setData(chi); |
808 |
+ |
simnfo->addProperty(chiValue); |
809 |
+ |
|
810 |
+ |
DoubleData* integralOfChidtValue = new DoubleData(); |
811 |
+ |
integralOfChidtValue->setID(INTEGRALOFCHIDT_ID); |
812 |
+ |
integralOfChidtValue->setData(integralOfChidt); |
813 |
+ |
simnfo->addProperty(integralOfChidtValue); |
814 |
+ |
|
815 |
+ |
} |
816 |
+ |
else |
817 |
+ |
return NULL; |
818 |
+ |
|
819 |
+ |
//get eta |
820 |
+ |
for(int i = 0 ; i < 9; i++){ |
821 |
+ |
foo = strtok(NULL, " ,;\t"); |
822 |
+ |
if(foo == NULL){ |
823 |
+ |
sprintf( painCave.errMsg, |
824 |
+ |
"error in reading eta[%d] from %s\n", i, inName ); |
825 |
+ |
return strdup( painCave.errMsg ); |
826 |
+ |
} |
827 |
+ |
eta[i] = atof( foo ); |
828 |
+ |
} |
829 |
+ |
|
830 |
+ |
//push eta into SimInfo::properties which can be |
831 |
+ |
//retrieved by integrator later |
832 |
+ |
//simnfo->setBoxM( theBoxMat3 ); |
833 |
+ |
DoubleArrayData* etaValue = new DoubleArrayData(); |
834 |
+ |
etaValue->setID(ETAVALUE_ID); |
835 |
+ |
etaValue->setData(eta, 9); |
836 |
+ |
simnfo->addProperty(etaValue); |
837 |
+ |
|
838 |
+ |
|
839 |
+ |
return NULL; |
840 |
+ |
|
841 |
+ |
|
842 |
+ |
|
843 |
|
} |
844 |
|
|
845 |
|
|
847 |
|
|
848 |
|
// a couple of functions to let us escape the read loop |
849 |
|
|
850 |
< |
void initFile::nodeZeroError( void ){ |
850 |
> |
void dumpRead::nodeZeroError( void ){ |
851 |
|
int j, myStatus; |
852 |
|
|
853 |
|
myStatus = 0; |
862 |
|
|
863 |
|
} |
864 |
|
|
865 |
< |
void initFile::anonymousNodeDie( void ){ |
865 |
> |
void dumpRead::anonymousNodeDie( void ){ |
866 |
|
|
867 |
|
MPI_Finalize(); |
868 |
|
exit (0); |