A Short Introduction to Fortran 90

What is Fortran 90

Fortran is the most widely used programming language for numerical and high-performance computing. Fortran 90 is the current version which adds many important features to Fortran 77, e.g., dynamic memory allocation, array processing features, structured data types, modules and pointers. Note that all Fortran 77 commands remain valid, but some (like GOTO, COMMON) are made obsolete by new Fortran 90 features.

Availability and usage

Fortran 90 is available on WAM and Glue Sun and DEC Alpha machines and Math department Sun machines.

To compile a program type f90 myprogram.f90 . To run the resulting program type a.out .

Example program

This program illustrates the most important Fortan 90 commands:

!  this module can be placed in separate file and compiled separately 
module vectorfun
  implicit none
contains
  function length(v)
! compute the euclidian length of a vector
    real    :: length, v(:), s
    integer :: n, i
    n = size(v)
    s = 0.
    do i=1,n
      s = s + v(i)**2
    end do
    length=sqrt(s)
  end function
end module

! the main program can be placed in a separate file and compiled separately
program test
  use vectorfun ! this makes all declarations and definitions of module available
  implicit none
  integer :: i,n
  real    :: r 
  real, allocatable :: x(:)
  print *,'n ='
  read *, n
  allocate(x(n))
  do i=1,n
    print *,'x(',i,') ='
    read *, x(i)
  end do
  r=length(x)
  print *, 'length =',r
end program

Input format

Fortran 90 can use a free format which is not restricted to certain columns.

Data types

I strongly recommend that you declare all variables explicitly and put the statement implicit none at the beginning of your programs and modules.

Control statements

Functions and subroutines

More information



T. von Petersdorff , � tvp@math.umd.edu
Last modified: Wed May 22 15:05:02 EDT 1996