Lahey/Fujitsu Fortran

CSHIFT Function

Description

The CSHIFT function performs a circular shift of all rank one sections in an array. Elements shifted out at one end are shifted in at the other. Different sections can be shifted by different amounts and in different directions by using an array-valued shift.

Syntax

CSHIFT (array, shift [, dim] )

Required Arguments

array is an INTENT(IN) array of any type. It must not be scalar.

shift is an INTENT(IN) INTEGER and must be scalar if array is of rank one; otherwise it can either be scalar or of rank n-1 and shape (d1,d2, ...,ddim-1,ddim+1, ...,dn), where (d1,d2, ...,dn) is the shape of array.

Optional Arguments

dim is an INTENT(IN) scalar INTEGER with a value in the range 1 ≤ xn, where n is the rank of array. If dim is omitted, it is as if it were present with the value one.

Result

The result is of the same type, kind, and shape as array.

If array is of rank one, the value of the result is the value of array circularly shifted shift elements. A shift of n performed on array gives a result value of array(1 + MODULO(i + n - 1, SIZE(array))) for element i.

If array is of rank two or greater, each complete vector along dimension dim is circularly shifted shift elements. shift can be an array.

Example

integer :: a(3), b(3,3) a = (/1,2,3/) b = reshape ((/1,2,3,4,5,6,7,8,9/), (/3,3/)) write(*,10) a ! writes 1 2 3 write(*,10) cshift(a, 1) ! writes 2 3 1 write(*,20) b ! writes 1 2 3 ! 4 5 6 ! 7 8 9 write(*,20) cshift(b,-1) ! writes 3 1 2 ! 6 4 5 ! 9 7 8 write(*,20) cshift(b,(/1,-1,0/))! writes 2 3 1 ! 6 4 5 ! 7 8 9 write(*,20) cshift(b,1,dim=2) ! writes 4 5 6 ! 7 8 9 ! 1 2 3 10 format(3i3) 20 format(3(/,3i3))