replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - How to pass a large amount of data from Fortran to C#?
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 

How to pass a large amount of data from Fortran to C#?

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



Joined: 14 May 2009
Posts: 29

PostPosted: Fri May 15, 2009 5:57 pm    Post subject: How to pass a large amount of data from Fortran to C#? Reply with quote

I have a c# application that calls a legacy Fortran dll. Once the C# application calls the Fortran dll, the Fortran dll spits out some binary files. There has been a request to see if Fortran could pass the contents of the files directly to C#. Rather than having C# read the files.

Maybe in one of the following ways?

1. Could this be done by passing a Fortran object to C#?

2. Could this be done by creating a Fortran module with a bunch of variables populated, then have c# access those variables directly to create its own C# object?

3. Pass some file stream from Fortran to C#? Again, rather than creating the files, somehow pass the data to C#?

Are any of these possible or maybe something better to do?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Sat May 16, 2009 7:00 am    Post subject: Reply with quote

First of all you will need to use the same Fortran compiler to read the binary as that was used to create it. Also you will need the code in order to replicate it in the read instructions. If it was FTN95 then...

Look up what the help file has to say about accessing Fortran arrays from C#. Start in .NET platform->Calling Fortran from other .NET languages.
Back to top
View user's profile Send private message AIM Address
Andrew



Joined: 09 Sep 2004
Posts: 232
Location: Frankfurt, Germany

PostPosted: Sat May 16, 2009 9:17 am    Post subject: Reply with quote

You can pass .NET objects around, from C# to Fortran and from Fortran to C#. Objects can be created in the Fortran, populated and passed to C# or vice versa, however you want. Delegates should be avoided however. The most appropriate solution would depend on what exactly you want to achieve and the amount of data you want to pass around.

Topics that will be of interest in the help file are the .NET extensions such as:

- new@
- assembly_interface
- assembly_external

You also free to use streams if you like. After all they are .NET objects too and can be passed around in same way. If you wanted to create a stream, write to it and then pass the stream on then that would also be possible.
Back to top
View user's profile Send private message
silverdan



Joined: 14 May 2009
Posts: 29

PostPosted: Mon May 18, 2009 2:33 pm    Post subject: Reply with quote

Andrew,
Thanks for your reply. Can you point me to a sample of how to pass a stream from FTN95 to .NET?

I know how to use OPEN in Fortran and WRITE to a file. I also know how to use StreamReader in C#. However, how can I open a file and a stream in FTN95 in one Class and then read that stream in a C# Class?

--Dan
Back to top
View user's profile Send private message
Andrew



Joined: 09 Sep 2004
Posts: 232
Location: Frankfurt, Germany

PostPosted: Mon May 18, 2009 2:52 pm    Post subject: Reply with quote

You can do this with use of the ASSEMBLY_EXTERNAL and OBJECT extensions pointed at earlier in the thread. But, and example of passing a StreamReader could be...

Code:
PROGRAM TestStream

OBJECT("System.IO.StreamReader") StreamReader
ASSEMBLY_EXTERNAL("System.IO.File.OpenText") FileOpen
ASSEMBLY_EXTERNAL("System.IO.StreamReader.Close") StreamReaderClose

OBJECT("ClassLibrary1.Class1") CSharpClass
ASSEMBLY_EXTERNAL("ClassLibrary1.Class1.ReadStream") ReadStream

CSharpClass = new@("ClassLibrary1.Class1")
! Dont need to pass the object as its a static method
StreamReader = FileOpen("c:\Documents and Settings\andy\Desktop\text.txt")
! Pass the object as its an instance method
CALL ReadStream(CSharpClass, StreamReader)

CALL StreamReaderClose(StreamReader)

PAUSE

END


With C# code something like:

Code:
namespace ClassLibrary1
{
    public class Class1
    {
        public void ReadStream(StreamReader streamReader)
        {
            string s = "";
            while ((s = streamReader.ReadLine()) != null)
            {
                Console.WriteLine(s);
            }

        }
    }
}


The stream could be closed in the C# of course, I just put the example into the Fortan to show how it could be done there.

This example could be extrapolated for other .NET types you may need.
Back to top
View user's profile Send private message
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