Arrays in subprograms (subroutines and functions) come in several different flavors. We discuss a few of them here and in the next section.

First we'll take a look at arrays that appear in the parameter (dummy argument) list. A dummy array can take one of several forms:

  1. explicit-shape, where the bounds are set by constants in the subprogram;
  2. explicit-shape and adjustable, where the bounds are determined from parameters in the parameter list; or
  3. assumed-shape, where the shape of the array is left unspecified except for rank.

In the last case, only the rank of the array is specified, with a plain colon (:) standing in for each dimension of any actual array that will be passed in as an argument. It is called "assumed-shape" because the dummy array assumes the shape (rank and extents) of the actual array that is passed when the subprogram is called.

For the assumed-shape case to work, the caller must have correct information about the interface to the subprogram. It can be provided in one of two ways: (1) by defining the subprogram in a module (cf. section on modules) that the caller will use; or (2) by including an explicit interface block in the caller. We will not cover interface blocks here, beyond giving a couple of examples.

Here is a sample code that illustrates the three varieties of dummy arrays listed above:

 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Inclusivity Statement