1 / 16

FORTRAN 77 Programming.

FORTRAN 77 Programming. Lecture 3 : January 2001 Dr. Andrew Paul Myers. 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 :

delu
Download Presentation

FORTRAN 77 Programming.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. FORTRAN 77 Programming. Lecture 3 : January 2001 Dr. Andrew Paul Myers

  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

  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)

  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)

  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)

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

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

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

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

  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)

  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’/

  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.

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

  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)

  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

  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

More Related