Fortran
|
Fortran (also FORTRAN) is a statically typed, compiled programming language originally developed in the 1950s and still heavily used for scientific computing and numerical computation half a century later. The name is a portmanteau of Formula Translator/Translation. Early versions of the language were known as FORTRAN, but the capitalization has been dropped in newer revisions beginning with Fortran 90. The official language standards now refer to the language as "Fortran".
Although originally a procedural language, recent versions of Fortran have included some features to support object-oriented programming.
Contents |
History, versions, and revisions
The first FORTRAN compiler was developed for the IBM 704 in 1954–57 by an IBM team led by John W. Backus. This was an optimizing compiler, because the authors reasoned that no one would use the language if its performance were not comparable to assembly language.
The language was widely adopted by scientists for writing numerically intensive programs, which encouraged compiler writers to produce compilers that generate faster code. The inclusion of a complex number data type in the language made Fortran especially suited to scientific computation. There are many vendors of high performance Fortran compilers today. Many advances in the theory and design of compilers were motivated by the need to generate good code for Fortran programs.
Several standards of the language have appeared: FORTRAN II in 1958, FORTRAN IV in 1961, FORTRAN 66 in 1966, FORTRAN 77 in 1977 , Fortran 90 in 1990, Fortran 95 in 1995, and Fortran 2003 in 2003. (Fortran III was designed in 1958, allowing for inline assembler code; but it was never released because the portability concept of a high-level language would be lost.) Fortran 90 was a major revision, adding free source form, dynamic memory allocation, array operations, abstract data types, operator overloading, pointers, and modules to group related procedures and data together. Fortran 95 was a minor revision, adding features for parallel programming from the High Performance Fortran dialect, such as user-defined pure and elemental functions, and the forall construct. The most recent formal standard for the language, published in 2004, is known as Fortran 2003. It is an upwardly-compatible extension of Fortran 95, adding, among other things, support for IEEE floating-point arithmetic, exception handling, object-oriented programming, and improved interoperability with the C language. A comprehensive summary of the 2003 additions is at the ISO Fortran Working Group (WG5) web site, ftp://ftp.nag.co.uk/sc22wg5/N1551-N1600/N1579.pdf.
Features and extensions
Initially, the language relied on precise formatting of the source code and heavy use of statement numbers and goto statements. These quirks have been removed from newer versions of the language. Successive versions also introduced 'modern' programming concepts, such as source code comments and output of text, IF-THEN-ELSE (in FORTRAN 77), and parallel constructs, while still attempting to maintain Fortran's 'lean' profile and high performance. Among the most popular specialized Fortran-based languages were SAS, for generating statistical reports, and SIMSCRIPT, for simulating processes involving queuing. F is a clean subset of Fortran 95 that removes the unstructured features of Fortran, such as EQUIVALENCE.
Vendors of high performance scientific computers (Burroughs, CDC, Cray, Honeywell, IBM, Texas Instruments, UNIVAC...) added extensions to Fortran to make use of special hardware features such as: instruction cache, CPU pipeline , vector arrays, etc. For example, one of IBM's Fortran compilers (H Extended IUP) had a level of optimization which reordered the machine code instructions to keep several internal arithmetic units busy at the same time. Another example is CFD, a special 'version' of Fortran designed specifically for the ILLIAC IV supercomputer, running at NASA's Ames Research Center. These extensions have either disappeared over time or had elements incorporated into the main standard; the major remaining extension is OpenMP, which is a cross-platform extension for shared memory programming. One new extension, CoArray Fortran, is intended to promote parallel programming. There is a new programming language under development, Fortress, which is intended to be a replacement for Fortran.
Syntax drawbacks and advantages
As what was basically a first attempt at designing a high-level language, the language's syntax is regarded as arcane by many programmers who learned more modern languages. It is difficult to write a lexical analyser for, and one-character mistakes can lead to runtime errors rather than compilation errors if more recent constructs such as free-form source are not used. Some of the earlier versions, particularly, lacked facilities that would be regarded as useful in modern machines, such as dynamic memory allocation.
One should, however, consider that the features of Fortran have been tuned to scientific and numerical work, and that many of its deficiencies have been addressed in more recent versions. For example, Fortran 95 has very short commands for performing mathematical operations on arrays which not only greatly improve program readability but also provide useful information to the compiler to enable it to vectorize operations. For these reasons, Fortran is not often used outside scientific and engineering numerical work, but remains the language of choice for high performance numerical computing.
Sample programs
Hello World
A simple Hello World program to be compiled and run with any Fortran 90 or 95 compiler.
program hello print*,"Hello World!" end program hello
Cylinder Area
This program, which calculates the area of a cylinder, can be compiled and run with any Fortran 90 or 95 compiler. The text after the initial "!" on a line is a comment.
program cylinder ! Calculate the area of a cylinder. ! ! Declare variables and constants. implicit none ! Require all variables to be declared -- Fortran 90 feature. integer :: ierr real :: radius,height,area real , parameter :: pi = 3.14159 do ! Prompt the user for radius and height and read them. write (*,*) "Enter radius and height, 'q' to end." read (*,*,iostat=ierr) radius,height ! ! If radius and height could not be read from input, terminate program. if (ierr /= 0) stop "ending program" ! ! Compute area. The ** means "raise to a power". area = 2*pi*(radius**2 + radius*height) ! ! Write the input variables (radius, height) and output (area) to the screen. write (*,"(1x,'radius=',f6.2,5x,'height=',f6.2,5x,'area=',f6.2)") radius,height,area end do end program cylinder
A retro example of a Fortran IV (as it was called in 1968) program deck is available on the IBM 1130 page including the IBM 1130 DM2 JCL required for compilation and execution.
The standard Fortran joke
"GOD is REAL (unless declared INTEGER)."
References
General:
- Adams, Jeanne; Brainerd, Walter; Martin, Jeanne; Smith, Brian; Wagener, Jerrold (1997). Fortran 95 Handbook: Complete ISO/ANSI Reference. MIT Press.
- Metcalf, Michael; Reid, John; Cohen, Malcolm (2004). Fortran 95/2003 Explained. Oxford University Press.
- Nyhoff, Larry; Leestma, Sanford (1995). FORTRAN 77 for Engineers and Scientists with an Introduction to FORTRAN 90. 4th Edition. Prentice Hall. ISBN 013363003X.
Standards documents:
- ANSI X3.198-1992 (R1997). Title: Programming Language "Fortran" Extended. Informally known as Fortran 90. Published by ANSI.
- ISO/IEC 1539-1:1997. Title: Information technology - Programming languages - Fortran - Part 1: Base language. Informally known as Fortran 95. There are a further two parts to this standard. Part 1 has been formally adopted by ANSI.
- ISO/IEC 1539-1:2004. Title: Information technology -- Programming languages -- Fortran -- Part 1: Base language. Informally known as Fortran 2003.
External links
General
- Early Fortran Manuals (http://www.fh-jena.de/~kleine/history/)
- The Fortran Company: compilers, books, tutorials, consulting (http://www.fortran.com)
- Fortran Open Directory category (http://dmoz.org/Computers/Programming/Languages/Fortran/)
- Usenet forum: comp.lang.fortran (http://groups-beta.google.com/group/comp.lang.fortran)
- Fortran 90, 95 and 2003 information (http://www.kcl.ac.uk/kis/support/cit/fortran/f90home.html)
- USER NOTES ON FORTRAN PROGRAMMING (UNFP) (http://www.ibiblio.org/pub/languages/fortran/unfp.html)
- Unit 7.1 FORTRAN 77 (http://www.aspire.cs.uah.edu/textbook/index_f77.html) – Part of ASPIRE (http://www.aspire.cs.uah.edu/)'s textbook in Computational Science
- Unit 7.2 FORTRAN 90 (http://www.aspire.cs.uah.edu/textbook/index_f90.html) – Ditto
- How Not to Write FORTRAN in Any Language (http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=271) There are characteristics of good coding that transcend all programming languages.
Program repositories
- Fortran 90 Software Repository (http://www.nag.co.uk/nagware/Examples.asp)
- National HPCC software repository (http://www.nhse.org/)
- Netlib Repository (http://www.netlib.org/)
Proprietary compilers
- Absoft (http://www.absoft.com)
- Fujitsu (http://www.fr.fse.fujitsu.com/devuk/solaris.shtml)
- HP (http://h18009.www1.hp.com/fortran)
- IBM (http://www-306.ibm.com/software/awdtools/fortran)
- Intel (http://www.intel.com/software/products/compilers)
- Lahey (http://www.lahey.com)
- NA Software (http://www.nasoftware.co.uk/fortran-plus/index.html)
- NAG (http://www.nag.co.uk/nagware/NP.asp)
- PathScale (http://www.pathscale.com/products.html)
- Portland Group (http://www.pgroup.com)
- Salford (http://www.silverfrost.com/11/ftn95/overview.asp)
- Sun (http://developers.sun.com/prodtech/cc/compilers_index.html)
Free software compilers
- g95 -- Fortran 95 (under development) (http://www.g95.org/)
- Gfortran -- Fortran 95 (under development) (http://gcc.gnu.org/fortran/)
- Open Watcom -- Fortran 77 and C/C++ (http://www.openwatcom.org/)
- g77 -- Fortran 77 (http://www.gnu.org/software/fortran/fortran.html)
Template:Major programming languages smallca:Fortran cs:Fortran da:Fortran de:Fortran es:Fortran eo:Fortran (programlingvo) fr:Fortran ko:포트란 hr:Fortran ia:FORTRAN it:Fortran he:FORTRAN lt:Fortran nl:Fortran no:Fortran ja:FORTRAN pl:Fortran pt:Fortran ru:Фортран sk:Fortran sr:FORTRAN fi:Fortran sv:Fortran tr:FORTRAN zh:Fortran