02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Array constructors<br />

Arrays<br />

Array constructors<br />

An array constructor is used to assign values to an array. The generated values are<br />

supplied from a list of scalar values, arrays of any rank, and implied DO specifications. An<br />

array constructor may appear in any context in which a rank-one array expression is allowed.<br />

An array with a rank greater than one may be constructed by using the RESHAPE intrinsic<br />

function. The type of an array constructor is taken from the values in the list, which must all<br />

have the same type and type parameters (including character length). The extent is taken<br />

from the number of values specified.<br />

The syntax of an array constructor is:<br />

(/ ac-value-list /)<br />

where ac-value-list is a comma-separated list of one or more ac-values. Eachac-value<br />

may be any of the following:<br />

Scalar expressions, for example:<br />

(/ 1.2, 0.0, 2.3 /)<br />

An array expression, for example:<br />

(/ x(0:5) /)<br />

where the values in x(0) through x(5) become the values of the array constructor. If the<br />

array the value list has a rank greater than one, the values are generated in<br />

column-major order, as explained in “Array fundamentals” on page 55.<br />

An implied-DO specification, taking the form:<br />

(ac-value-list, do-var = expr1, expr2 [, expr3])<br />

where do-var is the name of a scalar integer variable, expr1 is the initial value, expr2 is<br />

the final value, and expr2 is the stride (the default is 1). For example:<br />

(/ i, i = 1, 10 )<br />

When used to initialize an array in a type declaration or in an assignment statement, all<br />

elements in the array must be initialized. For example, the following is illegal:<br />

INTEGER :: i(10) = (/ 1, 2, 3 /) ! ILLEGAL: too few<br />

! initializers<br />

If no values are supplied, the array constructor is zero-sized. For example, the size of the<br />

following array constructor:<br />

(/ ( i, i=10,n) /)<br />

Chapter 4 73

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

Saved successfully!

Ooh no, something went wrong!