The f77 Problem Page

People who know me might know that I
think f77 is a problem itself, however this page is dedicated to f77reorder
the f77 filter which solves some compatibility problems of the
f2c fortran-2-c translator and other f77-extended-standard compilers.

The f2c program is a big
help for compiling fortran programs on linux. There are other compilers
available, among them g77 by the FSF (gnu).
g77 suffers however from
some serious incompatibilies which makes it unusable for standard
HEP code. But g77 is not yet completed. It needs
founding of a
small scale compared to normal HEP software costs. We did not hear
of any experiences with the NAG fortran compilers. Feel free to
submit them to me

f77 extensions handled by f77reorder

Download the latest version of f77reorder(2.28)
(A set of new functions for libf77 & a man page by
Alex Romosan for the Debian GNU/Linux project.
See Changelog for details)

IMPORTANT NOTICE:
If you have any kind of problems with the f77reorder script, don't
hesitate a second to tell
me
about it. Otherwise the problem will certainly NOT get fixed.

The following extensions to f77 are not allowed within f2c. f77reorder
modifies the code passed to f2c in order to avoid compilation errors.

<tab><digit> line continuation.
is converted to 5 space characters followed by a > sign.

Include path search.
If using the -cpp option for the C-preprocessor, all fortran
include statements
are automaticly converted to cpp #include statements in order to use the
better include path search.

Data statement reordering.
Standard f77 requires DATA statements to follow all variable
declarations and common block definitions. Due to the extensive
use of patchy/cmz this
requirement is not always easily fulfillable for HEP
software. f77reorder
reads in all initialization statements of functions/subroutines filters
out the DATA statements and places them at the end of the initialization
before the code begins.

PROGRAM test
integer i
data i/2/
integer k

is therefore transformed to

PROGRAM test
integer i
integer k
data i/2/

Variable
initialization within the declaration
This is also forbidden by standard f77. f77reorder contains a large
piece of code (I would call it sophisticated;-) to split
these statements
into pure declarations and data statements. This code is however not
tested too well and may produce wrong results, even if the declaration
does not contain initializations but only some unknown form of variable
declaration.

Missing commatas at the end of common block definition lines
(since version 2.4)
In some f77 dialects it is possible to omit the comma at the end
of a continued line. Thus f77reorder will change

common /block/ a, b, c
& d, e, f

to

common /block/ a, b, c
> , ! inserted by f77reorder
& d, e, f

Bitoperations
Bitoperations are not standard f77 function.
The libraries libf77.a for
both elf and aout format coming with f77reorder contain the functions
btest, ishft, iand, ior, ibset, ibclr, ieor.
However if you use this functions
in your code, you have to declare them as functions to your routine like

logical btest

as they are not part of the compiler but only external functions.

fdate
The fortran function fdate is now also included in libf77 thanks to
Alexandru Romosan.

Debug Comments - a 'D' at the start of a line
(since version 2.12)
Without the compiler flag -GD the 'D' at the start of a line is
replaced by 'C' and thus the line is marked as a comment. The
compiler flag -GD will make f77 replace the 'D' by a space character
and thus compile the line.

f77 extensions NOT handled by f77reorder

Bitoperations.
As mentioned above the bitoparations are part of the libf77.a which
comes with f77reorder but before calling this external functions they
have to be declared.

Structures.
Are neither supported by f2c nor is is
possible in any way to support
them in f77reorder.

Concatenations of variable sized string parameters
In order to concatenate variable sized string parameters, which is
possible in some extended f77
compilers, one has to copy the variable
sized string to a fixed sized
string before trying the concatenation.

Automatic conversion of integers into booleans
Tests like

integer clike
...
if ( clike ) then ...

are not allowed in standard f77. Instead f2c requests

integer f77like
...
if ( f77line .ne. 0 ) then ...

Other extensions...
There is certainly a huge list of other extensions not handled by f2c.
If you know one and have a workaround, please let
me
know in order to
extend this list.

f77reorder error messages

f77reorder is not forgiving any errors it encounters in the variable
declaration part of the f77 functions. In fact it stops execution at
the first error it finds. This behaviour should be fixed in a later
version!

Due to my lack of f77 knowlegde it might also happen that f77reorder
regards some variable declaration as an error which in fact is an
allowed one. Please send me the complete source files in such a case
to fix the problem. We were however not able to find any inconsistencies
in 40000 lines of f77 code tested...
f77reorder error messages are:

f77reorder: out ouf memory.
This error should normally not occur. It indicates that there is no
heap available to store some of the relevant data in the input file.
Either this is a bug in f77reorder (most likely) or you are running
the program on a 2MB Linux system without swap space...

f77reorder: Internal error...
This is an internal error. Please send
me
a bug report including the
offending source file(s).

f77reorder: error in variable statement
This is one of the above mentioned errors in the variable declarations.
Either there is really a bug in your code (the line number - after
eventual cpp expansion!) is also given in the error message, or this
is a new kind of variable declaration not known to me or f77reorder.
Please send
me
a bug report including the
offending source file(s).

f77reorder: Non positive array dimension in line ... variable ...
f77reorder thinks to have found an array of length 0 in your code.

f77reorder: syntax in line ...
This is most likely a variable declaration ending with a comma instead
of a variable name.

f77reorder: Too many initializers in line ...
or

f77reorder: not enough initializers in line ...
A variable declaration including initializers does not match the number
of initializers given in this line, like

integer notenough(5) /4*0/
integer tomany(5) /6*0/

f77reorder: Unknown parameter '...'
A symbolic name was fond in a variable declaration indicating the
dimension of either the variable or the initial values which has not
been found by f77reorder in the source, like:

A collegue of mine states that you do not need debuggers if you write
good code (I will *not* include his code to test his statement here ;-)

There are two options of including debug information for f77 code with
f77reorder:

Debugging in the f2c generated C code
The options to pass to f77 in this case are -g --keepC. This will
tell f2c (using the f2c option -c) to include the original f77 lines
into the program as C comments.
The advantage for the programmer is that the access of
common blocks with this method is easy as one gets the f2c generated common
block names from the C code while being able to check the execution of the
f77 code in the f77 code inlined as C comments.

Debugging in the f77 source code
The options to pass to f77 are -g only (available since
version 2.15 of f77reorder). f77reorder passes the -g option to
f2c causing it to spit out #line information in the C code.
f77reorder then corrects this #line information in a second step
to change it back to the original source and include file lines before
cpp and f77reorder steps which probably changed the line and source file
information.
Debugging works well here. One has to take into account that common blocks
are put into structures by f2c and can use the common-block name together
with gdb's TAB-expansion to get to the generated common-block names.
Variables and functions can however be accessed directly.
With one exception: To set a break point at the program start one
has to type