X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=getlinecommand.cpp;h=f1ec55cab12261a5b91f425553bf34bc71393727;hb=4ba6188707e67c638ea5ee3c787d5d07ccd07e3e;hp=09b16541930d34f795bba4ca182ed74b9054d8fc;hpb=51cf89e90eef8b300c2786eb1560dd89e6e83445;p=mothur.git diff --git a/getlinecommand.cpp b/getlinecommand.cpp index 09b1654..f1ec55c 100644 --- a/getlinecommand.cpp +++ b/getlinecommand.cpp @@ -9,20 +9,41 @@ #include "getlinecommand.h" - -GetlineCommand::GetlineCommand(){ +//********************************************************************************************************************** +GetlineCommand::GetlineCommand(string option){ try { globaldata = GlobalData::getInstance(); + abort = false; + + //allow user to run help + if(option == "help") { help(); abort = true; } + + else { + if (option != "") { mothurOut("There are no valid parameters for the get.line command."); mothurOutEndLine(); abort = true; } + + if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { mothurOut("You must read a list, sabund or rabund before you can use the get.line command."); mothurOutEndLine(); abort = true; } + } + } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the GetlineCommand class Function GetlineCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "GetlineCommand", "GetlineCommand"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the GetlineCommand class function GetlineCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; +} +//********************************************************************************************************************** + +void GetlineCommand::help(){ + try { + mothurOut("The get.line command can only be executed after a successful read.otu command.\n"); + mothurOut("You may not use any parameters with the get.line command.\n"); + mothurOut("The get.line command should be in the following format: \n"); + mothurOut("get.line()\n"); + mothurOut("Example get.line().\n"); + } + catch(exception& e) { + errorOut(e, "GetlineCommand", "help"); exit(1); - } - + } } //********************************************************************************************************************** @@ -34,37 +55,35 @@ GetlineCommand::~GetlineCommand(){ int GetlineCommand::execute(){ try { - filename = globaldata->inputFileName; + + if (abort == true) { return 0; } + ifstream in; - openInputFile(filename, in); + openInputFile(globaldata->inputFileName, in); string label; int numBins = 0; int count = -1; int line = 1; - while(in.good()) - { + while(in.good()) { if(count > numBins) count = 0; - if(count == 0) - { - cout << line << "\n"; + if(count == 0) { + mothurOut(toString(line)); mothurOutEndLine(); in >> numBins; line++; } in >> label; count++; } + + in.close(); return 0; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the GetlineCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "GetlineCommand", "execute"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the GetlineCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } }