Debian Codegraph @

doc/src/intrinsics/array/cshift.md

raw
1 # cshift(A, shift [, dim]): Circular Shift
2
3 Circular shift elements of an array.
4
5 ## Declaration
6
7 ### Syntax
8
9 ```fortran
10 retval = cshift(A, shift [, dim])
11 integer function cshift(A, shift, [, dim])
12 ```
13
14 ### Arguments
15
16 `A` the input array of any type or rank.
17
18 `shift` the input value of integer type.
19
20 `dim` optional dimension, if present, `cshift` returns the result of this dimension.
21
22 ### Return values
23
24 The return value is of input array type and rank as the `A` array input argument.
25
26 ## Description
27
28 **cshift(A, shift [, dim])** performs a circular shift on elements of `A` array
29 along the dimension of `dim`. Default value of `dim` is 1, used when `dim` is
30 not passed.
31
32 If the rank of array is 1, then all elements of array are shifted by `shift`
33 places. If rank is greater than one, then all complexte rank one sections of
34 array along the given dimension are shifted.
35
36 Elements shifted out one end of each rank one section are shifted back in the
37 other end.
38
39 ## Types
40
41 Supported argument type is array for `A` and integer for `shift` and `dim`.
42
43 ## Examples
44
45 ```fortran
46 program intrinsics_cshift
47 implicit none
48 integer, dimension(5):: a = [1, 2, 3, 4, 5]
49 print '(5i3)', a
50 a = cshift(a, shift = 2)
51 print *, size(A, 2)
52 end program
53 ```
54
55 **Result**:
56
57 ```
58 1, 2, 3
59 4, 5, 1
60 ```
61
62 ## See Also