Assigning Values to an Array: Difference between revisions

Content added Content deleted
Line 147: Line 147:
In ISO Fortran 90 or later, use array section syntax to assign sections of an array:
In ISO Fortran 90 or later, use array section syntax to assign sections of an array:
b(1:4) = i4(1,:) ! gets row 1 of i4 into first 4 elements of b
b(1:4) = i4(1,:) ! gets row 1 of i4 into first 4 elements of b
a(2:8:2) = i4(:,2) ! gets column 2 of i4 into first 4 even numbered elements of a (stride of 2)
a(1:7:2) = i4(:,3) ! gets column 3 of i4 into first 4 odd-numbered elements of a (stride of 2)
i4(2:4,2:4) = i4(1:3,1:3) ! gets 3x3 subarray of i4 starting at row 1, column 1
i4(2:4,2:4) = i4(1:3,1:3) ! gets 3x3 subarray of i4 starting at row 1, column 1
! into 3x3 subarray of i4 starting at row 2, column 2
! into 3x3 subarray of i4 starting at row 2, column 2