Reduction functions are aptly named because an array is operated upon and a result obtained which has a smaller rank than the original source array. For a rank n array, if DIM is absent or n = 1 then the result is scalar, otherwise the result is of rank n-1.
If
and
then the following
PRINT*, ALL(A.NE.B,DIM=1)
gives
T F F
recall that dimension 1 runs up and down the page.
Similarly
PRINT*, ALL(A.NE.B,DIM=2)
gives,
F F
where dimension 2 run across the page.
PRINT*, ALL(A.NE.B)
gives the scalar value,
F
PRINT*, ANY(A.NE.B,DIM=1) PRINT*, ANY(A.NE.B,DIM=2)
gives
T F T T T
PRINT*, ANY(A.NE.B)
gives the scalar value,
T
PRINT*, COUNT(A.NE.B,DIM=1) PRINT*, COUNT(A.NE.B,DIM=2)
gives
2 0 1 1 2
PRINT*, COUNT(A.NE.B)
gives the scalar,
3
PRINT*, MAXVAL(A,DIM=1) PRINT*, MAXVAL(A,DIM=2)
gives
2 4 6 5 6
PRINT*, MAXVAL(A,MASK=A.LT.4)
only considers elements of A that are less than 4 and gives
3
PRINT*, MINVAL(A,DIM=1) PRINT*, MINVAL(A,DIM=2)
gives
1 3 5 1 2
PRINT*, MINVAL(A,MASK=A.GT.4)
gives
5
PRINT*, PRODUCT(A,DIM=1) PRINT*, PRODUCT(A,DIM=2)
gives
2 12 30 15 48
PRINT*, PRODUCT(A,MASK=A.LT.4)
gives
6
PRINT*, SUM(A,DIM=1) PRINT*, SUM(A,DIM=2)
gives
3 7 11 9 12
PRINT*, SUM(A,MASK=A.LT.4)
gives
6