expand the growing 2d array
first reset all entries
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(grw_int2darray_type) | :: | me |
array to resize |
|||
integer, | intent(in), | optional | :: | length |
optional length to expand the array |
subroutine expand_ga2d_int( me, length ) ! -------------------------------------------------------------------------- !> array to resize type(grw_int2darray_type) :: me !> optional length to expand the array integer, intent(in), optional :: length ! -------------------------------------------------------------------------- integer, 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 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_int