Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Restructured code so that there is a progress display option for the …
Browse files Browse the repository at this point in the history
…bare-bones progress bar, and the compact option will be text only to be read in by the Python code and interpreted by a tqdm progress bar
  • Loading branch information
daminton committed Nov 21, 2022
1 parent fb1764f commit 49f5433
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/io/io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ module subroutine io_get_args(integrator, param_file_name, display_style)
! Arguments
integer(I4B) :: integrator !! Symbolic code of the requested integrator
character(len=:), allocatable :: param_file_name !! Name of the input parameters file
character(len=:), allocatable :: display_style !! Style of the output display {"STANDARD", "COMPACT"}). Default is "STANDARD"
character(len=:), allocatable :: display_style !! Style of the output display {"STANDARD", "COMPACT", "PROGRESS"}). Default is "STANDARD"
! Internals
character(len=STRMAX), dimension(:), allocatable :: arg
integer(I4B), dimension(:), allocatable :: ierr
Expand Down Expand Up @@ -1788,7 +1788,7 @@ module subroutine io_read_in_param(self, param_file_name)
character(STRMAX) :: errmsg !! Error message in UDIO procedure

! Read in name of parameter file
write(*, *) 'Parameter input file is ', trim(adjustl(param_file_name))
write(self%display_unit, *) 'Parameter input file is ', trim(adjustl(param_file_name))
self%param_file_name = param_file_name

!! todo: Currently this procedure does not work in user-defined derived-type input mode
Expand All @@ -1799,7 +1799,7 @@ module subroutine io_read_in_param(self, param_file_name)
if (ierr == 0) return

667 continue
write(*,*) "Error reading parameter file: " // trim(adjustl(errmsg))
write(self%display_unit,*) "Error reading parameter file: " // trim(adjustl(errmsg))
call util_exit(FAILURE)
end subroutine io_read_in_param

Expand Down Expand Up @@ -1915,11 +1915,11 @@ module subroutine io_set_display_param(self, display_style)
select case(display_style)
case ('STANDARD')
self%display_unit = OUTPUT_UNIT !! stdout from iso_fortran_env
self%compact_display = .false.
case ('COMPACT')
self%log_output = .false.
case ('COMPACT', 'PROGRESS')
open(unit=SWIFTEST_LOG_OUT, file=SWIFTEST_LOG_FILE, status='replace', err = 667, iomsg = errmsg)
self%display_unit = SWIFTEST_LOG_OUT
self%compact_display = .true.
self%log_output = .true.
case default
write(*,*) display_style, " is an unknown display style"
call util_exit(USAGE)
Expand Down
14 changes: 7 additions & 7 deletions src/main/swiftest_driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ program swiftest_driver
class(swiftest_parameters), allocatable :: param !! Run configuration parameters
integer(I4B) :: integrator !! Integrator type code (see swiftest_globals for symbolic names)
character(len=:),allocatable :: param_file_name !! Name of the file containing user-defined parameters
character(len=:), allocatable :: display_style !! Style of the output display {"STANDARD", "COMPACT"}). Default is "STANDARD"
character(len=:), allocatable :: display_style !! Style of the output display {"STANDARD", "COMPACT", "PROGRESS"}). Default is "STANDARD"
integer(I4B) :: ierr !! I/O error code
integer(I8B) :: iloop !! Loop counter
integer(I8B) :: idump !! Dump cadence counter
Expand Down Expand Up @@ -59,7 +59,7 @@ program swiftest_driver
!$ write(param%display_unit,'(a)') ' OpenMP parameters:'
!$ write(param%display_unit,'(a)') ' ------------------'
!$ write(param%display_unit,'(a,i3,/)') ' Number of threads = ', nthreads
!$ if (param%compact_display) write(*,'(a,i3)') ' OpenMP: Number of threads = ',nthreads
!$ if (param%log_output) write(*,'(a,i3)') ' OpenMP: Number of threads = ',nthreads

call setup_construct_system(nbody_system, param)
call param%read_in(param_file_name)
Expand All @@ -71,8 +71,8 @@ program swiftest_driver
istep_out => param%istep_out, &
istep_dump => param%istep_dump, &
ioutput => param%ioutput, &
display_unit => param%display_unit, &
compact_display => param%compact_display)
display_style => param%display_style, &
display_unit => param%display_unit)

call nbody_system%initialize(param)
t = t0
Expand All @@ -96,7 +96,7 @@ program swiftest_driver

write(display_unit, *) " *************** Main Loop *************** "
if (param%lrestart .and. param%lenergy) call nbody_system%conservation_report(param, lterminal=.true.)
if (compact_display) then
if (display_style == "PROGRESS") then
call pbar%reset(nloops)
write(pbarmessage,fmt=pbarfmt) t0, tstop
call pbar%update(1,message=pbarmessage)
Expand All @@ -111,7 +111,7 @@ program swiftest_driver

!> Evaluate any discards or collisional outcomes
call nbody_system%discard(param)
if (compact_display) call pbar%update(iloop)
if (display_style == "PROGRESS") call pbar%update(iloop)

!> If the loop counter is at the output cadence value, append the data file with a single frame
if (istep_out > 0) then
Expand All @@ -133,7 +133,7 @@ program swiftest_driver
call integration_timer%reset()

iout = istep_out
if (compact_display) then
if (display_style == "PROGRESS") then
write(pbarmessage,fmt=pbarfmt) t, tstop
call pbar%update(1,message=pbarmessage)
end if
Expand Down
6 changes: 3 additions & 3 deletions src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ module swiftest_classes
logical :: lfirstkick = .true. !! Initiate the first kick in a symplectic step
logical :: lrestart = .false. !! Indicates whether or not this is a restarted run

character(len=:), allocatable :: display_style !! Style of the output display {"STANDARD", "COMPACT"}). Default is "STANDARD"
integer(I4B) :: display_unit !! File unit number for display (either to stdout or to a log file)
logical :: compact_display = .false. !! Turns on the compact display
character(len=:), allocatable :: display_style !! Style of the output display {"STANDARD", "COMPACT"}). Default is "STANDARD"
integer(I4B) :: display_unit !! File unit number for display (either to stdout or to a log file)
logical :: log_output = .false. !! Logs the output to file instead of displaying it on the terminal

! Future features not implemented or in development
logical :: lgr = .false. !! Turn on GR
Expand Down
2 changes: 1 addition & 1 deletion src/util/util_exit.f90
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module subroutine util_exit(code)
character(*), parameter :: BAR = '("------------------------------------------------")'
character(*), parameter :: SUCCESS_MSG = '(/, "Normal termination of Swiftest (version ", f3.1, ")")'
character(*), parameter :: FAIL_MSG = '(/, "Terminating Swiftest (version ", f3.1, ") due to error!!")'
character(*), parameter :: USAGE_MSG = '("Usage: swiftest [bs|helio|ra15|rmvs|symba|tu4|whm] <paramfile> [standard|compact|NONE]")'
character(*), parameter :: USAGE_MSG = '("Usage: swiftest [bs|helio|ra15|rmvs|symba|tu4|whm] <paramfile> [standard|compact|progress|NONE]")'
character(*), parameter :: HELP_MSG = USAGE_MSG

select case(code)
Expand Down

0 comments on commit 49f5433

Please sign in to comment.