MODFLOW 6  version 6.7.0.dev0
USGS Modular Hydrologic Model
headfilereadermodule Module Reference

Data Types

type  headfilereadertype
 

Functions/Subroutines

subroutine initialize (this, iu, iout)
 
subroutine read_record (this, success, iout_opt)
 
subroutine finalize (this)
 

Function/Subroutine Documentation

◆ finalize()

subroutine headfilereadermodule::finalize ( class(headfilereadertype this)

Definition at line 130 of file HeadFileReader.f90.

131  class(HeadFileReaderType) :: this
132  close (this%inunit)
133  if (allocated(this%head)) deallocate (this%head)

◆ initialize()

subroutine headfilereadermodule::initialize ( class(headfilereadertype this,
integer(i4b), intent(in)  iu,
integer(i4b), intent(in)  iout 
)
private

Definition at line 38 of file HeadFileReader.f90.

39  ! -- dummy
40  class(HeadFileReaderType) :: this
41  integer(I4B), intent(in) :: iu
42  integer(I4B), intent(in) :: iout
43  ! -- local
44  integer(I4B) :: kstp_last, kper_last
45  logical :: success
46  this%inunit = iu
47  this%endoffile = .false.
48  this%nlay = 0
49  !
50  ! -- Read the first head data record to set kstp_last, kstp_last
51  call this%read_record(success)
52  kstp_last = this%kstp
53  kper_last = this%kper
54  rewind(this%inunit)
55  !
56  ! -- Determine number of records within a time step
57  if (iout > 0) &
58  write (iout, '(a)') &
59  'Reading binary file to determine number of records per time step.'
60  do
61  call this%read_record(success, iout)
62  if (.not. success) exit
63  if (kstp_last /= this%kstp .or. kper_last /= this%kper) exit
64  this%nlay = this%nlay + 1
65  end do
66  rewind(this%inunit)
67  if (iout > 0) &
68  write (iout, '(a, i0, a)') 'Detected ', this%nlay, &
69  ' unique records in binary file.'

◆ read_record()

subroutine headfilereadermodule::read_record ( class(headfilereadertype this,
logical, intent(out)  success,
integer(i4b), intent(in), optional  iout_opt 
)
private

Definition at line 74 of file HeadFileReader.f90.

75  ! -- modules
77  ! -- dummy
78  class(HeadFileReaderType) :: this
79  logical, intent(out) :: success
80  integer(I4B), intent(in), optional :: iout_opt
81  ! -- local
82  integer(I4B) :: iostat, iout
83  integer(I4B) :: ncol, nrow, ilay
84  !
85  if (present(iout_opt)) then
86  iout = iout_opt
87  else
88  iout = 0
89  end if
90  !
91  this%kstp = 0
92  this%kper = 0
93  success = .true.
94  this%kstpnext = 0
95  this%kpernext = 0
96  read (this%inunit, iostat=iostat) this%kstp, this%kper, this%pertim, &
97  this%totim, this%text, ncol, nrow, ilay
98  if (iostat /= 0) then
99  success = .false.
100  if (iostat < 0) this%endoffile = .true.
101  return
102  end if
103  !
104  ! -- allocate head to proper size
105  if (.not. allocated(this%head)) then
106  allocate (this%head(ncol * nrow))
107  else
108  if (size(this%head) /= ncol * nrow) then
109  deallocate (this%head)
110  allocate (this%head(ncol * nrow))
111  end if
112  end if
113  !
114  ! -- read the head array
115  read (this%inunit) this%head
116  !
117  ! -- look ahead to next kstp and kper, then backup if read successfully
118  if (.not. this%endoffile) then
119  read (this%inunit, iostat=iostat) this%kstpnext, this%kpernext
120  if (iostat == 0) then
121  call fseek_stream(this%inunit, -2 * i4b, 1, iostat)
122  else if (iostat < 0) then
123  this%endoffile = .true.
124  end if
125  end if
subroutine, public fseek_stream(iu, offset, whence, status)
Move the file pointer.
Here is the call graph for this function: