Skip to content

Commit

Permalink
fix(grb): fix binary grid output (#1739)
Browse files Browse the repository at this point in the history
* fix a bug
* update test to load the binary grid file
* use consistent naming in binary grid file
  • Loading branch information
langevin-usgs committed Apr 17, 2024
1 parent 1d6e6b1 commit a3e7f56
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion autotest/test_swf_dfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def check_output(idx, test):
grb = flopy.mf6.utils.MfGrdFile(fpth)
ia = grb.ia
ja = grb.ja
assert ia.shape[0] == grb.nodes + 1, "ia in grb file is not correct size"
assert ia.shape[0] == grb.ncells + 1, "ia in grb file is not correct size"

# read stage file
fpth = test.workspace / f"{name}.stage"
Expand Down
2 changes: 1 addition & 1 deletion autotest/test_swf_dfw_beg2022.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def check_output(idx, test):
grb = flopy.mf6.utils.MfGrdFile(fpth)
ia = grb.ia
ja = grb.ja
assert ia.shape[0] == grb.nodes + 1, "ia in grb file is not correct size"
assert ia.shape[0] == grb.ncells + 1, "ia in grb file is not correct size"

# check to make sure stage file can be read
fpth = test.workspace / f"{name}.stage"
Expand Down
2 changes: 1 addition & 1 deletion autotest/test_swf_dfw_gwf.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def check_output(idx, test):
grb = flopy.mf6.utils.MfGrdFile(fpth)
ia = grb.ia
ja = grb.ja
assert ia.shape[0] == grb.nodes + 1, "ia in grb file is not correct size"
assert ia.shape[0] == grb.ncells + 1, "ia in grb file is not correct size"

# read stage file
fpth = test.workspace / f"{name}.stage"
Expand Down
2 changes: 1 addition & 1 deletion autotest/test_swf_dfw_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def check_output(idx, test):
fpth = test.workspace / f"{name}.disv1d.grb"
grb = flopy.mf6.utils.MfGrdFile(fpth)
ia = grb.ia
assert ia.shape[0] == grb.nodes + 1, "ia in grb file is not correct size"
assert ia.shape[0] == grb.ncells + 1, "ia in grb file is not correct size"

# read stage file
fpth = test.workspace / f"{name}.stage"
Expand Down
7 changes: 7 additions & 0 deletions autotest/test_swf_vcatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ def check_output(idx, test):
if makeplot:
make_plot(test, mfsim)

# read the binary grid file
fpth = test.workspace / f"{swfname}.dis2d.grb"
grb = flopy.mf6.utils.MfGrdFile(fpth)
ia = grb.ia
ja = grb.ja
assert ia.shape[0] == grb.ncells + 1, "ia in grb file is not correct size"

# read binary stage file
fpth = test.workspace / f"{swfname}.stage"
sobj = flopy.utils.HeadFile(fpth, precision="double", text="STAGE")
Expand Down
5 changes: 2 additions & 3 deletions src/Model/Discretization/Dis2d.f90
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ subroutine write_grb(this, icelltype)
class(Dis2dType) :: this
integer(I4B), dimension(:), intent(in) :: icelltype
! -- local
integer(I4B) :: iunit, ntxt, ncpl
integer(I4B) :: iunit, ntxt
integer(I4B), parameter :: lentxt = 100
character(len=50) :: txthdr
character(len=lentxt) :: txt
Expand All @@ -500,8 +500,7 @@ subroutine write_grb(this, icelltype)
&/,6X,'UNIT NUMBER: ', I0,/,6X, 'FILE NAME: ', A)"
!
! -- Initialize
ntxt = 16
ncpl = this%nrow * this%ncol
ntxt = 14
!
! -- Open the file
fname = trim(this%input_fname)//'.grb'
Expand Down
8 changes: 6 additions & 2 deletions src/Model/Discretization/Disv1d.f90
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ subroutine write_grb(this, icelltype)
&/,6X,'UNIT NUMBER: ', I0,/,6X, 'FILE NAME: ', A)"
!
! -- Initialize
ntxt = 9
ntxt = 10
if (this%nvert > 0) ntxt = ntxt + 5
!
! -- Open the file
Expand All @@ -898,7 +898,7 @@ subroutine write_grb(this, icelltype)
write (iunit) txthdr
!
! -- write variable definitions
write (txt, '(3a, i0)') 'NODES ', 'INTEGER ', 'NDIM 0 # ', this%nodesuser
write (txt, '(3a, i0)') 'NCELLS ', 'INTEGER ', 'NDIM 0 # ', this%nodesuser
txt(lentxt:lentxt) = new_line('a')
write (iunit) txt
write (txt, '(3a, i0)') 'NJA ', 'INTEGER ', 'NDIM 0 # ', this%con%nja
Expand All @@ -913,6 +913,9 @@ subroutine write_grb(this, icelltype)
write (txt, '(3a, 1pg24.15)') 'ANGROT ', 'DOUBLE ', 'NDIM 0 # ', this%angrot
txt(lentxt:lentxt) = new_line('a')
write (iunit) txt
write (txt, '(3a, i0)') 'BOTM ', 'DOUBLE ', 'NDIM 1 ', this%nodesuser
txt(lentxt:lentxt) = new_line('a')
write (iunit) txt
write (txt, '(3a, i0)') 'IA ', 'INTEGER ', 'NDIM 1 ', this%nodesuser + 1
txt(lentxt:lentxt) = new_line('a')
write (iunit) txt
Expand Down Expand Up @@ -951,6 +954,7 @@ subroutine write_grb(this, icelltype)
write (iunit) this%xorigin ! xorigin
write (iunit) this%yorigin ! yorigin
write (iunit) this%angrot ! angrot
write (iunit) this%bottom ! botm
write (iunit) this%con%iausr ! ia
write (iunit) this%con%jausr ! ja
write (iunit) icelltype ! icelltype
Expand Down

0 comments on commit a3e7f56

Please sign in to comment.