MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
Memory.f90
Go to the documentation of this file.
2 
3  use kindmodule, only: dp, lgp, i4b
9  use tablemodule, only: tabletype
11 
12  implicit none
13  private
14  public :: memorytype
15 
17  character(len=LENVARNAME) :: name !< name of the array
18  character(len=LENVARNAME) :: mastername = 'none' !< name of the master array
19  character(len=LENMEMPATH) :: path !< path to memory object
20  character(len=LENMEMPATH) :: masterpath = 'none' !< path to master memory object
21  character(len=LENMEMTYPE) :: memtype !< type (INTEGER or DOUBLE)
22  integer(I4B) :: id !< id, not used
23  integer(I4B) :: nrealloc = 0 !< number of times reallocated
24  integer(I4B) :: isize = -1 !< size of the array, equal to the number of array elements; 1 for scalars
25  integer(I4B) :: element_size = 0 !< byte size of an element; string length
26  integer(I4B) :: set_handler_idx = 0 !< index of side effect handler for external access
27  logical(LGP) :: master = .true. !< master copy, others point to this one
28  character(len=:), pointer :: strsclr => null() !< pointer to the character string
29  logical(LGP), pointer :: logicalsclr => null() !< pointer to the logical
30  integer(I4B), pointer :: intsclr => null() !< pointer to the integer
31  real(dp), pointer :: dblsclr => null() !< pointer to the double
32  character(len=:), dimension(:), pointer, contiguous :: astr1d => null() !< pointer to the 1d character string array
33  integer(I4B), dimension(:), pointer, contiguous :: aint1d => null() !< pointer to 1d integer array
34  integer(I4B), dimension(:, :), pointer, contiguous :: aint2d => null() !< pointer to 2d integer array
35  integer(I4B), dimension(:, :, :), pointer, contiguous :: aint3d => null() !< pointer to 3d integer array
36  real(dp), dimension(:), pointer, contiguous :: adbl1d => null() !< pointer to 1d double array
37  real(dp), dimension(:, :), pointer, contiguous :: adbl2d => null() !< pointer to 2d double array
38  real(dp), dimension(:, :, :), pointer, contiguous :: adbl3d => null() !< pointer to 3d double array
39  type(characterstringtype), dimension(:), pointer, contiguous :: &
40  acharstr1d => null() !< pointer to the 1d character string array
41  contains
42  procedure :: table_entry
43  procedure :: mt_associated
44  procedure :: mt_deallocate
45  end type
46 
47 contains
48 
49  subroutine table_entry(this, memtab)
50  ! -- dummy
51  class(memorytype) :: this
52  type(tabletype), intent(inout) :: memtab
53  ! -- local
54  character(len=16) :: cmem
55  character(len=LENMEMADDRESS) :: cptr
56  integer(I4B) :: ipos
57  ! -- formats
58  !
59  ! -- determine memory type
60  ipos = index(this%memtype, ' (')
61  if (ipos < 1) then
62  ipos = 16
63  else
64  ipos = min(16, ipos - 1)
65  end if
66  cmem = this%memtype(1:ipos)
67  !
68  ! -- Set pointer string
69  cptr = '--'
70  if (.not. this%master) then
71  cptr = create_mem_address(this%masterPath, this%mastername)
72  end if
73  !
74  ! -- write data to the table
75  call memtab%add_term(this%path)
76  call memtab%add_term(this%name)
77  call memtab%add_term(cmem)
78  call memtab%add_term(this%isize)
79  call memtab%add_term(cptr)
80  end subroutine table_entry
81 
82  function mt_associated(this) result(al)
83  class(memorytype) :: this
84  logical :: al
85  al = .false.
86  if (associated(this%strsclr)) al = .true.
87  if (associated(this%logicalsclr)) al = .true.
88  if (associated(this%intsclr)) al = .true.
89  if (associated(this%dblsclr)) al = .true.
90  if (associated(this%astr1d)) al = .true.
91  if (associated(this%aint1d)) al = .true.
92  if (associated(this%aint2d)) al = .true.
93  if (associated(this%aint3d)) al = .true.
94  if (associated(this%adbl1d)) al = .true.
95  if (associated(this%adbl2d)) al = .true.
96  if (associated(this%adbl3d)) al = .true.
97  if (associated(this%acharstr1d)) al = .true.
98  end function mt_associated
99 
100  subroutine mt_deallocate(this)
101  class(memorytype) :: this
102  integer(I4B) :: n
103 
104  if (associated(this%strsclr)) then
105  if (this%master) deallocate (this%strsclr)
106  nullify (this%strsclr)
107  end if
108 
109  if (associated(this%logicalsclr)) then
110  if (this%master) deallocate (this%logicalsclr)
111  nullify (this%logicalsclr)
112  end if
113 
114  if (associated(this%intsclr)) then
115  if (this%master) deallocate (this%intsclr)
116  nullify (this%intsclr)
117  end if
118 
119  if (associated(this%dblsclr)) then
120  if (this%master) deallocate (this%dblsclr)
121  nullify (this%dblsclr)
122  end if
123 
124  if (associated(this%astr1d)) then
125  if (this%master) deallocate (this%astr1d)
126  nullify (this%astr1d)
127  end if
128 
129  if (associated(this%aint1d)) then
130  if (this%master) deallocate (this%aint1d)
131  nullify (this%aint1d)
132  end if
133 
134  if (associated(this%aint2d)) then
135  if (this%master) deallocate (this%aint2d)
136  nullify (this%aint2d)
137  end if
138 
139  if (associated(this%aint3d)) then
140  if (this%master) deallocate (this%aint3d)
141  nullify (this%aint3d)
142  end if
143 
144  if (associated(this%adbl1d)) then
145  if (this%master) deallocate (this%adbl1d)
146  nullify (this%adbl1d)
147  end if
148 
149  if (associated(this%adbl2d)) then
150  if (this%master) deallocate (this%adbl2d)
151  nullify (this%adbl2d)
152  end if
153 
154  if (associated(this%adbl3d)) then
155  if (this%master) deallocate (this%adbl3d)
156  nullify (this%adbl3d)
157  end if
158 
159  if (associated(this%acharstr1d)) then
160  if (this%master) then
161  do n = 1, size(this%acharstr1d)
162  call this%acharstr1d(n)%destroy()
163  end do
164  deallocate (this%acharstr1d)
165  end if
166  nullify (this%acharstr1d)
167  end if
168  end subroutine mt_deallocate
169 
170 end module memorytypemodule
This module contains simulation constants.
Definition: Constants.f90:9
@ tabcenter
centered table column
Definition: Constants.f90:172
@ tabright
right justified table column
Definition: Constants.f90:173
@ tableft
left justified table column
Definition: Constants.f90:171
integer(i4b), parameter lenmemaddress
maximum length of the full memory address, including variable name
Definition: Constants.f90:31
@ tabstring
string table data
Definition: Constants.f90:179
@ tabinteger
integer table data
Definition: Constants.f90:181
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, public maxmemrank
maximum memory manager length (up to 3-dimensional arrays)
Definition: Constants.f90:61
integer(i4b), parameter, public lenmemtype
maximum length of a memory manager type
Definition: Constants.f90:62
integer(i4b), parameter lenmempath
maximum length of the memory path
Definition: Constants.f90:27
This module defines variable data types.
Definition: kind.f90:8
character(len=lenmemaddress) function create_mem_address(mem_path, var_name)
returns the address string of the memory object
subroutine mt_deallocate(this)
Definition: Memory.f90:101
subroutine table_entry(this, memtab)
Definition: Memory.f90:50
logical function mt_associated(this)
Definition: Memory.f90:83
This class is used to store a single deferred-length character string. It was designed to work in an ...
Definition: CharString.f90:23