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 

Fortran to .net

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



Joined: 11 Oct 2006
Posts: 1

PostPosted: Wed Oct 11, 2006 10:10 am    Post subject: Fortran to .net Reply with quote

Dear All,

I used to have software written in fortran 90( Compaq Fortran). Now I try to use some parts of it as a dll for my code in .net. How can I transfer a peice of code in fortran90 to salford fortran which is useable in .net? I should add that I have a salford compiler for visual studio 2003.
Thank you very much in advance.

Best Regards,
Reza
Back to top
View user's profile Send private message
DrTip



Joined: 01 Aug 2006
Posts: 74
Location: Manchester

PostPosted: Wed Oct 11, 2006 3:22 pm    Post subject: Fortran to .net Reply with quote

Rezal

What are you try to do?

THe documentation has lot sof example of this. The difficulties will be in the compaq to ftn95 conversions (ie the use of compiler specific language extensions. if you are accessing native libraries (non .NET ) it is painful but can be done ( i wont go into it here)


on the .NET side

I suggest that you declare all entry points to your dll as 'assembly_interface' see the help files for details and set the linker to be assembly only. This makes the fortran dll look more like any other standard .net dll ie all subroutines are private unless declared otherwise.

obvously compile to the target .net ie select this option in visual studio.

here is a simple little dll I wrote as an example


module datastore
! this is an array to store an array of global data

real*8,allocatable :: A(:,Smile
real tik,tok

end module

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

subroutine fill(B)
use datastore
assembly_interface(name="InitialiseLogitModel")
! allocates the array A and then sets the first column equal to input array B
!prepare memory and then fill array
real*8 B(Smile

call cpu_time (tik)

if (allocated (A)) then
deallocate(A)
end if

allocate(A(size(B),2))


A(:,1) = B
A(:,2) = 0.0


end subroutine

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

subroutine endlogit(B)
use datastore
assembly_interface(name="FinaliseLogitModel")
real*8 B(Smile
!return answer and then destroy global array
B(Smile = A(:,2)
deallocate (A)
call cpu_time(tok)

write (*,*) "All Fortran Finished in ",tok-tik,"seconds"

end subroutine

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

subroutine logitmodel(lambda)
use datastore
assembly_interface(name="RunLogitModel")
real*8 lambda


! do some calculations

! do a logit calculation for the entire array
A(:,2) = EXP(-lambda*A(:,1))/SUM(EXP(-lambda*A(:,1)))




end subroutine

! end of fortran


I can now call this dll like any other static .NET class

I initialise the class be using the InitialiseLogitModel() method

I do some calcs using the RunLogitModel() method

the tidy up by using the FinaliseLogitModel() method

All I have to do is include my fortran dll into a C# project (or C++ or VB or what ever ) my method I have exposed become visible and as far as C# is concerned I just have a static class

I hope that helps but if you need some more guidance... after you have read the documentation, I am sure someone will help.



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


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

PostPosted: Thu Oct 12, 2006 12:49 am    Post subject: Fortran to .net Reply with quote

Basically you need to create a Visual Studio "Project" within a "Solution". This project should be an "FTN95 application extension" for .NET. Put all of your DLL sobprograms in here. Use ASSEMBLY_INTERFACE as recommended above.

Then create another project (perhaps C# or Visual Basic .NET or FTN95 Visual ClearWin) as a .NET frontend. In this project, create a "Reference" to your FTN95 DLL.
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