51
52 class(BudgetFileReaderType) :: this
53 integer(I4B), intent(in) :: iu
54 integer(I4B), intent(in) :: iout
55 integer(I4B), intent(out) :: ncrbud
56
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
69 if (iout > 0) &
70 write (iout, '(a)') &
71 'Reading budget file to determine number of terms per time step.'
72
73
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
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.'