Changeset 548 for XIOS/branchs/xios-1.0/src/client.cpp
- Timestamp:
- 01/23/15 16:18:43 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/branchs/xios-1.0/src/client.cpp
r507 r548 21 21 int CClient::rank = INVALID_RANK; 22 22 StdOFStream CClient::m_infoStream; 23 StdOFStream CClient::m_errorStream; 23 24 24 25 void CClient::initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm) … … 233 234 } 234 235 235 /*! 236 * \brief Open file stream to write in 237 * Opening a file stream with a specific file name suffix-client+rank 238 * \param [in] protype file name 239 */ 240 void CClient::openInfoStream(const StdString& fileName) 241 { 242 std::filebuf* fb = m_infoStream.rdbuf(); 243 StdStringStream fileNameClient; 244 int numDigit = 0; 245 int size = 0; 246 MPI_Comm_size(CXios::globalComm, &size); 247 while (size) 248 { 249 size /= 10; 250 ++numDigit; 251 } 252 253 fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ".out"; 254 fb->open(fileNameClient.str().c_str(), std::ios::out); 255 if (!fb->is_open()) 256 ERROR("void CClient::openInfoStream(const StdString& fileName)", 257 <<endl<< "Can not open <"<<fileNameClient<<"> file to write" ); 258 259 info.write2File(fb); 260 report.write2File(fb); 261 } 262 263 //! Write out to standard output 264 void CClient::openInfoStream() 265 { 266 info.write2StdOut(); 267 report.write2StdOut(); 268 } 269 270 //! Close file if it opens 271 void CClient::closeInfoStream() 272 { 273 if (m_infoStream.is_open()) m_infoStream.close(); 274 } 275 276 236 /*! 237 * Open a file specified by a suffix and an extension and use it for the given file buffer. 238 * The file name will be suffix+rank+extension. 239 * 240 * \param fileName[in] protype file name 241 * \param ext [in] extension of the file 242 * \param fb [in/out] the file buffer 243 */ 244 void CClient::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb) 245 { 246 StdStringStream fileNameClient; 247 int numDigit = 0; 248 int size = 0; 249 MPI_Comm_size(CXios::globalComm, &size); 250 while (size) 251 { 252 size /= 10; 253 ++numDigit; 254 } 255 256 fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ext; 257 fb->open(fileNameClient.str().c_str(), std::ios::out); 258 if (!fb->is_open()) 259 ERROR("void CClient::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb)", 260 << std::endl << "Can not open <" << fileNameClient << "> file to write the client log(s)."); 261 } 262 263 /*! 264 * \brief Open a file stream to write the info logs 265 * Open a file stream with a specific file name suffix+rank 266 * to write the info logs. 267 * \param fileName [in] protype file name 268 */ 269 void CClient::openInfoStream(const StdString& fileName) 270 { 271 std::filebuf* fb = m_infoStream.rdbuf(); 272 openStream(fileName, ".out", fb); 273 274 info.write2File(fb); 275 report.write2File(fb); 276 } 277 278 //! Write the info logs to standard output 279 void CClient::openInfoStream() 280 { 281 info.write2StdOut(); 282 report.write2StdOut(); 283 } 284 285 //! Close the info logs file if it opens 286 void CClient::closeInfoStream() 287 { 288 if (m_infoStream.is_open()) m_infoStream.close(); 289 } 290 291 /*! 292 * \brief Open a file stream to write the error log 293 * Open a file stream with a specific file name suffix+rank 294 * to write the error log. 295 * \param fileName [in] protype file name 296 */ 297 void CClient::openErrorStream(const StdString& fileName) 298 { 299 std::filebuf* fb = m_errorStream.rdbuf(); 300 openStream(fileName, ".err", fb); 301 302 error.write2File(fb); 303 } 304 305 //! Write the error log to standard error output 306 void CClient::openErrorStream() 307 { 308 error.write2StdErr(); 309 } 310 311 //! Close the error log file if it opens 312 void CClient::closeErrorStream() 313 { 314 if (m_errorStream.is_open()) m_errorStream.close(); 315 } 277 316 }
Note: See TracChangeset
for help on using the changeset viewer.