> Languages and APIs > The ILOG CPLEX Callable Library > ILOG CPLEX Programming Practices > FORTRAN Interface |
FORTRAN Interface |
INDEX PREVIOUS NEXT |
The Callable Library can be interfaced with FORTRAN applications. Although they are no longer distributed with the prodcut, you can download examples of a FORTRAN application from the ILOG web site. Direct your browser to this FTP site:
ftp://ftp.cplex.com/pub/examples
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 ILOG CPLEX in building a FORTRAN interface.
As you know, FORTRAN is a case-insensitive language, whereas routines in the ILOG CPLEX 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 ILOG CPLEX 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.
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.
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.
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)) |
Certain ILOG CPLEX routines return a pointer to memory. In FORTRAN 77, such a pointer cannot be dereferenced; however, you can store its value in an appropriate integer type, and you can then pass it to other ILOG CPLEX routines. On most operating systems, the default integer type of four bytes is sufficient to hold pointer variables. On some systems, a variable of type INTEGER*8
may be needed. Consult your system documentation to determine the appropriate integer type to hold variables that are C pointers.
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)
.
Copyright © 1987-2003 ILOG, S.A. All rights reserved. Legal terms. | PREVIOUS NEXT |