]> git.donarmstrong.com Git - mothur.git/blobdiff - mothurout.cpp
added tree reader class to handle reading trees. Reworked the tree map to tree class...
[mothur.git] / mothurout.cpp
index 98f5ce09608855690a9fc7442814841a064db379..ee809fafc6e39f6c5cc02d78b513d82704864aa8 100644 (file)
@@ -598,6 +598,48 @@ string MothurOut::getPathName(string longName){
 }
 /***********************************************************************/
 
+bool MothurOut::dirCheck(string& dirName){
+       try {
+        
+        string tag = "";
+        #ifdef USE_MPI
+            int pid; 
+            MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
+               
+            tag = toString(pid);
+        #endif
+
+        //add / to name if needed
+        string lastChar = dirName.substr(dirName.length()-1);
+        #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+        if (lastChar != "/") { dirName += "/"; }
+        #else
+        if (lastChar != "\\") { dirName += "\\"; }     
+        #endif
+
+        //test to make sure directory exists
+        dirName = getFullPathName(dirName);
+        string outTemp = dirName + tag + "temp";
+        ofstream out;
+        out.open(outTemp.c_str(), ios::trunc);
+        if(!out) {
+            mothurOut(dirName + " directory does not exist or is not writable."); mothurOutEndLine(); 
+        }else{
+            out.close();
+            mothurRemove(outTemp);
+            return true;
+        }
+        
+        return false;
+    }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "dirCheck");
+               exit(1);
+       }       
+    
+}
+/***********************************************************************/
+
 string MothurOut::hasPath(string longName){
        try {
                string path = "";
@@ -972,7 +1014,8 @@ int MothurOut::appendFiles(string temp, string filename) {
                
                int numLines = 0;
                if (ableToOpen == 0) { //you opened it
-                       while(char c = input.get()){
+                       while(!input.eof()){
+                char c = input.get();
                                if(input.eof())         {       break;                  }
                                else                            {       output << c;    if (c == '\n') {numLines++;} }
                        }