9.3.46 EOSHIFT (ARRAY, SHIFT [, BOUNDARY] [, DIM])

Description:  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.  
Class:  Transformational function; Generic 
Arguments:  ARRAY Must be an array (of any data type). 
  SHIFT 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 (opt) 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). 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 (opt) 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:

  • By the value of SHIFT, if SHIFT is scalar

  • According to the corresponding value in SHIFT(s1, s2, ..., sDIM-1, sDIM+1, ..., sn), if SHIFT is an array
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).  

Examples

V is the 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 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

  [ 0  0  0 ]
  [ 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 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.


Previous Page Next Page Table of Contents