Scor­pio News

  

January–March 1987 – Volume 1. Issue 1.











Page 15 of 63











The form of the FUNCTION statement is as follows:

FUNCTION name (dummy arguments – if needed)

or, more explicitly,

type FUNCTION name (dummy arguments)

The reason for the second form is that the type can be explicitly declared a INTEGER, REAL, DOUBLE PRECISION, LOGICAL or (in ProFortran) COMPLEX. Thus, if the function required was called LENGTH and it was a REAL number rather than an INTEGER, the correct form for the FUNCTION subprogram which gave the single value for LENGTH would be:

REAL FUNCTION LENGTH

The same rule applies if the function name is one which by default would be a REAL if an INTEGER value was required for example:

INTEGER FUNCTION AREA

INTRINSIC FUNCTIONS

In all high-level languages, there is a range of particular functions for which the necessary code is supplied – such as INT or ABS in BASIC. These are termed intrinsic functions and are called by name to produce a particular value. There are rather more intrinsic functions in FORTRAN than will be found in most BASICS since some are available in integer, real and double precision forms. There is always a list of these in the documentation associated with the version of FORTRAN you are using. Some old favourites Like CHR$ and LEFT$ are never found in FORTRAN, others are spelt differently – SIGN rather than SGN – but most are readily interpreted.

EXTERNAL FUNCTIONS

Again, these have their counterparts in BASIC although many are available in double precision or even complex number forms in addition to the conventional real number form – typical of these are the trigonometric functions, SIN, COS or TAN, and SQRT – spelt differently to the BASIC way (SQR). There is log base e (ALOG) and log base 10 (ALOG10) and a random number generator – variously spelt RND or RAND. A list of these will also be found in the documentation, together with a list of restrictions on the type of variable with which they can be used – thus if you want the square root of a variable it must be of type real or double precision and if it is an integer, this must be converted to real by the use of a cunning little intrinsic function called FLOAT. Failure to do this first will lead to an execution error and the program grinding to an unprofitable halt. An external function called IFIX does just that to REAL numbers, converting them to INTEGER type.

DATA INPUT/OUTPUT

On first acquaintance, this appears to be rather more complicated than in BASIC, but it is a great deal more flexible. Data to be read into or results output from s program can be in almost any desired form provided the machine is properly instructed by meant of a FORMAT statement. Data is read in from either keyboard or disk file using a READ statement and written to the screen, disk file or printer by means of WRITE statement in their basic form these are as follows:

READ (u,f) k         or         WRITE (u,f) k












Page 15 of 63