MapleSim / Modelica FORTRAN DLL Calling Convention
The Modelica modeling language supports calls from external FORTRAN libraries, however MapleSim includes support for calling functions from the C DLL, although it says it has full Modelica support and I have no choice but to use this FORTRAN DLL (I cannot reprogram its in C and I can't use other Modelica environments besides MapleSim), so I'm not in the area of โโundocumented features.
I tried to get MapleSim to include the FORTRAN DLL and create a custom component, but it doesn't work. This is the code I got when I opened the custom component: [relevant part only]
model ExternalCode
function GETPSAT
input Real TC;
output Real PC;
external "C" PC = GETPSAT(TC)
annotation (
Library = "C:/Path/To/My/DLL/FORTRAN.dll", __Maplesoft_callconv = "stdcall");
end GETPSAT;
equation
(PC) = GETPSAT(TC);
annotation (
experiment(__Maplesoft_engine = 2));
end ExternalCode;
I know what I should change external "C"
to external "FORTRAN"
, but what should I do with __Maplesoft_callconv = "stdcall"
? ie: what is the calling convention for FORTRAN functions? (I don't know anything about calling conventions).
Note that the parent framework MapleSim 6.1 (Maple 17) supports importing external functions from FORTRAN, so I think MapleSim will support it even though it is undocumented.
edit: By the way, the DLL was compiled with Compaq visual fortran (I don't remember the version)
edit2: The function in the FORTRAN library is exported as follows:
FUNCTION GETPSAT(TC)
!DEC$ ATTRIBUTES ALIAS:'GETPSAT' :: GETPSAT
!DEC$ ATTRIBUTES DLLEXPORT :: GETPSAT
!DEC$ ATTRIBUTES VALUE :: TC
GETPSAT=PSAT11(TC)
RETURN
END
edit3: I don't know if this helps, but the same function can be called from C # like this:
[DllImport("C:\\Path\\To\\My\\DLL\\FORTRAN.dll")]
static extern float GETPSAT(float T);
source to share
This particular Fortran function is supposed to behave like a completely normal C function because of the attributes it has. Don't add external(FORTRAN)
or the like. Its name must be GETPSAT
and it takes 1 float TC
by value.
Use same attribute "stdcal"
as default for DEC, Compaq and Intel Fortran https://software.intel.com/sites/products/documentation/hpc/mkl/mkl_userguide_win/GUID-E74229B0-7389-46A6-9FCF-91CD6CD5B0E4.htm
source to share