Scor­pio News

  

January–March 1987 – Volume 1. Issue 1.

Page 12 of 63

Assingments

This is the correct way of describing statements which contain an ‘equals’ sign. The use of the ‘−’ sign in Fortran is exactly the same as in BASIC and Pascal.

Arithmetic Operators

Again, this is the correct way of describing the +, –, *, /, and ** operators. The first four are familiar enough in BASIC but the fifth replaces the ‘up-arrow’ used to indicate exponentiation. The order in which the operators work is follows – from left to right in three sweeps; these deal respectively with any exponentiation, followed by multiplication or division and finally the addition or subtraction. There is no precedence between addition and subtraction or division and multiplication and the use of parentheses (brackets) can be used to emphasize or change the natural order which has just been described. Again, there is no difference between BASIC end Fortran.

ARRAYS

Arrays are characterised by having 1, 2 of 3 dimensions (or more in some versions of Fortran!). The size of an array must therefore be declared explicitly at the beginning of a program or subroutine, by using the Dimension statement in which the array name (1-6 characters, the first of which is a letter) and its dimensions are stated. The process is broadly similar to BASIC and the relevant programs line appears thus:

DIMENSION SQUARE(10,10),CUBE(5,4,3),LINE(20)

gives the dimensions of two REAL arrays and one Integer array; Square has two dimensions with a maximum of 100 elements, CUBE has three dimensions and 60 elements and LINE is single dimension linear array (vector) which can store up to 20 Integer values only, just as CUBE and SQUARE can only store REAL numbers. If the Dimension statement is preceded by an explicit variable declaration – such as making CUBE an integer variable, the array CUBE becomes capable of holding only integer data. The values in brackets after the array name are referred to as subscripts and identify the array elements, on the first occasion that an array (3 declared, the dimensions muse be numerical but if the array is required in a subroutine (the Fortran ‘equivalent’ of the GOSUB – RETURN or the PROCedure in other versions of BASIC), these numerical values can be replaced by letters or other variable names provided these have been given a value before the subroutine is called. The value of the subscript should be adequate to deal with the anticipated amount of data so that if 105 values are input into array SQUARE, there will be an overflow and program execution will cease. One dimension and two dimension arrays are fairly straightforward and are widely used in BASIC, and the method of accessing a particular array element is identical in Fortran. The threw dimension array is simply a series of two-dimension arrays arranged in ‘layers’. In the example given above, CUBE consists of 3 ‘layers’, each with 5 rows and 4 columns, so that CUBE(4,3,2) = 10.5 indicates that the array element in the fourth row of the third column in the second layer has the value 10.5 assigned to it and CUBE(5,4,3) = −1.5 indicates that the very last element (row 5, column 4, layer 3) has the value −1.5 assigned to it.

It is possible to reduce storage requirements by three methods, one relies upon the different amount of storage required by each data type. One REAL data value occupies 4 bytes, Double Precision takes 8 bytes, Integer takes 2 and Logical, 1 byte. Space can be saved by making sure that data is given an appropriate type – serial numbers, for example can be stored as integers rather than real numbers. Another method uses the Equivalence statement in which arrays can share the same storage area – preferably if they are of the same type (integer, or real). The statement has the general form:

Page 12 of 63