Introduction to Computing for Civil Engineers
6.1 What is an Array?
An array is a collection of data of the
type. Array elements are
, just like
in mathematics. An Array is an example of a
, an object which can
have more than one value).
6.2 Important Components of an Array
A one-dimensional array has the following important components:
: this is the type of
: this is the
of the indices or subscripts of array elements. For example, the range
of an array can be 1 to 10 (
, element 1, element 2, element 3, .
.., element 10) or -3 to 5 (
element -3, element -2, .
.., element 4, element 5).
Indices or subscripts must be integers within the range. The smallest and the largest indices or
subscripts are referred to as the
bound and the
The extent of an array is simply the following:
are the lower bound and the upper bound of the extent. Thus,
if array indices are in the range of 0 and 11, the extent is
; if array indices are in the range of -3 and
21, the extent is
. However, if the lower bound of an extent is 1, it can be omitted as well as the
colon following it.
6.3 Declaring an Array
There are two ways to declare an array:
(1)type, DIMENSION( extent ) :: name-1, name-2, .
is the type (real, integer, character or logical) of the arrays
is a required keyword, and
gives the range of the array indices.
type name-1,name-2, …, name-n
DIMENSION name-1(extent-1),name-2(extent-2), …, name-n(extent-n)
:: a, Sum
INTEGER, DIMENSION(0:100) :: InputData
The elements of arrays
and the indices are in the range of -1 and 1.
The elements of array
and the indices are in the range of 0 and 100.
The integers in an extent can be
INTEGER, PARAMETER :: MaximumSize = 100
LOGICAL, DIMENSION(1:MaximumSize) :: AnswerSheet
INTEGER, PARAMETER :: LowerBound = -10
INTEGER, PARAMETER :: UpperBound =
REAL, DIMENSION(LowerBound:UpperBound) :: Score, Mark