FORTRAN interface
Describes coding conventions of the C API to support interface with a FORTRAN application.
The Callable Library can be interfaced with FORTRAN applications. Although they are no longer distributed with the product, you can download examples of a FORTRAN application from the technotes of the product support web site. At the portal of your product, search for CPLEX and FORTRAN to locate relevant technotes, such as "Calling CPLEX from FORTRAN" or "Calling CPLEX C API from Fortran using Open Watcom"
Those examples were compiled with CPLEX versions 7.0 and earlier on a particular platform. Since C-to-FORTRAN interfaces vary across platforms (operating system, hardware, compilers, etc.), you may need to modify the examples for your own system.
Whether you need intermediate routines for the interface depends on your operating system. As a first step in building such an interface, it is a good idea to study your system documentation about C-to-FORTRAN interfaces. In that context, this section lists a few considerations particular to CPLEX in building a FORTRAN interface.
Case-sensitivity
As you know, FORTRAN is a case-insensitive language,
whereas routines in the Callable Library have names with mixed case.
Most FORTRAN compilers have an option, such as the option -U
on UNIX systems, that treats symbols in a case-sensitive way. It is
a good idea to use this option in any file that calls Callable Library
routines.
On some operating systems, certain intrinsic FORTRAN functions must be in all upper case (that is, capital letters) for the compiler to accept those functions.
Underscore
On some systems, all FORTRAN external symbols are created with an underscore character (that is, _) added to the end of the symbol name. Some systems have an option to turn off this feature. If you are able to turn off those postpended underscores, you may not need other “glue” routines.
Six-character identifiers
FORTRAN 77 allows identifiers that are unique only up to six characters. However, in practice, most FORTRAN compilers allow you to exceed this limit. Since routines in the Callable Library have names greater than six characters, you need to verify whether your FORTRAN compiler enforces this limit or allows longer identifiers.
Call by reference
By default, FORTRAN passes arguments by reference; that
is, the address of
a variable is passed to a routine, not its value. In contrast, many
routines of the Callable Library require arguments passed by value.
To accommodate those routines, most FORTRAN compilers have the VMS
FORTRAN extension %VAL() . This operator
used in calls to external functions or subroutines causes its argument
to be passed by value (rather than by the default FORTRAN convention
of passed by reference). For example, with that extension, you can
call the routine CPXprimopt with this
FORTRAN statement:
status = CPXprimopt (%val(env), %val(lp))
Pointers
Certain CPLEX routines return a pointer to memory. In FORTRAN 77, such a pointer cannot be
de-referenced; however, you can store its value in an appropriate integer type, and you can then
pass it to other CPLEX routines. On 64-bit operating systems, a variable of type
INTEGER*8 may be needed. Consult your system documentation to learn the appropriate
integer type to hold variables that are C pointers.
Strings
When you pass strings to routines of the Callable Library,
they expect C strings; that is, strings terminated by an ASCII NULL character,
denoted \0 in C. Consequently, when you
pass a FORTRAN string, you must add a terminating NULL character;
you do so by means of the FORTRAN intrinsic function CHAR(0) .