Changeset 523 for XIOS/trunk/src/client.cpp
- Timestamp:
- 12/01/14 16:21:48 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/client.cpp
r511 r523 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) … … 246 247 } 247 248 248 /*! 249 * \brief Open file stream to write in 250 * Opening a file stream with a specific file name suffix-client+rank 251 * \param [in] protype file name 252 */ 253 void CClient::openInfoStream(const StdString& fileName) 254 { 255 std::filebuf* fb = m_infoStream.rdbuf(); 256 StdStringStream fileNameClient; 257 int numDigit = 0; 258 int size = 0; 259 MPI_Comm_size(CXios::globalComm, &size); 260 while (size) 261 { 262 size /= 10; 263 ++numDigit; 264 } 265 266 fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ".out"; 267 fb->open(fileNameClient.str().c_str(), std::ios::out); 268 if (!fb->is_open()) 269 ERROR("void CClient::openInfoStream(const StdString& fileName)", 270 <<endl<< "Can not open <"<<fileNameClient<<"> file to write" ); 271 272 info.write2File(fb); 273 report.write2File(fb); 274 } 275 276 //! Write out to standard output 277 void CClient::openInfoStream() 278 { 279 info.write2StdOut(); 280 report.write2StdOut(); 281 } 282 283 //! Close file if it opens 284 void CClient::closeInfoStream() 285 { 286 if (m_infoStream.is_open()) m_infoStream.close(); 287 } 288 289 249 /*! 250 * Open a file specified by a suffix and an extension and use it for the given file buffer. 251 * The file name will be suffix+rank+extension. 252 * 253 * \param fileName[in] protype file name 254 * \param ext [in] extension of the file 255 * \param fb [in/out] the file buffer 256 */ 257 void CClient::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb) 258 { 259 StdStringStream fileNameClient; 260 int numDigit = 0; 261 int size = 0; 262 MPI_Comm_size(CXios::globalComm, &size); 263 while (size) 264 { 265 size /= 10; 266 ++numDigit; 267 } 268 269 fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ext; 270 fb->open(fileNameClient.str().c_str(), std::ios::out); 271 if (!fb->is_open()) 272 ERROR("void CClient::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb)", 273 << std::endl << "Can not open <" << fileNameClient << "> file to write the client log(s)."); 274 } 275 276 /*! 277 * \brief Open a file stream to write the info logs 278 * Open a file stream with a specific file name suffix+rank 279 * to write the info logs. 280 * \param fileName [in] protype file name 281 */ 282 void CClient::openInfoStream(const StdString& fileName) 283 { 284 std::filebuf* fb = m_infoStream.rdbuf(); 285 openStream(fileName, ".out", fb); 286 287 info.write2File(fb); 288 report.write2File(fb); 289 } 290 291 //! Write the info logs to standard output 292 void CClient::openInfoStream() 293 { 294 info.write2StdOut(); 295 report.write2StdOut(); 296 } 297 298 //! Close the info logs file if it opens 299 void CClient::closeInfoStream() 300 { 301 if (m_infoStream.is_open()) m_infoStream.close(); 302 } 303 304 /*! 305 * \brief Open a file stream to write the error log 306 * Open a file stream with a specific file name suffix+rank 307 * to write the error log. 308 * \param fileName [in] protype file name 309 */ 310 void CClient::openErrorStream(const StdString& fileName) 311 { 312 std::filebuf* fb = m_errorStream.rdbuf(); 313 openStream(fileName, ".err", fb); 314 315 error.write2File(fb); 316 } 317 318 //! Write the error log to standard error output 319 void CClient::openErrorStream() 320 { 321 error.write2StdErr(); 322 } 323 324 //! Close the error log file if it opens 325 void CClient::closeErrorStream() 326 { 327 if (m_errorStream.is_open()) m_errorStream.close(); 328 } 290 329 }
Note: See TracChangeset
for help on using the changeset viewer.