28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.
-
date post
21-Dec-2015 -
Category
Documents
-
view
232 -
download
0
Transcript of 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.
![Page 1: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/1.jpg)
18/04/23 1
FORTRAN 77 Programming.
Lecture 1 : January 2001
Dr. Andrew Paul Myers
![Page 2: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/2.jpg)
18/04/23 2
Course Methods.
Lectures. Handout notes. Supervised practical work. Daily submission of exercises. Daily feedback on exercises. Model Answers. Final project. Weekly clinic for final Project.
![Page 3: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/3.jpg)
18/04/23 3
Introduction.
A course in FORTRAN 77. Why FORTRAN? Objectives :
• General education in computing.• Introduction to programming.• First write a simple program, then…• Write complex program.
Course Benefits :• I.T. is a part of all our lives and getting more
so!• FORTRAN and computing skills for other
courses.• Future employment.
![Page 4: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/4.jpg)
18/04/23 4
Tools For The Job.
Programming Environment :
CFS system and Exceed 6.2. Unix system (SG IRIX 6.5). Silicon Graphics Desktop Windows Text Editor (emacs). FORTRAN 77 Compiler (Mips 7.2.1). Workshop Debugger (cvd).
![Page 5: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/5.jpg)
18/04/23 5
Programming Languages. You are users! How computers work. Machine code. High level languages. Fortran : FORMula TRANslation. Other languages :
• Basic• C/C++• Pascal
![Page 6: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/6.jpg)
18/04/23 6
Programming Cycle.
Analyse the task. Plan the program, a structured
approach! Flowcharts & Dry running. Edit your source code. Compile and link program. Execute and debug program. Edit and recompile as necessary.
![Page 7: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/7.jpg)
18/04/23 7
IRIX f77 Compiler.
Edit source program (*.f) with “emacs” editor. Save file.
Compile and run on Unix command line in a shell window :/disk/n/gps> f77 –o test test.f
/disk/n/gps> test
![Page 8: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/8.jpg)
18/04/23 8
Simple Structure of A FORTRAN Program.
Program name. Declare variables and structures. Assign values to variables. Process data. Print results. End program.
![Page 9: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/9.jpg)
18/04/23 9
Flow of a Program.
Linear sequence. One command per line. Position on line : Very Important! Comments Statements (ignored). Repetition : Loops. Selections : Conditional statements. Always finish with an END statement.
![Page 10: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/10.jpg)
18/04/23 10
Position on a line.
The layout of FORTRAN program dates back to old 80 column punched cards, which were used for program input.
1 2-5 6 7-72 73-80
Total=x_value+y_value
& +z_value
C Comment line.
9 9999 FORMAT(‘Answer =‘,I4)
![Page 11: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/11.jpg)
18/04/23 11
Variable Declarations.
Variable names : Must be at least one alphabetic
character long, up to a maximum of 31 alphanumeric characters.
Must start with an alphabetic character. Case insensitive.
Alphanumeric characters are : a-z, 0-9 and the underscore ( _ ).
Implicit variables. I to N integers!
![Page 12: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/12.jpg)
18/04/23 12
Examples.
Valid names :• X
• THEDAY
• Min_cur
• Time28
Invalid names :• X*Z
• THE TIME
• 7YEARS
• _no_way$
![Page 13: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/13.jpg)
18/04/23 13
Basic Data Types.
REAL x=5.0 INTEGER i=20 COMPLEX z=(1.4,3.2) LOGICAL test=.TRUE. CHARACTER char=‘Hello’
More advanced data types can be made from these basic types.
![Page 14: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/14.jpg)
18/04/23 14
Declarations.
<Data Type> <variable> [,<variable(s)>]
e.g.
REAL x
REAL radius,volume
INTEGER loop,temp
CHARACTER string*10,name*30
![Page 15: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/15.jpg)
18/04/23 15
Parameters.
Parameters are constants, their value, once defined, can not be changed.
REAL g,pi
INTEGER days
PARAMETER (days=365)
PARAMETER (g=9.81,pi=3.142)
![Page 16: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/16.jpg)
18/04/23 16
Assignments.
<variable> = <value> | <variable> | <expression>
radius=2.5y=ztest=value+loop-tempvolume=(4.0*pi*radius**3.0)/3.0
Expressions follow the BODMAS precedence rule. Operators +, -, *, / and **
![Page 17: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/17.jpg)
18/04/23 17
Control Structures.
Basic building blocks of programs.
They control the flow of the program.
There are 3 different types :
Linear Sequence. Selection. Iteration or Loop.
![Page 18: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/18.jpg)
18/04/23 18
Other Statements.
PROGRAM [ program name ] END
C or * A comment.
PRINT*,’Hello’ PRINT*,’Value of X = ‘,x
This is free format output.
![Page 19: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/19.jpg)
18/04/23 19
Data Input.
Programs are useless without data! Use the READ statement to allow
users to input data. Prompt user for the data too!
e.g.
PRINT*,’Enter values for x & y :’
READ*,x,y
![Page 20: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/20.jpg)
18/04/23 20
Character Input.
A normal read statement can not be used to enter character variables. Use the following:
PRINT*,’Continue (y/n) : ‘
READ ‘(A1)’,yes_or_no
‘(A<n>)’ – <n> is the number of characters.
![Page 21: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/21.jpg)
18/04/23 21
Good Programming Style.
Comment your program! FORTRAN keywords in upper case. Variables in lower case. Use descriptive variable names. Blanks may be used to improve
readability. Indent code with “tabs”.
![Page 22: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/22.jpg)
18/04/23 22
General Program Layout.
PROGRAM [ program name ]
[ comments ]
[ declaration statements ]
[ executable statements ]
STOP
END
![Page 23: 28/06/20151 FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers.](https://reader036.fdocuments.us/reader036/viewer/2022081419/56649d645503460f94a471c3/html5/thumbnails/23.jpg)
18/04/23 23
References.
A Crash Course in FORTRAN 77.Donald M. Monro.(Edward Arnold).
Irix Insight On-line Help.SGI Developer Section.MIPSpro FORTRAN 77 Programmer’s guide.