]> git.treefish.org Git - phys/latlib.git/blobdiff - writeout.cpp
...
[phys/latlib.git] / writeout.cpp
index 7834d6b743173b70e239dd4849a1c69171dc7847..966559da14950f088522878f237e5f693ce05de1 100644 (file)
@@ -22,7 +22,7 @@ string writeout::tstamp(const long& timestamp)
 }
 
 void writeout::newsub(string subname) {
-   of[subname] = new ofstream;
+  of[subname] = new ofstream;
 
   if ( fulldir != "" ) {
     if(rank>0) of[subname]->open( (fulldir + "/rank" + cRank + "-" + subname + ".tmp").c_str() );
@@ -85,9 +85,12 @@ writeout::~writeout()
 {
   if(fulldir != "") {
     for (map<string,ofstream*>::iterator ofit = of.begin(); ofit != of.end(); ++ofit) {
-      if( cRank[0] == '0' ) {    
+      cout << ofit->first << endl;
+      if( cRank[0] == '0' ) {
        int jobsdone=0;
        while(jobsdone<numprocs-1) {
+         cout << ofit->first << endl;
+         cout << "here" << endl;
          string nextfile;
          if( (nextfile = getdatfile(ofit->first)) == "" ) 
            sleep(1);
@@ -108,14 +111,15 @@ writeout::~writeout()
        }
        *ofit->second << "#end" << endl << flush;
        ofit->second->close();
-       rename( fulldir.c_str(), fulldir.substr(0, fulldir.length()-4).c_str() );
       }
       else {
        ofit->second->close();
-       rename((fulldir + "/rank" + cRank + ".tmp").c_str(),
-              (fulldir + "/rank" + cRank + ".part").c_str());
+       rename((fulldir + "/rank" + cRank + "-" + ofit->first + ".tmp").c_str(),
+              (fulldir + "/rank" + cRank + "-" + ofit->first + ".part").c_str());
       }
     }
+    if( cRank[0] == '0' )
+      rename( fulldir.c_str(), fulldir.substr(0, fulldir.length()-4).c_str() );
   }
   logf << "[ " << timestring() << " ] Log ends here." << endl;
   logf.close();
@@ -127,15 +131,23 @@ string writeout::getdatfile(string subname)
   DIR *dp;
   struct dirent *dirp;
 
+  cout << "getting:" << subname << endl;
+
   if((dp  = opendir(fulldir.c_str())) == NULL) {
     logf << "Error(" << errno << ") opening " << fulldir << endl;
+    cout << "blub" << endl;
     return "";
   }
   
   while ((dirp = readdir(dp)) != NULL)
     {
       myfile = string(dirp->d_name);
-      if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part") {
+
+      cout << myfile << endl;
+
+      if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part" &&
+        subname == myfile.substr( myfile.find("-")+1, myfile.rfind(".")-myfile.find("-")-1 ) ) {
+       cout << myfile << endl;
        return myfile;
       }
     }