When a program is loaded into the computers memory, the contents of declared variables are normally undefined, it is clearly useful to override this and give variables useful initial values. For example,
INTEGER :: i = 5, j = 100 REAL :: max = 10.D5 CHARACTER(LEN=5) :: light = 'Amber' CHARACTER(LEN=9) :: gumboot = 'Wellie' LOGICAL :: on = .TRUE., off = .FALSE.
For CHARACTER variables, if the object and initialisation expression are of different lengths then either:
Variables can be initialised in a number of ways
Limited expressions known as initialisation expressions can also
be used in type declaration statements. These expression must be able
to be evaluated when the program
is compiled -- if you can't work out the values then neither can the
compiler. Initialisation expressions can contain PARAMETER s or literals.
Arrays may be initialised by specifying a scalar
value or by using a conformable array constructor, (/.../)
.
REAL, PARAMETER :: pi = 3.141592 REAL :: radius = 3.5 REAL :: circum = 2 * pi * radius INTEGER :: a(1:4) = (/1,2,3,4/)
In general, intrinsic functions cannot be used in initialisation expressions, however, the following intrinsics may be used:
In this context the arguments to these functions must be initialisation expressions.