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 C# arrays to fortran

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



Joined: 22 Feb 2007
Posts: 1

PostPosted: Wed Feb 28, 2007 3:26 pm    Post subject: Passing C# arrays to fortran Reply with quote

Hi,

I got the following C# function

float[,] c = {{1.0f,2.0f},{3.0f,4.0f},{5.0f,6.0f}};
// Reshuffling to ftn indexing
float[,] buf = FtnUtilities.ToFortran(c);
int i=3, j=2;
FromDotNet(buf, i, j);

The FromDotNet is a fortran assembly interface as declared below
Subroutine FromDotNet(Buf2D, IN, JN)
IMPLICIT NONE
ASSEMBLY_INTERFACE(Name="FromDotNet")
INTEGER IN, JN
REAL(Kind=1) Buf2D(:,Smile

Call FtnSub(Buf2D, IN, JN)
End Subroutine FromDotNet

Subroutine FtnSub (Buf2D, IN, JN)
IMPLICIT NONE
INTEGER IN, JN
REAL(Kind=1) Buf2D(IN,JN)

End Subroutine FtnSub

When the buffer received by the fortran assembly interface function is passed to the fortran function, the following exception is thrown:
"'Salford.Fortran.RuntimeException' occurred in ftn95lib.mdl Additional information: 19: Argument one is too small for its declared size". Is it possible to pass a C# array to a fortran assembly interface and then passing the same array further on to a fortran subroutine? If so, how should the 2 dimensional array be declared in the ftn assembly interface and in the fortran subroutine to make this possible?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Wed Feb 28, 2007 9:46 pm    Post subject: Reply with quote

The relevant information can be found in the help file under .NET Platform->.NET Programming->.NET Arrays.

FTN95 does not convert .NET arrays into Fortran arrays. You can pass a .NET array (or indeed a Fortran array) but you must treat it as the same object at both ends or do your own copying from one form to the other.

You need also to be aware of the garbage collection problem, namely that (in .NET) objects can be moved by the garbage collector and this can be a problem if they are treated as fixed in memory whilst in Fortran code. Thus, for example, you can have problems if a .NET array element is passed as an INTENT(OUT) argument to a subroutine (if garbage collection occurs whilst in the Fortran routine then the element may have been moved to a different address when the information is passed back to the caller). The latest version of FTN95 prevents you from doing this.
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 -> Support 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