ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/io/ifstrstream.cpp
(Generate patch)

Comparing trunk/src/io/ifstrstream.cpp (file contents):
Revision 1796 by gezelter, Mon Sep 10 18:38:44 2012 UTC vs.
Revision 1962 by gezelter, Wed Jan 15 22:26:18 2014 UTC

# Line 35 | Line 35
35   *                                                                      
36   * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37   * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 < * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
38 > * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).          
39   * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40   * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42  
43   /**
44 < * @file basic_ifstrstream.cpp
44 > * @file ifstrstream.cpp
45   * @author Teng Lin
46   * @date 10/14/2004
47   * @version 1.0
48   */
49  
50 #include "io/ifstrstream.hpp"
51
50   #ifdef IS_MPI
51   #include <mpi.h>
52   #endif
53  
54 + #include "io/ifstrstream.hpp"
55 +
56   namespace OpenMD {
57    
58    /**  Constructs an object of class ifstream.  */
59   #ifdef IS_MPI
60    ifstrstream::ifstrstream()
61      :  std::basic_istream<char, std::char_traits<char> >(0),
62 <       internalStringBuf_(), isRead(false)  {    
62 >    internalStringBuf_(), isRead(false)  {    
63      this->init(&internalStringBuf_);
64    }
65   #else
66    ifstrstream::ifstrstream()
67      :  std::basic_istream<char, std::char_traits<char> >(0),
68 <       internalFileBuf_(), isRead(false)  {    
68 >    internalFileBuf_(), isRead(false)  {    
69      this->init(&internalFileBuf_);
70    }
71   #endif
72    
73    /**
74     * Explicit constructor
75 <   * @filename String containing the name of the file to be opened
76 <   * @mode Flags describing the requested i/o mode for the file, default value is ios_base::in      
77 <   * @checkFilename Flags indicating checking the file name in parallel
75 >   * @param filename String containing the name of the file to be opened
76 >   * @param mode Flags describing the requested i/o mode for the file,
77 >   * default value is ios_base::in
78 >   * @param checkFilename Flags indicating checking the file name in parallel
79     */
80   #ifdef IS_MPI
81    ifstrstream::ifstrstream(const char* filename, std::ios_base::openmode mode, bool checkFilename)
# Line 93 | Line 94 | namespace OpenMD {
94    }
95   #endif  
96    /**
97 <   * virtual destructor will close the file(in single mode) and clear the stream buffer
97 >   * virtual destructor will close the file (in single mode) and clear
98 >   * the stream buffer
99     */
100    ifstrstream::~ifstrstream(){
101      close();
102    }
103    
104    /**
105 <   * Opens a file and associats a buffer with the specified file to perform the i/o operations
106 <   * (single mode). Master reads a file and brocasts its content to the other slave nodes. After
107 <   * brocasting, every nodes fall back to stringstream (parallel mode).
108 <   * @filename String containing the name of the file to be opened
109 <   * @mode Flags describing the requested i/o mode for the file
110 <   * @checkFilename Flags indicating checking the file name in parallel
105 >   * Opens a file and associates a buffer with the specified file to
106 >   * perform the i/o operations (single mode). The master node reads a
107 >   * file and broadcasts its content to the other slave nodes. After
108 >   * broadcasting, all nodes fall back to stringstream (parallel
109 >   * mode).
110 >   * @param filename String containing the name of the file to be opened
111 >   * @param mode Flags describing the requested i/o mode for the file
112 >   * @param checkFilename Flags indicating checking the file name in parallel
113     */
114    void ifstrstream::open(const char* filename, std::ios_base::openmode mode, bool checkFilename){
115      
# Line 115 | Line 119 | namespace OpenMD {
119    }
120  
121    /**
122 <   * Tests if the stream is currently associated with a valid  buffer.
123 <   * @return true if a file has successfully been opened (single mode) or the whole file is read
124 <   * and spreaded among all of the processors (parallel mode),  otherwise false is returned
122 >   * Tests if the stream is currently associated with a valid buffer.
123 >   * @return true if a file has successfully been opened (single mode)
124 >   * or the whole file has been read and spread among all of the
125 >   * processors (parallel mode), otherwise false is returned
126     */
127    bool ifstrstream::is_open ( ) {
128   #ifdef IS_MPI            
# Line 131 | Line 136 | namespace OpenMD {
136    /**
137     * In single mode, closes a file. The stream's file buffer is
138     * released from its association with the currently open file. In
139 <   * parallel mode, clean the
139 >   * parallel mode, cleans up.
140     */
141    void ifstrstream::close() {
142   #ifndef IS_MPI            
# Line 157 | Line 162 | namespace OpenMD {
162    }  
163    
164    /**
165 <     * Internal function used to open the file
166 <     * @return true if succesfully opens a file (single mode) or gets the file content (parallel mode)
167 <     * otherwise return false
168 <     * @filename String containing the name of the file to be opened
169 <     * @mode Flags describing the requested i/o mode for the file
170 <     * @todo use try - catch syntax to make the program more readable
171 <     */
165 >   * Internal function used to open the file
166 >   * @return true if succesfully opens a file (single mode) or gets
167 >   * the file content (parallel mode) otherwise return false
168 >   * @param filename String containing the name of the file to be opened
169 >   * @param mode Flags describing the requested i/o mode for the file
170 >   * @param checkFilename Flags indicating checking the file name in parallel
171 >   * @todo use try - catch syntax to make the program more readable
172 >   */
173  
174    bool ifstrstream::internalOpen(const char* filename, std::ios_base::openmode mode, bool checkFilename){
175      
# Line 192 | Line 198 | namespace OpenMD {
198          
199          diffFilename = 0;
200          MPI::COMM_WORLD.Allreduce(&diffFilename, &error, 1, MPI::INT, MPI::SUM);
201 <
201 >        
202          //if file names are different just return false
203          if (error > 0)
204            return false;  
# Line 221 | Line 227 | namespace OpenMD {
227          
228          if (fileSize < 0) {
229            fin.close();                    
230 <          delete fbuf;
230 >          delete[] fbuf;
231            
232            return false;
233          }
# Line 233 | Line 239 | namespace OpenMD {
239          //close the file and delete the buffer
240          fin.close();      
241          internalStringBuf_.str(fbuf);
242 <        delete [] fbuf;
242 >        delete[] fbuf;
243        }else{
244          fileSize = FileNotExists;
245          MPI::COMM_WORLD.Bcast(&fileSize, 1, MPI::LONG, masterNode);
# Line 255 | Line 261 | namespace OpenMD {
261          else
262            diffFilename = 1;
263          
264 <        delete masterFilename;
264 >        delete[] masterFilename;
265          
266          MPI::COMM_WORLD.Allreduce(&diffFilename, &error, 1, MPI::INT, MPI::SUM);
267          

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines