﻿ PACK Function
 LF Fortran 95

# PACK Function

### Description

The PACK function packs an array into a vector under the control of a mask.

```Syntax
PACK (array, mask [, vector] )
```

### Required Arguments

array is an INTENT(IN) array can be of any type.

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

### Optional Arguments

vector is an INTENT(IN) array of rank one, and must be the same type and kind as array. It must have at least as many elements as there are true elements in array. If mask is scalar with value true, vector must have at least as many elements as array.

### Result

The result is an array of rank one with the same type and kind as array.

If vector is present, the result size is the size of vector.

If vector is absent, the result size is the number of true elements in mask unless mask is scalar with the value true, in which case the size is the size of array.

The value of element i of the result is the ith true element of mask, in array-element order. If vector is present and is larger than the number of true elements in mask, the elements of the result beyond the number of true elements in mask are filled with values from the corresponding elements of vector.

```Example
integer :: c(3,3)=reshape((/0,3,2,4,3,2,5,1,2/),shape(c))
integer :: cc(9)=-1
write(*,'(3i3)') c        ! writes 0 3 2
!        4 3 2
!        5 1 2
! writes 3 4 3 5
! writes 3 4 3 5 -1 -1 -1 -1 -1
write(*,*) pack(c,.true.) ! writes 0 3 2 4 3 2 5 1 2
```