You are on page 1of 4

FORTRAN

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.”

Fortran program unit is divided into three sections:


1. The declaration section. This section consists of a group of nonexecutable statements at the
beginning of the program that define the name of the program and the number and types of
variables referenced in the program.
2. The execution section. This section consists of one or more statements describing the actions to
be performed by the program.
3. The termination section. This section consists of a statement or statements stopping the
execution of the program and telling the compiler that the program is complete.

“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

REAL, PARAMETER :: PI = 3.141593

CHARACTER, PARAMETER :: ERROR_MESSAGE = 'Unknown error!'


Relational logic operators
== .EQ. Equal to
/= .NE. Not equal to
> .GT. Greater than
>= .GE. Greater than or equal to
< .LT. Less than
<= .LE. Less than or equal to

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

Function name Argument Result


and arguments type type Comments
INT(X) REAL INTEGER Integer part of x (x is truncated)
NINT(X) REAL INTEGER Nearest integer to x (x is rounded)
CEILING(X) REAL INTEGER Nearest integer above or equal to the value of x
FLOOR(X) REAL INTEGER Nearest integer below or equal to the value of x
REAL(I) INTEGER REAL Converts integer value to real
IMPLICIT NONE
IMPLICIT NONE statement disables the default typing provisions of Fortran. When the IMPLICIT
NONE statement is included in a program, any variable that does not appear in an explicit type
declaration statement is considered an error. The IMPLICIT NONE statement should appear after the
PROGRAM statement and before any type declaration statements.

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.

You might also like