5 * Created by Pat Schloss on 8/14/08.
\r
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
\r
11 #include "engine.hpp"
\r
12 #include "globaldata.hpp"
\r
13 #include "mothurout.h"
\r
16 /**************************************************************************************************/
\r
18 GlobalData* GlobalData::_uniqueInstance = 0;
\r
19 CommandFactory* CommandFactory::_uniqueInstance = 0;
\r
20 MothurOut* MothurOut::_uniqueInstance = 0;
\r
22 /***********************************************************************/
\r
23 volatile int ctrlc_pressed = 0;
\r
24 void ctrlc_handler ( int sig ) {
\r
25 MothurOut* m = MothurOut::getInstance();
\r
27 m->control_pressed = ctrlc_pressed;
\r
29 if (m->executing) { //if mid command quit execution, else quit mothur
\r
30 m->mothurOutEndLine(); m->mothurOut("quitting command..."); m->mothurOutEndLine();
\r
32 m->mothurOut("quitting mothur"); m->mothurOutEndLine();
\r
36 /***********************************************************************/
\r
37 int main(int argc, char *argv[]){
\r
38 MothurOut* m = MothurOut::getInstance();
\r
41 signal(SIGINT, ctrlc_handler );
\r
43 time_t ltime = time(NULL); /* calendar time */
\r
44 string logFileName = "mothur." + toString(ltime) + ".logfile";
\r
47 MPI_Init(&argc, &argv);
\r
50 m->setFileName(logFileName);
\r
54 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
\r
56 #if defined (__APPLE__) || (__MACH__)
\r
57 m->mothurOutJustToLog("Mac version");
\r
58 m->mothurOutEndLine(); m->mothurOutEndLine();
\r
60 m->mothurOutJustToLog("Linux version");
\r
61 m->mothurOutEndLine(); m->mothurOutEndLine();
\r
66 m->mothurOutJustToLog("Windows version");
\r
67 m->mothurOutEndLine(); m->mothurOutEndLine();
\r
71 m->mothurOutJustToLog("Using ReadLine");
\r
72 m->mothurOutEndLine(); m->mothurOutEndLine();
\r
76 m->mothurOut("mothur v.1.10.2");
\r
77 m->mothurOutEndLine();
\r
78 m->mothurOut("Last updated: 5/26/2010");
\r
79 m->mothurOutEndLine();
\r
80 m->mothurOutEndLine();
\r
82 m->mothurOutEndLine();
\r
83 m->mothurOut("Patrick D. Schloss");
\r
84 m->mothurOutEndLine();
\r
85 m->mothurOutEndLine();
\r
86 m->mothurOut("Department of Microbiology & Immunology");
\r
87 m->mothurOutEndLine();
\r
88 m->mothurOut("University of Michigan");
\r
89 m->mothurOutEndLine();
\r
90 m->mothurOut("pschloss@umich.edu");
\r
91 m->mothurOutEndLine();
\r
92 m->mothurOut("http://www.mothur.org");
\r
93 m->mothurOutEndLine();
\r
94 m->mothurOutEndLine();
\r
95 m->mothurOut("When using, please cite:");
\r
96 m->mothurOutEndLine();
\r
97 m->mothurOut("Schloss, P.D., et al., Introducing mothur: Open-source, platform-independent, community-supported software for describing and comparing microbial communities. Appl Environ Microbiol, 2009. 75(23):7537-41.");
\r
98 m->mothurOutEndLine();
\r
99 m->mothurOutEndLine();
\r
100 m->mothurOut("Distributed under the GNU General Public License");
\r
101 m->mothurOutEndLine();
\r
102 m->mothurOutEndLine();
\r
103 m->mothurOut("Type 'help()' for information on the commands that are available");
\r
104 m->mothurOutEndLine();
\r
105 m->mothurOutEndLine();
\r
106 m->mothurOut("Type 'quit()' to exit program");
\r
107 m->mothurOutEndLine();
\r
110 m->mothurOutJustToLog("Using MPI\tversion ");
\r
111 int version, subversion;
\r
112 MPI_Get_version(&version, &subversion);
\r
113 m->mothurOutJustToLog(toString(version) + "." + toString(subversion) + "\n");
\r
117 srand( (unsigned)time( NULL ) );
\r
126 if (input[0] == '#') {
\r
127 m->mothurOutJustToLog("Script Mode");
\r
128 m->mothurOutEndLine(); m->mothurOutEndLine();
\r
130 mothur = new ScriptEngine(argv[0], argv[1]);
\r
132 m->mothurOutJustToLog("Batch Mode");
\r
133 m->mothurOutEndLine(); m->mothurOutEndLine();
\r
135 mothur = new BatchEngine(argv[0], argv[1]);
\r
139 m->mothurOutJustToLog("Interactive Mode");
\r
140 m->mothurOutEndLine(); m->mothurOutEndLine();
\r
142 mothur = new InteractEngine(argv[0]);
\r
145 while(bail == 0) { bail = mothur->getInput(); }
\r
147 //closes logfile so we can rename
\r
150 string outputDir = mothur->getOutputDir();
\r
151 string tempLog = mothur->getLogFileName();
\r
152 bool append = mothur->getAppend();
\r
154 string newlogFileName;
\r
155 if (tempLog != "") {
\r
156 newlogFileName = outputDir + tempLog;
\r
159 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
\r
160 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
\r
163 ofstream outNewLog;
\r
164 openOutputFileAppend(newlogFileName, outNewLog);
\r
165 outNewLog << endl << endl << "*********************************************************************************" << endl << endl;
\r
168 appendFiles(logFileName, newlogFileName);
\r
169 remove(logFileName.c_str());
\r
172 newlogFileName = outputDir + logFileName;
\r
173 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
\r
174 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
\r
186 catch(exception& e) {
\r
187 m->errorOut(e, "mothur", "main");
\r
192 /**************************************************************************************************/
\r