HP Fortran Programmer's Reference (September 2007)

Arrays
Array constructors
Chapter 376
depends on the value of the variable n; if the value of the variable is less than 10, then the
constructor contains no values.
If the list contains only constant values, the array constructor may initialize a named
constant or a type declaration statement. An array constructor may not initialize variables in
a DATA statement, which may contain scalar constants only.
As an extension, HP Fortran allows the use of [ and ] in place of (/ and /).
The following are examples of array constructors:
! array x is assigned three real values.
x = (/19.3, 24.1, 28.6/)
! One vector, consisting of 16 integer values, is assigned to j
j = (/4, 10, k(1:5), 2 + l, (m(n), n = -7,-2),16, 1/)
! assign 5 values
a = (/(base(k), k=1,5)/)
! The named constant t is a rank-one array initialized with
! the values 36.0 and 37.0
REAL,DIMENSION(2):: t
PARAMETER (t=(/ 36.0, 37.0/))
! the array constructor is reshaped as 1 3 5 7
! 2 4 6 8
! and is then assigned to z
z=RESHAPE((/1,2,3,4,5,6,7,8/), (/2,4/) )
! an array constructor is used for the second component of
! the structure constructor
alaska = site(”NOME”,(/-63,4/))
diagonal = (/ (b(i,i), i=1,n) /)
hilbert = RESHAPE( (/ ((1.0/(i+j), i=1,n), j=1,n) /), (/ n,n /) )
ident = RESHAPE ( (/ (1, (0, i=1,n), j=1,n-1), 1 /), (/ n,n /) )
As shown in last three examples, an array constructor with implied- DO loops and the RESHAPE
function permit construction of arrays that cannot otherwise be expressed conveniently with
alternative notations.