Multiplies together all elements in an entire array, or selected elements from all vectors along a dimension.
Class
Transformational function
Result Value
If DIM is present, the result is an array of rank rank(ARRAY)-1 and the same data type as ARRAY. If DIM is missing, or if MASK has a rank of one, the result is a scalar.
The result is calculated by one of the following methods:
+---------------------------------Fortran 95---------------------------------+
Because both DIM and MASK are optional, various combinations of arguments are possible. When the -qintlog option is specified with two arguments, the second argument refers to one of the following:
+-----------------------------End of Fortran 95------------------------------+
Examples
! Multiply all elements in an array.
RES = PRODUCT( (/2, 3, 4/) )
! The result is 24 because (2 * 3 * 4) = 24.
! Do the same for a two-dimensional array.
RES = PRODUCT( (/2, 3, 4/), (/4, 5, 6/) )
! The result is 2880. All elements are multiplied.
! A is the array (/ -3, -7, -5, 2, 3 /)
! Multiply all elements of the array that are > -5.
RES = PRODUCT(A, MASK = A .GT. -5)
! The result is -18 because (-3 * 2 * 3) = -18.
! A is the array | -2 5 7 |
! | 3 -4 3 |
! Find the product of each column in A.
RES = PRODUCT(A, DIM = 1)
! The result is | -6 -20 21 | because (-2 * 3) = -6
! ( 5 * -4 ) = -20
! ( 7 * 3 ) = 21
! Find the product of each row in A.
RES = PRODUCT(A, DIM = 2)
! The result is | -70 -36 |
! because (-2 * 5 * 7) = -70
! (3 * -4 * 3) = -36
! Find the product of each row in A, considering
! only those elements greater than zero.
RES = PRODUCT(A, DIM = 2, MASK = A .GT. 0)
! The result is | 35 9 | because ( 5 * 7) = 35
! (3 * 3) = 9