CSHIFT(3) - [ARRAY:TRANSFORMATIONAL] Circular shift elements of an array
result = cshift(array, shift [,dim])
type(TYPE(kind=KIND)) function cshift(array, shift, dim )type(TYPE(kind=KIND)),intent(in) :: array(..) integer(kind=**),intent(in) :: shift integer(kind=**),intent(in) :: dim
NOTE: :a kind designated as ** may be any supported kind for the type
o ARRAY may be any type and rank o SHIFT an integer scalar if ARRAY has rank one. Otherwise, it shall be scalar or of rank n-1 and of shape [d1, d2, ..., dDIM-1, dDIM+1, ..., dn] where [d1, d2, ..., dn] is the shape of ARRAY. o DIM is an integer scalar with a value in the range 1 <= DIM <= n, where n is the rank of ARRAY. If DIM is absent, it is as if it were present with the value 1. o the result will automatically be of the same type, kind and shape as ARRAY.
CSHIFT(3) performs a circular shift on elements of ARRAY along the dimension of DIM. If DIM is omitted it is taken to be 1. DIM is a scalar of type integer in the range of 1 <= DIM <= N, where "n" is the rank of ARRAY.
If the rank of ARRAY is one, then all elements of ARRAY are shifted by SHIFT places. If rank is greater than one, then all complete rank one sections of ARRAY along the given dimension are shifted. Elements shifted out one end of each rank one section are shifted back in the other end.
o ARRAY : An array of any type which is to be shifted o SHIFT : the number of positions to circularly shift. A negative value produces a right shift, a positive value produces a left shift. o DIM : the dimension along which to shift a multi-rank ARRAY. Defaults to 1.
Returns an array of same type and rank as the ARRAY argument.
The rows of an array of rank two may all be shifted by the same amount or by different amounts.
cshift
Sample program:
program demo_cshift implicit none integer, dimension(5) :: i1,i2,i3 integer, dimension(3,4) :: a, b !basics i1=[10,20,30,40,50] print *,start with: print (1x,5i3), i1 print *,shift -2 print (1x,5i3), cshift(i1,-2) print *,shift +2 print (1x,5i3), cshift(i1,+2)Results:print *,start with a matrix a = reshape( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], [ 3, 4 ]) print (4i3), a(1,:) print (4i3), a(2,:) print (4i3), a(3,:) print *,matrix shifted along rows, each by its own amount [-1,0,1] b = cshift(a, SHIFT=[1, 0, -1], DIM=2) print * print (4i3), b(1,:) print (4i3), b(2,:) print (4i3), b(3,:) end program demo_cshift
> start with: > 10 20 30 40 50 > shift -2 > 40 50 10 20 30 > shift +2 > 30 40 50 10 20 > start with a matrix > 1 4 7 10 > 2 5 8 11 > 3 6 9 12 > matrix shifted along rows, each by its own amount > > 4 7 10 1 > 2 5 8 11 > 12 3 6 9
Fortran 95
Fortran intrinsic descriptions
o EOSHIFT(3) - End-off shift elements of an array o SUM(3) - sum the elements of an array o PRODUCT(3) - Product of array elements o FINDLOC(3) - Location of first element of ARRAY identified by MASK along dimension DIM having a value o MAXLOC(3) - Location of the maximum value within an array
Nemo Release 3.1 | cshift (3fortran) | November 02, 2024 |