Store the elements of vector in an array of higher rank.
Fortran 95 and later
Transformational function
result = unpack(vector, mask, field)
vector - Shall be an array of any type and rank one. It shall have at least as many elements as mask has true values.mask - Shall be an array of type logical.field - Shall be of the same type as vector and have the same shape as mask.The resulting array corresponds to field with true elements of mask replaced by values from vector in array element order.
program test_unpack
integer :: vector(2) = (/1,1/)
logical :: mask(4) = (/ .true., .false., .false., .true. /)
integer :: field(2,2) = 0, unity(2,2)
! result: unity matrix
unity = unpack(vector, reshape(mask, (/2,2/)), field)
end program