Silverfrost Forums

Welcome to our forums

FTN95 Application Extension error, passing Fortran array

16 Aug 2012 6:29 #10636

I get the error: 'An unhandled exception of type 'System.InvalidProgramException' occurred in Ftn95.dll' 'Additional information: Common Language Runtime detected an invalid program.'

I have a C# code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Ftn95.Sub1();
            Console.ReadLine();
        }
                
    }
}

where, in a FTN95 Application Extension, I have

subroutine Sub1 ()
    implicit none
    ASSEMBLY_INTERFACE (NAME='Sub1')
    double precision A(3,3), B(3,3)
    A = 1.d0
    call Sub2 (A,B)
    write(*,*) B
end subroutine

and

subroutine Sub2 (A,B)
    implicit none
    ASSEMBLY_INTERFACE (NAME='Sub2')
    double precision A(:,:), B(:,:)
    B = A
end subroutine

What is wrong? :?:

Config. Manager: Debug CSharp: x86 Ftn95: .NET

16 Aug 2012 10:23 #10638

I can't comment on your interface between Fortran and C, but you need a fortran definition to define the interface between Sub1 and Sub2, as below: subroutine Sub1 () implicit none ASSEMBLY_INTERFACE (NAME='Sub1') double precision A(3,3), B(3,3)

   interface
     subroutine Sub2 (A,B) 
      double precision A(:,:), B(:,:) 
     end subroutine Sub2
   end interface 

    A = 1.d0 
    call Sub2 (A,B) 
    write(*,*) B 
end subroutine 
 
subroutine Sub2 (A,B) 
    implicit none 
    double precision A(:,:), B(:,:) 
    B = A 
end subroutine 

John

18 Aug 2012 10:48 #10649

Yes, of course, and thank you. Sorry for the silly question. I have been working with Intel Interoperative Systems, which I guess does the interfaces in the background for me.

I have many Fortran routines that call each other. I added ASSEMBLY_INTERFACE to some of them to be able to call them from C#. For this, I already changed the old fixed arrays, say A(3,3), for assumed size A(:,: ) if they appeared as dummy arguments. Now I have to go back and add the interfaces manually for any internal arrays (that are not dummy arguments), if they appear in a call to another routine to which I added ASSEMBLY_INTERFACE.

Does anyone know of any utility that would add the interfaces automatically?

Is there any way to set the Fortran95 compiler to treat all arrays as dynamic, thus avoiding having to write an Interface EVERY time one needs to use a Function or Subroutine?

Please login to reply.