MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
TableTerm.f90
Go to the documentation of this file.
1 ! A table term is the information needed to describe flow.
2 ! The table object contains an array of table terms.
3 ! For an advanced package. The table object describes all of
4 ! the flows.
6 
7  use kindmodule, only: i4b, dp
12 
13  implicit none
14 
15  public :: tabletermtype
16 
17  type :: tabletermtype
18  character(len=LINELENGTH), pointer :: tag => null()
19  integer(I4B), pointer :: width => null()
20  integer(I4B), pointer :: alignment => null()
21  integer(I4B), pointer :: nheader_lines => null()
22 
23  character(len=LINELENGTH), dimension(:), pointer :: initial_lines => null()
24  character(len=LINELENGTH), dimension(:), pointer :: header_lines => null()
25 
26  contains
27 
28  procedure :: initialize
29  procedure, private :: allocate_scalars
30  procedure :: get_width
31  procedure :: get_alignment
32  procedure :: get_header_lines
33  procedure :: set_header
34  procedure :: get_header
35  procedure :: da
36 
37  end type tabletermtype
38 
39 contains
40 
41  !< @brief initialize the table term
42  !<
43  subroutine initialize(this, tag, width, alignment)
44  ! -- modules
45  ! -- dummy
46  class(tabletermtype) :: this
47  character(len=*), intent(in) :: tag
48  integer(I4B), intent(in) :: width
49  integer(I4B), intent(in), optional :: alignment
50  ! -- local
51  character(len=LINELENGTH) :: string
52  character(len=LINELENGTH) :: tstring
53  character(len=LINELENGTH), allocatable, dimension(:) :: words
54  integer(I4B) :: nwords
55  integer(I4B) :: ilen
56  integer(I4B) :: i
57  integer(I4B) :: j
58 
59  !
60  ! -- allocate scalars
61  call this%allocate_scalars()
62 
63  ! -- process dummy variables
64  this%tag = tag
65 
66  if (present(alignment)) then
67  this%alignment = alignment
68  else
69  this%alignment = tabcenter
70  end if
71 
72  this%width = width
73  !
74  ! -- parse tag into words
75  call parseline(tag, nwords, words, 0)
76  !
77  ! -- abbreviate any words that exceed the specified width
78  ! and trim trailing characters
79  do i = 1, nwords
80  ilen = len(trim(words(i)))
81  if (ilen > width) then
82  words(i) (width:width) = '.'
83  do j = width + 1, ilen
84  words(i) (j:j) = ' '
85  end do
86  end if
87  end do
88  !
89  ! -- combine words that fit into width
90  i = 0
91  do
92  i = i + 1
93  if (i > nwords) then
94  exit
95  end if
96  string = trim(adjustl(words(i)))
97  tstring = string
98  do j = i + 1, nwords
99  if (len(trim(adjustl(string))) > 0) then
100  tstring = trim(adjustl(tstring))//' '//trim(adjustl(words(j)))
101  else
102  tstring = trim(adjustl(words(j)))
103  end if
104  ilen = len(trim(adjustl(tstring)))
105  if (ilen == 0) then
106  continue
107  else if (ilen <= width) then
108  words(j) = ' '
109  string = tstring
110  else
111  exit
112  end if
113  end do
114  words(i) = string
115  end do
116  !
117  ! -- calculate the number of header lines
118  do i = 1, nwords
119  ilen = len(trim(adjustl(words(i))))
120  if (ilen > 0) then
121  this%nheader_lines = this%nheader_lines + 1
122  end if
123  end do
124  !
125  ! allocate initial_lines and fill with words
126  allocate (this%initial_lines(this%nheader_lines))
127  do i = 1, this%nheader_lines
128  this%initial_lines(i) = words(i) (1:width)
129  end do
130  !
131  ! -- deallocate words
132  deallocate (words)
133  !
134  ! -- return
135  return
136 
137  end subroutine initialize
138 
139  !< @brief get column width
140  !<
141  function get_width(this)
142  ! -- return variable
143  integer(I4B) :: get_width
144  ! -- modules
145  ! -- dummy
146  class(tabletermtype) :: this
147  ! -- local
148  get_width = this%width
149  end function get_width
150 
151  !< @brief get column alignment
152  !<
153  function get_alignment(this)
154  ! -- return variable
155  integer(I4B) :: get_alignment
156  ! -- modules
157  ! -- dummy
158  class(tabletermtype) :: this
159  ! -- local
160  get_alignment = this%alignment
161  end function get_alignment
162 
163  !< @brief get the number of lines in initial_lines
164  !<
165  function get_header_lines(this)
166  ! -- return variable
167  integer(I4B) :: get_header_lines
168  ! -- modules
169  ! -- dummy
170  class(tabletermtype) :: this
171  ! -- local
172  get_header_lines = this%nheader_lines
173  end function get_header_lines
174 
175  !< @brief allocate table term scalars
176  !<
177  subroutine allocate_scalars(this)
178  ! -- modules
179  ! -- dummy
180  class(tabletermtype) :: this
181  !
182  ! -- allocate scalars
183  allocate (this%tag)
184  allocate (this%alignment)
185  allocate (this%width)
186  allocate (this%nheader_lines)
187  !
188  ! -- initialize scalars
189  this%nheader_lines = 0
190  end subroutine allocate_scalars
191 
192  !< @brief deallocate table terms
193  !<
194  subroutine da(this)
195  ! -- modules
196  ! -- dummy
197  class(tabletermtype) :: this
198  ! -- local
199  !integer(I4B) :: n
200  !
201  ! -- deallocate scalars
202  deallocate (this%tag)
203  deallocate (this%alignment)
204  deallocate (this%width)
205  deallocate (this%nheader_lines)
206  deallocate (this%header_lines)
207  !
208  ! -- return
209  end subroutine da
210 
211  !< @brief set final header lines for table term
212  !<
213  subroutine set_header(this, nlines)
214  ! -- modules
215  ! -- dummy
216  class(tabletermtype) :: this
217  integer(I4B), intent(in) :: nlines
218  ! -- local
219  character(len=this%width) :: string
220  integer(I4B) :: idiff
221  integer(I4B) :: i0
222  integer(I4B) :: i
223  integer(I4B) :: j
224  !
225  ! -- initialize variables
226  string = ' '
227  !
228  ! allocate header_lines
229  allocate (this%header_lines(nlines))
230  !
231  ! -- initialize header lines
232  do i = 1, nlines
233  this%header_lines(i) = string
234  end do
235  !
236  ! -- fill header_lines with initial_lines from
237  ! bottom to top
238  idiff = nlines - this%nheader_lines
239  i0 = 1 - idiff
240  do i = this%nheader_lines, 1, -1
241  j = i + idiff
242  this%header_lines(j) = this%initial_lines(i)
243  end do
244  !
245  ! -- deallocate temporary header lines
246  deallocate (this%initial_lines)
247  !
248  ! -- reinitialize nheader_lines
249  this%nheader_lines = nlines
250  !
251  ! -- return
252  end subroutine set_header
253 
254  !< @brief get header entry for table term iline
255  !<
256  subroutine get_header(this, iline, cval)
257  ! -- modules
258  ! -- dummy
259  class(tabletermtype) :: this
260  integer(I4B), intent(in) :: iline
261  character(len=*), intent(inout) :: cval
262  ! -- return variable
263  ! -- local
264  !
265  ! -- set return value
266  cval = this%header_lines(iline) (1:this%width)
267  !
268  ! -- return
269  end subroutine get_header
270 
271 end module tabletermmodule
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition: Constants.f90:45
@ tabcenter
centered table column
Definition: Constants.f90:172
@ tabright
right justified table column
Definition: Constants.f90:173
@ tableft
left justified table column
Definition: Constants.f90:171
@ tabucstring
upper case string table data
Definition: Constants.f90:180
@ tabstring
string table data
Definition: Constants.f90:179
@ tabreal
real table data
Definition: Constants.f90:182
@ tabinteger
integer table data
Definition: Constants.f90:181
real(dp), parameter dzero
real constant zero
Definition: Constants.f90:65
integer(i4b), parameter lenbudtxt
maximum length of a budget component names
Definition: Constants.f90:37
subroutine, public parseline(line, nwords, words, inunit, filename)
Parse a line into words.
subroutine, public upcase(word)
Convert to upper case.
This module defines variable data types.
Definition: kind.f90:8
subroutine da(this)
Definition: TableTerm.f90:195
subroutine get_header(this, iline, cval)
Definition: TableTerm.f90:257
integer(i4b) function get_alignment(this)
Definition: TableTerm.f90:154
integer(i4b) function get_width(this)
Definition: TableTerm.f90:142
subroutine initialize(this, tag, width, alignment)
Definition: TableTerm.f90:44
subroutine allocate_scalars(this)
Definition: TableTerm.f90:178
subroutine set_header(this, nlines)
Definition: TableTerm.f90:214
integer(i4b) function get_header_lines(this)
Definition: TableTerm.f90:166