I am trying to implement a push_back routine as below.
SUBROUTINE push_back(array, val)
INTEGER,DIMENSION(:), ALLOCATABLE :: tmp_arr
INTEGER, DIMENSION(:) :: array
INTEGER val
ALLOCATE(tmp_arr(0 : SIZE(array)))
tmp_arr(0:(SIZE(array)-1))=array
tmp_arr(SIZE(array)) = val
DEALLOCATE(array)
ALLOCATE(array(0:SIZE(tmp_arr)-1))
CALL move_alloc(tmp_arr, array)
END SUBROUTINE push_back
On resizing an allocatable array (declared ALLOCATABLE in the calling subroutine) , I get the following compile errors
- error #6724: An allocate/deallocate object must have the ALLOCATABLE or POINTER attribute. [ARRAY]
- error #8195: The argument to the MOVE_ALLOC intrinsic subroutine shall be an allocatable object. [MOVE_ALLOC]
I want the resize to work such that the data that is passed is not lost. However, by making array ALLOCATABLE within the subroutine , I would lose the existing data.
Any help with this would be great.




