Lahey/Fujitsu Fortran

Literal Data

A literal datum, also known as a literal, literal constant, or immediate constant, is specified as follows for each of the Fortran data types. The syntax of a literal constant determines its intrinsic type.

Integer Literals

An INTEGER literal consists of one or more digits preceded by an optional sign (+ or -) and followed by an optional underscore and kind type parameter. If the optional underscore and kind type parameter are not present, the INTEGER literal is of default kind. Examples of valid INTEGER literals are

34 -256 345_4 +78_mykind

34 and -256 are of type default INTEGER. 345_4 is an INTEGER of kind 4 (default INTEGER in LF95). In the last example, mykind must have been previously declared as a scalar INTEGER named constant with the value of an INTEGER kind type parameter (1, 2, or 4 in LF95).

A binary, octal, or hexadecimal constant can appear in a DATA statement. Such constants are formed by enclosing a series of binary, octal, or hexadecimal digits in apostrophes or quotation marks, and preceding the opening apostrophe or quotation mark with a B, O, or Z for binary, octal, and hexadecimal representations, respectively. Two valid examples are

B'10101' Z"1AC3"

Real Literals

A REAL literal consists of one or more digits containing a decimal point (the decimal point can appear before, within, or after the digits), optionally preceded by a sign (+ or -), and optionally followed by an exponent letter and exponent, optionally followed by an underscore and kind type parameter. If an exponent letter is present the decimal point is optional. The exponent letter is E for single precision, D for double precision, or Q for quad precision If the optional underscore and kind type parameter are not present, the REAL literal is of default kind. Examples of valid REAL literals are

-3.45 .0001 34.E-4 1.4_8

The first three examples are of type default REAL. The last example is a REAL of kind 8.

Complex Literals

A COMPLEX literal is formed by enclosing in parentheses a comma-separated pair of REAL or INTEGER literals. The first of the REAL or INTEGER literals represents the real part of the complex number; the second represents the imaginary part. The kind type parameter of a COMPLEX constant is 16 if either the real or the imaginary part or both are quadruple precision REAL, 8 if either the real or the imaginary part or both are double-precision REAL, otherwise the kind type parameter is 4 (default COMPLEX). Examples of valid COMPLEX literals are

(3.4,-5.45) (-1,-3) (3.4,-5) (-3.d13,6._8)

The first three examples are of default kind, where four bytes are used to represent each part, real or imaginary, of the complex number. The fourth example uses eight bytes for each part.

Logical Literals

A LOGICAL literal is either .TRUE. or .FALSE., optionally followed by an underscore and a kind type parameter. If the optional underscore and kind type parameter are not present, the LOGICAL literal is of default kind. Examples of valid LOGICAL literals are:

.false. .true. .true._mykind

In the last example, mykind must have been previously declared as a scalar INTEGER named constant with the value of a LOGICAL kind type parameter (1 or 4 in LF95). The first two examples are of type default LOGICAL.

Character Literals

A CHARACTER literal consists of a string of characters enclosed in matching apostrophes or quotation marks, optionally preceded by a kind type parameter and an underscore.

If a quotation mark is needed within a CHARACTER string enclosed in quotation marks, double the quotation mark inside the string. The doubled quotation mark is then counted as a single quotation mark. Similarly, if an apostrophe is needed within a CHARACTER string enclosed in apostrophes, double the apostrophe inside the string. The double apostrophe is then counted as a single apostrophe.

Examples of valid CHARACTER literals are

"Hello world"
'don''t give up the ship!'
ASCII_'foobeedoodah'
""
''

ASCII must have been previously declared as a scalar INTEGER named constant with the value 1 to indicate the kind. The last two examples, which have no intervening characters between the quotes or apostrophes, are zero-length CHARACTER literals.