The FORTRAN Programming Language 

 

Handling of Data Objects

Types and Declaration
FORTRAN includes built in types for integers, real numbers of 2 sizes, complex numbers, Boolean values, and characters. Declarations name the type and the name of the variable, e.g., INTEGER :: <list of variables>.   Multiple variable names may be separated by commas in the same statement.

Integers
Integers are positive or negative numbers without decimals or fractions. '-' and '+' are unary operators denoting negative or positive integers. If no operator is designated, the value is positive.

Real Numbers
FORTRAN provides both decimal and exponential notation representations for Real number constants. Double precision constants use 'D' instead of 'E' for exponential representations, e.g., 2.678E6, 3.665D-4.

Complex Numbers
Complex constants are represented by an ordered pair enclosed in parenthesis. The first number is the real part, and the second the imaginary. Each of these can be either constant or variable integer or real values, e.g., (5, -17), (4.5, 7.50E4).  Double precision is not allowed.

Logical Values
Only two logical values are allowed, ".TRUE." and ".FALSE."

Characters
Character constants are usually used as an array called a string. These consist of characters enclosed in single quotes. Two sequential single quotes are used to represent one single quote character in the string, e.g.,  'Anything HERE.'.

Assignment and Type Conversion
FORTRAN uses '=' as the assignment operator, e.g., x = 9.

FORTRAN allows for both implicit and explicit type conversion in assignment and expression. For example, integers in expressions with real numbers or variables will be converted to their integer equivalents for the purpose of evaluation. Some functions for explicit type conversion are:
 

to integer

INT

to real

REAL

to double precision

DBLE

from character to integer

ICHAR

from integer to character

CHAR

String Implementation
FORTRAN 77 and FORTRAN 90 both use static length strings whose size is declared with the variable, e.g., CHARACTER (LEN = 20) name1 {,name2}.

The catenation operator '//' can be used to join two strings into one, e.g., j = ' Join these toget'//'her'.

Arrays and their Implementation
The subscripts in FORTRAN I, II, and IV used 1 as the beginning array subscript. FORTRAN 77 and 90 use 1 as the default, but the range can be specified. FORTRAN uses parenthesis for array indexes. Of course such reference can be easily confused with function calls. This can be a problem because FORTRAN allows separate compilation of procedures. If the array is declared elsewhere, it may not be possible to determine the nature of the statement. FORTRAN does not require range checking of subscripts. In early versions of FORTRAN the number of subscripts was limited to 3. Currently, the number of allowed subscripts is seven.

In FORTRAN 77, all arrays and subscripts are statically bound. These arrays can be initialized using the DATA statement. FORTRAN 90 provides dynamic arrays through the use of the ALLOCATABLE label and the ALLOCATE statement and memory recovery with DEALLOCATE.
 

                                           INTEGER, ALLOCATABLE, ARRAY (:,:) :: Matrix

                                           ALLOCATE (Matrix(10, variable))

                                           DEALLOCATE (Matrix)

FORTRAN 77 does not include array operations. However, FORTRAN 90 makes elemental operators available along with matrix and vector library functions. FORTRAN 90 also provides for array slices. Ranges are divided by colons and slices can be treated as arrays of the same dimensions, e.g., Cube(1:3, 2, 1:2).  The example could be treated as a 3 x 1 x 2 array or modified into another shape using EQUIVALENCE. Irregular slices, and element lists are also allowed. FORTRAN uses column major order.

Records
Pre-90's versions of FORTRAN did not include records. FORTRAN 90 allows records to be declared with TYPE. Records must be type declared before being nested. Reference for record fields move from the largest enclosing record to the smallest. The names are separated by '%'.

Free Unions
FORTRAN provides a free union construct without type checking using EQUIVALENCE.

Pointers
FORTRAN 77 doesn't provide pointers to programmers. FORTRAN 90 has pointers that are automatically dereferenced, e.g., INTEGER, POINTER :: int_ptr

Variables that can be pointed to must have TARGET in their declaration. DEALLOCATE is used to regain memory, and the dereferencing of pointers can be turned off.