replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Problem Passing Attributes from C# to Compiled FORTRAN Sub
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 

Problem Passing Attributes from C# to Compiled FORTRAN Sub

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



Joined: 31 Aug 2011
Posts: 30
Location: Connecticut

PostPosted: Fri Sep 02, 2011 5:54 am    Post subject: Problem Passing Attributes from C# to Compiled FORTRAN Sub Reply with quote

I am having a very difficult time passing attributes from a Visual Studio C# function into a compile FORTRAN Subroutine. I can't seemed to figure out the attribute declarations.

Here's the main error message,

Error 4 The best overloaded method match for 'NIST_Fluid_Props.SETUP(int*, Salford.Fortran.Character*, Salford.Fortran.Character*, Salford.Fortran.Character*, int*, Salford.Fortran.Character*, int, int, int, int)' has some invalid arguments

It is telling me some invalid arguments....but not which ones.

Here are the remaining errors:

Error 5 Argument 1: cannot convert from 'int' to 'int*'
Error 7 Argument 3: cannot convert from 'string' to 'Salford.Fortran.Character*'
Error 8 Argument 4: cannot convert from 'char[]' to 'Salford.Fortran.Character*'
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Fri Sep 02, 2011 7:02 am    Post subject: Reply with quote

To start with you should read from ftn95.chm under

.NET platform->.NET Prograamming ->Calling Fortran from other .NET languages
Back to top
View user's profile Send private message AIM Address
BillJohnson



Joined: 31 Aug 2011
Posts: 30
Location: Connecticut

PostPosted: Fri Sep 02, 2011 7:19 am    Post subject: Reply with quote

Hello Paul,

Thank you for the advice. I have gone thru the help doc and can't find any specific examples for support my problem. Mainly, I am dealing with two problems right now:


Cannot convert from 'string' to 'Salford.Fortran.Character*'

and

Cannot convert from 'char' to 'Salford.Fortran.Character*'

Neither one of these is accepting a variable dimensioned as a 'string' or as a 'char'


Please advice. Or maybe you could provide a simple example. The FORTRAN sub I am trying to execute is the following: SUBROUTINE SETUP (nc,hfiles,hfmix,hrf,ierr,herr) with the attributes dimensioned as follows:

c nc--number of components (1 for pure fluid) [integer]
c if called with nc=-1, the version number*100 will be returned in ierr
c hfiles--array of file names specifying fluid/mixture components
c [character*255 variable]
c hfmix--mixture coefficients [character*255]
c hrf--reference state for thermodynamic calculations [character*3]
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Fri Sep 02, 2011 5:42 pm    Post subject: Reply with quote

My knowledge of the interaction between C# and FTN95 is a little rusty but if you can post a few lines of C# code together with the relevant Fortran then someone out there may be able to help you.
Back to top
View user's profile Send private message AIM Address
BillJohnson



Joined: 31 Aug 2011
Posts: 30
Location: Connecticut

PostPosted: Fri Sep 02, 2011 9:13 pm    Post subject: Reply with quote

Hello Paul,

Here's a snippet of the Fortran subroutine I am trying to call from Visual Studio C# below.

FORTRAN SUBROUTINE CALL - INSIDE FORTRAN:
subroutine SETUP (nc,hfiles,hfmix,hrf,ierr,herr)


FORTRAN VARIABLE DIMENSION STATEMENTS - INSIDE FORTRAN:
character*255 hfiles(ncmax),hfile(n0:nx),hfmix,hfmix2,rflnam
parameter (ncmax=20)
parameter (n0=-ncmax-nrefmx,nx=ncmax)


hfiles and hfmix is a string character specifying the location on ASCII text files to be read by the FORTRAN Subroutine.

For Example hfiles = "c:\program files\refprops\data\water.txt"
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Sat Sep 03, 2011 6:25 am    Post subject: Reply with quote

There is not enough information here. What is needed is a few lines of C# code together with a few lines of Fortran code which together would form a working program that illustrates the problem. At the moment we can only guess at what you are trying to do.
Back to top
View user's profile Send private message AIM Address
Emanuele



Joined: 21 Oct 2009
Posts: 78
Location: Bologna (Italy)

PostPosted: Mon Sep 05, 2011 2:38 pm    Post subject: Reply with quote

Dear Bill,

To pass strings, I adopted this strategy:
1) declare the argument as string;
2) declare a corresponding-length character variable;
3) convert explicitly the string into character.

For example:

Code:

subroutine mytest(hfile)
ASSEMBLY_INTERFACE(NAME="mytestname")

string, intent(in):: hfile
character(len=len(hfile))::chfile

chfile=char(hfile)

!do something

end subroutine


I can say it works, but I cannot say if it is the best way!

Good luck!

Emanuele
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 -> 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