From ba5e85964cea93d82dfc62212e8a7ce2ea20acf4 Mon Sep 17 00:00:00 2001 From: nhorelik Date: Fri, 26 Apr 2013 15:06:38 -0400 Subject: [PATCH 1/8] Added progress bar to plotter --- src/DEPENDENCIES | 1 + src/OBJECTS | 1 + src/plot.F90 | 5 +++++ src/timer_header.F90 | 2 +- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/DEPENDENCIES b/src/DEPENDENCIES index 8cafde3f41..c184ea2134 100644 --- a/src/DEPENDENCIES +++ b/src/DEPENDENCIES @@ -311,6 +311,7 @@ plot.o: output.o plot.o: particle_header.o plot.o: plot_header.o plot.o: ppmlib.o +plot.o: progress_header.o plot.o: source.o plot.o: string.o diff --git a/src/OBJECTS b/src/OBJECTS index c9612e6af0..c2a777c4e2 100644 --- a/src/OBJECTS +++ b/src/OBJECTS @@ -46,6 +46,7 @@ physics.o \ plot.o \ plot_header.o \ ppmlib.o \ +progress_header.o \ random_lcg.o \ search.o \ set_header.o \ diff --git a/src/plot.F90 b/src/plot.F90 index 0b68f4c219..6252b6c6b9 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -10,6 +10,7 @@ module plot use plot_header use ppmlib, only: Image, init_image, allocate_image, & deallocate_image, set_pixel + use progress_header use source, only: initialize_particle use string, only: to_str @@ -108,6 +109,7 @@ contains real(8) :: out_pixel real(8) :: xyz(3) type(Image) :: img + type(ProgressBar) :: progress ! Initialize and allocate space for image call init_image(img) @@ -147,6 +149,7 @@ contains p % coord % universe = BASE_UNIVERSE do y = 1, img % height + call progress % set_value(dble(y)/dble(img % height)*100.) do x = 1, img % width ! get pixel color @@ -226,6 +229,7 @@ contains integer :: id ! id of cell or material real(8) :: vox(3) ! x, y, and z voxel widths real(8) :: ll(3) ! lower left starting point for each sweep direction + type(ProgressBar) :: progress ! compute voxel widths in each direction vox = pl % width/dble(pl % pixels) @@ -251,6 +255,7 @@ contains ll = ll + vox / 2.0 do x = 1, pl % pixels(1) + call progress % set_value(dble(x)/dble(pl % pixels(1))*100.) do y = 1, pl % pixels(2) do z = 1, pl % pixels(3) diff --git a/src/timer_header.F90 b/src/timer_header.F90 index 0dde85d0c2..7acef0fc4f 100644 --- a/src/timer_header.F90 +++ b/src/timer_header.F90 @@ -45,7 +45,7 @@ contains function timer_get_value(self) result(elapsed) class(Timer), intent(in) :: self ! the timer - real(8) :: elapsed ! total elapsed time + real(8) :: elapsed ! total elapsed time integer :: end_counts ! current number of counts integer :: count_rate ! system-dependent counting rate From f51532f5da856e227170bb61a2ff97cf407284e1 Mon Sep 17 00:00:00 2001 From: nhorelik Date: Fri, 26 Apr 2013 15:09:10 -0400 Subject: [PATCH 2/8] Added progress header file --- src/progress_header.F90 | 72 +++++++++++++++++++++++++++++++++++++++++ src/timer_header.F90 | 2 +- 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/progress_header.F90 diff --git a/src/progress_header.F90 b/src/progress_header.F90 new file mode 100644 index 0000000000..d46b834c7d --- /dev/null +++ b/src/progress_header.F90 @@ -0,0 +1,72 @@ +module progress_header + + use, intrinsic :: ISO_FORTRAN_ENV + + implicit none + +!=============================================================================== +! PROGRESSBAR +!=============================================================================== + + type ProgressBar + private + character(len=72) :: bar="???% | " // & + " |" + contains + procedure :: set_value => bar_set_value + end type ProgressBar + +contains + +!=============================================================================== +! BAR_SET_VALUE prints the progress bar without advancing. The value is +! specified as percent completion, from 0 to 100. If the value is ever set to +! 100 or above, the +!=============================================================================== + + subroutine bar_set_value(self, val) + + class(ProgressBar), intent(inout) :: self + real(8), intent(in) :: val + + integer :: i + + ! set the percentage + if (val >= 100.) then + write(unit=self % bar(1:3),fmt="(i3)") 100 + else + write(unit=self % bar(1:3),fmt="(i3)") int(val) + end if + + ! set the bar width + if (val >= 100.) then + do i=1,65 + self % bar(i+6:i+6) = '=' + end do + else + do i=1,int(dble(65)*val/100.) + self % bar(i+6:i+6) = '=' + end do + end if + + open(UNIT=OUTPUT_UNIT, carriagecontrol='fortran') + write(UNIT=OUTPUT_UNIT, FMT='(a1,a1,a72)', ADVANCE='no') '+', char(13), & + self % bar + call flush(OUTPUT_UNIT) + + if (val >= 100.) then + + ! make new line + write(UNIT=OUTPUT_UNIT, FMT="(A)") "" + + ! reset the bar in case we want to use this instance again + self % bar = "???% | " // & + " |" + + close(UNIT=OUTPUT_UNIT) + + end if + + end subroutine bar_set_value + +end module progress_header diff --git a/src/timer_header.F90 b/src/timer_header.F90 index 7acef0fc4f..0dde85d0c2 100644 --- a/src/timer_header.F90 +++ b/src/timer_header.F90 @@ -45,7 +45,7 @@ contains function timer_get_value(self) result(elapsed) class(Timer), intent(in) :: self ! the timer - real(8) :: elapsed ! total elapsed time + real(8) :: elapsed ! total elapsed time integer :: end_counts ! current number of counts integer :: count_rate ! system-dependent counting rate From 7e383e6f3f69288770d5d915467ce90e8b96aae4 Mon Sep 17 00:00:00 2001 From: Nick Horelik Date: Fri, 26 Apr 2013 14:59:20 -0700 Subject: [PATCH 3/8] Changed to conform to gfortran -pedantic -std=f2008 --- src/plot.F90 | 2 +- src/progress_header.F90 | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/plot.F90 b/src/plot.F90 index 6252b6c6b9..1645d54afc 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -10,7 +10,7 @@ module plot use plot_header use ppmlib, only: Image, init_image, allocate_image, & deallocate_image, set_pixel - use progress_header + use progress_header, only: ProgressBar use source, only: initialize_particle use string, only: to_str diff --git a/src/progress_header.F90 b/src/progress_header.F90 index d46b834c7d..244fd29ebe 100644 --- a/src/progress_header.F90 +++ b/src/progress_header.F90 @@ -33,38 +33,38 @@ contains ! set the percentage if (val >= 100.) then - write(unit=self % bar(1:3),fmt="(i3)") 100 + write(self % bar(1:3), "(I3)") 100 + else if (val <= 0.) then + write(self % bar(1:3), "(I3)") 0 else - write(unit=self % bar(1:3),fmt="(i3)") int(val) + write(self % bar(1:3), "(I3)") int(val) end if ! set the bar width if (val >= 100.) then do i=1,65 - self % bar(i+6:i+6) = '=' + write(self % bar(i+6:i+6), '(A)') '=' end do else do i=1,int(dble(65)*val/100.) - self % bar(i+6:i+6) = '=' + write(self % bar(i+6:i+6), '(A)') '=' end do end if - open(UNIT=OUTPUT_UNIT, carriagecontrol='fortran') - write(UNIT=OUTPUT_UNIT, FMT='(a1,a1,a72)', ADVANCE='no') '+', char(13), & - self % bar - call flush(OUTPUT_UNIT) + open(OUTPUT_UNIT) + write(OUTPUT_UNIT, '(A1,A1,A72)', ADVANCE='no') '+', char(13), self % bar + flush(OUTPUT_UNIT) if (val >= 100.) then ! make new line - write(UNIT=OUTPUT_UNIT, FMT="(A)") "" - + write(OUTPUT_UNIT, "(A)") "" + flush(OUTPUT_UNIT) + ! reset the bar in case we want to use this instance again self % bar = "???% | " // & " |" - close(UNIT=OUTPUT_UNIT) - end if end subroutine bar_set_value From 00bfe55c7f266889631a7224d8c0295a7424aee8 Mon Sep 17 00:00:00 2001 From: Nick Horelik Date: Sat, 27 Apr 2013 08:37:03 -0700 Subject: [PATCH 4/8] Removed open and added check for tty --- src/progress_header.F90 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/progress_header.F90 b/src/progress_header.F90 index 244fd29ebe..762d392292 100644 --- a/src/progress_header.F90 +++ b/src/progress_header.F90 @@ -1,9 +1,17 @@ module progress_header - use, intrinsic :: ISO_FORTRAN_ENV + use, intrinsic :: ISO_FORTRAN_ENV, only: OUTPUT_UNIT implicit none + interface + function check_isatty(fd) bind(C, name = 'isatty') + use, intrinsic :: ISO_C_BINDING, only: c_int + integer(c_int) :: check_isatty + integer(c_int), value :: fd + end function + end interface + !=============================================================================== ! PROGRESSBAR !=============================================================================== @@ -31,6 +39,8 @@ contains integer :: i + if (check_isatty(1) == 0) return + ! set the percentage if (val >= 100.) then write(self % bar(1:3), "(I3)") 100 @@ -51,7 +61,6 @@ contains end do end if - open(OUTPUT_UNIT) write(OUTPUT_UNIT, '(A1,A1,A72)', ADVANCE='no') '+', char(13), self % bar flush(OUTPUT_UNIT) From 3a7a7d70164ecf9516b9302b42836c4d69a7f47e Mon Sep 17 00:00:00 2001 From: Nick Horelik Date: Sun, 28 Apr 2013 08:51:50 -0700 Subject: [PATCH 5/8] Surrounded progressbar c binding code with #ifdef __linux__ --- src/progress_header.F90 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/progress_header.F90 b/src/progress_header.F90 index 762d392292..4bdc172c57 100644 --- a/src/progress_header.F90 +++ b/src/progress_header.F90 @@ -4,6 +4,7 @@ module progress_header implicit none +#ifdef __linux__ interface function check_isatty(fd) bind(C, name = 'isatty') use, intrinsic :: ISO_C_BINDING, only: c_int @@ -11,6 +12,7 @@ module progress_header integer(c_int), value :: fd end function end interface +#endif !=============================================================================== ! PROGRESSBAR @@ -29,7 +31,7 @@ contains !=============================================================================== ! BAR_SET_VALUE prints the progress bar without advancing. The value is ! specified as percent completion, from 0 to 100. If the value is ever set to -! 100 or above, the +! 100 or above, the bar is set to 100 and a newline is written. !=============================================================================== subroutine bar_set_value(self, val) @@ -39,7 +41,11 @@ contains integer :: i +#ifdef __linux__ if (check_isatty(1) == 0) return +#else + return +#endif ! set the percentage if (val >= 100.) then From 8d8a14faa40cd9ca09b6450a28e68b91774b0e7a Mon Sep 17 00:00:00 2001 From: Nick Horelik Date: Wed, 1 May 2013 07:49:40 -0700 Subject: [PATCH 6/8] Changed progressbar wrapping to #if !defined(__WIN32) --- src/progress_header.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/progress_header.F90 b/src/progress_header.F90 index 4bdc172c57..5e5820f865 100644 --- a/src/progress_header.F90 +++ b/src/progress_header.F90 @@ -4,7 +4,7 @@ module progress_header implicit none -#ifdef __linux__ +#if !defined(__WIN32) interface function check_isatty(fd) bind(C, name = 'isatty') use, intrinsic :: ISO_C_BINDING, only: c_int @@ -41,7 +41,7 @@ contains integer :: i -#ifdef __linux__ +#if !defined(__WIN32) if (check_isatty(1) == 0) return #else return From 20d31d8b8a1ec90e6fd92231614eebca0053a58e Mon Sep 17 00:00:00 2001 From: Nicholas Horelik Date: Tue, 21 May 2013 13:43:47 -0300 Subject: [PATCH 7/8] Changed progressbar wrapping to #if !defined(_WIN32) --- src/progress_header.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/progress_header.F90 b/src/progress_header.F90 index 5e5820f865..7055db064d 100644 --- a/src/progress_header.F90 +++ b/src/progress_header.F90 @@ -4,7 +4,7 @@ module progress_header implicit none -#if !defined(__WIN32) +#if !defined(_WIN32) interface function check_isatty(fd) bind(C, name = 'isatty') use, intrinsic :: ISO_C_BINDING, only: c_int @@ -41,7 +41,7 @@ contains integer :: i -#if !defined(__WIN32) +#if !defined(_WIN32) if (check_isatty(1) == 0) return #else return From 57d3d9d30192791c2f9c0301d28747a768be67da Mon Sep 17 00:00:00 2001 From: Nick Horelik Date: Tue, 6 May 2014 10:34:46 -0400 Subject: [PATCH 8/8] Changed to ifdef to be consistent with the rest of the codebase --- src/progress_header.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/progress_header.F90 b/src/progress_header.F90 index 7af891af35..d0ee7563a5 100644 --- a/src/progress_header.F90 +++ b/src/progress_header.F90 @@ -4,7 +4,7 @@ module progress_header implicit none -#if (UNIX) +#ifdef UNIX interface function check_isatty(fd) bind(C, name = 'isatty') use, intrinsic :: ISO_C_BINDING, only: c_int @@ -39,7 +39,7 @@ contains istty = .true. -#if (UNIX) +#ifdef UNIX if (check_isatty(1) == 0) istty = .false. #else istty = .false.