MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
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 (1d array, or always 1 for keystring loads)
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) :: head_nbody = 0 !< on a record head column: number of body columns that follow it (0 on non-head columns)
56 integer(I4B) :: body_start = 0 !< on a record head column: SA column index of its first body (0 = not a head/metadata vector)
57 integer(I4B) :: charlen = linelength !< character length for charstr1d allocation
58 character(len=LENVARNAME) :: varname_override = '' !< overrides idt%mf6varname as the memory-manager name
59 ! Data pointers
60 integer(I4B), dimension(:), pointer, contiguous :: int1d => null()
61 integer(I4B), dimension(:, :), pointer, contiguous :: int2d => null()
62 real(dp), dimension(:), pointer, contiguous :: dbl1d => null()
63 real(dp), dimension(:, :), pointer, contiguous :: dbl2d => null()
64 type(characterstringtype), dimension(:), pointer, contiguous :: &
65 charstr1d => null()
66 type(stlvecint), pointer :: intvector => null()
67 logical(LGP) :: intvector_ragged = .false. !< .true. if column has no predetermined width; read to end of record
68 type(stlvecint), pointer :: intvector_ia => null() !< CSR row-start offsets into intvector; published as "<TAGNAME>_IA"
69 ! Shape data pointers
70 integer(I4B), pointer :: intshape => null()
71 integer(I4B), dimension(:), pointer, contiguous :: intvector_shape => null()
72 ! TimeSeries strings
73 type(listtype) :: ts_strlocs
74 contains
75 procedure :: clear => sv_clear
76 procedure :: read_token => sv_read_token
77 procedure :: add_ts_strloc => sv_add_ts_strloc
78 procedure :: get_ts_strloc => sv_get_ts_strloc
79 end type structvectortype
80
81contains
82
83 function sv_read_token(this, token, structarray_col, col, row) result(val)
84 class(structvectortype) :: this
85 character(len=*), intent(in) :: token
86 integer(I4B), intent(in) :: structarray_col
87 integer(I4B), intent(in) :: col
88 integer(I4B), intent(in) :: row
89 real(dp) :: val
90 integer(I4B) :: istat
91 real(dp) :: r
92 ! initialize
93 val = dnodata
94 read (token, *, iostat=istat) r
95 if (istat == 0) then
96 val = r
97 else
98 call this%add_ts_strloc(token, structarray_col, col, row)
99 end if
100 end function sv_read_token
101
102 subroutine sv_add_ts_strloc(this, token, structarray_col, col, row)
103 class(structvectortype) :: this
104 character(len=*), intent(in) :: token
105 integer(I4B), intent(in) :: structarray_col
106 integer(I4B), intent(in) :: col
107 integer(I4B), intent(in) :: row
108 class(tsstringloctype), pointer :: str_field
109 class(*), pointer :: obj
110 allocate (str_field)
111 str_field%structarray_col = structarray_col
112 str_field%col = col
113 str_field%row = row
114 str_field%token = token
115 obj => str_field
116 call this%ts_strlocs%Add(obj)
117 end subroutine sv_add_ts_strloc
118
119 function sv_get_ts_strloc(this, idx) result(res)
120 class(structvectortype) :: this
121 integer(I4B), intent(in) :: idx !< package number
122 class(tsstringloctype), pointer :: res
123 class(*), pointer :: obj
124 ! initialize res
125 res => null()
126 ! get the package from the list
127 obj => this%ts_strlocs%GetItem(idx)
128 if (associated(obj)) then
129 select type (obj)
130 class is (tsstringloctype)
131 res => obj
132 end select
133 end if
134 end function sv_get_ts_strloc
135
136 !> @brief
137 !<
138 subroutine sv_clear(this)
139 class(structvectortype) :: this
140 class(tsstringloctype), pointer :: ts_strloc
141 integer(I4B) :: n
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 call this%ts_strlocs%Clear()
148 end subroutine sv_clear
149
150end 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
subroutine clear(this, destroy)
Deallocate all items in list.
Definition List.f90:89
This module contains the StructVectorModule.
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)
@ mtype_str
charstr1d column
@ mtype_int2d
int2d (NCELLDIM) column
@ mtype_int
int1d column
@ mtype_undef
undefined memtype
@ mtype_intvec
intvector column
@ mtype_dbl2d
dbl2d (NAUX/NSEG) column
@ mtype_dbl
dbl1d column
This class is used to store a single deferred-length character string. It was designed to work in an ...
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