ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/io/DumpWriter.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/io/DumpWriter.cpp (file contents):
Revision 1935 by tim, Wed Jan 12 23:24:55 2005 UTC vs.
Revision 2079 by tim, Thu Mar 3 14:40:20 2005 UTC

# Line 42 | Line 42
42   #include "io/DumpWriter.hpp"
43   #include "primitives/Molecule.hpp"
44   #include "utils/simError.h"
45 <
45 > #include "io/basic_teebuf.hpp"
46   #ifdef IS_MPI
47   #include <mpi.h>
48   #endif //is_mpi
49  
50   namespace oopse {
51 +
52 + DumpWriter::DumpWriter(SimInfo* info)
53 +                   : info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){
54 + #ifdef IS_MPI
55 +
56 +    if (worldRank == 0) {
57 + #endif // is_mpi
58 +
59 +        dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc);
60 +
61 +        if (!dumpFile_) {
62 +            sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
63 +                    filename_.c_str());
64 +            painCave.isFatal = 1;
65 +            simError();
66 +        }
67 +
68 + #ifdef IS_MPI
69 +
70 +    }
71 +
72 +    sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n");
73 +    MPIcheckPoint();
74 +
75 + #endif // is_mpi
76 +
77 + }
78  
79 +
80   DumpWriter::DumpWriter(SimInfo* info, const std::string& filename)
81                     : info_(info), filename_(filename){
82   #ifdef IS_MPI
# Line 56 | Line 84 | DumpWriter::DumpWriter(SimInfo* info, const std::strin
84      if (worldRank == 0) {
85   #endif // is_mpi
86  
87 +        eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor";
88          dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc);
89  
90          if (!dumpFile_) {
# Line 120 | Line 149 | void DumpWriter::writeCommentLine(std::ostream& os, Sn
149           << eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t"
150           << eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";";
151          
152 <    os << std::endl;
152 >    os << "\n";
153   }
154  
155   void DumpWriter::writeFrame(std::ostream& os) {
# Line 183 | Line 212 | void DumpWriter::writeFrame(std::ostream& os) {
212          }
213      }
214  
215 +    os.flush();
216   #else // is_mpi
217      /*********************************************************************
218       * Documentation?  You want DOCUMENTATION?
# Line 228 | Line 258 | void DumpWriter::writeFrame(std::ostream& os) {
258      int which_node;
259      double atomData[13];
260      int isDirectional;
231    const char * atomTypeString;
261      char MPIatomTypeString[MINIBUFFERSIZE];
262      int msgLen; // the length of message actually recieved at master nodes
263      int haveError;
# Line 300 | Line 329 | void DumpWriter::writeFrame(std::ostream& os) {
329                               which_node, myPotato, MPI_COMM_WORLD,
330                               &istatus);
331  
303                    atomTypeString = MPIatomTypeString;
304
332                      myPotato++;
333  
334                      MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato,
# Line 319 | Line 346 | void DumpWriter::writeFrame(std::ostream& os) {
346  
347                      if (!isDirectional) {
348                          sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
349 <                                atomTypeString, atomData[0],
349 >                                MPIatomTypeString, atomData[0],
350                                  atomData[1], atomData[2],
351                                  atomData[3], atomData[4],
352                                  atomData[5]);
# Line 329 | Line 356 | void DumpWriter::writeFrame(std::ostream& os) {
356                      } else {
357                          sprintf(writeLine,
358                                  "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
359 <                                atomTypeString,
359 >                                MPIatomTypeString,
360                                  atomData[0],
361                                  atomData[1],
362                                  atomData[2],
# Line 361 | Line 388 | void DumpWriter::writeFrame(std::ostream& os) {
388                  }
389                  
390                  for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
391 <                    integrableObject = mol->nextIntegrableObject(ii)) {
365 <                        
366 <                    atomTypeString = integrableObject->getType().c_str();
391 >                    integrableObject = mol->nextIntegrableObject(ii)) {      
392  
393                      pos = integrableObject->getPos();
394                      vel = integrableObject->getVel();
# Line 402 | Line 427 | void DumpWriter::writeFrame(std::ostream& os) {
427  
428                      if (!isDirectional) {
429                          sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
430 <                                atomTypeString, atomData[0],
430 >                                integrableObject->getType().c_str(), atomData[0],
431                                  atomData[1], atomData[2],
432                                  atomData[3], atomData[4],
433                                  atomData[5]);
# Line 412 | Line 437 | void DumpWriter::writeFrame(std::ostream& os) {
437                      } else {
438                          sprintf(writeLine,
439                                  "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
440 <                                atomTypeString,
440 >                                integrableObject->getType().c_str(),
441                                  atomData[0],
442                                  atomData[1],
443                                  atomData[2],
# Line 485 | Line 510 | void DumpWriter::writeFrame(std::ostream& os) {
510                                   &istatus);
511                      }
512  
488                    atomTypeString = integrableObject->getType().c_str();
489
513                      pos = integrableObject->getPos();
514                      vel = integrableObject->getVel();
515  
# Line 516 | Line 539 | void DumpWriter::writeFrame(std::ostream& os) {
539                          atomData[12] = ji[2];
540                      }
541  
542 <                    strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE);
542 >                    strncpy(MPIatomTypeString, integrableObject->getType().c_str(), MINIBUFFERSIZE);
543  
544                      // null terminate the  std::string before sending (just in case):
545                      MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0';
# Line 548 | Line 571 | void DumpWriter::writeFrame(std::ostream& os) {
571  
572   }
573  
574 + void DumpWriter::writeDump() {
575 +    writeFrame(dumpFile_);
576 +
577 + }
578 +
579 + void DumpWriter::writeEor() {
580 +    std::ofstream eorStream;
581 +    
582 + #ifdef IS_MPI
583 +    if (worldRank == 0) {
584 + #endif // is_mpi
585 +
586 +        eorStream.open(eorFilename_.c_str());
587 +        if (!eorStream.is_open()) {
588 +            sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n",
589 +                    eorFilename_.c_str());
590 +            painCave.isFatal = 1;
591 +            simError();
592 +        }
593 +
594 + #ifdef IS_MPI
595 +    }
596 + #endif // is_mpi    
597 +
598 +    writeFrame(eorStream);
599 + }
600 +
601 +
602 + void DumpWriter::writeDumpAndEor() {
603 +    std::ofstream eorStream;
604 +    std::vector<std::streambuf*> buffers;
605 + #ifdef IS_MPI
606 +    if (worldRank == 0) {
607 + #endif // is_mpi
608 +
609 +        buffers.push_back(dumpFile_.rdbuf());
610 +
611 +        eorStream.open(eorFilename_.c_str());
612 +        if (!eorStream.is_open()) {
613 +            sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n",
614 +                    eorFilename_.c_str());
615 +            painCave.isFatal = 1;
616 +            simError();
617 +        }
618 +
619 +        buffers.push_back(eorStream.rdbuf());
620 +        
621 + #ifdef IS_MPI
622 +    }
623 + #endif // is_mpi    
624 +
625 +    TeeBuf tbuf(buffers.begin(), buffers.end());
626 +    std::ostream os(&tbuf);
627 +
628 +    writeFrame(os);
629 +    
630 + }
631 +
632 +
633 +
634   }//end namespace oopse

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines