expand_ga2d_long Subroutine

public subroutine expand_ga2d_long(me, length)

expand the growing 2d array

first reset all entries

Arguments

Type IntentOptional Attributes Name
type(grw_long2darray_type) :: me

array to resize

integer, intent(in), optional :: length

optional length to expand the array


Called by

proc~~expand_ga2d_long~~CalledByGraph proc~expand_ga2d_long expand_ga2d_long interface~expand~16 expand interface~expand~16->proc~expand_ga2d_long

Source Code

  subroutine expand_ga2d_long( me, length )
    ! --------------------------------------------------------------------------
    !> array to resize
    type(grw_long2darray_type) :: me
    !> optional length to expand the array
    integer, intent(in), optional :: length
    ! --------------------------------------------------------------------------
    integer(kind=long_k), allocatable :: swpval(:,:)
    integer :: explen
    ! --------------------------------------------------------------------------

    explen = 0
    ! increase the container by the requested length of double it
    if( present(length) ) then
      explen = length
    else
      ! set the global minimum length, if doubling would be smaller than that
      explen = max(me%containersize, minlength)
    end if


    ! if the current size plus explen exceeds the max container size,
    ! reduce the size to the max container size.
    if( (huge(me%containersize) - explen) <= me%containersize) then
      ! set max container size
      me%containersize = huge(me%containersize)
    else
      ! set the calculated size
      me%containersize = me%containersize + explen
    end if


    if ( me%nvals > 0 ) then
      allocate(swpval(me%containerwidth,me%containersize))
      !> first reset all entries
      swpval(:,:) = -1_long_k
      swpval(:,:me%nvals) = me%val(:,:me%nvals)
      call move_alloc( swpval, me%val )
    else ! me%nvals == 0
      if ( allocated(me%val) ) deallocate( me%val )
      allocate( me%val(me%containerwidth,me%containersize) )
    end if

  end subroutine expand_ga2d_long