| 1 |
! { dg-do run } |
| 2 |
! { dg-additional-sources "cf-descriptor-7-c.c dump-descriptors.c" } |
| 3 |
! |
| 4 |
! This program tests passing the result of the CFI_select_part C library |
| 5 |
! routine back to Fortran. Most of the work happens on the C side. |
| 6 |
|
| 7 |
module mm |
| 8 |
use iso_c_binding |
| 9 |
type, bind (c) :: m |
| 10 |
integer(C_INT) :: i, j |
| 11 |
end type |
| 12 |
|
| 13 |
integer, parameter :: imax=10, jmax=5 |
| 14 |
end module |
| 15 |
|
| 16 |
subroutine ftest (iarray, jarray) bind (c, name="ftest") |
| 17 |
use iso_c_binding |
| 18 |
use mm |
| 19 |
integer(C_INT), pointer :: iarray(:,:), jarray(:,:) |
| 20 |
|
| 21 |
integer :: i, j, i1, i2, j1, j2 |
| 22 |
|
| 23 |
! iarray and jarray must have the same shape as the original array, |
| 24 |
! but might be zero-indexed instead of one-indexed. |
| 25 |
if (size (iarray, 1) .ne. imax) stop 101 |
| 26 |
if (size (iarray, 2) .ne. jmax) stop 102 |
| 27 |
if (size (jarray, 1) .ne. imax) stop 103 |
| 28 |
if (size (jarray, 2) .ne. jmax) stop 104 |
| 29 |
|
| 30 |
j1 = lbound(iarray, 2) |
| 31 |
j2 = lbound(jarray, 2) |
| 32 |
do j = 1, jmax |
| 33 |
i1 = lbound(iarray, 1) |
| 34 |
i2 = lbound(jarray, 1) |
| 35 |
do i = 1, imax |
| 36 |
if (iarray (i1, j1) .ne. i) stop 201 |
| 37 |
if (jarray (i2, j2) .ne. j) stop 202 |
| 38 |
i1 = i1 + 1 |
| 39 |
i2 = i2 + 1 |
| 40 |
end do |
| 41 |
j1 = j1 + 1 |
| 42 |
j2 = j2 + 1 |
| 43 |
end do |
| 44 |
end subroutine |
| 45 |
|
| 46 |
|
| 47 |
program testit |
| 48 |
use iso_c_binding |
| 49 |
use mm |
| 50 |
implicit none |
| 51 |
|
| 52 |
interface |
| 53 |
subroutine ctest (a) bind (c) |
| 54 |
use iso_c_binding |
| 55 |
use mm |
| 56 |
type(m) :: a(:,:) |
| 57 |
end subroutine |
| 58 |
end interface |
| 59 |
|
| 60 |
type(m), target :: aa(imax,jmax) |
| 61 |
integer :: i, j |
| 62 |
do j = 1, jmax |
| 63 |
do i = 1, imax |
| 64 |
aa(i,j)%i = i |
| 65 |
aa(i,j)%j = j |
| 66 |
end do |
| 67 |
end do |
| 68 |
|
| 69 |
! Pass the initialized array to a C function ctest, which will split it |
| 70 |
! into i and j component arrays and pass them to ftest. |
| 71 |
|
| 72 |
call ctest (aa) |
| 73 |
|
| 74 |
end program |