Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trasfering array of string from fortran into cpp #101

Open
Kun-Qu opened this issue Aug 18, 2023 · 1 comment
Open

trasfering array of string from fortran into cpp #101

Kun-Qu opened this issue Aug 18, 2023 · 1 comment
Assignees

Comments

@Kun-Qu
Copy link

Kun-Qu commented Aug 18, 2023

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
Copy link
Member

Wendi-L commented Aug 21, 2023

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:

  • OS: Ubuntu 20.04.6 LTS 64-bit
  • Compilers: GCC & GNU Fortran v9.4.0
  • MUI version: MUI v2.0
  • Procedure of compilation: By using MUI CMake build files with the CMake parameter "FORTRAN_WRAPPER=ON". No error was shown during compiling.
  • Test the code: MUI Demo "10-1-1-multiple-interfaces", which contains the "create_and_get_uniface_multi_1d_f()" subroutine, was used as a test for the code and the compilation. The code was run as expected and no error was shown during running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants