Manual Reference Pages  - ubound (3fortran)

NAME

UBOUND(3) - [ARRAY:INQUIRY] Upper dimension bounds of an array

SYNOPSIS

result = ubound(array [,dim] [,kind] )

         elemental TYPE(kind=KIND) function ubound(array,dim,kind)

TYPE(kind=KIND),intent(in) :: array integer(kind=**),intent(in),optional :: dim integer(kind=**),intent(in),optional :: kind

CHARACTERISTICS

o ARRAY shall be assumed-rank or an array, of any type. It cannot be an unallocated allocatable array or a pointer that is not associated.
o DIM shall be a scalar integer. The corresponding actual argument shall not be an optional dummy argument, a disassociated pointer, or an unallocated allocatable.
o KIND an integer initialization expression indicating the kind parameter of the result.
o The return value is of type integer and of kind KIND. If KIND is absent, the return value is of default integer kind. The result is scalar if DIM is present; otherwise, the result is an array of rank one and size n, where n is the rank of ARRAY.
o a kind designated as ** may be any supported kind for the type

DESCRIPTION

UBOUND(3) returns the upper bounds of an array, or a single upper bound along the DIM dimension.

OPTIONS

o ARRAY : The assumed-rank or array of any type whose upper bounds are to be determined. If allocatable it must be allocated; if a pointer it must be associated. If an assumed-size array, DIM must be present.
o DIM : a specific dimension of ARRAY to determine the bounds of. If DIM is absent, the result is an array of the upper bounds of ARRAY. DIM is required if ARRAY is an assumed-size array, and in that case must be less than or equal to the rank of ARRAY.
o KIND : indicates the kind parameter of the result. If absent, an integer of the default kind is returned.

RESULT

The return value is of type integer and of kind KIND. If KIND is absent, the return value is of default integer kind.

If DIM is absent, the result is an array of the upper bounds of each dimension of the ARRAY.

If DIM is present, the result is a scalar corresponding to the upper bound of the array along that dimension.

If ARRAY is an expression rather than a whole array or array structure component, or if it has a zero extent along the relevant dimension, the upper bound is taken to be the number of elements along the relevant dimension.

NOTE1 If ARRAY is assumed-rank and has rank zero, DIM cannot be present since it cannot satisfy the requirement 1 <= DIM <= 0.

EXAMPLES

Note this function should not be used on assumed-size arrays or in any function without an explicit interface. Errors can occur if there is no interface defined.

Sample program

    ! program demo_ubound
    module m2_bounds
    implicit none

contains

subroutine msub(arr) !!integer,intent(in) :: arr(*) ! cannot be assumed-size array integer,intent(in) :: arr(:) write(*,*)’MSUB: LOWER=’,lbound(arr),’UPPER=’,ubound(arr), & & ’SIZE=’,size(arr) end subroutine msub

end module m2_bounds ! program demo_ubound use m2_bounds, only : msub implicit none interface subroutine esub(arr) integer,intent(in) :: arr(:) end subroutine esub end interface integer :: arr(-10:10) write(*,*)’MAIN: LOWER=’,lbound(arr),’UPPER=’,ubound(arr), & & ’SIZE=’,size(arr) call csub() call msub(arr) call esub(arr) contains subroutine csub write(*,*)’CSUB: LOWER=’,lbound(arr),’UPPER=’,ubound(arr), & & ’SIZE=’,size(arr) end subroutine csub

end

subroutine esub(arr) implicit none integer,intent(in) :: arr(:) ! WARNING: IF CALLED WITHOUT AN EXPLICIT INTERFACE ! THIS WILL GIVE UNDEFINED ANSWERS (like 0,0,0) write(*,*)’ESUB: LOWER=’,lbound(arr),’UPPER=’,ubound(arr), & & ’SIZE=’,size(arr) end subroutine esub !end program demo_ubound

Results:

     >  MAIN: LOWER=         -10 UPPER=          10 SIZE=          21
     >  CSUB: LOWER=         -10 UPPER=          10 SIZE=          21
     >  MSUB: LOWER=           1 UPPER=          21 SIZE=          21
     >  ESUB: LOWER=           1 UPPER=          21 SIZE=          21

STANDARD

Fortran 95 , with KIND argument Fortran 2003

SEE ALSO

Array inquiry:
o SIZE(3) - Determine the size of an array
o RANK(3) - Rank of a data object
o SHAPE(3) - Determine the shape of an array
o LBOUND(3) - Lower dimension bounds of an array
CO_UBOUND(3), CO_LBOUND(3)

State Inquiry:
o ALLOCATED(3) - Status of an allocatable entity
o IS_CONTIGUOUS(3) - Test if object is contiguous
Kind Inquiry:
o KIND(3) - Kind of an entity
Bit Inquiry:
o STORAGE_SIZE(3) - Storage size in bits
o BIT_SIZE(3) - Bit size inquiry function
o BTEST(3) - Tests a bit of an integer value.
o LBOUND(3),
Fortran intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 ubound (3fortran) November 02, 2024
Generated by manServer 1.08 from 253d0485-6033-4605-b24d-26f023f73540 using man macros.