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;
77 //add / to name if needed
78 string lastChar = temp.substr(temp.length()-1);
79 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
80 if (lastChar != "/") { temp += "/"; }
82 if (lastChar != "\\") { temp += "\\"; }
85 temp = getFullPathName(temp);
86 m->setDefaultPath(temp);
88 m->mothurOutJustToLog("Using default file location " + temp);
89 m->mothurOutEndLine(); m->mothurOutEndLine();
93 m->mothurOutJustToLog("Running 64Bit Version");
94 m->mothurOutEndLine(); m->mothurOutEndLine();
96 m->mothurOutJustToLog("Running 32Bit Version");
97 m->mothurOutEndLine(); m->mothurOutEndLine();
100 //get releaseDate from Make
101 string releaseDate = RELEASE_DATE;
102 string mothurVersion = VERSION;
103 m->setReleaseDate(releaseDate);
104 m->setVersion(mothurVersion);
107 m->mothurOut("mothur v." + mothurVersion);
108 m->mothurOutEndLine();
109 m->mothurOut("Last updated: " + releaseDate);
110 m->mothurOutEndLine();
111 m->mothurOutEndLine();
113 m->mothurOutEndLine();
114 m->mothurOut("Patrick D. Schloss");
115 m->mothurOutEndLine();
116 m->mothurOutEndLine();
117 m->mothurOut("Department of Microbiology & Immunology");
118 m->mothurOutEndLine();
119 m->mothurOut("University of Michigan");
120 m->mothurOutEndLine();
121 m->mothurOut("pschloss@umich.edu");
122 m->mothurOutEndLine();
123 m->mothurOut("http://www.mothur.org");
124 m->mothurOutEndLine();
125 m->mothurOutEndLine();
126 m->mothurOut("When using, please cite:");
127 m->mothurOutEndLine();
128 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.");
129 m->mothurOutEndLine();
130 m->mothurOutEndLine();
131 m->mothurOut("Distributed under the GNU General Public License");
132 m->mothurOutEndLine();
133 m->mothurOutEndLine();
134 m->mothurOut("Type 'help()' for information on the commands that are available");
135 m->mothurOutEndLine();
136 m->mothurOutEndLine();
137 m->mothurOut("Type 'quit()' to exit program");
138 m->mothurOutEndLine();
141 m->mothurOutJustToLog("Using MPI\tversion ");
142 int version, subversion;
143 MPI_Get_version(&version, &subversion);
144 m->mothurOutJustToLog(toString(version) + "." + toString(subversion) + "\n");
148 srand( (unsigned)time( NULL ) );
157 if (input[0] == '#') {
158 m->mothurOutJustToLog("Script Mode");
159 m->mothurOutEndLine(); m->mothurOutEndLine();
161 mothur = new ScriptEngine(argv[0], argv[1]);
163 m->mothurOutJustToLog("Batch Mode");
164 m->mothurOutEndLine(); m->mothurOutEndLine();
166 mothur = new BatchEngine(argv[0], argv[1]);
170 m->mothurOutJustToLog("Interactive Mode");
171 m->mothurOutEndLine(); m->mothurOutEndLine();
173 mothur = new InteractEngine(argv[0]);
176 while(bail == 0) { bail = mothur->getInput(); }
178 //closes logfile so we can rename
181 string outputDir = mothur->getOutputDir();
182 string tempLog = mothur->getLogFileName();
183 bool append = mothur->getAppend();
185 string newlogFileName;
187 newlogFileName = outputDir + tempLog;
190 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
191 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
195 openOutputFileAppend(newlogFileName, outNewLog);
196 outNewLog << endl << endl << "*********************************************************************************" << endl << endl;
199 appendFiles(logFileName, newlogFileName);
200 remove(logFileName.c_str());
203 newlogFileName = outputDir + logFileName;
204 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
205 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
217 catch(exception& e) {
218 m->errorOut(e, "mothur", "main");
223 /**************************************************************************************************/