Clicky

Fortran Wiki
pack (Rev #2, changes)

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

Showing changes from revision #1 to #2: (追記) Added (追記ここまで) | (削除) Removed (削除ここまで) | (削除) Chan (削除ここまで)(追記) ged (追記ここまで)

Description

Stores the elements of array in an array of rank one.

The beginning of the resulting array is made up of elements whose mask equals true. Afterwards, positions are filled with elements taken from vector.

Standard

(削除) Fortran 95 and later (削除ここまで)(追記) Fortran 95 (追記ここまで)(追記) and later (追記ここまで)

Class

Transformational function

Syntax

result = pack(array, mask[,vector]

Arguments

  • array - Shall be an array of any type.
  • mask - Shall be an array of type logical and of the same size as array. Alternatively, it may be a logical scalar.
  • vector - (Optional) shall be an array of the same type as array and of rank one. If present, the number of elements in vector shall be equal to or greater than the number of true elements in mask. If mask is scalar, the number of elements in vector shall be equal to or greater than the number of elements in array.

Return value

The result is an array of rank one and the same type as that of array. If vector is present, the result size is that of vector, the number of true values in mask otherwise.

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 /)
 write(*, fmt="(4(i0, ' '))") pack(m, m /= 0, (/ 0, 0, 3, 4 /)) ! "1 2 3 4"
end program

See also

unpack

category: (削除) Intrinsics (削除ここまで)(追記) intrinsics (追記ここまで)

Revision from April 30, 2009 20:15:43 by Jason Blevins
Forward in time (to current) | Back in time (1 more) | See current | Hide changes | History | Rollback | View: Source | Linked from: Intrinsic procedures, unpack

AltStyle によって変換されたページ (->オリジナル) /