Software Archive
Read-only legacy content
17061 Discussions

Use of intrinsic function: UBOUND !

aagaard
Beginner
404 Views
I am trying to use the intrinsic function UBOUND to determine the size of an array, transferred as parameter to a subroutine. I am not able even to compile the code.
As far as I read the documentation, it should be possible the determine the upper bound of an assumed size array.
What am I dping wrong ????

Example:
 
   program bounds 
 
   implicit none 
 
   INTEGER(4), PARAMETER :: MXDIME=10 
   INTEGER(4)  :: NXTEST,MXBOUN 
   DIMENSION NXTEST(1:MXDIME) 
 
      MXBOUN=LBOUND(NXTEST,DIM=1) 
      WRITE(*,*) 'MAIN:LOWER BOUNDS:',MXBOUN 
 
      MXBOUN=UBOUND(NXTEST,DIM=1) 
      WRITE(*,*) 'MAIN:UPPER BOUNDS:',MXBOUN 
 
      CALL XTESTS(NXTEST) 
 
   end program bounds 
 
    SUBROUTINE XTESTS(NYTEST) 
 
    IMPLICIT NONE 
    INTEGER(4)  :: NYTEST,MXBOUN 
    DIMENSION NYTEST(*) 
 
       MXBOUN=LBOUND(NYTEST,DIM=1) 
       WRITE(*,*) 'SUB:LOWER BOUNDS:',MXBOUN 
 
       MXBOUN=UBOUND(NYTEST,DIM=1) 
       WRITE(*,*) 'SUB:UPPER BOUNDS:',MXBOUN 
    END 
 
0 Kudos
1 Reply
Steven_L_Intel1
Employee
404 Views
The wording in the manual is "It can be an assumed-size array if DIM is present with a value less than the rank of ARRAY." (emphasis mine).

In your case, your array argument has rank 1, therefore there is no value of DIM that is acceptable. The idea is if you have a multi-dimensioned array, you can use UBOUND to get the bound of all but the last dimension, since only the last is permitted to have * as an upper bound.

Steve
0 Kudos
Reply