Summary of FORTRAN statements: ------------------------------------- (This is not an exhaustive list. For a much more detailed summary see, for example, http://www.nsc.liu.se/~boein/f77to90/a2.html) Default conventions for numerical variable names, statement function names and function subprogram names: integer if the name starts with I, J, K, L, M, or N real otherwise. 1. Subprograms ----------- (i) SUBROUTINE name(arguments): defines name and arguments(if any) of a subroutine subprogram examples: SUBROUTINE MATIN(A,B) SUBROUTINE SOLVE (ii) FUNCTION name(arguments): defines name and argument(s) of a function subprogram. examples: FUNCTION MYFUNC(X) FUNCTION SUMA(A,B) MYFUNC takes a real argument, but returns an integer result, while SUMA takes two real arguments and returns a real value. The function name (MYFUNC or SUMA) must appear before the = sign in at least one assignment statement in the subprogram (iii) statement function : a single assignment statement with dummy argument(s) before the first executable statement example: AREA(X) = 3.141596*X*X 2. Declaration statements --------------------- (i) DIMENSION list : declares the size and shapes of arrays (ii) CHARACTER list : declares variables as character strings of specified length (default length 1) (iii)DATA list/values: assigns constant values to variables at compile time (iv) REAL list : declares the variables in the list as real (floating point); this overrides the implicit cnventions in FORTRAN. (v) INTEGER list : declares the variables in the list as integer; this overrides the implicit cnventions in FORTRAN. REAL, INTEGER as well as CHARACTER statements may also be used to declare array dimensions. The DIMENSION statement is now considered old fashioned! examples: DIMENSION A(10,10), P(15), LIN(10) REAL LAMP, B(10), KLAP(50) INTEGER Q, L(50), RL(5) CHARACTER*2 U, AQ, LIN CHARACTER KNAM(10) DATA PI,PLANC / 3.14159627, 6.626196E-27/ 3. Input/output (I/O) ------------------ (i) READ(*,*) list : format free read, waits at terminal for data entry READ(n,*) list : format free read from unit n (ii) WRITE(n,m) list : write onto unit n as per format given in statement number m examples: READ(3,*) A,B READ(K,10)(Q(I),I=1,5) WRITE(7,15)L, Z(L) WRITE(*,20) (iii)OPEN(n, FILE=name) : connects a file to unit number n. for name, substitute a character string in quotes or a character variable name examples: OPEN(3, FILE='MYDAT') OPEN(6, FILE=OFIL) (iv) st. no. FORMAT(list): controls representation of I/O data examples: 10 FORMAT(5X,F10.4,2X,I2) 200 FORMAT(2X,A4,5X,E11.4/2X, 5(F8.2,2X)) 111 FORMAT(//5X,'ENTER THE INPUT') 25 FORMAT(' AZV = ',E11.4, ' KP = ', I4) 4. Other executable statements --------------------------- (i) variable name = expression : arithmatic or character assignment statement examples : AQ = P*2.5/SQRT(X) R = 'ROOT' S = A(I)/P K = ABS(Y)/QA(2) (ii) CALL subroutine name(arguments) : begin execution of a subroutine with actual arguments corresponding to dummy arguments in the SUBROUTINE statement examples : CALL MATIN(X,B) CALL SOLVE (iii) GOTO st.number : jump to statement number example : GOTO 105 (iv) GOTO(st.number list) int : jumps to statement number in the list depending on the value of int example: GOTO(5,100,15,77,2) L (v) DO st.number var=starting value, ending value, step : loop over the following statements examples : DO 100 J = 1, 10, 3 (J will take values 1,4,7, and 10) DO 5 LA=N,M DO 12 KAT=N,M,I (vi) IF (logical expression) statement : statement executed if expression is true examples : IF(A.GT.B) B=2.*A IF(Q(I).EQ.P)GOTO 12 IF((A + ABS(B)).LE.SAY) WRITE(*,11)A,B IF((Y.GT.B).AND.(RUB.GT.CART)) GOTO 100 IF((L.LT.M).OR.(JAY.EQ.LAZ)) STOP (vii) IF (logical expression) THEN : following statements executed upto ELSE, ELSEIF or ENDIF, if expression is true (block IF) ELSE : following statements executed upto ENDIF if expression in block IF is false ELSEIF (logical expression) THEN : following statements executed upto ELSE, ELSEIF or ENDIF if previous block IF expression is false and current expression is true. ENDIF : terminates block IF segment examples: IF (A.LT.Z) THEN IF(X.LT.Y) THEN TEMP = A X=-X A=Z ELSE Z=TEMP Y=-Y ENDIF ENDIF IF(I.GT.0) THEN A=P(I)**2 J=I ELSEIF(I.EQ.-1) THEN A=Q(1)**2 J=I ELSE A=0 J=0 ENDIF (viii) st.number CONTINUE : may be used to terminate a Do loop example : DO 5 I=1,1000 .... .... 5 CONTINUE (ix) RETURN : returns control to the calling program from a subroutine example : SUBROUTINE MATIN(X,Y) ...... ...... RETURN (x) STOP : terminates program execution (xi) END : last statement ----------------------------------------------------------------- Partial list of built in functions: ---------------------------------- INT(r) : converts to integer. If A=-4.8, L=INT(A) will assign a value of -4 to L FLOAT(i): converts to floating point. If INZ=33, QART=FLOAT(INZ) will assign a value of 33.000... to QART ABS(r) : absolute value of a real (floating point) number IABS(i) : absolute value of an integer number AMOD(r1,r2) : BAT = AMOD(A,Y) will assign the value of A - INT(A/Y)*Y to BAT AMAX1(r1,r2,r3,...) : gives the maximum among the listed real arguments MAX0(i1,i2,..) : gives the maximum among the listed integer argmts. AMIN1(r1,r2,..) MIN0(i1,i2,i3....) SQRT(r) SIN(r) COS(r) TAN(r) ASIN(r) ACOS(r) ATAN(r) EXP(r) ALOG(r) or LOG(r) ALOG10(r) or LOG10(r) For a more complete list of such functions see, for example: http://www.amath.unc.edu/sysadmin/DOC4.0/fortran/f77rm/6_intrinsics.doc.html