MODFLOW 6  version 6.7.0.dev2
USGS Modular Hydrologic Model
budgetfilereadermodule Module Reference

Data Types

type  budgetfileheadertype
 
type  budgetfilereadertype
 

Functions/Subroutines

subroutine initialize (this, iu, iout, ncrbud)
 
subroutine read_header (this, success, iout)
 
subroutine read_record (this, success, iout)
 
subroutine finalize (this)
 
character(len=:) function, allocatable get_str (this)
 Get a string representation of the budget file header. More...
 
subroutine rewind (this)
 

Function/Subroutine Documentation

◆ finalize()

subroutine budgetfilereadermodule::finalize ( class(budgetfilereadertype this)

Definition at line 248 of file BudgetFileReader.f90.

249  class(BudgetFileReaderType) :: this
250  close (this%inunit)
251  if (allocated(this%flowja)) deallocate (this%flowja)
252  if (allocated(this%nodesrc)) deallocate (this%nodesrc)
253  if (allocated(this%nodedst)) deallocate (this%nodedst)
254  if (allocated(this%flow)) deallocate (this%flow)
255  if (allocated(this%auxvar)) deallocate (this%auxvar)
256  if (allocated(this%header)) deallocate (this%header)
257  if (allocated(this%headernext)) deallocate (this%headernext)

◆ get_str()

character(len=:) function, allocatable budgetfilereadermodule::get_str ( class(budgetfileheadertype), intent(in)  this)
private

Definition at line 261 of file BudgetFileReader.f90.

262  class(BudgetFileHeaderType), intent(in) :: this
263  character(len=:), allocatable :: str
264  character(len=LENHUGELINE) :: temp
265 
266  write (temp, '(*(G0))') &
267  'Budget file header (pos: ', this%pos, &
268  ', kper: ', this%kper, &
269  ', kstp: ', this%kstp, &
270  ', delt: ', this%delt, &
271  ', pertim: ', this%pertim, &
272  ', totim: ', this%totim, &
273  ', budtxt: ', trim(this%budtxt), &
274  ', nval: ', this%nval, &
275  ', idum1: ', this%idum1, &
276  ', idum2: ', this%idum2, &
277  ', imeth: ', this%imeth, &
278  ', srcmodel: ', trim(this%srcmodelname), &
279  ', srcpackage: ', trim(this%srcpackagename), &
280  ', dstmodel: ', trim(this%dstmodelname), &
281  ', dstpackage: ', trim(this%dstpackagename), &
282  ', ndat: ', this%ndat, &
283  ', naux: ', this%naux, &
284  ', nlist: ', this%nlist, &
285  ')'
286  str = trim(temp)

◆ 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 50 of file BudgetFileReader.f90.

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

◆ read_header()

subroutine budgetfilereadermodule::read_header ( class(budgetfilereadertype), intent(inout)  this,
logical, intent(out)  success,
integer(i4b), intent(in), optional  iout 
)
private

Definition at line 124 of file BudgetFileReader.f90.

125  ! -- dummy
126  class(BudgetFileReaderType), intent(inout) :: this
127  logical, intent(out) :: success
128  integer(I4B), intent(in), optional :: iout
129  ! -- local
130  integer(I4B) :: iostat, pos
131  character(len=LINELENGTH) :: errmsg
132  !
133  success = .true.
134  select type (h => this%header)
135  type is (budgetfileheadertype)
136  h%kstp = 0
137  h%kper = 0
138  h%budtxt = ''
139  h%nval = 0
140  h%idum1 = 0
141  h%idum2 = 0
142  h%imeth = 0
143  h%srcmodelname = ''
144  h%srcpackagename = ''
145  h%dstmodelname = ''
146  h%dstpackagename = ''
147  h%ndat = 0
148  h%naux = 0
149  h%nlist = 0
150  if (allocated(h%auxtxt)) deallocate (h%auxtxt)
151 
152  inquire (unit=this%inunit, pos=h%pos)
153  read (this%inunit, iostat=iostat) h%kstp, h%kper, &
154  h%budtxt, h%nval, h%idum1, h%idum2
155  if (iostat /= 0) then
156  success = .false.
157  if (iostat < 0) this%endoffile = .true.
158  return
159  end if
160  read (this%inunit) h%imeth, h%delt, h%pertim, h%totim
161  if (h%imeth == 6) then
162  read (this%inunit) h%srcmodelname
163  read (this%inunit) h%srcpackagename
164  read (this%inunit) h%dstmodelname
165  read (this%inunit) h%dstpackagename
166  read (this%inunit) h%ndat
167  h%naux = h%ndat - 1
168  if (allocated(h%auxtxt)) deallocate (h%auxtxt)
169  allocate (h%auxtxt(h%naux))
170  read (this%inunit) h%auxtxt
171  read (this%inunit) h%nlist
172  elseif (h%imeth /= 1) then
173  write (errmsg, '(a, a)') 'ERROR READING: ', trim(h%budtxt)
174  call store_error(errmsg)
175  write (errmsg, '(a, i0)') 'INVALID METHOD CODE DETECTED: ', h%imeth
176  call store_error(errmsg)
177  call store_error_unit(this%inunit)
178  end if
179  end select
180  inquire (unit=this%inunit, pos=pos)
181  this%header%size = pos - this%header%pos
Here is the call graph for this function:

◆ read_record()

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

Definition at line 186 of file BudgetFileReader.f90.

187  ! -- modules
189  ! -- dummy
190  class(BudgetFileReaderType), intent(inout) :: this
191  logical, intent(out) :: success
192  integer(I4B), intent(in), optional :: iout
193  ! -- local
194  integer(I4B) :: i, n, iout_opt
195  !
196  if (present(iout)) then
197  iout_opt = iout
198  else
199  iout_opt = 0
200  end if
201  !
202  call this%read_header(success, iout_opt)
203  if (.not. success) return
204  !
205  select type (h => this%header)
206  type is (budgetfileheadertype)
207  if (h%imeth == 1) then
208  if (trim(adjustl(h%budtxt)) == 'FLOW-JA-FACE') then
209  if (allocated(this%flowja)) deallocate (this%flowja)
210  allocate (this%flowja(h%nval))
211  read (this%inunit) this%flowja
212  this%hasimeth1flowja = .true.
213  else
214  h%nval = h%nval * h%idum1 * abs(h%idum2)
215  if (allocated(this%flow)) deallocate (this%flow)
216  allocate (this%flow(h%nval))
217  if (allocated(this%nodesrc)) deallocate (this%nodesrc)
218  allocate (this%nodesrc(h%nval))
219  read (this%inunit) this%flow
220  do i = 1, h%nval
221  this%nodesrc(i) = i
222  end do
223  end if
224  elseif (h%imeth == 6) then
225  if (allocated(this%nodesrc)) deallocate (this%nodesrc)
226  allocate (this%nodesrc(h%nlist))
227  if (allocated(this%nodedst)) deallocate (this%nodedst)
228  allocate (this%nodedst(h%nlist))
229  if (allocated(this%flow)) deallocate (this%flow)
230  allocate (this%flow(h%nlist))
231  if (allocated(this%auxvar)) deallocate (this%auxvar)
232  allocate (this%auxvar(h%naux, h%nlist))
233  read (this%inunit) (this%nodesrc(n), this%nodedst(n), this%flow(n), &
234  (this%auxvar(i, n), i=1, h%naux), n=1, h%nlist)
235  end if
236 
237  if (iout_opt > 0) then
238  write (iout_opt, '(1pg15.6, a, 1x, a)') h%totim, h%budtxt, &
239  h%dstpackagename
240  end if
241  end select
242  !
243  call this%peek_record()
subroutine, public fseek_stream(iu, offset, whence, status)
Move the file pointer.
Here is the call graph for this function:

◆ rewind()

subroutine budgetfilereadermodule::rewind ( class(budgetfilereadertype), intent(inout)  this)
private

Definition at line 289 of file BudgetFileReader.f90.

290  class(BudgetFileReaderType), intent(inout) :: this
291 
292  rewind(this%inunit)
293  this%endoffile = .false.
294  if (allocated(this%header)) deallocate (this%header)
295  if (allocated(this%headernext)) deallocate (this%headernext)
296  allocate (budgetfileheadertype :: this%header)
297  allocate (budgetfileheadertype :: this%headernext)
298  this%header%pos = 1
299  this%headernext%pos = 1