Formula translation

Fortran is designed for formula translation. Many elementary Fortran programs will include three components:

  1. The input of data which is stored as variables

  2. The evaluation of formulae using the input data

  3. The output of the results

Here is a simple example:

PROGRAM Prog2

INTEGER i,j

READ *,i

j=2*i+3

PRINT *,j

END PROGRAM Prog2

The next example is similar but uses REAL numbers:

PROGRAM Prog3

REAL x

WRITE(*,"(a)",ADVANCE="NO") "Enter a real number:"

READ *,x

PRINT *, "The result is:", x/3.0-0.9E6

END PROGRAM Prog3

In Fortran it is possible to use a variable without explicitly declaring its type. Variables that are not declared are assumed to be either INTEGER or REAL depending on the first letter in the name. However, the use of this implicit typing is not recommended. Moreover, if a variable name is spelled incorrectly, the implicit typing rule will cause the rogue variable to be declared leading to erroneous results. In order to avoid this happening, it is recommended that the implicit typing facility be switched off. To do this, include the statement IMPLICIT NONE before any type declarations.

Note: FTN95 can be configured so that IMPLICIT NONE is the default for all program units (see the compiler options /CONFIG and /IMPLICIT_NONE).

 

 

Basket
Empty
 
Copyright © 1999-2024 Silverfrost Limited