Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 3 : January 2001 Dr. Andrew Paul Myers

Similar presentations


Presentation on theme: "Lecture 3 : January 2001 Dr. Andrew Paul Myers"— Presentation transcript:

1 Lecture 3 : January 2001 Dr. Andrew Paul Myers
FORTRAN 77 Programming. Lecture 3 : January 2001 Dr. Andrew Paul Myers 24/02/2019

2 Array Variables. An array is a simple structure, capable of storing many variables of the same type in a single data structure. Declare arrays with other variables. Arrays can be of any data type. Declaration : REAL array(100) INTEGER loop(20),data(500) CHARACTER names(10)*20 24/02/2019

3 More on Arrays. Each array member is addressable by an array subscript. e.g for REAL x(10), subscripts range from 1 to 10. i.e. array(1), … array(10) The subscript may be a constant, variable or expression : array(1)=SIN(x) array(loop)=4.0*array(loop-1) 24/02/2019

4 And There’s More… Consider : REAL array(10)
As mentioned before, array subscripts range from 1 to 10. We can over ride this default: REAL array(-10:10) INTEGER data(0:200) 24/02/2019

5 Still more… Arrays can be multi-dimensional REAL array(5,2)
i.e. array(1,1), array(1,2), array(2,1)… Taking things to an extreme!!! REAL array(5,0:12,20,-10:100) 24/02/2019

6 Iterations. Loops allow blocks of command to be repeated.
Simplest is the DO loop. DO <index> = <start>,<stop> [,<step>] <statement(s)> END DO 24/02/2019

7 Example DO Loop. INTEGER loop REAL array(100) DO loop=1,100,1
array(loop)=0.0 END DO 24/02/2019

8 DO WHILE Loop. Another type of loop : DO WHILE <condition>
<statement(s)> END DO Not in all versions of FORTRAN 77. 24/02/2019

9 Example. INTEGER test test=15 DO WHILE ( test .GT. 12 ) test=test-1
END DO Useful for repeating a program? 24/02/2019

10 The Horrible Past… DO loop with numeric label. DO 1000 loop=0,10,2
<statement(s)> 1000 CONTINUE Implied DO loop! READ*,(value(loop),loop=1,10,1) 24/02/2019

11 The DATA statement. Another method of assigning values to variables and arrays. REAL a,b,c INTEGER d(5),lots(100) CHARACTER single(5)*1 DATA a /1.5/ DATA b,c /2.5,5.6/ DATA d /1,2,3,4,5/ DATA lots /100*0.0/ DATA single /5*’Y’/ 24/02/2019

12 Advanced Data Types. Structures. Not in all versions of F77.
Structures can hold many variables of different types. Structures are declared with all other variables at the beginning of a program. With structures you can build powerful, custom data types. 24/02/2019

13 Declaring A Structure. STRUCTURE / book_type / CHARACTER title*80
CHARACTER author*40 INTEGER stock_level REAL price END STRUCTURE 24/02/2019

14 The Next Step… Now we must declare a record of the type defined in the structure. RECORD / book_type / science RECORD / book_type / rubbish(10) 24/02/2019

15 Value Assignments. Each part of the record is identified thus :
science.title = ‘2001’ science.author = ‘A.C.Clarke’ science.stock = 25 science.price = 9.99 24/02/2019

16 For the More Brave… Remember? RECORD / book_type / rubbish(10)
DO loop=1,10 READ’(A80)’,rubbish.title(loop) READ*,rubbish.price(loop) END DO 24/02/2019


Download ppt "Lecture 3 : January 2001 Dr. Andrew Paul Myers"

Similar presentations


Ads by Google