Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shifting array in the vertical direction 1

Status
Not open for further replies.

ignacio_b

Technical User
Jul 29, 2019
10
GB
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top