MODFLOW 6  version 6.8.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
22 
23  enum, bind(C)
24  enumerator :: mtype_undef = 0 !< undefined memtype
25  enumerator :: mtype_int = 1 !< int1d column
26  enumerator :: mtype_dbl = 2 !< dbl1d column
27  enumerator :: mtype_str = 3 !< charstr1d column
28  enumerator :: mtype_intvec = 4 !< intvector column
29  enumerator :: mtype_int2d = 5 !< int2d (NCELLDIM) column
30  enumerator :: mtype_dbl2d = 6 !< dbl2d (NAUX/NSEG) column
31  end enum
32 
33  !> @brief derived type which describes time series string field
34  !<
36  integer(I4B) :: structarray_col !< global SA column index
37  integer(I4B) :: col !< SV column (1 if 1d array)
38  integer(I4B) :: row !< SV row
39  character(LINELENGTH) :: token !< TS string token
40  contains
41  end type tsstringloctype
42 
43  !> @brief derived type for generic vector
44  !!
45  !! This derived type is used in the StructArrayType to
46  !! store any type of vector.
47  !!
48  !<
50  type(inputparamdefinitiontype), pointer :: idt !< input definition
51  ! SA vector attributes
52  integer(I4B) :: memtype = 0 !< SA memtype
53  integer(I4B) :: icol = 0 !< SA column
54  integer(I4B) :: size = 0 !< size of array
55  integer(I4B) :: nsubmembers = 0 !< sub-member count for compound KEYWORD
56  ! Data pointers
57  integer(I4B), dimension(:), pointer, contiguous :: int1d => null()
58  integer(I4B), dimension(:, :), pointer, contiguous :: int2d => null()
59  real(dp), dimension(:), pointer, contiguous :: dbl1d => null()
60  real(dp), dimension(:, :), pointer, contiguous :: dbl2d => null()
61  type(characterstringtype), dimension(:), pointer, contiguous :: &
62  charstr1d => null()
63  type(stlvecint), pointer :: intvector => null()
64  ! Shape data pointers
65  integer(I4B), pointer :: intshape => null()
66  integer(I4B), dimension(:), pointer, contiguous :: intvector_shape => null()
67  ! TimeSeries strings
68  type(listtype) :: ts_strlocs
69  contains
70  procedure :: clear => sv_clear
71  procedure :: read_token => sv_read_token
72  procedure :: add_ts_strloc => sv_add_ts_strloc
73  procedure :: get_ts_strloc => sv_get_ts_strloc
74  end type structvectortype
75 
76 contains
77 
78  function sv_read_token(this, token, structarray_col, col, row) result(val)
79  class(structvectortype) :: this
80  character(len=*), intent(in) :: token
81  integer(I4B), intent(in) :: structarray_col
82  integer(I4B), intent(in) :: col
83  integer(I4B), intent(in) :: row
84  real(dp) :: val
85  integer(I4B) :: istat
86  real(dp) :: r
87  ! initialize
88  val = dnodata
89  read (token, *, iostat=istat) r
90  if (istat == 0) then
91  val = r
92  else
93  call this%add_ts_strloc(token, structarray_col, col, row)
94  end if
95  end function sv_read_token
96 
97  subroutine sv_add_ts_strloc(this, token, structarray_col, col, row)
98  class(structvectortype) :: this
99  character(len=*), intent(in) :: token
100  integer(I4B), intent(in) :: structarray_col
101  integer(I4B), intent(in) :: col
102  integer(I4B), intent(in) :: row
103  class(tsstringloctype), pointer :: str_field
104  class(*), pointer :: obj
105  allocate (str_field)
106  str_field%structarray_col = structarray_col
107  str_field%col = col
108  str_field%row = row
109  str_field%token = token
110  obj => str_field
111  call this%ts_strlocs%Add(obj)
112  end subroutine sv_add_ts_strloc
113 
114  function sv_get_ts_strloc(this, idx) result(res)
115  class(structvectortype) :: this
116  integer(I4B), intent(in) :: idx !< package number
117  class(tsstringloctype), pointer :: res
118  class(*), pointer :: obj
119  ! initialize res
120  res => null()
121  ! get the package from the list
122  obj => this%ts_strlocs%GetItem(idx)
123  if (associated(obj)) then
124  select type (obj)
125  class is (tsstringloctype)
126  res => obj
127  end select
128  end if
129  end function sv_get_ts_strloc
130 
131  !> @brief
132  !<
133  subroutine sv_clear(this)
134  class(structvectortype) :: this
135  class(tsstringloctype), pointer :: ts_strloc
136  integer(I4B) :: n
137  do n = 1, this%ts_strlocs%Count()
138  ts_strloc => this%get_ts_strloc(n)
139  deallocate (ts_strloc)
140  nullify (ts_strloc)
141  end do
142  call this%ts_strlocs%Clear()
143  end subroutine sv_clear
144 
145 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
Input definition module.
This module defines variable data types.
Definition: kind.f90:8
This module contains the StructVectorModule.
Definition: StructVector.f90:7
@, public mtype_intvec
intvector column
class(tsstringloctype) function, pointer sv_get_ts_strloc(this, idx)
@, public mtype_dbl
dbl1d column
real(dp) function sv_read_token(this, token, structarray_col, col, row)
@, public mtype_int2d
int2d (NCELLDIM) column
@, public mtype_int
int1d column
@, public mtype_dbl2d
dbl2d (NAUX/NSEG) column
@, public mtype_str
charstr1d column
@, public mtype_undef
undefined memtype
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
Input parameter definition. Describes an input parameter.
A generic heterogeneous doubly-linked list.
Definition: List.f90:14
derived type for generic vector
derived type which describes time series string field