14 character(len=16) :: budtxt
15 integer(I4B) :: nval, idum1, idum2, imeth
17 character(len=16) :: srcmodelname, srcpackagename
18 character(len=16) :: dstmodelname, dstpackagename
19 integer(I4B) :: ndat, naux, nlist
20 character(len=16),
dimension(:),
allocatable :: auxtxt
26 logical :: hasimeth1flowja = .false.
27 integer(I4B) :: nbudterms
28 character(len=16),
dimension(:),
allocatable :: budtxtarray
29 integer(I4B),
dimension(:),
allocatable :: imetharray
30 integer(I4B),
dimension(:),
allocatable :: nauxarray
31 character(len=16),
dimension(:, :),
allocatable :: auxtxtarray
32 real(dp),
dimension(:),
allocatable :: flowja
33 integer(I4B),
dimension(:),
allocatable :: nodesrc
34 integer(I4B),
dimension(:),
allocatable :: nodedst
35 real(dp),
dimension(:),
allocatable :: flow
36 real(dp),
dimension(:, :),
allocatable :: auxvar
37 character(len=16),
dimension(:),
allocatable :: dstpackagenamearray
53 integer(I4B),
intent(in) :: iu
54 integer(I4B),
intent(in) :: iout
55 integer(I4B),
intent(out) :: ncrbud
57 integer(I4B) :: ibudterm
58 integer(I4B) :: kstp_last, kper_last
59 integer(I4B) :: maxaux
71 'Reading budget file to determine number of terms per time step.'
75 call this%read_record(success)
76 if (.not. success)
exit
77 this%nbudterms = this%nbudterms + 1
78 select type (h => this%header)
80 if (h%naux > maxaux) maxaux = h%naux
83 if (this%endoffile)
exit
84 if (this%header%kstp /= this%headernext%kstp .or. &
85 this%header%kper /= this%headernext%kper) &
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(:, :) =
''
99 do ibudterm = 1, this%nbudterms
100 call this%read_record(success, iout)
101 if (.not. success)
exit
102 select type (h => this%header)
104 this%budtxtarray(ibudterm) = h%budtxt
105 this%imetharray(ibudterm) = h%imeth
106 this%dstpackagenamearray(ibudterm) = h%dstpackagename
107 this%nauxarray(ibudterm) = h%naux
109 this%auxtxtarray(1:h%naux, ibudterm) = h%auxtxt(:)
111 if (h%srcmodelname == h%dstmodelname)
then
112 if (
allocated(this%nodesrc)) ncrbud = max(ncrbud, maxval(this%nodesrc))
118 write (iout,
'(a, i0, a)')
'Detected ', this%nbudterms, &
119 ' unique flow terms in budget file.'
127 logical,
intent(out) :: success
128 integer(I4B),
intent(in),
optional :: iout
130 integer(I4B) :: iostat, pos
131 character(len=LINELENGTH) :: errmsg
134 select type (h => this%header)
144 h%srcpackagename =
''
146 h%dstpackagename =
''
150 if (
allocated(h%auxtxt))
deallocate (h%auxtxt)
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
157 if (iostat < 0) this%endoffile = .true.
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
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)
175 write (errmsg,
'(a, i0)')
'INVALID METHOD CODE DETECTED: ', h%imeth
180 inquire (unit=this%inunit, pos=pos)
181 this%header%size = pos - this%header%pos
191 logical,
intent(out) :: success
192 integer(I4B),
intent(in),
optional :: iout
194 integer(I4B) :: i, n, iout_opt
196 if (
present(iout))
then
202 call this%read_header(success, iout_opt)
203 if (.not. success)
return
205 select type (h => this%header)
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.
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
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)
237 if (iout_opt > 0)
then
238 write (iout_opt,
'(1pg15.6, a, 1x, a)') h%totim, h%budtxt, &
243 call this%peek_record()
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)
263 character(len=:),
allocatable :: str
264 character(len=LENHUGELINE) :: temp
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, &
293 this%endoffile = .false.
294 if (
allocated(this%header))
deallocate (this%header)
295 if (
allocated(this%headernext))
deallocate (this%headernext)
299 this%headernext%pos = 1
subroutine read_header(this, success, iout)
character(len=:) function, allocatable get_str(this)
Get a string representation of the budget file header.
subroutine read_record(this, success, iout)
subroutine finalize(this)
subroutine initialize(this, iu, iout, ncrbud)
This module contains simulation constants.
integer(i4b), parameter linelength
maximum length of a standard line
integer(i4b), parameter lenhugeline
maximum length of a huge line
This module defines variable data types.
This module contains simulation methods.
subroutine, public store_error(msg, terminate)
Store an error message.
subroutine, public store_error_unit(iunit, terminate)
Store the file unit number.