]> git.donarmstrong.com Git - mothur.git/blob - getlabelcommand.cpp
added checks for ^C to quit command instead of program
[mothur.git] / getlabelcommand.cpp
1 /*
2  *  GetlabelCommand.cpp
3  *  Mothur
4  *
5  *  Created by Thomas Ryabin on 1/30/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "getlabelcommand.h"
11
12 //**********************************************************************************************************************
13
14 GetlabelCommand::GetlabelCommand(string option)  {
15         try {
16                 globaldata = GlobalData::getInstance();
17                 abort = false;
18                 
19                 //allow user to run help
20                 if(option == "help") { help(); abort = true; }
21                 
22                 else {
23                         if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { m->mothurOut("You must read a list, sabund or rabund before you can use the get.label command."); m->mothurOutEndLine(); abort = true; }                         
24                 }
25
26         }
27         catch(exception& e) {
28                 m->errorOut(e, "GetlabelCommand", "GetlabelCommand");
29                 exit(1);
30         }
31 }
32 //**********************************************************************************************************************
33
34 void GetlabelCommand::help(){
35         try {
36                 m->mothurOut("The get.label command can only be executed after a successful read.otu command.\n");
37                 m->mothurOut("You may not use any parameters with the get.label command.\n");
38                 m->mothurOut("The get.label command should be in the following format: \n");
39                 m->mothurOut("get.label()\n");
40                 m->mothurOut("Example get.label().\n");
41         }
42         catch(exception& e) {
43                 m->errorOut(e, "GetlabelCommand", "help");
44                 exit(1);
45         }
46 }
47
48 //**********************************************************************************************************************
49
50 GetlabelCommand::~GetlabelCommand(){
51 }
52
53 //**********************************************************************************************************************
54
55 int GetlabelCommand::execute(){
56         try {
57                 
58                 if (abort == true) { return 0; }
59                 
60                 filename = globaldata->inputFileName;
61                 ifstream in;
62                 openInputFile(filename, in);
63                 string label;
64                 int numBins = 0;
65                 int count = -1;
66                 while(in.good()) {
67                         
68                         if (m->control_pressed) { in.close();  return 0; }
69                         
70                         if(count > numBins)
71                                 count = 0;
72                         if(count == 0) {
73                                 m->mothurOut(label); m->mothurOutEndLine();
74                                 in >> numBins;
75                         }
76                         in >> label;
77                         count++;
78                 }       
79                 
80                 in.close();
81                 return 0;       
82         }
83
84         catch(exception& e) {
85                 m->errorOut(e, "GetlabelCommand", "execute");
86                 exit(1);
87         }
88 }
89