2. How to get FORTRAN 95 Compiler
• Write FTN silverfrost in google and download it for free
3. History
• One of the oldest programming languages, the FORTRAN was
developed by a team of programmers at IBM led by John
Backus, and was first published in 1957.
• The name FORTRAN is an acronym for FORmula TRANslation,
because it was designed to allow easy translation of math
formulas into code.
• Often referred to as a scientific language, FORTRAN was the
first high-level language, using the first compiler ever
developed.
• Prior to the development of FORTRAN computer
programmers were required to program in machine/assembly
code, which was an extremely difficult and time consuming
task, difficult to debug the code.
4. Significant Language Features
• Simple to learn
• Machine Independent - allows for easy transportation of a program
from one machine to another.
• More natural ways to express mathematical functions - FORTRAN
permits even severely complex mathematical functions to be
expressed similarly to regular algebraic notation.
• Problem orientated language
• Remains close to and exploits the available hardware
• Efficient execution - there is only an approximate 20% decrease in
efficiency as compared to assembly/machine code.
5. Areas of Application
• Number crunching - due to the more natural (like it's true
algebraic form) way of expressing complex mathematical
functions and it's quick execution time, FORTRAN is easy and
efficient at processing mathematical equations.
• Scientific, mathematical, statistical, and engineering type
procedures -due to it's rapid number-crunching ability
FORTRAN is a good choice for these type of applications.
6. Basic Elements of Fortran Program
The Fortran Character Set
The following are valid in a Fortran 90/95 program:
alpha-numeric: a-z, A-Z, 0-9, and _ (the underscore);
arithmetic symbols: +, -, *, /, **
miscellaneous symbols: e.g.
, comma
. decimal point
< less than
etc
7. Structure of a FORTRAN Statement
A program consists of a series of statements
designed to accomplish the goal.
There are two basic types of statements:
Executable statements describe the actions taken
by the program (additions, subtractions,
multiplications, divisions).
Non-executable statements provide information
necessary for proper operation of the program.
8. Rules on Fortran statements:
Each line may be up to 132 characters long.
A statement too long to fit in a single line may be
continued on the next line by ending the
current line with an & (ampersand). e. g.
output = input1 + input2 ! sum the inputs
Commenting your code is very important. To
comment in FORTRAN, one uses the
exclamation point (!)
All comments after the ! are ignored by the
compiler
9. Structure of a Fortran Program
A FORTRAN program can be divided into three sections:
Declarations - This section consists of a group of non-executable
statements at the start of the program.
Execution - This section consists of one or more statements
describing the actions to be performed by the program.
Termination - This section consists of a statement (or
statements) telling the computer to stop/end running the
program.
10. The program reads two numbers as input,
multiplies them, and prints out the result
PROGRAM my_first_program
! Purpose:
! To illustrate some of the basic features of a
Fortran program.
!
! Declare the variables used in this program.
INTEGER :: i, j, k ! All variables are integers
! Get two values to store in variables i and j
WRITE (*,*) 'Enter the numbers to multiply: '
READ (*,*) i, j
11. Continued…
! Multiply the numbers together
k=i*j
! Write out the result.
WRITE (*,*) 'Result = ', k
! Finish up.
STOP
END PROGRAM my_first_program
12. Discussion of Program Above
The first statement of this program begins with the word
PROGRAM. This is a non-executable statement that
specifies the name of the program to the FORTRAN
compiler.
The name may be up to 31 characters long and be any
combination of alphabetic characters, digits, and the
underscore.
The first character must be a letter.
The PROGRAM statement must be the first line of the program.
13. The Declaration Section
This section begins with a comment stating that variable
declarations are to follow.
The declaration begins with the data type (INTEGER) followed by
two colons and then the variable name.
A comment follows the variable name. Every variable must be
commented as to its purpose in the program.
These statements are non-executable.
14. The Execution Section
The first statement in this section is the WRITE statement
that tells the user to enter the input.
The second statement will read the input and assign the
values to the corresponding variables.
The third statement multiplies the two variables and the
product is assigned to a third variable.
The last executable statement prints the product to the
screen.
15. The Termination Section
The STOP statement tells the computer to stop
running the program.
The use of the STOP command is optional here.
The END PROGRAM statement informs the
compiler that no more statements exist.
16. Compiling and Executing the FORTRAN Program
Before a program can be run (executed) it must be compiled into
an executable program.
In this process the code may also be linked to various system
libraries.
17. Variables and the IMPLICIT NONE
Checking a constant (e.g.7, 3.14156, 'John'), it is easy to
determine which type it may be. However, for a variable,
we must assign a type to that variable.
Assigning a type reserves the memory needed to store the data
expected (e.g.4 bytes for: 7 , 3.14156 and
2 bytes/letter for: 'John').