<
robert....@oracle.com> wrote in message
news:e28906f6-25e2-4159...@h9g2000yqi.googlegroups.com...
> The array section A(1:10:2)is not contiguous. The array C is
> is an explicit-shape array, which for most implementations is
> required to be contiguous. The common way of working around
> this inconsistency is to make a contiguous copy of the elements
> of the section and pass that to C. After the return, the
> elements of the copy are copied back to the corresponding
> elements of the array A.
Fun example, Bob! For even more fun, we could try permuting the
order of arguments B and C and making A itself discontiguous:
C:\gfortran\clf\copy_test>type ct1.for
SUBROUTINE SUBR(B, C)
DIMENSION B(10), C(5)
DO 10 I = 1, 10
B(I) = 2.0
10 CONTINUE
END
PROGRAM COPY
DIMENSION A(10)
DO 10 I = 1,10
A(I) = 1.0
10 CONTINUE
CALL SUBR(A, A(1:10:2))
PRINT *, A
END
C:\gfortran\clf\copy_test>gfortran ct1.for -oct1
C:\gfortran\clf\copy_test>ct1
1.00000000 2.00000000 1.00000000 2.00000000
1.0000000
0 2.00000000 1.00000000 2.00000000 1.00000000
2.00
000000
C:\gfortran\clf\copy_test>type ct2.for
SUBROUTINE SUBR(C, B)
DIMENSION B(10), C(5)
DO 10 I = 1, 10
B(I) = 2.0
10 CONTINUE
END
PROGRAM COPY
DIMENSION A(10)
DO 10 I = 1,10
A(I) = 1.0
10 CONTINUE
CALL SUBR(A(1:10:2), A)
PRINT *, A
END
C:\gfortran\clf\copy_test>gfortran ct2.for -oct2
C:\gfortran\clf\copy_test>ct2
1.00000000 2.00000000 1.00000000 2.00000000
1.0000000
0 2.00000000 1.00000000 2.00000000 1.00000000
2.00
000000
C:\gfortran\clf\copy_test>type ct3.for
SUBROUTINE SUBR(B, C)
DIMENSION B(10), C(5)
DO 10 I = 1, 10
B(I) = 2.0
10 CONTINUE
END
PROGRAM COPY
DIMENSION D(20)
TARGET D
REAL(KIND(D)), POINTER :: A(:)
A => D(1:20:2)
DO 10 I = 1,10
A(I) = 1.0
10 CONTINUE
CALL SUBR(A, A(1:10:2))
PRINT *, A
END
C:\gfortran\clf\copy_test>gfortran ct3.for -oct3
C:\gfortran\clf\copy_test>ct3
1.00000000 2.00000000 1.00000000 2.00000000
1.0000000
0 2.00000000 1.00000000 2.00000000 1.00000000
2.00
000000
C:\gfortran\clf\copy_test>type ct4.for
SUBROUTINE SUBR(C, B)
DIMENSION B(10), C(5)
DO 10 I = 1, 10
B(I) = 2.0
10 CONTINUE
END
PROGRAM COPY
DIMENSION D(20)
TARGET D
REAL(KIND(D)), POINTER :: A(:)
A => D(1:20:2)
DO 10 I = 1,10
A(I) = 1.0
10 CONTINUE
CALL SUBR(A(1:10:2), A)
PRINT *, A
END
C:\gfortran\clf\copy_test>gfortran ct4.for -oct4
C:\gfortran\clf\copy_test>ct4
2.00000000 2.00000000 2.00000000 2.00000000
2.0000000
0 2.00000000 2.00000000 2.00000000 2.00000000
2.00
000000
For ct3.for and ct4.for we may expect results to depend upon compiler
and optimization level because there is then no certain order in
which copy-in/copy out is performed.
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end