Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran 90 Programmer's Reference: HP Series 700/800 Computers > Chapter 4 Arrays

Array constructors

» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

An array constructor allows a rank-one array to be constructed from a list of scalar values, arrays of any rank, and implied DO specifications. The type of an array constructor is taken from the values in the list which must all have the same type and type parameters (including character length), and its shape is taken from the number of values specified.

An array constructor may appear in any context in which a rank-one array expression is allowed. An array with a rank greater than one may be constructed by passing the array constructor to the RESHAPE intrinsic function.

If the list contains only constant values, the array constructor may be used to initialize a named constant, or it may be used in an initialization expression in a type declaration statement; however an array constructor may not be used to initialize variables in a DATA statement as this statement may only contain scalar constants.

Syntax

The syntax of an array constructor is:

(/ array-constructor-value-list /)
array-constructor-value-list

is a comma-separated list of array-constructor-value

array-constructor-value

is one of:

  • scalar-expression

  • array-expression

  • array-constructor-implied-do

array-constructor-implied-do

is

( array-constructor-value-list, scalar-int-var-name =  &
     scalar-int-expression, scalar-int-expression  &
    [, scalar-int-expression] )

If an array expression appears in a value list, it is treated as a succession of values appearing in array element order (see “Array element storage order”).

The extent of an array constructor is the number of values supplied. If no values were supplied then the array constructor is zero-sized. For example, the size of the following array constructor:

(/ ( i, i=10,n) /)

depends on the value of the variable n; if the value of the variable is less than 10 then the constructor will contain no values.

HP Fortran 90 allows the use of [ and ] in place of (/ and /). This notation is an extension to the Fortran 90 Standard.

The following are examples of array constructors:

x = (/19.3, 24.1, 28.6/)
! Array x is assigned three real values.
j = (/4, 10, k(1:5), 2 + l,  &
   (m(n), n = -7,-2),16, 1/)
! One vector, consisting of 16 integer values, 
! is assigned to j.
a = (/(base(k), k=1,5)/)
! 5 values are assigned.
REAL,DIMENSION(2):: t
PARAMETER (t=(/ 36.0, 37.0/))
! The named constant t is a rank-one array
! initialized with the values 36.0 and 37.0.
z=RESHAPE((/1,2,3,4,5,6,7,8/), (/2,4/) )
! the array constructor is reshaped as  1 3 5 7
!                                       2 4 6 8
! and is then assigned to z
alaska = site("NOME",(/-63,4/))
! An array constructor is used for the second
! component of the structure constructor.
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 illustrated by the last three examples, an array constructor with implied DOs and the RESHAPE function can be used to construct arrays that cannot be expressed conveniently with alternative notations.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1996 Hewlett-Packard Development Company, L.P.