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
16 
17  implicit none
18  private
20 
21  !> @brief derived type which describes time series string field
22  !<
24  integer(I4B) :: structarray_col !< global SA column index
25  integer(I4B) :: col !< SV column (1 if 1d array)
26  integer(I4B) :: row !< SV row
27  character(LINELENGTH) :: token !< TS string token
28  contains
29  end type tsstringloctype
30 
31  !> @brief derived type for generic vector
32  !!
33  !! This derived type is used in the StructArrayType to
34  !! store any type of vector.
35  !!
36  !<
38  type(inputparamdefinitiontype), pointer :: idt !< input definition
39  ! SA vector attributes
40  integer(I4B) :: memtype = 0 !< SA memtype
41  integer(I4B) :: icol = 0 !< SA column
42  integer(I4B) :: size = 0 !< size of array
43  ! Data pointers
44  integer(I4B), dimension(:), pointer, contiguous :: int1d => null()
45  integer(I4B), dimension(:, :), pointer, contiguous :: int2d => null()
46  real(dp), dimension(:), pointer, contiguous :: dbl1d => null()
47  real(dp), dimension(:, :), pointer, contiguous :: dbl2d => null()
48  type(characterstringtype), dimension(:), pointer, contiguous :: &
49  charstr1d => null()
50  type(stlvecint), pointer :: intvector => null()
51  ! Shape data pointers
52  integer(I4B), pointer :: intshape => null()
53  integer(I4B), dimension(:), pointer, contiguous :: intvector_shape => null()
54  ! TimeSeries strings
55  type(listtype) :: ts_strlocs
56  contains
57  procedure :: clear => sv_clear
58  procedure :: read_token => sv_read_token
59  procedure :: add_ts_strloc => sv_add_ts_strloc
60  procedure :: get_ts_strloc => sv_get_ts_strloc
61  end type structvectortype
62 
63 contains
64 
65  function sv_read_token(this, token, structarray_col, col, row) result(val)
66  class(structvectortype) :: this
67  character(len=*), intent(in) :: token
68  integer(I4B), intent(in) :: structarray_col
69  integer(I4B), intent(in) :: col
70  integer(I4B), intent(in) :: row
71  real(dp) :: val
72  integer(I4B) :: istat
73  real(dp) :: r
74  ! initialize
75  val = dnodata
76  read (token, *, iostat=istat) r
77  if (istat == 0) then
78  val = r
79  else
80  call this%add_ts_strloc(token, structarray_col, col, row)
81  end if
82  end function sv_read_token
83 
84  subroutine sv_add_ts_strloc(this, token, structarray_col, col, row)
85  class(structvectortype) :: this
86  character(len=*), intent(in) :: token
87  integer(I4B), intent(in) :: structarray_col
88  integer(I4B), intent(in) :: col
89  integer(I4B), intent(in) :: row
90  class(tsstringloctype), pointer :: str_field
91  class(*), pointer :: obj
92  allocate (str_field)
93  str_field%structarray_col = structarray_col
94  str_field%col = col
95  str_field%row = row
96  str_field%token = token
97  obj => str_field
98  call this%ts_strlocs%Add(obj)
99  end subroutine sv_add_ts_strloc
100 
101  function sv_get_ts_strloc(this, idx) result(res)
102  class(structvectortype) :: this
103  integer(I4B), intent(in) :: idx !< package number
104  class(tsstringloctype), pointer :: res
105  class(*), pointer :: obj
106  ! initialize res
107  res => null()
108  ! get the package from the list
109  obj => this%ts_strlocs%GetItem(idx)
110  if (associated(obj)) then
111  select type (obj)
112  class is (tsstringloctype)
113  res => obj
114  end select
115  end if
116  end function sv_get_ts_strloc
117 
118  !> @brief
119  !<
120  subroutine sv_clear(this)
121  class(structvectortype) :: this
122  class(tsstringloctype), pointer :: ts_strloc
123  integer(I4B) :: n
124  do n = 1, this%ts_strlocs%Count()
125  ts_strloc => this%get_ts_strloc(n)
126  deallocate (ts_strloc)
127  nullify (ts_strloc)
128  end do
129  call this%ts_strlocs%Clear()
130  end subroutine sv_clear
131 
132 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