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 CommandFactory* CommandFactory::_uniqueInstance = 0;
18 MothurOut* MothurOut::_uniqueInstance = 0;
20 /***********************************************************************/
21 volatile int ctrlc_pressed = 0;
22 void ctrlc_handler ( int sig ) {
23 MothurOut* m = MothurOut::getInstance();
25 m->control_pressed = ctrlc_pressed;
27 if (m->executing) { //if mid command quit execution, else quit mothur
28 m->mothurOutEndLine(); m->mothurOut("quitting command..."); m->mothurOutEndLine();
30 m->mothurOut("quitting mothur"); m->mothurOutEndLine();
34 /***********************************************************************/
35 int main(int argc, char *argv[]){
36 MothurOut* m = MothurOut::getInstance();
38 signal(SIGINT, ctrlc_handler );
40 time_t ltime = time(NULL); /* calendar time */
41 string logFileName = "mothur." + toString(ltime) + ".logfile";
44 MPI_Init(&argc, &argv);
47 m->setFileName(logFileName);
49 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
56 string temp = MOTHUR_FILES;
58 //add / to name if needed
59 string lastChar = temp.substr(temp.length()-1);
60 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
61 if (lastChar != "/") { temp += "/"; }
63 if (lastChar != "\\") { temp += "\\"; }
66 temp = m->getFullPathName(temp);
67 m->setDefaultPath(temp);
71 int version, subversion;
72 MPI_Get_version(&version, &subversion);
75 //get releaseDate from Make
76 string releaseDate = RELEASE_DATE;
77 string mothurVersion = VERSION;
78 m->setReleaseDate(releaseDate);
79 m->setVersion(mothurVersion);
81 //will make the gui output "pretty"
84 string guiInput = argv[1];
85 if (guiInput[0] == '+') { guiMode = true; }
90 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
91 #if defined (__APPLE__) || (__MACH__)
92 m->mothurOutJustToLog("Mac version");
93 m->mothurOutEndLine(); m->mothurOutEndLine();
95 m->mothurOutJustToLog("Linux version");
96 m->mothurOutEndLine(); m->mothurOutEndLine();
100 m->mothurOutJustToLog("Windows version");
101 m->mothurOutEndLine(); m->mothurOutEndLine();
105 m->mothurOutJustToLog("Using ReadLine");
106 m->mothurOutEndLine(); m->mothurOutEndLine();
110 m->mothurOutJustToLog("Using default file location " + temp);
111 m->mothurOutEndLine(); m->mothurOutEndLine();
115 m->mothurOutJustToLog("Running 64Bit Version");
116 m->mothurOutEndLine(); m->mothurOutEndLine();
118 m->mothurOutJustToLog("Running 32Bit Version");
119 m->mothurOutEndLine(); m->mothurOutEndLine();
123 m->mothurOut("mothur v." + mothurVersion);
124 m->mothurOutEndLine();
125 m->mothurOut("Last updated: " + releaseDate);
126 m->mothurOutEndLine();
127 m->mothurOutEndLine();
129 m->mothurOutEndLine();
130 m->mothurOut("Patrick D. Schloss");
131 m->mothurOutEndLine();
132 m->mothurOutEndLine();
133 m->mothurOut("Department of Microbiology & Immunology");
134 m->mothurOutEndLine();
135 m->mothurOut("University of Michigan");
136 m->mothurOutEndLine();
137 m->mothurOut("pschloss@umich.edu");
138 m->mothurOutEndLine();
139 m->mothurOut("http://www.mothur.org");
140 m->mothurOutEndLine();
141 m->mothurOutEndLine();
142 m->mothurOut("When using, please cite:");
143 m->mothurOutEndLine();
144 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.");
145 m->mothurOutEndLine();
146 m->mothurOutEndLine();
147 m->mothurOut("Distributed under the GNU General Public License");
148 m->mothurOutEndLine();
149 m->mothurOutEndLine();
150 m->mothurOut("Type 'help()' for information on the commands that are available");
151 m->mothurOutEndLine();
152 m->mothurOutEndLine();
153 m->mothurOut("Type 'quit()' to exit program");
154 m->mothurOutEndLine();
157 m->mothurOutJustToLog("Using MPI\tversion ");
158 m->mothurOutJustToLog(toString(version) + "." + toString(subversion) + "\n");
163 srand( (unsigned)time( NULL ) );
171 //m->mothurOut("input = " + input); m->mothurOutEndLine();
173 if (input[0] == '#') {
174 m->mothurOutJustToLog("Script Mode");
175 m->mothurOutEndLine(); m->mothurOutEndLine();
177 mothur = new ScriptEngine(argv[0], argv[1]);
178 }else if (input[0] == '+') {
179 mothur = new ScriptEngine(argv[0], argv[1]);
182 m->mothurOutJustToLog("Batch Mode");
183 m->mothurOutEndLine(); m->mothurOutEndLine();
185 mothur = new BatchEngine(argv[0], argv[1]);
189 m->mothurOutJustToLog("Interactive Mode");
190 m->mothurOutEndLine(); m->mothurOutEndLine();
192 mothur = new InteractEngine(argv[0]);
195 while(bail == 0) { bail = mothur->getInput(); }
197 //closes logfile so we can rename
200 string outputDir = mothur->getOutputDir();
201 string tempLog = mothur->getLogFileName();
202 bool append = mothur->getAppend();
204 string newlogFileName;
206 newlogFileName = outputDir + tempLog;
209 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
210 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
214 m->openOutputFileAppend(newlogFileName, outNewLog);
217 outNewLog << endl << endl << "*********************************************************************************" << endl << endl;
221 m->appendFiles(logFileName, newlogFileName);
222 remove(logFileName.c_str());
225 newlogFileName = outputDir + logFileName;
226 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
227 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
239 catch(exception& e) {
240 m->errorOut(e, "mothur", "main");
245 /**************************************************************************************************/