A Brief Review of FORTRAN 77 by John H. Mathews (to accompany "NUMERICAL METHODS: FORTRAN Programs", Prentice Hall, 1995). Specified Columns Each line of FORTRAN code must be written using the following column conventions. Column Contents 1 "C" or "*" for a comment line 1-5 Statement number or label (non-signed integer). 6 Blank or character for continuation line. 7-72 FORTRAN statement 73-80 Sequence number (usually omitted). Form of a FORTRAN Program PROGRAM {} {} END Form of a FORTRAN Subroutine SUBROUTINE [] {} {} RETURN END Form of a Subroutine call. CALL [] Form of a FORTRAN function [] FUNCTION [()] {} {} RETURN END Specification Statements (or Type Declaration Statements) INTEGER I,J,Row REAL A0,B0,Max,X,Y DOUBLE PRECISION LOGICAL A,B,C COMPLEX Z,W0 CHARACTER*10 Name IMPLICIT F,DF PARAMETER (Pi=3.1415926535) DATA E/2.178281828/ COMMON A0,B0 COMMON /BlockA/ A,B,X,Y Variables Variable names can be from one to six characters long. Variables beginning with I,J,K,L,M,N are presumed to be integers unless they are declared otherwise. Assignment Statements X = A(1) + 3 Y = A*X**2 + B*X + C Flag = .TRUE. Name = 'Fran' Warning. Mixed Mode arithmetic might result in some frustrating surprises. For example, when two integers are divided the result is an unexpected integer value. To avoid errors use explicit decimal points for real numbers and the intrinsic functions REAL, INT, DBLE, and CMPLX to get the required type conversion. Arrays DIMENSION A(1:50), M(1:10,1:10) Arithmetic Operations + Addition - Subtraction * Multiplication / Division ** Exponentiation Relational Operators .EQ. Equal to .NE. Not equal to .LT. Less than .GT. Greater than .LE. Less than or equal to .GE. Greater than or equal to Logical Operators .NOT. Complement .AND. True if both operands are true .OR. True if either (or both) operands are true Logical Constants .TRUE. .FALSE. Remark Statement C This is a comment. Place-holder Statement (or label) 10 CONTINUE Unconditional Transfer GOTO 10 Computed Control Statement Transfers control to a specified statement, depending on the value of an integer expression, e.g. . GOTO(100,200,300,400), IJUMP Warning. Do not use the GOTO statement to transfer into a DO, IF, ELSE, or ELSEIF block from outside the block. IF (Arithmetic) Control Statement Transfers control to a statement depending on whether the value of the () is positive, negative or zero. IF () 100, 200, 300 IF (Logical) Control Statement Executes a single statement only if the () is true. IF () GOTO 100 IF () WRITE (*,*) 'Yes' IF () X = A+B IF (Block) Control Statement Performs the series of {} following it or transfers control to an ELSEIF, ELSE, or ENDIF statement, depending on the value of the (). IF () THEN {} ENDIF IF () THEN {} ELSE {} ENDIF IF () THEN {} ELSEIF () THEN {} ELSEIF () THEN {}  ELSE {} ENDIF IF (ABS(P3-P1).LT.ABS(P3-P0)) THEN U=P1; P1=P0; P0=U V=Y1; Y1=Y0; Y0=V ENDIF IF (Df.EQ.0) THEN Dp=P1-P0 P1=P0 ELSE Dp=Y0/Df P1=P0-Dp ENDIF IF (YC.EQ.0) THEN A=C B=C ELSEIF ((YB*YC).GT.0) THEN B=C YB=YC KR=KR+1 ELSE A=C YA=YC KL=KL+1 ENDIF DO (Block) Control Statement DO K = M1, M2 {} ENDDO DO K = M1, M2, Mstep {} ENDDO DO (M TIMES) {} ENDDO SUM = 0 DO K=0,100,2 SUM = SUM + K ENDDO SUM = 0 DO K=100,-1,1 SUM = SUM + 1.0/REAL(K) ENDDO DO J=1,5 DO K=1,5 A(J,K) = 1.0/FLOAT(1+J+K) ENDDO ENDDO SUM = 0 DO K=1,10000 SUM = SUM + 1.0/REAL(K) IF (SUM.GT.5) EXIT ENDDO WHILE (Block) Control Statement WHILE () {} REPEAT SUM = 0 WHILE (K.LT.10000) SUM = SUM + 1.0/REAL(K) IF (SUM.GT.5) EXIT K = K+1 REPEAT Input and Output READ *, READ , READ , where is a FORMAT statement number, e.g. 111 FORMAT(5X,I10,4F15.5) PRINT * PRINT *, PRINT , PRINT , where is a FORMAT statement number, e.g. 999 FORMAT(5X,'X = ',F15.5) WRITE (*,*) WRITE (*,*) WRITE (*,N) where is a FORMAT statement number, e.g. 999 FORMAT(5X,'X = ',F15.5) Pause Statement PAUSE Stop Statement STOP Mathematical Functions COS(X) cosine (radians) SIN(X) sine (radians) TAN(X) tangent (radians) EXP(X) exponential exp(x) ACOS(X) inverse cosine (radians) ASIN(X) inverse sine (radians) ATAN(X) inverse tangent (radians) ALOG(X) natural logarithm base e LOG10(X) common logarithm base 10 SQRT(X) square root ABS(X) absolute value INT(X) conversion to integer FLOAT(I) conversion to real number type REAL(I) conversion to real number type DBLE(X) conversion to double precision type CMPLX(X) conversion to double precision type