Professional Documents
Culture Documents
A Fortran program consists of a series of statements designed to accomplish the goal of the
programmer. There are two basic types of statements: executable statements and non executable
statements.
Executable statements describe the actions taken by the program when it is executed (additions,
subtractions, multiplications, divisions, etc.), while non-executable statements provide information
necessary for the proper operation of the program.
Examples of executable statements- WRITE, READ, ASSIGNMENT STATEMENTS(add, subt,.....)
Examples of NON-exec. statements- IMPLICIT NONE
&
If a statement is too long to fit onto a single line, then it may be continued on the next line by ending
the current line (and optionally starting the next line) with an ampersand (&) character.
For example- the following three Fortran statements are identical
1. output = input1 + input2
2. output = input1 &
+ input2
3. output = input1 &
& + input2
“A statement label can be any number between 1 and 99,999. It is the “name” of a Fortran
statement, and may be used to refer to the statement in other parts of the program.
If a statement label is used, it must be unique within a given program unit. For example, if 100 is
used as a statement label on one line, it cannot be used again as a statement label on any other line
in the same program unit.”
“The STOP statement is a statement that tells the computer to stop running the program. The END
PROGRAM statement is a statement that tells the compiler that there are no more statements to be
compiled in the program”
“Any variable names beginning with the letters i, j, k, l, m, or n are assumed to be of type INTEGER.
Any variable names starting with another letter are assumed to be of type REAL”
The best way to achieve consistency and precision throughout a program is to assign a name to a
constant, and then to use that name to refer to the constant throughout the program.
Named constants are created using the PARAMETER attribute of a type declaration statement. The
form of a type declaration statement with a PARAMETER attribute is
Hierarchy of Operations
The order in which the arithmetic operations are evaluated is:
1. The contents of all parentheses are evaluated first, starting from the innermost parentheses and
working outward.
2. All exponentials are evaluated, working from right to left.
3. All multiplications and divisions are evaluated, working from left to right.
4. All additions and subtractions are evaluated, working from left to right.
In the hierarchy of operations, combinational logic operators are evaluated after all arithmetic
operations and all relational operators have been evaluated. The order in which the operators in an
expression are evaluated is:
1. All arithmetic operators are evaluated first in the order previously described.
2. All relational operators (==, /=, >, >=, <=) are evaluated, working from left to right.
3. All .NOT. operators are evaluated.
4. All .AND. operators are evaluated, working from left to right.
5. All .OR. operators are evaluated, working from left to right.
6. All .EQV. and .NEQV. operators are evaluated, working from left to right
ERRORS
Three types of errors are found in Fortran programs.
Syntax errors are errors in the Fortran statement itself, such as spelling errors or
punctuation errors. These errors are detected by the compiler during compilation.
A runtime error occurs when an illegal mathematical operation is attempted during program
execution (for example, attempting to divide by zero). These errors cause the program to
abort during execution.
Logical errors occur when the program compiles and runs successfully but produces the
wrong answer.