Science makes it known,
Engineering makes it work,
Art makes it beautiful.
|
|
Mixed Language Programming (C++, COBOL, D, FORTRAN, Lazarus, Pascal, XBLite);
COBOL, D, FORTRAN, Lazarus, and Pascal Tutorials;
COBOL, D, FORTRAN, Lazarus, Pascal, and Basic Downloads1
(This page presumes the user is an experienced programmer, knowledgeable with
multiple programming languages and operating systems. It also requires familiarity
with unzipping programs, installing software, and directory structures. Experience
with multiple platforms would be helpful as well.)
Each programming language has its own strengths and
weaknesses. And there are the occasions
when you have an external application (for example, a licensed library
whose source code is unavailable), complete with API's,
and you need to interface it with another application written
in a different programming language. These
two situations (combining strengths of multiple programming
languages; interfacing with a third party application) are two
common reasons for one software system to be written in several
programming languages.
The COBOL tutorials and downloads on this page have been developed using and/or
for the
(previously) free
Fujitsu
COBOL 3.0/PowerCOBOL 3.0 student compilers executing on a
Win32 system. When the
Fujitsu American distribution was assumed by
Alchemy Solutions
the free student compilers were no longer available.2
Hopefully, the COBOL
tutorials will still
be useful. COBOL 3.0/PowerCOBOL 3.0 does
have one drawback - it does not recognize spaces in
long file names.3
The D 4, FORTRAN, Object Pascal, Lazarus (Delphi compatible), and
XBLite development tools (XBLite,
Lazarus,
Free Pascal,
Silverfrost FTN95,
and
Digital Mars D Compiler)
used for these tutorials are still freely available
(Silverfrost FTN95 free for
non-commercial and non-research use). The USPS
Address Matching System Application Programming Interface
user guide is available, along with licensing information. The unmodified
Numerical Recipes FORTRAN Statistical Descriptions of Data
and Simulated Annealing subprograms are available for purchase at the
Older Numerical Recipes book editions
site. A student version of
Numerical Recipes In 'C': The Art Of Scientific Computing, Second Edition, © 1988-1992
is available from
PennState.
In these tutorials, two FORTRAN backends are used -
sttstcs.for
and
mathproc.for.
Object Pascal is used for both frontends and backends. COBOL and
Lazarus are used for frontends. D is used for both.
Inter-Program Mixed-Language calling considerations:
-
Variable Storage Compatibility and Equivalence
(Character vs Integer vs Short vs Float vs Complex;
variable's Word Size) - elements of Inter-Program
Communications;
character data and complex variables can be special cases
-
Array Compatibility
(A special case of
Variable Storage Compatibility and Equivalence
above) - indexing, dimensioning, row major or column major. See also
IC-POINT-ARRAY and IC-POINT-ARRAY-REDEF in
COBOL Files - COBOL 3.0, PowerCOBOL 3.0, Silverfrost FTN95, and Numerical Recipes
and
Pascal Arrays.
-
Case Sensitivity (may affect compiler options)
C, C++, D, and XBLite (XBasic Lite) are case sensitive; COBOL, FORTRAN, and Pascal are
case
insensitive - variable/subprogram name lower case letters may be
automatically converted to upper case; D's
extern (Pascal) {...}
can affect case sensitivity
-
Variables passed By Reference (basically, variable's address passed; address
unmodifiable), By Value (subprogram uses a local copy), or By Pointer
(variable's address passed; address modifiable). XBLite is an
example of a language that can pass parameters by all three methods. C
uses By Value and By Pointer; Pascal and Lazarus By Value and By
Reference; FORTRAN defaults to By Reference.
-
Calling Model (Standard Call vs cdecl; other calling mechanisms include
register, interrupt, pascal, safecall, and oldfpccall)
-
The order the passed arguments are Pushed/Popped to/from the stack
(sometimes called passed left-to-right or
right-to-left). This
is one of several considerations in both
D calling FORTRAN
and D calling Pascal.
-
Function/Procedure/Subroutine name mangling
- some programming languages/compilers will mangle a subprogram's name
internally (.lib file and .dll file), though any source code written for
that programming language/compiler can refer to the unmangled name. For
example, the DMD D compiler will mangle procedure name hEditInitMsg(...)
to D6hedtio12hEditInitMsgFNbPvZv (...). Use
Dependency Walker to
determine a procedure's mangled name (if any).
-
Import Libraries - some compilers require an import library (*.lib) while others
do not. Two incompatible formats are used - COFF and Intel 32 bit
OMF. Fujitsu
COBOL (and XBLite via GoAsm & Linker) generates and requires Microsoft 32
bit Linker compatible COFF import libraries, Silverfrost FTN95 SLINK
can generate Microsoft 32 bit Linker compatible COFF import libraries. Digital
Mars D compiler generates and requires
Intel 32 bit OMF import libraries (fortunately, they supply a free utility,
implib, to generate an OMF import library from a *.dll). Free
Pascal and Lazarus do not require import libraries.
Tutorials
COBOL Program Structure and Elements:
Structure, keywords, data definition, and executable statements of a COBOL
program.
FORTRAN Program Structure and Elements:
Layout, keywords, specification statements, and executable statements of a
FORTRAN program.5
Pascal Program Structure and Elements:
Covers Pascal Main Programs, Pascal Units, Lazarus Object Pascal Units, and
Object Pascal Libraries.5
Appending Text to Windows Edit Control:
done on the Windows API level, written in Object Pascal; should be
able to port the Win32 API calls to other programming languages.
Includes downloads of Object Pascal Library source files, compiling
instructions, code snippets of showing how to use.
Using Lazarus Tab Sheets (TPageControl & TTabSheet):
Uses a real world example of calculating Coefficients of Normal Force and
Centers of Pressure for a multi-stage rocket to demonstrate
Tab Controls.
These tutorials and downloads are strictly for the Win32 platform
(Win98, WinXP, Win7).
These tutorials detail D procedures/programs calling FORTRAN
functions/subprograms/subroutines, D procedures/programs calling
Object Pascal functions/procedures,
Object Pascal programs/procedures calling D functions/procedures,
Object Pascal programs/procedures calling FORTRAN
functions/subroutines,
and COBOL programs calling functions/procedures/subroutines
written in
C++ and FORTRAN. Compiler options, linking
details, data passing, and data compatibility issues will be examined.
COBOL calling FORTRAN .dll:
Interfacing COBOL with a
Silverfrost FTN95
FORTRAN .dll (This example
demonstrates combining computation strengths of FORTRAN with the data
input/output strengths of COBOL):
-
Overview - Combining Fujitsu COBOL 3.0, PowerCOBOL 3.0, Silverfrost FTN95, and Numerical Recipes: The Art of Scientific Computing
: Using a COBOL "wrapper" around FORTRAN subroutines to calculate
Average, Median, Standard Deviation, and Variance (Statistics Analysis).
-
COBOL Files - Combining Fujitsu COBOL 3.0, PowerCOBOL 3.0, Silverfrost FTN95, and Numerical Recipes: The Art of Scientific Computing
: The COBOL "wrapper" - source files, compiling, and linking.
Includes downloads of some COBOL source files.
-
FORTRAN File - Combining Fujitsu COBOL 3.0, PowerCOBOL 3.0, Silverfrost FTN95, and Numerical Recipes: The Art of Scientific Computing (Statistics Analysis)
: The FORTRAN backend (sttstcs.dll) - source file, compiling,
and linking. sttstcs.dll is used in multiple projects.
COBOL calling C++ .dll:
Interfacing COBOL with a
C++ .dll (This example demonstrates interfacing with a
third party application, the USPS Address Matching System
API; USPS AMS API source code unavailable, only import library and
dynamic link library available - often a common situation when using
commercial third party libraries):
-
Using Fujitsu COBOL 3.0 to call the USPS Address Matching System API (USPS AMS API)
: Describes how to call C++ functions
from a COBOL main program on the
Win32 platform. Uses the
Fujitsu COBOL 3.0 compiler and
the USPS AMS API as an example. Shows how to define the
AMS API ZIP4_PARM C++ struct as a COBOL record
(can be downloaded below). Includes
compiling and linking options.
-
Combining Fujitsu COBOL 3.0, PowerCOBOL 3.0, and the USPS Address Matching System API
: Describes
one solution to interfacing a Fujitsu PowerCOBOL 3.0 GUI application with a
C++ library on the Win32 platform. This is
a practical application of the
Using Fujitsu COBOL 3.0 to call the USPS Address Matching System API (USPS AMS API)
tutorial above. Includes compiling and linking
options. This example demonstrates combining
COBOL's file processing strengths with a third party API.
Includes downloads of many COBOL source files.
These tutorials detail D programs calling subprograms
written in other programming languages
(FORTRAN, Pascal, and XBLite). Compiler options, linking
details, data passing, and import library issues will be examined using
D command line and Windows main programs, as well as a D .dll (D .dll
modules
hedtio
and
dnrprocs
are often updated - hedtio for common Win32 API functionality,
dnrprocs for Traveling Salesman problem, root finding, plotting).
D main program calling FORTRAN .dll:
Interfacing D programming language main program with a
Silverfrost FTN95
FORTRAN .dll (This example
demonstrates combining computation strengths of FORTRAN with the
general purpose systems and applications programming language D):
-
D Programming Language, Silverfrost Fortran 95, and Numerical Recipes
:
Describes how to call FORTRAN subprograms using a simple command line
Digital Mars D main program. Differences between D, Pascal, and FORTRAN
arrays and matrices, using D extern statements, and passing parameters.
-
D Windows program, Silverfrost Fortran 95, and Numerical Recipes
:
Describes how to call FORTRAN subprograms in a Windows program written in
D. Includes downloads of the D source files.
-
FORTRAN File - Combining Digital Mars D main program, Silverfrost FTN95, and Numerical Recipes: The Art of Scientific Computing (Statistics Analysis)
: The FORTRAN backend - source file, compiling, and linking. This
is the same FORTRAN sttstcs.dll used in COBOL calling FORTRAN .dll.
D .dll calling FORTRAN .dll:
Using a D .dll to call subprograms in a FORTRAN .dll is somewhat more
complex. This example also examines constructing a D .dll as well as a
D interface file. Using Simulated Annealing from
Numerical Recipes: The Art of Scientific Computing, it also
demonstrates how to do an application staged migration from one
programming language to another:
-
D .dll, Silverfrost Fortran 95, and Numerical Recipes
: Some pointers of writing D .dll's, D interface files, and calling
FORTRAN subprograms from a D .dll. Compiling and linking the D .dll.
Includes downloads of the D source files.
-
FORTRAN FILE - D .dll, Silverfrost Fortran 95, and Numerical Recipes (Simulated Annealing)
: mathproc.dll - the FORTRAN backend - source file, compiling,
and linking. mathproc.dll contains engineering, mathematic,
and scientific subprograms, used in several projects.
D main program calling Object Pascal .dll:
Interfacing D programming language main program with a
Free Pascal Pascal .dll.
This is somewhat easier than D calling FORTRAN:
-
D Programming Language, Free Pascal, and Financial Functions :
Describes how to call Pascal functions and procedures using a simple command
line
Digital Mars D main program. D extern statements, data type equivalency,
passing parameters By Reference or By Value, cdecl, and stdcall.
-
Pascal File - D Programming Language, Free Pascal, and Financial Functions :
Sample Pascal backend - source file, compiling, linking, side effects of
D's extern (Pascal) {...}, and import library creation.
Includes downloads of source file and .bat file to compile source file.
D .dll calling Object Pascal .dll:
Demonstrates several concepts - command line parameter parsing;
software reuse; D .dll calling Object
Pascal .dll;
Object Pascal .dll uses user-written secondary
Lazarus
unit:
D calling XBasic Lite :
Covers using D's extern (C) {...}, XBLite's CFUNCTION,
limitations of passing parameters to XBLite, compiling, and linking
(implib /system switch):
-
D main program calling XBLite Library :
D command console program calling XBLite elliptical functions; brief
introduction/demonstration of hypergeometric functions. Includes download
of XBasic source file, listing of D program.
Tutorials demonstrating Object Pascal and
Lazarus
employing FORTRAN's mathematical capabilities. Free Pascal programs do
not crash (unlike D) calling FORTRAN subprograms that use
eX functions [EXP(), SINH(), etc.]. However, Pascal
does not support complex variables. Overall, Pascal should be better
able than D of making use of extensive FORTRAN engineering and scientific
libraries. These pages are often updated - primarily downloadable
source code enhancements, corrections, and improved explanations.
Object Pascal Programs calling FORTRAN .dll:
Using Free Pascal to
call subprograms in a FORTRAN .dll
(sttstcs.dll,
Statistics Analysis .dll used by both COBOL and D; and
mathproc.dll,
Simulated Annealing .dll used above) - the easiest for linking:
Lazarus Programs calling FORTRAN .dll:
Lazarus (Delphi compatible) calling FORTRAN subprograms via a Free
Pascal .dll.
(These examples represents combining a Rapid Application Development Tool with
a time proven .dll):
-
Lazarus, Free Pascal, Silverfrost FTN95, and Numerical Recipes: The Art of Scientific Computing
: This is basically an updated, enhanced, and more functional
implementation of
STF95COB.
Like Fujitsu PowerCOBOL 3.0, Lazarus is event driven programming and can
present data in table form. Where Fujitsu
COBOL 3.0 programs need an interface subprogram
(INVKSHT.COB and F5BBRUNS.DLL)
to use PowerCOBOL sheets, Lazarus program ST95DLPH needs an
user written Free Pascal LIBRARY
nrlazrs
procedure rMoment (...) to call the Numerical Recipes FORTRAN
subprograms. Includes downloads of Lazarus program source files,
Pascal Library, and include files.
-
FORTRAN File - Silverfrost FTN95 and Numerical Recipes: The Art of Scientific Computing (Statistics Analysis)
: The FORTRAN backend - source file, compiling, and linking.
While this is the same FORTRAN sttstcs.dll used in
COBOL calling FORTRAN .dll,
different subprograms, AVEVAR (...) and MDIAN2 (...), are called.
-
Lazarus Sub-forms, Grid Cell Background Color, StringGrid Cell Editor, and Calling FORTRAN
: Introduction to Lazarus sub-forms; changing the cell background
color in a TStringGrid; using a cbsEllipsis Editor Style
in a TStringGrid; and Lazarus calling FORTRAN via Object
Pascal .dll. Part of an actual application to input and analyze a model
rocket design. Uses Pascal missle02.dll (see above) to call
mathproc.dll FORTRAN subprograms and Pascal nrlazrs.dll (see
above) to call sttstcs.dll FORTRAN subprograms.
-
Lazarus Sub-forms, Calling FORTRAN, Software Re-use, and Aerodynamics
: Another example of Lazarus sub-forms and calling FORTRAN via Object
Pascal. Detailed example of software re-use. Part of an actual
application to input and analyze model rocket design - adding
Parallel Stages to a rocket's launch configuration. Via Object Pascal,
calls FORTRAN subroutines to
calculate parallel stage surface area and estimate impact on Coefficient of
Normal Force and Center of Pressure.
(Many of the download source files are regularly
enhanced. New versions will be uploaded as they are completed.)
Additional Downloads
USPS AMS API C struct ZIP4_PARM translated to COBOL Record layout
: As
described
in the
Using Fujitsu COBOL 3.0 to call the USPS Address Matching System API
tutorial above. Conforms to the
Address Matching System API User Guide July 2003. This
is a 01 Level record. Can be used as an include file
in the DATA DIVISION WORKING-STORAGE SECTION
or LINKAGE SECTION with the statement
INCLUDE "AMSZ4PRM.COB". Contains line sequence
numbers, which can be removed using the COBOL Line Numbering Utility
(download link below).
COBOL Line Numbering Utility
:
An extremely simple COBOL source file line number manipulation utility that
can be downloaded
and modified (includes source code, written in Visual Basic 2.0). Runs
on both Win16 and Win32 platforms (pre Win Vista) (if anyone upgrades this
to a later version of VB, please
email
to me).
Silverfrost Fortran 95 subprogram to compute Nth Root of X
:
FORTRAN function (including source code) to compute
N
√ X
.
Miscellaneous mathematical subprograms in mathproc.dll
:
FORTRAN functions and subroutines (including source code) for Point Rotation,
Triangular Segment Area, Signum (return sign of argument),
Quadratic Roots, Synthetic Division, and Cubic Polynomial Roots extracted
from mathproc.for.
1. Many of the downloadable source files are enhanced regularly. Some
may contain developmental and/or experimental code. The source files
are distributed in the hope that they will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. Depending on your O/S, some may require VMware.
2. You may be able to find the free student compiler installation file in
a web
search. The name of the install file is COBOLV3.EXE,
11,740 KB (or 11,739 KB). Any other size may contain malware.
Currently Fujitsu NetCOBOL® is distributed by
GT Software
3. Earlier versions of Lazarus also had this limitation. See
WinXP Command Prompt Path
for additional details on short file names vs. long file names. While
have not tried it in a PowerCOBOL application, it should work.
4. D was designed to be both C like and a replacement for C++. The
designers wanted to eliminate many of the backwards compatibility issues
of C++. Using 32-bit D version
2.0.066
compiler.
5. Thanks to Prof. John H. Mathews, Department of Mathematics,
California State University Fullerton for some of the material.
|