I suggest you start with a little test code. Compile the FORTRAN.dll file with some routines with simple parameters and play with C # to make the call work. You can also wrap Fortran with many arguments in one structure (the TYPE keyword), which will greatly simplify the interaction.
Here is a working example that you can use to get a lot of ideas on how it works.
Original FORTRAN Code:
SUBROUTINE CALC2(BLKL,BLKW, N_LAMINA,N_SLICE, LOAD, SLOP,SKW, & DIA1,DIA2, Y1, Y2, N1, N2, DROP1, DROP2, & PARRAY, P_MAX, P_MAX_INDEX, ENDEFCT) !DEC$ ATTRIBUTES DLLEXPORT :: CALC2 !DEC$ ATTRIBUTES ALIAS:'CALC2' :: CALC2 !DEC$ ATTRIBUTES VALUE :: BLKL, BLKW, N_LAMINA, N_SLICE, LOAD, SLOP, SKW !DEC$ ATTRIBUTES VALUE :: DIA1, DIA2, Y1, Y2, N1, N2 IMPLICIT NONE INTEGER*4, INTENT(IN) ::N_LAMINA, N_SLICE REAL*4, INTENT(IN) :: BLKL, BLKW, LOAD, SLOP, SKW, & DIA1, DIA2, Y1, Y2, N1, N2, & DROP1(MAX_LAMINA), DROP2(MAX_LAMINA) REAL*4, INTENT(OUT):: PARRAY(MAX_PATCH), P_MAX INTEGER*4, INTENT(OUT) :: P_MAX_INDEX, ENDEFCT INTEGER*4 :: NDIAG, N_PATCH REAL*4 :: SLNG, SWID REAL*4 :: DROPS_1(MAX_LAMINA), DROPS_2(MAX_LAMINA) ... END SUBROUTINE CALC2
with different scalar and array values โโin real and integer form. For example, DROP1 introduces a 1D array. PARRAY outputs a 2D array as a 1D array. BLKL - input floats.
Pay attention to the decoration !DEC$ ATTRIBUTES VALUE , so as not to declare everything as a ref .
In C #, the code is called
[DllImport("mathlib.dll")] static extern void CALC2(float major_dim, float minor_dim, int N_lamina, int N_slices, float total_load, float slope, float skew, float diameter_1, float diameter_2, float youngs_1, float youngs_2, float nu_1, float nu_2, float[] drops_1, float[] drops_2, float[] pressures, ref float p_max, ref int p_max_index, ref EndEffect end_effect); ... { float max_pressure = 0; int max_pressure_index = 0; float[] pressures = new float[Definition.MAX_PATCH]; EndEffect end_effect = EndEffect.NO; CALC2(length, width, lamina_count, slice_count, load, slope, skew, dia_1, dia_2, y_1, y_2, n_1, n_2, drops_1, drops_2, pressures, ref max_pressure, ref max_pressure_index, ref end_effect); }
note I do not pass a single line.