Intel® Fortran Compiler 16.0 User and Reference Guide

EOSHIFT

Transformational Intrinsic Function (Generic): Performs an end-off shift on a rank-one array, or performs end-off shifts on all the complete rank-one sections along a given dimension of an array of rank two or greater. Elements are shifted off at one end of a section and copies of a boundary value are filled in at the other end. Different sections can have different boundary values and can be shifted by different amounts and in different directions.

result = EOSHIFT (array,shift [,boundary][,dim])

array

(Input) Must be an array (of any data type).

shift

(Input) Must be a scalar integer or an array with a rank that is one less than array, and shape (d1, d2, ..., ddim-1, ddim+1, ..., dn), where (d1, d2, ..., dn) is the shape of array.

boundary

(Input; optional) Must have the same type and kind parameters as array. It must be a scalar or an array with a rank that is one less than array, and shape (d1, d2, ..., ddim-1, ddim+1, ..., dn). The boundary specifies a value to replace spaces left by the shifting procedure.

If boundary is not specified, it is assumed to have the following default values (depending on the data type of array):

array Type

boundary Value

Integer

0

Real

0.0

Complex

(0.0, 0.0)

Logical

false

Character(len)

len blanks

dim

(Input; optional) Must be a scalar integer with a value in the range 1 to n, where n is the rank of array. If dim is omitted, it is assumed to be 1.

Results

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

If array has rank one, the same shift is applied to each element. If an element is shifted off one end of the array, the boundary value is placed at the other end the array.

If array has rank greater than one, each section (s1, s2, ..., sdim-1, :, sdim+1, ..., sn) of the result is shifted as follows:

If an element is shifted off one end of a section, the boundary value is placed at the other end of the section.

The value of shift determines the amount and direction of the end- off shift. A positive shift value causes a shift to the left (in rows) or up (in columns). A negative shift value causes a shift to the right (in rows) or down (in columns).

Example

V is the integer array (1, 2, 3, 4, 5, 6).

EOSHIFT (V, SHIFT=2) shifts the elements in V to the left by 2 positions, producing the value (3, 4, 5, 6, 0, 0). 1 and 2 are shifted off the beginning and two elements with the default BOUNDARY value are placed at the end.

EOSHIFT (V, SHIFT= -3, BOUNDARY= 99) shifts the elements in V to the right by 3 positions, producing the value (99, 99, 99, 1, 2, 3). 4, 5, and 6 are shifted off the end and three elements with BOUNDARY value 99 are placed at the beginning.

M is the CHARACTER(LEN=1) array

  [ 1  2  3 ]
  [ 4  5  6 ]
  [ 7  8  9 ].

EOSHIFT (M, SHIFT = 1, BOUNDARY = '*', DIM = 2) produces the result

  [ 2  3  * ]
  [ 5  6  * ]
  [ 8  9  * ].
 

Each element in rows 1, 2, and 3 is shifted to the left by 1 position. This causes the first element in each row to be shifted off the beginning, and the BOUNDARY value to be placed at the end.

EOSHIFT (M, SHIFT = -1, DIM = 1) produces the result

  [ ^  ^  ^ ]
  [ 1  2  3 ]
  [ 4  5  6 ].

Each element in columns 1, 2, and 3 is shifted down by 1 position. This causes the last element in each column to be shifted off the end and the BOUNDARY value (the default character boundary value <space>, represented by "^") to be placed at the beginning.

EOSHIFT (M, SHIFT = (/1, -1, 0/), BOUNDARY = (/ '*', '?', '/' /), DIM = 2) produces the result

  [ 2  3  * ]
  [ ?  4  5 ]
  [ 7  8  9 ].

Each element in row 1 is shifted to the left by 1 position, causing the first element to be shifted off the beginning and the BOUNDARY value * to be placed at the end. Each element in row 2 is shifted to the right by 1 position, causing the last element to be shifted off the end and the BOUNDARY value ? to be placed at the beginning. No element in row 3 is shifted at all, so the specified BOUNDARY value is not used.

The following shows another example:

INTEGER shift(3)
CHARACTER(1) array(3, 3), AR1(3, 3)
array = RESHAPE ((/'A', 'D', 'G', 'B', 'E', 'H', &
                   'C', 'F', 'I'/), (/3,3/))
!        array is A B C
!                 D E F
!                 G H I
shift = (/-1, 1, 0/)
AR1 = EOSHIFT (array, shift, BOUNDARY = (/'*','?','#'/), DIM= 2)
! returns         * A B
!                 E F ?
!                 G H I

See Also