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

This module contains the BudgetModule. More...

Data Types

type  budgettype
 Derived type for the Budget object. More...
 

Functions/Subroutines

subroutine, public budget_cr (this, name_model)
 @ brief Create a new budget object More...
 
subroutine budget_df (this, maxsize, bdtype, bddim, labeltitle, bdzone)
 @ brief Define information for this object More...
 
subroutine value_to_string (val, string, big, small)
 @ brief Convert a number to a string More...
 
subroutine budget_ot (this, kstp, kper, iout)
 @ brief Output the budget table More...
 
subroutine budget_da (this)
 @ brief Deallocate memory More...
 
subroutine reset (this)
 @ brief Reset the budget object More...
 
subroutine add_single_entry (this, rin, rout, delt, text, isupress_accumulate, rowlabel)
 @ brief Add a single row of information More...
 
subroutine add_multi_entry (this, budterm, delt, budtxt, isupress_accumulate, rowlabel)
 @ brief Add multiple rows of information More...
 
subroutine finalize_step (this, delt)
 @ brief Update accumulators More...
 
subroutine allocate_scalars (this, name_model)
 @ brief allocate scalar variables More...
 
subroutine allocate_arrays (this)
 @ brief allocate array variables More...
 
subroutine resize (this, maxsize)
 @ brief Resize the budget object More...
 
subroutine, public rate_accumulator (flow, rin, rout)
 @ brief Rate accumulator subroutine More...
 
subroutine set_ibudcsv (this, ibudcsv)
 @ brief Set unit number for csv output file More...
 
subroutine writecsv (this, totim)
 @ brief Write csv output More...
 
subroutine write_csv_header (this)
 @ brief Write csv header More...
 

Detailed Description

New entries can be added for each time step, however, the same number of entries must be provided, and they must be provided in the same order. If not, the module will terminate with an error.

Maxsize is required as part of the df method and the arrays will be allocated to maxsize. If additional entries beyond maxsize are added, the arrays will dynamically increase in size, however, to avoid allocation and copying, it is best to set maxsize large enough up front.

vbvl(1, :) contains cumulative rate in vbvl(2, :) contains cumulative rate out vbvl(3, :) contains rate in vbvl(4, :) contains rate out vbnm(:) contains a LENBUDTXT character text string for each entry rowlabel(:) contains a LENBUDROWLABEL character text string to write as a label for each entry

Function/Subroutine Documentation

◆ add_multi_entry()

subroutine budgetmodule::add_multi_entry ( class(budgettype this,
real(dp), dimension(:, :), intent(in)  budterm,
real(dp), intent(in)  delt,
character(len=lenbudtxt), dimension(:), intent(in)  budtxt,
integer(i4b), intent(in), optional  isupress_accumulate,
character(len=*), intent(in), optional  rowlabel 
)
private

Add information corresponding to one multiple rows in the budget table budterm is an array with inflow in column 1 and outflow in column 2 delt is the time step length budtxt is the name of the entries. It should have one entry for each row in budterm isupress_accumulate is an optional flag. If specified as 1, then the volume is NOT added to the accumulators on vbvl(1, :) and vbvl(2, :). rowlabel is a LENBUDROWLABEL character text entry that is written to the right of the table. It can be used for adding package names to budget entries. For multiple entries, the same rowlabel is used for each entry.

Parameters
thisBudgetType object
[in]budtermarray of budget terms
[in]delttime step length
[in]budtxtname of the entries
[in]isupress_accumulatesuppress accumulate
[in]rowlabelrow label

Definition at line 454 of file Budget.f90.

456  ! -- dummy
457  class(BudgetType) :: this !< BudgetType object
458  real(DP), dimension(:, :), intent(in) :: budterm !< array of budget terms
459  real(DP), intent(in) :: delt !< time step length
460  character(len=LENBUDTXT), dimension(:), intent(in) :: budtxt !< name of the entries
461  integer(I4B), optional, intent(in) :: isupress_accumulate !< suppress accumulate
462  character(len=*), optional, intent(in) :: rowlabel !< row label
463  ! -- local
464  character(len=LINELENGTH) :: errmsg
465  character(len=*), parameter :: fmtbuderr = &
466  &"('Error in MODFLOW 6.', 'Entries do not match: ', (a), (a) )"
467  integer(i4b) :: iscv, i
468  integer(I4B) :: nbudterms, maxsize
469  !
470  iscv = 0
471  if (present(isupress_accumulate)) then
472  iscv = isupress_accumulate
473  end if
474  !
475  ! -- ensure budget arrays are large enough
476  nbudterms = size(budtxt)
477  maxsize = this%msum - 1 + nbudterms
478  if (maxsize > this%maxsize) then
479  call this%resize(maxsize)
480  end if
481  !
482  ! -- Process each of the multi-entry budget terms
483  do i = 1, size(budtxt)
484  !
485  ! -- If budget has been written at least once, then make sure that the present
486  ! text entry matches the last text entry
487  if (this%written_once) then
488  if (trim(adjustl(this%vbnm(this%msum))) /= &
489  trim(adjustl(budtxt(i)))) then
490  write (errmsg, fmtbuderr) trim(adjustl(this%vbnm(this%msum))), &
491  trim(adjustl(budtxt(i)))
492  call store_error(errmsg)
493  end if
494  end if
495  !
496  this%vbvl(3, this%msum) = budterm(1, i)
497  this%vbvl(4, this%msum) = budterm(2, i)
498  this%vbnm(this%msum) = adjustr(budtxt(i))
499  if (present(rowlabel)) then
500  this%rowlabel(this%msum) = adjustl(rowlabel)
501  this%labeled = .true.
502  end if
503  this%msum = this%msum + 1
504  !
505  end do
506  !
507  ! -- Check for errors
508  if (count_errors() > 0) then
509  call store_error('Could not add multi-entry', terminate=.true.)
510  end if
511  !
512  ! -- Return
513  return
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_single_entry()

subroutine budgetmodule::add_single_entry ( class(budgettype this,
real(dp), intent(in)  rin,
real(dp), intent(in)  rout,
real(dp), intent(in)  delt,
character(len=lenbudtxt), intent(in)  text,
integer(i4b), intent(in), optional  isupress_accumulate,
character(len=*), intent(in), optional  rowlabel 
)
private

Add information corresponding to one row in the budget table rin the inflow rate rout is the outflow rate delt is the time step length text is the name of the entry isupress_accumulate is an optional flag. If specified as 1, then the volume is NOT added to the accumulators on vbvl(1, :) and vbvl(2, :). rowlabel is a LENBUDROWLABEL character text entry that is written to the right of the table. It can be used for adding package names to budget entries.

Parameters
thisBudgetType object
[in]rininflow rate
[in]routoutflow rate
[in]delttime step length
[in]textname of the entry
[in]isupress_accumulateaccumulate flag
[in]rowlabelrow label

Definition at line 389 of file Budget.f90.

391  ! -- dummy
392  class(BudgetType) :: this !< BudgetType object
393  real(DP), intent(in) :: rin !< inflow rate
394  real(DP), intent(in) :: rout !< outflow rate
395  real(DP), intent(in) :: delt !< time step length
396  character(len=LENBUDTXT), intent(in) :: text !< name of the entry
397  integer(I4B), optional, intent(in) :: isupress_accumulate !< accumulate flag
398  character(len=*), optional, intent(in) :: rowlabel !< row label
399  ! -- local
400  character(len=LINELENGTH) :: errmsg
401  character(len=*), parameter :: fmtbuderr = &
402  &"('Error in MODFLOW 6.', 'Entries do not match: ', (a), (a) )"
403  integer(i4b) :: iscv
404  integer(I4B) :: maxsize
405  !
406  iscv = 0
407  if (present(isupress_accumulate)) then
408  iscv = isupress_accumulate
409  end if
410  !
411  ! -- ensure budget arrays are large enough
412  maxsize = this%msum
413  if (maxsize > this%maxsize) then
414  call this%resize(maxsize)
415  end if
416  !
417  ! -- If budget has been written at least once, then make sure that the present
418  ! text entry matches the last text entry
419  if (this%written_once) then
420  if (trim(adjustl(this%vbnm(this%msum))) /= trim(adjustl(text))) then
421  write (errmsg, fmtbuderr) trim(adjustl(this%vbnm(this%msum))), &
422  trim(adjustl(text))
423  call store_error(errmsg, terminate=.true.)
424  end if
425  end if
426  !
427  this%vbvl(3, this%msum) = rin
428  this%vbvl(4, this%msum) = rout
429  this%vbnm(this%msum) = adjustr(text)
430  if (present(rowlabel)) then
431  this%rowlabel(this%msum) = adjustl(rowlabel)
432  this%labeled = .true.
433  end if
434  this%msum = this%msum + 1
435  !
436  ! -- Return
437  return
Here is the call graph for this function:
Here is the caller graph for this function:

◆ allocate_arrays()

subroutine budgetmodule::allocate_arrays ( class(budgettype this)
private

Allocate array variables of this budget object

Parameters
thisBudgetType object

Definition at line 582 of file Budget.f90.

583  ! -- modules
584  ! -- dummy
585  class(BudgetType) :: this !< BudgetType object
586  !
587  ! -- If redefining, then need to deallocate/reallocate
588  if (associated(this%vbvl)) then
589  deallocate (this%vbvl)
590  nullify (this%vbvl)
591  end if
592  if (associated(this%vbnm)) then
593  deallocate (this%vbnm)
594  nullify (this%vbnm)
595  end if
596  if (associated(this%rowlabel)) then
597  deallocate (this%rowlabel)
598  nullify (this%rowlabel)
599  end if
600  !
601  ! -- Allocate
602  allocate (this%vbvl(4, this%maxsize))
603  allocate (this%vbnm(this%maxsize))
604  allocate (this%rowlabel(this%maxsize))
605  !
606  ! -- Initialize values
607  this%vbvl(:, :) = dzero
608  this%vbnm(:) = ''
609  this%rowlabel(:) = ''
610  !
611  return

◆ allocate_scalars()

subroutine budgetmodule::allocate_scalars ( class(budgettype this,
character(len=*), intent(in)  name_model 
)
private

Allocate scalar variables of this budget object

Parameters
thisBudgetType object
[in]name_modelname of the model

Definition at line 544 of file Budget.f90.

545  ! -- modules
546  ! -- dummy
547  class(BudgetType) :: this !< BudgetType object
548  character(len=*), intent(in) :: name_model !< name of the model
549  !
550  allocate (this%msum)
551  allocate (this%maxsize)
552  allocate (this%budperc)
553  allocate (this%written_once)
554  allocate (this%labeled)
555  allocate (this%bdtype)
556  allocate (this%bddim)
557  allocate (this%labeltitle)
558  allocate (this%bdzone)
559  allocate (this%ibudcsv)
560  allocate (this%icsvheader)
561  !
562  ! -- Initialize values
563  this%msum = 0
564  this%maxsize = 0
565  this%written_once = .false.
566  this%labeled = .false.
567  this%bdtype = ''
568  this%bddim = ''
569  this%labeltitle = ''
570  this%bdzone = ''
571  this%ibudcsv = 0
572  this%icsvheader = 0
573  !
574  return

◆ budget_cr()

subroutine, public budgetmodule::budget_cr ( type(budgettype), pointer  this,
character(len=*), intent(in)  name_model 
)

Create a new budget object.

Parameters
thisBudgetType object
[in]name_modelname of the model

Definition at line 83 of file Budget.f90.

84  ! -- modules
85  ! -- dummy
86  type(BudgetType), pointer :: this !< BudgetType object
87  character(len=*), intent(in) :: name_model !< name of the model
88  !
89  ! -- Create the object
90  allocate (this)
91  !
92  ! -- Allocate scalars
93  call this%allocate_scalars(name_model)
94  !
95  ! -- Return
96  return
Here is the caller graph for this function:

◆ budget_da()

subroutine budgetmodule::budget_da ( class(budgettype this)
private

Deallocate budget memory

Parameters
thisBudgetType object

Definition at line 328 of file Budget.f90.

329  class(BudgetType) :: this !< BudgetType object
330  !
331  ! -- Scalars
332  deallocate (this%msum)
333  deallocate (this%maxsize)
334  deallocate (this%budperc)
335  deallocate (this%written_once)
336  deallocate (this%labeled)
337  deallocate (this%bdtype)
338  deallocate (this%bddim)
339  deallocate (this%labeltitle)
340  deallocate (this%bdzone)
341  deallocate (this%ibudcsv)
342  deallocate (this%icsvheader)
343  !
344  ! -- Arrays
345  deallocate (this%vbvl)
346  deallocate (this%vbnm)
347  deallocate (this%rowlabel)
348  !
349  ! -- Return
350  return

◆ budget_df()

subroutine budgetmodule::budget_df ( class(budgettype this,
integer(i4b), intent(in)  maxsize,
character(len=*), optional  bdtype,
character(len=*), optional  bddim,
character(len=*), optional  labeltitle,
character(len=*), optional  bdzone 
)
private

Allocate arrays and set member variables

Parameters
thisBudgetType object
[in]maxsizemaximum size of budget arrays
bdtypetype of budget, default is VOLUME
bddimdimensions of terms, default is L**3
labeltitlebudget label, default is PACKAGE NAME
bdzonecorresponding zone, default is ENTIRE MODEL

Definition at line 104 of file Budget.f90.

105  class(BudgetType) :: this !< BudgetType object
106  integer(I4B), intent(in) :: maxsize !< maximum size of budget arrays
107  character(len=*), optional :: bdtype !< type of budget, default is VOLUME
108  character(len=*), optional :: bddim !< dimensions of terms, default is L**3
109  character(len=*), optional :: labeltitle !< budget label, default is PACKAGE NAME
110  character(len=*), optional :: bdzone !< corresponding zone, default is ENTIRE MODEL
111  !
112  ! -- Set values
113  this%maxsize = maxsize
114  !
115  ! -- Allocate arrays
116  call this%allocate_arrays()
117  !
118  ! -- Set the budget type
119  if (present(bdtype)) then
120  this%bdtype = bdtype
121  else
122  this%bdtype = 'VOLUME'
123  end if
124  !
125  ! -- Set the budget dimension
126  if (present(bddim)) then
127  this%bddim = bddim
128  else
129  this%bddim = 'L**3'
130  end if
131  !
132  ! -- Set the budget zone
133  if (present(bdzone)) then
134  this%bdzone = bdzone
135  else
136  this%bdzone = 'ENTIRE MODEL'
137  end if
138  !
139  ! -- Set the label title
140  if (present(labeltitle)) then
141  this%labeltitle = labeltitle
142  else
143  this%labeltitle = 'PACKAGE NAME'
144  end if
145  !
146  ! -- Return
147  return

◆ budget_ot()

subroutine budgetmodule::budget_ot ( class(budgettype this,
integer(i4b), intent(in)  kstp,
integer(i4b), intent(in)  kper,
integer(i4b), intent(in)  iout 
)
private

Write the budget table for the current set of budget information.

Parameters
thisBudgetType object
[in]kstptime step
[in]kperstress period
[in]ioutoutput unit number

Definition at line 185 of file Budget.f90.

186  class(BudgetType) :: this !< BudgetType object
187  integer(I4B), intent(in) :: kstp !< time step
188  integer(I4B), intent(in) :: kper !< stress period
189  integer(I4B), intent(in) :: iout !< output unit number
190  character(len=17) :: val1, val2
191  integer(I4B) :: msum1, l
192  real(DP) :: two, hund, bigvl1, bigvl2, small, &
193  totrin, totrot, totvin, totvot, diffr, adiffr, &
194  pdiffr, pdiffv, avgrat, diffv, adiffv, avgvol
195  !
196  ! -- Set constants
197  two = 2.d0
198  hund = 100.d0
199  bigvl1 = 9.99999d11
200  bigvl2 = 9.99999d10
201  small = 0.1d0
202  !
203  ! -- Determine number of individual budget entries.
204  this%budperc = dzero
205  msum1 = this%msum - 1
206  if (msum1 <= 0) return
207  !
208  ! -- Clear rate and volume accumulators.
209  totrin = dzero
210  totrot = dzero
211  totvin = dzero
212  totvot = dzero
213  !
214  ! -- Add rates and volumes (in and out) to accumulators.
215  do l = 1, msum1
216  totrin = totrin + this%vbvl(3, l)
217  totrot = totrot + this%vbvl(4, l)
218  totvin = totvin + this%vbvl(1, l)
219  totvot = totvot + this%vbvl(2, l)
220  end do
221  !
222  ! -- Print time step number and stress period number.
223  if (this%labeled) then
224  write (iout, 261) trim(adjustl(this%bdtype)), trim(adjustl(this%bdzone)), &
225  kstp, kper
226  write (iout, 266) trim(adjustl(this%bdtype)), trim(adjustl(this%bddim)), &
227  trim(adjustl(this%bddim)), this%labeltitle
228  else
229  write (iout, 260) trim(adjustl(this%bdtype)), trim(adjustl(this%bdzone)), &
230  kstp, kper
231  write (iout, 265) trim(adjustl(this%bdtype)), trim(adjustl(this%bddim)), &
232  trim(adjustl(this%bddim))
233  end if
234  !
235  ! -- Print individual inflow rates and volumes and their totals.
236  do l = 1, msum1
237  call value_to_string(this%vbvl(1, l), val1, bigvl1, small)
238  call value_to_string(this%vbvl(3, l), val2, bigvl1, small)
239  if (this%labeled) then
240  write (iout, 276) this%vbnm(l), val1, this%vbnm(l), val2, this%rowlabel(l)
241  else
242  write (iout, 275) this%vbnm(l), val1, this%vbnm(l), val2
243  end if
244  end do
245  call value_to_string(totvin, val1, bigvl1, small)
246  call value_to_string(totrin, val2, bigvl1, small)
247  write (iout, 286) val1, val2
248  !
249  ! -- Print individual outflow rates and volumes and their totals.
250  write (iout, 287)
251  do l = 1, msum1
252  call value_to_string(this%vbvl(2, l), val1, bigvl1, small)
253  call value_to_string(this%vbvl(4, l), val2, bigvl1, small)
254  if (this%labeled) then
255  write (iout, 276) this%vbnm(l), val1, this%vbnm(l), val2, this%rowlabel(l)
256  else
257  write (iout, 275) this%vbnm(l), val1, this%vbnm(l), val2
258  end if
259  end do
260  call value_to_string(totvot, val1, bigvl1, small)
261  call value_to_string(totrot, val2, bigvl1, small)
262  write (iout, 298) val1, val2
263  !
264  ! -- Calculate the difference between inflow and outflow.
265  !
266  ! -- Calculate difference between rate in and rate out.
267  diffr = totrin - totrot
268  adiffr = abs(diffr)
269  !
270  ! -- Calculate percent difference between rate in and rate out.
271  pdiffr = dzero
272  avgrat = (totrin + totrot) / two
273  if (avgrat /= dzero) pdiffr = hund * diffr / avgrat
274  this%budperc = pdiffr
275  !
276  ! -- Calculate difference between volume in and volume out.
277  diffv = totvin - totvot
278  adiffv = abs(diffv)
279  !
280  ! -- Get percent difference between volume in and volume out.
281  pdiffv = dzero
282  avgvol = (totvin + totvot) / two
283  if (avgvol /= dzero) pdiffv = hund * diffv / avgvol
284  !
285  ! -- Print differences and percent differences between input
286  ! -- and output rates and volumes.
287  call value_to_string(diffv, val1, bigvl2, small)
288  call value_to_string(diffr, val2, bigvl2, small)
289  write (iout, 299) val1, val2
290  write (iout, 300) pdiffv, pdiffr
291  !
292  ! -- flush the file
293  flush (iout)
294  !
295  ! -- set written_once to .true.
296  this%written_once = .true.
297  !
298  ! -- formats
299 260 FORMAT(//2x, a, ' BUDGET FOR ', a, ' AT END OF' &
300  , ' TIME STEP', i5, ', STRESS PERIOD', i4 / 2x, 78('-'))
301 261 FORMAT(//2x, a, ' BUDGET FOR ', a, ' AT END OF' &
302  , ' TIME STEP', i5, ', STRESS PERIOD', i4 / 2x, 99('-'))
303 265 FORMAT(1x, /5x, 'CUMULATIVE ', a, 6x, a, 7x &
304  , 'RATES FOR THIS TIME STEP', 6x, a, '/T'/5x, 18('-'), 17x, 24('-') &
305  //11x, 'IN:', 38x, 'IN:'/11x, '---', 38x, '---')
306 266 FORMAT(1x, /5x, 'CUMULATIVE ', a, 6x, a, 7x &
307  , 'RATES FOR THIS TIME STEP', 6x, a, '/T', 10x, a16, &
308  /5x, 18('-'), 17x, 24('-'), 21x, 16('-') &
309  //11x, 'IN:', 38x, 'IN:'/11x, '---', 38x, '---')
310 275 FORMAT(1x, 3x, a16, ' =', a17, 6x, a16, ' =', a17)
311 276 FORMAT(1x, 3x, a16, ' =', a17, 6x, a16, ' =', a17, 5x, a)
312 286 FORMAT(1x, /12x, 'TOTAL IN =', a, 14x, 'TOTAL IN =', a)
313 287 FORMAT(1x, /10x, 'OUT:', 37x, 'OUT:'/10x, 4('-'), 37x, 4('-'))
314 298 FORMAT(1x, /11x, 'TOTAL OUT =', a, 13x, 'TOTAL OUT =', a)
315 299 FORMAT(1x, /12x, 'IN - OUT =', a, 14x, 'IN - OUT =', a)
316 300 FORMAT(1x, /1x, 'PERCENT DISCREPANCY =', f15.2 &
317  , 5x, 'PERCENT DISCREPANCY =', f15.2/)
318  !
319  ! -- Return
320  return
Here is the call graph for this function:

◆ finalize_step()

subroutine budgetmodule::finalize_step ( class(budgettype this,
real(dp), intent(in)  delt 
)
private

This must be called before any output is written in order to update the accumulators in vbvl(1,:) and vbl(2,:).

Parameters
thisBudgetType object

Definition at line 522 of file Budget.f90.

523  ! -- modules
524  ! -- dummy
525  class(BudgetType) :: this !< BudgetType object
526  real(DP), intent(in) :: delt
527  ! -- local
528  integer(I4B) :: i
529  !
530  do i = 1, this%msum - 1
531  this%vbvl(1, i) = this%vbvl(1, i) + this%vbvl(3, i) * delt
532  this%vbvl(2, i) = this%vbvl(2, i) + this%vbvl(4, i) * delt
533  end do
534  !
535  ! -- Return
536  return

◆ rate_accumulator()

subroutine, public budgetmodule::rate_accumulator ( real(dp), dimension(:), intent(in), contiguous  flow,
real(dp), intent(out)  rin,
real(dp), intent(out)  rout 
)

Routing for tallying inflows and outflows of an array

Parameters
[in]flowarray of flows
[out]rincalculated sum of inflows
[out]routcalculated sum of outflows

Definition at line 663 of file Budget.f90.

664  ! -- modules
665  ! -- dummy
666  real(DP), dimension(:), contiguous, intent(in) :: flow !< array of flows
667  real(DP), intent(out) :: rin !< calculated sum of inflows
668  real(DP), intent(out) :: rout !< calculated sum of outflows
669  integer(I4B) :: n
670  !
671  rin = dzero
672  rout = dzero
673  do n = 1, size(flow)
674  if (flow(n) < dzero) then
675  rout = rout - flow(n)
676  else
677  rin = rin + flow(n)
678  end if
679  end do
680  return
Here is the caller graph for this function:

◆ reset()

subroutine budgetmodule::reset ( class(budgettype this)
private

Reset the budget object in preparation for next set of entries

Parameters
thisBudgetType object

Definition at line 358 of file Budget.f90.

359  ! -- modules
360  ! -- dummy
361  class(BudgetType) :: this !< BudgetType object
362  ! -- local
363  integer(I4B) :: i
364  !
365  this%msum = 1
366  do i = 1, this%maxsize
367  this%vbvl(3, i) = dzero
368  this%vbvl(4, i) = dzero
369  end do
370 
371  ! -- Return
372  return

◆ resize()

subroutine budgetmodule::resize ( class(budgettype this,
integer(i4b), intent(in)  maxsize 
)
private

If the size wasn't allocated to be large enough, then the budget object we reallocate itself to a larger size.

Parameters
thisBudgetType object
[in]maxsizemaximum size

Definition at line 620 of file Budget.f90.

621  ! -- modules
622  ! -- dummy
623  class(BudgetType) :: this !< BudgetType object
624  integer(I4B), intent(in) :: maxsize !< maximum size
625  ! -- local
626  real(DP), dimension(:, :), allocatable :: vbvl
627  character(len=LENBUDTXT), dimension(:), allocatable :: vbnm
628  character(len=LENBUDROWLABEL), dimension(:), allocatable :: rowlabel
629  integer(I4B) :: maxsizeold
630  !
631  ! -- allocate and copy into local storage
632  maxsizeold = this%maxsize
633  allocate (vbvl(4, maxsizeold))
634  allocate (vbnm(maxsizeold))
635  allocate (rowlabel(maxsizeold))
636  vbvl(:, :) = this%vbvl(:, :)
637  vbnm(:) = this%vbnm(:)
638  rowlabel(:) = this%rowlabel(:)
639  !
640  ! -- Set new size and reallocate
641  this%maxsize = maxsize
642  call this%allocate_arrays()
643  !
644  ! -- Copy from local back into member variables
645  this%vbvl(:, 1:maxsizeold) = vbvl(:, 1:maxsizeold)
646  this%vbnm(1:maxsizeold) = vbnm(1:maxsizeold)
647  this%rowlabel(1:maxsizeold) = rowlabel(1:maxsizeold)
648  !
649  ! - deallocate local copies
650  deallocate (vbvl)
651  deallocate (vbnm)
652  deallocate (rowlabel)
653  !
654  ! -- return
655  return

◆ set_ibudcsv()

subroutine budgetmodule::set_ibudcsv ( class(budgettype this,
integer(i4b), intent(in)  ibudcsv 
)
private

This routine can be used to activate csv output by passing in a valid unit number opened for output

Parameters
thisBudgetType object
[in]ibudcsvunit number for csv budget output

Definition at line 689 of file Budget.f90.

690  ! -- modules
691  ! -- dummy
692  class(BudgetType) :: this !< BudgetType object
693  integer(I4B), intent(in) :: ibudcsv !< unit number for csv budget output
694  this%ibudcsv = ibudcsv
695  return

◆ value_to_string()

subroutine budgetmodule::value_to_string ( real(dp), intent(in)  val,
character(len=*), intent(out)  string,
real(dp), intent(in)  big,
real(dp), intent(in)  small 
)
private

This is sometimes needed to avoid numbers that do not fit correctly into a text string

Parameters
[in]valvalue to convert
[out]stringstring to fill
[in]bigbig value
[in]smallsmall value

Definition at line 156 of file Budget.f90.

157  real(DP), intent(in) :: val !< value to convert
158  character(len=*), intent(out) :: string !< string to fill
159  real(DP), intent(in) :: big !< big value
160  real(DP), intent(in) :: small !< small value
161  real(DP) :: absval
162  !
163  absval = abs(val)
164  if (val /= dzero .and. (absval >= big .or. absval < small)) then
165  if (absval >= 1.d100 .or. absval <= 1.d-100) then
166  ! -- if exponent has 3 digits, then need to explicitly use the ES
167  ! format to force writing the E character
168  write (string, '(es17.4E3)') val
169  else
170  write (string, '(1pe17.4)') val
171  end if
172  else
173  ! -- value is within range where number looks good with F format
174  write (string, '(f17.4)') val
175  end if
176  return
Here is the caller graph for this function:

◆ write_csv_header()

subroutine budgetmodule::write_csv_header ( class(budgettype this)
private

This routine will write the csv header based on the names in vbnm

Parameters
thisBudgetType object

Definition at line 763 of file Budget.f90.

764  ! -- modules
765  ! -- dummy
766  class(BudgetType) :: this !< BudgetType object
767  ! -- local
768  integer(I4B) :: l
769  character(len=LINELENGTH) :: txt, txtl
770  write (this%ibudcsv, '(a)', advance='NO') 'time,'
771  !
772  ! -- first write IN
773  do l = 1, this%msum - 1
774  txt = this%vbnm(l)
775  txtl = ''
776  if (this%labeled) then
777  txtl = '('//trim(adjustl(this%rowlabel(l)))//')'
778  end if
779  txt = trim(adjustl(txt))//trim(adjustl(txtl))//'_IN,'
780  write (this%ibudcsv, '(a)', advance='NO') trim(adjustl(txt))
781  end do
782  !
783  ! -- then write OUT
784  do l = 1, this%msum - 1
785  txt = this%vbnm(l)
786  txtl = ''
787  if (this%labeled) then
788  txtl = '('//trim(adjustl(this%rowlabel(l)))//')'
789  end if
790  txt = trim(adjustl(txt))//trim(adjustl(txtl))//'_OUT,'
791  write (this%ibudcsv, '(a)', advance='NO') trim(adjustl(txt))
792  end do
793  write (this%ibudcsv, '(a)') 'TOTAL_IN,TOTAL_OUT,PERCENT_DIFFERENCE'
794  !
795  ! -- return
796  return

◆ writecsv()

subroutine budgetmodule::writecsv ( class(budgettype this,
real(dp), intent(in)  totim 
)
private

This routine will write a row of output to the csv file, if it is available for output. Upon first call, it will write the csv header.

Parameters
thisBudgetType object
[in]totimtime corresponding to this data

Definition at line 705 of file Budget.f90.

706  ! -- modules
707  ! -- dummy
708  class(BudgetType) :: this !< BudgetType object
709  real(DP), intent(in) :: totim !< time corresponding to this data
710  ! -- local
711  integer(I4B) :: i
712  real(DP) :: totrin
713  real(DP) :: totrout
714  real(DP) :: diffr
715  real(DP) :: pdiffr
716  real(DP) :: avgrat
717  !
718  if (this%ibudcsv > 0) then
719  !
720  ! -- write header
721  if (this%icsvheader == 0) then
722  call this%write_csv_header()
723  this%icsvheader = 1
724  end if
725  !
726  ! -- Calculate in and out
727  totrin = dzero
728  totrout = dzero
729  do i = 1, this%msum - 1
730  totrin = totrin + this%vbvl(3, i)
731  totrout = totrout + this%vbvl(4, i)
732  end do
733  !
734  ! -- calculate percent difference
735  diffr = totrin - totrout
736  pdiffr = dzero
737  avgrat = (totrin + totrout) / dtwo
738  if (avgrat /= dzero) then
739  pdiffr = dhundred * diffr / avgrat
740  end if
741  !
742  ! -- write data
743  write (this%ibudcsv, '(*(G0,:,","))') &
744  totim, &
745  (this%vbvl(3, i), i=1, this%msum - 1), &
746  (this%vbvl(4, i), i=1, this%msum - 1), &
747  totrin, totrout, pdiffr
748  !
749  ! -- flush the file
750  flush (this%ibudcsv)
751  end if
752  !
753  ! -- return
754  return