tem_resizeDp1dArray Subroutine

private subroutine tem_resizeDp1dArray(Array, Newsize)

append an entry to an allocatable array 1d with integer If the array is too small, reallocate with double size

Arguments

Type IntentOptional Attributes Name
real(kind=rk), intent(inout), allocatable :: Array(:)

array to resize

integer, intent(in) :: Newsize

new size of the array


Called by

proc~~tem_resizedp1darray~~CalledByGraph proc~tem_resizedp1darray tem_resizeDp1dArray interface~resize resize interface~resize->proc~tem_resizedp1darray

Source Code

  subroutine tem_resizeDp1dArray( Array, Newsize )
    ! ---------------------------------------------------------------------------
    !> array to resize
    real(kind=rk),intent(inout), allocatable :: Array(:)
    !> new size of the array
    integer,intent(in) :: Newsize
    ! ---------------------------------------------------------------------------
    real(kind=rk),allocatable :: tempArray(:)
    integer :: ierr
    ! ---------------------------------------------------------------------------

    ! allocate temporary array with double size
    allocate(tempArray(NewSize), stat=ierr)
    ! Copy to temp array
    tempArray(1:NewSize) = Array(1:NewSize)
    ! Deallocate Array
    deallocate(Array)
    ! Reallocate Array
    allocate(Array(NewSize), stat=ierr)
    Array(1:NewSize) = tempArray(1:NewSize)
    ! Deallocate temp array
    deallocate(tempArray)
    if(ierr .ne. 0) Write(*,*) 'Error in reallocating array'

  end subroutine tem_resizeDp1dArray