PACK(SOURCE,MASK[,VECTOR])
This function packs a arbitrary shaped array into a one-dimensional array under a mask. VECTOR, if present, must be 1-D and must be of same type and kind as SOURCE.
Element i of the result is the element of SOURCE that corresponds to the ith .TRUE. element of MASK, (in array element order,) for i=1,...,t, where t is the number .TRUE. elements in MASK.
If VECTOR is present, the result size is that of VECTOR; otherwise, the result size is t unless MASK is scalar with the value .TRUE. in which case the result size is the size of SOURCE. If VECTOR has size n > t, element i of the result has the value VECTOR(i), for i=t+1,...,n.
For example, if
and
then
VECTOR is absent meaning that size of the result is the number of .TRUE. elements in MASK, 3. The elements of A which correspond to the .TRUE. elements of MASK are
It can be seen that the highlighted elements are taken from A in array element order and packed into the result.
Here VECTOR is present so the result is of
size 4. The first t elements of the results are as before
corresponding to the .TRUE. elements of the mask. The remaining values
are taken from VECTOR the 4th value of the result is the t+1th
element of VECTOR, 6. Hence the result (/1, 5, 11, 6/)
.
Here the mask is scalar so the first 6 elements are A and the rest from the end of VECTOR.
Return to corresponding overview page