MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
budgetobjectmodule Module Reference

Data Types

type  budgetobjecttype
 

Functions/Subroutines

subroutine, public budgetobject_cr (this, name)
 Create a new budget object. More...
 
subroutine budgetobject_df (this, ncv, nbudterm, iflowja, nsto, bddim_opt, labeltitle_opt, bdzone_opt, ibudcsv)
 Define the new budget object. More...
 
subroutine flowtable_df (this, iout, cellids)
 Define the new flow table object. More...
 
subroutine accumulate_terms (this)
 Add up accumulators and submit to budget table. More...
 
subroutine write_flowtable (this, dis, kstp, kper, cellidstr)
 Write the flow table for each advanced package control volume. More...
 
subroutine write_budtable (this, kstp, kper, iout, ibudfl, totim, delt)
 Write the budget table. More...
 
subroutine save_flows (this, dis, ibinun, kstp, kper, delt, pertim, totim, iout)
 Write the budget table. More...
 
subroutine read_flows (this, dis, ibinun)
 Read from a binary file into this BudgetObjectType. More...
 
subroutine budgetobject_da (this)
 Deallocate. More...
 
subroutine, public budgetobject_cr_bfr (this, name, ibinun, iout, colconv1, colconv2)
 Create a new budget object from a binary flow file. More...
 
subroutine bfr_init (this, ibinun, ncv, nbudterm, iout)
 Initialize the budget file reader. More...
 
subroutine bfr_advance (this, dis, iout)
 Advance the binary file readers for setting the budget terms of the next time step. More...
 
subroutine fill_from_bfr (this, dis, iout)
 Copy the information from the binary file into budterms. More...
 

Function/Subroutine Documentation

◆ accumulate_terms()

subroutine budgetobjectmodule::accumulate_terms ( class(budgetobjecttype this)

Definition at line 286 of file BudgetObject.f90.

287  ! -- modules
288  use tdismodule, only: delt
289  ! -- dummy
290  class(BudgetObjectType) :: this
291  ! -- local
292  character(len=LENBUDTXT) :: flowtype
293  integer(I4B) :: i
294  real(DP) :: ratin, ratout
295  !
296  ! -- Reset the budget table
297  call this%budtable%reset()
298  !
299  ! -- Calculate the budget table terms
300  do i = 1, this%nbudterm
301  !
302  ! -- Accumulate positive and negative flows for each budget term
303  flowtype = this%budterm(i)%flowtype
304  select case (trim(adjustl(flowtype)))
305  case ('FLOW-JA-FACE')
306  ! -- Skip
307  case default
308  !
309  ! -- Calculate sum of positive and negative flows
310  call this%budterm(i)%accumulate_flow(ratin, ratout)
311  !
312  ! -- Pass accumulators into the budget table
313  call this%budtable%addentry(ratin, ratout, delt, flowtype)
314  end select
315  end do
316  !
317  ! -- Return
318  return
real(dp), pointer, public delt
length of the current time step
Definition: tdis.f90:29

◆ bfr_advance()

subroutine budgetobjectmodule::bfr_advance ( class(budgetobjecttype this,
class(disbasetype), intent(in)  dis,
integer(i4b), intent(in)  iout 
)

Definition at line 653 of file BudgetObject.f90.

654  ! -- modules
655  use tdismodule, only: kstp, kper
656  ! -- dummy
657  class(BudgetObjectType) :: this
658  class(DisBaseType), intent(in) :: dis
659  integer(I4B), intent(in) :: iout
660  ! -- local
661  logical :: readnext
662  ! -- formats
663  character(len=*), parameter :: fmtkstpkper = &
664  &"(1x,/1x, a, ' READING BUDGET TERMS FOR KSTP ', i0, ' KPER ', i0)"
665  character(len=*), parameter :: fmtbudkstpkper = &
666  "(1x,/1x, a, ' SETTING BUDGET TERMS FOR KSTP ', i0, ' AND KPER ', &
667  &i0, ' TO BUDGET FILE TERMS FROM KSTP ', i0, ' AND KPER ', i0)"
668  !
669  ! -- Do not read the budget if the budget is at end of file or if the next
670  ! record in the budget file is the first timestep of the next stress
671  ! period. Also do not read if it is the very first time step because
672  ! the first chunk of data is read as part of the initialization
673  readnext = .true.
674  if (kstp * kper == 1) then
675  readnext = .false.
676  else if (kstp * kper > 1) then
677  if (this%bfr%endoffile) then
678  readnext = .false.
679  else
680  if (this%bfr%kpernext == kper + 1 .and. this%bfr%kstpnext == 1) &
681  readnext = .false.
682  end if
683  end if
684  !
685  ! -- Read the next record
686  if (readnext) then
687  !
688  ! -- Write the current time step and stress period
689  if (iout > 0) &
690  write (iout, fmtkstpkper) this%name, kstp, kper
691  !
692  ! -- Read flows from the binary file and copy them into this%budterm(:)
693  call this%fill_from_bfr(dis, iout)
694  else
695  if (iout > 0) &
696  write (iout, fmtbudkstpkper) trim(this%name), kstp, kper, &
697  this%bfr%kstp, this%bfr%kper
698  end if
699  !
700  ! -- Return
701  return
integer(i4b), pointer, public kstp
current time step number
Definition: tdis.f90:24
integer(i4b), pointer, public kper
current stress period number
Definition: tdis.f90:23

◆ bfr_init()

subroutine budgetobjectmodule::bfr_init ( class(budgetobjecttype this,
integer(i4b), intent(in)  ibinun,
integer(i4b), intent(inout)  ncv,
integer(i4b), intent(inout)  nbudterm,
integer(i4b), intent(in)  iout 
)

Definition at line 633 of file BudgetObject.f90.

634  ! -- dummy
635  class(BudgetObjectType) :: this
636  integer(I4B), intent(in) :: ibinun
637  integer(I4B), intent(inout) :: ncv
638  integer(I4B), intent(inout) :: nbudterm
639  integer(I4B), intent(in) :: iout
640  !
641  ! -- Initialize budget file reader
642  allocate (this%bfr)
643  call this%bfr%initialize(ibinun, iout, ncv)
644  nbudterm = this%bfr%nbudterms
645  !
646  ! -- Return
647  return

◆ budgetobject_cr()

subroutine, public budgetobjectmodule::budgetobject_cr ( type(budgetobjecttype), pointer  this,
character(len=*), intent(in)  name 
)

Definition at line 82 of file BudgetObject.f90.

83  ! -- dummy
84  type(BudgetObjectType), pointer :: this
85  character(len=*), intent(in) :: name
86  !
87  ! -- Create the object
88  allocate (this)
89  !
90  ! -- Initialize variables
91  this%name = name
92  this%ncv = 0
93  this%nbudterm = 0
94  this%iflowja = 0
95  this%nsto = 0
96  this%iterm = 0
97  !
98  ! -- Initialize budget table
99  call budget_cr(this%budtable, name)
100  !
101  ! -- Return
102  return
Here is the call graph for this function:
Here is the caller graph for this function:

◆ budgetobject_cr_bfr()

subroutine, public budgetobjectmodule::budgetobject_cr_bfr ( type(budgetobjecttype), pointer  this,
character(len=*), intent(in)  name,
integer(i4b), intent(in)  ibinun,
integer(i4b), intent(in)  iout,
character(len=16), dimension(:), optional  colconv1,
character(len=16), dimension(:), optional  colconv2 
)

Definition at line 579 of file BudgetObject.f90.

580  ! -- dummy
581  type(BudgetObjectType), pointer :: this
582  character(len=*), intent(in) :: name
583  integer(I4B), intent(in) :: ibinun
584  integer(I4B), intent(in) :: iout
585  character(len=16), dimension(:), optional :: colconv1
586  character(len=16), dimension(:), optional :: colconv2
587  ! -- local
588  integer(I4B) :: ncv, nbudterm
589  integer(I4B) :: iflowja, nsto
590  integer(I4B) :: i, j
591  !
592  ! -- Create the object
593  call budgetobject_cr(this, name)
594  !
595  ! -- Initialize the budget file reader
596  call this%bfr_init(ibinun, ncv, nbudterm, iout)
597  !
598  ! -- Define this budget object using number of control volumes and number
599  ! of budget terms read from ibinun
600  iflowja = 0
601  nsto = 0
602  call this%budgetobject_df(ncv, nbudterm, iflowja, nsto)
603  !
604  ! -- Set the conversion flags, which cause id1 or id2 to be converted from
605  ! user node numbers to reduced node numbers
606  if (present(colconv1)) then
607  do i = 1, nbudterm
608  do j = 1, size(colconv1)
609  if (colconv1(j) == adjustl(this%bfr%budtxtarray(i))) then
610  this%budterm(i)%olconv1 = .true.
611  exit
612  end if
613  end do
614  end do
615  end if
616  if (present(colconv2)) then
617  do i = 1, nbudterm
618  do j = 1, size(colconv2)
619  if (colconv2(j) == adjustl(this%bfr%budtxtarray(i))) then
620  this%budterm(i)%olconv2 = .true.
621  exit
622  end if
623  end do
624  end do
625  end if
626  !
627  ! -- Return
628  return
Here is the call graph for this function:
Here is the caller graph for this function:

◆ budgetobject_da()

subroutine budgetobjectmodule::budgetobject_da ( class(budgetobjecttype this)

Definition at line 543 of file BudgetObject.f90.

544  ! -- dummy
545  class(BudgetObjectType) :: this
546  ! -- local
547  integer(I4B) :: i
548  !
549  ! -- Save flows for each budget term
550  do i = 1, this%nbudterm
551  call this%budterm(i)%deallocate_arrays()
552  end do
553  !
554  ! -- Destroy the flow table
555  if (associated(this%flowtab)) then
556  deallocate (this%add_cellids)
557  deallocate (this%icellid)
558  deallocate (this%nflowterms)
559  deallocate (this%istart)
560  deallocate (this%iflowterms)
561  call this%flowtab%table_da()
562  deallocate (this%flowtab)
563  nullify (this%flowtab)
564  end if
565  !
566  ! -- Destroy the budget object table
567  if (associated(this%budtable)) then
568  call this%budtable%budget_da()
569  deallocate (this%budtable)
570  nullify (this%budtable)
571  end if
572  !
573  ! -- Return
574  return

◆ budgetobject_df()

subroutine budgetobjectmodule::budgetobject_df ( class(budgetobjecttype this,
integer(i4b), intent(in)  ncv,
integer(i4b), intent(in)  nbudterm,
integer(i4b), intent(in)  iflowja,
integer(i4b), intent(in)  nsto,
character(len=*), optional  bddim_opt,
character(len=*), optional  labeltitle_opt,
character(len=*), optional  bdzone_opt,
integer(i4b), intent(in), optional  ibudcsv 
)

Definition at line 107 of file BudgetObject.f90.

110  ! -- dummy
111  class(BudgetObjectType) :: this
112  integer(I4B), intent(in) :: ncv
113  integer(I4B), intent(in) :: nbudterm
114  integer(I4B), intent(in) :: iflowja
115  integer(I4B), intent(in) :: nsto
116  character(len=*), optional :: bddim_opt
117  character(len=*), optional :: labeltitle_opt
118  character(len=*), optional :: bdzone_opt
119  integer(I4B), intent(in), optional :: ibudcsv
120  ! -- local
121  character(len=20) :: bdtype
122  character(len=5) :: bddim
123  character(len=16) :: labeltitle
124  character(len=20) :: bdzone
125  !
126  ! -- Set values
127  this%ncv = ncv
128  this%nbudterm = nbudterm
129  this%iflowja = iflowja
130  this%nsto = nsto
131  !
132  ! -- Allocate space for budterm
133  allocate (this%budterm(nbudterm))
134  !
135  ! -- Set the budget type to name
136  bdtype = this%name
137  !
138  ! -- Set the budget dimension
139  if (present(bddim_opt)) then
140  bddim = bddim_opt
141  else
142  bddim = 'L**3'
143  end if
144  !
145  ! -- Set the budget zone
146  if (present(bdzone_opt)) then
147  bdzone = bdzone_opt
148  else
149  bdzone = 'ENTIRE MODEL'
150  end if
151  !
152  ! -- Set the label title
153  if (present(labeltitle_opt)) then
154  labeltitle = labeltitle_opt
155  else
156  labeltitle = 'PACKAGE NAME'
157  end if
158  !
159  ! -- Setup the budget table object
160  call this%budtable%budget_df(nbudterm, bdtype, bddim, labeltitle, bdzone)
161  !
162  ! -- Trigger csv output
163  if (present(ibudcsv)) then
164  call this%budtable%set_ibudcsv(ibudcsv)
165  end if
166  !
167  ! -- Return
168  return

◆ fill_from_bfr()

subroutine budgetobjectmodule::fill_from_bfr ( class(budgetobjecttype this,
class(disbasetype), intent(in)  dis,
integer(i4b), intent(in)  iout 
)

Definition at line 706 of file BudgetObject.f90.

707  ! -- dummy
708  class(BudgetObjectType) :: this
709  class(DisBaseType), intent(in) :: dis
710  integer(I4B), intent(in) :: iout
711  ! -- local
712  integer(I4B) :: i
713  logical :: success
714  !
715  ! -- Read flows from the binary file and copy them into this%budterm(:)
716  do i = 1, this%nbudterm
717  call this%bfr%read_record(success, iout)
718  call this%budterm(i)%fill_from_bfr(this%bfr, dis)
719  end do
720  !
721  ! -- Return
722  return

◆ flowtable_df()

subroutine budgetobjectmodule::flowtable_df ( class(budgetobjecttype this,
integer(i4b), intent(in)  iout,
character(len=*), intent(in), optional  cellids 
)

Definition at line 173 of file BudgetObject.f90.

174  ! -- dummy
175  class(BudgetObjectType) :: this
176  integer(I4B), intent(in) :: iout
177  character(len=*), intent(in), optional :: cellids
178  ! -- local
179  character(len=LINELENGTH) :: title
180  character(len=LINELENGTH) :: text
181  character(len=LENBUDTXT) :: flowtype
182  character(len=LENBUDTXT) :: tag
183  character(len=LENBUDTXT) :: coupletype
184  logical :: lfound
185  logical :: add_cellids
186  integer(I4B) :: maxcol
187  integer(I4B) :: idx
188  integer(I4B) :: ipos
189  integer(I4B) :: i
190  !
191  ! -- Process optional variables
192  if (present(cellids)) then
193  add_cellids = .true.
194  coupletype = cellids
195  else
196  add_cellids = .false.
197  end if
198  !
199  ! -- Allocate scalars
200  allocate (this%add_cellids)
201  allocate (this%icellid)
202  allocate (this%nflowterms)
203  !
204  ! -- Initialize scalars
205  this%add_cellids = add_cellids
206  this%nflowterms = 0
207  this%icellid = 0
208  !
209  ! -- Determine the number of columns in the table
210  maxcol = 3
211  if (add_cellids) then
212  maxcol = maxcol + 1
213  end if
214  do i = 1, this%nbudterm
215  lfound = .false.
216  flowtype = this%budterm(i)%get_flowtype()
217  if (trim(adjustl(flowtype)) == 'FLOW-JA-FACE') then
218  lfound = .true.
219  maxcol = maxcol + 2
220  else if (trim(adjustl(flowtype)) /= 'AUXILIARY') then
221  lfound = .true.
222  maxcol = maxcol + 1
223  end if
224  if (lfound) then
225  this%nflowterms = this%nflowterms + 1
226  if (add_cellids) then
227  if (trim(adjustl(flowtype)) == trim(adjustl(coupletype))) then
228  this%icellid = i
229  end if
230  end if
231  end if
232  end do
233  !
234  ! -- Allocate arrays
235  allocate (this%istart(this%nflowterms))
236  allocate (this%iflowterms(this%nflowterms))
237  !
238  ! -- Set up flow tableobj
239  title = trim(this%name)//' PACKAGE - SUMMARY OF FLOWS FOR '// &
240  'EACH CONTROL VOLUME'
241  call table_cr(this%flowtab, this%name, title)
242  call this%flowtab%table_df(this%ncv, maxcol, iout, transient=.true.)
243  !
244  ! -- Go through and set up flow table budget terms
245  text = 'NUMBER'
246  call this%flowtab%initialize_column(text, 10, alignment=tabcenter)
247  if (add_cellids) then
248  text = 'CELLID'
249  call this%flowtab%initialize_column(text, 20, alignment=tableft)
250  end if
251  idx = 1
252  do i = 1, this%nbudterm
253  lfound = .false.
254  flowtype = this%budterm(i)%get_flowtype()
255  tag = trim(adjustl(flowtype))
256  ipos = index(tag, '-')
257  if (ipos > 0) then
258  tag(ipos:ipos) = ' '
259  end if
260  if (trim(adjustl(flowtype)) == 'FLOW-JA-FACE') then
261  lfound = .true.
262  text = 'INFLOW'
263  call this%flowtab%initialize_column(text, 12, alignment=tabcenter)
264  text = 'OUTFLOW'
265  call this%flowtab%initialize_column(text, 12, alignment=tabcenter)
266  else if (trim(adjustl(flowtype)) /= 'AUXILIARY') then
267  lfound = .true.
268  call this%flowtab%initialize_column(tag, 12, alignment=tabcenter)
269  end if
270  if (lfound) then
271  this%iflowterms(idx) = i
272  idx = idx + 1
273  end if
274  end do
275  text = 'IN - OUT'
276  call this%flowtab%initialize_column(text, 12, alignment=tabcenter)
277  text = 'PERCENT DIFFERENCE'
278  call this%flowtab%initialize_column(text, 12, alignment=tabcenter)
279  !
280  ! -- Return
281  return
Here is the call graph for this function:

◆ read_flows()

subroutine budgetobjectmodule::read_flows ( class(budgetobjecttype this,
class(disbasetype), intent(in)  dis,
integer(i4b), intent(in)  ibinun 
)

Definition at line 518 of file BudgetObject.f90.

519  ! -- dummy
520  class(BudgetObjectType) :: this
521  class(DisBaseType), intent(in) :: dis
522  integer(I4B), intent(in) :: ibinun
523  ! -- local
524  integer(I4B) :: kstp
525  integer(I4B) :: kper
526  real(DP) :: delt
527  real(DP) :: pertim
528  real(DP) :: totim
529  integer(I4B) :: i
530  !
531  ! -- Read flows for each budget term
532  do i = 1, this%nbudterm
533  call this%budterm(i)%read_flows(dis, ibinun, kstp, kper, delt, &
534  pertim, totim)
535  end do
536  !
537  ! -- Return
538  return

◆ save_flows()

subroutine budgetobjectmodule::save_flows ( class(budgetobjecttype this,
class(disbasetype), intent(in)  dis,
integer(i4b), intent(in)  ibinun,
integer(i4b), intent(in)  kstp,
integer(i4b), intent(in)  kper,
real(dp), intent(in)  delt,
real(dp), intent(in)  pertim,
real(dp), intent(in)  totim,
integer(i4b), intent(in)  iout 
)

Definition at line 491 of file BudgetObject.f90.

493  ! -- dummy
494  class(BudgetObjectType) :: this
495  class(DisBaseType), intent(in) :: dis
496  integer(I4B), intent(in) :: ibinun
497  integer(I4B), intent(in) :: kstp
498  integer(I4B), intent(in) :: kper
499  real(DP), intent(in) :: delt
500  real(DP), intent(in) :: pertim
501  real(DP), intent(in) :: totim
502  integer(I4B), intent(in) :: iout
503  ! -- dummy
504  integer(I4B) :: i
505  !
506  ! -- Save flows for each budget term
507  do i = 1, this%nbudterm
508  call this%budterm(i)%save_flows(dis, ibinun, kstp, kper, delt, &
509  pertim, totim, iout)
510  end do
511  !
512  ! -- Return
513  return

◆ write_budtable()

subroutine budgetobjectmodule::write_budtable ( class(budgetobjecttype this,
integer(i4b), intent(in)  kstp,
integer(i4b), intent(in)  kper,
integer(i4b), intent(in)  iout,
integer(i4b), intent(in)  ibudfl,
real(dp), intent(in)  totim,
real(dp), intent(in)  delt 
)

Definition at line 468 of file BudgetObject.f90.

469  ! -- dummy
470  class(BudgetObjectType) :: this
471  integer(I4B), intent(in) :: kstp
472  integer(I4B), intent(in) :: kper
473  integer(I4B), intent(in) :: iout
474  integer(I4B), intent(in) :: ibudfl
475  real(DP), intent(in) :: totim
476  real(DP), intent(in) :: delt
477  !
478  ! -- Write the table
479  call this%budtable%finalize_step(delt)
480  if (ibudfl /= 0) then
481  call this%budtable%budget_ot(kstp, kper, iout)
482  end if
483  call this%budtable%writecsv(totim)
484  !
485  ! -- Return
486  return

◆ write_flowtable()

subroutine budgetobjectmodule::write_flowtable ( class(budgetobjecttype this,
class(disbasetype), intent(in)  dis,
integer(i4b), intent(in)  kstp,
integer(i4b), intent(in)  kper,
character(len=20), dimension(:), optional  cellidstr 
)

Definition at line 323 of file BudgetObject.f90.

324  ! -- dummy
325  class(BudgetObjectType) :: this
326  class(DisBaseType), intent(in) :: dis
327  integer(I4B), intent(in) :: kstp
328  integer(I4B), intent(in) :: kper
329  character(len=20), dimension(:), optional :: cellidstr
330  ! -- local
331  character(len=LENBUDTXT) :: flowtype
332  character(len=20) :: cellid
333  integer(I4B) :: nlist
334  integer(I4B) :: id1
335  integer(I4B) :: id2
336  integer(I4B) :: icv
337  integer(I4B) :: idx
338  integer(I4B) :: i
339  integer(I4B) :: j
340  real(DP) :: v
341  real(DP) :: qin
342  real(DP) :: qout
343  real(DP) :: q
344  real(DP) :: qinflow
345  real(DP) :: qoutflow
346  real(DP) :: qerr
347  real(DP) :: qavg
348  real(DP) :: qpd
349  !
350  ! -- Reset starting position
351  do j = 1, this%nflowterms
352  this%istart(j) = 1
353  end do
354  !
355  ! -- Set table kstp and kper
356  call this%flowtab%set_kstpkper(kstp, kper)
357  !
358  ! -- Write the table
359  do icv = 1, this%ncv
360  call this%flowtab%add_term(icv)
361  !
362  ! -- Initialize flow terms for the control volume
363  qin = dzero
364  qout = dzero
365  !
366  ! -- Add cellid if required
367  if (this%add_cellids) then
368  if (present(cellidstr)) then
369  !
370  ! -- If there are not maxbound entries for this%budterm(idx),
371  ! which can happen for sfr, for example, if 'none' connections
372  ! are specified, then cellidstr should be passed in if the flow
373  ! table needs a cellid label.
374  cellid = cellidstr(icv)
375  else
376  !
377  ! -- Determine the cellid for this entry. The cellid, such as
378  ! (1, 10, 10), is assumed to be in the id2 column of this budterm.
379  j = this%icellid
380  idx = this%iflowterms(j)
381  i = this%istart(j)
382  id2 = this%budterm(idx)%get_id2(i)
383  if (id2 > 0) then
384  call dis%noder_to_string(id2, cellid)
385  else
386  cellid = 'NONE'
387  end if
388  end if
389  call this%flowtab%add_term(cellid)
390  end if
391  !
392  ! -- Iterate over the flow terms
393  do j = 1, this%nflowterms
394  !
395  ! -- Initialize flow terms for the row
396  q = dzero
397  qinflow = dzero
398  qoutflow = dzero
399  !
400  ! -- Determine the index, flowtype and length of
401  ! the flowterm
402  idx = this%iflowterms(j)
403  flowtype = this%budterm(idx)%get_flowtype()
404  nlist = this%budterm(idx)%get_nlist()
405  !
406  ! -- Iterate over the entries in the flowtype. If id1 is not ordered
407  ! then need to look through the entire list each time
408  colterm: do i = this%istart(j), nlist
409  id1 = this%budterm(idx)%get_id1(i)
410  if (this%budterm(idx)%ordered_id1) then
411  if (id1 > icv) then
412  this%istart(j) = i
413  exit colterm
414  end if
415  else
416  if (id1 /= icv) then
417  cycle colterm
418  end if
419  end if
420  if (id1 /= icv) then
421  v = dzero
422  else
423  v = this%budterm(idx)%get_flow(i)
424  end if
425  if (trim(adjustl(flowtype)) == 'FLOW-JA-FACE') then
426  if (v < dzero) then
427  qoutflow = qoutflow + v
428  else
429  qinflow = qinflow + v
430  end if
431  end if
432  !
433  ! -- Accumulators
434  q = q + v
435  if (v < dzero) then
436  qout = qout + v
437  else
438  qin = qin + v
439  end if
440  end do colterm
441  !
442  ! -- Add entry to table
443  if (trim(adjustl(flowtype)) == 'FLOW-JA-FACE') then
444  call this%flowtab%add_term(qinflow)
445  call this%flowtab%add_term(qoutflow)
446  else
447  call this%flowtab%add_term(q)
448  end if
449  end do
450  !
451  ! -- Calculate in-out and percent difference
452  qerr = qin + qout
453  qavg = dhalf * (qin - qout)
454  qpd = dzero
455  if (qavg > dzero) then
456  qpd = dhundred * qerr / qavg
457  end if
458  call this%flowtab%add_term(qerr)
459  call this%flowtab%add_term(qpd)
460  end do
461  !
462  ! -- Return
463  return