Lahey/Fujitsu Fortran

PRODUCT Function

Description

The PRODUCT function returns the product of elements of an array expression, along a given dimension, or under the control of a logical mask.

Syntax

PRODUCT (array [, dim] [, mask])

Required Arguments

array is an INTENT(IN) array of type INTEGER, REAL or COMPLEX.

Optional Arguments

dim is an INTENT(IN) scalar INTEGER in the range 1 ≤ dimn, where n is the rank of array. The corresponding actual argument must not be an optional dummy argument.

mask is INTENT(IN), must be of type LOGICAL, and must be conformable with array.

Result

The result is of the same type and kind as array.

It is scalar if dim is absent or if array has rank one; 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 array.

If dim is absent, the result is the product of all the elements of array.

If dim is present, the result is the product of all elements of array along dimension dim.

If mask is present, the result is the product of all elements of array for which mask evaluates to true.

Example

integer,dimension(2,2) :: m=reshape((/1,2,3,4/),shape(m)) write(*,'2i3)') m ! writes 1 2 ! 3 4 write(*,*) product(m) ! writes 24 write(*,*) product(m,dim=1) ! writes 2 12 write(*,*) product(m,dim=2) ! writes 3 8 write(*,*) product(m,mask=m>2) ! writes 12 write(*,*) product(m,dim=1,mask=m>2) ! writes 1 12 write(*,*) product(m,dim=2,mask=m>2) ! writes 3 4