Created
August 29, 2012 18:38
-
-
Save ponderomotion/3516860 to your computer and use it in GitHub Desktop.
Array resizing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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