ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/DumpReader.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/DumpReader.cpp (file contents):
Revision 646 by mmeineke, Tue Jul 22 20:05:30 2003 UTC vs.
Revision 656 by mmeineke, Tue Jul 29 16:32:37 2003 UTC

# 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 83 | Line 103 | DumpReader :: ~DumpReader( ){
103    return;
104   }
105  
106 + int DumpReader::getNframes( void ){
107  
108 +  if( !isScanned ) scanFile();
109 +  return nFrames;
110 + }
111  
112 < void DumpReader :: getFrame( SimInfo* the_simnfo, int whichFrame){
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 + void DumpReader :: readFrame( SimInfo* the_simnfo, int whichFrame){
199 +
200 +  simnfo = the_simnfo;
201 +
202 +  this->readSet( whichFrame );
203 + }
204 +
205 +
206 +
207 + void DumpReader :: readSet( int whichFrame ){
208 +
209    int i, j, done, which_node, which_atom; // loop counter
210  
211    const int BUFFERSIZE = 2000; // size of the read buffer
# Line 101 | Line 220 | void DumpReader :: getFrame( SimInfo* the_simnfo, int
220    int procIndex;
221    double boxMat[9];
222    double theBoxMat3[3][3];
223 +  
224 +  fpos_t *framePos;
225 +  
226 + #ifndef IS_MPI
227 +  
228 +  framePos = startFrame[whichFrame].getPos();
229  
230 <  simnfo = the_simnfo;
230 >  
231  
232 < #ifndef IS_MPI
233 <  eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
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 <             c_in_name );
237 >             inName );
238      painCave.isFatal = 1;
239      simError();
240    }
# Line 123 | Line 248 | void DumpReader :: getFrame( SimInfo* the_simnfo, int
248      sprintf( painCave.errMsg,
249               "DumpReader error. %s n_atoms, %d, "
250               "does not match the BASS file's n_atoms, %d.\n",
251 <             c_in_name, n_atoms, simnfo->n_atoms );
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), c_in_file);
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", c_in_name);
261 >             "error in reading commment in %s\n", inName);
262      painCave.isFatal = 1;
263      simError();
264    }
# Line 156 | Line 281 | void DumpReader :: getFrame( SimInfo* the_simnfo, int
281  
282    for( i=0; i < n_atoms; i++){
283      
284 <    eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
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 <              c_in_name, n_atoms, i );
290 >              inName, n_atoms, i );
291        painCave.isFatal = 1;
292        simError();
293      }
# Line 193 | Line 318 | void DumpReader :: getFrame( SimInfo* the_simnfo, int
318    haveError = 0;
319    if (worldRank == 0) {
320  
321 <    eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
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 ",c_in_name);
324 >               "Error reading 1st line of %d \n ",inName);
325        haveError = 1;
326        simError();
327      }
# Line 213 | Line 338 | void DumpReader :: getFrame( SimInfo* the_simnfo, int
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 <               c_in_name, n_atoms, simnfo->n_atoms );
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), c_in_file);
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", c_in_name);
351 >               "error in reading commment in %s\n", inName);
352        haveError = 1;
353        simError();
354      }
# Line 243 | Line 368 | void DumpReader :: getFrame( SimInfo* the_simnfo, int
368      
369      for (i=0 ; i < mpiSim->getTotAtoms(); i++) {
370        
371 <      eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
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 <                c_in_name, n_atoms, i );
377 >                inName, n_atoms, i );
378          haveError= 1;
379          simError();
380        }
# Line 362 | Line 487 | char* DumpReader::parseDumpLine(char* readLine, int gl
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, c_in_name, mpiSim->getMyNode() );
490 >             globalIndex, inName, mpiSim->getMyNode() );
491      return strdup( painCave.errMsg );
492    }  
493   #else
# Line 381 | Line 506 | char* DumpReader::parseDumpLine(char* readLine, int gl
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, c_in_name, atoms[atomIndex]->getType() );
509 >             foo, atomIndex, inName, atoms[atomIndex]->getType() );
510      return strdup( painCave.errMsg );
511    }
512      
# Line 392 | Line 517 | char* DumpReader::parseDumpLine(char* readLine, int gl
517      sprintf( painCave.errMsg,
518               "error in reading postition x from %s\n"
519               "natoms  = %d, index = %d\n",
520 <             c_in_name, n_atoms, atomIndex );
520 >             inName, n_atoms, atomIndex );
521      return strdup( painCave.errMsg );
522    }
523    rx = atof( foo );
# Line 402 | Line 527 | char* DumpReader::parseDumpLine(char* readLine, int gl
527      sprintf( painCave.errMsg,
528               "error in reading postition y from %s\n"
529               "natoms  = %d, index = %d\n",
530 <             c_in_name, n_atoms, atomIndex );
530 >             inName, n_atoms, atomIndex );
531      return strdup( painCave.errMsg );
532    }
533    ry = atof( foo );
# Line 412 | Line 537 | char* DumpReader::parseDumpLine(char* readLine, int gl
537      sprintf( painCave.errMsg,
538               "error in reading postition z 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    rz = atof( foo );    
# Line 425 | Line 550 | char* DumpReader::parseDumpLine(char* readLine, int gl
550      sprintf( painCave.errMsg,
551               "error in reading velocity x from %s\n"
552               "natoms  = %d, index = %d\n",
553 <             c_in_name, n_atoms, atomIndex );
553 >             inName, n_atoms, atomIndex );
554      return strdup( painCave.errMsg );
555    }
556    vx = atof( foo );
# Line 435 | Line 560 | char* DumpReader::parseDumpLine(char* readLine, int gl
560      sprintf( painCave.errMsg,
561               "error in reading velocity y from %s\n"
562               "natoms  = %d, index = %d\n",
563 <             c_in_name, n_atoms, atomIndex );
563 >             inName, n_atoms, atomIndex );
564      return strdup( painCave.errMsg );
565    }
566    vy = atof( foo );
# Line 445 | Line 570 | char* DumpReader::parseDumpLine(char* readLine, int gl
570      sprintf( painCave.errMsg,
571               "error in reading velocity z from %s\n"
572               "natoms  = %d, index = %d\n",
573 <             c_in_name, n_atoms, atomIndex );
573 >             inName, n_atoms, atomIndex );
574      return strdup( painCave.errMsg );
575    }
576    vz = atof( foo );
# Line 460 | Line 585 | char* DumpReader::parseDumpLine(char* readLine, int gl
585        sprintf(painCave.errMsg,
586                "error in reading quaternion 0 from %s\n"
587                "natoms  = %d, index = %d\n",
588 <              c_in_name, n_atoms, atomIndex );
588 >              inName, n_atoms, atomIndex );
589        return strdup( painCave.errMsg );
590      }
591      q[0] = atof( foo );
# Line 470 | Line 595 | char* DumpReader::parseDumpLine(char* readLine, int gl
595        sprintf( painCave.errMsg,
596                 "error in reading quaternion 1 from %s\n"
597                 "natoms  = %d, index = %d\n",
598 <               c_in_name, n_atoms, atomIndex );
598 >               inName, n_atoms, atomIndex );
599        return strdup( painCave.errMsg );
600      }
601      q[1] = atof( foo );
# Line 480 | Line 605 | char* DumpReader::parseDumpLine(char* readLine, int gl
605        sprintf( painCave.errMsg,
606                 "error in reading quaternion 2 from %s\n"
607                 "natoms  = %d, index = %d\n",
608 <               c_in_name, n_atoms, atomIndex );
608 >               inName, n_atoms, atomIndex );
609        return strdup( painCave.errMsg );
610      }
611      q[2] = atof( foo );
# Line 490 | Line 615 | char* DumpReader::parseDumpLine(char* readLine, int gl
615        sprintf( painCave.errMsg,
616                 "error in reading quaternion 3 from %s\n"
617                 "natoms  = %d, index = %d\n",
618 <               c_in_name, n_atoms, atomIndex );
618 >               inName, n_atoms, atomIndex );
619        return strdup( painCave.errMsg );
620      }
621      q[3] = atof( foo );
# Line 502 | Line 627 | char* DumpReader::parseDumpLine(char* readLine, int gl
627        sprintf( painCave.errMsg,
628                 "error in reading angular momentum jx from %s\n"
629                 "natoms  = %d, index = %d\n",
630 <               c_in_name, n_atoms, atomIndex );
630 >               inName, n_atoms, atomIndex );
631        return strdup( painCave.errMsg );
632      }
633      jx = atof( foo );
# Line 512 | Line 637 | char* DumpReader::parseDumpLine(char* readLine, int gl
637        sprintf( painCave.errMsg,
638                 "error in reading angular momentum jy from %s\n"
639                 "natoms  = %d, index = %d\n",
640 <               c_in_name, n_atoms, atomIndex );
640 >               inName, n_atoms, atomIndex );
641        return strdup( painCave.errMsg );
642      }
643      jy = atof(foo );
# Line 522 | Line 647 | char* DumpReader::parseDumpLine(char* readLine, int gl
647        sprintf( painCave.errMsg,
648                 "error in reading angular momentum jz from %s\n"
649                 "natoms  = %d, index = %d\n",
650 <               c_in_name, n_atoms, atomIndex );
650 >               inName, n_atoms, atomIndex );
651        return strdup( painCave.errMsg );
652      }
653      jz = atof( foo );
# Line 574 | Line 699 | char* DumpReader::parseCommentLine(char* readLine, dou
699    if(foo == NULL){
700      sprintf( painCave.errMsg,
701               "error in reading time from %s\n",
702 <             c_in_name );
702 >             inName );
703      return strdup( painCave.errMsg );
704    }
705    time = atof( foo );
# Line 585 | Line 710 | char* DumpReader::parseCommentLine(char* readLine, dou
710    if(foo == NULL){
711      sprintf( painCave.errMsg,
712               "error in reading Hx[0] from %s\n",
713 <             c_in_name );
713 >             inName );
714      return strdup( painCave.errMsg );
715    }
716    boxMat[0] = atof( foo );
# Line 594 | Line 719 | char* DumpReader::parseCommentLine(char* readLine, dou
719    if(foo == NULL){
720      sprintf( painCave.errMsg,
721               "error in reading Hx[1] from %s\n",
722 <             c_in_name );
722 >             inName );
723      return strdup( painCave.errMsg );
724    }
725    boxMat[1] = atof( foo );
# Line 603 | Line 728 | char* DumpReader::parseCommentLine(char* readLine, dou
728    if(foo == NULL){
729      sprintf( painCave.errMsg,
730               "error in reading Hx[2] from %s\n",
731 <             c_in_name );
731 >             inName );
732      return strdup( painCave.errMsg );
733    }
734    boxMat[2] = atof( foo );    
# Line 614 | Line 739 | char* DumpReader::parseCommentLine(char* readLine, dou
739    if(foo == NULL){
740      sprintf( painCave.errMsg,
741               "error in reading Hy[0] from %s\n",
742 <             c_in_name );
742 >             inName );
743      return strdup( painCave.errMsg );
744    }
745    boxMat[3] = atof( foo );
# Line 623 | Line 748 | char* DumpReader::parseCommentLine(char* readLine, dou
748    if(foo == NULL){
749      sprintf( painCave.errMsg,
750               "error in reading Hy[1] from %s\n",
751 <             c_in_name );
751 >             inName );
752      return strdup( painCave.errMsg );
753    }
754    boxMat[4] = atof( foo );
# Line 632 | Line 757 | char* DumpReader::parseCommentLine(char* readLine, dou
757    if(foo == NULL){
758      sprintf( painCave.errMsg,
759               "error in reading Hy[2] from %s\n",
760 <             c_in_name );
760 >             inName );
761      return strdup( painCave.errMsg );
762    }
763    boxMat[5] = atof( foo );    
# Line 643 | Line 768 | char* DumpReader::parseCommentLine(char* readLine, dou
768    if(foo == NULL){
769      sprintf( painCave.errMsg,
770               "error in reading Hz[0] from %s\n",
771 <             c_in_name );
771 >             inName );
772      return strdup( painCave.errMsg );
773    }
774    boxMat[6] = atof( foo );
# Line 652 | Line 777 | char* DumpReader::parseCommentLine(char* readLine, dou
777    if(foo == NULL){
778      sprintf( painCave.errMsg,
779               "error in reading Hz[1] from %s\n",
780 <             c_in_name );
780 >             inName );
781      return strdup( painCave.errMsg );
782    }
783    boxMat[7] = atof( foo );
# Line 661 | Line 786 | char* DumpReader::parseCommentLine(char* readLine, dou
786    if(foo == NULL){
787      sprintf( painCave.errMsg,
788               "error in reading Hz[2] from %s\n",
789 <             c_in_name );
789 >             inName );
790      return strdup( painCave.errMsg );
791    }
792    boxMat[8] = atof( foo );    

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines