Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Shift array index without copying

Wee_Beng_T_
Beginner
149 Views

Hi,

I have an array e.g. A(3:7,4:8). So index starts from 3 / 4 and ends with 7 / 8. I would like to change it to A(43:47,44:48) without creating a new array and copying it. Is that possible? The array could be dynamically allocated ones. The values in the array will be changed so it doesn't matter if they are the same or not.

 

Thanks.

0 Kudos
2 Replies
jimdempseyatthecove
Black Belt
149 Views
program arrayindex
    implicit none
    real, target :: rawA(5,5)
    real, pointer :: A(:,:)
    integer :: r,c
    do r=1,5
        do c=1,5
            rawA(c,r) = c*10+r
        end do
    end do
    A(3:7,4:8) => rawA
    print *, A
    A(43:47,44:48) => rawA
    print *,A
end program arrayindex

Jim Dempsey

Wee_Beng_T_
Beginner
149 Views

Thanks Jim for the solution!

Reply