MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
StructVector.f90
Go to the documentation of this file.
1 !> @brief This module contains the StructVectorModule
2 !!
3 !! This module contains a generic type for storing
4 !! different types of vectors.
5 !!
6 !<
8 
9  use kindmodule, only: i4b, dp, lgp
12  use listmodule, only: listtype
15  use stlvecintmodule, only: stlvecint
17 
18  implicit none
19  private
21 
22  !> @brief derived type which describes time series string field
23  !<
25  integer(I4B) :: structarray_col !< global SA column index
26  integer(I4B) :: col !< SV column (1 if 1d array)
27  integer(I4B) :: row !< SV row
28  character(LINELENGTH) :: token !< TS string token
29  contains
30  end type tsstringloctype
31 
32  !> @brief derived type for generic vector
33  !!
34  !! This derived type is used in the StructArrayType to
35  !! store any type of vector.
36  !!
37  !<
39  type(inputparamdefinitiontype), pointer :: idt !< input definition
40  ! SA vector attributes
41  integer(I4B) :: memtype = 0 !< SA memtype
42  integer(I4B) :: icol = 0 !< SA column
43  integer(I4B) :: size = 0 !< size of array
44  ! Data pointers
45  integer(I4B), dimension(:), pointer, contiguous :: int1d => null()
46  integer(I4B), dimension(:, :), pointer, contiguous :: int2d => null()
47  real(dp), dimension(:), pointer, contiguous :: dbl1d => null()
48  real(dp), dimension(:, :), pointer, contiguous :: dbl2d => null()
49  type(characterstringtype), dimension(:), pointer, contiguous :: &
50  charstr1d => null()
51  type(stlvecint), pointer :: intvector => null()
52  ! Shape data pointers
53  integer(I4B), pointer :: intshape => null()
54  integer(I4B), dimension(:), pointer, contiguous :: intvector_shape => null()
55  ! TimeSeries strings
56  type(listtype) :: ts_strlocs
57  contains
58  procedure :: clear => sv_clear
59  procedure :: read_token => sv_read_token
60  procedure :: add_ts_strloc => sv_add_ts_strloc
61  procedure :: get_ts_strloc => sv_get_ts_strloc
62  end type structvectortype
63 
64 contains
65 
66  function sv_read_token(this, token, structarray_col, col, row) result(val)
67  ! -- modules
68  ! -- dummy
69  class(structvectortype) :: this
70  character(len=*), intent(in) :: token
71  integer(I4B), intent(in) :: structarray_col
72  integer(I4B), intent(in) :: col
73  integer(I4B), intent(in) :: row
74  real(dp) :: val
75  ! -- local
76  integer(I4B) :: istat
77  real(dp) :: r
78  !
79  ! -- initialize
80  val = dnodata
81  !
82  read (token, *, iostat=istat) r
83  if (istat == 0) then
84  val = r
85  else
86  call this%add_ts_strloc(token, structarray_col, col, row)
87  end if
88  end function sv_read_token
89 
90  subroutine sv_add_ts_strloc(this, token, structarray_col, col, row)
91  ! -- dummy variables
92  class(structvectortype) :: this
93  character(len=*), intent(in) :: token
94  integer(I4B), intent(in) :: structarray_col
95  integer(I4B), intent(in) :: col
96  integer(I4B), intent(in) :: row
97  class(tsstringloctype), pointer :: str_field
98  ! -- local variables
99  class(*), pointer :: obj
100  !
101  ! --
102  allocate (str_field)
103  str_field%structarray_col = structarray_col
104  str_field%col = col
105  str_field%row = row
106  str_field%token = token
107  !
108  obj => str_field
109  call this%ts_strlocs%Add(obj)
110  end subroutine sv_add_ts_strloc
111 
112  function sv_get_ts_strloc(this, idx) result(res)
113  ! -- dummy variables
114  class(structvectortype) :: this
115  integer(I4B), intent(in) :: idx !< package number
116  class(tsstringloctype), pointer :: res
117  ! -- local variables
118  class(*), pointer :: obj
119  !
120  ! -- initialize res
121  res => null()
122  !
123  ! -- get the package from the list
124  obj => this%ts_strlocs%GetItem(idx)
125  if (associated(obj)) then
126  select type (obj)
127  class is (tsstringloctype)
128  res => obj
129  end select
130  end if
131  end function sv_get_ts_strloc
132 
133  !> @brief
134  !<
135  subroutine sv_clear(this)
136  ! -- modules
137  ! -- dummy
138  class(structvectortype) :: this
139  class(tsstringloctype), pointer :: ts_strloc
140  integer(I4B) :: n
141  !
142  do n = 1, this%ts_strlocs%Count()
143  ts_strloc => this%get_ts_strloc(n)
144  deallocate (ts_strloc)
145  nullify (ts_strloc)
146  end do
147  !
148  call this%ts_strlocs%Clear()
149  !
150  return
151  end subroutine sv_clear
152 
153 end module structvectormodule
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition: Constants.f90:45
real(dp), parameter dnodata
real no data constant
Definition: Constants.f90:95
integer(i4b), parameter lentimeseriesname
maximum length of a time series name
Definition: Constants.f90:42
integer(i4b), parameter lenvarname
maximum length of a variable name
Definition: Constants.f90:17
integer(i4b), parameter lenmempath
maximum length of the memory path
Definition: Constants.f90:27
This module contains the InputDefinitionModule.
This module defines variable data types.
Definition: kind.f90:8
This module contains the StructVectorModule.
Definition: StructVector.f90:7
class(tsstringloctype) function, pointer sv_get_ts_strloc(this, idx)
real(dp) function sv_read_token(this, token, structarray_col, col, row)
subroutine sv_add_ts_strloc(this, token, structarray_col, col, row)
subroutine sv_clear(this)
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
derived type for generic vector
derived type which describes time series string field