Returning real values ββfrom fortran77 dll in c #
Can anyone point out what I am doing wrong here?
DLL FORTRAN 77
*$pragma aux DON "DON" export parm(value*8,value*8)
SUBROUTINE DON(DAA,DBB,DCC)
REAL*8, DAA,DBB,DCC
DBB=DAA+1
DCC=DBB+1
RETURN
END
C # code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace pDON
{
class Program
{
[DllImport("DON.dll",
CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern void DON(
[MarshalAs(UnmanagedType.R8)] double DAA,
[MarshalAs(UnmanagedType.R8)] double DBB,
[MarshalAs(UnmanagedType.R8)] double DCC
);
static void Main(string[] args)
{
//double TIME = 100.0;
double DAA = 5.5;
double DBB = 7;
double DCC = 9;
//START( ENERIN, VAL1);
DON(DAA, DBB, DCC);
Console.Write("val1 = " + DBB);
Console.Write("val2 = " + DCC);
Debug.WriteLine("VAR = " + DBB.ToString());
Console.Write("Press any key to exit");
Console.ReadKey(false);
}
}
}
I want to get DBB DCC values ββback to C # main prog .. after they have been processed through a FORTRAN 77 routine.
PS: I cannot use INTENT (out) as I am using fortran 77. thanks a lot in advance.
+2
Raj
source
to share
2 answers
Well, you are calling a Fortran function with parameter values. You have to use reference parameters (pointers) to get a value from it.
Alternatively, you can return strcuture from fortran code that contains your two values. You have to cast it in C # to the appropriate types and read the results from it.
But I am afraid that I have no idea about fortran, and if even one of my suggestions might work.
0
source to share