FORTRAN IV

FORTRAN IV was a major change from FORTRAN II. Not only
did it introduce several new features, but there were
several incompatibilities between FORTRAN IV and FORTRAN II.

Function names no longer ended in F, and a function
returned an integer value (by default) if it began with a
letter from I through N, rather than the letter X, following
the same rules as variables.

Variables could be explicitly given a type by a type
declaration statement. Arrays could also be dimensioned in
these statements, so that a separate DIMENSION statement would
not be required, and variables could be initialized in those
statements, so that a separate DATA statement, also a new statement
for FORTRAN IV, would not be required.

Character strings in FORMAT statements could be enclosed in
single quotes, rather than it being necessary to count the characters
in them for the former syntax of a Hollerith format specification.

Explicitly declaring the type of variables allowed
variables to be declared as DOUBLE PRECISION, LOGICAL, or COMPLEX.

The LOGICAL data type could only have two values, .TRUE. or .FALSE.,
and corresponded to the type of a relational expression in a logical
IF statement. Thus, instead of writing

IF (X-Y) 10,20,10
10 CONTINUE

it was now possible to write

IF (X .NE. Y) GO TO 20

The form of input-output statements was changed in FORTRAN IV
as well. Instead of special purpose statements such as READ, PRINT,
PUNCH, READ INPUT TAPE, and WRITE OUTPUT TAPE, there was simply
READ (device, format) and WRITE (device, format). However, the
BACKSPACE and REWIND statements continued to be available.

Also, the NAMELIST statement was provided, allowing list-directed
input/output; on input, the variables to be changed could be
indicated by name.

Functions and subroutines replaced the special statements that
dealt with the sense switches and sense lights, as well as those
that provided trapping of overflow and related conditions.

One important additional feature of FORTRAN IV was the ability
to pass a function or subroutine to another function or subroutine
as an argument. This meant, for example, that one could write
a subroutine that did numerical integration, and pass to it the
function to be integrated. This feature worked like this:

The versions of FORTRAN IV provided by IBM for the IBM System/360
included some extensions. REAL and DOUBLE PRECISION could be referred
to as REAL*4 and REAL*8. COMPLEX*16, allowing complex numbers the
real and imaginary parts of which were both double precision, was
also one of these extensions.

As well, one could declare a variable to be of CHARACTER*n type,
to reserve space for n characters. These variables would usually have
to be filled with trailing blanks if they contained a short string,
and no explicit character manipulation functions were included in the
language, but the A format code, present even in the original
FORTRAN language, permitted the input and output of these variables.

The IMPLICIT statement, allowing the first letter rule to be changed,
was another extension to FORTRAN IV included on the System/360.

The first FORTRAN IV compiler, the one for the STRETCH, still included
the FREQUENCY statement from the original FORTRAN compiler.

Here is an example of a FORTRAN IV program. It includes constants
for converting from degrees to radians, and radians to degrees, expressed
in internal binary form, which is machine dependent. Also note that
it makes use of the assigned GO TO statement, because it repeatedly uses
the same one of several alternatives in an inner loop: it is a program
to draw a map of the world in one of several projections.

Aside from System/360 machine dependencies, this also calls routines
to use an on-line plotter on I/O unit 9 that are peculiar to the particular
MTS installation on which it was used: it also tested if it was being run
from punched cards or from a terminal, to determine how it would ask for
input, again using a routine peculiar to the operating system.

The version of FORTRAN used (or a local addition to its library)
allowed free-format I/O, but the compiler did not allow putting an asterisk
directly in the I/O statement, although a variable containing an asterisk
was what indicated free-format I/O. So, as $ is the shift of * on
a keypunch, and this version of FORTRAN allowed $ in variable names even as
the first letter, a variable containing only an asterisk was given $ as
its name.

Also, it is meant to work with either a CALCOMP plotter whose plotting
area is 33 inches wide, or to be used from a Tektronix 4010 display, which is
the reason for some of the less obvious portions of the code. It should be
immediately obvious that CALL PLOT(X,Y,3) means to plot to point X, Y without
drawing (with the pen up) and CALL PLOT(X,Y,2) means to draw to point X, Y
from a perusal of the code.

A few comments have been added to the code as it stood originally; otherwise,
it is not changed. In addition to an assigned GO TO being used to switch the
program to the correct routine to calculate a point for the projection in use,
another is used to allow the program to switch from plotting the map to the
graticule, and another deals with various possible cases of whether or not a
line should be drawn to the current point from the previous point.

This code does not illustrate particularly good programming style,
and could thus be categorized as a youthful folly of mine, but it still does
illustrate that even in the FORTRAN IV era, the assigned GO TO still can be
put to good use shaving cycles from a program.

The FORTRAN 66 standard codified FORTRAN IV in an official standard;
since FORTRAN IV had been in existence since 1963, however, except in
contexts where standards conformance was specified, FORTRAN 66 never really
caught on as the name of this form of the language.