Calling Fortran intrinsic functions from Visual Basic


There is a great way to call the Fortran intrinsic libraries from Visual Basic, without wrapping them to dynamic libraries. I have the Digital Fortran installed on my computer, so I found out one of the running DLLs which is the dforrt.dll and that contains the Fortran intrinsic libraries (which are used by the Digital compiler).
I simply opened the DLL with the Depends program and I found out the name of the functions that are declared in the DLL file. Knowing that the tangent function is declared as DTAN in Fortran, I found out some functions and declared them in a Visual Basic module file like this:

Public Declare Function DTAN# Lib "dforrt.dll" Alias "_FXDTAN" (x#)
Public Declare Function DTAN5# Lib "dforrt.dll" Alias "_FXIDTAN" (x#)

And here is a sample call:

Const PI As Double = 3.14159265358979
'the tangent of PI/4 will return 1.0
Debug.Print DTAN(PI / 4)

Of course the tangent function is an intrinsic one in Visual Basic. However, there are many functions in the Fortran DLL file and many of those do not have VB equivalents, such as the hyperbolic functions and functions that take complex numbers as arguments. It is very interesting to search for those ready-to-use functions in the Fortran libraries and use them in Visual Basic or other languages that are capable to call external API functions!

Comments

Popular posts from this blog

Write Unicode text using VBA

Dictionary class extensions (CopyTo, Sort) (C#)