Is it necessary to declare array dimensions before any other code? For example, I have written the following simplified example code:
PROGRAM mytest
IMPLI
You want to use allocatable arrays:
PROGRAM mytest
IMPLICIT NONE
INTEGER :: i, j, k, mysum
REAL, DIMENSION(:,:), allocatable :: c !<- c is allocatable, rank 2
! Let array c be a k-by-k**2 array
! Determine k within the program by some means...for example,
mysum=0
DO i=1, 3
mysum=mysum+1
END DO
k=mysum
WRITE(*,*) "k=", k
WRITE(*,*) "k**2=", k**2
WRITE(*,*)
allocate(c(k,k**2)) ! <-- allocate array c with supplied shape
DO i=1,size(c,1)
WRITE(*,"(100(3X,F3.1))") (c(i,j), j=1,size(c,2))
END DO
deallocate(c) ! <-- deallocate when done
END PROGRAM mytest