]> git.donarmstrong.com Git - mothur.git/blobdiff - mothurout.cpp
1.21.0
[mothur.git] / mothurout.cpp
index a56a6217a8c136e1fcb9f3f3078c5418547220fa..367f5d12fc0555833061fb3d3dcabb4581006e64 100644 (file)
@@ -562,6 +562,21 @@ string MothurOut::getSimpleName(string longName){
 
 /***********************************************************************/
 
+int MothurOut::getRandomIndex(int highest){
+       try {
+               
+               int random = (int) ((float)(highest+1) * (float)(rand()) / ((float)RAND_MAX+1.0));
+               
+               return random;
+       }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "getRandomIndex");
+               exit(1);
+       }       
+       
+}
+/**********************************************************************/
+
 string MothurOut::getPathName(string longName){
        try {
                string rootPathName = longName;
@@ -796,7 +811,7 @@ int MothurOut::openInputFile(string fileName, ifstream& fileHandle, string m){
           cerr << "Decompressing " << completeFileName << " via temporary named pipe " << tempName << "\n";
           system(command.c_str());
           cerr << "Done decompressing " << completeFileName << "\n";
-          remove(tempName.c_str());
+          mothurRemove(tempName);
           exit(EXIT_SUCCESS);
         } else {
           cerr << "waiting on child process " << fork_result << "\n";
@@ -842,7 +857,7 @@ int MothurOut::openInputFile(string fileName, ifstream& fileHandle){
       cerr << "Decompressing " << completeFileName << " via temporary named pipe " << tempName << "\n";
       system(command.c_str());
       cerr << "Done decompressing " << completeFileName << "\n";
-      remove(tempName.c_str());
+      mothurRemove(tempName);
       exit(EXIT_SUCCESS);
     } else {
       cerr << "waiting on child process " << fork_result << "\n";
@@ -887,7 +902,7 @@ int MothurOut::renameFile(string oldName, string newName){
                string command = "mv " + oldName + " " + newName;
                system(command.c_str());
        #else
-               remove(newName.c_str());
+               m->mothurRemove(newName);
                int renameOk = rename(oldName.c_str(), newName.c_str());
        #endif
                return 0;
@@ -1023,8 +1038,8 @@ string MothurOut::sortFile(string distFile, string outputDir){
                        output.close();
                
                        //remove temp files
-                       remove(tempDistFile.c_str());
-                       remove(tempOutfile.c_str());
+                       mothurRemove(tempDistFile);
+                       mothurRemove(tempOutfile);
                #endif
                
                return outfile;
@@ -1392,7 +1407,18 @@ int MothurOut::getNumNames(string names){
                exit(1);
        }
 }
+/***********************************************************************/
 
+void MothurOut::mothurRemove(string filename){
+       try {
+               filename = getFullPathName(filename);
+               remove(filename.c_str());
+       }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "mothurRemove");
+               exit(1);
+       }
+}
 /**************************************************************************************************/
 
 vector<vector<double> > MothurOut::binomial(int maxOrder){