5 * Created by Pat Schloss on 8/14/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
12 #include "globaldata.hpp"
13 #include "mothurout.h"
15 /**************************************************************************************************/
17 GlobalData* GlobalData::_uniqueInstance = 0;
18 CommandFactory* CommandFactory::_uniqueInstance = 0;
19 MothurOut* MothurOut::_uniqueInstance = 0;
21 /***********************************************************************/
22 volatile int ctrlc_pressed = 0;
23 void ctrlc_handler ( int sig ) {
24 MothurOut* m = MothurOut::getInstance();
26 m->control_pressed = ctrlc_pressed;
28 if (m->executing) { //if mid command quit execution, else quit mothur
29 m->mothurOutEndLine(); m->mothurOut("quitting command..."); m->mothurOutEndLine();
31 m->mothurOut("quitting mothur"); m->mothurOutEndLine();
35 /***********************************************************************/
36 int main(int argc, char *argv[]){
37 MothurOut* m = MothurOut::getInstance();
40 signal(SIGINT, ctrlc_handler );
42 time_t ltime = time(NULL); /* calendar time */
43 string logFileName = "mothur." + toString(ltime) + ".logfile";
46 MPI_Init(&argc, &argv);
49 m->setFileName(logFileName);
53 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
55 #if defined (__APPLE__) || (__MACH__)
56 m->mothurOutJustToLog("Mac version");
57 m->mothurOutEndLine(); m->mothurOutEndLine();
59 m->mothurOutJustToLog("Linux version");
60 m->mothurOutEndLine(); m->mothurOutEndLine();
65 m->mothurOutJustToLog("Windows version");
66 m->mothurOutEndLine(); m->mothurOutEndLine();
70 m->mothurOutJustToLog("Using ReadLine");
71 m->mothurOutEndLine(); m->mothurOutEndLine();
75 string temp = MOTHUR_FILES;
76 m->setDefaultPath(temp);
77 m->mothurOutJustToLog("Using default file location " + temp);
78 m->mothurOutEndLine(); m->mothurOutEndLine();
82 m->mothurOutJustToLog("Running 64Bit Version");
83 m->mothurOutEndLine(); m->mothurOutEndLine();
85 m->mothurOutJustToLog("Running 32Bit Version");
86 m->mothurOutEndLine(); m->mothurOutEndLine();
90 m->mothurOut("mothur v.1.11.0");
91 m->mothurOutEndLine();
92 m->mothurOut("Last updated: 6/18/2010");
93 m->mothurOutEndLine();
94 m->mothurOutEndLine();
96 m->mothurOutEndLine();
97 m->mothurOut("Patrick D. Schloss");
98 m->mothurOutEndLine();
99 m->mothurOutEndLine();
100 m->mothurOut("Department of Microbiology & Immunology");
101 m->mothurOutEndLine();
102 m->mothurOut("University of Michigan");
103 m->mothurOutEndLine();
104 m->mothurOut("pschloss@umich.edu");
105 m->mothurOutEndLine();
106 m->mothurOut("http://www.mothur.org");
107 m->mothurOutEndLine();
108 m->mothurOutEndLine();
109 m->mothurOut("When using, please cite:");
110 m->mothurOutEndLine();
111 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.");
112 m->mothurOutEndLine();
113 m->mothurOutEndLine();
114 m->mothurOut("Distributed under the GNU General Public License");
115 m->mothurOutEndLine();
116 m->mothurOutEndLine();
117 m->mothurOut("Type 'help()' for information on the commands that are available");
118 m->mothurOutEndLine();
119 m->mothurOutEndLine();
120 m->mothurOut("Type 'quit()' to exit program");
121 m->mothurOutEndLine();
124 m->mothurOutJustToLog("Using MPI\tversion ");
125 int version, subversion;
126 MPI_Get_version(&version, &subversion);
127 m->mothurOutJustToLog(toString(version) + "." + toString(subversion) + "\n");
131 srand( (unsigned)time( NULL ) );
140 if (input[0] == '#') {
141 m->mothurOutJustToLog("Script Mode");
142 m->mothurOutEndLine(); m->mothurOutEndLine();
144 mothur = new ScriptEngine(argv[0], argv[1]);
146 m->mothurOutJustToLog("Batch Mode");
147 m->mothurOutEndLine(); m->mothurOutEndLine();
149 mothur = new BatchEngine(argv[0], argv[1]);
153 m->mothurOutJustToLog("Interactive Mode");
154 m->mothurOutEndLine(); m->mothurOutEndLine();
156 mothur = new InteractEngine(argv[0]);
159 while(bail == 0) { bail = mothur->getInput(); }
161 //closes logfile so we can rename
164 string outputDir = mothur->getOutputDir();
165 string tempLog = mothur->getLogFileName();
166 bool append = mothur->getAppend();
168 string newlogFileName;
170 newlogFileName = outputDir + tempLog;
173 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
174 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
178 openOutputFileAppend(newlogFileName, outNewLog);
179 outNewLog << endl << endl << "*********************************************************************************" << endl << endl;
182 appendFiles(logFileName, newlogFileName);
183 remove(logFileName.c_str());
186 newlogFileName = outputDir + logFileName;
187 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
188 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
200 catch(exception& e) {
201 m->errorOut(e, "mothur", "main");
206 /**************************************************************************************************/