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();
39 signal(SIGINT, ctrlc_handler );
41 time_t ltime = time(NULL); /* calendar time */
42 string logFileName = "mothur." + toString(ltime) + ".logfile";
45 MPI_Init(&argc, &argv);
48 m->setFileName(logFileName);
52 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
54 #if defined (__APPLE__) || (__MACH__)
55 m->mothurOutJustToLog("Mac version");
56 m->mothurOutEndLine(); m->mothurOutEndLine();
58 m->mothurOutJustToLog("Linux version");
59 m->mothurOutEndLine(); m->mothurOutEndLine();
64 m->mothurOutJustToLog("Windows version");
65 m->mothurOutEndLine(); m->mothurOutEndLine();
69 m->mothurOutJustToLog("Using ReadLine");
70 m->mothurOutEndLine(); m->mothurOutEndLine();
74 string temp = MOTHUR_FILES;
76 //add / to name if needed
77 string lastChar = temp.substr(temp.length()-1);
78 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
79 if (lastChar != "/") { temp += "/"; }
81 if (lastChar != "\\") { temp += "\\"; }
84 temp = m->getFullPathName(temp);
85 m->setDefaultPath(temp);
87 m->mothurOutJustToLog("Using default file location " + temp);
88 m->mothurOutEndLine(); m->mothurOutEndLine();
92 m->mothurOutJustToLog("Running 64Bit Version");
93 m->mothurOutEndLine(); m->mothurOutEndLine();
95 m->mothurOutJustToLog("Running 32Bit Version");
96 m->mothurOutEndLine(); m->mothurOutEndLine();
99 //get releaseDate from Make
100 string releaseDate = RELEASE_DATE;
101 string mothurVersion = VERSION;
102 m->setReleaseDate(releaseDate);
103 m->setVersion(mothurVersion);
106 m->mothurOut("mothur v." + mothurVersion);
107 m->mothurOutEndLine();
108 m->mothurOut("Last updated: " + releaseDate);
109 m->mothurOutEndLine();
110 m->mothurOutEndLine();
112 m->mothurOutEndLine();
113 m->mothurOut("Patrick D. Schloss");
114 m->mothurOutEndLine();
115 m->mothurOutEndLine();
116 m->mothurOut("Department of Microbiology & Immunology");
117 m->mothurOutEndLine();
118 m->mothurOut("University of Michigan");
119 m->mothurOutEndLine();
120 m->mothurOut("pschloss@umich.edu");
121 m->mothurOutEndLine();
122 m->mothurOut("http://www.mothur.org");
123 m->mothurOutEndLine();
124 m->mothurOutEndLine();
125 m->mothurOut("When using, please cite:");
126 m->mothurOutEndLine();
127 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.");
128 m->mothurOutEndLine();
129 m->mothurOutEndLine();
130 m->mothurOut("Distributed under the GNU General Public License");
131 m->mothurOutEndLine();
132 m->mothurOutEndLine();
133 m->mothurOut("Type 'help()' for information on the commands that are available");
134 m->mothurOutEndLine();
135 m->mothurOutEndLine();
136 m->mothurOut("Type 'quit()' to exit program");
137 m->mothurOutEndLine();
140 m->mothurOutJustToLog("Using MPI\tversion ");
141 int version, subversion;
142 MPI_Get_version(&version, &subversion);
143 m->mothurOutJustToLog(toString(version) + "." + toString(subversion) + "\n");
147 srand( (unsigned)time( NULL ) );
156 if (input[0] == '#') {
157 m->mothurOutJustToLog("Script Mode");
158 m->mothurOutEndLine(); m->mothurOutEndLine();
160 mothur = new ScriptEngine(argv[0], argv[1]);
162 m->mothurOutJustToLog("Batch Mode");
163 m->mothurOutEndLine(); m->mothurOutEndLine();
165 mothur = new BatchEngine(argv[0], argv[1]);
169 m->mothurOutJustToLog("Interactive Mode");
170 m->mothurOutEndLine(); m->mothurOutEndLine();
172 mothur = new InteractEngine(argv[0]);
175 while(bail == 0) { bail = mothur->getInput(); }
177 //closes logfile so we can rename
180 string outputDir = mothur->getOutputDir();
181 string tempLog = mothur->getLogFileName();
182 bool append = mothur->getAppend();
184 string newlogFileName;
186 newlogFileName = outputDir + tempLog;
189 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
190 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
194 m->openOutputFileAppend(newlogFileName, outNewLog);
195 outNewLog << endl << endl << "*********************************************************************************" << endl << endl;
198 m->appendFiles(logFileName, newlogFileName);
199 remove(logFileName.c_str());
202 newlogFileName = outputDir + logFileName;
203 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
204 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
216 catch(exception& e) {
217 m->errorOut(e, "mothur", "main");
222 /**************************************************************************************************/