MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
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 243 of file BudgetFileReader.f90.

244 ! ******************************************************************************
245 ! budgetdata_finalize
246 ! ******************************************************************************
247 !
248 ! SPECIFICATIONS:
249 ! ------------------------------------------------------------------------------
250  class(BudgetFileReaderType) :: this
251 ! ------------------------------------------------------------------------------
252  close (this%inunit)
253  if (allocated(this%auxtxt)) deallocate (this%auxtxt)
254  if (allocated(this%flowja)) deallocate (this%flowja)
255  if (allocated(this%nodesrc)) deallocate (this%nodesrc)
256  if (allocated(this%nodedst)) deallocate (this%nodedst)
257  if (allocated(this%flow)) deallocate (this%flow)
258  if (allocated(this%auxvar)) deallocate (this%auxvar)
259  !
260  ! -- return
261  return

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

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

◆ read_record()

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

Definition at line 131 of file BudgetFileReader.f90.

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