]> git.donarmstrong.com Git - mothur.git/blob - progress.cpp
added logfile feature
[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                 mothurOut("********************#****#****#****#****#****#****#****#****#****#****#");
22                 
23                 nTicks = 0;
24                 finalPos = 0;
25         }
26         catch(exception& e) {
27                 errorOut(e, "Progress", "Progress");
28                 exit(1);
29         }
30 }
31
32 /***********************************************************************/
33
34 Progress::Progress(string job, int end){
35         try {
36                 mothurOut("********************#****#****#****#****#****#****#****#****#****#****#\n");
37                 cout << setw(20) << left << job << setw(1) << marker;
38                 mothurOutJustToLog(job);
39                 mothurOut(toString(marker));
40                 cout.flush();
41
42                 nTicks = 0;
43                 finalPos = end;
44         }
45         catch(exception& e) {
46                 errorOut(e, "Progress", "Progress");
47                 exit(1);
48         }
49 }
50
51 /***********************************************************************/
52
53 void Progress::newLine(string job, int end){
54         try {
55                 mothurOutEndLine();
56                 cout << setw(20) << left << job << setw(1) << marker;
57                 mothurOutJustToLog(job);
58                 mothurOut(toString(marker));
59                 cout.flush();
60                 
61                 nTicks = 0;
62                 finalPos = end;
63         }
64         catch(exception& e) {
65                 errorOut(e, "Progress", "newLine");
66                 exit(1);
67         }
68 }
69         
70 /***********************************************************************/
71
72 void Progress::update(const int currentPos){
73         try {
74                 int ratio = int(totalTicks * (float)currentPos / finalPos);
75         
76                 if(ratio > nTicks){
77                         for(int i=nTicks;i<ratio;i++){
78                                 mothurOut(toString(marker));
79                                 cout.flush();
80                         }
81                         nTicks = ratio;
82                 }
83         }
84         catch(exception& e) {
85                 errorOut(e, "Progress", "update");
86                 exit(1);
87         }
88 }
89
90 /***********************************************************************/
91
92 void Progress::finish(){
93         try {
94                 for(int i=nTicks;i<totalTicks;i++){
95                         mothurOut(toString(marker));
96                         cout.flush();
97                 }
98         
99         
100                 mothurOutEndLine();
101                 mothurOut("***********************************************************************\n");
102                 cout.flush();
103         }
104         catch(exception& e) {
105                 errorOut(e, "Progress", "finish");
106                 exit(1);
107         }
108 }
109
110 /***********************************************************************/