]> git.donarmstrong.com Git - mothur.git/blobdiff - fileoutput.cpp
precluster command finished
[mothur.git] / fileoutput.cpp
index 9c1f9c0f0c61fe3b27d84f699482d8708ad1e660..004ed8313511c2dd42d4b87aca93c0ad5750bce5 100644 (file)
@@ -16,7 +16,7 @@ ThreeColumnFile::~ThreeColumnFile(){
        inFile.close();
        outFile.close();
        remove(outName.c_str());
-};
+}
 
 /***********************************************************************/
 
@@ -27,7 +27,7 @@ void ThreeColumnFile::initFile(string label){
                        openInputFile(inName, inFile);
 
                        string inputBuffer;
-                       getline(inFile, inputBuffer);
+                       inputBuffer = getline(inFile);
                
                        outFile <<  inputBuffer << '\t' << label << "\tlci\thci" << endl;
                }
@@ -40,11 +40,7 @@ void ThreeColumnFile::initFile(string label){
                outFile.setf(ios::showpoint);
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the ThreeColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "ThreeColumnFile", "initFile");
                exit(1);
        }
 }
@@ -55,7 +51,7 @@ void ThreeColumnFile::output(int nSeqs, vector<double> data){
        try {
                if(counter != 0){               
                        string inputBuffer;
-                       getline(inFile, inputBuffer);
+                       inputBuffer = getline(inFile);
                
                        outFile <<  inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
                }
@@ -64,14 +60,10 @@ void ThreeColumnFile::output(int nSeqs, vector<double> data){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "ThreeColumnFile", "output");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the ThreeColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-};
+}
 
 /***********************************************************************/
 
@@ -90,17 +82,15 @@ void ThreeColumnFile::resetFile(){
                renameOk = rename(outName.c_str(), inName.c_str());
                
                //checks to make sure user was able to rename and remove successfully
-               if ((renameOk != 0)) {  cout << "Unable to rename necessary files." << endl;  cout << outName << "  g   " << inName << endl;}
-
+               if ((renameOk != 0)) { 
+                       mothurOut("Unable to rename " + outName); mothurOutEndLine();
+                       perror(" : ");
+               }       
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "ThreeColumnFile", "resetFile");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the ThreeColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 /***********************************************************************/
@@ -111,7 +101,7 @@ ColumnFile::~ColumnFile(){
        inFile.close();
        outFile.close();
        remove(outName.c_str());
-};
+}
 
 /***********************************************************************/
 
@@ -122,7 +112,7 @@ void ColumnFile::initFile(string label, vector<string> tags){
                        openInputFile(inName, inFile);
 
                        string inputBuffer;
-                       getline(inFile, inputBuffer);
+                       inputBuffer = getline(inFile);
                
                        outFile <<  inputBuffer << '\t'; 
                        for(int i = 0; i < tags.size(); i++) {
@@ -142,11 +132,7 @@ void ColumnFile::initFile(string label, vector<string> tags){
                outFile.setf(ios::showpoint);
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the ColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "ColumnFile", "initFile");
                exit(1);
        }
 }
@@ -158,16 +144,16 @@ void ColumnFile::output(vector<double> data){
        
                if(counter != 0){               
                        string inputBuffer;
-                       getline(inFile, inputBuffer);
+                       inputBuffer = getline(inFile);
 
-                       outFile << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(globaldata->getIters().length());
+                       outFile << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(iters.length());
                        for (int i = 1; i< data.size(); i++) {
                                outFile << '\t' << data[i]; 
                        }
                        outFile << endl;
                }
                else{
-                       outFile << setprecision(6) << data[0] << setprecision(globaldata->getIters().length());
+                       outFile << setprecision(6) << data[0] << setprecision(iters.length());
                        for (int i = 1; i< data.size(); i++) {
                                outFile << '\t' << data[i]; 
                        }
@@ -176,14 +162,10 @@ void ColumnFile::output(vector<double> data){
 
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "ColumnFile", "output");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the ColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-};
+}
 
 /***********************************************************************/
 
@@ -202,17 +184,15 @@ void ColumnFile::resetFile(){
                renameOk = rename(outName.c_str(), inName.c_str());
                
                //checks to make sure user was able to rename and remove successfully
-               if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
-
+               if ((renameOk != 0)) { 
+                       mothurOut("Unable to rename " + outName); mothurOutEndLine();
+                       perror(" : ");
+               }       
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "ColumnFile", "resetFile");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the ColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 /***********************************************************************/
@@ -223,7 +203,7 @@ SharedThreeColumnFile::~SharedThreeColumnFile(){
        inFile.close();
        outFile.close();
        remove(outName.c_str());
-};
+}
 
 /***********************************************************************/
 
@@ -234,7 +214,7 @@ void SharedThreeColumnFile::initFile(string label){
                        openInputFile(inName, inFile);
 
                        string inputBuffer;
-                       getline(inFile, inputBuffer);
+                       inputBuffer = getline(inFile);
                
                        outFile <<  inputBuffer << '\t' << label << "\tlci\thci" << endl;
                }
@@ -247,11 +227,7 @@ void SharedThreeColumnFile::initFile(string label){
                outFile.setf(ios::showpoint);
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the SharedThreeColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "SharedThreeColumnFile", "initFile");
                exit(1);
        }
 }
@@ -262,7 +238,7 @@ void SharedThreeColumnFile::output(int nSeqs, vector<double> data){
        try {
                if(counter != 0){               
                        string inputBuffer;
-                       getline(inFile, inputBuffer);
+                       inputBuffer = getline(inFile);
                
                        outFile <<  inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
                }
@@ -272,14 +248,10 @@ void SharedThreeColumnFile::output(int nSeqs, vector<double> data){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the SharedThreeColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "SharedThreeColumnFile", "output");
                exit(1);
        }
-};
+}
 
 /***********************************************************************/
 
@@ -297,17 +269,15 @@ void SharedThreeColumnFile::resetFile(){
                renameOk = rename(outName.c_str(), inName.c_str());
                
                //checks to make sure user was able to rename and remove successfully
-               if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
-
+               if ((renameOk != 0)) { 
+                       mothurOut("Unable to rename " + outName); mothurOutEndLine();
+                       perror(" : ");
+               }       
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "SharedThreeColumnFile", "resetFile");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the SharedThreeColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 /***********************************************************************/
@@ -319,7 +289,7 @@ OneColumnFile::~OneColumnFile(){
        inFile.close();
        outFile.close();
        remove(outName.c_str());        
-};
+}
 
 /***********************************************************************/
 
@@ -330,7 +300,7 @@ void OneColumnFile::initFile(string label){
                        openInputFile(inName, inFile);
                
                        string inputBuffer;
-                       getline(inFile, inputBuffer);
+                       inputBuffer = getline(inFile);
                
                        outFile <<  inputBuffer << '\t' << label << endl;
                }
@@ -343,13 +313,9 @@ void OneColumnFile::initFile(string label){
                outFile.setf(ios::showpoint);
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "OneColumnFile", "initFile");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the OneColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 /***********************************************************************/
@@ -358,7 +324,7 @@ void OneColumnFile::output(int nSeqs, vector<double> data){
        try {   
                if(counter != 0){               
                        string inputBuffer;
-                       getline(inFile, inputBuffer);
+                       inputBuffer = getline(inFile);
                
                        outFile <<  inputBuffer << setprecision(4) << '\t'  << data[0] << endl;
                }
@@ -367,14 +333,10 @@ void OneColumnFile::output(int nSeqs, vector<double> data){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "OneColumnFile", "output");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the OneColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
-};
+}
 
 /***********************************************************************/
 
@@ -392,17 +354,15 @@ void OneColumnFile::resetFile(){
                renameOk = rename(outName.c_str(), inName.c_str());
                
                //checks to make sure user was able to rename and remove successfully
-               if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
-
+               if ((renameOk != 0)) { 
+                       mothurOut("Unable to rename " + outName); mothurOutEndLine();
+                       perror(" : ");
+               }       
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "OneColumnFile", "resetFile");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the OneColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 /***********************************************************************/
@@ -413,7 +373,7 @@ SharedOneColumnFile::~SharedOneColumnFile(){
        inFile.close();
        outFile.close();
        remove(outName.c_str());        
-};
+}
 
 /***********************************************************************/
 
@@ -424,7 +384,7 @@ void SharedOneColumnFile::initFile(string label){
                        openInputFile(inName, inFile);
                
                        string inputBuffer;
-                       getline(inFile, inputBuffer);
+                       inputBuffer = getline(inFile);
                
                        outFile <<  inputBuffer << '\t' << label  << endl;
 
@@ -439,13 +399,9 @@ void SharedOneColumnFile::initFile(string label){
                outFile.setf(ios::showpoint);
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "SharedOneColumnFile", "initFile");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the OneColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 /***********************************************************************/
@@ -461,7 +417,7 @@ void SharedOneColumnFile::output(int nSeqs, vector<double> data){
                        }
                        if(counter != 0){               
                                string inputBuffer;
-                               getline(inFile, inputBuffer);
+                               inputBuffer = getline(inFile);
 
                                outFile <<  inputBuffer << setprecision(2) << '\t' << dataOutput << endl;
                        }
@@ -470,14 +426,10 @@ void SharedOneColumnFile::output(int nSeqs, vector<double> data){
                        }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "SharedOneColumnFile", "output");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the OneColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
-};
+}
 
 /***********************************************************************/
 
@@ -491,23 +443,21 @@ void SharedOneColumnFile::resetFile(){
                        outFile.close();
                }       
                counter = 1;
-               
+
                remove(inName.c_str());
+
                renameOk = rename(outName.c_str(), inName.c_str());
                
                //checks to make sure user was able to rename and remove successfully
-               if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
-
-               
+               if ((renameOk != 0)) { 
+                       mothurOut("Unable to rename " + outName); mothurOutEndLine();
+                       perror(" : ");
+               }       
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "SharedOneColumnFile", "resetFile");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the OneColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 /***********************************************************************/