Cshift is an array intrinsic procedure.
The function Cshift takes an array and preforms a circular shift of its elements along a specified dimension.
cshift( array,shift )
Array
Array can be an array of any size and rank.
Shift
Shift can be an integer or integer array with rank one less than the rank of "array". It dictates how many spaces to shift each element. A positive value would cause the end elements to be shifted toward the first position in the array. A negative value for shift would result in the beginning elements being shifted toward the high numbered end of the array. See the example below for use of "shift" as an array in conjunction with the optional argument "dim". If "array" has a rank greater than one and "shift" is a scalar (single integer) then that shift is applied everywhere.
cshift( array,shift,dim )
Dim
Dim designates along which dimension of the array that the elements are shifted. This is optional because if this argument is omitted the compiler will assume dim=1.
Let us assume we have declared the array called granite(4,4) to have the values stored in its elements:
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
We then preform the following shift on it.
Granite2 = cshift( granite,shift=/1,-1,0,2/,dim=1 )
Granite2 would have the following values stored in it.
5 4 3 2 9 2 7 6 3 6 1 4 1 0 5 8
If you wanted to preform a circular shift on granite's rows, do the following:
granite2 = cshift( granite,shift=/1,-1,0,5/,dim=2/ )
This time granite2 will the following values stored in its elements:
2 3 4 1 8 5 6 7 9 0 1 2 5 6 3 4
lecture thirty six
examples: sort3a.f and dimtest.f
Written by Jason Wehr : jcw142@psu.edu and Maintained by John Mahaffy : jhm@cac.psu.edu