PACK — Pack an array into an array of rank one#
- 
PACK(ARRAY, MASK, VECTOR)#
 Stores the elements of
ARRAYin an array of rank one.- Parameters
 ARRAY – Shall be an array of any type.
MASK – Shall be an array of type
LOGICALand of the same size asARRAY. Alternatively, it may be aLOGICALscalar.VECTOR – (Optional) shall be an array of the same type as
ARRAYand of rank one. If present, the number of elements inVECTORshall be equal to or greater than the number of true elements inMASK. IfMASKis scalar, the number of elements inVECTORshall be equal to or greater than the number of elements inARRAY.
- Returns
 The result is an array of rank one and the same type as that of
ARRAY. IfVECTORis present, the result size is that ofVECTOR, the number ofTRUEvalues inMASKotherwise.
- Standard:
 Fortran 90 and later
- Class:
 Transformational function
- Syntax:
 RESULT = PACK(ARRAY, MASK[,VECTOR])
- Example:
 Gathering nonzero elements from an array:
PROGRAM test_pack_1 INTEGER :: m(6) m = (/ 1, 0, 0, 0, 5, 0 /) WRITE(*, FMT="(6(I0, ' '))") pack(m, m /= 0) ! "1 5" END PROGRAM
Gathering nonzero elements from an array and appending elements from
VECTOR:PROGRAM test_pack_2 INTEGER :: m(4) m = (/ 1, 0, 0, 2 /) ! The following results in "1 2 3 4" WRITE(*, FMT="(4(I0, ' '))") pack(m, m /= 0, (/ 0, 0, 3, 4 /)) END PROGRAM
- See also: