f2c (+gcc)
The f2c program comes standard with all GNU/Linux distributions with
which I am familiar. The home site of f2c is at
AT&T's netlib software
repository.
f2c converts standard Fortran-77 code to
standard C code. On GNU/linux, this is further compiled into assembly
by gcc. Three immediate advantages of f2c are:
- it is free,
- it is extremely well-debugged,
- and it produces pretty fast code when coupled with gcc.
A further advantage, if you are a nuclear or
particle physicist, is that
- it has been used to compile all of the CERN libraries,
so using it you can get your favorite GEANT code or data
analyzer running.
Disadvantages of f2c+gcc are that
- it really accepts standard Fortran-77 code,
and little else. Most Fortran programs out there in the
physics world (in my experience) use many extensions, so
you might have to do some editing. Trivial examples I've
seen are the "q" format specifier, and the TYPE * statement
which are both VAXisms. These two are fairly easy to fix.
A nontrivial example is the STRUCTURE
data type. If your code makes heavy use of it, you're looking
at a serious rewrite if you want to use f2c+gcc.
Look at Wolfgang Wander's
f77 Problem Page
for more information
about this.
Debugging f2c+gcc-compiled code --- There are two ways to do
this:
-
Use
f77/reorder. This allows your code to be debugged
under gdb.
- Install the f2c_stabs package (available from standard
linux software archives.) This package only runs under
the Emacs editor.
Getting correct results ---
schuetze@math.tu-dresden.de (T.Schuetze) pointed out that if one turns on
optimization, the "paranoia" suite fails.
This can be cured by passing the option -ffloat-store to the
gcc phase of the compilation.
If you use fort77 as a compiler driver, you can simply specify
the option as printed above; some other compiler drivers
may require you to
pass it to gcc using some special option prefix.
-ffloat-store forces all real variables to have their stated (either
real*4 or real*8) precision.
If you don't specify it, certain variables which only live in registers
may have the precision of the Intel FP registers, which is different
than real*4 or real*8.
Jeff Templon
Last modified: Wed Apr 11 14:54:45 EDT 2001