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

subscript in the last dimension of an assumed-size array may extend from the lower bound to<br />

a value that does not cause the reference to go beyond the storage associated with the actual<br />

argument.<br />

Because the last dimension of an assumed-size array has no upper bound, the dimension has<br />

no extent and the array consequently has no shape. The name of an assumed-size array<br />

therefore cannot appear in contexts in which a shape is required, such as a function result or<br />

a whole array reference.<br />

The following example, assumed_size.f90, illustrates two assumed-size arrays: x (declared in<br />

subr) andi_array (declared in func):<br />

Example 4-2 assumed_size.f90<br />

PROGRAM main<br />

REAL :: a(2,3) ! an explicit-shape array, represented by the<br />

! vector [10, 10]<br />

k = 0<br />

DO i = 1, 3<br />

DO j = 1, 2<br />

k = k + 1<br />

a(j, i) = k<br />

END DO<br />

END DO<br />

PRINT *, 'main: a =', a<br />

CALL subr (a)<br />

END PROGRAM main<br />

SUBROUTINE subr(x)<br />

REAL :: x(2,*) ! an assumed-size array; the subscript for the<br />

! last dimension may take any value 1 - 3<br />

! PRINT *, x ! ILLEGAL, whole array reference not allowed<br />

64<br />

PRINT *, ‘main: x(2, 2) = ‘, x(2, 2)<br />

PRINT *, 'returned by func: ', func(x), ', the value in x(2,3)'<br />

END SUBROUTINE subr<br />

REAL FUNCTION func(y)<br />

REAL :: y(0:*) ! an assumed-size array; the subscript may<br />

! take any value 0 - 5<br />

func = y(5)<br />

END FUNCTION func<br />

Here are the command lines to compile and execute the program, along with the output from<br />

asamplerun:<br />

Chapter 4

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

Saved successfully!

Ooh no, something went wrong!