expand_ga_stringkeyvaluepair Subroutine

private subroutine expand_ga_stringkeyvaluepair(me, pos, length)

Arguments

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

optional length to expand the array


Called by

proc~~expand_ga_stringkeyvaluepair~~CalledByGraph proc~expand_ga_stringkeyvaluepair expand_ga_stringkeyvaluepair interface~expand~24 expand interface~expand~24->proc~expand_ga_stringkeyvaluepair proc~append_ga_stringkeyvaluepair append_ga_stringkeyvaluepair proc~append_ga_stringkeyvaluepair->interface~expand~24 proc~append_ga_stringkeyvaluepair_vec append_ga_stringkeyvaluepair_vec proc~append_ga_stringkeyvaluepair_vec->interface~expand~24 proc~placeat_ga_stringkeyvaluepair placeat_ga_stringkeyvaluepair proc~placeat_ga_stringkeyvaluepair->interface~expand~24 proc~placeat_ga_stringkeyvaluepair_vec placeat_ga_stringkeyvaluepair_vec proc~placeat_ga_stringkeyvaluepair_vec->interface~expand~24 interface~append~25 append interface~append~25->proc~append_ga_stringkeyvaluepair interface~append~25->proc~append_ga_stringkeyvaluepair_vec interface~placeat~14 placeat interface~placeat~14->proc~placeat_ga_stringkeyvaluepair interface~placeat~14->proc~placeat_ga_stringkeyvaluepair_vec proc~tem_create_varmap tem_create_varMap proc~tem_create_varmap->interface~append~25 proc~tem_variable_loadmapping_single tem_variable_loadMapping_single proc~tem_variable_loadmapping_single->interface~append~25 proc~tem_load_bc_state tem_load_bc_state proc~tem_load_bc_state->interface~append~25 proc~append_possible_variable append_possible_variable proc~append_possible_variable->interface~append~25

Contents


Source Code

  subroutine expand_ga_stringkeyvaluepair(me, pos, length)
    type(grw_stringkeyvaluepairarray_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(tem_stringkeyvaluepair_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_stringkeyvaluepair