expand_ga2d_logical Subroutine

public subroutine expand_ga2d_logical(me, length)

expand the growing 2d array

first reset all entries

Arguments

Type IntentOptional Attributes Name
type(grw_logical2darray_type) :: me

array to resize

integer, intent(in), optional :: length

optional length to expand the array


Called by

proc~~expand_ga2d_logical~~CalledByGraph proc~expand_ga2d_logical expand_ga2d_logical interface~expand~19 expand interface~expand~19->proc~expand_ga2d_logical

Contents

Source Code


Source Code

  subroutine expand_ga2d_logical( me, length )
    ! --------------------------------------------------------------------------
    !> array to resize
    type(grw_logical2darray_type) :: me
    !> optional length to expand the array
    integer, intent(in), optional :: length
    ! --------------------------------------------------------------------------
    logical, 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(:,:) = .false.
      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_logical