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";
32 mkdir(fulldir.c_str(), 0775);
34 if(rank>0) of.open( (fulldir + "/rank" + cRank + ".tmp").c_str() );
35 else of.open( (fulldir + "/" + signature + ".dat").c_str() );
37 logf.open( (fulldir + "/rank" + cRank + ".log").c_str() );
39 if ( (!of.is_open()) || (!logf.is_open()) ) {
40 cerr << "WRITEOUT: Could not open output- and/or log-file!" << endl << flush;
44 logf << "[ " << timestring() << " ] Log starts here." << endl;
47 logbuf = logf.rdbuf();
53 logbuf = cerr.rdbuf();
55 out = new ostream(buf);
56 log = new ostream(logbuf);
59 string writeout::timestring()
64 timestring = asctime( localtime( &rawtime ) );
65 return timestring.substr(0, timestring.size()-1);;
75 while(jobsdone<numprocs-1)
78 if( (nextfile=getdatfile()) == "" ) sleep(1);
81 logf << "collecting " << nextfile << endl;
83 ifstream myfile( (fulldir + "/" + nextfile).c_str() );
86 getline(myfile, line);
87 if( !myfile.good() ) break;
88 of << line << endl << flush;
91 remove( (fulldir + "/" + nextfile).c_str() );
95 of << "#end" << endl << flush;
97 rename( fulldir.c_str(), fulldir.substr(0, fulldir.length()-4).c_str() );
102 rename((fulldir + "/rank" + cRank + ".tmp").c_str(),
103 (fulldir + "/rank" + cRank + ".part").c_str());
106 logf << "[ " << timestring() << " ] Log ends here." << endl;
110 string writeout::getdatfile()
116 if((dp = opendir(fulldir.c_str())) == NULL) {
117 logf << "Error(" << errno << ") opening " << fulldir << endl;
121 while ((dirp = readdir(dp)) != NULL)
123 myfile = string(dirp->d_name);
124 if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part")