Statement Format FORTRAN 77 requires a fixed format for programs FORTRAN 90/95 relaxes these requirements: allows free field input comments following statements (! delimiter) long variable names (31 characters) PROGRAM MAIN C COMMENTS ARE ALLOWED IF A “C” IS PLACED IN COLUMN #1 DIMENSION X(10) READ(5,*) (X(I),I=1,10) WRITE(6,1000) X 1000 FORMAT(1X,’THIS IS A VERY LONG LINE OF TEXT TO SHOW HOW TO CONTINUE ’ * ‘THE STATEMENT TO A SECOND LINE’,/,10F12.4) 1-5 Label 6 7-72 Statements 73-80 Optional Line #s Any character: continuation lineĨ Program Organization Most FORTRAN programs consist of a main program and one or more subprograms (subroutines, functions) There is a fixed order: Heading Declarations Variable initializations Program code Format statements Subprogram definitions (functions & subroutines)īasic data types are: INTEGER – integer numbers (+/-) REAL – floating point numbers DOUBLE PRECISION – extended precision floating point CHARACTER*n – string with up to n characters LOGICAL – takes on values. Make command) Executable File FORTRAN Program FORTRAN Compiler Link with Libraries Libraries Executable Code Source Code Object Code Make Changes in Source Code Test & Debug Program Execute Program
OBJECTIVES History and purpose of FORTRAN FORTRAN essentials Program structure Data types and specification statements Essential program control FORTRAN I/O subfunctions and subroutines Pitfalls and common coding problems Sample problemsĢ FORTRAN History One of the oldest computer languages Version historyĬreated by John Backus and released in 1957 designed for scientific and engineering computations Version history FORTRAN 1957 FORTRAN II FORTRAN IV FORTRAN 66 (released as ANSI standard in 1966) FORTRAN 77 (ANSI standard in 1977) FORTRAN 90 (ANSI standard in 1990) FORTRAN 95 (latest ANSI standard version) Many different “dialects” produced by computer vendors (one of most popular is Digital VAX Fortran) Large majority of existing engineering software is coded in FORTRAN (various versions)ģ Why FORTRAN FORTRAN was created to write programs to solve scientific and engineering problems Introduced integer and floating point variables Introduced array data types for math computations Introduced subroutines and subfunctions Compilers can produce highly optimized code (fast) Lots of available numerical-math libraries Problems encouraged liberal use of GO TO statements resulted in hard to decipher and maintain (“spaghetti”) code limited ability to handle nonnumeric data no recursive capabilityĤ FORTRAN Today FORTRAN 77 is “standard” but FORTRAN 90/95 has introduced contemporary programming constructs There are proprietary compilers Compaq/HP Visual Fortran Absoft Fortran Lahey Fortran There is a free compiler in Unix-Linux systems f77, g77 g95 (under development) Available scientific libraries LINPACK: early effort to develop linear algebra library EISPACK: similar to Linpack IMSL: commercial library ($’s) NAG: commercial library ($’s)ĥ Class Objectives Not nearly enough time to teach all the details of FORTRAN (which has evolved into a VERY complex language with many “dialects” …) We’ll try to highlight some of the most important features: that are confusing or often lead to problems, that appear in older programs written in FORTRAN 77 (or IV) that are quite different from contemporary languages For example: I/O instructions variable declarations subprograms: functions and subroutines We’ll look at some code fragments, and You’ll program a simple example problemįORTRAN is a complied language (like C) so the source code (what you write) must be converted into machine code before it can be executed (e.g.