MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
budgetfilereadermodule Module Reference

Data Types

type  budgetfilereadertype
 

Functions/Subroutines

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

Function/Subroutine Documentation

◆ finalize()

subroutine budgetfilereadermodule::finalize ( class(budgetfilereadertype this)

Definition at line 229 of file BudgetFileReader.f90.

230  class(BudgetFileReaderType) :: this
231  close (this%inunit)
232  if (allocated(this%auxtxt)) deallocate (this%auxtxt)
233  if (allocated(this%flowja)) deallocate (this%flowja)
234  if (allocated(this%nodesrc)) deallocate (this%nodesrc)
235  if (allocated(this%nodedst)) deallocate (this%nodedst)
236  if (allocated(this%flow)) deallocate (this%flow)
237  if (allocated(this%auxvar)) deallocate (this%auxvar)

◆ initialize()

subroutine budgetfilereadermodule::initialize ( class(budgetfilereadertype this,
integer(i4b), intent(in)  iu,
integer(i4b), intent(in)  iout,
integer(i4b), intent(out)  ncrbud 
)
private

Definition at line 61 of file BudgetFileReader.f90.

62  ! -- dummy
63  class(BudgetFileReaderType) :: this
64  integer(I4B), intent(in) :: iu
65  integer(I4B), intent(in) :: iout
66  integer(I4B), intent(out) :: ncrbud
67  ! -- local
68  integer(I4B) :: ibudterm
69  integer(I4B) :: kstp_last, kper_last
70  integer(I4B) :: maxaux
71  logical :: success
72  this%inunit = iu
73  this%endoffile = .false.
74  this%nbudterms = 0
75  ncrbud = 0
76  maxaux = 0
77  !
78  ! -- Determine number of budget terms within a time step
79  if (iout > 0) &
80  write (iout, '(a)') &
81  'Reading budget file to determine number of terms per time step.'
82  !
83  ! -- Read through the first set of data for time step 1 and stress period 1
84  do
85  call this%read_record(success)
86  if (.not. success) exit
87  this%nbudterms = this%nbudterms + 1
88  if (this%naux > maxaux) maxaux = this%naux
89  if (this%kstp /= this%kstpnext .or. this%kper /= this%kpernext) &
90  exit
91  end do
92  kstp_last = this%kstp
93  kper_last = this%kper
94  allocate (this%budtxtarray(this%nbudterms))
95  allocate (this%imetharray(this%nbudterms))
96  allocate (this%dstpackagenamearray(this%nbudterms))
97  allocate (this%nauxarray(this%nbudterms))
98  allocate (this%auxtxtarray(maxaux, this%nbudterms))
99  this%auxtxtarray(:, :) = ''
100  rewind(this%inunit)
101  !
102  ! -- Now read through again and store budget text names
103  do ibudterm = 1, this%nbudterms
104  call this%read_record(success, iout)
105  if (.not. success) exit
106  this%budtxtarray(ibudterm) = this%budtxt
107  this%imetharray(ibudterm) = this%imeth
108  this%dstpackagenamearray(ibudterm) = this%dstpackagename
109  this%nauxarray(ibudterm) = this%naux
110  if (this%naux > 0) then
111  this%auxtxtarray(1:this%naux, ibudterm) = this%auxtxt(:)
112  end if
113  if (this%srcmodelname == this%dstmodelname) then
114  if (allocated(this%nodesrc)) ncrbud = max(ncrbud, maxval(this%nodesrc))
115  end if
116  end do
117  rewind(this%inunit)
118  if (iout > 0) &
119  write (iout, '(a, i0, a)') 'Detected ', this%nbudterms, &
120  ' unique flow terms in budget file.'

◆ read_record()

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

Definition at line 125 of file BudgetFileReader.f90.

126  ! -- modules
128  ! -- dummy
129  class(BudgetFileReaderType) :: this
130  logical, intent(out) :: success
131  integer(I4B), intent(in), optional :: iout_opt
132  ! -- local
133  integer(I4B) :: i, n, iostat, iout
134  character(len=LINELENGTH) :: errmsg
135  !
136  if (present(iout_opt)) then
137  iout = iout_opt
138  else
139  iout = 0
140  end if
141  !
142  this%kstp = 0
143  this%kper = 0
144  this%budtxt = ''
145  this%nval = 0
146  this%naux = 0
147  this%idum1 = 0
148  this%idum2 = 0
149  this%srcmodelname = ''
150  this%srcpackagename = ''
151  this%dstmodelname = ''
152  this%dstpackagename = ''
153 
154  success = .true.
155  this%kstpnext = 0
156  this%kpernext = 0
157  read (this%inunit, iostat=iostat) this%kstp, this%kper, this%budtxt, &
158  this%nval, this%idum1, this%idum2
159  if (iostat /= 0) then
160  success = .false.
161  if (iostat < 0) this%endoffile = .true.
162  return
163  end if
164  read (this%inunit) this%imeth, this%delt, this%pertim, this%totim
165  if (this%imeth == 1) then
166  if (trim(adjustl(this%budtxt)) == 'FLOW-JA-FACE') then
167  if (allocated(this%flowja)) deallocate (this%flowja)
168  allocate (this%flowja(this%nval))
169  read (this%inunit) this%flowja
170  this%hasimeth1flowja = .true.
171  else
172  this%nval = this%nval * this%idum1 * abs(this%idum2)
173  if (allocated(this%flow)) deallocate (this%flow)
174  allocate (this%flow(this%nval))
175  if (allocated(this%nodesrc)) deallocate (this%nodesrc)
176  allocate (this%nodesrc(this%nval))
177  read (this%inunit) this%flow
178  do i = 1, this%nval
179  this%nodesrc(i) = i
180  end do
181  end if
182  elseif (this%imeth == 6) then
183  ! -- method code 6
184  read (this%inunit) this%srcmodelname
185  read (this%inunit) this%srcpackagename
186  read (this%inunit) this%dstmodelname
187  read (this%inunit) this%dstpackagename
188  read (this%inunit) this%ndat
189  this%naux = this%ndat - 1
190  if (allocated(this%auxtxt)) deallocate (this%auxtxt)
191  allocate (this%auxtxt(this%naux))
192  read (this%inunit) this%auxtxt
193  read (this%inunit) this%nlist
194  if (allocated(this%nodesrc)) deallocate (this%nodesrc)
195  allocate (this%nodesrc(this%nlist))
196  if (allocated(this%nodedst)) deallocate (this%nodedst)
197  allocate (this%nodedst(this%nlist))
198  if (allocated(this%flow)) deallocate (this%flow)
199  allocate (this%flow(this%nlist))
200  if (allocated(this%auxvar)) deallocate (this%auxvar)
201  allocate (this%auxvar(this%naux, this%nlist))
202  read (this%inunit) (this%nodesrc(n), this%nodedst(n), this%flow(n), &
203  (this%auxvar(i, n), i=1, this%naux), n=1, this%nlist)
204  else
205  write (errmsg, '(a, a)') 'ERROR READING: ', trim(this%budtxt)
206  call store_error(errmsg)
207  write (errmsg, '(a, i0)') 'INVALID METHOD CODE DETECTED: ', this%imeth
208  call store_error(errmsg)
209  call store_error_unit(this%inunit)
210  end if
211  if (iout > 0) then
212  write (iout, '(1pg15.6, a, 1x, a)') this%totim, this%budtxt, &
213  this%dstpackagename
214  end if
215  !
216  ! -- look ahead to next kstp and kper, then backup if read successfully
217  if (.not. this%endoffile) then
218  read (this%inunit, iostat=iostat) this%kstpnext, this%kpernext
219  if (iostat == 0) then
220  call fseek_stream(this%inunit, -2 * i4b, 1, iostat)
221  else if (iostat < 0) then
222  this%endoffile = .true.
223  end if
224  end if
subroutine, public fseek_stream(iu, offset, whence, status)
Move the file pointer.
Here is the call graph for this function: