1 / 11

FORTRAN 77 Programming.

FORTRAN 77 Programming. Lecture 4 : January 2001 Dr. Andrew Paul Myers. The Story So Far…. FORTRAN 77 program structure. PROGRAM <program name> <comment(s)> <declaration(s)> <assignment(s)> <statement(s)> END. Intrinsic or Extrinsic?. So far we have seen :

jenis
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 4 : January 2001 Dr. Andrew Paul Myers

  2. The Story So Far… • FORTRAN 77 program structure. PROGRAM <program name> <comment(s)> <declaration(s)> <assignment(s)> <statement(s)> END

  3. Intrinsic or Extrinsic? • So far we have seen : value = SIN( angle_in_radians ) • Every angle has to be converted to radians with the same formula. Very repetitive!

  4. This Would Be Nice… • FORTRAN 77 does not have a degrees to radians function, but one would be useful. e.g. radians = RAD(degrees) or value = SIN ( RAD ( degrees ) )

  5. We Can Do It! • FORTRAN allows you to define your own functions! • They conform to all the rules of intrinsic functions. • Must return a single value. • Defined after the END statement of the main program.

  6. A Simple Function. REAL FUNCTION radians(degrees) REAL degrees,pi,temp pi=4.0*ATAN(1.0) temp=(pi*degrees)/180.0 radians=temp RETURN END

  7. More Complex. REAL FUNCTION power(x,y) REAL temp,x INTEGER loop,y temp=1 DO loop=1,y temp=temp*x END DO power=temp RETURN END

  8. Subroutines. • Another method for “structuring” your program. • Subroutines do not return a value. • Subroutines may change none, one or many of the parameters passed to them.

  9. Definition. SUBROUTINE print_at(message,line) CHARACTER message*80 INTEGER loop,line DO loop=1,line-1 print* END DO PRINT*,message RETURN END

  10. Calling Subroutines. • The CALL statement is used to call subroutines. • Parameter data types must match in the main program and subroutine. CALL print_at(‘Hello!’,10)

  11. Memory Allocation! • The compiler reserves memory for arrays. Consider… CALL bad(100) SUBROUTINE bad(n) INTEGER n REAL array(n)

More Related