16 string writeout::tstamp(const long& timestamp)
19 if(!timestamp) sstr << time (NULL);
20 else sstr << timestamp;
24 void writeout::newsub(string subname) {
25 of[subname] = new ofstream;
27 if ( fulldir != "" ) {
28 if(rank>0) of[subname]->open( (fulldir + "/rank" + cRank + "-" + subname + ".tmp").c_str() );
29 else of[subname]->open( (fulldir + "/" + signature + "-" + subname + ".dat").c_str() );
31 if ( !of[subname]->is_open() ) {
32 logf << "WRITEOUT: Could not open output-file!" << endl << flush;
36 buf[subname] = of[subname]->rdbuf();
39 buf[subname] = cout.rdbuf();
41 out[subname] = new ostream(buf[subname]);
44 writeout::writeout(const string& wdir, const string& _signature,
45 const int& _rank, const int& procs, const long& timestamp)
48 signature = _signature;
53 sprintf(cRank, "%d", rank);
54 fulldir = wdir + "/" + tstamp(timestamp) + "_" + signature + ".tmp";
56 mkdir(fulldir.c_str(), 0775);
58 logf.open( (fulldir + "/rank" + cRank + ".log").c_str() );
60 if ( !logf.is_open() ) {
61 cerr << "WRITEOUT: Could not open log-file!" << endl << flush;
65 logf << "[ " << timestring() << " ] Log starts here." << endl;
67 logbuf = logf.rdbuf();
70 logbuf = cerr.rdbuf();
72 log = new ostream(logbuf);
75 string writeout::timestring()
80 timestring = asctime( localtime( &rawtime ) );
81 return timestring.substr(0, timestring.size()-1);;
87 for (map<string,ofstream*>::iterator ofit = of.begin(); ofit != of.end(); ++ofit) {
88 cout << ofit->first << endl;
89 if( cRank[0] == '0' ) {
91 while(jobsdone<numprocs-1) {
92 cout << ofit->first << endl;
93 cout << "here" << endl;
95 if( (nextfile = getdatfile(ofit->first)) == "" )
98 logf << "collecting " << nextfile << endl;
100 ifstream myfile( (fulldir + "/" + nextfile).c_str() );
103 getline(myfile, line);
104 if( !myfile.good() ) break;
105 *ofit->second << line << endl << flush;
108 remove( (fulldir + "/" + nextfile).c_str() );
112 *ofit->second << "#end" << endl << flush;
113 ofit->second->close();
116 ofit->second->close();
117 rename((fulldir + "/rank" + cRank + "-" + ofit->first + ".tmp").c_str(),
118 (fulldir + "/rank" + cRank + "-" + ofit->first + ".part").c_str());
121 if( cRank[0] == '0' )
122 rename( fulldir.c_str(), fulldir.substr(0, fulldir.length()-4).c_str() );
124 logf << "[ " << timestring() << " ] Log ends here." << endl;
128 string writeout::getdatfile(string subname)
134 cout << "getting:" << subname << endl;
136 if((dp = opendir(fulldir.c_str())) == NULL) {
137 logf << "Error(" << errno << ") opening " << fulldir << endl;
138 cout << "blub" << endl;
142 while ((dirp = readdir(dp)) != NULL)
144 myfile = string(dirp->d_name);
146 cout << myfile << endl;
148 if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part" &&
149 subname == myfile.substr( myfile.find("-")+1, myfile.rfind(".")-myfile.find("-")-1 ) ) {
150 cout << myfile << endl;