Incomplete Fortran to C/C++ converter

This script transforms old Fortran 77 code to C/C++. Put your Fortran 77 code in the text field below and press the convert button. The program does not convert to full compatible C code. You won't be able to compile the generated code.
Why do you need such a converter?
Two more or less complete converters, f2c and fable have been published so far. Both tools try to transform your old code to match full compatibility with the fortran rules but neglecting readability. This is the point were this script could help you. The script contain some more intelligent substitution algorithms that will help you to transform your source code manually by doing all the nasty stuff.
  • Insert Indention
  • Remove of first column
  • Convert Comments
  • Convert Gotos
  • Remove blanks
  • Move Format lines to read and write functions
  • Convert if and do
  • Remove unnecessary gotos
  • Add Semicolons at end of line
  • Convert array brackets
  • Convert 'DO' loops to the corresponding 'for' loop
  • Transform common blocks to global structs
  • Parse Parameters and convert
  • Substitute obvious tokens
The program does not convert the array indexing scheme of Fortran!.
Put you Fortran 77 code here:
c This is a comment PROGRAM QUAD E = 1E-9 READ *, A,B,C IF (A.GE. -E .AND. A.LE.E) THEN PRINT *, 'FIRST COEFFICIENT MUST BE NON-ZERO.' ELSE S = B**2 - 4*A*C IF (S.GT.E) THEN D = S**0.5 X1 = (-B+D)/(2*A) X2 = (-B-D)/(2*A) PRINT *, 'TWO DISTINCT ROOTS:' X1 'AND' X2 ELSE IF (S.GT. -E) THEN X = -B/(2*A) PRINT *, 'TWO COINCIDENT ROOTS',X ELSE PRINT *, 'NO REAL ROOTS.' END IF END IF END SUBROUTINE TEST INTEGER I, NN 123 DO 234 I=1,NN c do something 234 CONTINUE go to 123 GOTO(123, 234, 123, 234, 123), NN END C AREA OF A TRIANGLE - HERON'S FORMULA C INPUT - CARD READER UNIT 5, INTEGER INPUT C OUTPUT - LINE PRINTER UNIT 6, REAL OUTPUT C INPUT ERROR DISPAY ERROR OUTPUT CODE 1 IN JOB CONTROL LISTING SUBROUTINE AREA INTEGER A,B,C READ(5,501) A,B,C 501 FORMAT(3I5) IF(A.EQ.0 .OR. B.EQ.0 .OR. C.EQ.0) STOP 1 S = (A + B + C) / 2.0 AREA = SQRT( S * (S - A) * (S - B) * (S - C) ) WRITE(6,601) A,B,C,AREA 601 FORMAT(4H A= ,I5,5H B= ,I5,5H C= ,I5,8H AREA= ,F10.2,12HSQUARE UNITS) STOP END * euclid.f (FORTRAN 77) * Find greatest common divisor using the Euclidean algorithm SUBROUTINE EUCLID PRINT *, 'A?' READ *, NA IF (NA.LE.0) THEN PRINT *, 'A must be a positive integer.' STOP END IF PRINT *, 'B?' READ *, NB IF (NB.LE.0) THEN PRINT *, 'B must be a positive integer.' STOP END IF PRINT *, 'The GCD of', NA, ' and', NB, ' is', NGCD(NA, NB), '.' STOP END FUNCTION NGCD(NA, NB) IA = NA IB = NB 1 IF (IB.NE.0) THEN ITEMP = IA IA = IB IB = MOD(ITEMP, IB) GOTO 1 END IF NGCD = IA RETURN END



Output: