5 * Created by Pat Schloss on 6/14/09.
6 * Copyright 2009 Patrick D. Schloss. All rights reserved.
10 #include "mergefilecommand.h"
12 //**********************************************************************************************************************
14 MergeFileCommand::MergeFileCommand(string option){
18 if(option == "help") {
23 //valid paramters for this command
24 string Array[] = {"input", "output"};
25 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
27 OptionParser parser(option);
28 map<string,string> parameters = parser.getParameters();
30 ValidParameters validParameter;
32 //check to make sure all parameters are valid for command
33 for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
34 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
37 string fileList = validParameter.validFile(parameters, "input", false);
38 if(fileList == "not found") { mothurOut("you must enter two or more file names"); mothurOutEndLine(); abort=true; }
39 else{ splitAtDash(fileList, fileNames); }
41 numInputFiles = fileNames.size();
43 if(numInputFiles == 0){
44 mothurOut("you must enter two or more file names and you entered " + toString(fileNames.size()) + " file names"); mothurOutEndLine();
48 for(int i=0;i<numInputFiles;i++){
49 if(openInputFile(fileNames[i], testFile)){ abort = true; }
54 outputFileName = validParameter.validFile(parameters, "output", false);
55 if (outputFileName == "not found") { mothurOut("you must enter an output file name"); mothurOutEndLine(); abort=true; }
60 errorOut(e, "MergeFileCommand", "MergeFileCommand");
65 //**********************************************************************************************************************
67 MergeFileCommand::~MergeFileCommand() { /* do nothing */ }
69 //**********************************************************************************************************************
71 int MergeFileCommand::execute(){
73 if (abort == true) { return 0; }
76 openOutputFile(outputFileName, outputFile);
79 for(int i=0;i<numInputFiles;i++){
80 ifstream inputFile; //declaration must be inside for loop of windows throws an error
82 openInputFile(fileNames[i], inputFile);
84 while(!inputFile.eof()){ c = inputFile.get(); outputFile << c; }
93 errorOut(e, "MergeFileCommand", "execute");
98 //**********************************************************************************************************************
100 void MergeFileCommand::help(){
102 mothurOut("The merge.file command..."); mothurOutEndLine();
104 catch(exception& e) {
105 errorOut(e, "MergeFileCommand", "help");
110 //**********************************************************************************************************************