MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
StringList.f90
Go to the documentation of this file.
2 
3  use kindmodule, only: dp, i4b
4  use listmodule, only: listtype
6 
7  private
9 
10 contains
11 
12  subroutine constructcharactercontainer(newCharCont, text)
13  implicit none
14  type(characterstringtype), pointer, intent(out) :: newCharCont
15  character(len=*), intent(in) :: text
16  !
17  allocate (newcharcont)
18  newcharcont = text
19  end subroutine constructcharactercontainer
20 
21  function castascharacterstringtype(obj) result(res)
22  implicit none
23  class(*), pointer, intent(inout) :: obj
24  type(characterstringtype), pointer :: res
25  !
26  res => null()
27  if (.not. associated(obj)) return
28  !
29  select type (obj)
30  type is (characterstringtype)
31  res => obj
32  end select
33  end function castascharacterstringtype
34 
35  subroutine addstringtolist(list, string)
36  implicit none
37  ! -- dummy
38  type(listtype), intent(inout) :: list
39  character(len=*), intent(in) :: string
40  ! -- local
41  class(*), pointer :: obj
42  type(characterstringtype), pointer :: newcharactercontainer
43  !
44  newcharactercontainer => null()
45  call constructcharactercontainer(newcharactercontainer, string)
46  if (associated(newcharactercontainer)) then
47  obj => newcharactercontainer
48  call list%Add(obj)
49  end if
50  end subroutine addstringtolist
51 
52  function getstringfromlist(list, indx) result(string)
53  implicit none
54  ! -- dummy
55  type(listtype), intent(inout) :: list
56  integer(I4B), intent(in) :: indx
57  character(len=:), allocatable :: string
58  ! -- local
59  class(*), pointer :: obj
60  type(characterstringtype), pointer :: charcont
61  !
62  obj => list%GetItem(indx)
63  charcont => castascharacterstringtype(obj)
64  if (associated(charcont)) then
65  allocate (character(len=charcont%strlen()) :: string)
66  string(:) = charcont
67  else
68  string = ''
69  end if
70  end function getstringfromlist
71 
72 end module stringlistmodule
This module defines variable data types.
Definition: kind.f90:8
subroutine constructcharactercontainer(newCharCont, text)
Definition: StringList.f90:13
type(characterstringtype) function, pointer castascharacterstringtype(obj)
Definition: StringList.f90:22
character(len=:) function, allocatable, public getstringfromlist(list, indx)
Definition: StringList.f90:53
subroutine, public addstringtolist(list, string)
Definition: StringList.f90:36
This class is used to store a single deferred-length character string. It was designed to work in an ...
Definition: CharString.f90:23
A generic heterogeneous doubly-linked list.
Definition: List.f90:14