16 string writeout::tstamp(const long& timestamp)
19 if(!timestamp) sstr << time (NULL);
20 else sstr << timestamp;
24 writeout::writeout(const string& wdir, const string& signature,
25 const int& rank, const int& procs, const long& timestamp)
29 sprintf(cRank, "%d", rank);
30 fulldir = wdir + "/" + tstamp(timestamp) + "_" + signature + ".tmp";
31 mkdir( fulldir.c_str(), 0775);
33 if(rank>0) of.open( (fulldir + "/rank" + cRank + ".tmp").c_str() );
34 else of.open( (fulldir + "/" + signature + ".dat").c_str() );
36 logf.open( (fulldir + "/rank" + cRank + ".log").c_str() );
38 logf << "[ " << timestring() << " ] Log starts here." << endl;
41 logbuf = logf.rdbuf();
45 logf.open("/dev/null");
46 logbuf = logf.rdbuf();
48 out = new ostream(buf);
49 log = new ostream(logbuf);
52 string writeout::timestring()
57 timestring = asctime( localtime( &rawtime ) );
58 return timestring.substr(0, timestring.size()-1);;
68 while(jobsdone<numprocs-1)
71 if( (nextfile=getdatfile()) == "" ) sleep(1);
74 cerr << "collecting " << nextfile << endl;
76 ifstream myfile( (fulldir + "/" + nextfile).c_str() );
79 getline(myfile, line);
80 if( !myfile.good() ) break;
81 of << line << endl << flush;
84 remove( (fulldir + "/" + nextfile).c_str() );
88 of << "#end" << endl << flush;
90 rename( fulldir.c_str(), fulldir.substr(0, fulldir.length()-4).c_str() );
95 rename((fulldir + "/rank" + cRank + ".tmp").c_str(),
96 (fulldir + "/rank" + cRank + ".part").c_str());
99 logf << "[ " << timestring() << " ] Log ends here." << endl;
103 string writeout::getdatfile()
109 if((dp = opendir(fulldir.c_str())) == NULL) {
110 cerr << "Error(" << errno << ") opening " << fulldir << endl;
114 while ((dirp = readdir(dp)) != NULL)
116 myfile = string(dirp->d_name);
117 if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part")