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() );
41 out = new ostream(buf);
51 while(jobsdone<numprocs-1)
54 if( (nextfile=getdatfile()) == "" ) sleep(1);
57 cerr << "collecting " << nextfile << endl;
59 ifstream myfile( (fulldir + "/" + nextfile).c_str() );
62 getline(myfile, line);
63 if( !myfile.good() ) break;
64 of << line << endl << flush;
67 remove( (fulldir + "/" + nextfile).c_str() );
71 of << "#end" << endl << flush;
73 rename( fulldir.c_str(), fulldir.substr(0, fulldir.length()-4).c_str() );
78 rename((fulldir + "/rank" + cRank + ".tmp").c_str(),
79 (fulldir + "/rank" + cRank + ".part").c_str());
84 string writeout::getdatfile()
90 if((dp = opendir(fulldir.c_str())) == NULL) {
91 cerr << "Error(" << errno << ") opening " << fulldir << endl;
95 while ((dirp = readdir(dp)) != NULL)
97 myfile = string(dirp->d_name);
98 if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part")