]> git.donarmstrong.com Git - mothur.git/blobdiff - mergefilecommand.cpp
test
[mothur.git] / mergefilecommand.cpp
index 497d535e4810fac221b6ae399d59a7b1ff457d46..d5973394e5a097e879bf1526689d137266a417c1 100644 (file)
@@ -21,7 +21,7 @@ MergeFileCommand::MergeFileCommand(string option){
                }
                else {
                        //valid paramters for this command
-                       string Array[] =  {"input", "output"};
+                       string Array[] =  {"input", "output","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -34,36 +34,47 @@ MergeFileCommand::MergeFileCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       
                        string fileList = validParameter.validFile(parameters, "input", false);                 
-                       if(fileList == "not found") { cout << "you must enter two or more file names" << endl;  abort=true;  }
+                       if(fileList == "not found") { mothurOut("you must enter two or more file names"); mothurOutEndLine();  abort=true;  }
                        else{   splitAtDash(fileList, fileNames);       }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       string outputDir = validParameter.validFile(parameters, "outputdir", false);            if (outputDir == "not found")   {       outputDir = "";         }
+                       
+                       
                        numInputFiles = fileNames.size();
                        ifstream testFile;
                        if(numInputFiles == 0){
-                               cout << "you must enter two or more file names and you entered " << fileNames.size() <<  " file names" << endl;
+                               mothurOut("you must enter two or more file names and you entered " + toString(fileNames.size()) +  " file names"); mothurOutEndLine();
                                abort=true;  
                        }
                        else{
                                for(int i=0;i<numInputFiles;i++){
+                                       if (inputDir != "") {
+                                               string path = hasPath(fileNames[i]);
+                                               //if the user has not given a path then, add inputdir. else leave path alone.
+                                               if (path == "") {       fileNames[i] = inputDir + fileNames[i];         }
+                                       }
+                                       
                                        if(openInputFile(fileNames[i], testFile)){      abort = true;   }
                                        testFile.close();
                                }
                        }   
                        
                        outputFileName = validParameter.validFile(parameters, "output", false);                 
-                       if (outputFileName == "not found") { cout << "you must enter an output file name" << endl;  abort=true;  }
+                       if (outputFileName == "not found") { mothurOut("you must enter an output file name"); mothurOutEndLine();  abort=true;  }
+                       else if (outputDir != "") { outputFileName = outputDir + getSimpleName(outputFileName); }
                }
                        
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the MergeFileCommand class Function MergeFileCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "MergeFileCommand", "MergeFileCommand");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the MergeFileCommand class function MergeFileCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 //**********************************************************************************************************************
@@ -79,9 +90,10 @@ int MergeFileCommand::execute(){
                ofstream outputFile;
                openOutputFile(outputFileName, outputFile);
                
-               ifstream inputFile;
                char c;
                for(int i=0;i<numInputFiles;i++){
+                       ifstream inputFile; //declaration must be inside for loop of windows throws an error
+                       
                        openInputFile(fileNames[i], inputFile);
                        
                        while(!inputFile.eof()){        c = inputFile.get(); outputFile << c;   }
@@ -93,31 +105,21 @@ int MergeFileCommand::execute(){
                return 0;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the BinSeqCommand class Function BinSeqCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "MergeFileCommand", "execute");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the BinSeqCommand class function BinSeqCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
-       
 }
 
 //**********************************************************************************************************************
 
 void MergeFileCommand::help(){
        try {
-               cout << "The merge.file command..." << endl;
+               mothurOut("The merge.file command..."); mothurOutEndLine();
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the MergeFileCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "MergeFileCommand", "help");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the MergeFileCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
-       
 }
 
 //**********************************************************************************************************************