cshift

Date:

10-12-2011

NAME

CSHIFT - Performs a circular shift on an array expression

SYNOPSIS

CSHIFT ([ARRAY=]array, [SHIFT=]shift [, [DIM=]dim])

IMPLEMENTATION

Cray Linux Environment (CLE)

STANDARDS

Fortran

DESCRIPTION

The CSHIFT intrinsic function performs a circular shift on an array expression of rank 1 or performs circular shifts on all the complete rank 1 sections along a given array expression of rank 2 or greater. Elements shifted out at one end are shifted in at the other end. Different sections can be shifted by different amounts and in different directions; positive for left shifts, negative for right shifts.

CSHIFT accepts the following arguments:

array

Can be of any type. It must not be a scalar.

shift

Must be integer. If array has rank 1, shift must be a scalar. Otherwise, shift must be scalar or have rank n-1 and have shape

(d1, d2, ..., ddim-1, ddim+1, ..., dn)
  • where

(d1, d2, ..., dn)
  • is the shape of array.

dim

Must be a scalar. It is an integer with a value in the range 1 <= dim <= n, where n is the rank of array. If dim is omitted, a value of 1 is assumed.

CSHIFT is a transformational function. The name of this intrinsic cannot be passed as an argument.

RETURN VALUES

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

If array has rank 1, element i of the result is array(1 + modulo(i + shift - 1, size(array))).

If array has rank greater than 1, section

(s1, s2, ..., sdim-1, : , sdim+1, ..., sn)

of the result has a value equal to

CSHIFT(array (s1, s2, ..., sdim-1, : , sdim+1, ..., sn), sh, 1)

where sh is shift or

shift(s1, s2, ..., sdim-1, sdim+1, ..., sn)

EXAMPLES

Example 1: If V is a rank 1 array [1,2,3,4,5,6], the effect of shifting V circularly to the left by two positions is achieved by CSHIFT(V,SHIFT=2), which has the value [3,4,5,6,1,2]. Specifying CSHIFT(V,SHIFT=-2) achieves a circular shift to the right by two positions and has the value [5,6,1,2,3,4].

Example 2: The rows of an array of rank 2 can all be shifted by the same amount or by different amounts. Assume M is the following array:

| 1 2 3 |
| 4 5 6 |
| 7 8 9 |

CSHIFT(M,SHIFT=-1,DIM=2) yields:

| 3 1 2 |
| 6 4 5 |
| 9 7 8 |

CSHIFT(M,SHIFT=(/-1,1,0),DIM=2) yields:

| 3 1 2 |
| 5 6 4 |
| 7 8 9 |

Example 3: N is the following array:

| 1  2  3  4 |
| 5  6  7  8 |
| 9 10 11 12 |

CSHIFT(N,SHIFT=-1,DIM=1) yields:

| 9 10 11 12 |
| 1  2  3  4 |
| 5  6  7  8 |

With an array section of multidimensional array N, CSHIFT(N(2:3,2:4),SHIFT=-1,DIM=1)) yields:

| 10 11 12 |
|  6  7  8 |