MxUI / MUI

Multiscale Universal Interface: A Concurrent Framework for Coupling Heterogeneous Solvers
http://mxui.github.io/
Apache License 2.0
54 stars 40 forks source link

trasfering array of string from fortran into cpp #101

Open Kun-Qu opened 1 year ago

Kun-Qu commented 1 year ago
interface 
    !Set of 1D interfaces with float=double and int=int32
    !Recomend to use the create_and_get_uniface_multi_1d_f(*) subroutine
    ! instead of use this subroutine directly
    subroutine mui_create_uniface_multi_1d_f(domain, interfaces, &
        interface_count) bind(C)
      import :: c_char,c_int
      character(kind=c_char), intent(in) :: domain(*)
      character(kind=c_char,len=*), intent(in) :: interfaces(*)
      integer(kind=c_int), value :: interface_count
    end subroutine mui_create_uniface_multi_1d_f
.....
end interface

    subroutine create_and_get_uniface_multi_1d_f(uniface_pointers_1d, domain, interfaces, &
      interface_count)
      use, intrinsic :: iso_c_binding
      implicit none

      type(ptr_typ_1d), target :: uniface_pointers_1d(:)
      character(kind=c_char), intent(in) :: domain(*)
      character(kind=c_char,len=*), intent(in) :: interfaces(*)
      integer(kind=c_int), VALUE :: interface_count
      integer :: i

      call mui_create_uniface_multi_1d_f(domain, interfaces, &
        interface_count)

      do i = 1, interface_count
        uniface_pointers_1d(i)%ptr = get_mui_uniface_multi_1d_f(i)
      end do
    end subroutine create_and_get_uniface_multi_1d_f

compiler reported error for character(kind=c_char,len=*), intent(in) :: interfaces(*)

I made some modification:

For the interface

subroutine mui_create_uniface_multi_1d_f(domain, interfaces, &
    interface_count) bind(C)
  import :: c_char,c_int,c_ptr
  character(kind=c_char), intent(in) :: domain(*)
  type(c_ptr),DIMENSION(*) :: interfaces
  integer(kind=c_int), value :: interface_count
end subroutine mui_create_uniface_multi_1d_f

In create_and_get_uniface_multi_1d_f, modify

character(kind=c_char, len=*),  target, intent(in) :: interfaces(*)
type(c_ptr) :: c_interfaces(interface_count)

do i=1, interface_count
  c_interfaces(i) = c_loc(  interfaces(i) )
enddo

call  mui_create_uniface_multi_1d_f(domain, c_interfaces, interface_count)
Wendi-L commented 1 year ago

Many thanks for your bug report. Unfortunately, I cannot repeat the compilation error that you mentioned.

Please share the OS, compiler and version number when you hit the error for further analysis.

Let me share mine first: