]> git.donarmstrong.com Git - mothur.git/blobdiff - summarycommand.cpp
version working on mac with .tellg changed to unget for windows
[mothur.git] / summarycommand.cpp
index 009c278cd618d03c08f06bbd2f9c240e9390dac4..ee4ba9f760c656f84cbe13da9ed6da0cccb73e60 100644 (file)
@@ -48,14 +48,14 @@ SummaryCommand::SummaryCommand(string option){
                        string Array[] =  {"line","label","calc","abund","size"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
                        
-                       ValidParameters* validParameter = new ValidParameters();
-               
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -63,14 +63,14 @@ SummaryCommand::SummaryCommand(string option){
                        
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -86,7 +86,7 @@ SummaryCommand::SummaryCommand(string option){
                                lines = globaldata->lines;
                        }
                                
-                       calc = validParameter->validFile(parameters, "calc", false);                    
+                       calc = validParameter.validFile(parameters, "calc", false);                     
                        if (calc == "not found") { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson";  }
                        else { 
                                 if (calc == "default")  {  calc = "sobs-chao-ace-jack-shannon-npshannon-simpson";  }
@@ -94,14 +94,12 @@ SummaryCommand::SummaryCommand(string option){
                        splitAtDash(calc, Estimators);
 
                        string temp;
-                       temp = validParameter->validFile(parameters, "abund", false);           if (temp == "not found") { temp = "10"; }
+                       temp = validParameter.validFile(parameters, "abund", false);            if (temp == "not found") { temp = "10"; }
                        convert(temp, abund); 
                        
-                       temp = validParameter->validFile(parameters, "size", false);                    if (temp == "not found") { temp = "0"; }
+                       temp = validParameter.validFile(parameters, "size", false);                     if (temp == "not found") { temp = "0"; }
                        convert(temp, size); 
        
-                       delete validParameter;
-                       
                        if (abort == false) {
                        
                                validCalculator = new ValidCalculators();
@@ -196,10 +194,12 @@ void SummaryCommand::help(){
 //**********************************************************************************************************************
 
 SummaryCommand::~SummaryCommand(){
-       delete sabund;
-       delete input;
-       delete read;
-       delete validCalculator;
+       if (abort == false) {
+               delete input;  globaldata->ginput = NULL;
+               delete read;
+               delete validCalculator;
+               globaldata->sabund = NULL;
+       }
 }
 
 //**********************************************************************************************************************
@@ -274,7 +274,7 @@ int SummaryCommand::execute(){
                                outputFileHandle << endl;
                        }               
 
-                       if (count != 1) { delete lastSAbund; }
+                       if (count != 1) { delete lastSAbund;  }
                        lastSAbund = sabund;                    
 
                        sabund = input->getSAbundVector();
@@ -306,6 +306,8 @@ int SummaryCommand::execute(){
                        outputFileHandle << endl;
                }
                
+               outputFileHandle.close();
+               
                delete lastSAbund;
                return 0;
        }