3/9/2018

Part of the WikiBook The following Fortran code examples or sample programs show different situations depending on the compiler. The first set of examples are for the Fortran II, IV, and 77 compilers.

PROGRAMS WRITTEN IN FORTRAN PROGRAMMING LANGUAGE. Finding the roots of an equation using BISECTION method. Finding the roots of an equation using NEWTON'S method. Finding the roots of an equation using SECANT method. Finding the roots of a system of equations using NEWTON'S method. Fortran/Fortran examples. The following Fortran code examples or sample programs show different situations. Pointers and targets methods. Sep 19, 2013. Program Description. Program to demonstrate the Aitken acceleration subroutine; Explanation File of Program above (Aitken) NEW; Program to demonstrate the complex domain Allroot subroutine; Program to demonstrate the Bairstow subroutine (2 conjugate complex roots); Program to demonstrate the. Numerical Methods for Natural Sciences IB. Numerical Methods. Natural Sciences Tripos 1B. Lecture Notes. Lent Term 1999. © Stuart Dalziel. Department of Applied Mathematics and Theoretical Physics. University of Cambridge. Phone: (01223) 337911. E-mail: s.dalziel@damtp.cam.ac.uk.

The remaining examples can be compiled and run with any newer standard Fortran compiler (see the for lists of compilers). By convention most contemporary Fortran compilers select the language standard to use during compilation based on source code file name suffix: FORTRAN 77 for.f (or the less common.for), Fortran 90 for.f90, Fortran 95 for.f95. Other standards, if supported, may be selected manually with a command line option. Contents • • • • • • • • • • • • • • • • • • • • • • FORTRAN II, IV, and 77 compilers [ ] NOTE: Before FORTRAN 90, most FORTRAN compilers enforced fixed-format source code, a carryover from • comments must begin with a * or C!

In column 1 • statement labels must occur in columns 1-5 • continuation lines must have a non-blank character in column 6 • statements must start in column 7 • the line-length may be limited to 72 characters (derived from the 80-byte width of a punch-card, with last 8 characters reserved for (optional) sequence numbers) If errors are produced when you compile your FORTRAN code, first check the column alignment. Some compilers also offer free form source by using a compiler flag Area Of a Triangle program [ ] Simple Fortran II program [ ] One data card input If one of the input values is zero, then the program will end with an error code of '1' in the job control card listing following the execution of the program. Normal output will be one line printed with A, B, C, and AREA. No specific units are stated. C AREA OF A TRIANGLE - HERON'S FORMULA C INPUT - CARD READER UNIT 5, INTEGER INPUT C OUTPUT - READ ( 5, 501 ) A, B, C 501 FORMAT ( 3 I5 ) IF ( A.

0 ) STOP 1 S = ( A + B + C ) / 2.0 AREA = SQRT ( S * ( S - A ) * ( S - B ) * ( S - C ) ) WRITE ( 6, 601 ) A, B, C, AREA 601 FORMAT ( 4 H A =, I5, 5 H B =, I5, 5 H C =, I5, 8 H AREA =, F10. 2, $ 13 H SQUARE UNITS ) STOP END Simple Fortran IV program [ ] Multiple data card input This program has two input checks: one for a blank card to indicate end-of-data, and the other for a zero value within the input data. Either condition causes a message to be. C AREA OF A TRIANGLE - HERON'S FORMULA C INPUT - CARD READER UNIT 5, INTEGER INPUT, ONE BLANK CARD FOR END-OF-DATA C OUTPUT - LINE PRINTER UNIT 6, REAL OUTPUT C INPUT ERROR DISPAY ERROR MESSAGE ON OUTPUT 501 FORMAT ( 3 I5 ) 601 FORMAT ( 4 H A =, I5, 5 H B =, I5, 5 H C =, I5, 8 H AREA =, F10. 2, $ 13 H SQUARE UNITS ) 602 FORMAT ( 10 HNORMAL END ) 603 FORMAT ( 23 HINPUT ERROR, ZERO VALUE ) INTEGER A, B, C 10 READ ( 5, 501 ) A, B, C IF ( A.

0 ) GO TO 50 IF ( A. 0 ) GO TO 90 S = ( A + B + C ) / 2.0 AREA = SQRT ( S * ( S - A ) * ( S - B ) * ( S - C ) ) WRITE ( 6, 601 ) A, B, C, AREA GO TO 10 50 WRITE ( 6, 602 ) STOP 90 WRITE ( 6, 603 ) STOP END Simple Fortran 77 program [ ] Multiple data card input This program has two input checks in the READ statement with the END and ERR parameters, one for a blank card to indicate end-of-data; and the other for zero value along with valid data. In either condition, a message will be printed. C AREA OF A TRIANGLE - HERON'S FORMULA C INPUT - CARD READER UNIT 5, INTEGER INPUT, NO BLANK CARD FOR END OF DATA C OUTPUT - LINE PRINTER UNIT 6, REAL OUTPUT C INPUT ERROR DISPAYS ERROR MESSAGE ON OUTPUT 501 FORMAT ( 3 I5 ) 601 FORMAT ( ' A= ', I5, ' B= ', I5, ' C= ', I5, ' AREA= ', F10. Revo Uninstaller Pro Activation File more. 2, $ 'SQUARE UNITS' ) 602 FORMAT ( 'NORMAL END' ) 603 FORMAT ( 'INPUT ERROR OR ZERO VALUE ERROR' ) INTEGER A, B, C 10 READ ( 5, 501, END = 50, ERR = 90 ) A, B, C IF ( A = 0. C = 0 ) GO TO 90 S = ( A + B + C ) / 2.0 AREA = SQRT ( S * ( S - A ) * ( S - B ) * ( S - C ) ) WRITE ( 6, 601 ) A, B, C, AREA GO TO 10 50 WRITE ( 6, 602 ) STOP 90 WRITE ( 6, 603 ) STOP END 'Retro' FORTRAN IV [ ] A retro example of a FORTRAN IV (later evolved into FORTRAN 66) program deck is available on the page, including the IBM 1130 DM2 JCL required for compilation and execution. An IBM 1130 emulator is available at that will allow the FORTRAN IV program to be compiled and run on a.