Add pointer to single-array map (grow if needed)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(array_ptr), | allocatable | :: | map(:) | |||
| type(array_type), | intent(in), | target | :: | ptr |
subroutine single_map_add(map, ptr) !! Add pointer to single-array map (grow if needed) implicit none type(array_ptr), allocatable :: map(:) type(array_type), intent(in), target :: ptr integer :: n, i if(.not. allocated(map))then allocate(map(diffstruc__init_map_cap)) end if n = size(map) ! find first null slot do i = 1, n if(.not. associated(map(i)%p))then map(i)%p => ptr return end if end do ! no slot -> grow (double capacity) block type(array_ptr) :: tmp(n) integer :: newcap newcap = n tmp = map deallocate(map) allocate(map(n + newcap)) map(1:n) = tmp end block map(n+1)%p => ptr end subroutine single_map_add