mod_type.f90 997 Bytes
Newer Older
Mozul Rémy's avatar
Mozul Rémy committed
1 2 3 4 5 6 7

module test_type

  use iso_c_binding

  implicit none

8 9 10 11
  enum, bind(c)
    enumerator :: p1=1, p2, p3, p4
  end enum

Mozul Rémy's avatar
Mozul Rémy committed
12 13
  type, bind(c) :: myftype
    integer(c_int) :: i, j
14 15
    type(c_ptr) :: my_mat
    real(c_double), dimension(4) :: params
Mozul Rémy's avatar
Mozul Rémy committed
16 17 18 19 20 21
  end type myftype

  contains

  subroutine print_type(ft) bind(c, name='print_type')
    type(myftype) :: ft
Mozul Rémy's avatar
Mozul Rémy committed
22 23 24
    !
    real(c_double), dimension(:,:), pointer :: tab

25
    call c_f_pointer(fptr=tab,cptr=ft%my_mat,shape=(/ft%j,ft%i/))
Mozul Rémy's avatar
Mozul Rémy committed
26

27
    print *,'my mat : '
Mozul Rémy's avatar
Mozul Rémy committed
28 29
    print *, ft%i
    print *, ft%j
Mozul Rémy's avatar
Mozul Rémy committed
30
    print *, tab
31
    print *,'param vector : ', ft%params
Mozul Rémy's avatar
Mozul Rémy committed
32 33 34 35 36 37

  end subroutine

  subroutine increment(ft) bind(c,name='increment')
    implicit none
    type(myftype) :: ft
Mozul Rémy's avatar
Mozul Rémy committed
38 39 40 41
    !
    integer(c_int) :: i,j
    real(c_double), dimension(:,:), pointer :: tab

42
    call c_f_pointer(fptr=tab,cptr=ft%my_mat,shape=(/ft%j,ft%i/))
Mozul Rémy's avatar
Mozul Rémy committed
43 44 45 46 47 48

    do i = 1, ft%i
      do j = 1, ft%j
        tab(j,i) = 0.1d0*i*j
      end do
    end do
Mozul Rémy's avatar
Mozul Rémy committed
49 50 51 52 53

  end subroutine

end module test_type