From 49f5433ce387c5391cee368e27b656c5eb61860a Mon Sep 17 00:00:00 2001 From: David A Minton Date: Mon, 21 Nov 2022 12:13:21 -0500 Subject: [PATCH] Restructured code so that there is a progress display option for the 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 --- src/io/io.f90 | 12 ++++++------ src/main/swiftest_driver.f90 | 14 +++++++------- src/modules/swiftest_classes.f90 | 6 +++--- src/util/util_exit.f90 | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/io/io.f90 b/src/io/io.f90 index 7296d00dd..e93cc265e 100644 --- a/src/io/io.f90 +++ b/src/io/io.f90 @@ -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 @@ -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 @@ -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 @@ -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) diff --git a/src/main/swiftest_driver.f90 b/src/main/swiftest_driver.f90 index ee8fda1f1..14403faa2 100644 --- a/src/main/swiftest_driver.f90 +++ b/src/main/swiftest_driver.f90 @@ -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 @@ -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) @@ -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 @@ -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) @@ -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 @@ -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 diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index e499f8332..78b82d43b 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -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 diff --git a/src/util/util_exit.f90 b/src/util/util_exit.f90 index 65d92206d..a7b77c197 100644 --- a/src/util/util_exit.f90 +++ b/src/util/util_exit.f90 @@ -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] [standard|compact|NONE]")' + character(*), parameter :: USAGE_MSG = '("Usage: swiftest [bs|helio|ra15|rmvs|symba|tu4|whm] [standard|compact|progress|NONE]")' character(*), parameter :: HELP_MSG = USAGE_MSG select case(code)