Skip to content

Commit

Permalink
fix(urword): increase number of characters for integers and floats (M…
Browse files Browse the repository at this point in the history
…ODFLOW-USGS#2067)

* fix(urword): increase number of characters allowed for input integers and floats

* handle special urword case

* add unit test for inputoutput

* update develop.tex
  • Loading branch information
langevin-usgs authored Nov 27, 2024
1 parent d22b6ee commit f744064
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 8 deletions.
79 changes: 77 additions & 2 deletions autotest/TestInputOutput.f90
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module TestInputOutput
use testdrive, only: error_type, unittest_type, new_unittest, check
use KindModule, only: I4B, DP
use ConstantsModule, only: LINELENGTH
! use InputOutputModule, only: ???
use InputOutputModule, only: urword
implicit none
private
public :: collect_inputoutput
Expand All @@ -10,7 +11,81 @@ module TestInputOutput

subroutine collect_inputoutput(testsuite)
type(unittest_type), allocatable, intent(out) :: testsuite(:)
allocate (testsuite(0))
testsuite = [ &
new_unittest("urword", test_urword) &
]
end subroutine collect_inputoutput

subroutine test_urword(error)
type(error_type), allocatable, intent(out) :: error
character(len=LINELENGTH) :: line
integer(I4B) :: icol
integer(I4B) :: istart
integer(I4B) :: istop
integer(I4B) :: ncode
integer(I4B) :: n
integer(I4B) :: iout
integer(I4B) :: in
real(DP) :: r

! parse integer
line = "77"
icol = 1
ncode = 2
call URWORD(line, icol, istart, istop, ncode, n, r, iout, in)
call check(error, n == 77)
if (allocated(error)) return

! parse float
line = "1.0"
icol = 1
ncode = 3
call URWORD(line, icol, istart, istop, ncode, n, r, iout, in)
call check(error, r == 1.D0)
if (allocated(error)) return

! parse string
line = "mymodel"
icol = 1
ncode = 0
call URWORD(line, icol, istart, istop, ncode, n, r, iout, in)
call check(error, line(istart:istop) == "mymodel")
if (allocated(error)) return

! parse string and convert to caps
line = "mymodel"
icol = 1
ncode = 1
call URWORD(line, icol, istart, istop, ncode, n, r, iout, in)
call check(error, line(istart:istop) == "MYMODEL")
if (allocated(error)) return

! parse float with more than 30 characters
line = "1000000000000000000000000000000000000000"
icol = 1
ncode = 3
call URWORD(line, icol, istart, istop, ncode, n, r, iout, in)
call check(error, r == 1D39)
if (allocated(error)) return

! parse empty line into a zero float value
line = " "
icol = 1
ncode = 3
r = -999.D0
call URWORD(line, icol, istart, istop, ncode, n, r, iout, in)
call check(error, r == 0.D0)
if (allocated(error)) return

! parse empty line into a zero integer value
line = " "
icol = 1
ncode = 2
n = -999
call URWORD(line, icol, istart, istop, ncode, n, r, iout, in)
call check(error, n == 0)
if (allocated(error)) return

end subroutine test_urword

end module TestInputOutput
1 change: 1 addition & 0 deletions doc/ReleaseNotes/develop.tex
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
\item The GWF-GWF Exchange has been fixed to support the configuration of the Mover package (MVR) also in cases where the number of exchanges equals zero (NEXG = 0). In earlier versions this has caused MODFLOW to terminate with an error.
\item A PRT bug was fixed in which array-based input read from the RCH (recharge) or EVT (evapotranspiration) packages could fail to be processed correctly by the PRT FMI (flow model interface) package, causing a crash.
\item When the SQUARE\_GWET option was invoked in the UZF options block, evapotranspiration from the water table (GWET) was calculated incorrectly. Instead of acting as a sink, the calculated evapotranspiration flux was added as a source of water. The applied fix ensures that groundwater evapotranspiration is removed from the water table and as a result the GWET values are accumulated as outflows in the budget table.
\item The number of characters used to represent integers and floating point numbers in MODFLOW input files was restricted to 30. The program was modified to accept any number of characters provided the number is valid. This may be useful for parameter estimation programs that use character substitution to create new input files.
% \item xxx

\end{itemize}
Expand Down
16 changes: 10 additions & 6 deletions src/Utilities/InputOutput.f90
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ subroutine URWORD(line, icol, istart, istop, ncode, n, r, iout, in)
integer(I4B), intent(in) :: in !< input file unit number
! -- local
character(len=20) string
character(len=30) rw
character(len=1) tab
character(len=1) charend
character(len=200) :: msg
Expand Down Expand Up @@ -520,12 +519,17 @@ subroutine URWORD(line, icol, istart, istop, ncode, n, r, iout, in)
!
! -- Convert word to a number if requested.
100 if (ncode == 2 .or. ncode == 3) then
rw = ' '
l = 30 - istop + istart
l = istop - istart + 1
if (l < 1) go to 200
rw(l:30) = line(istart:istop)
if (ncode == 2) read (rw, '(i30)', err=200) n
if (ncode == 3) read (rw, '(f30.0)', err=200) r
if (istart > linlen) then
! support legacy urword behavior to return a zero value when
! no more data is on the line
if (ncode == 2) n = 0
if (ncode == 3) r = DZERO
else
if (ncode == 2) read (line(istart:istop), *, err=200) n
if (ncode == 3) read (line(istart:istop), *, err=200) r
end if
end if
return
!
Expand Down

0 comments on commit f744064

Please sign in to comment.