Return array of strings from Fortran to C#

Return array of strings from Fortran to C#


I need a simple way to return an array of strings with unknown size to C#. Here there is a sample code of fortran subroutine:

subroutine testStringArray(strArr)
! directive
!DEC$ ATTRIBUTES DLLEXPORT, Alias:'testStringArray' :: testStringArray
! argument
character(len=32),allocatable,intent(out) :: strArr(:)
! local variable
integer :: size
! main
print*, 'Please enter the size of array:'
read(*,*) size
strArr='Hello world'C
end subroutine testStringArray

Can anyone give me a C# code to use this subroutine?

There is no matter in changing the directives, interface, arguments and body of subroutine. my main goal is returing strings to C#.

Best regards, Arash.

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I would recommend using a SafeArray to set up your string array, then using Marshalas(UnmanagedType.SafeArray) on the C# side.

There is a Fortran SafeArray example that comes with the Intel compiler that you an utilise for guidance.

Leave a Comment

Please sign in to add a comment. Not a member? Join today