Fortran

from Wikipedia, the free encyclopedia
Fortran
Title page of a 1956 manual
Basic data
Paradigms : procedural , imperative , structured , object-oriented
Publishing year: 1957
Designer: John W. Backus
Developer: John W. Backus , IBM
Current  version : Fortran 2018 (ISO / IEC 1539: 2018)   (2018)
Typing : static , strong
Important implementations : GNU Fortran , Intel , Flang , g95 , Open Watcom , XL Fortran and others
Influenced by: Speed ​​coding
Affected: Algol 58 , PL / I , BASIC
fortran-lang.org

Fortran is a procedural and , in its latest versions, an object-oriented programming language , which is used in particular for numerical calculations in science, technology and research. The name originated from FORmula TRANslation and was written with capital letters up to version FORTRAN 77.

history

Fortran is considered to be the first high-level programming language ever actually implemented . It goes back to a suggestion that John W. Backus , programmer at IBM , made to his superiors in 1953.

The design of the language was followed by the development of a compiler by an IBM team under the direction of Backus. The project started in 1954 and was originally designed to last six months. In fact, Harlan Herrick, the inventor of the later heavily criticized Goto instruction, was able to execute the first Fortran program on September 20, 1954. But it was not until 1957 that the compiler was found ready for the market and shipped with every IBM 704 system. Backus had insisted on equipping the compiler with the ability to optimize it right from the start: He foresaw that Fortran would only prevail if execution speeds similar to those of previous assembler programs were achieved.

Versions

Listing of a FORTRAN 77 program with compiler output (created in 1987 on a CDC 175 at the RWTH Aachen data center )
Punch card with preprinted FORTRAN line format

Fortran has been expanded several times. Many new language elements were initially introduced by a single manufacturer and later incorporated into the international standard. The versions that followed each other were FORTRAN I, FORTRAN II, FORTRAN IV, FORTRAN 66, FORTRAN 77, Fortran 90, Fortran 95, Fortran 2003, Fortran 2008, etc. From FORTRAN 66, Fortran is standardized by the ISO . The updating of the standards is a complicated process that often takes considerably longer than initially intended: The successor to the FORTRAN 77 standard published in 1978, which was called Fortran 8x, was originally planned for 1982, and later for 1985, and was finally adopted under the name Fortran 90 on April 11, 1991 as the new standard and successor to FORTRAN 77. In 2018, Fortran was released in 2018. The interoperability with C and functions related to parallel programming have been improved. Further innovations concern the floating point arithmetic on microprocessors , the input and output of hexadecimal numbers and implicit none.

Language elements

In the course of these expansions, numerous language elements were adopted from programming languages ​​that were created later. Early FORTRAN versions up to version 4 only had two different Goto instructions and the call of subroutines as flow control structure ; structured programming with loops was possible with FORTRAN 77. Fortran 90 allowed a freer format used by later programming languages in addition to the fixed line format from the punch card era . From Fortran 90, interesting elements are introduced that are also present in Ada , for example, optional parameters and the possibility of identifying procedure parameters not only by their position in the parameter list, but also by their name. Since Fortran 2003, polymorphic data types and inheritance are also supported, so that one can program object-oriented . Since Fortran 2008 with Coarray Fortran a parallelization built into the language that the PGAS follows scheme.

Example:

subroutine test(argument1, argument2, argument3)
    real,             intent(in)           :: argument1
    character(len=*), intent(in)           :: argument2
    integer,          intent(in), optional :: argument3
    ! Hier etwas Sinnvolles ...
end subroutine test

Possible calls are then e.g. B .:

call test(1.0, 'Tach')
call test(argument1=1.0, argument2='Tach auch')
call test(argument2='Tach Auch', argument1=1.0)
call test(argument3=3, argument1=1.0, argument2='Tach auch')

While the parameter association occurs with the first call via the order of the parameters, in the other examples the parameters are identified by their names. With the latter, the order no longer plays a role.

variants

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

properties

Fortran was and is intended and optimized for numerical calculations. From the beginning, Fortran had the power operator **- which is not available in many other high-level languages ​​- and a data type for complex numbers . With Fortran 90 vector and matrix operations were standardized. In addition, Fortran case is insensitive , i. H. In contrast to languages ​​like C or C ++ , the compiler does not differentiate between upper and lower case. It is in the style of the programmer whether he writes uppercase or lowercase, but in general you can see more and more often (e.g. in textbooks) the trend to write everything down.

Fortran has extensive libraries , especially for scientific and numerical calculations , which are still widely used, even if an increasing amount of functionality has since been ported to C and C ++.

Implicit variable declaration

Based on the use of mathematical notation, variables in Fortran are declared by default using their initial letters: Identifiers that begin with one of the letters i, j, k, l, m, n stand for an integer variable or an integer function value, all other identifiers stand for floating point numbers. This implicit type declaration of variables can be overwritten by declaring individual variables, it can be replaced by a line such as

! Alle nichtdeklarierten Bezeichner, deren erster Buchstabe c oder z ist,
! bezeichnen komplexe Zahlen.
implicit complex(c, z)

can be changed, and the implicit agreement can be changed by the command

implicit none

be canceled entirely. In this case, using an undeclared identifier will throw an error during translation. This considerably simplifies troubleshooting.

Transfer of parameters

Up to and including FORTRAN 77, subroutines did not have to be declared before they could be used. At most, the type of return value could be determined by a declaration. The compiler normally did not check whether a subroutine call was made with the correct parameters. The transfer of parameters to subroutines ( subroutineor function) is usually done by address. Before Fortran 90, basically all actual parameters could be changed from subroutineor function. Therefore, all parameters must e.g. B. be passed by address transfer. An automatic type conversion can therefore not take place.

Most Fortran systems also do not perform type checking at runtime. This is a common source of errors.

Program example 1:

call drucke_zahl(3.14)
! ...
subroutine drucke_zahl(meine_zahl)

In the subroutine drucke_zahl()is meine_zahlbecause with mimplicit starting when Integer declared. A call is made at runtime with the realargument 3.14. Then the integer variable is filled meine_zahlwith the bits of the floating point representation of 3.14- which leads to randomly absurd numerical results.

Many Fortran compilers pass parameters by reference . This sometimes leads to unintended results, for example the following program example 2:

program bsp_bar
    call bar(4)
    print *, 4
end program bsp_bar

subroutine bar(i)
    i = 42
end subroutine bar

Some compilers would output the number 42. However, the program is not correct like this.

Programming tools such as "ftnchek", however, allow a separate check of the correspondence of argument lists and would issue a warning in these cases. Current compilers also carry out such checks or generate a runtime error when assigning a value to a constant.

In Fortran 90 and subsequent versions, it is possible to define the parameter types of the subroutines using interfaces ( interface) and modules ( module). The compiler can thus check whether the transferred parameter type and the expected type match. However, this notification is not mandatory, as is the case in other programming languages ​​- for example Ada. The programming language F, derived from Fortran 95, enforces this; In F, only calls to subroutines are permitted whose parameter uselist is made known, for example, by statements. In a subroutine, you can also specify whether a parameter is an input parameter ( intent(in)), an output parameter ( intent(out)) or both ( intent(in out)). In Fortran 90, the subroutine bar is declared as follows:

subroutine bar(i)
  integer, intent(in) :: i
  ! ...
end subroutine bar

If the subroutine should try ito change the value of the actual parameter  , the compiler would display an error.

Dynamic memory allocation

Dynamic memory allocation means the possibility of requesting memory (especially for fields such as matrices) only when the program is running, i.e. the size of the arrays does not have to be specified when the program is compiled. A simple example:

real, allocatable :: a(:,:)

print *, 'Zeilen- und Spaltenzahl eingeben'
read (*, *) m, n
allocate(a(m, n))
! ...
deallocate(a)

Up to FORTRAN 77, dynamic memory allocation is not possible or only possible through non-standardized extensions by the compiler manufacturer. From Fortran 90, dynamic memory management is included in the language standard.

Another example of dynamic memory reservation: Creating and editing a linked list:

type element_t
    type(element_t), pointer :: naechstes
    real                     :: datum
end type element_t

type(element_t), pointer, save :: liste => null()
type(element_t), pointer       :: element

! Anlegen eines Elements und Eintragen am Anfang der Liste
allocate(element)

element%datum = 4711.0
element%naechstes => liste
liste => element

! Durchlaufen der Liste:
element => liste

do while (associated(element))
    call bearbeiten(element%datum)
    element => element%naechstes
end do

Compiler

Fortran compilers are available for practically all computers, from desktop computers to supercomputers .

Proprietary software

Commercial vendors of Fortran compilers are either computer manufacturers such as B. IBM, SUN, HP, Intel or specialized software manufacturers such as Absoft, PGI, NAG, Lahey, Salford. Pure FORTRAN 77 compilers are mostly no longer produced today, as FORTRAN 77 is almost completely contained in the Fortran 95 language standard (only DO loops with REAL iteration variables and Hollerith edit descriptors are no longer available in Fortran 95 and later).

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

Free software

From version 4.0 the GNU Compiler Collection (GCC) , which is available for practically all platforms, contains a compiler for Fortran 95 ( GNU Fortran ). Older versions of GCC still contain the FORTRAN-77 compiler g77. In addition, there is another free compiler for Fortran 95, G95. From this, gfortran emerged in 2003 as the new GNU Fortran compiler. Version 8.0 supports Fortran 2003 almost completely and Fortran 2008 to a large extent.

From version 4.4 “Luna” there is an integrated development environment for Eclipse .

The OpenWatcom developer suite also has a FORTRAN-77 compiler.

Transcompiler

There are transcompilers such as B. f2c for automatic translation of Fortran 77 (hardly human readable) in C . The NAG compiler also used C as an intermediate language in the past; however, the required runtime library was not available in the source code.

Language support

While most compilers fully support the Fortran 95 standard, in the case of the Fortran 2003 and Fortran 2008 language standards this still varies considerably (as of August 2010). Most compilers, however, already support large parts of the Fortran 2003 standard, or in the case of Cray and IBM, the standard practically completely.

Literature on the history of Fortran

  • Annals of History of Computing. Vol. 6, No. 1, 1984, ISSN  0164-1239
  • Saul Rosen (Ed.): Programming Systems and Languages. McGraw-Hill, New York NY et al. a. 1967.
  • Richard L. Wexelblat (Ed.): History of Programming Languages. Academic Press, New York NY et al. a. 1981, ISBN 0-12-745040-8 , pp. 25-74.
  • FORTRAN technical dictionary. In: sheets of the German Society for Insurance Mathematics. Vol. 8, H. 3, October 1967, pp. 499-520.

Literature on Fortran

  • Stephen J. Chapman: Fortran 90/95 for Scientists and Engineers. 2nd edition, international edition. McGraw Hill Higher Education, Boston MA a. a. 2004, ISBN 0-07-123233-8 .
  • Thomas Kühme, Peter Witschital: The FORTRAN primer. Structured programming with FORTRAN 77. Textbook and workbook for beginners. 3rd revised edition. Oldenbourg, Munich a. a. 1991, ISBN 3-486-22016-0 .
  • Michael Metcalf, John Reid, Malcolm Cohen: Fortran 95/2003 Explained . Oxford University Press, Oxford u. a. 2004, ISBN 978-0-19-852693-3 .
  • Michael Metcalf, John Reid, Malcolm Cohen: Modern Fortran explained . Oxford University Press, Oxford u. a. 2011, ISBN 978-0-19-960142-4 .
  • 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 u. a. 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 u. a. 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 a. a. 1996, ISBN 3-486-23896-5 .

Web links

Wikibooks: Fortran  - learning and teaching materials
Wiktionary: Fortran  - explanations of meanings, origins of words, synonyms, translations

Individual evidence

  1. heise online: Programming language: Fortran 2018 published. Retrieved December 6, 2018 .
  2. 60 years ago: IBM publishes first language specification for Fortran Heise online October 17, 2016
  3. ^ Foreword by Michael Metcalf in: WH Press, SA Teukolsky, WT Vetterling, BP Flannery: Numerical Recipes in Fortran 90 . Cambridge University Press, 1999, ISBN 0-521-57439-0 .
  4. Fortran 2018 in Fortran Wiki. Retrieved December 14, 2018 .
  5. ftnchek fordham.edu
  6. Photran - An Integrated Development Environment and refactoring tool for Fortran . eclipse.org
  7. ^ Ian D. Chivers, Jane Sleightholme: Compiler support for the Fortran 2003 standard . In: ACM SIGPLAN Fortran Forum , 29, 2, 2009, doi: 10.1145 / 1520752.1520755