forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Passing INTEGER/REAL Arrays from FTN95 to C#

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
TAC



Joined: 02 Sep 2005
Posts: 1

PostPosted: Fri Sep 02, 2005 11:16 pm    Post subject: Passing INTEGER/REAL Arrays from FTN95 to C# Reply with quote

Perhaps I'm missing something obvious, but I'm merely trying to pass an array from a FTN95 routine (in a DLL) to a C# static routine (in another DLL) and the following test code causes a runtime error:

[u]FTN95[/u]
SUBROUTINE SUB1
LIBRARY "CSlib.dll" ! C# DLL
ASSEMBLY_EXTERNAL(NAME="CSlib.TestClass.test") TEST
INTEGER IRET,ITEST(2)

IRET = TEST(ITEST)

END SUBROUTINE


[u]C#[/u]
public class TestClass
{
public static int test(ref int[] itest)
{
itest[0] = 1;
itest[1] = 2;
return(0);
}
}


I'm using .NET in Visual Studio 2003. At runtime the debugger raises the error: "Method not found: Int32 CSlib.TestClass.test(Int32 ByRef)". Works fine if I pass a scalar (i.e. "INTEGER ITEST" and "ref int itest"), but not an array.

Am I using the correct syntax for FTN95/C# for passing an array by reference? Any suggestions?

Thanks in advance,

Andy.

Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6593
Location: Salford, UK

PostPosted: Wed Sep 07, 2005 1:08 am    Post subject: Passing INTEGER/REAL Arrays from FTN95 to C# Reply with quote

The simple answer to your question is to use

public static unsafe int test(int* itest)

The alternative is to create a .NET array in the Fortran and to copy the Fortran array to the .NET array.

The main thing to note is that .NET arrays are "safe arrays" with a header part containing the array properties. A Fortran array is just a contiguous block of data for the array elements. If you go into more that one dimension then you need to be aware that Fortran arrays use "column major" ordering i.e. the opposite to C#.

Sometimes you can resolve this kind of question by looking at a disassembly of the exe/dll. To do this you can use the C# utility called ILDASM.exe.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group