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)
31 sprintf(cRank, "%d", rank);
32 fulldir = wdir + "/" + tstamp(timestamp) + "_" + signature + ".tmp";
35 for (int itry=0; itry < 10 && mkdir( fulldir.c_str(), 0775) != 0; itry++)
38 for (int itry=0; itry < 100 && (!(stat(fulldir.c_str(), &sb) == 0) && S_ISDIR(sb.st_mode)); itry++)
41 if(rank>0) of.open( (fulldir + "/rank" + cRank + ".tmp").c_str() );
42 else of.open( (fulldir + "/" + signature + ".dat").c_str() );
44 logf.open( (fulldir + "/rank" + cRank + ".log").c_str() );
46 if ( (!of.is_open()) || (!logf.is_open()) ) {
47 cerr << "WRITEOUT: Could not open output- and/or log-file!" << endl << flush;
51 logf << "[ " << timestring() << " ] Log starts here." << endl;
54 logbuf = logf.rdbuf();
60 logbuf = cerr.rdbuf();
62 out = new ostream(buf);
63 log = new ostream(logbuf);
66 string writeout::timestring()
71 timestring = asctime( localtime( &rawtime ) );
72 return timestring.substr(0, timestring.size()-1);;
82 while(jobsdone<numprocs-1)
85 if( (nextfile=getdatfile()) == "" ) sleep(1);
88 logf << "collecting " << nextfile << endl;
90 ifstream myfile( (fulldir + "/" + nextfile).c_str() );
93 getline(myfile, line);
94 if( !myfile.good() ) break;
95 of << line << endl << flush;
98 remove( (fulldir + "/" + nextfile).c_str() );
102 of << "#end" << endl << flush;
104 rename( fulldir.c_str(), fulldir.substr(0, fulldir.length()-4).c_str() );
109 rename((fulldir + "/rank" + cRank + ".tmp").c_str(),
110 (fulldir + "/rank" + cRank + ".part").c_str());
113 logf << "[ " << timestring() << " ] Log ends here." << endl;
117 string writeout::getdatfile()
123 if((dp = opendir(fulldir.c_str())) == NULL) {
124 logf << "Error(" << errno << ") opening " << fulldir << endl;
128 while ((dirp = readdir(dp)) != NULL)
130 myfile = string(dirp->d_name);
131 if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part")