Fortran

Fortran a procedural and in their latest version is also an object-oriented programming language that is used in particular for numerical computations. The name originated from FORmula TRANslation and was written to the FORTRAN 77 version with capital letters.

  • 2.1 Implicit variable declaration
  • 2.2 Passing Parameters
  • 2.3 Dynamic memory allocation
  • 2.4 Computed GOTO
  • 3.1 Proprietary software
  • 3.2 Free Software
  • 3.3 Trans compiler
  • 3.4 Language Support

History

Fortran is considered the first ever actually realized high-level language. It goes back to a proposal made by John W. Backus, Programmer at IBM, in 1953 his superiors submitted.

The design of the language followed by the development of a compiler by an IBM team led by Backus. The project began in 1954 and was originally designed for six months. Indeed, it was Harlan Herrick, the inventor of the later heavily criticized Goto statement, run the first Fortran program on 20 September 1954. But the compiler in 1957 was found to be ready for the market and supplied with every IBM 704 system. Backus had insisted from the beginning provide the compiler with the ability to optimizations: He foresaw that Fortran would only prevail if similar execution speeds as with previous assembler programs would be achieved.

Versions

Fortran has been extended several times. Many new language elements were first introduced by a single manufacturer and later adopted in the international standard. As versions followed each FORTRAN I, FORTRAN II, FORTRAN IV, FORTRAN 66, FORTRAN 77, Fortran 90, Fortran 95, Fortran 2000 Fortran 2003 Fortran 2008 and last Fortran 2010. Starting FORTRAN 66 Fortran is standardized by the ISO. The updating of standards is a complicated process that often takes much longer than initially targeted: The sequel to the 1978 published standards FORTRAN -77, which was designated as Fortran 8x, was originally planned for 1982, and later for 1985, and Fortran90 was finally adopted only on 11 April 1991 as the new standard and replacement of FORTRAN -77 under the designation.

In the course of these extensions many language elements were taken from programming languages ​​, developed later. Was previously based Fortran - style yet to goto statements, you can program 77 fully structured since FORTRAN. With a Fortran 90 programming languages ​​used by later freer format is allowed in addition to the fixed line format derived from the punch card time. From Fortran 90 interesting elements are introduced, which are also present, for example, in Ada, such as optional parameters and the possibility to identify procedure parameters not only on the position in the parameter list, but also by their name. Since Fortran 2003 polymorphic data types and inheritance are supported, so you can object oriented programming. And since Fortran 2008 with Coarray Fortran parallelization in the language installed, which follows the PGAS schema.

Example:

SUBROUTINE test ( Argument1, arg2, Argument3 )     REAL, INTENT ( IN) :: Argument1     CHARACTER ( LEN = * ), INTENT ( IN) :: arg2     INTEGER, INTENT ( IN), OPTIONAL :: Argument3    ! Here something useful. END SUBROUTINE Possible calls are then, for example:

CALL test (1.0, ' Tach ') CALL test ( Argument1 = 1.0, arg2 = ' Tach also ') CALL test ( arg2 = ' Tach also ' Argument1 = 1.0) CALL test ( Argument3 = 3, Argument1 = 1.0, arg2 = ' Tach also ') While the first call is carried out, the parameters of the association of the sequence parameter, in other examples, the parameters are identified by the name. In the latter, then the order does not matter.

Variants

Some derived from Fortran programming languages ​​are Ratfor, F and HPF (High Performance Fortran ).

Properties

Was Fortran and is intended for numerical computations and optimized. From the beginning, the Fortran exponentiation operator ** - the present is not in many other high-level languages ​​- and a data type for complex numbers. With Fortran 90 vector and matrix operations have been standardized. In addition, Fortran " case insensitive ", ie In contrast to languages ​​such as C or C is not distinguished by the compiler is case- sensitive. It is in the style of the programmer whether he writes big or small, generally one sees but more often (eg in textbooks ) the trend of small write everything down, like in C.

A Fortran program can be optimized more easily than, say, a C program, because Fortran is more restrictive. For example, it is not allowed to change the value of the iteration variable within an iteration loop. Among other things, therefore, the entry into the loop, the maximum number of passes is known.

! IFUNC () is a function that calculates an INTEGER value. ! The compiler must generate only one call of IFUNC. DO i = 1, IFUNC ( 4711 )    ! .. Meaningful here.    ! Within this loop, i may not be changed. ENDDO In C, such an iteration looks like this:

For (i = 1; i <= IFUNC ( 4711 ); i ) {      / * Useful here * /      / * It is allowed here, i to change * /   } The for loop in C is not a simple counting loop as in Fortran. The second argument ( here i <= IFUNC ( 4711 ) ) is a logical expression. The loop runs as long as the expression is true. On the other hand, so there are not simply the maximum value as a function result, there can be no assurance that IFUNC has no side effects, notwithstanding that it always returns the same result for 4711.

In particular, for scientific and numerical calculations are available in FORTRAN extensive libraries that are still widely used, although an increasing amount of functionality has now been ported to C and C .

Implicit variable declaration

Based on mathematical notation use variables in Fortran declared default on their initial letters: identifier, i, j, k, l, m, n start with one of the letters that stand for an INTEGER variable or an INTEGER function value, all other identifiers are for REAL values ​​. This implicit type declaration of variables can be overridden by declaring individual variables, they may as by a line

! All undeclared identifier whose first letter is c or z denote complex numbers. IMPLICIT COMPLEX (c, z) be changed, and the implicit agreement may using the command

IMPLICIT NONE be completely eliminated. In this case, the use of an undeclared identifier triggers an error during translation. This troubleshooting is simplified considerably.

Passing parameters

In old versions of Fortran ( FORTRAN 77 and earlier) needed subroutines not be declared before use. It could be defined by a declaration at best the type of the return value. The compiler normally did not consider whether a subroutine is called with the correct type parameters. Passing parameters to subroutines ( SUBROUTINE or FUNCTION ) usually takes place by address. Before Fortran 90 could in principle all actual parameters of a SUBROUTINE or FUNCTION be changed. Therefore, all parameters must be passed by address given, for example. An automatic type conversion can not take place therefore.

Most Fortran systems perform no type checking at runtime.

This is a frequent source of error. Program Example 1:

... CALL Prints number ( 3.14) ... SUBROUTINE Prints number (my number ) ... In the subroutine prints number is my number, because declared with m starting implicitly as INTEGER. At runtime, a call is made with the REAL argument 3.14. Then the INTEGER variable my number is padded with bits of floating point 3.14 - which leads to any outlandish numerical results.

Many Fortran compilers pass parameters by reference. This leads to some amusing results, such as the following program example 2:

Call bar ( 3) print *, 3 end subroutine bar ( i) i = 42 end This would in some compilers emit the number 42. The program is, however, not entirely correct.

However, programming tools like ftnchek allow separate examination of the conformity of argument lists and would warn in these cases.

In Fortran 90 and subsequent versions, it is possible, the parameter types of the programs based on interface (interface) and modules (modules) to be defined. The compiler can thus check whether the passed parameter type and the expected type match. However, this announcement is not mandatory, as in other programming languages ​​- the case - for example, Ada. The Fortran 95 programming language derived F enforces this, in F only subroutine calls are allowed, the parameter list are familiar, for example, through USE statements. In a subroutine can also specify whether a parameter is an input parameter ( INTENT ( IN) ), output parameters ( INTENT ( OUT) ) or both ( INTENT ( INOUT ) ) is. In Fortran 90 to declare the subroutine bar as follows:

Subroutine bar ( i) integer, intent ( in ) :: i [ ... ] end subroutine If the subroutine should try to change the value of the actual parameter i, the compiler would display an error.

Dynamic memory allocation

Under dynamic memory allocation is the ability, memory only to ask for (especially for fields such as matrices ) for the duration of the program, which means that the size of the array need not be determined prior to the time of the compilation of the program. Until Fortran 77 is a dynamic memory allocation, or only on non-standard extensions to the compiler manufacturer is possible. From Fortran 90, the dynamic memory management in the language standard is included.

An example of dynamic memory allocation: Creating and Editing a linked list:

TYPE tele ment      TYPE (tele ment ), POINTER :: The next      REAL :: Date   END TYPE tele ment   TYPE (tele ment ), POINTER, SAVE :: List = > NULL ()! - NULL (): Fortran 95       TYPE (tele ment ), POINTER :: element    ! Creating an element and submit at the beginning of the list   ALLOCATE ( element )   Element % date = 4711.0   The next element % => list   List = > Element    ! Through the list:   Element = > list   DO WHILE ( ASSOCIATED ( element ) )      CALL Edit ( item% date)      Item => item% The next   ENDDO Computed GOTO

A special feature is the so-called " Computed GOTO", are given in the three Anchor links and the program depending on whether the value of an expression is negative, zero or positive, jump to the first, second or third brand.

Compiler

Fortran compilers are available for virtually all computers, from personal computers to supercomputers.

Proprietary software

Commercial vendors of Fortran compilers are either computer manufacturers such as IBM, SUN, HP, Intel, or specialized software manufacturers such as Absoft, PGI, NAG, Lahey, Salford. Pure F77 compilers are nowadays usually no longer manufactured because Fortran 77 is almost entirely contained in the language standard Fortran95 (only DO loops with REAL iteration and Hollerith edit descriptors are in Fortran95 and later disappeared ).

Some of the above compilers are free of charge for private or non- commercial use, for example, the Linux version of the Intel Fortran compiler (Version 11), Sun Studio Express ( with Fortran, C and C compilers for Linux and Solaris), for Microsoft Windows, the compiler of Salford or DEC Fortran for OpenVMS.

Free Software

Since version 4.0, the practically available for all platforms GNU Compiler Collection (GCC ) includes a compiler for Fortran 95 (GNU Fortran ). Older versions of GCC listed the FORTRAN 77 compiler g77. In addition, with G95 There is another free compiler for Fortran 95 For this emerged in 2003 gfortran.

The OpenWatcom developer suite has a Fortran 77 compiler.

Trans compiler

There Trans compiler, such as F2C for automatic translation of Fortran 77 ( hardly readable ) C. Also, the NAG compiler intermediate language is used as a C; However, the necessary runtime library is not available in the source code.

Language Support

While most compilers support the Fortran95 standard full, this varies in the case of Language standards Fortran2003 and Fortran2008 some still significantly (August 2010). Most compilers already support either but large parts of the standards Fortran2003, or in the case of Cray and IBM standard practically complete.

Literature on the history of Fortran

  • Annals of History of Computing. Vol 6, No. 1, 1984, ISSN 0164-1239, John C. McPherson: Early Computers and Computing Institutions. Pp. 15-16, doi: 10.1109/MAHC.1984.10005;
  • Herbert S. Bright: Early Fortran user experience. Pp. 28-30, doi: 10.1109/MAHC.1984.10011;
  • Daniel N. Leeson: IBM FORTRAN Exhibit and Film. Pp. 41-48, doi: 10.1109/MAHC.1984.10000;
  • January Lee: An Annotated Bibliography of Fortran. Pp. 49-58, doi: 10.1109/MAHC.1984.10003.

Literature on Fortran

  • Stephen J. Chapman: Fortran 90/95 for Scientists and Engineers. 2nd edition, international edition. McGraw Hill Higher Education, Boston MA, inter alia, 2004, ISBN 0-07-123233-8.
  • Thomas Kühme, Peter Witschital: The FORTRAN Primer. Structured Programming with FORTRAN 77 teaching and work book for beginners. 3rd revised edition. Oldenbourg, Munich, and others, 1991, ISBN 3-486-22016-0.
  • Michael Metcalf, John Reid, Malcolm Cohen: Fortran 95/2003 Explained. Oxford University Press, Oxford, inter alia, 2004, ISBN 0-19-852693-8.
  • William H. Press, Saul A. Teukolsky, William T. Vetterling, Brian P. Flannery: Numerical recipes in Fortran 77 The Art of Scientific Computing (. = Numerical recipes in Fortran Vol. 1). 2nd edition. Cambridge University Press, Cambridge, inter alia, 1992, ISBN 0 - 521-43064 -X ( 2nd edition, reprinted with corrections. Ibid. 2003).
  • William H. Press, Saul A. Teukolsky, William T. Vetterling, Brian P. Flannery: Numerical Recipes in Fortran 90 The Art of Parallel Scientific Computing ( = Numerical recipes in Fortran Vol 2. ). 2nd edition. Cambridge University Press, Cambridge, inter alia, 1996, ISBN 0-521-57439-0 ( 2nd edition, reprinted with corrections. Ibid. 1999).
  • Günter Schmitt: Fortran 90 Course technically oriented. Introduction to Programming with Fortran 90 Oldenbourg, Munich, etc. 1996, ISBN 3-486-23896-5.
342980
de