From: Alex Schmidt Date: Mon, 25 Jun 2012 12:46:23 +0000 (+1000) Subject: added writeout class X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/6441a11e7c0fe2ab5bad813770474858302a88dd added writeout class --- diff --git a/.gitignore b/.gitignore index 9673182..382dfaa 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ CMakeFiles cmake_install.cmake Makefile *.a +*~ diff --git a/writeout.cpp b/writeout.cpp new file mode 100644 index 0000000..4fb68e1 --- /dev/null +++ b/writeout.cpp @@ -0,0 +1,101 @@ +#include "writeout.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +string writeout::tstamp() +{ + stringstream sstr; + sstr << time (NULL); + return sstr.str(); +} + +writeout::writeout(const string& wdir, const string& signature, + const int& rank, const int& procs) +{ + if(wdir != ""){ + numprocs = procs; + sprintf(cRank, "%d", rank); + fulldir = wdir + "/" + tstamp() + "_" + signature; + mkdir( fulldir.c_str(), 0775); + + if(rank>0) of.open( (fulldir + "/rank" + cRank + ".tmp").c_str() ); + else of.open( (fulldir + "/" + signature + ".dat").c_str() ); + + buf = of.rdbuf(); + } + else{ + buf = cout.rdbuf(); + } + out = new ostream(buf); +} + +writeout::~writeout() +{ + if(fulldir != "") + { + if( cRank[0] == '0' ) + { + int jobsdone=0; + while(jobsdoned_name); + if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part") + return myfile; + } + + return ""; +} diff --git a/writeout.h b/writeout.h new file mode 100644 index 0000000..48057d4 --- /dev/null +++ b/writeout.h @@ -0,0 +1,27 @@ +#ifndef WRITEOUT_H +#define WRITEOUT_H + +#include +#include + +using namespace std; + +class writeout +{ + public: + writeout(const string& wdir, const string& signature, + const int& rank, const int& procs); + ostream *out; + ~writeout(); + + private: + ofstream of; + streambuf *buf; + string fulldir; + char cRank[20]; + string tstamp(); + int numprocs; + string getdatfile(); +}; + +#endif