Professional Documents
Culture Documents
Introduction to FORTRAN
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
by
Introduction
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
FORTRAN
FORTRAN = FORmula TRANslation Developed for the IBM 704 Computer Developed by John Backus and a team of 13 other programmers Developed between 1954 and 1957
Introduction
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
FORTRAN is a high-level language such as BASIC, C, and C++ A compiler translates each statement in the program into a sequence of basic machine language instruction
X = A* B + C
Dr. Assakkaf Slide No. 3
Introduction
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
Compiler
Object Program (machine language)
Program Development
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
A program consists of
Input An execution logic (computation) Output
Program Development
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
Computation
D V= h 4
2
Output:
Volume, V
Dr. Assakkaf Slide No. 6
Program Development
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
D h V= 4
END
A flow chart is a block diagram that summarizes the program structure and logic flow
Dr. Assakkaf Slide No. 7
Program Development
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
Computation
h= 4V
D
2
Output:
Height, h
Dr. Assakkaf Slide No. 8
Program Development
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
BEGIN
h=
4V
D 2
END
A flow chart is a block diagram that summarizes the program structure and logic flow
Dr. Assakkaf Slide No. 9
Fundamentals of FORTRAN
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
Fundamentals of FORTRAN
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
FORTRAN Statements
Positions 7 to 72 of a line can be used. To continue on the next line, use any character on position 6 of the next line
Constants
Examples
-12 1.2345 12.45-e10
Fundamentals of FORTRAN
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
1234567890123456789012345678901234567890123456789012345678901234567890 1234567890 C
Character different from 0 or blank in column 6 Indicates a continuation of the preceding line Statement labels in columns 1 to 5 C or * in column 1 indicates a comment
Fundamentals of FORTRAN
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
Data Types
Integer Real Double Precision Complex Character Logical
Fundamentals of FORTRAN
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
Variables
Variables starts with a letter The first letter defines the variable type
Integer or real
Fundamentals of FORTRAN
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
Type Statements
REAL list of variables INTEGER list of variables CHARACTER*n list of variables with size n (default n = 1) PARAMETER (param1 = value1, param2 = value2, .etc) DATA list1/data1/, list2/data2/, , listn/datan?
Dr. Assakkaf Slide No. 15
Fundamentals of FORTRAN
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
Fundamentals of FORTRAN
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
Arithmetic Operations
Addition Subtraction Multiplication Division Exponentiation + * / **
Fundamentals of FORTRAN
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
Priority Rules
** * and / + and from right to left from left to right from left to right
Fundamentals of FORTRAN
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
Fundamentals of FORTRAN
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
10
Fundamentals of FORTRAN
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
Examples:
PRINT * (print a blank line) PRINT *, Test, Test Test, Test PRINT *, Interest =, Int Interest = 5
Dr. Assakkaf Slide No. 21
Fundamentals of FORTRAN
A. J. Clark School of Engineering Department of Civil and Environmental Engineering
Examples:
PRINT *, Enter Velocity and Time? READ *, VELOC0, TIME READ *, Int, A Note: It is a good practice to prompt the user that input is needed, using PRINT statement before READ with prompt information
Dr. Assakkaf Slide No. 22
11
This program calculates the velocity and height of a projectile given its initial height, velocity,and constant acceleration
Height : h = Velocity : 1 2 at + v0t + h0 2 v = at + v0
PROGRAM PROJECT
C C C C C C C C
This program calculates the velocity and height of a projectile given its initial height, initial velocity, and constant acceleration. Variables used are: HGHT : initial height HGHT : height at any time VELOC : initial vertical velocity VELOC : vertical velocity at any time ACCEL : vertical acceleration (Gravity) TIME : time elapsed since projectile was launched REAL HGHT , HGHT, VELOC , VELO, ACCEL, TIME ACCEL = - . PRINT *, `Enter initial height, initial velocity, and time?` READ *, HGHT , VELOC , TIME HGHT = . * ACCEL * TIME ** +VELOC * TIME + HGHT VELOC = ACCEL * TIME + VELOC PRINT *, `AT TIME `, TIME, ` THE VERTICAL VELOCITY IS `, VELOC PRINT *, `AND THE HEIGHT IS `, HGHT END
Dr. Assakkaf Slide No. 24
12