Previous Table of Contents Next


1.2.1.4. The Fortran Character Set

A Fortran statement is a sequence of characters. The characters of the Fortran character set consist of the uppercase letters A to Z, the lowercase letters a to z, the digits 0 to 9, the underscore (_), and the special characters in Table 1.1.

Table 1.1. The Fortran special characters.

Character Name of Character

Blank
: Colon
= Equals
! Exclamation point
+ Plus
Quotation mark or quote
Minus
% Percent
* Asterisk
& Ampersand
/ Slash
; Semicolon
( Left parenthesis
< Less than
) Right parenthesis
> Greater than
, Comma
? Question mark
. Decimal point or period
$ Currency symbol
Apostrophe or single quote

The character set contains all required characters but may contain additional characters, such as the nonprintable characters tab or bell or additional printable characters, such as {.

These additional characters may appear in a Fortran program only within a comment or character constant.

Two of the characters, $ and ?, have no special use, and the currency symbol need not display or print as $ in all implementations.

1.2.2. The program Statement

Each Fortran program must begin with a program statement. It consists of the keyword program followed by a program name of the programmer’s choosing. A name must start with a letter and consist of at most 31 letters, digits, and underscores. Other Fortran names also follow these rules.

1.2.3. The end program Statement

The end program statement begins with the keywords end program, followed by the name of the program. Every Fortran program must have an end program statement as its last statement.

1.2.4. Intrinsic Data Types

The five intrinsic (in other words, built-in) data types in Fortran are integer, real, complex, logical, and character. Each data type has a set of values that may be represented in that type and operations that can be performed on those values.

1.2.4.1. The Integer Type

The integer type is used to represent values that are whole numbers. An integer constant is a string containing only the digits 0 to 9, possibly followed by an underscore (_) and a named integer constant, which designates the kind parameter, as described in section 1.2.5. The following are examples of integer constants:

   23 0 1234567 42_short 42_long

1.2.4.2. The Real Type

There are two forms of a real constant. The first is called positional form because the place value of each digit is determined by its position relative to the decimal point. The positional form of a real constant consists of an integer followed by a decimal point followed by a string of digits representing the fractional part of the value, possibly followed by an underscore and a kind parameter. Assuming that double and quad are names of integer constants that are permissible real kinds on the Fortran system being used, all the following are real constants written in positional form:

   13.5           0.1234567  123.45678
   00.30_double  3.0         0.1234567_quad

The exponential form of a real number consists of a real number written in positional form followed by the letter e and an optionally signed integer (without a kind parameter) and optionally followed by an underscore and kind parameter. The letter e is read as “times 10 to the power” and the integer following the e is a power of 10 to be multiplied by the number preceding the e. For example, 23.4e5 represents 23.4 × 105. Another example is 1.0e9_double, which is one billion with kind parameter double.

1.2.4.3. The Complex Type

The Fortran complex type is used to represent the mathematical complex numbers. A complex constant is written as two (possibly signed) real numbers, separated by a comma and enclosed in parentheses. Examples of complex constants are

   (1.0, -1.0)
   (-1.0, 3.1e-27)
   (3.14_double, -7.0_double)

1.2.4.4. Arithmetic Operators

The operators that may be used to combine two numeric values (integer, real, or complex) include +, , *, /, and **. Except for **, these symbols have their usual mathematical meaning indicating addition, subtraction, multiplication, and division. The two asterisks indicate exponentiation.

Integer division always produces an integer result obtained by chopping off any fractional part of the mathematical result. For example, the value of 23 / 2 is 11.

1.2.4.5. Relational Operators

Numeric (and character) values may be compared with the relational operators <, <=, ==, /=, >=, and >. The result of a relational operator is type logical.

1.2.4.6. Mixed-Mode Expressions

The two operands of a numeric operator do not have to be the same data type; when they are different, one is converted to the type of the other prior to executing the operation. If one is type integer and the other is type real, the integer is converted to a real value; if one is type integer and the other is type complex, the integer is converted to a complex value; if one is type real and the other is type complex, the real is converted to a complex value. As an example, the value of the expression 23.0 / 2 is 11.5. If the two operands have different kind parameters, the number whose kind parameter specifies lesser precision is converted to the kind with greater precision before the operation is performed.


Previous Table of Contents Next