- Introduction
- 1. Source code form
- 2. Alternative representations
- 3. Specifications
- 4. Conditional statement
- 5. DO-loop
- 6. Program units
- 7. Character string variables
- 8. Input
- 9. Vector and matrix management
- 10. Dynamic storage
- 11. Intrinsic functions
- 12. Use of the user-defined data type
- 13. Modules
- 14. The data type "bit"
- 15. Pointers
- 16. User extensions

The underline symbol _ is permitted inside the names of variables, and the length of variables must have at most 31 characters (instead of at most 6 in the Fortran 77 standard).

Blanks become significant in the free form of the source code. Old
commands like `ENDIF ` and `GOTO ` can also in the future
be written either
as `END IF ` or `GO TO ` respectively, but of course not
like `EN DIF ` or `GOT ` `O`. To permit significant
blanks in the old (fixed) form of the source
code would not be possible, since it for example is permitted to write
`END ` in the following silly way

E N D

As in most Algol-type languages the word `END ` can be complemented
with the name of the routine or function like `END FUNCTION GAMMA`.

< .LT. > .GT. <= .LE. >= .GE. == .EQ. /= .NE.

REAL, DIMENSION (3), PARAMETER :: & a = (/ 0.0, 0.0, 0.0 /), b = (/ 1.0, 1.0, 1.0 /) COMPLEX, DIMENSION(10) :: johnwhile the variables a and b become constant vectors with 3 elements and the floating-point values 0.0 and 1.0, respectively, while john becomes a complex vector with 10 complex elements, not yet assigned any values.

If you wish to use the Algol principle to specify all variables,
this is simplified by the command `IMPLICIT NONE ` which switches off the
implicit-type rules.

Double precision has been implemented with a more general method to
give the desired precision, namely the parameter ` KIND ` for which
precision we wish, useful on all variable types.

INTEGER, PARAMETER :: LP = SELECTED_REAL_KIND(20) REAL (KIND = LP) :: X, Y, ZThe above two statements thus declare the variables

SELECT CASE (expression) CASE block-switch block CASE block-switch block CASE DEFAULT default block END SELECTTypical construct:

SELECT CASE(3*I-J) ! the control variable is 3*i-j CASE(0) ! for the value zero : ! you execute the code here CASE(2,4:7) ! for the variables 2, 4, 5, 6, 7 : ! you execute the code here CASE DEFAULT ! and for all other values ! you execute the code here : ! END SELECTIf the

Another example:

INTEGER FUNCTION SIGNUM(N) SELECT CASE (N) CASE (:-1) SIGNUM = -1 CASE (0) SIGNUM = 0 CASE (1:) SIGNUM = 1 END SELECT END

name: DO executable statements END DO nameThe usual

name: DO i = integer_expr_1, integer_expr_2 ,integer_expr_3 executable statements END DO namewhere

name: DO WHILE (logical_expression) executable statements END DO nameThe name is optional but can be used for nested loops in order to indicate which one that is to be iterated once again with the

S1: DO IF (X > Y ) THEN Z = X EXIT S1 END IF CALL NEW(X) END DO N = 0 LOOP1: DO I = 1, 10 J= I LOOP2: DO K =1, 5 L = K N = N +1 END DO LOOP2 END DO LOOP1In the latter case the final values from the variables will be as follows, in full accordance with the standard,

To name the loop is completely optional. Also note that this type
of name is limited to `DO`-loop, `CASE ` or
`IF...THEN...ELSE...ENDIF `
constructs. The old possibilities with statement numbers are still
available, also in the free form.

SUBROUTINE solve (a, b, n) REAL, OPTIONAL, INTENT (IN) :: bcan be called with

CALL solve (n = i, a = x)where two of the arguments are given with keywords instead of position and where the third one has a default value. If

RECURSIVE FUNCTION factorial (n) RESULT (fac)but must then have a special

a = ''and assignment of an overlapping string is now permitted

a(:5) = a(3:7)The new intrinsic function

NAMELIST /list2 / a, i, x : READ (unit, NML = list2)which wishes to get input data of the following form, but all variables do not have to given, and they can be given in any order.

&list2 X = 4.3, A = 1.E20, I = -4 /

REAL, DIMENSION(5,20) :: x, y REAL, DIMENSION(-2:2,20) :: z : z = 4.0*y*sgrt(x)We perhaps here wish to protect against negative elements of

WHERE ( x >= 0.0 ) z = 4.0*y*sgrt(x) ELSEWHERE z = 0.0 END WHEREPlease note that

You can pick out a part of an array. Assume that the array `A` is
specified in the following way.

REAL, DIMENSION(-4:0, 7) :: AWith

REAL, DIMENSION(6) :: B REAL, DIMENSION(2,3) :: C B = (/ 1, 1, 2, 3, 5, 8 /) C = RESHAPE( B, (/ 2,3 /) )where the first argument to the intrinsic function

The above can also be written in a more compressed form using the
`PARAMETER ` attribute. In the first line below the
`PARAMETER ` attribute
is compulsory (if the assignment is to be made on the same line),
but in the second line it is optional. Remember that the `PARAMETER `
attribute means that the quantity can not be changed during execution
of the program.

REAL, DIMENSION(6), PARAMETER :: B = (/ 11, 12, 13, 14, 15, 16 /) REAL, DIMENSION(2,3), PARAMETER :: C = RESHAPE( B, (/ 2, 3 /) )Any statements for real parallel computation are not included in Fortran 90. The committee believes it is necessary with additional experience before the standardization of parallelization. See also HPF discussed in the Appendix 8.

The second is to use an "allocatable array", i.e. with the
statements `ALLOCATE ` and `DEALLOCATE ` you get and return a storage area for an
array with type, rank and name (and possible other attributes) which had been
specified earlier with the additional attribute `ALLOCATABLE`.

REAL, DIMENSION(:), ALLOCATABLE :: x : Allocate(x(N:M)) ! N and M are the integer expressions here. : x(j) = q ! Some assignment of the array. CALL sub(x) ! Use of the array in a subroutine. : DEALLOCATE (x)Deallocation occurs automatically (if the attribute

The third variant is an "automatic array", it is almost available in the old Fortran, where x in the example below has to be in the list of arguments. This is not required any more.

SUBROUTINE sub (i, j, k) REAL, DIMENSION (i, j, k) :: xDimensions for x are taken from the integers in the calling program. Finally there is an "assumed-shape array" where the storage is defined in the calling procedure and for which only the type, rank and name are given.

SUBROUTINE sub(a) REAL, DIMENSION (:,:,:) :: aAccording to Metcalf and Reid (1990, 1992), section 6.3 you here require an explicit interface. This has to look as follows

INTERFACE SUBROUTINE SUB(A) REAL, DIMENSION (:,:,:) :: A END SUBROUTINE SUB END INTERFACEIf you forget the

Some intrinsic functions are available to determine the actual dimension limits

DO (i = LBOUND(a,1), UBOUND(a,1)) DO (j = LBOUND (a,2), UBOUND (a,2)) DO (k = LBOUND(a,3),UBOUND (a,3))where

The sum of the positive value of a number of elements in an array is written

SUM ( X, MASK = X .GT. 0.0)These statements can not be used in order to avoid division by zero at for example summation of

The function `SPREAD ` is discussed more fully in the solution of
exercise (11.1).

All intrinsic functions and subroutines are discussed in Appendix 5.

TYPE staff_member CHARACTER(LEN=20) :: first_name, last_name INTEGER :: identification, department END TYPEwhich can be used in order to describe an individual. A combination of individuals can also be formed

TYPE(staff_member), DIMENSION(100) :: staffIndividuals can be referred to as staff(number) and a field can be referred as

TYPE company CHARACTER(LEN=20) :: company_name TYPE(staff_member), DIMENSION(100) :: staff END TYPE : TYPE(company), DIMENSION(10) :: several_companiesA numerically more interesting example is a sparse matrix

TYPE NONZERO REAL VALUE INTEGER ROW, COLUMN END TYPEand

TYPE (NONZERO) :: A(100)You then get the value of

A(15) = NONZERO(17.0,3,7)In order to use user-defined data types in for example

B'01010101010101010101010101010101'for binary,

O'01234567'for octal, and

Z'ABCDEF'for hexadecimal numbers.

Pointers are discussed in chapter 12.

Last modified: 17 April 1995