F90
Examples of FORTRAN90 Code


F90, programs which illustrate some of the features of the FORTRAN90 programming language.

The new array syntax added to FORTRAN90 is one of the nicest features for general scientific programming. Other useful features include a standard random number generator, a standard way to get the time and CPU time, and some ways to make a chunk of data available without resorting to common blocks or very long argument lists.

Licensing:

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

Languages:

Directories related to F90 are available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version and a Python version.

Related Data and Programs:

ALLOCATABLE_ARRAY, a FORTRAN90 program which demonstrates how a FORTRAN90 program can declare an allocatable array, pass it to a subroutine, which then allocates and initializes it, returning the allocated and initialized array to the calling program.

F90_INTRINSICS, FORTRAN90 programs which illustrate the use of FORTRAN90 intrinsic functions.

F90_INTRINSICS, FORTRAN90 programs which illustrate the use of FORTRAN90 intrinsic functions.

F90_RANDOM, FORTRAN90 programs which illustrate the use of Fortran's random number generator routines.

G95_INTRINSICS, FORTRAN90 programs which illustrate the use of intrinsic functions peculiar to the G95 FORTRAN compiler.

GFORTRAN, FORTRAN90 programs which includes examples of the use of the GFORTRAN compiler with FORTRAN90 code.

GFORTRAN_INTRINSICS, a FORTRAN90 program which demonstrates the use of some of the intrinsic functions included with the GFORTRAN compiler.

MAKEFILES, FORTRAN90 programs which show how to use makefiles with a set of FORTRAN90 files.

MIXED, FORTRAN90 programs which show how to write a program partly in FORTRAN90 and partly in some other language.

MPI, FORTRAN90 programs which show how to set up parallel programs in FORTRAN90.

REAL_PRECISION, FORTRAN90 programs which investigate the somewhat awkward methods for requesting a real data type with given precision. This is the preferred method for requesting double or quadruple precision arithmetic;

TIMER, FORTRAN90 programs which show how to compute elapsed CPU time in FORTRAN90.

TIMESTAMP, a FORTRAN90 library which shows how to get a timestamp in FORTRAN90.

XLF_INTRINSICS, FORTRAN90 programs which includes some examples of the use of intrinsic functions peculiar to the IBM XLF FORTRAN compiler.

Reference:

  1. Jeanne Adams, Walter Brainerd, Jeanne Martin, Brian Smith, Jerrold Wagener,
    Fortran90 Handbook,
    Complete ANSI/ISO Reference,
    McGraw Hill, 1992,
    ISBN: 0-07-000406-4,
    LC: QA76.73.F28.F67.
  2. Ian Chivers, Jane Sleightholme,
    Introduction to Programming with Fortran,
    Springer, 2005,
    ISBN: 1846280532,
    LC: QA76.73.F29.C48.
  3. Miles Ellis, Ivor Philips, Thomas Lahey,
    Fortran90 Programming,
    Addison-Wesley, 1994,
    ISBN: 0-201-54446-6,
    LC: QA76.73.F25E435.
  4. Michael Metcalf,
    Fortran95/2003 Explained,
    Oxford, 2004,
    ISBN: 0198526938,
    LC: QA76.73.F235.M48.
  5. Larry Nyhoff, Sanford Leestma,
    Introduction to Fortran90 for Engineers and Scientists,
    Prentice-Hall, 1996,
    ISBN: 0135052157,
    LC: QA76.73.F25N925.
  6. James Ortega,
    An Introduction to FORTRAN90 for Scientific Computing,
    Oxford, 1994,
    ISBN: 0-19-517213-2,
    LC: QA76.73.O75.
  7. William Press, Brian Flannery, Saul Teukolsky, William Vetterling,
    Numerical Recipes in FORTRAN: The Art of Scientific Computing,
    Second Edition,
    Cambridge University Press, 1992,
    ISBN: 0-521-43064-X,
    LC: QA297.N866.
  8. GNU,
    GFORTRAN Reference Manual.
  9. IBM Corporation,
    XLF Language Reference Manual
  10. Intel Corporation,
    Intel Fortran Language Reference.

Examples and Tests:

BIG_INTS shows how you can use the new KIND qualifier to create, for example, really big integers.

BIG_INTS_REAL shows what can go wrong when you try to move large integer values into and out of real variables.

BINARY_TREE shows how a binary tree can be defined and manipulated, using the FORTRAN90 "POINTER" type.

CHAR_ALLOC shows that in FORTRAN90 it is possible to declare an allocatable array of characters, for which the dimension, or perhaps the maximum string length (LEN) is not specified in advance.

  • char_alloc.f90, the source code;
  • char_alloc.txt, the output file;
  • CONSTANT_TYPE shows that FORTRAN90 constants have a type, and that if you don't specify it for real values, the default will be single precision.

    DIGITS investigates how many digits you can usefully specify for data.

    DIVISION shows that, if you're expecting double precision accuracy, you need to specify your constants carefully, as double precision values.

    DOUBLE_COMPLEX shows how you can use the new KIND qualifier to create and use variables of type "double precision complex".

    EXPONENT_FORMAT_OVERFLOW shows that (at least some) FORTRAN compilers cannot properly print real numbers with exponents of magnitude greater than 99. This becomes an especially serious problem if you write a very large or very small number out, and then read it back in, only to find that it has suddenly entirely lost its exponent, and now has magnitude roughly 1!

    EXPONENTIAL investigates ways of approximating the exponential function.

    HELLO is just a "Hello, world!" program.

    LINKED_LIST shows how a linked list can be defined, using the FORTRAN90 "POINTER" type.

    MATRIX_FUNCTION_TEST shows how you may now define a function whose return value is a matrix.

    MAXMIN_TEST shows the use of the very useful MAXVAL and MINVAL operators for vectors and arrays, and the so-very-fussy and hence maddeningly useless operators MAXLOC and MINLOC.

    MXM multiplies two matrices using the MATMUL intrinsic.

    RANDOM_test demonstrates the random number routines.

    READ_VARIABLE_RECORDS shows how to read lines of data when you don't know how many items are on each line. We're assuming that every item is in "I4" format, but the number of such items variables from line to line.

    RECURSIVE_FUN_TEST shows how you can use recursion in a function definition.

    RECURSIVE_SUB_TEST shows how you can use recursion in a subroutine definition.

    SGE_MOD tries to set up an interesting example of the use of modules. In this case, the idea is that a set of linear algebra routines will share a module that stores the value of a matrix, its LU factor and determinant, and also knows which of these items have been computed. This hides a lot of information from the user, and makes for simple calls.

    SORT_TEST bubble-sorts a real vector.

    STAR16 looks at the use of the common but nonstandard way to request quadruple real precision using "REAL*16" declarations. Most recently, this seems to work with the G95 compiler, but not with the GFORTRAN compiler.

    STOP_MESSAGE shows that a FORTRAN STOP statement can include a message to be printed.

    TRIANGLE_TYPE demonstrates how to create and use a derived data type.

    VECTOR_MAX inquires whether a loop with the body "Z(I)=max(X(I),Y(I))" can be replaced by the vector operation "Z(1:N)=max(X(1:N),Y(1:N))".

    WHERE_TEST demonstrates the WHERE statement.

    You can go up one level to the FORTRAN90 source codes.


    Last revised on 19 March 2019.