LF Fortran 95

UNPACK Function


The UNPACK function unpacks an array of rank one into an array under control of a mask.


UNPACK (vector, mask, field)


vector is an INTENT(IN) rank one array of any type. Its size must be at least as large as the number of true elements in mask.

mask is an INTENT(IN) array of type LOGICAL.

field is INTENT(IN) must be of the same type and type parameters as vector. It must be conformable with mask.


The result is an array of the same type and type parameters as vector and the same shape as mask. The element of the result that corresponds to the ith element of mask, in array-element order, has the value vector(i) for i=1, 2, ..., t, where t is the number of true values in mask. Each other element has the value field if field is scalar or the corresponding element in field, if field is an array.


integer, dimension(9) :: c=(/0,3,2,4,3,2,5,1,2/) logical,dimension(2,2) :: d integer,dimension(2,2) :: e d=reshape((/.false.,.true.,.true.,.false./),shape(d)) e=unpack(c,mask=d,field=-1) write(*,'(2i3)') e ! writes -1 0 ! 3 -1