XXX -> C (actually Fortran -> C)

Bill Venables wvenable at spam.ua.oz
Sat Jul 7 16:16:55 AEST 1990


In article <55422 at lanl.gov> rdw2030 at venus.tamu.edu writes: 
>C is really taking over!  Everyone needs converters now! &c &c

Anyone used to the look and feel of C is going to find the prospect of
working with large quantities of elderly Fortran code distasteful. The
sort of things that are most off-putting are statement numbers, fixed
card layout, (particularly the silent ignoring of anything past column
72), weird control structures, endemic goto-isms, exotic I/O, bulk use
of upper case and the general all round anti-structured flavour.

There is, however, a nice tool that does a good job of converting
Fortran code to a form instantly recognizable, nicely indented and
fully readable to any C programmer.  95% of the statement numbers are
removed, for example. It's called struct(1), it's part of most BSD
Unix releases, and it converts Fortran into Ratfor.  It should be more
widely known and used.  However it is and old program, and is somewhat
limited to fairly deadpan Fortran.

If you are faced with converting middling amounts of Fortran to C,
(for example one or two standard linear algebra or eigenvalue
subroutines), you have three main choices:

1) Use a Fortran to C converter (and usually end up with very odd C code),

2) Go right back to the algorithm and hand code it in C from scratch, and

3) Convert the code to Ratfor using `struct', and then manually convert
   that code to graceful C.

On occasion I have found 3) a useful alternative, particularly when
the original Fortran code is good code, and contains no I/O (which is
always going to be a problem.)  There are still difficulties in
converting Ratfor into idiomatic C, particularly if multiply
subscripted arrays are involved, but they are an order of magniture
less than trying to convert raw Fortran into C, either by hand or by
converter.

Does anyone know of an updated version of struct?

Has anyone tackled the job of writing a Ratfor to C converter?  

(This job could almost be done in emacs using a few tricky macros.)

-- 
  Bill Venables, Dept. Statistics,        | Email:   wvenable at spam.ua.oz.au
  Univ. of Adelaide,  South Australia.    | Phone:           +61 8 228 5412



More information about the Comp.lang.c mailing list