|
F77 style:
Type arrayName(size) ! Indices: 1, 2, ..., size Type arrayName(a:b) ! Indices: a, a+1, ..., b |
Examples:
REAL A(5) ! A(1), A(2), A(3), A(4), A(5) REAL B(-2:2) ! B(-2), B(-1), B(0), B(1), B(2) |
NOTE:
|
NOTE: I ran the array index in B out of bound
F90 style:
Type, DIMENSION(size) :: arrayName Type, DIMENSION(a:b) :: arrayName |
Examples:
REAL DIMENSION(5) :: A ! A(1), A(2), A(3), A(4), A(5) REAL DIMENSION(-2:2) :: B ! B(-2), B(-1), B(0), B(1), B(2) REAL DIMENSION(-2:2) :: C = (/ 111, 222, 333, 444, 555 /) |
(that's why this topic is so lengthy :-))
|
SUBROUTINE f(N) IMPLICIT NONE INTEGER N REAL, DIMENSION(N) :: A !! You can define arrays using !! VARIABLES in Fortran 90.... like Ada INTEGER i DO i = 1, N A(i) = i END DO print *, A !! Print an entire array END SUBROUTINE |
F77 style
Type arrayName(size1, size2) Type arrayName(a1:b1, a2:b2) |
Example:
REAL A(3,3) !! 3x3 matrix, indices (1,1), (1,2), etc REAL B(0:2, 0:2) !! 3x3 matrix, indices (0,0), (0,1), etc |
(No demo program, I'll demo the 2-dim. array in F90 style)
F90 style
Type, DIMENSION(size1, size2) :: arrayName Type, DIMENSION(a1:b1, a2:b2) :: arrayName |
Example:
REAL, DIMENSION(3, 3) :: A !! 3x3 matrix, indices (1,1), (1,2), etc REAL, DIMENSION(0:2, 0:2) :: B !! 3x3 matrix, indices (0,0), (0,1), etc REAL, DIMENSION(3, 0:2) :: C !! 3x3 matrix, indices (1,0), (1,1), etc |
|
DATA varName / val1, val2, .... / |
Example:
REAL A(5) REAL B(2, 3) DATA A / 1, 2, 3, 4, 5 / DATA B / 1, 2, 3, 4, 5, 6 / ! NOTE: Column major !!! |