MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
HeadFileReader.f90
Go to the documentation of this file.
2 
3  use kindmodule
4  use constantsmodule, only: linelength
5 
6  implicit none
7 
8  private
9  public :: headfilereadertype
10 
12 
13  integer(I4B) :: inunit
14  character(len=16) :: text
15  integer(I4B) :: nlay
16  integer(I4B) :: kstp
17  integer(I4B) :: kper
18  integer(I4B) :: kstpnext
19  integer(I4B) :: kpernext
20  logical :: endoffile
21  real(dp) :: delt
22  real(dp) :: pertim
23  real(dp) :: totim
24  real(dp), dimension(:), allocatable :: head
25 
26  contains
27 
28  procedure :: initialize
29  procedure :: read_record
30  procedure :: finalize
31 
32  end type headfilereadertype
33 
34 contains
35 
36  subroutine initialize(this, iu, iout)
37 ! ******************************************************************************
38 ! initialize
39 ! ******************************************************************************
40 !
41 ! SPECIFICATIONS:
42 ! ------------------------------------------------------------------------------
43  ! -- dummy
44  class(headfilereadertype) :: this
45  integer(I4B), intent(in) :: iu
46  integer(I4B), intent(in) :: iout
47  ! -- local
48  integer(I4B) :: kstp_last, kper_last
49  logical :: success
50 ! ------------------------------------------------------------------------------
51  this%inunit = iu
52  this%endoffile = .false.
53  this%nlay = 0
54  !
55  ! -- Read the first head data record to set kstp_last, kstp_last
56  call this%read_record(success)
57  kstp_last = this%kstp
58  kper_last = this%kper
59  rewind(this%inunit)
60  !
61  ! -- Determine number of records within a time step
62  if (iout > 0) &
63  write (iout, '(a)') &
64  'Reading binary file to determine number of records per time step.'
65  do
66  call this%read_record(success, iout)
67  if (.not. success) exit
68  if (kstp_last /= this%kstp .or. kper_last /= this%kper) exit
69  this%nlay = this%nlay + 1
70  end do
71  rewind(this%inunit)
72  if (iout > 0) &
73  write (iout, '(a, i0, a)') 'Detected ', this%nlay, &
74  ' unique records in binary file.'
75  !
76  ! -- return
77  return
78  end subroutine initialize
79 
80  subroutine read_record(this, success, iout_opt)
81 ! ******************************************************************************
82 ! read_record
83 ! ******************************************************************************
84 !
85 ! SPECIFICATIONS:
86 ! ------------------------------------------------------------------------------
87  ! -- modules
89  ! -- dummy
90  class(headfilereadertype) :: this
91  logical, intent(out) :: success
92  integer(I4B), intent(in), optional :: iout_opt
93  ! -- local
94  integer(I4B) :: iostat, iout
95  integer(I4B) :: ncol, nrow, ilay
96 ! ------------------------------------------------------------------------------
97  !
98  if (present(iout_opt)) then
99  iout = iout_opt
100  else
101  iout = 0
102  end if
103  !
104  this%kstp = 0
105  this%kper = 0
106  success = .true.
107  this%kstpnext = 0
108  this%kpernext = 0
109  read (this%inunit, iostat=iostat) this%kstp, this%kper, this%pertim, &
110  this%totim, this%text, ncol, nrow, ilay
111  if (iostat /= 0) then
112  success = .false.
113  if (iostat < 0) this%endoffile = .true.
114  return
115  end if
116  !
117  ! -- allocate head to proper size
118  if (.not. allocated(this%head)) then
119  allocate (this%head(ncol * nrow))
120  else
121  if (size(this%head) /= ncol * nrow) then
122  deallocate (this%head)
123  allocate (this%head(ncol * nrow))
124  end if
125  end if
126  !
127  ! -- read the head array
128  read (this%inunit) this%head
129  !
130  ! -- look ahead to next kstp and kper, then backup if read successfully
131  if (.not. this%endoffile) then
132  read (this%inunit, iostat=iostat) this%kstpnext, this%kpernext
133  if (iostat == 0) then
134  call fseek_stream(this%inunit, -2 * i4b, 1, iostat)
135  else if (iostat < 0) then
136  this%endoffile = .true.
137  end if
138  end if
139  !
140  ! -- return
141  return
142  end subroutine read_record
143 
144  subroutine finalize(this)
145 ! ******************************************************************************
146 ! budgetdata_finalize
147 ! ******************************************************************************
148 !
149 ! SPECIFICATIONS:
150 ! ------------------------------------------------------------------------------
151  class(headfilereadertype) :: this
152 ! ------------------------------------------------------------------------------
153  close (this%inunit)
154  if (allocated(this%head)) deallocate (this%head)
155  !
156  ! -- return
157  return
158  end subroutine finalize
159 
160 end module headfilereadermodule
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition: Constants.f90:44
subroutine finalize(this)
subroutine read_record(this, success, iout_opt)
subroutine initialize(this, iu, iout)
subroutine, public fseek_stream(iu, offset, whence, status)
Move the file pointer.
This module defines variable data types.
Definition: kind.f90:8