There is Fortran code from Stark, P.B., and R.L. Parker I build it on Visual Studio 2010 uing Fortran Compiler (Compóser XE 2011)

Original code is Fortran

subroutine bvls(key, m, n, a, b, bl, bu, x, w, act, zz, istate, loopA) implicit double precision (a-h, o-z) !DEC$ ATTRIBUTES DLLEXPORT :: bvls dimension a(m,n), b(m), x(n), bl(n), bu(n) ! dimension w(n), act(m,min(m,n)+2), zz(m), istate(n+1) dimension w(n), act(m,m+2), zz(m), istate(n+1)

C# code (I am not sure about [In,Out] and ref variables)

[DllImport("bvlsF.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] static extern void bvls( int key, //key = 0, the subroutine solves the problem from scratch. If key > 0 the routine initializes using the user's guess about which components of x are `active' int m, int n, double[] a, // m by n matrix double[] b, // m-vector double[] bl, //n-vector of lower bounds on the components of x. double[] bu, //n-vector of upper bounds on the components of x. [In, Out] double[] x, //unknown n-vector //Working arrays: [In, Out] double[] w, //dimension n double[] act, //dimension m*(mm+2). mm=min(m,n). double[] zz, //dimension m [In, Out] int[] istate, //dimension n+1. ref int loopA // number of iterations taken in the main loop, Loop A. );

To test dll I do:

static void BVTEST() { int key = 0, n = 2, m = 3; double[] a = { 19.0, 27.0, 33.0, 42.0, 51.0 }; double[] b = { 12.0, 27.0, 30.0 }; double[] bl = { 0.1, 0.2 }; double[] bu = { 0.9, 0.9 }; double[] x = new double[n]; double[] w = new double[n]; double[] act = new double[m * (Math.Min(m, n) + 2)]; double[] zz = new double[m]; int[] istate = new int[n + 1]; int loopA = 0; bvls(key, m, n, a, b, bl, bu, x, w, act, zz, istate, ref loopA); for (int i = 0; i < x.Length; i++) Console.WriteLine(" " + x[i]); Console.WriteLine(loopA); }

However I get:

System.EntryPointNotFoundException: Can not find entrypoint 'bvls' on file 'bvlsF.dll'.

on bvlsCs.Program.bvls(Int32 key, Int32 m, Int32 n, Double[] a, Double[] b, D

ouble[] bl, Double[] bu, Double[] x, Double[] w, Double[] act, Double[] zz, Int3

2[] istate, Int32& loopA)

I do not understand why is happening, so I tested with sample code I found on forum and it works:

fortran

subroutine Arr_Sub (var,row,col) !DEC$ ATTRIBUTES DLLEXPORT :: Arr_Sub integer :: row,col real var(col,row) integer :: i, j write(*,*) "Array var received from C# as array is" write(*,*) var ! do something to change the value of var end subroutine

c#

[DllImport("bvlsF.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] public static extern void ARR_SUB([In,Out] float[,] fArr, ref int row, ref int col);

and

float[,] fArr = new float[3, 4] { { 1, 23, 3, 4 }, { 1, 3, 20, 5 }, { 1, 23, 3, 6 } }; int row = 3; int col = 4; ARR_SUB(fArr, ref row, ref col);

Could you please help me execute that fortran code in c#?, I attach visual studio with fortran code...