count
- Date:
10-12-2011
NAME
COUNT - Counts the number of true array elements
SYNOPSIS
COUNT ([MASK=]mask [,[DIM=]dim, [KIND=]kind])
IMPLEMENTATION
Cray Linux Environment (CLE)
STANDARDS
Fortran
DESCRIPTION
The COUNT intrinsic function counts the number of true array elements of argument mask along dimension dim. It accepts the following arguments:
- mask
The mask argument must be of type logical. It must not be a scalar.
- dim
The dim argument must be a scalar. It is an integer with a value in the range 1 <= dim <= n, where n is the rank of mask. The corresponding actual argument must not be an optional dummy argument.
- kind
The kind argument determines the kind type of the return result. If this argument is not specified, the return result is of type default integer.
See the RETURN VALUES section for more information
This argument must be a scalar integer initialization expression.
COUNT is a transformational function. The name of this intrinsic cannot be passed as an argument.
RETURN VALUES
The result is type integer. It is a scalar result if dim is absent or if mask has rank 1. Otherwise, the result is an array of rank n-1 and of shape
(d1, d2, ..., ddim-1, ddim+1, ..., dn)
where
(d1, d2, ..., dn)
is the shape of mask.
The result of COUNT(mask) has a value equal to the number of TRUE elements of mask or has the value 0 if mask is a zero-sized array.
If mask has rank 1, COUNT(mask, dim) has a value equal to that of COUNT(mask). Otherwise, the value of element
(s1, s2, ..., sdim-1, sdim+1, ..., sn)
of COUNT(mask, dim) is equal to
COUNT(MASK (s1, s2, ..., sdim-1, : , sdim+1, ..., sn))
EXAMPLES
Example 1:
COUNT((/.TRUE.,.FALSE.,.TRUE./)) yields 2.
COUNT(mask) yields 0 when mask is a zero-sized array.
Example 2: Assume that B is the following array:
| 1 3 5 |
| 2 4 6 |
C is the following array:
| 0 3 5 |
| 7 4 8 |
COUNT(B.NE.C) yields 3.
COUNT(B.NE.C,DIM=1) yields [2,0,1].
COUNT(B.NE.C,DIM=2) yields [1,2].
COUNT(C.EQ.1) yields 0 because there are no true elements in the mask.
Example 3: Assume that array N is as follows:
| 0 1 2 3 |
| 4 5 6 7 |
| 8 9 0 1 |
In an array section reference, you can expect the following results:
COUNT((N(2:3,2:4).NE.0)) yields 5.
COUNT((N(2:3,2:4).NE.0),DIM=1) yields [2,1,2].
COUNT((N(2:3,2:4).NE.0),DIM=2) yields [3,2].