| 1 |
! { dg-do run } |
| 2 |
! { dg-additional-sources "cf-descriptor-1-c.c dump-descriptors.c" } |
| 3 |
! |
| 4 |
! This program checks that building a descriptor for a fixed-size array |
| 5 |
! in C works and that you can use it to call back into a Fortran function |
| 6 |
! declared to have c binding, as an assumed-shape argument. |
| 7 |
|
| 8 |
module mm |
| 9 |
use iso_c_binding |
| 10 |
type, bind (c) :: m |
| 11 |
integer(C_INT) :: i, j |
| 12 |
end type |
| 13 |
|
| 14 |
integer, parameter :: imax=10, jmax=5 |
| 15 |
end module |
| 16 |
|
| 17 |
subroutine ftest (a, b) bind (c, name="ftest") |
| 18 |
use iso_c_binding |
| 19 |
use mm |
| 20 |
type(m) :: a(:,:), b(:,:) |
| 21 |
integer :: i, j |
| 22 |
|
| 23 |
if (size (a,1) .ne. imax) stop 101 |
| 24 |
if (size (a,2) .ne. jmax) stop 102 |
| 25 |
if (size (b,1) .ne. jmax) stop 103 |
| 26 |
if (size (b,2) .ne. imax) stop 104 |
| 27 |
|
| 28 |
do j = 1, jmax |
| 29 |
do i = 1, imax |
| 30 |
if (a(i,j)%i .ne. i) stop 201 |
| 31 |
if (a(i,j)%j .ne. j) stop 202 |
| 32 |
if (b(j,i)%i .ne. i) stop 203 |
| 33 |
if (b(j,i)%j .ne. j) stop 204 |
| 34 |
end do |
| 35 |
end do |
| 36 |
end subroutine |
| 37 |
|
| 38 |
|
| 39 |
program testit |
| 40 |
use iso_c_binding |
| 41 |
use mm |
| 42 |
implicit none |
| 43 |
|
| 44 |
interface |
| 45 |
subroutine ctest (a) bind (c) |
| 46 |
use iso_c_binding |
| 47 |
use mm |
| 48 |
type(m) :: a(:,:) |
| 49 |
end subroutine |
| 50 |
end interface |
| 51 |
|
| 52 |
type(m) :: aa(imax,jmax) |
| 53 |
integer :: i, j |
| 54 |
do j = 1, jmax |
| 55 |
do i = 1, imax |
| 56 |
aa(i,j)%i = i |
| 57 |
aa(i,j)%j = j |
| 58 |
end do |
| 59 |
end do |
| 60 |
|
| 61 |
! Pass the initialized array to a C function ctest, which will generate its |
| 62 |
! transpose and call ftest with it. |
| 63 |
|
| 64 |
call ctest (aa) |
| 65 |
|
| 66 |
end program |