expand_ga_dynlong Subroutine

public subroutine expand_ga_dynlong(me, pos, length)

Arguments

Type IntentOptional Attributes Name
type(grw_dynlongarray_type) :: me
integer, intent(in), optional :: pos
integer, intent(in), optional :: length

optional length to expand the array


Called by

proc~~expand_ga_dynlong~~CalledByGraph proc~expand_ga_dynlong expand_ga_dynlong interface~expand~9 expand interface~expand~9->proc~expand_ga_dynlong proc~append_ga_dynint append_ga_dynint proc~append_ga_dynint->interface~expand~9 proc~append_ga_dynint_vec append_ga_dynint_vec proc~append_ga_dynint_vec->interface~expand~9 proc~append_ga_dynlong append_ga_dynlong proc~append_ga_dynlong->interface~expand~9 proc~append_ga_dynlong_vec append_ga_dynlong_vec proc~append_ga_dynlong_vec->interface~expand~9 proc~append_ga_grw_stencilelement append_ga_grw_stencilelement proc~append_ga_grw_stencilelement->interface~expand~9 proc~append_ga_grw_stencilelement_vec append_ga_grw_stencilelement_vec proc~append_ga_grw_stencilelement_vec->interface~expand~9 proc~placeat_ga_dynint placeat_ga_dynint proc~placeat_ga_dynint->interface~expand~9 proc~placeat_ga_dynint_vec placeat_ga_dynint_vec proc~placeat_ga_dynint_vec->interface~expand~9 proc~placeat_ga_dynlong placeat_ga_dynlong proc~placeat_ga_dynlong->interface~expand~9 proc~placeat_ga_dynlong_vec placeat_ga_dynlong_vec proc~placeat_ga_dynlong_vec->interface~expand~9 proc~placeat_ga_grw_stencilelement placeat_ga_grw_stencilelement proc~placeat_ga_grw_stencilelement->interface~expand~9 proc~placeat_ga_grw_stencilelement_vec placeat_ga_grw_stencilelement_vec proc~placeat_ga_grw_stencilelement_vec->interface~expand~9 interface~append~10 append interface~append~10->proc~append_ga_dynint interface~append~10->proc~append_ga_dynint_vec interface~append~11 append interface~append~11->proc~append_ga_dynlong interface~append~11->proc~append_ga_dynlong_vec interface~append~33 append interface~append~33->proc~append_ga_grw_stencilelement interface~append~33->proc~append_ga_grw_stencilelement_vec interface~placeat~24 placeat interface~placeat~24->proc~placeat_ga_grw_stencilelement interface~placeat~24->proc~placeat_ga_grw_stencilelement_vec interface~placeat~7 placeat interface~placeat~7->proc~placeat_ga_dynint interface~placeat~7->proc~placeat_ga_dynint_vec interface~placeat~8 placeat interface~placeat~8->proc~placeat_ga_dynlong interface~placeat~8->proc~placeat_ga_dynlong_vec

Source Code

  subroutine expand_ga_dynlong(me, pos, length)
    type(grw_dynlongarray_type) :: me !< array to resize
    integer, intent(in), optional :: pos !< optional predefined position
    !> optional length to expand the array
    integer, intent(in), optional :: length

    type(dyn_longarray_type), allocatable :: swpval(:)
    integer :: explen, ii

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

    ! if a position is given, increase the container to at least the size to
    ! fit the position.
    if( present(pos) ) explen = max(explen, pos-me%containersize)

    ! 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 new container size
      me%containersize = me%containersize + explen
    end if

    if ( me%nvals > 0 ) then
      allocate(swpval(me%containersize))
      do ii = 1, me%nvals
        swpval(ii) = me%val(ii)
      end do
      call move_alloc( swpval, me%val )
    else ! me%nvals == 0
      if ( allocated(me%val) ) deallocate( me%val )
      allocate( me%val(me%containersize) )
    end if

  end subroutine expand_ga_dynlong