CEE15 Introduction to Computing for Civil Engineers4

# CEE15 Introduction to Computing for Civil Engineers4 -...

This preview shows pages 1–3. Sign up to view the full content.

CEE15 Introduction to Computing for Civil Engineers 59 Chapter 6 Array Processing 6.1 What is an Array? An array is a collection of data of the same type. Array elements are indexed or subscripted , just like x 1 , x 2 , . .., x n in mathematics. An Array is an example of a compound object ( i.e. , 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: A name A type : this is the type of all array elements. An extent : this is the range of the indices or subscripts of array elements. For example, the range of an array can be 1 to 10 ( i.e. , element 1, element 2, element 3, . .., element 10) or -3 to 5 ( i.e. , 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 lower bound and the upper bound, respectively. The extent of an array is simply the following: smaller-integer : larger-integer where smaller-integer and larger-integer 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 0:11 ; if array indices are in the range of -3 and 21, the extent is -3:21 . 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, . .., name-n § type is the type (real, integer, character or logical) of the arrays name-1 , name-2 , . .., name-n § DIMENSION is a required keyword, and extent gives the range of the array indices. (2) type name-1,name-2, …, name-n DIMENSION name-1(extent-1),name-2(extent-2), …, name-n(extent-n) Examples: REAL, DIMENSION(-1:1) :: a, Sum INTEGER, DIMENSION(0:100) :: InputData The elements of arrays a and Sum are REAL and the indices are in the range of -1 and 1. The elements of array InputData are INTEGER ’S and the indices are in the range of 0 and 100. The integers in an extent can be PARAMETER ’S : Examples: INTEGER, PARAMETER :: MaximumSize = 100 LOGICAL, DIMENSION(1:MaximumSize) :: AnswerSheet INTEGER, PARAMETER :: LowerBound = -10 INTEGER, PARAMETER :: UpperBound = 10 REAL, DIMENSION(LowerBound:UpperBound) :: Score, Mark

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CEE15 Introduction to Computing for Civil Engineers 60 In the above, the range of array AnswerSheet is 1 and 100, while the range of arrays Score and Mark is -10 and 10. 6.4 Array Elements An element of an array has a form of the following: array-name ( integer-expression ) where array-name is the name of the array, and integer-expression is an expression whose final result is an integer. The result of integer-expression , which must be an integer in the range of the extent, gives the index or the subscript of the desired array element. Examples:
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 09/28/2011 for the course CE 13972 taught by Professor Chow during the Spring '09 term at Berkeley.

### Page1 / 16

CEE15 Introduction to Computing for Civil Engineers4 -...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online