|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
razzel
Joined: 11 Oct 2006 Posts: 1
|
Posted: Wed Oct 11, 2006 10:10 am Post subject: Fortran to .net |
|
|
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 |
|
|
DrTip
Joined: 01 Aug 2006 Posts: 74 Location: Manchester
|
Posted: Wed Oct 11, 2006 3:22 pm Post subject: Fortran to .net |
|
|
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(:,
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(
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(
!return answer and then destroy global array
B( = 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 |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7928 Location: Salford, UK
|
Posted: Thu Oct 12, 2006 12:49 am Post subject: Fortran to .net |
|
|
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 |
|
|
|
|
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
|