Variables are the fundamental building blocks of any program. In Fortran, a variable name may consist of up to
31 alphanumeric characters, of which the first character must be a letter. Underscores are allowed but not spaces or
special characters.
Variable Types
Fortran defines several distinct types corresponding to the generic types described above. These include
INTEGER
REAL
DOUBLE PRECISION (this name is obsolet but is still widely used)
COMPLEX
CHARACTER
LOGICAL
Constants are literal representations of a type that are specified by the programmer. In Fortran,
different constant formats are required for each type.
The following program illustrates variable declarations.
Characters
Characters can either be declared as a single CHARACTER variable, a string of characters or
an array of single characters or character strings.
character :: c1 ! Single character
character(len=80) :: c2 ! String of characters
character, dimension(10) :: c3 ! Array of single
! characters
character(len=80), dimension(10) :: c4 ! Array of character
! strings (10 elements)
Using kind
The current preferred method of specifying the precision of a variable is to use the KIND representation. With
KIND, the programmer specifies the number of decimal digits and the exponent range required, and the system
matches the request to its underlying machine representation as closely as possible. Since nearly all current
systems use the IEEE 754 convention, in practice only two kinds are widely used.
Compilers still recognize the REAL and DOUBLE PRECISION keywords. The advantage to the kind
convention is that it can be made very simple to switch between real and double precision.
For most purposes, it is only necessary to use the SELECTED_REAL_KIND intrinsic and the programmer
need never worry about what is going on within the machine. To declare single precision, use