MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
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  subroutine initialize(this, tag, width, alignment)
42 ! ******************************************************************************
43 ! initialize -- initialize the table term
44 ! ******************************************************************************
45 !
46 ! SPECIFICATIONS:
47 ! ------------------------------------------------------------------------------
48  ! -- modules
49  ! -- dummy
50  class(tabletermtype) :: this
51  character(len=*), intent(in) :: tag
52  integer(I4B), intent(in) :: width
53  integer(I4B), intent(in), optional :: alignment
54  ! -- local
55  character(len=LINELENGTH) :: string
56  character(len=LINELENGTH) :: tstring
57  character(len=LINELENGTH), allocatable, dimension(:) :: words
58  integer(I4B) :: nwords
59  integer(I4B) :: ilen
60  integer(I4B) :: i
61  integer(I4B) :: j
62 
63 ! ------------------------------------------------------------------------------
64  !
65  ! -- allocate scalars
66  call this%allocate_scalars()
67 
68  ! -- process dummy variables
69  this%tag = tag
70 
71  if (present(alignment)) then
72  this%alignment = alignment
73  else
74  this%alignment = tabcenter
75  end if
76 
77  this%width = width
78  !
79  ! -- parse tag into words
80  call parseline(tag, nwords, words, 0)
81  !
82  ! -- abbreviate any words that exceed the specified width
83  ! and trim trailing characters
84  do i = 1, nwords
85  ilen = len(trim(words(i)))
86  if (ilen > width) then
87  words(i) (width:width) = '.'
88  do j = width + 1, ilen
89  words(i) (j:j) = ' '
90  end do
91  end if
92  end do
93  !
94  ! -- combine words that fit into width
95  i = 0
96  do
97  i = i + 1
98  if (i > nwords) then
99  exit
100  end if
101  string = trim(adjustl(words(i)))
102  tstring = string
103  do j = i + 1, nwords
104  if (len(trim(adjustl(string))) > 0) then
105  tstring = trim(adjustl(tstring))//' '//trim(adjustl(words(j)))
106  else
107  tstring = trim(adjustl(words(j)))
108  end if
109  ilen = len(trim(adjustl(tstring)))
110  if (ilen == 0) then
111  continue
112  else if (ilen <= width) then
113  words(j) = ' '
114  string = tstring
115  else
116  exit
117  end if
118  end do
119  words(i) = string
120  end do
121  !
122  ! -- calculate the number of header lines
123  do i = 1, nwords
124  ilen = len(trim(adjustl(words(i))))
125  if (ilen > 0) then
126  this%nheader_lines = this%nheader_lines + 1
127  end if
128  end do
129  !
130  ! allocate initial_lines and fill with words
131  allocate (this%initial_lines(this%nheader_lines))
132  do i = 1, this%nheader_lines
133  this%initial_lines(i) = words(i) (1:width)
134  end do
135  !
136  ! -- deallocate words
137  deallocate (words)
138  !
139  ! -- return
140  return
141 
142  end subroutine initialize
143 
144  function get_width(this)
145 ! ******************************************************************************
146 ! get_width -- get column width
147 ! ******************************************************************************
148 !
149 ! SPECIFICATIONS:
150 ! ------------------------------------------------------------------------------
151  ! -- return variable
152  integer(I4B) :: get_width
153  ! -- modules
154  ! -- dummy
155  class(tabletermtype) :: this
156  ! -- local
157 ! ------------------------------------------------------------------------------
158  get_width = this%width
159  !
160  ! -- return
161  return
162  end function get_width
163 
164  function get_alignment(this)
165 ! ******************************************************************************
166 ! get_width -- get column width
167 ! ******************************************************************************
168 !
169 ! SPECIFICATIONS:
170 ! ------------------------------------------------------------------------------
171  ! -- return variable
172  integer(I4B) :: get_alignment
173  ! -- modules
174  ! -- dummy
175  class(tabletermtype) :: this
176  ! -- local
177 ! ------------------------------------------------------------------------------
178  get_alignment = this%alignment
179  !
180  ! -- return
181  return
182  end function get_alignment
183 
184  function get_header_lines(this)
185 ! ******************************************************************************
186 ! get_header_lines -- get the number of lines in initial_lines
187 ! ******************************************************************************
188 !
189 ! SPECIFICATIONS:
190 ! ------------------------------------------------------------------------------
191  ! -- return variable
192  integer(I4B) :: get_header_lines
193  ! -- modules
194  ! -- dummy
195  class(tabletermtype) :: this
196  ! -- local
197 ! ------------------------------------------------------------------------------
198  get_header_lines = this%nheader_lines
199  !
200  ! -- return
201  return
202  end function get_header_lines
203 
204  subroutine allocate_scalars(this)
205 ! ******************************************************************************
206 ! allocate_scalars -- allocate table term scalars
207 ! ******************************************************************************
208 !
209 ! SPECIFICATIONS:
210 ! ------------------------------------------------------------------------------
211  ! -- modules
212  ! -- dummy
213  class(tabletermtype) :: this
214 ! ------------------------------------------------------------------------------
215  !
216  ! -- allocate scalars
217  allocate (this%tag)
218  allocate (this%alignment)
219  allocate (this%width)
220  allocate (this%nheader_lines)
221  !
222  ! -- initialize scalars
223  this%nheader_lines = 0
224  !
225  ! -- return
226  return
227  end subroutine allocate_scalars
228 
229  subroutine da(this)
230 ! ******************************************************************************
231 ! da -- deallocate table terms
232 ! ******************************************************************************
233 !
234 ! SPECIFICATIONS:
235 ! ------------------------------------------------------------------------------
236  ! -- modules
237  ! -- dummy
238  class(tabletermtype) :: this
239  ! -- local
240  !integer(I4B) :: n
241 ! ------------------------------------------------------------------------------
242  !
243  ! -- deallocate scalars
244  deallocate (this%tag)
245  deallocate (this%alignment)
246  deallocate (this%width)
247  deallocate (this%nheader_lines)
248  deallocate (this%header_lines)
249  !
250  ! -- return
251  end subroutine da
252 
253  subroutine set_header(this, nlines)
254 ! ******************************************************************************
255 ! set_header -- set final header lines for table term
256 ! ******************************************************************************
257 !
258 ! SPECIFICATIONS:
259 ! ------------------------------------------------------------------------------
260  ! -- modules
261  ! -- dummy
262  class(tabletermtype) :: this
263  integer(I4B), intent(in) :: nlines
264  ! -- local
265  character(len=this%width) :: string
266  integer(I4B) :: idiff
267  integer(I4B) :: i0
268  integer(I4B) :: i
269  integer(I4B) :: j
270 ! ------------------------------------------------------------------------------
271  !
272  ! -- initialize variables
273  string = ' '
274  !
275  ! allocate header_lines
276  allocate (this%header_lines(nlines))
277  !
278  ! -- initialize header lines
279  do i = 1, nlines
280  this%header_lines(i) = string
281  end do
282  !
283  ! -- fill header_lines with initial_lines from
284  ! bottom to top
285  idiff = nlines - this%nheader_lines
286  i0 = 1 - idiff
287  do i = this%nheader_lines, 1, -1
288  j = i + idiff
289  this%header_lines(j) = this%initial_lines(i)
290  end do
291  !
292  ! -- deallocate temporary header lines
293  deallocate (this%initial_lines)
294  !
295  ! -- reinitialize nheader_lines
296  this%nheader_lines = nlines
297  !
298  ! -- return
299  end subroutine set_header
300 
301  subroutine get_header(this, iline, cval)
302 ! ******************************************************************************
303 ! get_header -- get header entry for table term iline
304 ! ******************************************************************************
305 !
306 ! SPECIFICATIONS:
307 ! ------------------------------------------------------------------------------
308  ! -- modules
309  ! -- dummy
310  class(tabletermtype) :: this
311  integer(I4B), intent(in) :: iline
312  character(len=*), intent(inout) :: cval
313  ! -- return variable
314  ! -- local
315 ! ------------------------------------------------------------------------------
316  !
317  ! -- set return value
318  cval = this%header_lines(iline) (1:this%width)
319  !
320  ! -- return
321  end subroutine get_header
322 
323 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:44
@ tabcenter
centered table column
Definition: Constants.f90:171
@ tabright
right justified table column
Definition: Constants.f90:172
@ tableft
left justified table column
Definition: Constants.f90:170
@ 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 dzero
real constant zero
Definition: Constants.f90:64
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 upcase(word)
Convert to upper case.
This module defines variable data types.
Definition: kind.f90:8
subroutine da(this)
Definition: TableTerm.f90:230
subroutine get_header(this, iline, cval)
Definition: TableTerm.f90:302
integer(i4b) function get_alignment(this)
Definition: TableTerm.f90:165
integer(i4b) function get_width(this)
Definition: TableTerm.f90:145
subroutine initialize(this, tag, width, alignment)
Definition: TableTerm.f90:42
subroutine allocate_scalars(this)
Definition: TableTerm.f90:205
subroutine set_header(this, nlines)
Definition: TableTerm.f90:254
integer(i4b) function get_header_lines(this)
Definition: TableTerm.f90:185