24.11.2014 Views

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4 Arrays<br />

4.1 Introduction<br />

An array is a non-empty collection of data. Arrays allow a convenient way of manipulating large quantities<br />

of data. An array can be referenced as an entity. In this way it is possible to conveniently pass large<br />

quantities of data between subprograms. Alternatively, it is possible to reference each element of an array<br />

individually so that data can be selectively processed. Consider the task of managing the marks of 100<br />

students. Without arrays one would have to have a unique name for each mark. They might be M1, M2,<br />

etc. up to M100. This is clearly cumbersome. Instead, we can use an array called MARKS containing 100<br />

elements. Now there is one name for all the marks. Each mark can be referenced by using that name<br />

followed by a subscript. Furthermore, suppose the size of the class doubled. Do we add the names M101,<br />

M102, etc. up to M200? Not if we use arrays. If the size of the class doubled, all that need be done is to<br />

define the array to contain 200 elements. It is not hard to see that programs that use arrays tend to be<br />

general in nature. Arrays also facilitate the repetitive computations that must be performed on large<br />

amounts of data in that they lend themselves to loop processing.<br />

4.2 Properties of Arrays<br />

Arrays are defined by an array declarator. The form of an array declarator is:<br />

<br />

a( d [,d] ... )<br />

where:<br />

a<br />

d<br />

is the symbolic name of the array<br />

is a dimension declarator.<br />

The number of dimensions of the array is determined by the number of dimension declarators appearing in<br />

the array declarator. Allowable dimensions for arrays range from 1 to 7. A 1-dimensional array can be<br />

viewed as a vector, a 2-dimensional array as a matrix and a 3-dimensional array as a number of parallel<br />

matrices. Arrays with dimension higher than 3 are generally difficult to intuitively describe and hence<br />

examples will deal with arrays whose dimension is 1, 2 or 3.<br />

Each dimension has a range of values. When referencing elements in that dimension, the dimension<br />

expression must fall in that range. The range of a dimension is defined in the dimension declarator. A<br />

dimension declarator has the following form:<br />

Properties of Arrays 159

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!