5 * Created by Pat Schloss on 8/14/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
12 #include "mothurout.h"
14 /**************************************************************************************************/
16 CommandFactory* CommandFactory::_uniqueInstance = 0;
17 MothurOut* MothurOut::_uniqueInstance = 0;
19 /***********************************************************************/
20 volatile int ctrlc_pressed = 0;
21 void ctrlc_handler ( int sig ) {
22 MothurOut* m = MothurOut::getInstance();
24 m->control_pressed = ctrlc_pressed;
26 if (m->executing) { //if mid command quit execution, else quit mothur
27 m->mothurOutEndLine(); m->mothurOut("quitting command..."); m->mothurOutEndLine();
29 m->mothurOut("quitting mothur"); m->mothurOutEndLine();
33 /***********************************************************************/
34 int main(int argc, char *argv[]){
35 MothurOut* m = MothurOut::getInstance();
37 signal(SIGINT, ctrlc_handler );
39 time_t ltime = time(NULL); /* calendar time */
40 string logFileName = "mothur." + toString(ltime) + ".logfile";
43 MPI_Init(&argc, &argv);
46 m->setFileName(logFileName);
48 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
55 string temp = MOTHUR_FILES;
57 //add / to name if needed
58 string lastChar = temp.substr(temp.length()-1);
59 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
60 if (lastChar != "/") { temp += "/"; }
62 if (lastChar != "\\") { temp += "\\"; }
65 temp = m->getFullPathName(temp);
66 m->setDefaultPath(temp);
70 int version, subversion;
71 MPI_Get_version(&version, &subversion);
74 //get releaseDate from Make
75 string releaseDate = RELEASE_DATE;
76 string mothurVersion = VERSION;
77 m->setReleaseDate(releaseDate);
78 m->setVersion(mothurVersion);
80 //will make the gui output "pretty"
83 string guiInput = argv[1];
84 if (guiInput[0] == '+') { guiMode = true; }
89 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
90 #if defined (__APPLE__) || (__MACH__)
91 m->mothurOutJustToLog("Mac version");
92 m->mothurOutEndLine(); m->mothurOutEndLine();
94 m->mothurOutJustToLog("Linux version");
95 m->mothurOutEndLine(); m->mothurOutEndLine();
99 m->mothurOutJustToLog("Windows version");
100 m->mothurOutEndLine(); m->mothurOutEndLine();
104 m->mothurOutJustToLog("Using ReadLine");
105 m->mothurOutEndLine(); m->mothurOutEndLine();
109 m->mothurOutJustToLog("Using default file location " + temp);
110 m->mothurOutEndLine(); m->mothurOutEndLine();
114 m->mothurOutJustToLog("Running 64Bit Version");
115 m->mothurOutEndLine(); m->mothurOutEndLine();
117 m->mothurOutJustToLog("Running 32Bit Version");
118 m->mothurOutEndLine(); m->mothurOutEndLine();
122 m->mothurOut("mothur v." + mothurVersion);
123 m->mothurOutEndLine();
124 m->mothurOut("Last updated: " + releaseDate);
125 m->mothurOutEndLine();
126 m->mothurOutEndLine();
128 m->mothurOutEndLine();
129 m->mothurOut("Patrick D. Schloss");
130 m->mothurOutEndLine();
131 m->mothurOutEndLine();
132 m->mothurOut("Department of Microbiology & Immunology");
133 m->mothurOutEndLine();
134 m->mothurOut("University of Michigan");
135 m->mothurOutEndLine();
136 m->mothurOut("pschloss@umich.edu");
137 m->mothurOutEndLine();
138 m->mothurOut("http://www.mothur.org");
139 m->mothurOutEndLine();
140 m->mothurOutEndLine();
141 m->mothurOut("When using, please cite:");
142 m->mothurOutEndLine();
143 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.");
144 m->mothurOutEndLine();
145 m->mothurOutEndLine();
146 m->mothurOut("Distributed under the GNU General Public License");
147 m->mothurOutEndLine();
148 m->mothurOutEndLine();
149 m->mothurOut("Type 'help()' for information on the commands that are available");
150 m->mothurOutEndLine();
151 m->mothurOutEndLine();
152 m->mothurOut("Type 'quit()' to exit program");
153 m->mothurOutEndLine();
156 m->mothurOutJustToLog("Using MPI\tversion ");
157 m->mothurOutJustToLog(toString(version) + "." + toString(subversion) + "\n");
162 srand( (unsigned)time( NULL ) );
170 //m->mothurOut("input = " + input); m->mothurOutEndLine();
172 if (input[0] == '#') {
173 m->mothurOutJustToLog("Script Mode");
174 m->mothurOutEndLine(); m->mothurOutEndLine();
176 mothur = new ScriptEngine(argv[0], argv[1]);
177 }else if (input[0] == '+') {
178 mothur = new ScriptEngine(argv[0], argv[1]);
181 m->mothurOutJustToLog("Batch Mode");
182 m->mothurOutEndLine(); m->mothurOutEndLine();
184 mothur = new BatchEngine(argv[0], argv[1]);
188 m->mothurOutJustToLog("Interactive Mode");
189 m->mothurOutEndLine(); m->mothurOutEndLine();
191 mothur = new InteractEngine(argv[0]);
194 while(bail == 0) { bail = mothur->getInput(); }
196 //closes logfile so we can rename
199 string outputDir = mothur->getOutputDir();
200 string tempLog = mothur->getLogFileName();
201 bool append = mothur->getAppend();
203 string newlogFileName;
205 newlogFileName = outputDir + tempLog;
208 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
209 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
213 m->openOutputFileAppend(newlogFileName, outNewLog);
216 outNewLog << endl << endl << "*********************************************************************************" << endl << endl;
222 m->appendFiles(logFileName, newlogFileName);
223 remove(logFileName.c_str());
226 newlogFileName = outputDir + logFileName;
227 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
228 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
240 catch(exception& e) {
241 m->errorOut(e, "mothur", "main");
246 /**************************************************************************************************/