Next: , Previous: COSH, Up: Intrinsic Procedures


7.48 COUNT — Count function

Description:
COUNT(MASK [, DIM [, KIND]]) counts the number of .TRUE. elements of MASK along the dimension of DIM. If DIM is omitted it is taken to be 1. DIM is a scalar of type INTEGER in the range of 1 /leq DIM /leq n) where n is the rank of MASK.
Standard:
Fortran 95 and later, with KIND argument Fortran 2003 and later
Class:
Transformational function
Syntax:
RESULT = COUNT(MASK [, DIM [, KIND]])
Arguments:

MASK The type shall be LOGICAL.
DIM (Optional) The type shall be INTEGER.
KIND (Optional) An INTEGER initialization expression indicating the kind parameter of the result.

Return value:
The return value is of type INTEGER and of kind KIND. If KIND is absent, the return value is of default integer kind. The result has a rank equal to that of MASK.
Example:
          program test_count
              integer, dimension(2,3) :: a, b
              logical, dimension(2,3) :: mask
              a = reshape( (/ 1, 2, 3, 4, 5, 6 /), (/ 2, 3 /))
              b = reshape( (/ 0, 7, 3, 4, 5, 8 /), (/ 2, 3 /))
              print '(3i3)', a(1,:)
              print '(3i3)', a(2,:)
              print *
              print '(3i3)', b(1,:)
              print '(3i3)', b(2,:)
              print *
              mask = a.ne.b
              print '(3l3)', mask(1,:)
              print '(3l3)', mask(2,:)
              print *
              print '(3i3)', count(mask)
              print *
              print '(3i3)', count(mask, 1)
              print *
              print '(3i3)', count(mask, 2)
          end program test_count