Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29386 Discussions

Return array of strings from Fortran to C#

Arash_Rasekh
Beginner
681 Views

Hi,

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:

[fortran]

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
allocate(strArr(size))
strArr='Hello world'C
end subroutine testStringArray

[/fortran]

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.

0 Kudos
1 Reply
Anthony_Richards
New Contributor I
681 Views

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.

0 Kudos
Reply