>> Rodney Roberts IS & Education Professional Homepage   >> Programming Tutorials And Downloads






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.
Free Pascal Program calling FORTRAN .dll

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.
Console Window executing Pascal test program

external 'mathproc' specifies that the procedure/subroutine is in mathproc.dll.  The Free Pascal Compiler/Linker does not require a user supplied
mathproc.libThis 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.

Resistive Ladder Network FORTRAN Subroutine

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)
Pascal program calling Resistive Ladder Network




1. Schick, William and Charles J. Mertz, Jr. (1972).  FORTRAN for Engineering.  New York: McGraw-Hill Book Company.



Any and all © copyrights, ™ trademarks, or other intellectual property (IP) mentioned here are the property of their respective owners.

Feel free to use any of the above in your project (without violating any intellectual property rights); please give credit (same idea as Copyleft).

Page best viewed with Mozilla FireFox 3.6.13 (or higher).

Web hosting provided by
Award Space Web Hosting Free Web Hosting , &  X10hosting Free Web Hosting.


>> Rodney Roberts IS & Education Professional Homepage   >> Programming Tutorials And Downloads