Most programmers will agree that FORTRAN is an unpleasant language to program in, yet there are many occasions when they are forced to use it.

From the introduction to 'RATFOR — A Preprocessor for a Rational FORTRAN' by Brian W. Kernighan

FORTRAN was the lingua franca for mainframe programmers in the 1960s and 1970s, but as Kernighan states it's not always easy to program in - the main reasons are lack of good control structures and the fixed line format. As a result, a number of preprocessors were developed that translated enhanced code down to plain FORTRAN that could then be compiled anywhere a compiler was available.

In this series of posts, we'll look at two preprocessors available on MTS: RATFOR and FLECS. MTS also had OVERDRIVE, but this is not available on D6.0 due to copyright reasons.

Prerequisites

No special installation instructions to get these preprocessors running - just do the standard D6.0 setup as described in this guide and then sign on as a regular user such as ST01.

RATFOR

RATFOR was developed by Brian Kernighan at Bell Telephone Labs in 1974; its syntax was (not surprisingly) inspired by the C programming language, with keywords like for, while and until. It was used as the language for examples in Software Tools and became one of the most popular preprocessors in use. Versions are still available today that run on Unix systems.

Preprocessing using *RATFOR

The version on MTS is called *RATFOR and takes a RATFOR program as input on scards and writes FORTRAN source to spunch. The generated file can then be compiled with *FTN.

Hello world

Here's a terminal log of how to compile and run a simple hello world program in RATFOR. This assumes the source code is in file hello.r.

# $list hello.r

      1     # *** Simple hello world program ***
      2     #
      3     integer i
      4     for (i = 0; i < 5; i = i + 1)
      5     {
      6        write(6, 200)
      7     }
      8     stop
      9     200 format("Hello, world!")
     10     end

# $run *ratfor scards=hello.r spunch=-hello.f
Execution begins   21:56:08  
Execution terminated   21:56:08  T=0.004

# #list -hello.f

      1           INTEGERI
      2           CONTINUE
      3           I=0
      4     23000 IF(.NOT.(I.LT.5))GOTO 23002
      5           WRITE(6,200)
      6     23001 I=I+1
      7           GOTO 23000
      8     23002 CONTINUE
      9           STOP
     10     200   FORMAT(13HHello, world!)
     11           END

# $run *ftn scards=-hello.f spunch=-load
Execution begins   21:56:36  
 No errors in MAIN
Execution terminated   21:56:36  T=0.008

# #run -load
Execution begins   21:56:39  
 Hello, world!
 Hello, world!
 Hello, world!
 Hello, world!
 Hello, world!
Execution terminated   21:56:39  T=0.001  

FLECS

FLECS was written in the early 1970s by Terry Beyer at the University of Oregon. It provides a smaller set of control structures that RATFOR but the syntax is closer to FORTRAN. Keywords include IF...THEN...ELSE and CONDITIONAL and multi-line statements are supported. It does not appear to have been used much past the introduction of FORTRAN77, but a a version is still available today for HPUX.

Compiling using UNSP:FLX

At the time D6.0 was released, FLECS was unsupported at UM so is available as the file FLX in UNSP:. The preprocessor does not used scards and spunch; instead, all parameters need to be passed in to par. Unlike RATFOR, FLECS can call the FORTRAN compiler directly to generate object code. In the listing below, PAR=SOURCE=hello.fl,P=*SINK*,FTNSOURCE,LOAD=-load would read source from hello.fl, print diagnostics to *SINK including the FORTRAN source generated, and write compiled output to -load.

Hello world

Here's a terminal log of how to compile and run a simple hello world program in FLECS. This assumes the source code is in file hello.fl.

# $list hello.fl

      1     C *** SIMPLE HELLO WORLD PROGRAM ***
      2     C
      3           DO (I = 1,5)
      4           WRITE (6,20)
      5           FIN
      6           STOP
      7        20 FORMAT(13H HELLO, WORLD)
      8           END

# $run UNSP:FLX PAR=SOURCE=hello.fl,P=*SINK*,FTNSOURCE,LOAD=-load
Execution begins   21:47:21  
 FFI(CT206)


 (FLECS VERSION 22.38)  MTS Version CT155 21:47:21    JAN 21, 1916    Page   1

 MTS Line#        Indented Source Listing...

      1     C *** SIMPLE HELLO WORLD PROGRAM ***
      2     C
      3           DO (I = 1,5)
      4           .  WRITE (6,20)
      5           ...FIN
      6           STOP
      7        20 FORMAT(13H HELLO, WORLD)
      8           END

   0.001 seconds CPU time used.  Translation rate is 480000 lines per CPU minute.

 There were   NO MAJOR ERRORS and   NO MINOR ERRORS in the above module.
 No preprocessor errors in module  1.


  MICHIGAN TERMINAL SYSTEM FORTRAN G(21.8) MAIN 01-21-16 21:47:21 PAGE P001

    0001              DO 99998 I = 1,5             3.000
    0002              WRITE (6,20)                 4.000
    0003        99998 CONTINUE                     5.000
    0004              STOP                         6.000
    0005           20 FORMAT(13H HELLO, WORLD)     7.000
    0006              END                          8.000
     *OPTIONS IN EFFECT*  ID,EBCDIC,SOURCE,NOLIST,NODECK,LOAD,NOMAP
     *OPTIONS IN EFFECT*  NAME = MAIN    , LINECNT =       57
     *STATISTICS*    SOURCE STATEMENTS =        6,PROGRAM SIZE =      344
     *STATISTICS*  NO DIAGNOSTICS GENERATED
 No errors in MAIN

 NO STATEMENTS FLAGGED IN THE ABOVE COMPILATIONS.
Execution terminated   21:47:21  T=0.018

# $run -load
Execution begins   21:47:31  
 HELLO, WORLD
 HELLO, WORLD
 HELLO, WORLD
 HELLO, WORLD
 HELLO, WORLD
Execution terminated   21:47:31  T=0.001  

Further information

The Wikipedia article on RATFOR has a basic introduction to language features and the history of its development. Kernighan's paper on RATFOR goes into more detail on the language.

Not much appears to exist on the Internet describing FLECS, but the D6.0 MTS tapes does include the complete User's Manual (in component 673/22) and the interface to MTS.

MTS Volume 6 describes the FORTRAN compilers on MTS, which are needed to compile the RATFOR preprocessor's output.