From cea7af28176207a127eeb6cb9d1c6fd7301d2431 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Mon, 8 Jul 2024 18:11:02 -0400 Subject: [PATCH] fix(oc): fix TimeStepSelect logging (#1933) #1923 introduced a module/type for time step selections, with a log() routine to handle logging of selected steps. This routine did not work properly when selecting multiple time steps with different keyword options (as supported by OC period-block settings). To restore the desired logging behavior, switch exclusive to inclusive conditionals, and reorder the conditions to preserve the original order of lines written to the list file. Also add a unit test for multiple selections. --- autotest/TestTimeStepSelect.f90 | 30 ++++++++++++++++++++- src/Model/ModelUtilities/TimeStepSelect.f90 | 26 +++++++++++++----- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/autotest/TestTimeStepSelect.f90 b/autotest/TestTimeStepSelect.f90 index bf1952f84f4..aa9a62ea7e9 100644 --- a/autotest/TestTimeStepSelect.f90 +++ b/autotest/TestTimeStepSelect.f90 @@ -16,7 +16,8 @@ subroutine collect_timestepselect(testsuite) new_unittest("last", test_last), & new_unittest("all", test_all), & new_unittest("freq", test_freq), & - new_unittest("step", test_step) & + new_unittest("step", test_step), & + new_unittest("multiple", test_multiple) & ] end subroutine collect_timestepselect @@ -119,4 +120,31 @@ subroutine test_step(error) end subroutine test_step + subroutine test_multiple(error) + type(error_type), allocatable, intent(out) :: error + type(TimeStepSelectType) :: steps + character(len=LINELENGTH) :: line + + call steps%init() + + line = "FIRST" + call steps%read(line) + + line = "LAST" + call steps%read(line) + + line = "STEPS 2" + call steps%read(line) + + call check(error, steps%is_selected(1, .false.)) + if (allocated(error)) return + + call check(error, steps%is_selected(2, .false.)) + if (allocated(error)) return + + call check(error, steps%is_selected(3, .true.)) + if (allocated(error)) return + + end subroutine test_multiple + end module TestTimeStepSelect diff --git a/src/Model/ModelUtilities/TimeStepSelect.f90 b/src/Model/ModelUtilities/TimeStepSelect.f90 index 881648f5138..aa7ab0fc344 100644 --- a/src/Model/ModelUtilities/TimeStepSelect.f90 +++ b/src/Model/ModelUtilities/TimeStepSelect.f90 @@ -23,6 +23,16 @@ module TimeStepSelectModule !! LAST !! FREQUENCY 4 !! + !! The read() procedure may be invoked multiple times to select multiple + !! time steps. Note that a character string re-using a keyword which has + !! been used for a previous read() invocation will override the previous + !! setting using that keyword. To combine multiple settings, be sure the + !! keywords are different on each invocation, e.g.: + !! + !! FIRST + !! LAST + !! STEPS 2 + !! !! The is_selected() function indicates whether the given time step is !! active. This function accepts an optional argument, indicating that !! the time step is the last in the stress period. @@ -75,15 +85,19 @@ subroutine log(this, iout, verb) if (this%all) then write (iout, "(6x,a,a)") 'ALL TIME STEPS WILL BE ', verb - else if (this%first) then - write (iout, "(6x,a,a)") 'THE FIRST TIME STEP WILL BE ', verb - else if (this%last) then - write (iout, "(6x,a,a)") 'THE LAST TIME STEP WILL BE ', verb - else if (size(this%steps) > 0) then + end if + if (size(this%steps) > 0) then write (iout, fmt_steps) verb, this%steps - else if (this%freq > 0) then + end if + if (this%freq > 0) then write (iout, fmt_freq) verb, this%freq end if + if (this%first) then + write (iout, "(6x,a,a)") 'THE FIRST TIME STEP WILL BE ', verb + end if + if (this%last) then + write (iout, "(6x,a,a)") 'THE LAST TIME STEP WILL BE ', verb + end if end subroutine log !> @brief Read a line of input and prepare the selection object.