21 #include "../base/base_uses.f90"
24 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'dbt_array_list_methods'
43 INTEGER,
DIMENSION(:),
ALLOCATABLE :: col_data
44 INTEGER,
DIMENSION(:),
ALLOCATABLE :: ptr
48 MODULE PROCEDURE allocate_and_get_ith_array
59 TYPE(array_list),
INTENT(IN) ::
list
72 TYPE(array_list),
INTENT(IN) ::
list
73 INTEGER,
DIMENSION(number_of_arrays(list)),
INTENT(IN) :: indices
78 DO i = 1,
SIZE(indices)
79 ind = indices(i) +
list%ptr(i) - 1
94 TYPE(array_list),
INTENT(OUT) ::
list
95 INTEGER,
INTENT(IN) :: ndata
96 INTEGER,
DIMENSION(:),
INTENT(IN),
OPTIONAL :: data_1, data_2, data_3, data_4
97 INTEGER :: ptr, size_all
101 IF (ndata .GE. 1)
THEN
102 cpassert(
PRESENT(data_1))
103 size_all = size_all +
SIZE(data_1)
105 IF (ndata .GE. 2)
THEN
106 cpassert(
PRESENT(data_2))
107 size_all = size_all +
SIZE(data_2)
109 IF (ndata .GE. 3)
THEN
110 cpassert(
PRESENT(data_3))
111 size_all = size_all +
SIZE(data_3)
113 IF (ndata .GE. 4)
THEN
114 cpassert(
PRESENT(data_4))
115 size_all = size_all +
SIZE(data_4)
118 ALLOCATE (
list%ptr(ndata + 1))
119 ALLOCATE (
list%col_data(size_all))
124 IF (ndata .GE. 1)
THEN
125 list%col_data(ptr:ptr +
SIZE(data_1) - 1) = data_1(:)
126 ptr = ptr +
SIZE(data_1)
129 IF (ndata .GE. 2)
THEN
130 list%col_data(ptr:ptr +
SIZE(data_2) - 1) = data_2(:)
131 ptr = ptr +
SIZE(data_2)
134 IF (ndata .GE. 3)
THEN
135 list%col_data(ptr:ptr +
SIZE(data_3) - 1) = data_3(:)
136 ptr = ptr +
SIZE(data_3)
139 IF (ndata .GE. 4)
THEN
140 list%col_data(ptr:ptr +
SIZE(data_4) - 1) = data_4(:)
141 ptr = ptr +
SIZE(data_4)
154 TYPE(array_list),
INTENT(IN) ::
list
155 INTEGER,
DIMENSION(:),
INTENT(IN) :: i_selected
158 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: data_1, data_2, data_3, data_4
160 ndata =
SIZE(i_selected)
171 CALL get_arrays(
list, data_1, data_2, data_3, i_selected=i_selected)
175 CALL get_arrays(
list, data_1, data_2, data_3, data_4, i_selected=i_selected)
185 TYPE(array_list),
INTENT(INOUT) ::
list
187 DEALLOCATE (
list%ptr,
list%col_data)
196 SUBROUTINE get_arrays(list, data_1, data_2, data_3, data_4, i_selected)
198 TYPE(array_list),
INTENT(IN) ::
list
199 INTEGER,
ALLOCATABLE,
DIMENSION(:),
INTENT(OUT), &
200 OPTIONAL :: data_1, data_2, data_3, data_4
201 INTEGER,
DIMENSION(:),
INTENT(IN), &
202 OPTIONAL :: i_selected
204 INTEGER,
DIMENSION(number_of_arrays(list)) :: o
207 IF (
PRESENT(i_selected))
THEN
208 ndata =
SIZE(i_selected)
209 o(1:ndata) = i_selected(:)
212 o(1:ndata) = (/(i, i=1, ndata)/)
215 associate(ptr =>
list%ptr, col_data =>
list%col_data)
217 ALLOCATE (data_1, source=col_data(ptr(o(1)):ptr(o(1) + 1) - 1))
220 ALLOCATE (data_2, source=col_data(ptr(o(2)):ptr(o(2) + 1) - 1))
223 ALLOCATE (data_3, source=col_data(ptr(o(3)):ptr(o(3) + 1) - 1))
226 ALLOCATE (data_4, source=col_data(ptr(o(4)):ptr(o(4) + 1) - 1))
237 TYPE(array_list),
INTENT(IN) ::
list
238 INTEGER,
INTENT(IN) :: i
239 INTEGER,
INTENT(IN) :: array_size
240 INTEGER,
DIMENSION(array_size),
INTENT(OUT) :: array
242 associate(ptr =>
list%ptr, col_data =>
list%col_data)
245 array(:) = col_data(ptr(i):ptr(i + 1) - 1)
255 SUBROUTINE allocate_and_get_ith_array(list, i, array)
256 TYPE(array_list),
INTENT(IN) ::
list
257 INTEGER,
INTENT(IN) :: i
258 INTEGER,
DIMENSION(:),
ALLOCATABLE,
INTENT(OUT) :: array
260 associate(ptr =>
list%ptr, col_data =>
list%col_data)
263 ALLOCATE (array, source=col_data(ptr(i):ptr(i + 1) - 1))
272 TYPE(array_list),
INTENT(IN) ::
list
275 INTEGER :: i_data, num_data
279 DO i_data = 1, num_data
289 TYPE(array_list),
INTENT(IN) ::
list
292 INTEGER :: i_data, num_data
296 DO i_data = 1, num_data
307 TYPE(array_list),
INTENT(IN) :: list_in
308 TYPE(array_list),
INTENT(OUT) :: list_out
310 INTEGER :: i_data, i_ptr, num_data, partial_sum
313 ALLOCATE (list_out%ptr, source=list_in%ptr)
314 ALLOCATE (list_out%col_data(
SIZE(list_in%col_data)))
315 DO i_data = 1, num_data
317 DO i_ptr = list_out%ptr(i_data), list_out%ptr(i_data + 1) - 1
318 list_out%col_data(i_ptr) = partial_sum
319 partial_sum = partial_sum + list_in%col_data(i_ptr)
329 TYPE(array_list),
INTENT(IN) :: list_in
330 TYPE(array_list),
INTENT(OUT) :: list_out
331 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: data_1, data_2, data_3, data_4
332 INTEGER,
DIMENSION(number_of_arrays(list_in)), &
336 CALL get_arrays(list_in, data_1, data_2, i_selected=dbt_inverse_order(order))
341 CALL get_arrays(list_in, data_1, data_2, data_3, i_selected=dbt_inverse_order(order))
343 data_1, data_2, data_3)
346 CALL get_arrays(list_in, data_1, data_2, data_3, data_4, i_selected=dbt_inverse_order(order))
348 data_1, data_2, data_3, data_4)
358 TYPE(array_list),
INTENT(IN) :: list1, list2
369 INTEGER,
INTENT(IN),
DIMENSION(:) :: arr1
370 INTEGER,
INTENT(IN),
DIMENSION(:) :: arr2
374 IF (
SIZE(arr1) .EQ.
SIZE(arr2))
array_eq_i = all(arr1 == arr2)
Wrapper for allocating, copying and reshaping arrays.
Representation of arbitrary number of 1d integer arrays with arbitrary sizes. This is needed for gene...
pure logical function, public array_eq_i(arr1, arr2)
check whether two arrays are equal
integer function, dimension(:), allocatable, public sum_of_arrays(list)
sum of all elements for each array stored in list
subroutine, public get_arrays(list, data_1, data_2, data_3, data_4, i_selected)
Get all arrays contained in list.
subroutine, public create_array_list(list, ndata, data_1, data_2, data_3, data_4)
collects any number of arrays of different sizes into a single array (listcol_data),...
subroutine, public destroy_array_list(list)
destroy array list.
integer function, dimension(:), allocatable, public sizes_of_arrays(list)
sizes of arrays stored in list
pure integer function, public number_of_arrays(list)
number of arrays stored in list
subroutine, public array_offsets(list_in, list_out)
partial sums of array elements.
pure integer function, dimension(number_of_arrays(list)), public get_array_elements(list, indices)
Get an element for each array.
subroutine, public get_ith_array(list, i, array_size, array)
get ith array
type(array_list) function, public array_sublist(list, i_selected)
extract a subset of arrays
subroutine, public reorder_arrays(list_in, list_out, order)
reorder array list.
logical function, public check_equal(list1, list2)
check whether two array lists are equal
tensor index and mapping to DBM index
pure integer function, dimension(size(order)), public dbt_inverse_order(order)
Invert order.
An array-based list which grows on demand. When the internal array is full, a new array of twice the ...