Array HTML version
Declaration in Main Program 2 ways to declare a real array A of rank N : DIMENSION A( start_index1 : end_index1, …, start_indexN : end_indexN ) REAL A( start_index1 : end_index1, …, start_indexN : end_indexN ) DIMENSION A(10, 20), M(-5:4, 1:20), C(2, 3:9, 4, 5
Declaration in Sub-Program Same as in the main program. With variable dimensions. –SUBROUTINE MA( N1, N2, A, B ) DIMENSION A(N1, N2), B(N1+N2) –DIMENSION X(3, 4), Y(7) CALL MA( 3, 4, X, Y ) With assumed dimensions. –SUBROUTINE MAT( N, A, B, M ) DIMENSION A(N, *), B(N), M(*) –DIMENSION X(5, -9:10), Y(5) ), K(30) CALL MAT( 5, X, Y, K )
Initialization DIMENSION M(2,3) DATA M / 1, 2, 3, 4, 5, 6 / DATA ( (M(I,J), I=1,2 ), J=1,3) / 1, 2, 3, 4, 5, 6 / DATA ( M(I,1), I=1,2 ) / 1, 2 /, ( M(I,2), I=1,2 ) / 3, 4/, ( M(I,3), I=1,2 ) / 5, 6/ DATA ( M(1,J), I=1,3 ) / 1, 3, 5 /, ( M(2,J), I=1,3 ) / 2, 4, 6 /
BLOCK DATA Arrays in common blocks can only be initialized in a BLOCK DATA. BLOCK DATA MA COMMON / MAT / M(2,3) DATA M / 1, 2, 3, 4, 5, 6 / END PROGRAM TS COMMON / MAT / M(2,3) WRITE(*, '(3I7)') ( (M(I,J), J=1,3 ), I=1,2) END