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


source to share


2 answers


Thanks everyone for the suggestions

input argument must be passed by value and from arguments put ... pass by refrence so I changed the Auxilary pragma to "* $ pragma aux DON" DON "export parm (value * 8, ref, ref)" "and now it works



Thanks again

+1


source


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







All Articles