There is a code in Fortran by Robert L. Parker and Philip B. Stark:
FORTRAN
subroutine bv(key, m, n, a, b, bl, bu, x, w, act, zz, istate, loopA)
implicit double precision (a-h, o-z)
! x is an unknown n-vector
! a is a given m by n matrix
! b is a given m-vector
! bl is a given n-vector of lower bounds on the components of x.
! bu is a given n-vector of upper bounds on the components of x.
! key = 0
! ---Output parameters:
! x the solution vector.
! w(1) the minimum 2-norm || a.x-b ||.
! istate vector indicating which components of x are active
! loopA number of iterations taken in the main loop, Loop A.
! ---Working arrays:
! w dimension n. act dimension m*(mm+2). mm=min(m,n).
! zz dimension m. istate dimension n+1.
I am trying to call that function from a dll in c# like:
C#
class Program
{
[DllImport("bv.dll", CallingConvention = CallingConvention.StdCall )]
public 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.
ref double[] x, //unknown n-vector
//Working arrays:
ref double[] w, //dimension n
double[] act, //dimension m*(mm+2). mm=min(m,n).
double[] zz, //dimension m
ref double[] istate, //dimension n+1.
ref int loopA // number of iterations taken in the main loop, Loop A.
);
static void Main(string[] args)
{
double[] a = new double[3 * 3] { //M*N
1.0, 10.0, 10.0,
2.0, 18.0, 16.0,
1.8, 69.0, 16.0
};
double[] b = new double[3] { //LDB*NRHS
4.3, 6.8, 1.0,
};
double[] bl = new double[3];
double[] bu = new double[3];
double[] x = new double[3];
double[] w = new double[3];
double[] act = new double[3* 5]; //dimension m*(mm+2). mm=min(m,n).
double[] zz = new double[3];
double[] istate = new double[4];
int loopA =0;
Program.bv(0, 3, 3, a, b, bl, bu, ref x, ref w, act, zz, ref istate, ref loopA);
for (int j = 0; j < 3; j++)
Console.Write(" \t" + x[j]);
}
}
However when executing the code I get
EntryPointNotFoundException: Entry point was not found. in 'bv' on file 'bv.dll'.
myProject.Program.bv(Int32 key, Int32 m, Int32 n, Double[] a, Double[] b, Double[] bl, Double[] bu, Double[]& x, Double[]& w, Double[] act, Double[] zz, Double[]& istate, Int32& loopA)
Basically I have 2 questions, How to get this to work? and other question,is it correct the way I defined the function
[DllImport("bv.dll", CallingConvention = CallingConvention.StdCall )]
public static extern void bvls(...)
based on the routine information of fortran code?
When using dependency walker I get:
I am suspecting dll is not correct and does not have the routine, Is there a way to check if dll was generated the right way?
UPDATE
After trying ILSpy I get following which seems incorrect, could you please suggest how to gen dll file correctly?, Does ILSpy tells that bvlsFortran is the function I should use? I tried it but couldn't get it to work