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
132 character(len=LINELENGTH) :: errmsg
135 select type (h => this%header)
145 h%srcpackagename =
''
147 h%dstpackagename =
''
151 if (
allocated(h%auxtxt))
deallocate (h%auxtxt)
153 inquire (unit=this%inunit, pos=h%pos)
154 read (this%inunit, iostat=iostat) h%kstp, h%kper, &
155 h%budtxt, h%nval, h%idum1, h%idum2
156 if (iostat /= 0)
then
158 if (iostat < 0) this%endoffile = .true.
161 read (this%inunit) h%imeth, h%delt, h%pertim, h%totim
162 if (h%imeth == 6)
then
163 read (this%inunit) h%srcmodelname
164 read (this%inunit) h%srcpackagename
165 read (this%inunit) h%dstmodelname
166 read (this%inunit) h%dstpackagename
167 read (this%inunit) h%ndat
169 if (
allocated(h%auxtxt))
deallocate (h%auxtxt)
170 allocate (h%auxtxt(h%naux))
171 read (this%inunit) h%auxtxt
172 read (this%inunit) h%nlist
173 elseif (h%imeth /= 1)
then
174 write (errmsg,
'(a, a)')
'ERROR READING: ', trim(h%budtxt)
176 write (errmsg,
'(a, i0)')
'INVALID METHOD CODE DETECTED: ', h%imeth
181 inquire (unit=this%inunit, pos=pos)
182 this%header%size = pos - this%header%pos
192 logical,
intent(out) :: success
193 integer(I4B),
intent(in),
optional :: iout
195 integer(I4B) :: i, n, iout_opt
197 if (
present(iout))
then
203 call this%read_header(success, iout_opt)
204 if (.not. success)
return
206 select type (h => this%header)
208 if (h%imeth == 1)
then
209 if (trim(adjustl(h%budtxt)) ==
'FLOW-JA-FACE')
then
210 if (
allocated(this%flowja))
deallocate (this%flowja)
211 allocate (this%flowja(h%nval))
212 read (this%inunit) this%flowja
213 this%hasimeth1flowja = .true.
215 h%nval = h%nval * h%idum1 * abs(h%idum2)
216 if (
allocated(this%flow))
deallocate (this%flow)
217 allocate (this%flow(h%nval))
218 if (
allocated(this%nodesrc))
deallocate (this%nodesrc)
219 allocate (this%nodesrc(h%nval))
220 read (this%inunit) this%flow
225 elseif (h%imeth == 6)
then
226 if (
allocated(this%nodesrc))
deallocate (this%nodesrc)
227 allocate (this%nodesrc(h%nlist))
228 if (
allocated(this%nodedst))
deallocate (this%nodedst)
229 allocate (this%nodedst(h%nlist))
230 if (
allocated(this%flow))
deallocate (this%flow)
231 allocate (this%flow(h%nlist))
232 if (
allocated(this%auxvar))
deallocate (this%auxvar)
233 allocate (this%auxvar(h%naux, h%nlist))
234 read (this%inunit) (this%nodesrc(n), this%nodedst(n), this%flow(n), &
235 (this%auxvar(i, n), i=1, h%naux), n=1, h%nlist)
238 if (iout_opt > 0)
then
239 write (iout_opt,
'(1pg15.6, a, 1x, a)') h%totim, h%budtxt, &
244 call this%peek_record()
252 if (
allocated(this%flowja))
deallocate (this%flowja)
253 if (
allocated(this%nodesrc))
deallocate (this%nodesrc)
254 if (
allocated(this%nodedst))
deallocate (this%nodedst)
255 if (
allocated(this%flow))
deallocate (this%flow)
256 if (
allocated(this%auxvar))
deallocate (this%auxvar)
257 if (
allocated(this%header))
deallocate (this%header)
258 if (
allocated(this%headernext))
deallocate (this%headernext)
264 character(len=:),
allocatable :: str
265 character(len=LENHUGELINE) :: temp
267 write (temp,
'(*(G0))') &
268 'Budget file header (pos: ', this%pos, &
269 ', kper: ', this%kper, &
270 ', kstp: ', this%kstp, &
271 ', delt: ', this%delt, &
272 ', pertim: ', this%pertim, &
273 ', totim: ', this%totim, &
274 ', budtxt: ', trim(this%budtxt), &
275 ', nval: ', this%nval, &
276 ', idum1: ', this%idum1, &
277 ', idum2: ', this%idum2, &
278 ', imeth: ', this%imeth, &
279 ', srcmodel: ', trim(this%srcmodelname), &
280 ', srcpackage: ', trim(this%srcpackagename), &
281 ', dstmodel: ', trim(this%dstmodelname), &
282 ', dstpackage: ', trim(this%dstpackagename), &
283 ', ndat: ', this%ndat, &
284 ', naux: ', this%naux, &
285 ', nlist: ', this%nlist, &
294 this%endoffile = .false.
295 if (
allocated(this%header))
deallocate (this%header)
296 if (
allocated(this%headernext))
deallocate (this%headernext)
300 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.