Manual Reference Pages  - size (3fortran)

NAME

SIZE(3) - [ARRAY:INQUIRY] Determine the size of an array or extent of one dimension

SYNOPSIS

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

         integer(kind=KIND) function size(array,dim,kind)

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

CHARACTERISTICS

o ARRAY is an assumed-rank array or array of any type and associated kind.

If ARRAY is a pointer it must be associated and allocatable arrays must be allocated.

o DIM is an integer scalar
o KIND is a scalar integer constant expression.
o the result is an integer scalar of kind KIND. If KIND is absent a integer of default kind is returned.
o a kind designated as ** may be any supported kind for the type

DESCRIPTION

SIZE(3) returns the total number of elements in an array, or if DIM is specified returns the number of elements along that dimension.

SIZE(3) determines the extent of ARRAY along a specified dimension DIM, or the total number of elements in ARRAY if DIM is absent.

OPTIONS

o ARRAY : the array to measure the number of elements of. If ARRAY is an assumed-size array, DIM shall be present with a value less than the rank of ARRAY.
o DIM : a value shall be in the range from 1 to n, where n equals the rank of ARRAY.

If not present the total number of elements of the entire array are returned.

o KIND : An integer initialization expression indicating the kind parameter of the result.

If absent the kind type parameter of the returned value is that of default integer type.

The KIND must allow for the magnitude returned by SIZE or results are undefined.

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

RESULT

If DIM is not present ARRAY is assumed-rank, the result has a value equal to PRODUCT(SHAPE(ARRAY,KIND)). Otherwise, the result has a value equal to the total number of elements of ARRAY.

If DIM is present the number of elements along that dimension are returned, except that if ARRAY is assumed-rank and associated with an assumed-size array and DIM is present with a value equal to the rank of ARRAY, the value is -1.

NOTE1

If ARRAY is assumed-rank and has rank zero, DIM cannot be present since it cannot satisfy the requirement

1 <= DIM <= 0.

EXAMPLES

Sample program:

    program demo_size
    implicit none
    integer :: arr(0:2,-5:5)
       write(*,*)’SIZE of simple two-dimensional array’
       write(*,*)’SIZE(arr)       :total count of elements:’,size(arr)
       write(*,*)’SIZE(arr,DIM=1) :number of rows         :’,size(arr,dim=1)
       write(*,*)’SIZE(arr,DIM=2) :number of columns      :’,size(arr,dim=2)

! pass the same array to a procedure that passes the value two ! different ways call interfaced(arr,arr) contains

subroutine interfaced(arr1,arr2) ! notice the difference in the array specification ! for arr1 and arr2. integer,intent(in) :: arr1(:,:) integer,intent(in) :: arr2(2,*) ! write(*,*)’interfaced assumed-shape array’ write(*,*)’SIZE(arr1) :’,size(arr1) write(*,*)’SIZE(arr1,DIM=1) :’,size(arr1,dim=1) write(*,*)’SIZE(arr1,DIM=2) :’,size(arr1,dim=2)

! write(*,*)’SIZE(arr2) :’,size(arr2) write(*,*)’SIZE(arr2,DIM=1) :’,size(arr2,dim=1) ! ! CANNOT DETERMINE SIZE OF ASSUMED SIZE ARRAY LAST DIMENSION ! write(*,*)’SIZE(arr2,DIM=2) :’,size(arr2,dim=2)

end subroutine interfaced

end program demo_size

Results:

      > SIZE of simple two-dimensional array
      > SIZE(arr)       :total count of elements:          33
      > SIZE(arr,DIM=1) :number of rows         :           3
      > SIZE(arr,DIM=2) :number of columns      :          11
      > interfaced assumed-shape array
      > SIZE(arr1)        :          33
      > SIZE(arr1,DIM=1)  :           3
      > SIZE(arr1,DIM=2)  :          11
      > SIZE(arr2,DIM=1)  :           2

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 UBOUND(3) - Upper dimension bounds of an array
o LBOUND(3) - Lower dimension bounds of an array
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.
Fortran intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 size (3fortran) November 02, 2024
Generated by manServer 1.08 from c4618696-eaaf-40cd-9633-e81c7a51486f using man macros.