Fortran to C converter (summary)

Raymond Chen raymond at math.berkeley.edu
Mon Mar 25 05:43:19 AEST 1991


Fortran to C conversion:

Karen Anderson (anderson at eecs.cs.pdx.edu) did a lot of work in collecting
this information.  Any additions or corrections to this document
would be greatly appreciated; please send them to raymond at math.berkeley.edu.

Standard disclaimers apply.  Opinions are those of the original authors.
Typing and editing errors are mine.

===============================================================================
f2c
-------------------------------------------------------------------------------
Joshua Simons (simons at think.com) and Mark.Maimone at a.gp.cs.cmu.edu
posted the press release:

Source for f2c, a Fortran 77 to C translator jointly developed
by folks from Bell Labs, Bellcore, and Carnegie Mellon, is now
freely available.

F2c was derived from the original UNIX operating system's f77(1),
and the generated C follows f77's calling conventions; on some
machines, the resulting object files are interchangeable with
(and behave indistinguishably from) objects compiled by f77.
The main "advantage" of f2c is that it converts ANSI standard
Fortran 77 into C without manual intervention, at least when
invoked by a suitable script or makefile (that may need to exercise
an f2c option to ensure that COMMON blocks are defined just once).

The main "problems" are that f2c does no code restructuring
(e.g., gotos are preserved) and that Fortran I/O gets converted
into a bunch of calls; thus the translated C code doesn't look
too pretty, and in general one would need to maintain the Fortran
rather than its translation into C.  [Indeed, maintainable C code
was specifically *not* an objective of the f2c project.  The
intent is that you maintain the Fortran. The f2c tech report
comments that producing maintainable C automatically seems to
require some amount of manual intervention even using commercial
($$$) translator programs. -- Henry Spencer]

There is a plethora of options, many of which exist to support
different compilation environments for the translated C (e.g.,
ANSI C or C++ compatability, different type sizes, separate files
for COMMON blocks to appease "smart" linkers).  So far f2c (and
f2c-generated source) has compiled successfully on many machines:
Sun, Vax, IBMRT, Apollo, SGI, MIPS, and Cray to name a few.

F2c has been under test by the net community for over six months
[as of 27 Apr 90], and has been verified on the NBS tests,
several large math libraries, floating point tests, even code for
laying cable on the ocean floor!

To find about f2c, send the following E-mail message to netlib
(netlib at research.att.com or research!netlib):

        echo send index from f2c | mail netlib at research.att.com

Your message will be answered automatically (by a program --
see CACM vol. 30 #5 (May, 1987), pp. 403-407).  You will receive
a reply explaining how to automatically acquire f2c source
(about 600K), f2c library source (130K), and supporting info
(man page, etc).

To get it using anonymous FTP, ftp research.att.com and cd to
directory dist/f2c.  All files are stored in compressed
format.  [Make sure to pick up the runtime libraries libf77
and/or libi77.]

   ****************************** DISCLAIMER ******************************
                Careful! Anything free comes with no guarantee.
   ************************************************************************

-------------------------------------------------------------------------------
Mike Black (black at seismo.CSS.GOV) reports:

I tried using f2c from the at&t distribution.  If your desperate, it
might be worth it.  But the code is a nightmare to read.  I've done hand
conversions before with much better results than f2c.  [See the comment
by Henry Spencer for an explanation.]

-------------------------------------------------------------------------------
Larry Jones (sdrc!scjones%thor at uunet.UU.NET) writes:

I haven't used f2c myself, but it's gotten rave reviews from others
here who have used it.

-------------------------------------------------------------------------------
Rick Stevens (zardoz!tmiuv0!rick at decwrl.dec.com) says:

There's a huge bugger from ATT Bellcore called F2C.  It's written in C
(natch) and is FTPable.  It's big, and you'll have to build it for your
system, however it does work and works quite well.

-------------------------------------------------------------------------------
And from Hans Georg v. Zezschwitz (zeschwitz at imdm.uke.uni-hamburg.dbp.de):

I'm am currently trying to work with the standart f2c (from netlib at att...)
Till now I made only one attempt with a Fortran program from a microVax.
It was for parametrization of eeg-segments. Apart from screen-specific
adaptions I had to edit it worked directly on a Unix (Xenix) system
(under C - of course).

For I rather don't know much about Unix nor Fortran I otherwise anyway
would not have coped with occuring problems.

===============================================================================
Cobalt Blue
-------------------------------------------------------------------------------
ubbpc!wgh at PRC.Unisys.COM (William G. Hutchison) writes:

We have had a client port an X-window application successfully from
FORTRAN to C using the Cobalt Blue converter.

-------------------------------------------------------------------------------
Tim.Ouellette at FtCollins.ncr.com says:

Of the Fortran-to-C convertors I've seen.  They've dealt with
the simple commands okay.  The main downfall I've seen is that they
don't have any way of dealing with the FORTRAN 'EQUIVALENCE'
statement.  I've listed one's I seen advertised below.  Hope it helps.
  

  FOR_C by Cobalt Blue
      2940 Union Ave, Ste C
      San Jose CA 95124
      (408)723-0474

-------------------------------------------------------------------------------
Ralph Carpenter (ralphc at tekcae.CAX.TEK.COM) adds,

        A demo disk is available for around $10.  It converts subroutines
        that are less than 1K in size.

        The address and phone of a mail order source:
                The Programmer's Connection
                7249 Whipple Ave NW
                North Canton, OH 44720-7137
                (800) 336-1166

        Price as of 1 Jan 1990 (including surface UPS shipping):
                $442 with binary runtime, ($575 list).
                $673 with runtime sources, ($875 list).

-------------------------------------------------------------------------------
Steve Fullerton (scf%statware.uucp at cs.orst.edu) notes:

Cobalt Blue, a company out of San Jose has 2 FORTRAN-to-C translator
products, FOR_C and FOR_C++.  I have a copy of FOR_C and have seen demos
of FOR_C++.  If you need to deal with complex variables, then take a
look at FOR_C++.  The translation results in very readable code.  FOR_C
also handles complex but the resulting code might be best described as
spaghetti, although it does a very nice job on other standard and
non-standard FORTRAN.

Their address and phone:   Cobalt Blue
                           1683 Milroy, Suite 101
                           San Jose, CA  95124
                           408/723-0474

===============================================================================
Promula.Fortran
-------------------------------------------------------------------------------
orszak at cfa243.harvard.edu (Jeff Orszak)  sent a post which appeared on
comp.lang.fortran written by tohanson at gonzo.lerc.nasa.gov (Jeff Hanson).

In Digital Review (June 18, 1990) there is a review of Promula.Fortran, a
Fortran to C source code translator on pages 29 - 31.

The Test Brief follows

Vendor: Promula Development Corp.
   3620 N. High St.
   Suite 301
   Columbus, OH 43214
   (614) 263-5454

Test configuration: Promula.Fortran version 2.01 installed on a VAXstation
II/GPX running VMS 5.2

Price as Tested: $995.

Pros:   Includes many command line options
   Can produce various "flavors" of C code
   Supports all VAX Fortran data types except REAL*16
   Successfully translated STRUCTURE and RECORD decalarations including
      UNION and MAP statements

Cons:   I/O subroutine library did not work properly with ANALYSIS and PHILCO
      (2 of the DR Labs test programs)
   Defaulted to pointer notation for representing arrays, which is unclear
      and less efficient in VAX C
   Required dialect and error message files to be copied to current
      working directory for translation
   Used double quotes for include file specifications but incorrectly
      defines VAXC$INCLUDE rather than C$INCLUDE
   Non VMS-style command line options

The final 2 paragraphs of the review are:

With the exception of some undesirable default options, less-than-ideal
handling of some I/O statements and unsatisfactory handling of the DATA
statement, Promula.Fortran is a very useful utility for users who must
translate large amounts of Fortran to C.  It translates quickly and generates
well-written and - with some expections - immediately executable C code.

Promula.Fortran has options that give users control over the C code produced.
Promula.Fortran's C code is very amenable to C programmers; it uses C
language conventions and, to put it simply, "feels" like C.

I have not seen this product and this posting should not be seen as an
endorsement for Promula. It should be seen as a high endorsement for DR Labs.


===============================================================================
for2c
-------------------------------------------------------------------------------
daveo at mipon3.intel.com (David O'Brien) writes:

I worked with a program about 18 months ago called for2c or something
like that.  It was DOS based.  I delt with the designer himself and
had good success.  If you would like, I can go dig the name/company up
for you.  I know right were they are at home.  Let me know.

===============================================================================
Green Hills Software, Inc.
-------------------------------------------------------------------------------
unisoft!peritek!dig (Dave Gotwisner) found this advertisement:

	Green Hills Software, Inc.
	425 East Colorado Street, Suite 710
	Glendale, CA 91205
	(818) 246-5555
	FAX: 818-246-7037

I don't know how good it is, but we use one of their
other products (a 68K cross compiler running under VMS), and it is quite
good.  Binary copies can be gotten from:

	OASYS, Inc.
	230 Second Ave.
	Waltham, MA 02154
	617-890-7889

>From the data sheet:

		    Language
	* ANSI Fortran-77 (Full language)
	* DoD Mil-STD 1753
	* VAX/VMS Extensions
		* NAMELIST
		* Full Syntax OPEN
		* STRUCTURES
		* %VAL, %REF, %LOC
		* !comments
		* ENCODE/DECODE
		* INTEGER *1, *2
		* Octal/Hex constants
		* etc.

		    Optimizations
	* Register allocation
	* Strength reduction
	* Loop Invariant elimination
	* Common subexpressions
	* Value propagation
	* Tail recursion
	* Loop rotation
	* Static address elimination

		    Hosts
	VAX/UNIX	Sun-2		386 UNIX/DOS
	VAX/VMS		Sun-3
	(others by arrangement)

For further information, please contact either OASYS or Green Hills.

===============================================================================
A masters thesis
-------------------------------------------------------------------------------

Roger Christman (dvl at psuvm.bitnet) is working on a Fortran-to-C
translator for his Masters thesis at Penn State U.  Here's what
he says:

        It is designed to accept any Fortran 66
        program and translate it into an equivalent C source.  Program flow
        structure is analyzed so that even the messiest GOTO arrangements
        should find themselves better approximating such things as loops
        and switches. ...

        The upshot of all this is that the resulting program will be more
        intuitively structured, as well as more efficient than the original.
        As an example of current benchmarks, using the F77 and CC compilers
        on a Sun Workstation Unix machine, my program is doing quite well.
        The time required to translate into C and compile there is less than
        the original Fortran compilation time.  Also, the object code in C
        executes faster than the original Fortran.

        If you would like to find out more later on, when I approach the end
        of the project, please send me mail at this address.  I must warn you
        that this project is for academic reasons alone, and is not designed
        with production-scale error-checking.  If your program will not compile
        in Fortran 66, don't expect this translator to give you very meaningful
        results.

===============================================================================
General comments
-------------------------------------------------------------------------------
On the subject of source code conversions in general
ittc!fbresz at uunet.UU.NET gets the last word:

Hi,
   I have seen this question asked a few time and I finally decided to
send an email to someone so ..

   I used to work for a company involved in such business.  We would
for a price take your working FORTRAN code and convert it to C.  Now this
was not cheap nor was it easy.  I spent 1 entire year of my life on a
project which bore little fruit.  So I am of the opinion that it might just
be easier to recode.  Also you might want to think about waht you mean by
translation, we of course had the bizarre definition, runs identically to
FORTRAN.  This leads into reproducing all the bizarre behaviours of FORTRAN
and if you think thats hard try doing PL/I => C  we also did that or how
about PL/I => Ada.  For these reasons (i.e. my brain is fried) I no longer
do much programming.  I run a medium sized network for Westinghouse in
which the biggest programming task is getting sendmail.cf files workking
correctly .  But seriously if you would care to have even more information
about translation, the company I used to work for has long since evaporated.
I can then tell you anything you want to know without problems of revealing
corporate secrets.

               Frank P. Bresz }*{
               ITTC Network Administrator


===============================================================================



More information about the Comp.lang.c mailing list