Skip to content

@ponderomotion /resize.f90
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Array resizing
PROGRAM test1
IMPLICIT NONE
INTEGER, DIMENSION(:,:), ALLOCATABLE :: a
INTEGER :: i,j,ni,nj
ni = 4
nj = 4
ALLOCATE(a(ni,nj))
DO i=1,ni
DO j=1,nj
a(i,j) = i * j
END DO
END DO
WRITE(*,*) UBOUND(a,1), UBOUND(a,2)
CALL reallocate(a,5,5)
!WRITE(*,*) a
END PROGRAM test1
SUBROUTINE reallocate(a,ni_new,nj_new)
IMPLICIT NONE
INTEGER,DIMENSION(:,:),ALLOCATABLE,INTENT(INOUT) :: a
INTEGER,DIMENSION(:,:),ALLOCATABLE :: temp
INTEGER,INTENT(IN) :: ni_new,nj_new
INTEGER :: ni_old,nj_old,i,j
ni_old = UBOUND(a,1)
nj_old = UBOUND(a,2)
ALLOCATE(temp(ni_new,nj_new))
WRITE(*,*) ni_old, nj_old
temp(1:ni_old,1:nj_old) = a
CALL MOVE_ALLOC(temp,a)
END SUBROUTINE reallocate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.