]> git.donarmstrong.com Git - mothur.git/blob - progress.cpp
fixed some bugs
[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                 cout << "********************#****#****#****#****#****#****#****#****#****#****#";
22                 
23                 nTicks = 0;
24                 finalPos = 0;
25         }
26         catch(exception& e) {
27                 cout << "Standard Error: " << e.what() << " has occurred in the Progress class Function Progress. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
28                 exit(1);
29         }
30         catch(...) {
31                 cout << "An unknown error has occurred in the Progress class function Progress. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
32                 exit(1);
33         }
34 }
35
36 /***********************************************************************/
37
38 Progress::Progress(string job, int end){
39         try {
40                 cout << "********************#****#****#****#****#****#****#****#****#****#****#\n";
41                 cout << setw(20) << left << job << setw(1) << marker;
42                 cout.flush();
43
44                 nTicks = 0;
45                 finalPos = end;
46         }
47         catch(exception& e) {
48                 cout << "Standard Error: " << e.what() << " has occurred in the Progress class Function Progress. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
49                 exit(1);
50         }
51         catch(...) {
52                 cout << "An unknown error has occurred in the Progress class function Progress. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
53                 exit(1);
54         }
55 }
56
57 /***********************************************************************/
58
59 void Progress::newLine(string job, int end){
60         try {
61                 cout << endl;
62                 cout << setw(20) << left << job << setw(1) << marker;
63                 cout.flush();
64                 
65                 nTicks = 0;
66                 finalPos = end;
67         }
68         catch(exception& e) {
69                 cout << "Standard Error: " << e.what() << " has occurred in the Progress class Function newline. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
70                 exit(1);
71         }
72         catch(...) {
73                 cout << "An unknown error has occurred in the Progress class function newline. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
74                 exit(1);
75         }
76 }
77         
78 /***********************************************************************/
79
80 void Progress::update(const int currentPos){
81         try {
82                 int ratio = int(totalTicks * (float)currentPos / finalPos);
83         
84                 if(ratio > nTicks){
85                         for(int i=nTicks;i<ratio;i++){
86                                 cout << marker;
87                                 cout.flush();
88                         }
89                         nTicks = ratio;
90                 }
91         }
92         catch(exception& e) {
93                 cout << "Standard Error: " << e.what() << " has occurred in the Progress class Function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
94                 exit(1);
95         }
96         catch(...) {
97                 cout << "An unknown error has occurred in the Progress class function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
98                 exit(1);
99         }
100 }
101
102 /***********************************************************************/
103
104 void Progress::finish(){
105         try {
106                 for(int i=nTicks;i<totalTicks;i++){
107                         cout << marker;
108                         cout.flush();
109                 }
110         
111         
112                 cout << endl;
113                 cout << "***********************************************************************\n";
114                 cout.flush();
115         }
116         catch(exception& e) {
117                 cout << "Standard Error: " << e.what() << " has occurred in the Progress class Function finish. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
118                 exit(1);
119         }
120         catch(...) {
121                 cout << "An unknown error has occurred in the Progress class function finish. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
122                 exit(1);
123         }
124 }
125
126 /***********************************************************************/