MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
Table.f90
Go to the documentation of this file.
1 ! Comprehensive table object that stores all of the
2 ! intercell flows, and the inflows and the outflows for
3 ! an advanced package.
4 module tablemodule
5 
6  use kindmodule, only: i4b, i8b, dp
9  tabcenter, &
10  dhnoflo, dhdry
13  use simmodule, only: store_error
14  use simvariablesmodule, only: errmsg
15 
16  implicit none
17 
18  public :: tabletype
19  public :: table_cr
20 
21  type :: tabletype
22  !
23  ! -- name, number of control volumes, and number of table terms
24  character(len=LENBUDTXT) :: name
25  character(len=LINELENGTH) :: title
26  character(len=1), pointer :: sep => null()
27  logical, pointer :: write_csv => null()
28  logical, pointer :: first_entry => null()
29  logical, pointer :: transient => null()
30  logical, pointer :: add_linesep => null()
31  logical, pointer :: allow_finalization => null()
32  integer(I4B), pointer :: iout => null()
33  integer(I4B), pointer :: maxbound => null()
34  integer(I4B), pointer :: nheaderlines => null()
35  integer(I4B), pointer :: nlinewidth => null()
36  integer(I4B), pointer :: ntableterm => null()
37  integer(I4B), pointer :: ientry => null()
38  integer(I4B), pointer :: iloc => null()
39  integer(I4B), pointer :: icount => null()
40  integer(I4B), pointer :: kstp => null()
41  integer(I4B), pointer :: kper => null()
42  !
43  ! -- array of table terms, with one separate entry for each term
44  ! such as rainfall, et, leakage, etc.
45  type(tabletermtype), dimension(:), pointer :: tableterm => null()
46  !
47  ! -- table table object, for writing the typical MODFLOW table
48  type(tabletype), pointer :: table => null()
49 
50  character(len=LINELENGTH), pointer :: linesep => null()
51  character(len=LINELENGTH), pointer :: dataline => null()
52  character(len=LINELENGTH), dimension(:), pointer :: header => null()
53 
54  contains
55 
56  procedure :: table_df
57  procedure :: table_da
58  procedure :: initialize_column
59  procedure :: line_to_columns
60  procedure :: finalize_table
61  procedure :: set_maxbound
62  procedure :: set_kstpkper
63  procedure :: set_title
64  procedure :: set_iout
65  procedure :: print_list_entry
66  procedure :: print_separator
67 
68  procedure, private :: allocate_strings
69  procedure, private :: set_header
70  procedure, private :: write_header
71  procedure, private :: write_line
72  procedure, private :: finalize
73  procedure, private :: add_error
74  procedure, private :: reset
75 
76  generic, public :: add_term => add_integer, add_long_integer, &
79 
80  end type tabletype
81 
82 contains
83 
84  subroutine table_cr(this, name, title)
85 ! ******************************************************************************
86 ! table_cr -- Create a new table object
87 ! ******************************************************************************
88 !
89 ! SPECIFICATIONS:
90 ! ------------------------------------------------------------------------------
91  ! -- modules
92  ! -- dummy
93  type(tabletype), pointer :: this
94  character(len=*), intent(in) :: name
95  character(len=*), intent(in) :: title
96  ! -- local
97 ! ------------------------------------------------------------------------------
98  !
99  ! -- check if table already associated and reset if necessary
100  if (associated(this)) then
101  call this%table_da()
102  deallocate (this)
103  nullify (this)
104  end if
105  !
106  ! -- Create the object
107  allocate (this)
108  !
109  ! -- initialize variables
110  this%name = name
111  this%title = title
112  !
113  ! -- Return
114  return
115  end subroutine table_cr
116 
117  subroutine table_df(this, maxbound, ntableterm, iout, transient, &
118  lineseparator, separator, finalize)
119 ! ******************************************************************************
120 ! table_df -- Define the new table object
121 ! ******************************************************************************
122 !
123 ! SPECIFICATIONS:
124 ! ------------------------------------------------------------------------------
125  ! -- modules
126  ! -- dummy
127  class(tabletype) :: this
128  integer(I4B), intent(in) :: maxbound
129  integer(I4B), intent(in) :: ntableterm
130  integer(I4B), intent(in) :: iout
131  logical, intent(in), optional :: transient
132  logical, intent(in), optional :: lineseparator
133  character(len=1), intent(in), optional :: separator
134  logical, intent(in), optional :: finalize
135 ! ------------------------------------------------------------------------------
136  !
137  ! -- allocate scalars
138  allocate (this%sep)
139  allocate (this%write_csv)
140  allocate (this%first_entry)
141  allocate (this%transient)
142  allocate (this%add_linesep)
143  allocate (this%allow_finalization)
144  allocate (this%iout)
145  allocate (this%maxbound)
146  allocate (this%nheaderlines)
147  allocate (this%nlinewidth)
148  allocate (this%ntableterm)
149  allocate (this%ientry)
150  allocate (this%iloc)
151  allocate (this%icount)
152  !
153  ! -- allocate space for tableterm
154  allocate (this%tableterm(ntableterm))
155  !
156  ! -- initialize values based on optional dummy variables
157  if (present(transient)) then
158  this%transient = transient
159  allocate (this%kstp)
160  allocate (this%kper)
161  else
162  this%transient = .false.
163  end if
164  if (present(separator)) then
165  this%sep = separator
166  if (separator == ',') then
167  this%write_csv = .true.
168  else
169  this%write_csv = .false.
170  end if
171  else
172  this%sep = ' '
173  this%write_csv = .false.
174  end if
175  if (present(lineseparator)) then
176  this%add_linesep = lineseparator
177  else
178  this%add_linesep = .true.
179  end if
180  if (present(finalize)) then
181  this%allow_finalization = finalize
182  else
183  this%allow_finalization = .true.
184  end if
185  !
186  ! -- initialize variables
187  this%first_entry = .true.
188  this%iout = iout
189  this%maxbound = maxbound
190  this%ntableterm = ntableterm
191  this%ientry = 0
192  this%icount = 0
193  !
194  ! -- return
195  return
196  end subroutine table_df
197 
198  subroutine initialize_column(this, text, width, alignment)
199 ! ******************************************************************************
200 ! initialize_column -- Initialize data for a column
201 ! ******************************************************************************
202 !
203 ! SPECIFICATIONS:
204 ! ------------------------------------------------------------------------------
205  ! -- modules
206  ! -- dummy
207  class(tabletype) :: this
208  character(len=*), intent(in) :: text
209  integer(I4B), intent(in) :: width
210  integer(I4B), intent(in), optional :: alignment
211  ! -- local
212  integer(I4B) :: idx
213  integer(I4B) :: ialign
214 ! ------------------------------------------------------------------------------
215  !
216  ! -- process optional dummy variables
217  if (present(alignment)) then
218  ialign = alignment
219  else
220  ialign = tabcenter
221  end if
222  !
223  ! -- update index for tableterm
224  this%ientry = this%ientry + 1
225  idx = this%ientry
226  !
227  ! -- check that ientry is in bounds
228  if (this%ientry > this%ntableterm) then
229  write (errmsg, '(a,a,a,i0,a,1x,a,1x,a,a,a,1x,i0,1x,a)') &
230  'Trying to add column "', trim(adjustl(text)), '" (', &
231  this%ientry, ') in the', trim(adjustl(this%name)), 'table ("', &
232  trim(adjustl(this%title)), '") that only has', this%ntableterm, &
233  'columns.'
234  call store_error(errmsg, terminate=.true.)
235  end if
236  !
237  ! -- initialize table term
238  call this%tableterm(idx)%initialize(text, width, alignment=ialign)
239  !
240  ! -- create header when all terms have been specified
241  if (this%ientry == this%ntableterm) then
242  call this%set_header()
243  !
244  ! -- reset ientry
245  this%ientry = 0
246  end if
247  !
248  ! -- return
249  return
250  end subroutine initialize_column
251 
252  subroutine set_header(this)
253 ! ******************************************************************************
254 ! set_header -- Set the table object header
255 ! ******************************************************************************
256 !
257 ! SPECIFICATIONS:
258 ! ------------------------------------------------------------------------------
259  ! -- modules
260  ! -- dummy
261  class(tabletype) :: this
262  ! -- local
263  character(len=LINELENGTH) :: cval
264  integer(I4B) :: width
265  integer(I4B) :: alignment
266  integer(I4B) :: nlines
267  integer(I4B) :: iloc
268  integer(I4B) :: ival
269  real(DP) :: rval
270  integer(I4B) :: j
271  integer(I4B) :: n
272  integer(I4B) :: nn
273 ! ------------------------------------------------------------------------------
274  !
275  ! -- initialize variables
276  width = 0
277  nlines = 0
278  !
279  ! -- determine total width and maximum number of lines
280  do n = 1, this%ntableterm
281  width = width + this%tableterm(n)%get_width()
282  nlines = max(nlines, this%tableterm(n)%get_header_lines())
283  end do
284  !
285  ! -- add length of separators
286  width = width + this%ntableterm - 1
287  !
288  ! -- allocate the header and line separator
289  call this%allocate_strings(width, nlines)
290  !
291  ! -- build final header lines
292  do n = 1, this%ntableterm
293  call this%tableterm(n)%set_header(nlines)
294  end do
295  !
296  ! -- build header
297  do n = 1, nlines
298  iloc = 1
299  this%iloc = 1
300  if (this%add_linesep) then
301  nn = n + 1
302  else
303  nn = n
304  end if
305  do j = 1, this%ntableterm
306  width = this%tableterm(j)%get_width()
307  alignment = this%tableterm(j)%get_alignment()
308  call this%tableterm(j)%get_header(n, cval)
309  if (this%write_csv) then
310  if (j == 1) then
311  write (this%header(nn), '(a)') trim(adjustl(cval))
312  else
313  write (this%header(nn), '(a,",",G0)') &
314  trim(this%header(nn)), trim(adjustl(cval))
315  end if
316  else
317  if (j == this%ntableterm) then
318  call uwword(this%header(nn), iloc, width, tabucstring, &
319  cval(1:width), ival, rval, alignment=alignment)
320  else
321  call uwword(this%header(nn), iloc, width, tabucstring, &
322  cval(1:width), ival, rval, alignment=alignment, &
323  sep=this%sep)
324  end if
325  end if
326  end do
327  end do
328  !
329  ! -- return
330  return
331  end subroutine set_header
332 
333  subroutine allocate_strings(this, width, nlines)
334 ! ******************************************************************************
335 ! allocate_strings -- Allocate allocatable character arrays
336 ! ******************************************************************************
337 !
338 ! SPECIFICATIONS:
339 ! ------------------------------------------------------------------------------
340  ! -- modules
341  ! -- dummy
342  class(tabletype) :: this
343  integer(I4B), intent(in) :: width
344  integer(I4B), intent(in) :: nlines
345  ! -- local
346  character(len=width) :: string
347  character(len=width) :: linesep
348  integer(I4B) :: n
349 ! ------------------------------------------------------------------------------
350  !
351  ! -- initialize local variables
352  string = ''
353  linesep = repeat('-', width)
354  !
355  ! -- initialize variables
356  this%nheaderlines = nlines
357  if (this%add_linesep) then
358  this%nheaderlines = this%nheaderlines + 2
359  end if
360  this%nlinewidth = width
361  !
362  ! -- allocate deferred length strings
363  allocate (this%header(this%nheaderlines))
364  allocate (this%linesep)
365  allocate (this%dataline)
366  !
367  ! -- initialize lines
368  this%linesep = linesep(1:width)
369  this%dataline = string(1:width)
370  do n = 1, this%nheaderlines
371  this%header(n) = string(1:width)
372  end do
373  !
374  ! -- fill first and last header line with
375  ! linesep
376  if (this%add_linesep) then
377  this%header(1) = linesep(1:width)
378  this%header(nlines + 2) = linesep(1:width)
379  end if
380  !
381  ! -- return
382  return
383  end subroutine allocate_strings
384 
385  subroutine write_header(this)
386 ! ******************************************************************************
387 ! write_table -- Write the table header
388 ! ******************************************************************************
389 !
390 ! SPECIFICATIONS:
391 ! ------------------------------------------------------------------------------
392  ! -- modules
393  ! -- dummy
394  class(tabletype) :: this
395  ! -- local
396  character(len=LINELENGTH) :: title
397  integer(I4B) :: width
398  integer(I4B) :: n
399 ! ------------------------------------------------------------------------------
400  !
401  ! -- initialize local variables
402  width = this%nlinewidth
403  !
404  ! -- write the table header
405  if (this%first_entry) then
406  ! -- write title
407  title = this%title
408  if (this%transient) then
409  write (title, '(a,a,i6)') trim(adjustl(title)), ' PERIOD ', this%kper
410  write (title, '(a,a,i8)') trim(adjustl(title)), ' STEP ', this%kstp
411  end if
412  if (len_trim(title) > 0) then
413  write (this%iout, '(/,1x,a)') trim(adjustl(title))
414  end if
415  !
416  ! -- write header
417  do n = 1, this%nheaderlines
418  write (this%iout, '(1x,a)') this%header(n) (1:width)
419  end do
420  end if
421  !
422  ! -- reinitialize variables
423  this%first_entry = .false.
424  this%ientry = 0
425  this%icount = 0
426  !
427  ! -- return
428  return
429  end subroutine write_header
430 
431  subroutine write_line(this)
432 ! ******************************************************************************
433 ! write_line -- Write the data line
434 ! ******************************************************************************
435 !
436 ! SPECIFICATIONS:
437 ! ------------------------------------------------------------------------------
438  ! -- modules
439  ! -- dummy
440  class(tabletype) :: this
441  ! -- local
442  integer(I4B) :: width
443 ! ------------------------------------------------------------------------------
444  !
445  ! -- initialize local variables
446  width = this%nlinewidth
447  !
448  ! -- write the dataline
449  write (this%iout, '(1x,a)') this%dataline(1:width)
450  !
451  ! -- update column and line counters
452  this%ientry = 0
453  this%iloc = 1
454  this%icount = this%icount + 1
455  !
456  ! -- return
457  return
458  end subroutine write_line
459 
460  subroutine finalize(this)
461 ! ******************************************************************************
462 ! finalize -- Private method that test for last line. If last line the
463 ! public finalize_table method is called
464 ! ******************************************************************************
465 !
466 ! SPECIFICATIONS:
467 ! ------------------------------------------------------------------------------
468  ! -- modules
469  ! -- dummy
470  class(tabletype) :: this
471  ! -- local
472 ! ------------------------------------------------------------------------------
473  !
474  ! -- finalize table if last entry
475  if (this%icount == this%maxbound) then
476  call this%finalize_table()
477  end if
478  !
479  ! -- return
480  return
481  end subroutine finalize
482 
483  subroutine finalize_table(this)
484 ! ******************************************************************************
485 ! finalize -- Public method to finalize the table
486 ! ******************************************************************************
487 !
488 ! SPECIFICATIONS:
489 ! ------------------------------------------------------------------------------
490  ! -- modules
491  ! -- dummy
492  class(tabletype) :: this
493  ! -- local
494 ! ------------------------------------------------------------------------------
495  !
496  ! -- write the final table separator
497  call this%print_separator(iextralines=1)
498  !
499  ! -- flush file
500  flush (this%iout)
501  !
502  ! -- reinitialize variables
503  call this%reset()
504  !
505  ! -- return
506  return
507  end subroutine finalize_table
508 
509  subroutine table_da(this)
510 ! ******************************************************************************
511 ! table_da -- deallocate
512 ! ******************************************************************************
513 !
514 ! SPECIFICATIONS:
515 ! ------------------------------------------------------------------------------
516  ! -- modules
517  ! -- dummy
518  class(tabletype) :: this
519  ! -- dummy
520  integer(I4B) :: i
521 ! ------------------------------------------------------------------------------
522  !
523  ! -- deallocate each table term
524  do i = 1, this%ntableterm
525  call this%tableterm(i)%da()
526  end do
527  !
528  ! -- deallocate space for tableterm
529  deallocate (this%tableterm)
530  !
531  ! -- deallocate character scalars and arrays
532  deallocate (this%linesep)
533  deallocate (this%dataline)
534  deallocate (this%header)
535  !
536  ! -- deallocate scalars
537  if (this%transient) then
538  deallocate (this%kstp)
539  deallocate (this%kper)
540  end if
541  deallocate (this%sep)
542  deallocate (this%write_csv)
543  deallocate (this%first_entry)
544  deallocate (this%transient)
545  deallocate (this%add_linesep)
546  deallocate (this%allow_finalization)
547  deallocate (this%iout)
548  deallocate (this%maxbound)
549  deallocate (this%nheaderlines)
550  deallocate (this%nlinewidth)
551  deallocate (this%ntableterm)
552  deallocate (this%ientry)
553  deallocate (this%iloc)
554  deallocate (this%icount)
555  !
556  ! -- Return
557  return
558  end subroutine table_da
559 
560  subroutine line_to_columns(this, line)
561 ! ******************************************************************************
562 ! line_to_columns -- convert a line to the correct number of columns
563 ! ******************************************************************************
564 !
565 ! SPECIFICATIONS:
566 ! ------------------------------------------------------------------------------
567  ! -- modules
568  ! -- dummy
569  class(tabletype) :: this
570  character(len=LINELENGTH), intent(in) :: line
571  ! -- local
572  character(len=LINELENGTH), allocatable, dimension(:) :: words
573  integer(I4B) :: nwords
574  integer(I4B) :: icols
575  integer(I4B) :: i
576 ! ------------------------------------------------------------------------------
577  !
578  ! -- write header
579  if (this%icount == 0 .and. this%ientry == 0) then
580  call this%write_header()
581  end if
582  !
583  ! -- parse line into words
584  call parseline(line, nwords, words, 0)
585  !
586  ! -- calculate the number of entries in line but
587  ! limit it to the maximum number of columns if
588  ! the number of words exceeds ntableterm
589  icols = this%ntableterm
590  icols = min(nwords, icols)
591  !
592  ! -- add data (as strings) to line
593  do i = 1, icols
594  call this%add_term(words(i))
595  end do
596  !
597  ! -- add empty strings to complete the line
598  do i = icols + 1, this%ntableterm
599  call this%add_term(' ')
600  end do
601  !
602  ! -- clean up local allocatable array
603  deallocate (words)
604  !
605  ! -- Return
606  return
607  end subroutine line_to_columns
608 
609  subroutine add_error(this)
610 ! ******************************************************************************
611 ! add_error -- evaluate if error condition occurs when adding data to dataline
612 ! ******************************************************************************
613 !
614 ! SPECIFICATIONS:
615 ! ------------------------------------------------------------------------------
616  ! -- modules
617  ! -- dummy
618  class(tabletype) :: this
619  ! -- local
620 ! ------------------------------------------------------------------------------
621  !
622  ! -- check that ientry is within bounds
623  if (this%ientry > this%ntableterm) then
624  write (errmsg, '(a,1x,i0,5(1x,a),1x,i0,1x,a)') &
625  'Trying to add data to column ', this%ientry, 'in the', &
626  trim(adjustl(this%name)), 'table (', trim(adjustl(this%title)), &
627  ') that only has', this%ntableterm, 'columns.'
628  call store_error(errmsg, terminate=.true.)
629  end if
630  !
631  ! -- Return
632  return
633  end subroutine add_error
634 
635  subroutine add_integer(this, ival)
636 ! ******************************************************************************
637 ! add_integer -- add integer value to the dataline
638 ! ******************************************************************************
639 !
640 ! SPECIFICATIONS:
641 ! ------------------------------------------------------------------------------
642  ! -- modules
643  ! -- dummy
644  class(tabletype) :: this
645  integer(I4B), intent(in) :: ival
646  ! -- local
647  logical :: line_end
648  character(len=LINELENGTH) :: cval
649  real(DP) :: rval
650  integer(I4B) :: width
651  integer(I4B) :: alignment
652  integer(I4B) :: j
653 ! ------------------------------------------------------------------------------
654  !
655  ! -- write header
656  if (this%icount == 0 .and. this%ientry == 0) then
657  call this%write_header()
658  end if
659  !
660  ! -- update index for tableterm
661  this%ientry = this%ientry + 1
662  !
663  ! -- check that ientry is within bounds
664  call this%add_error()
665  !
666  ! -- initialize local variables
667  j = this%ientry
668  width = this%tableterm(j)%get_width()
669  alignment = this%tableterm(j)%get_alignment()
670  line_end = .false.
671  if (j == this%ntableterm) then
672  line_end = .true.
673  end if
674  !
675  ! -- add data to line
676  if (this%write_csv) then
677  if (j == 1) then
678  write (this%dataline, '(G0)') ival
679  else
680  write (this%dataline, '(a,",",G0)') trim(this%dataline), ival
681  end if
682  else
683  if (j == this%ntableterm) then
684  call uwword(this%dataline, this%iloc, width, tabinteger, &
685  cval, ival, rval, alignment=alignment)
686  else
687  call uwword(this%dataline, this%iloc, width, tabinteger, &
688  cval, ival, rval, alignment=alignment, sep=this%sep)
689  end if
690  end if
691  !
692  ! -- write the data line, if necessary
693  if (line_end) then
694  call this%write_line()
695  end if
696  !
697  ! -- finalize the table, if necessary
698  if (this%allow_finalization) then
699  call this%finalize()
700  end if
701  !
702  ! -- Return
703  return
704  end subroutine add_integer
705 
706  subroutine add_long_integer(this, long_ival)
707 ! ******************************************************************************
708 ! add_long_integer -- add long integer value to the dataline
709 ! ******************************************************************************
710 !
711 ! SPECIFICATIONS:
712 ! ------------------------------------------------------------------------------
713  ! -- modules
714  ! -- dummy
715  class(tabletype) :: this
716  integer(I8B), intent(in) :: long_ival
717  ! -- local
718  logical :: line_end
719  character(len=LINELENGTH) :: cval
720  real(DP) :: rval
721  integer(I4B) :: ival
722  integer(I4B) :: width
723  integer(I4B) :: alignment
724  integer(I4B) :: j
725 ! ------------------------------------------------------------------------------
726  !
727  ! -- write header
728  if (this%icount == 0 .and. this%ientry == 0) then
729  call this%write_header()
730  end if
731  !
732  ! -- update index for tableterm
733  this%ientry = this%ientry + 1
734  !
735  ! -- check that ientry is within bounds
736  call this%add_error()
737  !
738  ! -- initialize local variables
739  j = this%ientry
740  width = this%tableterm(j)%get_width()
741  alignment = this%tableterm(j)%get_alignment()
742  line_end = .false.
743  if (j == this%ntableterm) then
744  line_end = .true.
745  end if
746  !
747  ! -- add data to line
748  if (this%write_csv) then
749  if (j == 1) then
750  write (this%dataline, '(G0)') long_ival
751  else
752  write (this%dataline, '(a,",",G0)') trim(this%dataline), long_ival
753  end if
754  else
755  write (cval, '(i0)') long_ival
756  if (j == this%ntableterm) then
757  call uwword(this%dataline, this%iloc, width, tabstring, &
758  trim(cval), ival, rval, alignment=alignment)
759  else
760  call uwword(this%dataline, this%iloc, width, tabstring, &
761  trim(cval), ival, rval, alignment=alignment, sep=this%sep)
762  end if
763  end if
764  !
765  ! -- write the data line, if necessary
766  if (line_end) then
767  call this%write_line()
768  end if
769  !
770  ! -- finalize the table, if necessary
771  if (this%allow_finalization) then
772  call this%finalize()
773  end if
774  !
775  ! -- Return
776  return
777  end subroutine add_long_integer
778 
779  subroutine add_real(this, rval)
780 ! ******************************************************************************
781 ! add_real -- add real value to the dataline
782 ! ******************************************************************************
783 !
784 ! SPECIFICATIONS:
785 ! ------------------------------------------------------------------------------
786  ! -- modules
787  ! -- dummy
788  class(tabletype) :: this
789  real(DP), intent(in) :: rval
790  ! -- local
791  logical :: line_end
792  character(len=LINELENGTH) :: cval
793  integer(I4B) :: ival
794  integer(I4B) :: j
795  integer(I4B) :: width
796  integer(I4B) :: alignment
797 ! ------------------------------------------------------------------------------
798 !
799  if (rval == dhnoflo) then
800  call this%add_string("INACTIVE")
801  else if (rval == dhdry) then
802  call this%add_string("DRY")
803  else
804  !
805  ! -- write header
806  if (this%icount == 0 .and. this%ientry == 0) then
807  call this%write_header()
808  end if
809  !
810  ! -- update index for tableterm
811  this%ientry = this%ientry + 1
812  !
813  ! -- check that ientry is within bounds
814  call this%add_error()
815  !
816  ! -- initialize local variables
817  j = this%ientry
818  width = this%tableterm(j)%get_width()
819  alignment = this%tableterm(j)%get_alignment()
820  line_end = .false.
821  if (j == this%ntableterm) then
822  line_end = .true.
823  end if
824  !
825  ! -- add data to line
826  if (this%write_csv) then
827  if (j == 1) then
828  write (this%dataline, '(G0)') rval
829  else
830  write (this%dataline, '(a,",",G0)') trim(this%dataline), rval
831  end if
832  else
833  if (j == this%ntableterm) then
834  call uwword(this%dataline, this%iloc, width, tabreal, &
835  cval, ival, rval, alignment=alignment)
836  else
837  call uwword(this%dataline, this%iloc, width, tabreal, &
838  cval, ival, rval, alignment=alignment, sep=this%sep)
839  end if
840  end if
841  !
842  ! -- write the data line, if necessary
843  if (line_end) then
844  call this%write_line()
845  end if
846  !
847  ! -- finalize the table, if necessary
848  if (this%allow_finalization) then
849  call this%finalize()
850  end if
851  end if
852  !
853  ! -- Return
854  return
855  end subroutine add_real
856 
857  subroutine add_string(this, cval)
858 ! ******************************************************************************
859 ! add_string -- add string value to the dataline
860 ! ******************************************************************************
861 !
862 ! SPECIFICATIONS:
863 ! ------------------------------------------------------------------------------
864  ! -- modules
865  ! -- dummy
866  class(tabletype) :: this
867  character(len=*) :: cval
868  ! -- local
869  logical :: line_end
870  integer(I4B) :: j
871  integer(I4B) :: ival
872  real(DP) :: rval
873  integer(I4B) :: width
874  integer(I4B) :: alignment
875 ! ------------------------------------------------------------------------------
876  !
877  ! -- write header
878  if (this%icount == 0 .and. this%ientry == 0) then
879  call this%write_header()
880  end if
881  !
882  ! -- update index for tableterm
883  this%ientry = this%ientry + 1
884  !
885  ! -- check that ientry is within bounds
886  call this%add_error()
887  !
888  ! -- initialize local variables
889  j = this%ientry
890  width = this%tableterm(j)%get_width()
891  alignment = this%tableterm(j)%get_alignment()
892  line_end = .false.
893  if (j == this%ntableterm) then
894  line_end = .true.
895  end if
896  !
897  ! -- add data to line
898  if (this%write_csv) then
899  if (j == 1) then
900  write (this%dataline, '(a)') trim(adjustl(cval))
901  else
902  write (this%dataline, '(a,",",a)') &
903  trim(this%dataline), trim(adjustl(cval))
904  end if
905  else
906  if (j == this%ntableterm) then
907  call uwword(this%dataline, this%iloc, width, tabstring, &
908  cval, ival, rval, alignment=alignment)
909  else
910  call uwword(this%dataline, this%iloc, width, tabstring, &
911  cval, ival, rval, alignment=alignment, sep=this%sep)
912  end if
913  end if
914  !
915  ! -- write the data line, if necessary
916  if (line_end) then
917  call this%write_line()
918  end if
919  !
920  ! -- finalize the table, if necessary
921  if (this%allow_finalization) then
922  call this%finalize()
923  end if
924  !
925  ! -- Return
926  return
927  end subroutine add_string
928 
929  subroutine set_maxbound(this, maxbound)
930 ! ******************************************************************************
931 ! set_maxbound -- reset maxbound
932 ! ******************************************************************************
933 !
934 ! SPECIFICATIONS:
935 ! ------------------------------------------------------------------------------
936  ! -- modules
937  ! -- dummy
938  class(tabletype) :: this
939  integer(I4B), intent(in) :: maxbound
940  ! -- local
941 ! ------------------------------------------------------------------------------
942  !
943  ! -- set maxbound
944  this%maxbound = maxbound
945  !
946  ! -- reset counters
947  call this%reset()
948  !
949  ! -- return
950  return
951  end subroutine set_maxbound
952 
953  subroutine set_kstpkper(this, kstp, kper)
954 ! ******************************************************************************
955 ! set_kstpkper -- reset kstp and kper
956 ! ******************************************************************************
957 !
958 ! SPECIFICATIONS:
959 ! ------------------------------------------------------------------------------
960  ! -- modules
961  ! -- dummy
962  class(tabletype) :: this
963  integer(I4B), intent(in) :: kstp
964  integer(I4B), intent(in) :: kper
965  ! -- local
966 ! ------------------------------------------------------------------------------
967  !
968  ! -- set maxbound
969  this%kstp = kstp
970  this%kper = kper
971  !
972  ! -- return
973  return
974  end subroutine set_kstpkper
975 
976  subroutine set_title(this, title)
977 ! ******************************************************************************
978 ! set_maxbound -- reset maxbound
979 ! ******************************************************************************
980 !
981 ! SPECIFICATIONS:
982 ! ------------------------------------------------------------------------------
983  ! -- modules
984  ! -- dummy
985  class(tabletype) :: this
986  character(len=*), intent(in) :: title
987  ! -- local
988 ! ------------------------------------------------------------------------------
989  !
990  ! -- set maxbound
991  this%title = title
992  !
993  ! -- return
994  return
995  end subroutine set_title
996 
997  subroutine set_iout(this, iout)
998 ! ******************************************************************************
999 ! set_iout -- reset iout
1000 ! ******************************************************************************
1001 !
1002 ! SPECIFICATIONS:
1003 ! ------------------------------------------------------------------------------
1004  ! -- modules
1005  ! -- dummy
1006  class(tabletype) :: this
1007  integer(I4B), intent(in) :: iout
1008  ! -- local
1009 ! ------------------------------------------------------------------------------
1010  !
1011  ! -- set iout
1012  this%iout = iout
1013  !
1014  ! -- return
1015  return
1016  end subroutine set_iout
1017 
1018  subroutine print_list_entry(this, i, nodestr, q, bname)
1019 ! ******************************************************************************
1020 ! print_list_entry -- write flow term table values
1021 ! ******************************************************************************
1022 !
1023 ! SPECIFICATIONS:
1024 ! ------------------------------------------------------------------------------
1025  ! -- modules
1026  ! -- dummy
1027  class(tabletype) :: this
1028  integer(I4B), intent(in) :: i
1029  character(len=*), intent(in) :: nodestr
1030  real(DP), intent(in) :: q
1031  character(len=*), intent(in) :: bname
1032  ! -- local
1033 ! ------------------------------------------------------------------------------
1034  !
1035  ! -- fill table terms
1036  call this%add_term(i)
1037  call this%add_term(nodestr)
1038  call this%add_term(q)
1039  if (this%ntableterm > 3) then
1040  call this%add_term(bname)
1041  end if
1042  !
1043  ! -- return
1044  return
1045  end subroutine print_list_entry
1046 
1047  subroutine print_separator(this, iextralines)
1048 ! ******************************************************************************
1049 ! print_separator -- print a line separator to the table
1050 ! ******************************************************************************
1051 !
1052 ! SPECIFICATIONS:
1053 ! ------------------------------------------------------------------------------
1054  ! -- modules
1055  ! -- dummy
1056  class(tabletype) :: this
1057  integer(I4B), optional :: iextralines
1058  ! -- local
1059  integer(I4B) :: i
1060  integer(I4B) :: iextra
1061  integer(I4B) :: width
1062 ! ------------------------------------------------------------------------------
1063  !
1064  ! -- process optional variables
1065  if (present(iextralines)) then
1066  iextra = iextralines
1067  else
1068  iextra = 0
1069  end if
1070  !
1071  ! -- initialize local variables
1072  width = this%nlinewidth
1073  !
1074  ! -- print line separator
1075  if (this%add_linesep) then
1076  write (this%iout, '(1x,a)') this%linesep(1:width)
1077  do i = 1, iextra
1078  write (this%iout, '(/)')
1079  end do
1080  end if
1081  !
1082  ! -- return
1083  return
1084  end subroutine print_separator
1085 
1086  subroutine reset(this)
1087 ! ******************************************************************************
1088 ! reset -- Private method to reset table counters
1089 ! ******************************************************************************
1090 !
1091 ! SPECIFICATIONS:
1092 ! ------------------------------------------------------------------------------
1093  ! -- modules
1094  ! -- dummy
1095  class(tabletype) :: this
1096  ! -- local
1097 ! ------------------------------------------------------------------------------
1098  !
1099  ! -- reset counters
1100  this%ientry = 0
1101  this%icount = 0
1102  this%first_entry = .true.
1103  !
1104  ! -- return
1105  return
1106  end subroutine reset
1107 
1108 end module tablemodule
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition: Constants.f90:44
real(dp), parameter dhdry
real dry cell constant
Definition: Constants.f90:93
@ tabcenter
centered table column
Definition: Constants.f90:171
@ tabucstring
upper case string table data
Definition: Constants.f90:179
@ tabstring
string table data
Definition: Constants.f90:178
@ tabreal
real table data
Definition: Constants.f90:181
@ tabinteger
integer table data
Definition: Constants.f90:180
real(dp), parameter dhnoflo
real no flow constant
Definition: Constants.f90:92
integer(i4b), parameter lenbudtxt
maximum length of a budget component names
Definition: Constants.f90:36
subroutine, public parseline(line, nwords, words, inunit, filename)
Parse a line into words.
subroutine, public uwword(line, icol, ilen, ncode, c, n, r, fmt, alignment, sep)
Create a formatted line.
This module defines variable data types.
Definition: kind.f90:8
This module contains simulation methods.
Definition: Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition: Sim.f90:92
This module contains simulation variables.
Definition: SimVariables.f90:9
character(len=maxcharlen) errmsg
error message string
subroutine set_kstpkper(this, kstp, kper)
Definition: Table.f90:954
subroutine set_header(this)
Definition: Table.f90:253
subroutine write_line(this)
Definition: Table.f90:432
subroutine table_df(this, maxbound, ntableterm, iout, transient, lineseparator, separator, finalize)
Definition: Table.f90:119
subroutine write_header(this)
Definition: Table.f90:386
subroutine finalize(this)
Definition: Table.f90:461
subroutine print_separator(this, iextralines)
Definition: Table.f90:1048
subroutine set_iout(this, iout)
Definition: Table.f90:998
subroutine, public table_cr(this, name, title)
Definition: Table.f90:85
subroutine reset(this)
Definition: Table.f90:1087
subroutine line_to_columns(this, line)
Definition: Table.f90:561
subroutine initialize_column(this, text, width, alignment)
Definition: Table.f90:199
subroutine set_maxbound(this, maxbound)
Definition: Table.f90:930
subroutine table_da(this)
Definition: Table.f90:510
subroutine add_long_integer(this, long_ival)
Definition: Table.f90:707
subroutine finalize_table(this)
Definition: Table.f90:484
subroutine set_title(this, title)
Definition: Table.f90:977
subroutine add_string(this, cval)
Definition: Table.f90:858
subroutine add_real(this, rval)
Definition: Table.f90:780
subroutine allocate_strings(this, width, nlines)
Definition: Table.f90:334
subroutine print_list_entry(this, i, nodestr, q, bname)
Definition: Table.f90:1019
subroutine add_integer(this, ival)
Definition: Table.f90:636
subroutine add_error(this)
Definition: Table.f90:610