Download presentation
1
Lecture 1 : January 2001 Dr. Andrew Paul Myers
FORTRAN 77 Programming. Lecture 1 : January 2001 Dr. Andrew Paul Myers 17/04/2017
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. 17/04/2017
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. 17/04/2017
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). 17/04/2017
5
Programming Languages.
You are users! How computers work. Machine code. High level languages. Fortran : FORMula TRANslation. Other languages : Basic C/C++ Pascal 17/04/2017
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. 17/04/2017
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 17/04/2017
8
Simple Structure of A FORTRAN Program.
Program name. Declare variables and structures. Assign values to variables. Process data. Print results. End program. 17/04/2017
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. 17/04/2017
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) 17/04/2017
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! 17/04/2017
12
Examples. Valid names : Invalid names : X THEDAY Min_cur Time28 X*Z
THE TIME 7YEARS _no_way$ 17/04/2017
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. 17/04/2017
14
Declarations. <Data Type> <variable> [,<variable(s)>] e.g. REAL x REAL radius,volume INTEGER loop,temp CHARACTER string*10,name*30 17/04/2017
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) 17/04/2017
16
Assignments. radius=2.5 y=z test=value+loop-temp
<variable> = <value> | <variable> | <expression> radius=2.5 y=z test=value+loop-temp volume=(4.0*pi*radius**3.0)/3.0 Expressions follow the BODMAS precedence rule. Operators +, -, *, / and ** 17/04/2017
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. 17/04/2017
18
Other Statements. PROGRAM [ program name ] END C or * A comment.
PRINT*,’Hello’ PRINT*,’Value of X = ‘,x This is free format output. 17/04/2017
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 17/04/2017
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. 17/04/2017
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”. 17/04/2017
22
General Program Layout.
PROGRAM [ program name ] [ comments ] [ declaration statements ] [ executable statements ] STOP END 17/04/2017
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. 17/04/2017
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.