Arrays. Dynamic arrays. Give an example

Arrays are ordered collections of similar items.

The array is characterized by the type of the elements, number of elements and the way they are numbering. The number of elements is called the size or length of the array; numbering method is described by a one-dimensional integer array, called the shape of the array.

It is assumed that there are arrays that do not contain any element - a zero-length arrays, which are necessary for describing many natural situations, such as one that occurs when you use sections in solving a system of linear equations.

Ax=B, where A- is a triangular matrix.

Example of finding the roots of linear equations:

:

DO I = N, 1, -1

X(i)= B(i) /A(i,i)

B(1:i-1)=B(1:i-1)-A(1:i-1,i)*X(i)

END DO

:

In FORTRAN arrays can have cup to 7 dimensions, which is each element of an array can have up to 7 indices that characterize his position in array, for example:

A (3, 4, I, J), B (1, 2, 3, 4, 5, b, 7), C (K)

The number of dimensions is called the rank of the array, the number of elements in the dimension called extents of the array in this dimension. Integer array, which length is equal to the rank of a given array, and each element is extent at the array in this dimension, called the shape of the array.

Arrays having the same shape are called compatible.

Dynamic arrays

The array size is not always known in advance, in order to identify it, necessary, for example, consider some of the data or perform calculations. In such a case, you can use dynamic arrays, which is allocated during the execution of the program.

A dynamic array has to be described with the attribute ALLOCATABLE, for example:

REAL, ALLOCATABLE, DIMENSION (:,:):: X (2*dimensional array)

The extents of a dynamic array in the description are not specified, as they are not known at this time, only the rank of the array is specified.

Memory allocation and determination of the actual bounds of the array is produced by the operator ALLOCATE:

ALLOCATE (X (N, N))

where n - integer variable with a certain positive value. The allocated memory is not freed automatically, it is necessary to use the operator DEALLOCATE:

DEALLOCATE (X)


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: