--- trunk/src/utils/ProgressBar.cpp 2010/04/08 14:27:53 1431 +++ trunk/src/utils/ProgressBar.cpp 2014/02/26 14:14:50 1969 @@ -35,15 +35,30 @@ * * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). - * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). - * [4] Vardeman, Stocker & Gezelter, in progress (2010). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ -#include -#include #ifdef IS_MPI #include #endif + +#include +#include + +#ifdef _MSC_VER +#include +#include +#include +#define isatty _isatty +#define fileno _fileno +#else +#include +#include +#include +#endif + #include "utils/ProgressBar.hpp" using namespace std; @@ -57,7 +72,9 @@ namespace OpenMD { void ProgressBar::clear() { #ifdef IS_MPI - if (MPI::COMM_WORLD.Get_rank() == 0) { + int myRank; + MPI_Comm_rank( MPI_COMM_WORLD, &myRank); + if (myRank == 0) { #endif cout << endl; cout.flush(); @@ -72,19 +89,29 @@ namespace OpenMD { void ProgressBar::update() { - int width; - #ifdef IS_MPI - if (MPI::COMM_WORLD.Get_rank() == 0) { + int myRank; + MPI_Comm_rank( MPI_COMM_WORLD, &myRank); + if (myRank == 0) { #endif // only do the progress bar if we are actually running in a tty: - if (isatty(fileno(stdout))) { - + if (isatty(fileno(stdout)) && (getenv("SGE_TASK_ID")==NULL)) { // get the window width: + + int width = 0; +#ifdef _MSC_VER + CONSOLE_SCREEN_BUFFER_INFO csbi; + HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE ); + int ret = GetConsoleScreenBufferInfo(hConsole, &csbi); + if(ret) { + width = csbi.dwSize.X - 1; + } +#else struct winsize w; ioctl(fileno(stdout), TIOCGWINSZ, &w); width = w.ws_col; +#endif // handle the case when the width is returned as a nonsensical value. if (width <= 0) width = 80; @@ -107,12 +134,18 @@ namespace OpenMD { // compute the best estimate of the ending time: time_t current_ = time(NULL); - time_t end_ = start_ + (current_ - start_) * (100.0/percent); + time_t end_ = static_cast(start_ + (current_ - start_) * + (100.0/percent) ); struct tm * ender = localtime(&end_); char buffer[22]; strftime(buffer, 22, "%a %b %d @ %I:%M %p", ender); - + +#ifdef _MSC_VER + csbi.dwCursorPosition.X = 0; + SetConsoleCursorPosition(hConsole, csbi.dwCursorPosition); +#else cout << '\r'; +#endif cout.width(3); cout << right << int(percent); cout.width(3);