Science makes it known,
Engineering makes it work,
Art makes it beautiful.
|
|
Free Pascal Calling Silverfrost FORTRAN
Free Pascal
is a 32, 64 and 16 bit compiler for multiple hardware platforms
(Intel x86, AMD64/x86-64, PowerPC, PowerPC64, SPARC) and operating
systems (DOS, Win32, Win64, Linux, FreeBSD, Mac OS X/iOS/Darwin, OS/2).
testsubs.pas
is an extremely simple command console program that calls FORTRAN
SUBROUTINE QUADROOT (...)
(solves quadratic equation)
in mathproc.dll.
It was tested in Compiler modes (Options,
Compiler, Compiler mode)
Free Pascal dialect and Delphi compatible. Compile
as 32-bit for compatibility with
Silverfrost Plato IDE
compiled mathproc.dll.
Program testsubs executes in a MS-DOS Command Prompt.
|
|
The statement
procedure QUADROOT (VAR A, B, C, ROOT1, ROOT2, DISC: single;
VAR IERR: smallint);
stdcall; external 'mathproc';
defines an external reference to the FORTRAN SUBROUTINE QUADROOT (...)
in mathproc.dll (Programmer's Guide Chapter 12).
FORTRAN converts the identifiers in its symbol table to upper case,
therefore the
procedure/subroutine names (QUADROOT) must be in upper case.
FORTRAN's default requires its parameters to be
passed by reference
(can be overridden in an all FORTRAN solution),
necessitating the VAR keywords.
Define/Pass data as smallint and single to match
FORTRAN's INTEGER*2 and REAL data types (see
Variable Storage Compatibility and Equivalency).
stdcall specifies the calling model.
|
|
external 'mathproc' specifies that the procedure/subroutine is in
mathproc.dll.
The Free Pascal Compiler/Linker does not require a user supplied
mathproc.lib. This is all that is needed to link in
mathproc.dll's SUBROUTINE QUADROOT (...) during Free Pascal
compilation and linkage to
produce an executable.
Calling a FORTRAN SUBROUTINE from Free Pascal is easier than from either
Fujitsu COBOL or DMD D.
Arrays
Consider the FORTRAN SUBROUTINE declaration (defined in mathproc.dll)
below. This subroutine takes
an array of electrical resistances, R, and calculates/returns an
equivalent resistance array for the circuit shown1, RE.
Both R and RE are dynamically dimensioned (or
dimensioned with variable bounds) for N elements. The
solution at right defines a single statically dimensioned
array TYPE resistance, defines RL (resistance array)
and re
(equivalent resistance array) as that TYPE, loads RL, and
calls RSTVLADR01 (...).
(iErr is returned error code)
|
|
1. Schick, William and Charles J. Mertz, Jr. (1972).
FORTRAN for Engineering. New York: McGraw-Hill Book
Company.
|