| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! This program checks that passing arrays as assumed-shape dummies to |
| 4 |
! and from Fortran functions with C binding works. |
| 5 |
|
| 6 |
module mm |
| 7 |
use iso_c_binding |
| 8 |
type, bind (c) :: m |
| 9 |
integer(C_INT) :: i, j |
| 10 |
end type |
| 11 |
|
| 12 |
integer, parameter :: imax=10, jmax=5 |
| 13 |
end module |
| 14 |
|
| 15 |
program testit |
| 16 |
use iso_c_binding |
| 17 |
use mm |
| 18 |
implicit none |
| 19 |
|
| 20 |
type(m) :: aa(imax,jmax) |
| 21 |
integer :: i, j |
| 22 |
do j = 1, jmax |
| 23 |
do i = 1, imax |
| 24 |
aa(i,j)%i = i |
| 25 |
aa(i,j)%j = j |
| 26 |
end do |
| 27 |
end do |
| 28 |
|
| 29 |
call testc (aa) |
| 30 |
call testf (aa) |
| 31 |
|
| 32 |
contains |
| 33 |
|
| 34 |
! C binding version |
| 35 |
|
| 36 |
subroutine checkc (a, b) bind (c) |
| 37 |
use iso_c_binding |
| 38 |
use mm |
| 39 |
type(m) :: a(:,:), b(:,:) |
| 40 |
integer :: i, j |
| 41 |
|
| 42 |
if (size (a,1) .ne. imax) stop 101 |
| 43 |
if (size (a,2) .ne. jmax) stop 102 |
| 44 |
if (size (b,1) .ne. jmax) stop 103 |
| 45 |
if (size (b,2) .ne. imax) stop 104 |
| 46 |
|
| 47 |
do j = 1, jmax |
| 48 |
do i = 1, imax |
| 49 |
if (a(i,j)%i .ne. i) stop 105 |
| 50 |
if (a(i,j)%j .ne. j) stop 106 |
| 51 |
if (b(j,i)%i .ne. i) stop 107 |
| 52 |
if (b(j,i)%j .ne. j) stop 108 |
| 53 |
end do |
| 54 |
end do |
| 55 |
end subroutine |
| 56 |
|
| 57 |
! Fortran binding version |
| 58 |
subroutine checkf (a, b) |
| 59 |
use iso_c_binding |
| 60 |
use mm |
| 61 |
type(m) :: a(:,:), b(:,:) |
| 62 |
integer :: i, j |
| 63 |
|
| 64 |
if (size (a,1) .ne. imax) stop 201 |
| 65 |
if (size (a,2) .ne. jmax) stop 202 |
| 66 |
if (size (b,1) .ne. jmax) stop 203 |
| 67 |
if (size (b,2) .ne. imax) stop 204 |
| 68 |
|
| 69 |
do j = 1, jmax |
| 70 |
do i = 1, imax |
| 71 |
if (a(i,j)%i .ne. i) stop 205 |
| 72 |
if (a(i,j)%j .ne. j) stop 206 |
| 73 |
if (b(j,i)%i .ne. i) stop 207 |
| 74 |
if (b(j,i)%j .ne. j) stop 208 |
| 75 |
end do |
| 76 |
end do |
| 77 |
end subroutine |
| 78 |
|
| 79 |
! C binding version |
| 80 |
subroutine testc (a) bind (c) |
| 81 |
use iso_c_binding |
| 82 |
use mm |
| 83 |
type(m) :: a(:,:) |
| 84 |
type(m) :: b(jmax, imax) |
| 85 |
integer :: i, j |
| 86 |
|
| 87 |
if (size (a,1) .ne. imax) stop 301 |
| 88 |
if (size (a,2) .ne. jmax) stop 302 |
| 89 |
do j = 1, jmax |
| 90 |
do i = 1, imax |
| 91 |
b(j,i)%i = a(i,j)%i |
| 92 |
b(j,i)%j = a(i,j)%j |
| 93 |
end do |
| 94 |
end do |
| 95 |
|
| 96 |
! Call both the C and Fortran binding check functions |
| 97 |
call checkc (a, b) |
| 98 |
call checkf (a, b) |
| 99 |
end subroutine |
| 100 |
|
| 101 |
! Fortran binding version |
| 102 |
subroutine testf (a) |
| 103 |
use iso_c_binding |
| 104 |
use mm |
| 105 |
type(m) :: a(:,:) |
| 106 |
type(m) :: b(jmax, imax) |
| 107 |
integer :: i, j |
| 108 |
|
| 109 |
if (size (a,1) .ne. imax) stop 401 |
| 110 |
if (size (a,2) .ne. jmax) stop 402 |
| 111 |
do j = 1, jmax |
| 112 |
do i = 1, imax |
| 113 |
b(j,i)%i = a(i,j)%i |
| 114 |
b(j,i)%j = a(i,j)%j |
| 115 |
end do |
| 116 |
end do |
| 117 |
|
| 118 |
! Call both the C and Fortran binding check functions |
| 119 |
call checkc (a, b) |
| 120 |
call checkf (a, b) |
| 121 |
end subroutine |
| 122 |
|
| 123 |
end program |