PROGRAM sample C this is how you put in a comment C CALL sumArray C CALL arrays C CALL erroneous C CALL recurse(0) C CALL setCommon C CALL showCommon C CALL useFCN CALL shortIF END SUBROUTINE sumArray WRITE(*,*), 'What is your limit?' READ(*,*), limit CALL directly(limit) CALL inArray(limit) END SUBROUTINE directly(howmany) INTEGER howmany REAL current, sum, bigsum C I never use current. "g77 -Wall" warns me. sum = 0.0 C bigsum is accidentally not initialized. It has garbage. DO 10, I = 1, howmany C forgot to declare variable I bigsum = bigsum + (float(I)+0.1)**2; sum = sum + I**2; 10 CONTINUE WRITE(*,*), 'Directly: the sum is ', sum, 1 ' and the big sum is ', bigsum END SUBROUTINE inArray(howmany) INTEGER howmany REAL sum, bigsum DIMENSION intValues(howmany), realValues(howmany) REAL realValues INTEGER intValues DO 10, I = 1, howmany intValues(I) = I realValues(I) = I + 0.1 10 CONTINUE sum = 0.0 bigsum = 0.0 DO 20, I = 1, howmany sum = sum + intValues(I)**2 bigsum = bigsum + realValues(I)**2 20 CONTINUE WRITE(*,*), 'inArray: the sum is ', sum, 1 ' and the big sum is ', bigsum END SUBROUTINE arrays C demonstrates other features of Fortran DIMENSION array3(10, 10, 10) INTEGER array3 INTEGER row, col, plane C fill a 3-d array, using 3-way IF and GOTO statements DO 79 row = 1, 10 DO 79 col = 1, 10 DO 79 plane = 1, 10 IF (row + col - (2*plane)) 10, 20, 30 10 array3(row, col, plane) = -row; GOTO 79 20 array3(row, col, plane) = 0; GOTO 79 30 array3(row, col, plane) = col + plane; 79 CONTINUE C print out the array, using formatted output and DO notation in C output list DO 179 row = 1, 10 PRINT 1000, row 1000 FORMAT (4HRow , I3) DO 179 col = 1, 10 PRINT 2000, col, (array3(row, col, plane),plane = 1,10) 2000 FORMAT (' Column ', I3, ': ', 10I4) 179 CONTINUE END SUBROUTINE modify(x) INTEGER x x = 4 END SUBROUTINE erroneous WRITE(*,*) 'Three is ', 3 CALL modify(3) WRITE(*,*) 'Three is ', 3 END SUBROUTINE rhelp(depth) C direct recursion is not allowed, so we use indirect for "recurse()" INTEGER depth CALL recurse(depth) END SUBROUTINE recurse(depth) INTEGER depth WRITE(*,*) 'Depth is ', depth IF (depth - 5) 10, 10, 20 10 CALL rhelp(depth+1) 20 RETURN END SUBROUTINE setCommon COMMON A, B, C, I, J C using default types A = 1.0 B = 2.1 C = 3.2 I = 10 J = 20 END SUBROUTINE showCommon COMMON X, Y, I, J, K C using default types; I is a mistake, because the value is float. WRITE(*,*) 'Contents of common: ', X, Y, I, J, K END REAL FUNCTION quad(X) INTEGER X quad = 4*X END SUBROUTINE useFCN triple(X) = 3 * X REAL val; val = 3.1; WRITE(*,*) 'Three times ', val, ' is ', triple(val) WRITE(*,*) 'Four times ', val, ' is ', quad(IFIX(val)) END SUBROUTINE shortIF INTEGER X X = 30 IF (X .GT. 40) GOTO 39 RETURN 39 WRITE(*,*) 'X is big' END