15 string writeout::tstamp(const long& timestamp)
18 if(!timestamp) sstr << time (NULL);
19 else sstr << timestamp;
23 writeout::writeout(const string& wdir, const string& signature,
24 const int& rank, const int& procs, const long& timestamp)
28 sprintf(cRank, "%d", rank);
29 fulldir = wdir + "/" + tstamp(timestamp) + "_" + signature + ".tmp";
30 mkdir( fulldir.c_str(), 0775);
32 if(rank>0) of.open( (fulldir + "/rank" + cRank + ".tmp").c_str() );
33 else of.open( (fulldir + "/" + signature + ".dat").c_str() );
40 out = new ostream(buf);
50 while(jobsdone<numprocs-1)
53 if( (nextfile=getdatfile()) == "" ) sleep(1);
56 cerr << "collecting " << nextfile << endl;
58 ifstream myfile( (fulldir + "/" + nextfile).c_str() );
61 getline(myfile, line);
62 if( !myfile.good() ) break;
63 of << line << endl << flush;
66 remove( (fulldir + "/" + nextfile).c_str() );
70 of << "#end" << endl << flush;
72 rename( fulldir.c_str(), fulldir.substr(0, fulldir.length()-4).c_str() );
77 rename((fulldir + "/rank" + cRank + ".tmp").c_str(),
78 (fulldir + "/rank" + cRank + ".part").c_str());
83 string writeout::getdatfile()
89 if((dp = opendir(fulldir.c_str())) == NULL) {
90 cerr << "Error(" << errno << ") opening " << fulldir << endl;
94 while ((dirp = readdir(dp)) != NULL)
96 myfile = string(dirp->d_name);
97 if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part")