# Shifting array in the vertical direction 1

Status
Not open for further replies.

#### ignacio_b

##### Technical User
Hello,

I have the following array
a(1,=(/2.144999981, 2.144999981, 2.144999981/)
a(2,=(/2.144999981, 2.144999981, 6.434999943/)
a(3,=(/2.144999981, 6.434999943, 2.144999981/)
a(4,=(/2.144999981, 6.434999943, 6.434999943/)
a(5,=(/6.434999943, 2.144999981, 2.144999981/)
a(6,=(/6.434999943, 2.144999981, 6.434999943/)
a(7,=(/6.434999943, 6.434999943, 2.144999981/)
a(8,=(/6.434999943, 6.434999943, 6.434999943/)

and in FORTRAN there's an option for horizontal shifting called CSHIFT, but I need to perform a vertical shift (up and down) of the previous array.
Is there an intrinsic function that does it? or someone knows a way.

Thanks and regards,

And what about TRANSPOSE, CSHIFT and then TRANSPOSE again ?

Can't you use CSHIFT(ARRAY, 1, 1)

The third parameter says which index to shift. 1 specifies the row, 2 specifies the column
Code:
``````program main
integer:: aa(3, 2), bb(3, 2)

aa(1,:) = (/ 1, 2 /)
aa(2,:) = (/ 3, 4 /)
aa(3,:) = (/ 5, 6 /)

write(*,*) 'Shift of 1'
bb = cshift(aa, 1, 1)
write(*, '(2I5)')((bb(ii,jj), jj = 1, 2), ii=1,3)
write(*,*) 'Shift of 2'
bb = cshift(aa, 1, 2)
write(*, '(2I5)')((bb(ii,jj), jj = 1, 2), ii=1,3)
stop
end program``````
Result
Code:
``````Shift of 1
3    4
5    6
1    2
Shift of 2
2    1
4    3
6    5``````

Thanks!!!!

Status
Not open for further replies.

Replies
2
Views
141
Replies
2
Views
138
Replies
2
Views
144
Replies
1
Views
44
Replies
0
Views
107