﻿ EOSHIFT Function
 LF Fortran 95

# EOSHIFT Function

### Description

The EOSHIFT function performs an end-off shift of all rank one sections in an array. Elements are shifted out at one end and copies of a boundary value 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
EOSHIFT (array, shift [, boundary] [, dim])
```

### Required Arguments

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

shift is an INTENT(IN) scalar or array of type INTEGER.

If array is rank one, shift must be scalar; otherwise shift may 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

boundary is INTENT(IN) and of same type and kind as array. It must be scalar if array is of rank one. Otherwise it may be scalar or of rank n-1 and shape (d1,d2, ...,ddim-1,ddim+1, ...,dn).

If array is of type CHARACTER, boundary must have the same length as array.

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

### Result

The result is the same type, kind and shape as array. The boundary value is assigned to any element of the array which does not have a source value.

If array is of rank one, the result is the value of array shifted by shift elements

If shift is scalar, and array is of rank two or greater, each element along dimension dim is shifted by shift elements.

If shift is an array, each element along dimension dim is shifted by the amount specified in the corresponding shift vector.

If boundary is absent, the default pad values are zero for numeric types, blanks for CHARACTER, and false for LOGICAL.

```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) eoshift(a, 1)            ! writes 2  3  0
write(*,10) eoshift(a,1, -1)         ! writes 2  3 -1
write(*,20) b                        ! writes 1  2  3
!        4  5  6
!        7  8  9
write(*,20) eoshift(b,-1)            ! writes 0  1  2
!        0  4  5
!        0  7  8
write(*,20) eoshift(b,-1,(/1,-1,0/)) ! writes 1  1  2
!       -1  4  5
!        0  7  8
write(*,20) eoshift(b,(/1,-1,0/))    ! writes 2  3  0
!        0  4  5
!        7  8  9
write(*,20) eoshift(b,1,dim=2)       ! writes 4  5  6
!        7  8  9
!        0  0  0
10 format(3i3)
20 format(3(/,3i3))
```