]> git.donarmstrong.com Git - mothur.git/blob - progress.cpp
changes while testing
[mothur.git] / progress.cpp
1 /*
2  *  progress.cpp
3  *  
4  *
5  *  Created by Pat Schloss on 8/14/08.
6  *  Copyright 2008 Patrick D. Schloss. All rights reserved.
7  *
8  */
9
10
11 #include "progress.hpp"
12
13 const int totalTicks = 50;
14 const char marker = '|';
15
16
17 /***********************************************************************/
18
19 Progress::Progress(){
20         try {
21                 m = MothurOut::getInstance();
22                 m->mothurOut("********************#****#****#****#****#****#****#****#****#****#****#");
23                 
24                 nTicks = 0;
25                 finalPos = 0;
26         }
27         catch(exception& e) {
28                 m->errorOut(e, "Progress", "Progress");
29                 exit(1);
30         }
31 }
32
33 /***********************************************************************/
34
35 Progress::Progress(string job, int end){
36         try {
37                 m = MothurOut::getInstance();
38                 
39                 m->mothurOut("********************#****#****#****#****#****#****#****#****#****#****#\n");
40                 cout << setw(20) << left << job << setw(1) << marker;
41                 m->mothurOutJustToLog(job);
42                 m->mothurOut(toString(marker));
43                 cout.flush();
44
45                 nTicks = 0;
46                 finalPos = end;
47                 
48         }
49         catch(exception& e) {
50                 m->errorOut(e, "Progress", "Progress");
51                 exit(1);
52         }
53 }
54
55 /***********************************************************************/
56
57 void Progress::newLine(string job, int end){
58         try {
59                 m->mothurOutEndLine();
60                 cout << setw(20) << left << job << setw(1) << marker;
61                 m->mothurOutJustToLog(job);
62                 m->mothurOut(toString(marker));
63                 cout.flush();
64                 
65                 nTicks = 0;
66                 finalPos = end;
67         }
68         catch(exception& e) {
69                 m->errorOut(e, "Progress", "newLine");
70                 exit(1);
71         }
72 }
73         
74 /***********************************************************************/
75
76 void Progress::update(const int currentPos){
77         try {
78                 int ratio = int(totalTicks * (float)currentPos / finalPos);
79         
80                 if(ratio > nTicks){
81                         for(int i=nTicks;i<ratio;i++){
82                                 m->mothurOut(toString(marker));
83                                 cout.flush();
84                         }
85                         nTicks = ratio;
86                 }
87         }
88         catch(exception& e) {
89                 m->errorOut(e, "Progress", "update");
90                 exit(1);
91         }
92 }
93
94 /***********************************************************************/
95
96 void Progress::finish(){
97         try {
98                 for(int i=nTicks;i<totalTicks;i++){
99                         m->mothurOut(toString(marker));
100                         cout.flush();
101                 }
102         
103         
104                 m->mothurOutEndLine();
105                 m->mothurOut("***********************************************************************\n");
106                 cout.flush();
107         }
108         catch(exception& e) {
109                 m->errorOut(e, "Progress", "finish");
110                 exit(1);
111         }
112 }
113
114 /***********************************************************************/