append an entry to an allocatable array 1d with integer If the array is too small, reallocate with double size
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=int_k), | intent(inout), | allocatable | :: | Array(:) |
array to resize |
|
integer, | intent(in) | :: | Newsize |
new size of the array |
subroutine tem_resizeInt1dArray(Array, Newsize ) ! --------------------------------------------------------------------------- !> array to resize integer(kind=int_k),intent(inout), allocatable :: Array(:) !> new size of the array integer,intent(in) :: Newsize ! --------------------------------------------------------------------------- integer,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_resizeInt1dArray