Dimension

Statement/Attribute Purpose

The DIMENSION statement or attribute provides one way to declare the dimensions and rank of arrays. The DIMENSION statement dates back to the early days of FORTRAN and with it a programmer can declare arrays independently of the type declaration statements. The DIMENSION attribute, associated with a type statement permits assignment of the same dimensions for all elements in the type statement.

Examples of Use

The DIMENSION attribute appears along with your type declaration statements ( INTEGER, REAL, etc. ) as part of an attribute list. The attribute list can include any number of valid attributes along with the DIMENSION attribute. For example, in the lines of sample code that follow below, the DIMENSION attribute is used both by itself and with other attributes. Notice that in all of the sample lines, the attribute declares both the rank and number of elements in the arrays, except when used with the allocatable or pointer attributes. In that case, it just declares the rank with the use of colons and allows the allocate statement assign the actual number of elements to the array later on.
		real, dimension(3,4) :: a,b,c
		integer, target, dimension(3,3,3) :: intvals
		real, allocatable, dimension(:,:) :: indata
          real, pointer, dimension (:,:,:) :: press, temp, vel
Finally, the DIMENSION statement can be used to create arrays out of variables which are given a type in a separate statement or assume a default type. For instance, in the following two lines of FORTRAN the variable xarray is first declared real in one statement, and then is declared as an array in the next line by the dimension statement.
		real xarray
		dimension xarray(5,6)

For more information and examples see

lecture eighteen

examples: sums.f and dual-interface.f

Up one level / Home


Written by Jason Wehr: jcw142@psu.edu and Maintained by John Mahaffy : jhm@cac.psu.edu