Dear all,
I have Visual Studio 2005 and use the FTN95 Personal Edition at the moment (how do I find the version number?). I have the Fortran code compiled into a DLL which I refrence in my calling code. I can see the Fortran function fine.
My task is to test whether I can do calculations using Fortran legacy code in a .NET v2 application.
The problem I encounter is that when I pass to my Fortran code two same size .NET arrays of floats and add the individual array items together to return a new array, I get quite some garbage.
This code generates the arrays in C#.NET:
const int arraysize = 10;
float[] a = new float[arraysize];
float[] b = new float[arraysize];
for (int i = 0; i < arraysize; i++)
{
a[i] = System.Convert.ToSingle(i.ToString());
b[i] = System.Convert.ToSingle('0.' + i.ToString());
}
a[0] = -1000F;
b[arraysize - 1] = -1000F;
float[] c = new float[arraysize];
for (int i = 0; i < c.Length; i++)
{
if (a[i] == -1000F || b[i] == -1000F)
{
c[i] =-1000F;
}
else
{
c[i] = a[i] + b[i];
}
}
float[] d = FortranFunctions.Add(a, b);
The two arrays to add together are: a: -1000 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 b: 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 -1000
The task is that if the value is -1000, assign it, otherwise add the items of the arrays together.
The result expected is array c: -1000 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 -1000
I pass arrays a and b to the following Fortran code:
REAL FUNCTION DIRECTCALL_ADD(A,B) RESULT(C)
ASSEMBLY_INTERFACE(NAME='Add')
REAL A(0:)
REAL B(0:)
REAL C(0:9)
D=-1000.00
DO i=0,9
IF (A(i).EQ.D .OR. B(i).EQ.D) THEN
C(i)=D
ELSE
C(i)=A(i)+B(i)
ENDIF
END DO
END FUNCTION
Apart from the result array being fixed size at the moment and the compiler moaning about my checking on the value -1000, the problem is more fundamental. The Fortran result array d: -1000 1 2.1 3.2 4.3 5.4 6.5 7.6 8.7 9.8 When I debug and step through the Fortran code, I can see the Fortran array A and its members, but I cannot access Fortran arrays B or C. Hovering over B gives 'B, REAL*4 (Invalid)'. Hovering over C gives 'unknown variable'.
I have these options set in the Fortran project (others installation default): Configuration Properties Compiler Options Miscelleaneous -Debug Target: somelocation\Modules.Calculations.Fortran.dll -Output Filename: somelocation\Modules.Calculations.Fortran.dll Linker Options Linker Options -Class name: Modules.Calculcations.Fortran.FortranFunctions -Interface only: yes
So, my question is: what is going wrong?
Regards, Alex
