Subscript triplets facilitate the selection of subsets of arrays, called array sections, which are often required in array assignments. Subscript triplets take the form
start index : end index : stride
indicating the first element, last element and the jump between each element. This can be a really powerful shorthand in programs. For example, selecting the interior (non-boundary) points from an array becomes much simpler when expressed in Fortran 90's triplet notation:
FORTRAN 77 Fortran 90
REAL A(10,10),B(10,10) REAL, DIMENSION(10,10) :: A,B
DO 1 J=1,8 A(1:8,1:8) = B(2:9,2:9)
DO 2 I=1,8
A(I,J) = B(I+1,J+1)
2 CONTINUE
1 CONTINUE
Array constants can be defined using this notation:
REAL, DIMENSION(1024) :: a
a(1:1024) = 1.0 ! same as a = 1.0
a(:1024:2) = 2.0 ! a(1)=a(3)=...= 2.0
Another option is to use the array constructor notation:
a = (/ (i,i=1,1024) /) ! a(1)=1,a(2)=2,...
a = (/ (i,i=1,1024,4) /) ! a(1)=1,a(5)=5,...
Note that arrays in F90 expressions should be
conformable, that is, they should have the same rank (number of dimensions) and the same extent in every dimension. Scalars are conformable with any array.