02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's 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.

Arrays<br />

Array sections<br />

! The arrays x, y, and z now have the following values:<br />

! x y z<br />

! 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 3<br />

! 0 0 0 0 0 0 0 2 0 2 0 2 0 0 3 3 3 3<br />

! 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br />

In the following example of an array substring, the variable dates(5:10) is an array section<br />

that includes elements 5 through to 10 of the parent array dates, and the variable<br />

dates(5:10)(8:11) is also an array section of the array dates but only contains the last 4<br />

character positions of the elements 5 through to 10.<br />

CHARACTER(11) :: dates(20)<br />

dates(5:10)(8:11) = ”1776”<br />

Vector subscripts<br />

A vector subscript is any expression that results in a rank-one array with integer value.<br />

The values of the array select the corresponding elements of the parent array for a given<br />

dimension. Vector subscripts can describe an irregular pattern and may be useful for indirect<br />

array addressing. For example, if v represents a rank-one integer array initialized with the<br />

values 4, 3, 1, 7, then the array section a(v) is a rank-one array composed of the array<br />

elements a(4), a(3), a(1), anda(7)—in that order.<br />

Vector subscripts are commonly specified using array constructors, which are described in the<br />

next section. For example, the expressions a(v) and a((/ 4, 3, 1, 7/)) reference the same<br />

section of the array a.<br />

Vector subscripts may not appear:<br />

68<br />

On the right hand side of a pointer assignment statement.<br />

InanI/Ostatementasaninternalfile.<br />

As an actual argument that is associated with a dummy argument declared with<br />

INTENT(OUT) or INTENT(INOUT) or with no INTENT.<br />

A vector subscript may specify the same element more than once. When a vector subscript of<br />

this form specifies an array section, the array section is known as a many-one array<br />

section. Anexampleofamany-one array section is:<br />

a( (/ 4, 3, 4, 7/) )<br />

where element 4 has been selected twice. A many-one array section may not appear in either<br />

an input list or on the left-hand side of an assignment statement.<br />

The following example, vector_sub.f90, illustrates an array section using a section subscript<br />

list.<br />

Chapter 4

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

Saved successfully!

Ooh no, something went wrong!