COUNT — Count function¶
- COUNT()¶
Counts the number of
.TRUE.elements in a logicalMASK, or, if theDIMargument is supplied, counts the number of elements along each row of the array in theDIMdirection. If the array has zero size, or all of the elements ofMASKare.FALSE., then the result is0.- Parameters
MASK – The type shall be
LOGICAL.DIM – (Optional) The type shall be
INTEGER.KIND – (Optional) An
INTEGERinitialization expression indicating the kind parameter of the result.
- Returns
The return value is of type
INTEGERand of kindKIND. IfKINDis absent, the return value is of default integer kind. IfDIMis present, the result is an array with a rank one less than the rank ofARRAY, and a size corresponding to the shape ofARRAYwith theDIMdimension removed.
Standard:Fortran 90 and later, with
KINDargument Fortran 2003 and laterClass:Transformational function
Syntax:RESULT = COUNT(MASK [, DIM, KIND])
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