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.

Arrays<br />

Array declarations<br />

For a given dimension, the values of lower-bound and upper-bound define the range of the<br />

array in that dimension. Usually, lower-bound is less than upper-bound; iflower-bound is<br />

thesameasupper-bound, then the dimension contains only one element; if it is greater, then<br />

the dimension contains no elements, the extent of the dimension is zero, and the array is<br />

zero-sized.<br />

The simplest form is represented by an array declaration in which the name of the array is<br />

not a dummy argument and all bounds are constant expressions, as in the following example:<br />

INTEGER :: a(100,4,5)<br />

This form of array may have the SAVE attribute and may be declared in any program unit.<br />

Other forms of the explicit-shape array include:<br />

58<br />

An automatic array: An array that is declared in a subprogram but is not a dummy<br />

argument and has at least one nonconstant bound. Automatic arrays may be declared in a<br />

subroutine or function, but may not have the SAVE attribute nor be initialized.<br />

Character strings can also be declared as automatic data objects; see “Character strings<br />

as automatic data objects” on page 39.<br />

A dummy array: An array that is identified by its appearance in a dummy argument list;<br />

its bounds may be constants or expressions. Dummy arrays may only be declared in a<br />

subroutine or function.<br />

An adjustable array: A particular form of a dummy array. Its name is specified in a<br />

dummy argument list, and at least one of its bounds is a nonconstant specification<br />

expression.<br />

Explicit-shape arrays may also be used as function results, as described in “Array-valued<br />

functions” on page 77 and in “Array dummy argument” on page 140.<br />

The following code segment illustrates different forms of explicit-shape arrays:<br />

SUBROUTINE sort(list1,list2,m,n)<br />

! examples of arrays with explicit shape<br />

INTEGER :: m,n<br />

INTEGER :: cnt1(2:99)<br />

! a rank-one array, having an explicit shape represented by<br />

! the vector [98]<br />

REAL :: list1(100), list2(0:m-1,-m:n)<br />

! two dummy arrays with explicit shape: list1 is a rank-one<br />

! array with an extent of 100; list2 is a rank-two array with an<br />

! extent of m * (m+n+1). list2 is also an adjustable array.<br />

REAL :: work(100,n)<br />

! work is an automatic array; it does not appear in the dummy<br />

! argument list and at least one of its bounds is not constant<br />

Chapter 4

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

Saved successfully!

Ooh no, something went wrong!