pack
- Date:
10-12-2011
NAME
PACK - Packs an array into an array of rank one under control of a mask
SYNOPSIS
PACK ([ARRAY=]array, [MASK=]mask [,[VECTOR=]vector])
IMPLEMENTATION
Cray Linux Environment (CLE)
STANDARDS
Fortran
DESCRIPTION
The PACK intrinsic function packs an array into an array of rank one under control of a mask. It can be used for array construction. It accepts the following arguments:
- array
Array of any type. It must not be scalar.
- mask
Control mask; must be of type logical and must be conformable with array.
- vector
Must be of the same type as array and must have rank one. The vector must have at least as many elements as there are true elements in mask. If mask is scalar with the value true, vector must have at least as many elements as there are in array.
PACK is a transformational function. The name of this intrinsic cannot be passed as an argument.
RETURN VALUES
The result is an array of rank one of the same type as array. If vector is present, the result size is that of vector; otherwise, the result size is the number t of true elements in mask unless mask is scalar with the value true, in which case the result size is the size of array.
Element i of the result is the element of array that corresponds to the ith true element of mask, taking elements in array element order, for i=1, 2, …,t. If vector is present and has size n>t, element i of the result has the value vector(i), for i=t+1, …, n.
EXAMPLES
Example 1: Given N = (/1,-1,3/), the following are true:
PACK(N,MASK=N.LT.0) yields (/-1/).
PACK(N,MASK=.TRUE.) yields (/1,-1,3/).
Example 2: Given array M:
| 0 0 0 |
| 9 0 0 |
| 0 0 7 |
the nonzero elements of array M can be gathered by the PACK function. The following are the results:
PACK(M,MASK=M.NE.0) yields (/9,7/).
PACK(M,MASK=M.NE.0,VECTOR=(/2,4,6,8,10,12/)) yields (/9,7,6,8,10,12/).