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";
34 mkdir( fulldir.c_str(), 0775);
36 if(rank>0) of.open( (fulldir + "/rank" + cRank + ".tmp").c_str() );
37 else of.open( (fulldir + "/" + signature + ".dat").c_str() );
39 logf.open( (fulldir + "/rank" + cRank + ".log").c_str() );
41 if ( (!of.is_open()) || (!logf.is_open()) ) {
42 cerr << "WRITEOUT: Could not open output- and/or log-file!" << endl << flush;
46 logf << "[ " << timestring() << " ] Log starts here." << endl;
49 logbuf = logf.rdbuf();
55 logbuf = cerr.rdbuf();
57 out = new ostream(buf);
58 log = new ostream(logbuf);
61 string writeout::timestring()
66 timestring = asctime( localtime( &rawtime ) );
67 return timestring.substr(0, timestring.size()-1);;
77 while(jobsdone<numprocs-1)
80 if( (nextfile=getdatfile()) == "" ) sleep(1);
83 logf << "collecting " << nextfile << endl;
85 ifstream myfile( (fulldir + "/" + nextfile).c_str() );
88 getline(myfile, line);
89 if( !myfile.good() ) break;
90 of << line << endl << flush;
93 remove( (fulldir + "/" + nextfile).c_str() );
97 of << "#end" << endl << flush;
99 rename( fulldir.c_str(), fulldir.substr(0, fulldir.length()-4).c_str() );
104 rename((fulldir + "/rank" + cRank + ".tmp").c_str(),
105 (fulldir + "/rank" + cRank + ".part").c_str());
108 logf << "[ " << timestring() << " ] Log ends here." << endl;
112 string writeout::getdatfile()
118 if((dp = opendir(fulldir.c_str())) == NULL) {
119 logf << "Error(" << errno << ") opening " << fulldir << endl;
123 while ((dirp = readdir(dp)) != NULL)
125 myfile = string(dirp->d_name);
126 if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part")