UNPACK

9.269 UNPACK — Unpack an array of rank one into an array

Description:
Store the elements of VECTOR in an array of higher rank.
Standard:
Fortran 95 and later
Class:
Transformational function
Syntax:
RESULT = UNPACK(VECTOR, MASK, FIELD)
Arguments:
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.
Return value:
The resulting array corresponds to FIELD with TRUE elements of MASK replaced by values from VECTOR in array element order.
Example:
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
See also:
PACK, SPREAD

© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-5.4.0/gfortran/UNPACK.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部