Skip to content

Commit cea7af2

Browse files
authored
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.
1 parent 300b21f commit cea7af2

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

autotest/TestTimeStepSelect.f90

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ subroutine collect_timestepselect(testsuite)
1616
new_unittest("last", test_last), &
1717
new_unittest("all", test_all), &
1818
new_unittest("freq", test_freq), &
19-
new_unittest("step", test_step) &
19+
new_unittest("step", test_step), &
20+
new_unittest("multiple", test_multiple) &
2021
]
2122
end subroutine collect_timestepselect
2223

@@ -119,4 +120,31 @@ subroutine test_step(error)
119120

120121
end subroutine test_step
121122

123+
subroutine test_multiple(error)
124+
type(error_type), allocatable, intent(out) :: error
125+
type(TimeStepSelectType) :: steps
126+
character(len=LINELENGTH) :: line
127+
128+
call steps%init()
129+
130+
line = "FIRST"
131+
call steps%read(line)
132+
133+
line = "LAST"
134+
call steps%read(line)
135+
136+
line = "STEPS 2"
137+
call steps%read(line)
138+
139+
call check(error, steps%is_selected(1, .false.))
140+
if (allocated(error)) return
141+
142+
call check(error, steps%is_selected(2, .false.))
143+
if (allocated(error)) return
144+
145+
call check(error, steps%is_selected(3, .true.))
146+
if (allocated(error)) return
147+
148+
end subroutine test_multiple
149+
122150
end module TestTimeStepSelect

src/Model/ModelUtilities/TimeStepSelect.f90

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ module TimeStepSelectModule
2323
!! LAST
2424
!! FREQUENCY 4
2525
!!
26+
!! The read() procedure may be invoked multiple times to select multiple
27+
!! time steps. Note that a character string re-using a keyword which has
28+
!! been used for a previous read() invocation will override the previous
29+
!! setting using that keyword. To combine multiple settings, be sure the
30+
!! keywords are different on each invocation, e.g.:
31+
!!
32+
!! FIRST
33+
!! LAST
34+
!! STEPS 2
35+
!!
2636
!! The is_selected() function indicates whether the given time step is
2737
!! active. This function accepts an optional argument, indicating that
2838
!! the time step is the last in the stress period.
@@ -75,15 +85,19 @@ subroutine log(this, iout, verb)
7585

7686
if (this%all) then
7787
write (iout, "(6x,a,a)") 'ALL TIME STEPS WILL BE ', verb
78-
else if (this%first) then
79-
write (iout, "(6x,a,a)") 'THE FIRST TIME STEP WILL BE ', verb
80-
else if (this%last) then
81-
write (iout, "(6x,a,a)") 'THE LAST TIME STEP WILL BE ', verb
82-
else if (size(this%steps) > 0) then
88+
end if
89+
if (size(this%steps) > 0) then
8390
write (iout, fmt_steps) verb, this%steps
84-
else if (this%freq > 0) then
91+
end if
92+
if (this%freq > 0) then
8593
write (iout, fmt_freq) verb, this%freq
8694
end if
95+
if (this%first) then
96+
write (iout, "(6x,a,a)") 'THE FIRST TIME STEP WILL BE ', verb
97+
end if
98+
if (this%last) then
99+
write (iout, "(6x,a,a)") 'THE LAST TIME STEP WILL BE ', verb
100+
end if
87101
end subroutine log
88102

89103
!> @brief Read a line of input and prepare the selection object.

0 commit comments

Comments
 (0)