]> git.donarmstrong.com Git - mothur.git/blob - mothurout.cpp
some changes while testing 1.9
[mothur.git] / mothurout.cpp
1 /*\r
2  *  m->mothurOut.cpp\r
3  *  Mothur\r
4  *\r
5  *  Created by westcott on 2/25/10.\r
6  *  Copyright 2010 Schloss Lab. All rights reserved.\r
7  *\r
8  */\r
9 \r
10 #include "mothurout.h"\r
11 \r
12 /******************************************************/\r
13 MothurOut* MothurOut::getInstance() {\r
14         if( _uniqueInstance == 0) {\r
15                 _uniqueInstance = new MothurOut();\r
16         }\r
17         return _uniqueInstance;\r
18 }\r
19 /*********************************************************************************************/\r
20 void MothurOut::setFileName(string filename)  {\r
21         try {\r
22                 logFileName = filename;\r
23                 \r
24                 #ifdef USE_MPI\r
25                         int pid;\r
26                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); \r
27                                         \r
28                         if (pid == 0) { //only one process should output to screen\r
29                 #endif\r
30                 \r
31                 openOutputFile(filename, out);\r
32                 \r
33                 #ifdef USE_MPI\r
34                         }\r
35                 #endif\r
36         }\r
37         catch(exception& e) {\r
38                 errorOut(e, "MothurOut", "setFileName");\r
39                 exit(1);\r
40         }\r
41 }\r
42 /*********************************************************************************************/\r
43 void MothurOut::closeLog()  {\r
44         try {\r
45                 \r
46                 #ifdef USE_MPI\r
47                         int pid;\r
48                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); \r
49                                         \r
50                         if (pid == 0) { //only one process should output to screen\r
51                 #endif\r
52                 \r
53                 out.close();\r
54                 \r
55                 #ifdef USE_MPI\r
56                         }\r
57                 #endif\r
58         }\r
59         catch(exception& e) {\r
60                 errorOut(e, "MothurOut", "closeLog");\r
61                 exit(1);\r
62         }\r
63 }\r
64 \r
65 /*********************************************************************************************/\r
66 MothurOut::~MothurOut() {\r
67         try {\r
68                 _uniqueInstance = 0;\r
69                 \r
70         }\r
71         catch(exception& e) {\r
72                 errorOut(e, "MothurOut", "MothurOut");\r
73                 exit(1);\r
74         }\r
75 }\r
76 /*********************************************************************************************/\r
77 void MothurOut::mothurOut(string output) {\r
78         try {\r
79                 \r
80                 #ifdef USE_MPI\r
81                         int pid;\r
82                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); \r
83                                         \r
84                         if (pid == 0) { //only one process should output to screen\r
85                 #endif\r
86                 \r
87                 cout << output;\r
88                 out << output;\r
89                 \r
90                 #ifdef USE_MPI\r
91                         }\r
92                 #endif\r
93         }\r
94         catch(exception& e) {\r
95                 errorOut(e, "MothurOut", "MothurOut");\r
96                 exit(1);\r
97         }\r
98 }\r
99 /*********************************************************************************************/\r
100 void MothurOut::mothurOutEndLine() {\r
101         try {\r
102                 #ifdef USE_MPI\r
103                         int pid;\r
104                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); \r
105                                         \r
106                         if (pid == 0) { //only one process should output to screen\r
107                 #endif\r
108                 \r
109                 cout << endl;\r
110                 out << endl;\r
111                 \r
112                 #ifdef USE_MPI\r
113                         }\r
114                 #endif\r
115         }\r
116         catch(exception& e) {\r
117                 errorOut(e, "MothurOut", "MothurOutEndLine");\r
118                 exit(1);\r
119         }\r
120 }\r
121 /*********************************************************************************************/\r
122 void MothurOut::mothurOutJustToLog(string output) {\r
123         try {\r
124                 #ifdef USE_MPI\r
125                         int pid;\r
126                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); \r
127                                         \r
128                         if (pid == 0) { //only one process should output to screen\r
129                 #endif\r
130                 \r
131                 out << output;\r
132                 \r
133                 #ifdef USE_MPI\r
134                         }\r
135                 #endif\r
136         }\r
137         catch(exception& e) {\r
138                 errorOut(e, "MothurOut", "MothurOutJustToLog");\r
139                 exit(1);\r
140         }\r
141 }\r
142 /*********************************************************************************************/\r
143 void MothurOut::errorOut(exception& e, string object, string function) {\r
144         mothurOut("Error: ");\r
145         mothurOut(toString(e.what()));\r
146         mothurOut(" has occurred in the " + object + " class function " + function + ". Please contact Pat Schloss at mothur.bugs@gmail.com, and be sure to include the mothur.logFile with your inquiry.");\r
147         mothurOutEndLine();\r
148 }\r
149 /*********************************************************************************************/\r
150 \r
151 \r
152 \r
153 \r
154 \r