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 logbuf = cerr.rdbuf();
47 out = new ostream(buf);
48 log = new ostream(logbuf);
51 string writeout::timestring()
56 timestring = asctime( localtime( &rawtime ) );
57 return timestring.substr(0, timestring.size()-1);;
67 while(jobsdone<numprocs-1)
70 if( (nextfile=getdatfile()) == "" ) sleep(1);
73 cerr << "collecting " << nextfile << endl;
75 ifstream myfile( (fulldir + "/" + nextfile).c_str() );
78 getline(myfile, line);
79 if( !myfile.good() ) break;
80 of << line << endl << flush;
83 remove( (fulldir + "/" + nextfile).c_str() );
87 of << "#end" << endl << flush;
89 rename( fulldir.c_str(), fulldir.substr(0, fulldir.length()-4).c_str() );
94 rename((fulldir + "/rank" + cRank + ".tmp").c_str(),
95 (fulldir + "/rank" + cRank + ".part").c_str());
98 logf << "[ " << timestring() << " ] Log ends here." << endl;
102 string writeout::getdatfile()
108 if((dp = opendir(fulldir.c_str())) == NULL) {
109 cerr << "Error(" << errno << ") opening " << fulldir << endl;
113 while ((dirp = readdir(dp)) != NULL)
115 myfile = string(dirp->d_name);
116 if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part")