Skip to content
33 changes: 26 additions & 7 deletions precice.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ module precice
implicit none

interface

! This interface contains subroutines of two kinds:
! - precicec_<name> expect C-style, null-terminated strings and their sizes
! - precicef_<name> automatically convert strings to null-terminated and call
! the corresponding `precicec_<name>`.

subroutine precicef_create(participantName, configFileName, &
& solverProcessIndex, solverProcessSize, &
& participantNameLength, configFileNameLength) &
& bind(c, name='precicef_create_')
subroutine precicec_create(participantName, configFileName, &
& solverProcessIndex, solverProcessSize) &
& bind(c, name='precicec_createParticipant')

use, intrinsic :: iso_c_binding
character(kind=c_char), dimension(*) :: participantName
character(kind=c_char), dimension(*) :: configFileName
integer(kind=c_int) :: solverProcessIndex
integer(kind=c_int) :: solverProcessSize
integer(kind=c_int), value :: participantNameLength
integer(kind=c_int), value :: configFileNameLength
end subroutine precicef_create
end subroutine precicec_create

subroutine precicef_initialize() &
& bind(c, name='precicef_initialize_')
Expand Down Expand Up @@ -312,4 +314,21 @@ end subroutine precicef_get_version_information

end interface

contains

subroutine precicef_create(participantName, configFileName, &
& solverProcessIndex, solverProcessSize)

use, intrinsic :: iso_c_binding, only: c_char, c_int
character(len=*), intent(in) :: participantName
character(len=*), intent(in) :: configFileName
integer(c_int), intent(in) :: solverProcessIndex
integer(c_int), intent(in) :: solverProcessSize

call precicec_create( &
trim(participantName)//c_null_char, &
trim(configFileName)//c_null_char, &
solverProcessIndex, solverProcessSize)
end subroutine precicef_create

end module precice