# | Line 19 | Line 19 | |
---|---|---|
19 | #include "mpiSimulation.hpp" | |
20 | #define TAKE_THIS_TAG_CHAR 0 | |
21 | #define TAKE_THIS_TAG_INT 1 | |
22 | + | #endif // is_mpi |
23 | ||
24 | namespace dumpRead{ | |
25 | + | |
26 | + | #ifdef IS_MPI |
27 | void nodeZeroError( void ); | |
28 | void anonymousNodeDie( void ); | |
29 | < | |
29 | > | #endif // is_mpi |
30 | ||
31 | class FilePos{ | |
29 | – | public: |
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; | |
56 | } | |
57 | ||
58 | using namespace dumpRead; | |
59 | ||
42 | – | #endif // is_mpi |
60 | ||
61 | DumpReader :: DumpReader( char *in_name ){ | |
62 | + | |
63 | + | isScanned = false; |
64 | + | |
65 | #ifdef IS_MPI | |
66 | if (worldRank == 0) { | |
67 | #endif | |
68 | ||
69 | < | c_in_file = fopen(in_name, "r"); |
70 | < | if(c_in_file == NULL){ |
69 | > | inFile = fopen(in_name, "r"); |
70 | > | if(inFile == NULL){ |
71 | sprintf(painCave.errMsg, | |
72 | "Cannot open file: %s\n", in_name); | |
73 | painCave.isFatal = 1; | |
74 | simError(); | |
75 | } | |
76 | ||
77 | < | strcpy( c_in_name, in_name); |
77 | > | strcpy( inName, in_name); |
78 | #ifdef IS_MPI | |
79 | } | |
80 | strcpy( checkPointMsg, "Dump file opened for reading successfully." ); | |
# | Line 68 | Line 88 | DumpReader :: ~DumpReader( ){ | |
88 | if (worldRank == 0) { | |
89 | #endif | |
90 | int error; | |
91 | < | error = fclose( c_in_file ); |
91 | > | error = fclose( inFile ); |
92 | if( error ){ | |
93 | sprintf( painCave.errMsg, | |
94 | < | "Error closing %s\n", c_in_name ); |
94 | > | "Error closing %s\n", inName ); |
95 | simError(); | |
96 | } | |
97 | #ifdef IS_MPI | |
# | Line 81 | Line 101 | DumpReader :: ~DumpReader( ){ | |
101 | #endif | |
102 | ||
103 | return; | |
104 | + | } |
105 | + | |
106 | + | int DumpReader::getNframes( void ){ |
107 | + | |
108 | + | if( !isScanned ) scanFile(); |
109 | + | return nFrames; |
110 | + | } |
111 | + | |
112 | + | void DumpReader::scanFile( void ){ |
113 | + | |
114 | + | int vectorSize; |
115 | + | int i, j, k; |
116 | + | int lineNum = 0; |
117 | + | char readBuffer[2000]; |
118 | + | char* foo; |
119 | + | fpos_t *currPos; |
120 | + | |
121 | + | #ifdef IS_MPI |
122 | + | if( worldRank == 0 ){ |
123 | + | #endif // is_mpi |
124 | + | |
125 | + | rewind( inFile ); |
126 | + | |
127 | + | currPos = new fpos_t; |
128 | + | fgetpos( inFile, currPos ); |
129 | + | fgets( readBuffer, sizeof( readBuffer ), in_file ); |
130 | + | lineNum++; |
131 | + | if( feof( in_file ) ){ |
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 | + | while( !feof( in_file ) ){ |
141 | + | |
142 | + | frameStart.push_back( FilePos( currPos ) ); |
143 | + | i = atoi(readBuffer); |
144 | + | |
145 | + | fgets( readBuffer, sizeof( readBuffer ), in_file ); |
146 | + | lineNum++; |
147 | + | if( feof( in_file ) ){ |
148 | + | sprintf( painCave.errMsg, |
149 | + | "File \"%s\" ended unexpectedly at line %d\n", |
150 | + | inName, |
151 | + | lineNum ); |
152 | + | painCave.isFatal = 1; |
153 | + | simError(); |
154 | + | } |
155 | + | |
156 | + | if(outTime){ |
157 | + | foo = strtok( readBuffer, " ,;\t" ); |
158 | + | time = atof( foo ); |
159 | + | } |
160 | + | |
161 | + | for(j=0; j<i; j++){ |
162 | + | |
163 | + | fgets( readBuffer, sizeof( readBuffer ), in_file ); |
164 | + | lineNum++; |
165 | + | if( feof( in_file ) ){ |
166 | + | sprintf( painCave.errMsg, |
167 | + | "File \"%s\" ended unexpectedly at line %d," |
168 | + | " with atom %d\n", |
169 | + | inName, |
170 | + | lineNum, |
171 | + | j ); |
172 | + | painCave.isFatal = 1; |
173 | + | simError(); |
174 | + | } |
175 | + | |
176 | + | } |
177 | + | |
178 | + | currPos = new fpos_t; |
179 | + | fgetpos( inFile, currPos ); |
180 | + | fgets( readBuffer, sizeof( readBuffer ), in_file ); |
181 | + | lineNum++; |
182 | + | } |
183 | + | |
184 | + | delete currPos; |
185 | + | vectorSize = frameStart.size(); |
186 | + | rewind( inFile ); |
187 | + | |
188 | + | #ifdef IS_MPI |
189 | + | } |
190 | + | strcpy( checkPointMsg, "Successfully scanned DumpFile\n" ); |
191 | + | MPIcheckPoint(); |
192 | + | #endif // is_mpi |
193 | + | |
194 | + | nFrames = vectorSize; |
195 | + | isScanned = true; |
196 | } | |
197 | ||
198 | ||
# | Line 105 | Line 217 | void DumpReader :: getFrame( SimInfo* the_simnfo, int | |
217 | simnfo = the_simnfo; | |
218 | ||
219 | #ifndef IS_MPI | |
220 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
220 | > | eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); |
221 | if( eof_test == NULL ){ | |
222 | sprintf( painCave.errMsg, | |
223 | "DumpReader error: error reading 1st line of \"%s\"\n", | |
224 | < | c_in_name ); |
224 | > | inName ); |
225 | painCave.isFatal = 1; | |
226 | simError(); | |
227 | } | |
# | Line 123 | Line 235 | void DumpReader :: getFrame( SimInfo* the_simnfo, int | |
235 | sprintf( painCave.errMsg, | |
236 | "DumpReader error. %s n_atoms, %d, " | |
237 | "does not match the BASS file's n_atoms, %d.\n", | |
238 | < | c_in_name, n_atoms, simnfo->n_atoms ); |
238 | > | inName, n_atoms, simnfo->n_atoms ); |
239 | painCave.isFatal = 1; | |
240 | simError(); | |
241 | } | |
242 | ||
243 | //read the box mat from the comment line | |
244 | ||
245 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
245 | > | eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); |
246 | if(eof_test == NULL){ | |
247 | sprintf( painCave.errMsg, | |
248 | < | "error in reading commment in %s\n", c_in_name); |
248 | > | "error in reading commment in %s\n", inName); |
249 | painCave.isFatal = 1; | |
250 | simError(); | |
251 | } | |
# | Line 156 | Line 268 | void DumpReader :: getFrame( SimInfo* the_simnfo, int | |
268 | ||
269 | for( i=0; i < n_atoms; i++){ | |
270 | ||
271 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
271 | > | eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); |
272 | if(eof_test == NULL){ | |
273 | sprintf(painCave.errMsg, | |
274 | "error in reading file %s\n" | |
275 | "natoms = %d; index = %d\n" | |
276 | "error reading the line from the file.\n", | |
277 | < | c_in_name, n_atoms, i ); |
277 | > | inName, n_atoms, i ); |
278 | painCave.isFatal = 1; | |
279 | simError(); | |
280 | } | |
# | Line 193 | Line 305 | void DumpReader :: getFrame( SimInfo* the_simnfo, int | |
305 | haveError = 0; | |
306 | if (worldRank == 0) { | |
307 | ||
308 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
308 | > | eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); |
309 | if( eof_test == NULL ){ | |
310 | sprintf( painCave.errMsg, | |
311 | < | "Error reading 1st line of %d \n ",c_in_name); |
311 | > | "Error reading 1st line of %d \n ",inName); |
312 | haveError = 1; | |
313 | simError(); | |
314 | } | |
# | Line 213 | Line 325 | void DumpReader :: getFrame( SimInfo* the_simnfo, int | |
325 | sprintf( painCave.errMsg, | |
326 | "Initialize from File error. %s n_atoms, %d, " | |
327 | "does not match the BASS file's n_atoms, %d.\n", | |
328 | < | c_in_name, n_atoms, simnfo->n_atoms ); |
328 | > | inName, n_atoms, simnfo->n_atoms ); |
329 | haveError= 1; | |
330 | simError(); | |
331 | } | |
332 | ||
333 | //read the time and boxMat from the comment line | |
334 | ||
335 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
335 | > | eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); |
336 | if(eof_test == NULL){ | |
337 | sprintf( painCave.errMsg, | |
338 | < | "error in reading commment in %s\n", c_in_name); |
338 | > | "error in reading commment in %s\n", inName); |
339 | haveError = 1; | |
340 | simError(); | |
341 | } | |
# | Line 243 | Line 355 | void DumpReader :: getFrame( SimInfo* the_simnfo, int | |
355 | ||
356 | for (i=0 ; i < mpiSim->getTotAtoms(); i++) { | |
357 | ||
358 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
358 | > | eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); |
359 | if(eof_test == NULL){ | |
360 | sprintf(painCave.errMsg, | |
361 | "error in reading file %s\n" | |
362 | "natoms = %d; index = %d\n" | |
363 | "error reading the line from the file.\n", | |
364 | < | c_in_name, n_atoms, i ); |
364 | > | inName, n_atoms, i ); |
365 | haveError= 1; | |
366 | simError(); | |
367 | } | |
# | Line 362 | Line 474 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
474 | sprintf( painCave.errMsg, | |
475 | "Initialize from file error. Atom at index %d " | |
476 | "in file %s does not exist on processor %d .\n", | |
477 | < | globalIndex, c_in_name, mpiSim->getMyNode() ); |
477 | > | globalIndex, inName, mpiSim->getMyNode() ); |
478 | return strdup( painCave.errMsg ); | |
479 | } | |
480 | #else | |
# | Line 381 | Line 493 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
493 | "Initialize from file error. Atom %s at index %d " | |
494 | "in file %s does not" | |
495 | " match the BASS atom %s.\n", | |
496 | < | foo, atomIndex, c_in_name, atoms[atomIndex]->getType() ); |
496 | > | foo, atomIndex, inName, atoms[atomIndex]->getType() ); |
497 | return strdup( painCave.errMsg ); | |
498 | } | |
499 | ||
# | Line 392 | Line 504 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
504 | sprintf( painCave.errMsg, | |
505 | "error in reading postition x from %s\n" | |
506 | "natoms = %d, index = %d\n", | |
507 | < | c_in_name, n_atoms, atomIndex ); |
507 | > | inName, n_atoms, atomIndex ); |
508 | return strdup( painCave.errMsg ); | |
509 | } | |
510 | rx = atof( foo ); | |
# | Line 402 | Line 514 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
514 | sprintf( painCave.errMsg, | |
515 | "error in reading postition y from %s\n" | |
516 | "natoms = %d, index = %d\n", | |
517 | < | c_in_name, n_atoms, atomIndex ); |
517 | > | inName, n_atoms, atomIndex ); |
518 | return strdup( painCave.errMsg ); | |
519 | } | |
520 | ry = atof( foo ); | |
# | Line 412 | Line 524 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
524 | sprintf( painCave.errMsg, | |
525 | "error in reading postition z from %s\n" | |
526 | "natoms = %d, index = %d\n", | |
527 | < | c_in_name, n_atoms, atomIndex ); |
527 | > | inName, n_atoms, atomIndex ); |
528 | return strdup( painCave.errMsg ); | |
529 | } | |
530 | rz = atof( foo ); | |
# | Line 425 | Line 537 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
537 | sprintf( painCave.errMsg, | |
538 | "error in reading velocity x from %s\n" | |
539 | "natoms = %d, index = %d\n", | |
540 | < | c_in_name, n_atoms, atomIndex ); |
540 | > | inName, n_atoms, atomIndex ); |
541 | return strdup( painCave.errMsg ); | |
542 | } | |
543 | vx = atof( foo ); | |
# | Line 435 | Line 547 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
547 | sprintf( painCave.errMsg, | |
548 | "error in reading velocity y from %s\n" | |
549 | "natoms = %d, index = %d\n", | |
550 | < | c_in_name, n_atoms, atomIndex ); |
550 | > | inName, n_atoms, atomIndex ); |
551 | return strdup( painCave.errMsg ); | |
552 | } | |
553 | vy = atof( foo ); | |
# | Line 445 | Line 557 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
557 | sprintf( painCave.errMsg, | |
558 | "error in reading velocity z from %s\n" | |
559 | "natoms = %d, index = %d\n", | |
560 | < | c_in_name, n_atoms, atomIndex ); |
560 | > | inName, n_atoms, atomIndex ); |
561 | return strdup( painCave.errMsg ); | |
562 | } | |
563 | vz = atof( foo ); | |
# | Line 460 | Line 572 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
572 | sprintf(painCave.errMsg, | |
573 | "error in reading quaternion 0 from %s\n" | |
574 | "natoms = %d, index = %d\n", | |
575 | < | c_in_name, n_atoms, atomIndex ); |
575 | > | inName, n_atoms, atomIndex ); |
576 | return strdup( painCave.errMsg ); | |
577 | } | |
578 | q[0] = atof( foo ); | |
# | Line 470 | Line 582 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
582 | sprintf( painCave.errMsg, | |
583 | "error in reading quaternion 1 from %s\n" | |
584 | "natoms = %d, index = %d\n", | |
585 | < | c_in_name, n_atoms, atomIndex ); |
585 | > | inName, n_atoms, atomIndex ); |
586 | return strdup( painCave.errMsg ); | |
587 | } | |
588 | q[1] = atof( foo ); | |
# | Line 480 | Line 592 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
592 | sprintf( painCave.errMsg, | |
593 | "error in reading quaternion 2 from %s\n" | |
594 | "natoms = %d, index = %d\n", | |
595 | < | c_in_name, n_atoms, atomIndex ); |
595 | > | inName, n_atoms, atomIndex ); |
596 | return strdup( painCave.errMsg ); | |
597 | } | |
598 | q[2] = atof( foo ); | |
# | Line 490 | Line 602 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
602 | sprintf( painCave.errMsg, | |
603 | "error in reading quaternion 3 from %s\n" | |
604 | "natoms = %d, index = %d\n", | |
605 | < | c_in_name, n_atoms, atomIndex ); |
605 | > | inName, n_atoms, atomIndex ); |
606 | return strdup( painCave.errMsg ); | |
607 | } | |
608 | q[3] = atof( foo ); | |
# | Line 502 | Line 614 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
614 | sprintf( painCave.errMsg, | |
615 | "error in reading angular momentum jx from %s\n" | |
616 | "natoms = %d, index = %d\n", | |
617 | < | c_in_name, n_atoms, atomIndex ); |
617 | > | inName, n_atoms, atomIndex ); |
618 | return strdup( painCave.errMsg ); | |
619 | } | |
620 | jx = atof( foo ); | |
# | Line 512 | Line 624 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
624 | sprintf( painCave.errMsg, | |
625 | "error in reading angular momentum jy from %s\n" | |
626 | "natoms = %d, index = %d\n", | |
627 | < | c_in_name, n_atoms, atomIndex ); |
627 | > | inName, n_atoms, atomIndex ); |
628 | return strdup( painCave.errMsg ); | |
629 | } | |
630 | jy = atof(foo ); | |
# | Line 522 | Line 634 | char* DumpReader::parseDumpLine(char* readLine, int gl | |
634 | sprintf( painCave.errMsg, | |
635 | "error in reading angular momentum jz from %s\n" | |
636 | "natoms = %d, index = %d\n", | |
637 | < | c_in_name, n_atoms, atomIndex ); |
637 | > | inName, n_atoms, atomIndex ); |
638 | return strdup( painCave.errMsg ); | |
639 | } | |
640 | jz = atof( foo ); | |
# | Line 574 | Line 686 | char* DumpReader::parseCommentLine(char* readLine, dou | |
686 | if(foo == NULL){ | |
687 | sprintf( painCave.errMsg, | |
688 | "error in reading time from %s\n", | |
689 | < | c_in_name ); |
689 | > | inName ); |
690 | return strdup( painCave.errMsg ); | |
691 | } | |
692 | time = atof( foo ); | |
# | Line 585 | Line 697 | char* DumpReader::parseCommentLine(char* readLine, dou | |
697 | if(foo == NULL){ | |
698 | sprintf( painCave.errMsg, | |
699 | "error in reading Hx[0] from %s\n", | |
700 | < | c_in_name ); |
700 | > | inName ); |
701 | return strdup( painCave.errMsg ); | |
702 | } | |
703 | boxMat[0] = atof( foo ); | |
# | Line 594 | Line 706 | char* DumpReader::parseCommentLine(char* readLine, dou | |
706 | if(foo == NULL){ | |
707 | sprintf( painCave.errMsg, | |
708 | "error in reading Hx[1] from %s\n", | |
709 | < | c_in_name ); |
709 | > | inName ); |
710 | return strdup( painCave.errMsg ); | |
711 | } | |
712 | boxMat[1] = atof( foo ); | |
# | Line 603 | Line 715 | char* DumpReader::parseCommentLine(char* readLine, dou | |
715 | if(foo == NULL){ | |
716 | sprintf( painCave.errMsg, | |
717 | "error in reading Hx[2] from %s\n", | |
718 | < | c_in_name ); |
718 | > | inName ); |
719 | return strdup( painCave.errMsg ); | |
720 | } | |
721 | boxMat[2] = atof( foo ); | |
# | Line 614 | Line 726 | char* DumpReader::parseCommentLine(char* readLine, dou | |
726 | if(foo == NULL){ | |
727 | sprintf( painCave.errMsg, | |
728 | "error in reading Hy[0] from %s\n", | |
729 | < | c_in_name ); |
729 | > | inName ); |
730 | return strdup( painCave.errMsg ); | |
731 | } | |
732 | boxMat[3] = atof( foo ); | |
# | Line 623 | Line 735 | char* DumpReader::parseCommentLine(char* readLine, dou | |
735 | if(foo == NULL){ | |
736 | sprintf( painCave.errMsg, | |
737 | "error in reading Hy[1] from %s\n", | |
738 | < | c_in_name ); |
738 | > | inName ); |
739 | return strdup( painCave.errMsg ); | |
740 | } | |
741 | boxMat[4] = atof( foo ); | |
# | Line 632 | Line 744 | char* DumpReader::parseCommentLine(char* readLine, dou | |
744 | if(foo == NULL){ | |
745 | sprintf( painCave.errMsg, | |
746 | "error in reading Hy[2] from %s\n", | |
747 | < | c_in_name ); |
747 | > | inName ); |
748 | return strdup( painCave.errMsg ); | |
749 | } | |
750 | boxMat[5] = atof( foo ); | |
# | Line 643 | Line 755 | char* DumpReader::parseCommentLine(char* readLine, dou | |
755 | if(foo == NULL){ | |
756 | sprintf( painCave.errMsg, | |
757 | "error in reading Hz[0] from %s\n", | |
758 | < | c_in_name ); |
758 | > | inName ); |
759 | return strdup( painCave.errMsg ); | |
760 | } | |
761 | boxMat[6] = atof( foo ); | |
# | Line 652 | Line 764 | char* DumpReader::parseCommentLine(char* readLine, dou | |
764 | if(foo == NULL){ | |
765 | sprintf( painCave.errMsg, | |
766 | "error in reading Hz[1] from %s\n", | |
767 | < | c_in_name ); |
767 | > | inName ); |
768 | return strdup( painCave.errMsg ); | |
769 | } | |
770 | boxMat[7] = atof( foo ); | |
# | Line 661 | Line 773 | char* DumpReader::parseCommentLine(char* readLine, dou | |
773 | if(foo == NULL){ | |
774 | sprintf( painCave.errMsg, | |
775 | "error in reading Hz[2] from %s\n", | |
776 | < | c_in_name ); |
776 | > | inName ); |
777 | return strdup( painCave.errMsg ); | |
778 | } | |
779 | boxMat[8] = atof( foo ); |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |