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 constructors<br />

depends on the value of the variable n; if the value of the variable is less than 10, then the<br />

constructor contains no values.<br />

If the list contains only constant values, the array constructor may initialize a named<br />

constant or a type declaration statement. An array constructor may not initialize variables in<br />

a DATA statement, which may contain scalar constants only.<br />

As an extension, <strong>HP</strong> <strong>Fortran</strong> allows the use of [ and ] in place of (/ and /).<br />

The following are examples of array constructors:<br />

! array x is assigned three real values.<br />

x = (/19.3, 24.1, 28.6/)<br />

! One vector, consisting of 16 integer values, is assigned to j<br />

j = (/4, 10, k(1:5), 2 + l, (m(n), n = -7,-2),16, 1/)<br />

! assign 5 values<br />

a = (/(base(k), k=1,5)/)<br />

! The named constant t is a rank-one array initialized with<br />

! the values 36.0 and 37.0<br />

REAL,DIMENSION(2):: t<br />

PARAMETER (t=(/ 36.0, 37.0/))<br />

! the array constructor is reshaped as 1 3 5 7<br />

! 2 4 6 8<br />

! and is then assigned to z<br />

z=RESHAPE((/1,2,3,4,5,6,7,8/), (/2,4/) )<br />

! an array constructor is used for the second component of<br />

! the structure constructor<br />

alaska = site(”NOME”,(/-63,4/))<br />

diagonal = (/ (b(i,i), i=1,n) /)<br />

hilbert = RESHAPE( (/ ((1.0/(i+j), i=1,n), j=1,n) /), (/ n,n /) )<br />

ident = RESHAPE ( (/ (1, (0, i=1,n), j=1,n-1), 1 /), (/ n,n /) )<br />

As shown in last three examples, an array constructor with implied- DO loops and the RESHAPE<br />

function permit construction of arrays that cannot otherwise be expressed conveniently with<br />

alternative notations.<br />

74<br />

Chapter 4

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

Saved successfully!

Ooh no, something went wrong!