From: westcott <westcott>
Date: Mon, 1 Mar 2010 11:59:21 +0000 (+0000)
Subject: adding mothurout.h and .cpp to repo
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=182db2b6f1747bc1e0b8cd3eceec8751abdd31d5;p=mothur.git

adding mothurout.h and .cpp to repo
---

diff --git a/aligncommand.cpp b/aligncommand.cpp
index 3b4b6c9..94cba4a 100644
--- a/aligncommand.cpp
+++ b/aligncommand.cpp
@@ -234,7 +234,13 @@ int AlignCommand::execute(){
 				
 				lines.push_back(new linePair(0, numFastaSeqs));
 				
-				driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+				int exitCommand = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+				if (exitCommand == 0) { 
+					remove(accnosFileName.c_str()); 
+					remove(alignFileName.c_str()); 
+					remove(reportFileName.c_str()); 
+					return 0; 
+				}
 				
 				//delete accnos file if its blank else report to user
 				if (isBlank(accnosFileName)) {  remove(accnosFileName.c_str());  hasAccnos = false; }
@@ -274,7 +280,7 @@ int AlignCommand::execute(){
 					lines.push_back(new linePair(startPos, numSeqsPerProcessor));
 				}
 				
-				createProcesses(alignFileName, reportFileName, accnosFileName, candidateFileNames[s]); 
+				int exitCommand = createProcesses(alignFileName, reportFileName, accnosFileName, candidateFileNames[s]); 
 				
 				rename((alignFileName + toString(processIDS[0]) + ".temp").c_str(), alignFileName.c_str());
 				rename((reportFileName + toString(processIDS[0]) + ".temp").c_str(), reportFileName.c_str());
@@ -310,6 +316,13 @@ int AlignCommand::execute(){
 					}else{  m->mothurOut(" If the reverse compliment proved to be better it was reported.");  }
 					m->mothurOutEndLine();
 				}else{ hasAccnos = false;  }
+				
+				if (exitCommand == 0) { 
+					remove(accnosFileName.c_str()); 
+					remove(alignFileName.c_str()); 
+					remove(reportFileName.c_str()); 
+					return 0; 
+				}
 			}
 #else
 			ifstream inFASTA;
@@ -319,7 +332,13 @@ int AlignCommand::execute(){
 			
 			lines.push_back(new linePair(0, numFastaSeqs));
 			
-			driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+			int exitCommand = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+			if (exitCommand == 0) { 
+				remove(accnosFileName.c_str()); 
+				remove(alignFileName.c_str()); 
+				remove(reportFileName.c_str()); 
+				return 0; 
+			}
 			
 			//delete accnos file if its blank else report to user
 			if (isBlank(accnosFileName)) {  remove(accnosFileName.c_str());  hasAccnos = false; }
@@ -374,7 +393,9 @@ int AlignCommand::driver(linePair* line, string alignFName, string reportFName,
 		inFASTA.seekg(line->start);
 		
 		for(int i=0;i<line->numSeqs;i++){
-		
+			
+			if (m->control_pressed) {  return 0; }
+			
 			Sequence* candidateSeq = new Sequence(inFASTA);  gobble(inFASTA);
 			int origNumBases = candidateSeq->getNumBases();
 			string originalUnaligned = candidateSeq->getUnaligned();
@@ -469,10 +490,11 @@ int AlignCommand::driver(linePair* line, string alignFName, string reportFName,
 
 /**************************************************************************************************/
 
-void AlignCommand::createProcesses(string alignFileName, string reportFileName, string accnosFName, string filename) {
+int AlignCommand::createProcesses(string alignFileName, string reportFileName, string accnosFName, string filename) {
 	try {
 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
 		int process = 0;
+		int exitCommand;
 		//		processIDS.resize(0);
 		
 		//loop through and create all the processes you want
@@ -483,7 +505,7 @@ void AlignCommand::createProcesses(string alignFileName, string reportFileName,
 				processIDS.push_back(pid);  //create map from line number to pid so you can append files in correct order later
 				process++;
 			}else if (pid == 0){
-				driver(lines[process], alignFileName + toString(getpid()) + ".temp", reportFileName + toString(getpid()) + ".temp", accnosFName + toString(getpid()) + ".temp", filename);
+				exitCommand = driver(lines[process], alignFileName + toString(getpid()) + ".temp", reportFileName + toString(getpid()) + ".temp", accnosFName + toString(getpid()) + ".temp", filename);
 				exit(0);
 			}else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
 		}
@@ -493,6 +515,8 @@ void AlignCommand::createProcesses(string alignFileName, string reportFileName,
 			int temp = processIDS[i];
 			wait(&temp);
 		}
+		
+		return exitCommand;
 #endif		
 	}
 	catch(exception& e) {
diff --git a/aligncommand.h b/aligncommand.h
index 8042983..f0496a5 100644
--- a/aligncommand.h
+++ b/aligncommand.h
@@ -37,7 +37,7 @@ private:
 	Alignment* alignment;
 	
 	int driver(linePair*, string, string, string, string);
-	void createProcesses(string, string, string, string);
+	int createProcesses(string, string, string, string);
 	void appendAlignFiles(string, string); 
 	void appendReportFiles(string, string);
 	
diff --git a/binsequencecommand.cpp b/binsequencecommand.cpp
index 274a890..1601f32 100644
--- a/binsequencecommand.cpp
+++ b/binsequencecommand.cpp
@@ -181,6 +181,7 @@ int BinSeqCommand::execute(){
 			readNamesFile();
 		}
 		
+		
 		//read list file
 		read = new ReadOTUFile(globaldata->getListFile());	
 		read->read(&*globaldata); 
@@ -189,6 +190,8 @@ int BinSeqCommand::execute(){
 		list = globaldata->gListVector;
 		string lastLabel = list->getLabel();
 		
+		if (m->control_pressed) {  return 0; }
+		
 		//if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
 		set<string> processedLabels;
 		set<string> userLabels = labels;
@@ -199,7 +202,7 @@ int BinSeqCommand::execute(){
 			if(allLines == 1 || labels.count(list->getLabel()) == 1){
 				
 				error = process(list);	
-				if (error == 1) { return 0; }	
+				if (error == 1) { for (int i = 0; i < outputNames.size(); i++) {	remove(outputNames[i].c_str());		} return 0; }	
 							
 				processedLabels.insert(list->getLabel());
 				userLabels.erase(list->getLabel());
@@ -212,7 +215,7 @@ int BinSeqCommand::execute(){
 				list = input->getListVector(lastLabel);
 				
 				error = process(list);	
-				if (error == 1) { return 0; }
+				if (error == 1) { for (int i = 0; i < outputNames.size(); i++) {	remove(outputNames[i].c_str());		} return 0; }
 													
 				processedLabels.insert(list->getLabel());
 				userLabels.erase(list->getLabel());
@@ -247,7 +250,7 @@ int BinSeqCommand::execute(){
 			list = input->getListVector(lastLabel);
 				
 			error = process(list);	
-			if (error == 1) { return 0; }
+			if (error == 1) { for (int i = 0; i < outputNames.size(); i++) {	remove(outputNames[i].c_str());		} return 0; }
 			
 			delete list;  
 		}
@@ -315,7 +318,9 @@ int BinSeqCommand::process(ListVector* list) {
 				
 				//for each bin in the list vector
 				for (int i = 0; i < list->size(); i++) {
-
+					
+					if (m->control_pressed) {  return 1; }
+					
 					binnames = list->get(i);
 					while (binnames.find_first_of(',') != -1) { 
 						name = binnames.substr(0,binnames.find_first_of(','));
@@ -333,7 +338,6 @@ int BinSeqCommand::process(ListVector* list) {
 								string group = groupMap->getGroup(name);
 								if (group == "not found") {  
 									m->mothurOut(name + " is missing from your group file. Please correct. ");  m->mothurOutEndLine();
-									remove(outputFileName.c_str());
 									return 1;
 								}else{
 									name = name + "|" + group + "|" + toString(i+1);
@@ -343,7 +347,6 @@ int BinSeqCommand::process(ListVector* list) {
 							}
 						}else { 
 							m->mothurOut(name + " is missing from your fasta or name file. Please correct. "); m->mothurOutEndLine();
-							remove(outputFileName.c_str());
 							return 1;
 						}
 						
@@ -361,7 +364,6 @@ int BinSeqCommand::process(ListVector* list) {
 							string group = groupMap->getGroup(binnames);
 							if (group == "not found") {  
 								m->mothurOut(binnames + " is missing from your group file. Please correct. "); m->mothurOutEndLine();
-								remove(outputFileName.c_str());
 								return 1;
 							}else{
 								binnames = binnames + "|" + group + "|" + toString(i+1);
@@ -371,7 +373,6 @@ int BinSeqCommand::process(ListVector* list) {
 						}
 					}else { 
 						m->mothurOut(binnames + " is missing from your fasta or name file. Please correct. "); m->mothurOutEndLine();
-						remove(outputFileName.c_str());
 						return 1;
 					}
 				}
diff --git a/bootstrapsharedcommand.cpp b/bootstrapsharedcommand.cpp
index b44ce4b..6b76918 100644
--- a/bootstrapsharedcommand.cpp
+++ b/bootstrapsharedcommand.cpp
@@ -223,7 +223,8 @@ int BootSharedCommand::execute(){
 			if(allLines == 1 || labels.count(order->getLabel()) == 1){			
 				
 				m->mothurOut(order->getLabel()); m->mothurOutEndLine();
-				process(order);
+				int error = process(order);
+				if (error == 1) {  for (int i = 0; i < outputNames.size(); i++) {	remove(outputNames[i].c_str());  } globaldata->Groups.clear(); return 0;	} 
 				
 				processedLabels.insert(order->getLabel());
 				userLabels.erase(order->getLabel());
@@ -236,7 +237,8 @@ int BootSharedCommand::execute(){
 				delete order;
 				order = input->getSharedOrderVector(lastLabel);													
 				m->mothurOut(order->getLabel()); m->mothurOutEndLine();
-				process(order);
+				int error = process(order);
+				if (error == 1) {  for (int i = 0; i < outputNames.size(); i++) {	remove(outputNames[i].c_str());  } globaldata->Groups.clear(); return 0;	} 
 
 				processedLabels.insert(order->getLabel());
 				userLabels.erase(order->getLabel());
@@ -271,7 +273,9 @@ int BootSharedCommand::execute(){
 				if (order != NULL) {	delete order;	}
 				order = input->getSharedOrderVector(lastLabel);													
 				m->mothurOut(order->getLabel()); m->mothurOutEndLine();
-				process(order);
+				int error = process(order);
+				if (error == 1) {  for (int i = 0; i < outputNames.size(); i++) {	remove(outputNames[i].c_str());  } globaldata->Groups.clear(); return 0;	} 
+				
 				delete order;
 
 		}
@@ -294,13 +298,15 @@ int BootSharedCommand::execute(){
 }
 //**********************************************************************************************************************
 
-void BootSharedCommand::createTree(ostream* out, Tree* t){
+int BootSharedCommand::createTree(ostream* out, Tree* t){
 	try {
 		
 		//do merges and create tree structure by setting parents and children
 		//there are numGroups - 1 merges to do
 		for (int i = 0; i < (numGroups - 1); i++) {
 		
+			if (m->control_pressed) {  return 1; }
+		
 			float largest = -1000.0;
 			int row, column;
 			//find largest value in sims matrix by searching lower triangle
@@ -357,6 +363,8 @@ void BootSharedCommand::createTree(ostream* out, Tree* t){
 	
 		//print newick file
 		t->print(*out);
+		
+		return 0;
 	
 	}
 	catch(exception& e) {
@@ -382,7 +390,7 @@ void BootSharedCommand::printSims() {
 	}
 }
 /***********************************************************/
-void BootSharedCommand::process(SharedOrderVector* order) {
+int BootSharedCommand::process(SharedOrderVector* order) {
 	try{
 				EstOutput data;
 				vector<SharedRAbundVector*> subset;
@@ -400,18 +408,22 @@ void BootSharedCommand::process(SharedOrderVector* order) {
 				//create a file for each calculator with the 1000 trees in it.
 				for (int p = 0; p < iters; p++) {
 					
+					if (m->control_pressed) {  return 1; }
+					
 					util->getSharedVectorswithReplacement(globaldata->Groups, lookup, order);  //fills group vectors from order vector.
 
 				
 					//for each calculator												
 					for(int i = 0 ; i < treeCalculators.size(); i++) {
-					
+						
+						if (m->control_pressed) {  return 1; }
+						
 						//initialize simMatrix
 						simMatrix.clear();
 						simMatrix.resize(numGroups);
-						for (int m = 0; m < simMatrix.size(); m++)	{
+						for (int o = 0; o < simMatrix.size(); o++)	{
 							for (int j = 0; j < simMatrix.size(); j++)	{
-								simMatrix[m].push_back(0.0);
+								simMatrix[o].push_back(0.0);
 							}
 						}
 				
@@ -437,6 +449,8 @@ void BootSharedCommand::process(SharedOrderVector* order) {
 						
 						tempTree = new Tree();
 						
+						if (m->control_pressed) {   delete tempTree; return 1; }
+						
 						//creates tree from similarity matrix and write out file
 						createTree(out[i], tempTree);
 						
@@ -456,6 +470,8 @@ void BootSharedCommand::process(SharedOrderVector* order) {
 					
 					m->mothurOut("Generating consensus tree for " + treeCalculators[k]->getName()); m->mothurOutEndLine();
 					
+					if (m->control_pressed) {  return 1; }
+					
 					//set global data to calc trees
 					globaldata->gTree = trees[k];
 					
@@ -477,6 +493,8 @@ void BootSharedCommand::process(SharedOrderVector* order) {
 					
 				//close ostream for each calc
 				for (int z = 0; z < treeCalculators.size(); z++) { out[z]->close(); }
+				
+				return 0;
 	
 	}
 	catch(exception& e) {
diff --git a/bootstrapsharedcommand.h b/bootstrapsharedcommand.h
index aa0c325..be4a764 100644
--- a/bootstrapsharedcommand.h
+++ b/bootstrapsharedcommand.h
@@ -32,9 +32,9 @@ public:
 	void help();
 	
 private:
-	void createTree(ostream*, Tree*);
+	int createTree(ostream*, Tree*);
 	void printSims();
-	void process(SharedOrderVector*);
+	int process(SharedOrderVector*);
 	
 	
 	GlobalData* globaldata;
diff --git a/clustercommand.cpp b/clustercommand.cpp
index 5d9c7bc..7484a62 100644
--- a/clustercommand.cpp
+++ b/clustercommand.cpp
@@ -154,6 +154,17 @@ int ClusterCommand::execute(){
 		double saveCutoff = cutoff;
 		
 		while (matrix->getSmallDist() < cutoff && matrix->getNNodes() > 0){
+		
+			if (m->control_pressed) { //clean up
+				delete globaldata->gSparseMatrix;  globaldata->gSparseMatrix = NULL;
+				delete globaldata->gListVector;	 globaldata->gListVector = NULL;
+				if (globaldata->getFormat() == "phylip") { globaldata->setPhylipFile(""); }
+				else if (globaldata->getFormat() == "column") { globaldata->setColumnFile(""); }
+				sabundFile.close();rabundFile.close();listFile.close();
+				for (int i = 0; i < outputNames.size(); i++) {	remove(outputNames[i].c_str()); 	}
+				return 0;
+			}
+		
 			if (print_start && isTrue(timing)) {
 				m->mothurOut("Clustering (" + tag + ") dist " + toString(matrix->getSmallDist()) + "/" 
 					+ toString(roundDist(matrix->getSmallDist(), precision)) 
diff --git a/collect.cpp b/collect.cpp
index 08426a8..62ed9f2 100644
--- a/collect.cpp
+++ b/collect.cpp
@@ -11,7 +11,7 @@
 
 /***********************************************************************/
 
-void Collect::getCurve(int increment = 1){
+int Collect::getCurve(int increment = 1){
         try {
                 RAbundVector* lookup = new RAbundVector(order->getNumBins());
                 SAbundVector* rank        = new SAbundVector(order->getMaxRank()+1);
@@ -23,7 +23,9 @@ void Collect::getCurve(int increment = 1){
                         displays[i]->init(label);                   //sets displays label
                 }                                                                           
                 for(int i=0;i<numSeqs;i++){
-
+						
+						if (m->control_pressed) { delete lookup; delete rank; delete ccd;  return 1;  }
+						
                         int binNumber = order->get(i);
                         int abundance = lookup->get(binNumber);
                 
@@ -50,6 +52,8 @@ void Collect::getCurve(int increment = 1){
 				delete lookup;
 				delete rank;
 				delete ccd;
+				
+				return 0;
         }
         catch(exception& e) {
 			m->errorOut(e, "Collect", "getCurve");
@@ -58,7 +62,7 @@ void Collect::getCurve(int increment = 1){
 }
 
 /***********************************************************************/
-void Collect::getSharedCurve(int increment = 1){
+int Collect::getSharedCurve(int increment = 1){
 try {
                 globaldata = GlobalData::getInstance();
                 vector<SharedRAbundVector*> lookup; 
@@ -94,6 +98,9 @@ try {
                 
                 //sample all the members
                 for(int i=0;i<numSeqs;i++){
+				
+						if (m->control_pressed) { for (int j = 0; j < lookup.size(); j++) {  delete lookup[j]; } delete ccd;  return 1;  }
+						
                         //get first sample
                         individual chosen = sharedorder->get(i);
                         int abundance; 
@@ -155,6 +162,8 @@ try {
 				for (int i = 0; i < lookup.size(); i++) {
 					delete lookup[i];
 				}
+				
+				return 0;
 
         }
         catch(exception& e) {
diff --git a/collect.h b/collect.h
index 0db1504..879755f 100644
--- a/collect.h
+++ b/collect.h
@@ -22,8 +22,8 @@ public:
 					numSeqs(sharedorder->getNumSeqs()), sharedorder(sharedorder), displays(disp), label(sharedorder->getLabel())  { m = MothurOut::getInstance(); }
 
 	~Collect(){		};
-	void getCurve(int);
-	void getSharedCurve(int);
+	int getCurve(int);
+	int getSharedCurve(int);
 	
 private:
 	SharedOrderVector* sharedorder;
diff --git a/collectcommand.cpp b/collectcommand.cpp
index d8da50e..9bf2c9a 100644
--- a/collectcommand.cpp
+++ b/collectcommand.cpp
@@ -140,7 +140,9 @@ int CollectCommand::execute(){
 		else {  inputFileNames = parseSharedFile(globaldata->getSharedFile());  globaldata->setFormat("rabund");  }
 	
 		for (int p = 0; p < inputFileNames.size(); p++) {
-		
+			
+			if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {	remove(outputNames[i].c_str()); 	}  globaldata->Groups.clear(); return 0; }
+			
 			if (outputDir == "") { outputDir += hasPath(inputFileNames[p]); }
 			string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p]));
 			globaldata->inputFileName = inputFileNames[p];
@@ -230,15 +232,38 @@ int CollectCommand::execute(){
 			//if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
 			set<string> processedLabels;
 			set<string> userLabels = labels;
+			
+			if (m->control_pressed) {  
+				for (int i = 0; i < outputNames.size(); i++) {	remove(outputNames[i].c_str()); 	}  
+				for(int i=0;i<cDisplays.size();i++){	delete cDisplays[i];	}
+				delete input;  globaldata->ginput = NULL;
+				delete read;
+				delete order; globaldata->gorder = NULL;
+				delete validCalculator;
+				globaldata->Groups.clear();
+				return 0;
+			}
+
 
 			while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
 				
 				if(allLines == 1 || labels.count(order->getLabel()) == 1){
 					
 					cCurve = new Collect(order, cDisplays);
-					cCurve->getCurve(freq);
+					int error = cCurve->getCurve(freq);
 					delete cCurve;
 					
+					if (error == 1) {
+						for (int i = 0; i < outputNames.size(); i++) {	remove(outputNames[i].c_str()); 	}  
+						for(int i=0;i<cDisplays.size();i++){	delete cDisplays[i];	}
+						delete input;  globaldata->ginput = NULL;
+						delete read;
+						delete order; globaldata->gorder = NULL;
+						delete validCalculator;
+						globaldata->Groups.clear();
+						return 0;
+					}
+					
 					m->mothurOut(order->getLabel()); m->mothurOutEndLine();
 					processedLabels.insert(order->getLabel());
 					userLabels.erase(order->getLabel());
@@ -253,9 +278,20 @@ int CollectCommand::execute(){
 					order = (input->getOrderVector(lastLabel));
 					
 					cCurve = new Collect(order, cDisplays);
-					cCurve->getCurve(freq);
+					int error = cCurve->getCurve(freq);
 					delete cCurve;
 					
+					if (error == 1) {
+						for (int i = 0; i < outputNames.size(); i++) {	remove(outputNames[i].c_str()); 	}  
+						for(int i=0;i<cDisplays.size();i++){	delete cDisplays[i];	}
+						delete input;  globaldata->ginput = NULL;
+						delete read;
+						delete order; globaldata->gorder = NULL;
+						delete validCalculator;
+						globaldata->Groups.clear();
+						return 0;
+					}
+					
 					m->mothurOut(order->getLabel()); m->mothurOutEndLine();
 					processedLabels.insert(order->getLabel());
 					userLabels.erase(order->getLabel());
@@ -291,8 +327,19 @@ int CollectCommand::execute(){
 				m->mothurOut(order->getLabel()); m->mothurOutEndLine();
 				
 				cCurve = new Collect(order, cDisplays);
-				cCurve->getCurve(freq);
+				int error = cCurve->getCurve(freq);
 				delete cCurve;
+				
+				if (error == 1) {
+					for (int i = 0; i < outputNames.size(); i++) {	remove(outputNames[i].c_str()); 	}  
+					for(int i=0;i<cDisplays.size();i++){	delete cDisplays[i];	}
+					delete input;  globaldata->ginput = NULL;
+					delete read;
+					delete order; globaldata->gorder = NULL;
+					delete validCalculator;
+					globaldata->Groups.clear();
+					return 0;
+				}
 				delete order;
 			}
 			
diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp
index 0c937f6..201709e 100644
--- a/collectsharedcommand.cpp
+++ b/collectsharedcommand.cpp
@@ -266,8 +266,19 @@ int CollectSharedCommand::execute(){
 				
 				//create collectors curve
 				cCurve = new Collect(order, cDisplays);
-				cCurve->getSharedCurve(freq);
+				int error = cCurve->getSharedCurve(freq);
 				delete cCurve;
+				
+				if (error == 1) {
+					for (int i = 0; i < outputNames.size(); i++) {	remove(outputNames[i].c_str()); 	}  
+					for(int i=0;i<cDisplays.size();i++){	delete cDisplays[i];	}
+					delete input;  globaldata->ginput = NULL;
+					delete read;
+					delete order; globaldata->gorder = NULL;
+					delete validCalculator;
+					globaldata->Groups.clear();
+					return 0;
+				}
 			
 				m->mothurOut(order->getLabel()); m->mothurOutEndLine();
 				processedLabels.insert(order->getLabel());
@@ -283,8 +294,20 @@ int CollectSharedCommand::execute(){
 				
 				//create collectors curve
 				cCurve = new Collect(order, cDisplays);
-				cCurve->getSharedCurve(freq);
+				int error = cCurve->getSharedCurve(freq);
 				delete cCurve;
+				
+				if (error == 1) {
+					for (int i = 0; i < outputNames.size(); i++) {	remove(outputNames[i].c_str()); 	}  
+					for(int i=0;i<cDisplays.size();i++){	delete cDisplays[i];	}
+					delete input;  globaldata->ginput = NULL;
+					delete read;
+					delete order; globaldata->gorder = NULL;
+					delete validCalculator;
+					globaldata->Groups.clear();
+					return 0;
+				}
+
 			
 				m->mothurOut(order->getLabel()); m->mothurOutEndLine();
 				processedLabels.insert(order->getLabel());
@@ -321,9 +344,21 @@ int CollectSharedCommand::execute(){
 			order = input->getSharedOrderVector(lastLabel);
 
 			cCurve = new Collect(order, cDisplays);
-			cCurve->getSharedCurve(freq);
+			int error = cCurve->getSharedCurve(freq);
 			delete cCurve;
 			
+			if (error == 1) {
+				for (int i = 0; i < outputNames.size(); i++) {	remove(outputNames[i].c_str()); 	}  
+				for(int i=0;i<cDisplays.size();i++){	delete cDisplays[i];	}
+				delete input;  globaldata->ginput = NULL;
+				delete read;
+				delete order; globaldata->gorder = NULL;
+				delete validCalculator;
+				globaldata->Groups.clear();
+				return 0;
+			}
+
+			
 			m->mothurOut(order->getLabel()); m->mothurOutEndLine();
 			delete order;
 		}
diff --git a/engine.cpp b/engine.cpp
index fdd017a..5e9ac5f 100644
--- a/engine.cpp
+++ b/engine.cpp
@@ -69,6 +69,7 @@ bool InteractEngine::getInput(){
 				//executes valid command
 				Command* command = cFactory->getCommand(commandName, options);
 				quitCommandCalled = command->execute();
+				mout->control_pressed = 0;
 				
 			}else {
 				mout->mothurOut("Your input contains errors. Please try again."); 
@@ -183,6 +184,7 @@ bool BatchEngine::getInput(){
 					//executes valid command
 					Command* command = cFactory->getCommand(commandName, options);
 					quitCommandCalled = command->execute();
+					mout->control_pressed = 0;
 				}else {		
 					mout->mothurOut("Invalid."); 
 					mout->mothurOutEndLine();
@@ -262,6 +264,7 @@ bool ScriptEngine::getInput(){
 				//executes valid command
 				Command* command = cFactory->getCommand(commandName, options);
 				quitCommandCalled = command->execute();
+				mout->control_pressed = 0;
 			}else {		
 				mout->mothurOut("Invalid."); 
 				mout->mothurOutEndLine();
diff --git a/mothur.cpp b/mothur.cpp
index ba058ba..7cd77a1 100644
--- a/mothur.cpp
+++ b/mothur.cpp
@@ -18,13 +18,20 @@ GlobalData* GlobalData::_uniqueInstance = 0;
 CommandFactory* CommandFactory::_uniqueInstance = 0;
 MothurOut* MothurOut::_uniqueInstance = 0;
 
+/***********************************************************************/
+volatile int ctrlc_pressed = 0;
+void ctrlc_handler ( int sig ) {
+	MothurOut* m = MothurOut::getInstance();
+    ctrlc_pressed = 1;
+	m->control_pressed = ctrlc_pressed;
+}
+/***********************************************************************/
 int main(int argc, char *argv[]){
 	MothurOut* m = MothurOut::getInstance();
 	try {
 		
-		//string log = "mothur.logFile";
-		//remove(log.c_str());
-		
+		signal(SIGINT, ctrlc_handler );
+				
 		time_t ltime = time(NULL); /* calendar time */  
 		string logFileName = "mothur." + toString(ltime) + ".logfile";
 		
diff --git a/mothur.h b/mothur.h
index db11ed1..26fd775 100644
--- a/mothur.h
+++ b/mothur.h
@@ -193,7 +193,6 @@ string toString(const T&x, int i){
     return output.str();
 }
 /***********************************************************************/
-
 inline int openOutputFileAppend(string fileName, ofstream& fileHandle){
 	
 	fileHandle.open(fileName.c_str(), ios::app);
diff --git a/mothurout.cpp b/mothurout.cpp
new file mode 100644
index 0000000..0f4faed
--- /dev/null
+++ b/mothurout.cpp
@@ -0,0 +1,88 @@
+/*
+ *  m->mothurOut.cpp
+ *  Mothur
+ *
+ *  Created by westcott on 2/25/10.
+ *  Copyright 2010 Schloss Lab. All rights reserved.
+ *
+ */
+
+#include "mothurout.h"
+
+/******************************************************/
+MothurOut* MothurOut::getInstance() {
+	if( _uniqueInstance == 0) {
+		_uniqueInstance = new MothurOut();
+	}
+	return _uniqueInstance;
+}
+/*********************************************************************************************/
+void MothurOut::setFileName(string filename)  {
+	try {
+		logFileName = filename;
+		openOutputFile(filename, out);
+	}
+	catch(exception& e) {
+		errorOut(e, "MothurOut", "setFileName");
+		exit(1);
+	}
+}
+/*********************************************************************************************/
+MothurOut::~MothurOut() {
+	try {
+		_uniqueInstance = 0;
+		out.close();
+	}
+	catch(exception& e) {
+		errorOut(e, "MothurOut", "MothurOut");
+		exit(1);
+	}
+}
+
+/*********************************************************************************************/
+void MothurOut::mothurOut(string output) {
+	try {
+	
+		cout << output;
+		out << output;
+		
+	}
+	catch(exception& e) {
+		errorOut(e, "MothurOut", "MothurOut");
+		exit(1);
+	}
+}
+/*********************************************************************************************/
+void MothurOut::mothurOutEndLine() {
+	try {
+		cout << endl;
+		out << endl;
+	}
+	catch(exception& e) {
+		errorOut(e, "MothurOut", "MothurOutEndLine");
+		exit(1);
+	}
+}
+/*********************************************************************************************/
+void MothurOut::mothurOutJustToLog(string output) {
+	try {
+		out << output;
+	}
+	catch(exception& e) {
+		errorOut(e, "MothurOut", "MothurOutJustToLog");
+		exit(1);
+	}
+}
+/*********************************************************************************************/
+void MothurOut::errorOut(exception& e, string object, string function) {
+	mothurOut("Error: ");
+	mothurOut(toString(e.what()));
+	mothurOut(" has occurred in the " + object + " class function " + function + ". Please contact Pat Schloss at mothur.bugs@gmail.com, and be sure to include the mothur.logFile with your inquiry.");
+	mothurOutEndLine();
+}
+/*********************************************************************************************/
+
+
+
+
+
diff --git a/mothurout.h b/mothurout.h
new file mode 100644
index 0000000..ac1ec3f
--- /dev/null
+++ b/mothurout.h
@@ -0,0 +1,44 @@
+#ifndef MOTHUROUT_H
+#define MOTHUROUT_H
+
+/*
+ *  m->mothurOut.h
+ *  Mothur
+ *
+ *  Created by westcott on 2/25/10.
+ *  Copyright 2010 Schloss Lab. All rights reserved.
+ *
+ */
+
+#include "mothur.h"
+
+/***********************************************/
+
+class MothurOut {
+	
+	public:
+		static MothurOut* getInstance();
+		void setFileName(string);
+		
+		void mothurOut(string);
+		void mothurOutEndLine();
+		void mothurOutJustToLog(string);
+		void errorOut(exception&, string, string);
+		int control_pressed;
+		
+
+	private:
+		static MothurOut* _uniqueInstance;
+		MothurOut( const MothurOut& ); // Disable copy constructor
+		void operator=( const MothurOut& ); // Disable assignment operator
+		MothurOut() {};
+		~MothurOut();
+
+		string logFileName;
+		ofstream out;
+
+};
+/***********************************************/
+
+#endif
+