Fortran: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Paul Wormer
No edit summary
imported>Paul Wormer
No edit summary
Line 8: Line 8:
From the end of the 1950s onward, many important computer language concepts were developed, such as [[recursion (computer)|recursion]], dynamic storage allocation, local and global variables,  if then else statements, etc. When at the end of the 1960s it was decided that a more modern variant of Fortran was needed (that later came to be known as Fortran-77), there was much pressure to extend the language with such constructs. However, this was successfully  resisted by programmers who feared that  their introduction would be  at the expense of the numerical efficiency of the language. At  that time very sophisticated  Fortran optimizing compilers were used for the numeric intensive work  and it was feared that concepts as recursion would impede the optimization.  In consequence, the Fortran-77 standard does not allow recursion, dynamic storage allocation and local variables. It does, however, allow more extended "if statements" and "loop" structures than its predecessors. Also character handling facilities were introduced into Fortran-77.   
From the end of the 1950s onward, many important computer language concepts were developed, such as [[recursion (computer)|recursion]], dynamic storage allocation, local and global variables,  if then else statements, etc. When at the end of the 1960s it was decided that a more modern variant of Fortran was needed (that later came to be known as Fortran-77), there was much pressure to extend the language with such constructs. However, this was successfully  resisted by programmers who feared that  their introduction would be  at the expense of the numerical efficiency of the language. At  that time very sophisticated  Fortran optimizing compilers were used for the numeric intensive work  and it was feared that concepts as recursion would impede the optimization.  In consequence, the Fortran-77 standard does not allow recursion, dynamic storage allocation and local variables. It does, however, allow more extended "if statements" and "loop" structures than its predecessors. Also character handling facilities were introduced into Fortran-77.   


The Fortran-90 variant, that appeared at the end of the 1990s, allows recursion, dynamic storage allocation, case statements, and a construct that is reminiscent of [[object (computers)|object]]s used in object oriented languages, namely modules. Fortran-90  allows handling of arrays as one entity.
The Fortran-90 variant, that appeared during the 1990s, allows recursion, dynamic storage allocation, case statements, and a construct that is reminiscent of [[object (computers)|object]]s used in object oriented languages, namely modules. Fortran-90  allows handling of arrays as one entity.


The latest standard, Fortran-2003, supports object-oriented and generic programming.
The latest standard, Fortran-2003, supports object-oriented and generic programming.
==Some features of the language prior to Fortran 90==
As stated earlier, much old (written before the 1990s) Fortran code is still in use. It is therefore of interest to discuss some of the features of the older versions of the language.
The majority of statements are simply assignment statements of the form
<pre>
      A = expression
</pre>
where the expression is first fully evaluated and then assigned to the variable named A.
===Implicit typing===
Fortran 77 introduced character data, before that time Fortran only recognized real (floating point) numbers, integer numbers, and logicals (booleans). Names of variables had to begin with a letter.
Only logicals had to be declared explicitly. The real and integer variables were implicitly declared by the rule: all variables with names beginning with I, J, K, L, M, and N are integer, the variables of which the names start with the other letters are real.
The oldest Fortran variants only allowed variable names of maximally 6 characters, which gave rise to names as "CNVRG" for "convergence", etc. Moreover, Fortran was strictly in capital letters.
===Fixed format===
Fortran-90 introduced free format, until that time Fortran statements have a fixed format.
The format of the statements was adapted to [[punch card]]s. The first column can contain the letter "C" indicating a comment card. Usually the first five columns of the card are either blank or contain a numeric label. The 6th column is preserved for a continuation  character, if any non-blank character is in this position the statement is interpreted as the continuation of the previous statement. Column 7 through 72 contains the actual statement where blanks are completely ignored, they are optionally used to improve readability by humans.
 
===Change of execution flow===
The oldest Fortran variants knew only the "arithmetic if". This is a statement of the form
<code>
      IF (N) 10, 20, 30
</code>
where execution continues at the statements  labeled  10, 20, or 30 for  N <0 , N = 0 and N > 0, respectively.  Labels contained in columns 1 through 5 can be any unique set of up to 5 digits.
Later the "logical if" was added that was usually used in conjunction with a "goto" statement, for example
<pre>
      IF (N .ge. M) GO TO 1234
</pre>
If N &ge; M execution continues with the statement carrying the label 1234.
Fortran 77 knows the "if (a) then ... else ... endif" construct, where a is either true or false. This construct does not need labels, while  prior to Fortran 77 programs were plagued by a multitude of labels.
===Subroutines and functions===
A Fortran program can be separated into smaller independent subprograms that at load/link time are combined to one executable program. These are "subroutines" that have a number of parameters that are input, output, or both and "functions" that have input parameters and return a single value.
===Common blocks and blank commons===
As stated, Fortran did not explicitly distinguish local and global variables. As a matter of fact, most compilers made local copies of variables, and kept arrays global. To provide for global variables Fortran knows "common blocks", either named or unnamed (blank).  These are memory areas that are assigned to the program at load time.
'''(To be continued)'''

Revision as of 06:45, 31 July 2009

This article is developing and not approved.
Main Article
Discussion
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
Catalogs [?]
 
This editable Main Article is under development and subject to a disclaimer.

Fortran (Formula translation) is the oldest high-level computer language. It was the first computer language that put humans before computers, meaning that Fortran programmers did not have to know machine instructions, but instead could use statements that largely coincide with mathematical formulas.

Fortran being the oldest language, there is an enormous legacy in the scientific and engineering communities of Fortran programs, some of them as large as a million statements. It has always been the primary language for intensive (super)computing tasks, such as weather and climate modeling, oil reservoir simulation, computational fluid dynamics, computational chemistry, computational economics, and computational physics. Since the existing body of Fortran programs is too large to rewrite into a more modern language, it is likely that Fortran is here to stay. A very noticeable feature of all Fortran variants that have appeared so far is their "upward compatibility". In principle, a modern Fortran compiler can still translate a Fortran program written in, say, 1959 into the machine language of a present day computer.

The first version of the language was developed in 1954 by an IBM team lead by John Backus. This version, known as Fortran I, was mainly restricted to IBM computers (notably the IBM 704). In 1958 a variant, known as Fortran II, was introduced that was also implemented by other computer companies. In 1966 the first standard endorsed by the American Standards Association (now ANSI) was established, Fortran-66.

From the end of the 1950s onward, many important computer language concepts were developed, such as recursion, dynamic storage allocation, local and global variables, if then else statements, etc. When at the end of the 1960s it was decided that a more modern variant of Fortran was needed (that later came to be known as Fortran-77), there was much pressure to extend the language with such constructs. However, this was successfully resisted by programmers who feared that their introduction would be at the expense of the numerical efficiency of the language. At that time very sophisticated Fortran optimizing compilers were used for the numeric intensive work and it was feared that concepts as recursion would impede the optimization. In consequence, the Fortran-77 standard does not allow recursion, dynamic storage allocation and local variables. It does, however, allow more extended "if statements" and "loop" structures than its predecessors. Also character handling facilities were introduced into Fortran-77.

The Fortran-90 variant, that appeared during the 1990s, allows recursion, dynamic storage allocation, case statements, and a construct that is reminiscent of objects used in object oriented languages, namely modules. Fortran-90 allows handling of arrays as one entity.

The latest standard, Fortran-2003, supports object-oriented and generic programming.

Some features of the language prior to Fortran 90

As stated earlier, much old (written before the 1990s) Fortran code is still in use. It is therefore of interest to discuss some of the features of the older versions of the language.

The majority of statements are simply assignment statements of the form

      A = expression

where the expression is first fully evaluated and then assigned to the variable named A.

Implicit typing

Fortran 77 introduced character data, before that time Fortran only recognized real (floating point) numbers, integer numbers, and logicals (booleans). Names of variables had to begin with a letter. Only logicals had to be declared explicitly. The real and integer variables were implicitly declared by the rule: all variables with names beginning with I, J, K, L, M, and N are integer, the variables of which the names start with the other letters are real.

The oldest Fortran variants only allowed variable names of maximally 6 characters, which gave rise to names as "CNVRG" for "convergence", etc. Moreover, Fortran was strictly in capital letters.

Fixed format

Fortran-90 introduced free format, until that time Fortran statements have a fixed format. The format of the statements was adapted to punch cards. The first column can contain the letter "C" indicating a comment card. Usually the first five columns of the card are either blank or contain a numeric label. The 6th column is preserved for a continuation character, if any non-blank character is in this position the statement is interpreted as the continuation of the previous statement. Column 7 through 72 contains the actual statement where blanks are completely ignored, they are optionally used to improve readability by humans.

Change of execution flow

The oldest Fortran variants knew only the "arithmetic if". This is a statement of the form

      IF (N) 10, 20, 30

where execution continues at the statements labeled 10, 20, or 30 for N <0 , N = 0 and N > 0, respectively. Labels contained in columns 1 through 5 can be any unique set of up to 5 digits.

Later the "logical if" was added that was usually used in conjunction with a "goto" statement, for example

       IF (N .ge. M) GO TO 1234

If N ≥ M execution continues with the statement carrying the label 1234.

Fortran 77 knows the "if (a) then ... else ... endif" construct, where a is either true or false. This construct does not need labels, while prior to Fortran 77 programs were plagued by a multitude of labels.

Subroutines and functions

A Fortran program can be separated into smaller independent subprograms that at load/link time are combined to one executable program. These are "subroutines" that have a number of parameters that are input, output, or both and "functions" that have input parameters and return a single value.

Common blocks and blank commons

As stated, Fortran did not explicitly distinguish local and global variables. As a matter of fact, most compilers made local copies of variables, and kept arrays global. To provide for global variables Fortran knows "common blocks", either named or unnamed (blank). These are memory areas that are assigned to the program at load time.


(To be continued)