LBOUND(3) - [ARRAY:INQUIRY] Lower dimension bounds of an array
result = lbound(array [,dim] [,kind] )
elemental TYPE(kind=KIND) function lbound(array,dim,kind)TYPE(kind=KIND),intent(in) :: array(..) integer(kind=**),intent(in),optional :: dim integer(kind=**),intent(in),optional :: kind
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
LBOUND(3) returns the lower bounds of an array, or a single lower bound along the DIM dimension.
o ARRAY : Shall be an array, of any type. o DIM : Shall be a scalar integer. If DIM is absent, the result is an array of the upper bounds of ARRAY. o KIND : An integer initialization expression indicating the kind parameter of the result.
If DIM is absent, the result is an array of the lower bounds of ARRAY.
If DIM is present, the result is a scalar corresponding to the lower 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 lower bound is taken to be
NOTE1
1.
If ARRAY is assumed-rank and has rank zero, DIM cannot be present since it cannot satisfy the requirement 1 <= DIM <= 0.
Note that 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_lbound module m_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 m_boundsResults:program demo_lbound use m_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_lbound
> 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
Fortran 95 , with KIND argument - Fortran 2003
Array inquiry:
CO_UBOUND(3), CO_LBOUND(3)
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 UBOUND(3) - Upper dimension bounds of an array State Inquiry:
Kind Inquiry:
o ALLOCATED(3) - Status of an allocatable entity o IS_CONTIGUOUS(3) - Test if object is contiguous Bit Inquiry:
o KIND(3) - Kind of an entity Fortran intrinsic descriptions (license: MIT) @urbanjost
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.
Nemo Release 3.1 | lbound (3fortran) | November 02, 2024 |