FORTRAN - Introduction
Diagram showing fixed format for lines of FORTRAN source code, from Digital Computing, FORTRAN IV, WATFIV, and MTS (with *FTN and *WATFIV)
For our second language we’ll look at FORTRAN, the most popular language run on MTS by far (40% by frequency of use in 1986 according to Introduction to programming and debugging in MTS, followed by Pascal at 35%). Due to its popularity it has the largest range of environments, libraries and tooling of any language available on MTS.
The FORTRAN language
FORTRAN is probably the oldest language still in wide use today. Originally developed at IBM in the early 1950s, it spread to many platforms in the 1960s and become the language of choice for scientific and mathematical applications. The first standardised version, FORTRAN 66, was a simple unstructured imperative language; later versions such as Fortran 77 and 90 added modular features and even object orientated programming constructs.
FORTRAN on MTS
Available with the D6.0 distribution are the two IBM FORTRAN IV (ie FORTRAN 66) compilers, FORTRANG and FORTRANH. The former includes better debugging support whereas the latter produces more efficient object code. Both of these compilers are available via the *FTN
front end.
There is also *IF66
, an innovative FORTRAN interpreter developed at the University of British Columbia, which is useful for developing and testing programs.
Due to copyright restrictions, the University of Waterloo compilers WATFOR and WATFIV are not available - these featured a unique compile-and-go model where compiler output was directly executed rather than writing an object file, which allows better diagnostic messages and reduced compilation costs.
FORTRAN 66 was already obsolete in 1986 and most new development in FORTRAN had moved on to FORTRAN 77 which was supported in MTS by the IBM compiler FORTRANV5 and UBC interpreter *IF77
- however neither of these are available in the D6.0 distribution due to copyright restrictions.
Also available are a number of FORTRAN preprocessors, such as RATFOR, and tools, such as the *DAVE
data flow analyser, which I will cover in a later series of posts.
Prerequisites
No special installation instructions to get FORTRAN running - just do the standard D6.0 setup as described in this guide and then sign on as a regular user such as ST01
.
Compiling using *FTN
You can invoke FORTRANG and FORTRANH directly, but it’s much easier to use the MTS front end *FTN
.
*FTN
will read source from scards
(by default *source*
ie standard input) and will write object files to spunch
(by default the temporary file -load
).
Other options can be provided using par=
on the command line or interactively.
format
determines the source code input format: options are IBM, LINE, EDITED or LONG with the default being EDITED. IBM format is the traditional FORTRAN fixed format shown at the diagram at the top of this post; LONG is IBM format with the maximum line length limit lifted; LINE is free format. EDITED is a compromise where the front end will try to guess what format the input is in.
opt
determines the optimisation level. Choices are G, which will cause the FORTRANG compiler to be used, or 0/1/2 which will select the FORTRANH compiler with increasing levels of optimisation. H is an alias for FORTRANH with level 2 optimisation. The default for opt
is G.
Other *FTN
parameters are listed in the online help or MTS Volume 6.
Hello world
Here’s a terminal log of how to compile and run a simple hello world program. This assumes the source code is in file hello.f
.
# $list hello.f
1 C *** HELLO WORLD PROGRAM ***
2 C
3 DO 10 I=1,5
4 WRITE (6,20)
5 10 CONTINUE
6 STOP
7 20 FORMAT(13H HELLO, WORLD)
8 END
# $run *ftn scards=hello.f
No errors in MAIN
# $run -load
HELLO, WORLD
HELLO, WORLD
HELLO, WORLD
HELLO, WORLD
HELLO, WORLD
The *IF66
FORTRAN interpreter
If you’ve used the UM BASIC interpreter, the *IF66
FORTRAN interpreter will appear familiar, with the ability to switch between editing, running and debugging programs. It integrates well with the MTS environment, allowing you to use the full MTS editor and is fully compatible with the FORTRAN compilers. It supports running of arbitrary FORTRAN statements or routines and debugging features such as atpoints, where code can be run when a breakpoint is reached.
A quick demo, using the file hello.f
from before:
# $run *if66
* IF(NOV80)
* /compile hello.f
ROUTINE NAME: MAIN
* /list main
* 1. C *** HELLO WORLD PROGRAM ***
* 2. C
* 3. DO 10 I=1,5
* 4. WRITE (6,20)
* 5. 10 CONTINUE
* 6. STOP
* 7. 20 FORMAT(13H HELLO, WORLD)
* 8. END
+ /edit main
You are now in the MTS editor and can type v
to enter visual mode and make changes; press PA2
to exit out of the editor. I’ll now show how to run the program and also *IF66
’s immediate execution of FORTRAN statements:
* /run main
HELLO, WORLD
HELLO, WORLD
HELLO, WORLD
HELLO, WORLD
HELLO, WORLD
/MAIN:6./ - /STOP /
+ x=40.0
+ y=sqrt(x)
+ print,y
6.324555
+ /stop
Definitely a useful and powerful tool, and I don’t think any other platform had such an advanced FORTRAN interpreter at that time.
In the next post, I’ll take a look at the FORTRAN language in more detail.
Further information
MTS Volume 6 describes *FTN
and *IF66
in full detail, along with the other FORTRAN tools available.
Digital Computing, FORTRAN IV, WATFIV, and MTS (with *FTN and *WATFIV) is a good contemporary introduction to programming FORTRAN on MTS from two authors at the Chemical Engineering department at UM. A number of different editions were produced; the linked one is from 1976. It also includes a useful description of the IBM S/360 architecture from the viewpoint of a non-systems programmer.
IF, an interactive FORTRAN compiler (link not working as of August 2023) is a paper from 1973 giving background information on why *IF66
was developed and a demo of its use.