]> git.donarmstrong.com Git - mothur.git/blobdiff - fileoutput.cpp
a few modifications for 1.9
[mothur.git] / fileoutput.cpp
index 63130a83ba6c850bc8db4ea720ba51a15d80ff81..117f8ab1c3a9a93c5f80f38613c4aefa1c898e32 100644 (file)
@@ -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,7 +40,7 @@ void ThreeColumnFile::initFile(string label){
                outFile.setf(ios::showpoint);
        }
        catch(exception& e) {
-               errorOut(e, "ThreeColumnFile", "initFile");
+               m->errorOut(e, "ThreeColumnFile", "initFile");
                exit(1);
        }
 }
@@ -51,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;
                }
@@ -60,7 +60,7 @@ void ThreeColumnFile::output(int nSeqs, vector<double> data){
                }
        }
        catch(exception& e) {
-               errorOut(e, "ThreeColumnFile", "output");
+               m->errorOut(e, "ThreeColumnFile", "output");
                exit(1);
        }
 }
@@ -81,12 +81,16 @@ void ThreeColumnFile::resetFile(){
                remove(inName.c_str());
                renameOk = rename(outName.c_str(), inName.c_str());
                
+               //renameFile(outName, inName);
+               
                //checks to make sure user was able to rename and remove successfully
-               if ((renameOk != 0)) {  mothurOut("Unable to rename necessary files."); mothurOutEndLine(); }
-
+               if ((renameOk != 0)) { 
+                       m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine();
+                       perror(" : ");
+               }       
        }
        catch(exception& e) {
-               errorOut(e, "ThreeColumnFile", "resetFile");
+               m->errorOut(e, "ThreeColumnFile", "resetFile");
                exit(1);
        }
 }
@@ -110,7 +114,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++) {
@@ -130,7 +134,7 @@ void ColumnFile::initFile(string label, vector<string> tags){
                outFile.setf(ios::showpoint);
        }
        catch(exception& e) {
-               errorOut(e, "ColumnFile", "initFile");
+               m->errorOut(e, "ColumnFile", "initFile");
                exit(1);
        }
 }
@@ -142,7 +146,7 @@ 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(iters.length());
                        for (int i = 1; i< data.size(); i++) {
@@ -160,7 +164,7 @@ void ColumnFile::output(vector<double> data){
 
        }
        catch(exception& e) {
-               errorOut(e, "ColumnFile", "output");
+               m->errorOut(e, "ColumnFile", "output");
                exit(1);
        }
 }
@@ -181,12 +185,16 @@ void ColumnFile::resetFile(){
                remove(inName.c_str());
                renameOk = rename(outName.c_str(), inName.c_str());
                
+               //renameFile(outName, inName);
+               
                //checks to make sure user was able to rename and remove successfully
-               if ((renameOk != 0)) { mothurOut("Unable to rename necessary files."); mothurOutEndLine(); }
-
+               if ((renameOk != 0)) { 
+                       m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine();
+                       perror(" : ");
+               }       
        }
        catch(exception& e) {
-               errorOut(e, "ColumnFile", "resetFile");
+               m->errorOut(e, "ColumnFile", "resetFile");
                exit(1);
        }
 }
@@ -210,7 +218,7 @@ void SharedThreeColumnFile::initFile(string label){
                        openInputFile(inName, inFile);
 
                        string inputBuffer;
-                       getline(inFile, inputBuffer);
+                       inputBuffer = getline(inFile);
                
                        outFile <<  inputBuffer << '\t' << label << "\tlci\thci" << endl;
                }
@@ -223,7 +231,7 @@ void SharedThreeColumnFile::initFile(string label){
                outFile.setf(ios::showpoint);
        }
        catch(exception& e) {
-               errorOut(e, "SharedThreeColumnFile", "initFile");
+               m->errorOut(e, "SharedThreeColumnFile", "initFile");
                exit(1);
        }
 }
@@ -234,7 +242,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;
                }
@@ -244,7 +252,7 @@ void SharedThreeColumnFile::output(int nSeqs, vector<double> data){
                }
        }
        catch(exception& e) {
-               errorOut(e, "SharedThreeColumnFile", "output");
+               m->errorOut(e, "SharedThreeColumnFile", "output");
                exit(1);
        }
 }
@@ -261,15 +269,20 @@ void SharedThreeColumnFile::resetFile(){
                        outFile.close();
                }
                counter = 1;
+               
                remove(inName.c_str());
                renameOk = rename(outName.c_str(), inName.c_str());
                
+               //renameFile(outName, inName);
+               
                //checks to make sure user was able to rename and remove successfully
-               if ((renameOk != 0)) { mothurOut("Unable to rename necessary files."); mothurOutEndLine(); }
-
+               if ((renameOk != 0)) { 
+                       m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine();
+                       perror(" : ");
+               }       
        }
        catch(exception& e) {
-               errorOut(e, "SharedThreeColumnFile", "resetFile");
+               m->errorOut(e, "SharedThreeColumnFile", "resetFile");
                exit(1);
        }
 }
@@ -294,20 +307,20 @@ void OneColumnFile::initFile(string label){
                        openInputFile(inName, inFile);
                
                        string inputBuffer;
-                       getline(inFile, inputBuffer);
+                       inputBuffer = getline(inFile);
                
                        outFile <<  inputBuffer << '\t' << label << endl;
                }
                else{
                        openOutputFile(outName, outFile);
-                       outFile << "numsequences\t" << label << endl;
+                       outFile << "numsampled\t" << label << endl;
                }
        
                outFile.setf(ios::fixed, ios::floatfield);
                outFile.setf(ios::showpoint);
        }
        catch(exception& e) {
-               errorOut(e, "OneColumnFile", "initFile");
+               m->errorOut(e, "OneColumnFile", "initFile");
                exit(1);
        }
 }
@@ -318,7 +331,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;
                }
@@ -327,7 +340,7 @@ void OneColumnFile::output(int nSeqs, vector<double> data){
                }
        }
        catch(exception& e) {
-               errorOut(e, "OneColumnFile", "output");
+               m->errorOut(e, "OneColumnFile", "output");
                exit(1);
        }
 }
@@ -339,20 +352,25 @@ void OneColumnFile::resetFile(){
                if(counter != 0){
                        outFile.close();
                        inFile.close();
-               }
-               else{
+               }else{
                        outFile.close();
                }       
                counter = 1;
+               
                remove(inName.c_str());
                renameOk = rename(outName.c_str(), inName.c_str());
                
+               //renameFile(outName, inName);
+               
                //checks to make sure user was able to rename and remove successfully
-               if ((renameOk != 0)) { mothurOut("Unable to rename necessary files."); mothurOutEndLine(); }
+               if ((renameOk != 0)) { 
+                       m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine();
+                       perror(" : ");
+               }       
 
        }
        catch(exception& e) {
-               errorOut(e, "OneColumnFile", "resetFile");
+               m->errorOut(e, "OneColumnFile", "resetFile");
                exit(1);
        }
 }
@@ -376,7 +394,7 @@ void SharedOneColumnFile::initFile(string label){
                        openInputFile(inName, inFile);
                
                        string inputBuffer;
-                       getline(inFile, inputBuffer);
+                       inputBuffer = getline(inFile);
                
                        outFile <<  inputBuffer << '\t' << label  << endl;
 
@@ -391,7 +409,7 @@ void SharedOneColumnFile::initFile(string label){
                outFile.setf(ios::showpoint);
        }
        catch(exception& e) {
-               errorOut(e, "SharedOneColumnFile", "initFile");
+               m->errorOut(e, "SharedOneColumnFile", "initFile");
                exit(1);
        }
 }
@@ -409,7 +427,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;
                        }
@@ -418,7 +436,7 @@ void SharedOneColumnFile::output(int nSeqs, vector<double> data){
                        }
        }
        catch(exception& e) {
-               errorOut(e, "SharedOneColumnFile", "output");
+               m->errorOut(e, "SharedOneColumnFile", "output");
                exit(1);
        }
 }
@@ -435,17 +453,20 @@ 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)) { mothurOut("Unable to rename necessary files."); mothurOutEndLine(); }
-
+               //renameFile(outName, inName);
                
+               //checks to make sure user was able to rename and remove successfully
+               if ((renameOk != 0)) { 
+                       m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine();
+                       perror(" : ");
+               }       
        }
        catch(exception& e) {
-               errorOut(e, "SharedOneColumnFile", "resetFile");
+               m->errorOut(e, "SharedOneColumnFile", "resetFile");
                exit(1);
        }
 }