Skip to content

Instantly share code, notes, and snippets.

@ponderomotion
Created August 29, 2012 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ponderomotion/3516860 to your computer and use it in GitHub Desktop.
Save ponderomotion/3516860 to your computer and use it in GitHub Desktop.
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