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