Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran Compiler for HP-UX: HP Fortran Programmer's Reference > Chapter 10 HP Fortran statements

DIMENSION (statement and attribute)

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

Declares a variable to be an array.

Syntax

A type declaration statement with the DIMENSION attribute is:

type, DIMENSION ( array-spec ) [[, attrib-list ]::] entity-list
type

is a valid type specification (INTEGER, REAL, LOGICAL, CHARACTER, TYPE( type-name ), etc.).

array-spec

is one of the following:

  • explicit-shape-spec-list

  • assumed-shape-spec-list

  • deferred-shape-spec-list

  • assumed-size-spec

explicit-shape-spec

is

[lower-bound :] upper-bound

lower-bound, upper-bound

are specification expressions.

assumed-shape-spec

is

[lower-bound] :
deferred-shape-spec

is

:
assumed-size-spec

is

[explicit-shape-spec-list ,] [lower-bound :] *

That is, assumed-size-spec is explicit-shape-spec-list with the final upper bound specified as *.

attrib-list

is a comma-separated list of attributes including DIMENSION and optionally those attributes compatible with it, namely:

Table 10-7 Title not available (DIMENSION (statement and attribute))

ALLOCATABLE

PARAMETER

PUBLIC

INTENT

POINTER

SAVE

OPTIONAL

PRIVATE

TARGET

 

entity-list

is

object-name[(array-spec)]

If (array-spec) is present, it overrides the (array-spec) given with the DIMENSION keyword in attribute-list; see the example below.

The syntax of the DIMENSION statement is:

DIMENSION [::] array-name (array-spec)
[, array-name (array-spec) ]...

Description

An array consists of a set of objects called the array elements, all of the same type and type parameters, arranged in a pattern involving columns, and possibly rows, planes, and higher dimensioned configurations. The type of the array elements may be intrinsic or user-defined. In HP Fortran, an array may have up to seven dimensions. The number of dimensions is called the rank of the array and is fixed when the array is declared. Each dimension has an extent that is the size in that dimension (upper bound minus lower bound plus one). The size of an array is the product of its extents. The shape of an array is the vector of its extents in each dimension. Two arrays that have the same shape are said to be conformable.

It is not necessary for the keyword DIMENSION to appear in the declaration of a variable to give it the DIMENSION attribute. This attribute, as well as the rank, and possibly the extents and the bounds of an array, may be specified in the entity declaration part of any of the following statements:

  • type declaration

  • DIMENSION

  • ALLOCATABLE

  • COMMON

  • POINTER

  • TARGET

The array-spec (see Syntax, above) determines the category of the array being declared. “Array declarations”, describes these categories as:

  • Explicit-shape array

  • Assumed-shape array

  • Assumed-size array

  • Deferred-shape array

Examples

! These 2 declaration statements are equivalent.
REAL a (20,2), b (20,2), c (20,2)
REAL, DIMENSION (20,2) :: a, b, c

DIMENSION x(100), y(100) ! x and y are 1-dimensional

! lower bounds specified for jj (if not given, they default to 1)
INTEGER jj (0:100, -1:1)

! l is a 4-dimensional, allocatable, deferred shape logical array
LOGICAL l
ALLOCATABLE l(:,:,:,:)

COMPLEX s ! s has explicit shape and
TARGET :: s(10,2) ! the target attribute

DOUBLE PRECISION d
! d has 5 dimensions and is declared in common
COMMON /stuff/ d(2,3,5,9,8)

! arr1 is an adjustable array, arr2 an automatic array
SUBROUTINE calc(arr1, ib1, ib2)
REAL, DIMENSION (ib1, ib2) :: arr1, arr2

! arr3 is a deferred-shape array with the pointer attribute
REAL, POINTER, DIMENSION(:,:) :: arr3

! all three arrays have explicit shape; array specifier (10,10)
! overrides specifier (10,20) for tb declaration only
LOGICAL, DIMENSION(10,20) :: ta, tb(10,10), tc

Related statements

ALLOCATABLE, COMMON, POINTER, TARGET, TYPE, and the type declaration statements

Related concepts

For related information, see the following:

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.