Silverfrost Forums

Welcome to our forums

Problem Passing Attributes from C# to Compiled FORTRAN Sub

2 Sep 2011 4:54 #8897

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*'

2 Sep 2011 6:02 #8900

To start with you should read from ftn95.chm under

.NET platform->.NET Prograamming →Calling Fortran from other .NET languages

2 Sep 2011 6:19 #8903

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 number100 will be returned in ierr c hfiles--array of file names specifying fluid/mixture components c [character255 variable] c hfmix--mixture coefficients [character255] c hrf--reference state for thermodynamic calculations [character3]

2 Sep 2011 4:42 #8906

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.

2 Sep 2011 8:13 #8908

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'

3 Sep 2011 5:25 #8909

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.

5 Sep 2011 1:38 #8911

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:

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

Please login to reply.