[UP]


Manual Reference Pages  - size (3)

NAME

size(3f) - [FORTRAN:INTRINSIC:ARRAY INQUIRY] Determine the size of an array

CONTENTS

Syntax
Description
Arguments
Return Value
Example
Standard
Class
See Also

SYNTAX

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

DESCRIPTION

Determine the extent of ARRAY along a specified dimension DIM, or the total number of elements in ARRAY if DIM is absent.

ARGUMENTS

ARRAY - Shall be an array of any type. If ARRAY is a pointer it must be associated and allocatable arrays must be allocated.
DIM - (Optional) shall be a scalar of type INTEGER and its value shall be in the range from 1 to n, where n equals the rank of ARRAY.
KIND - (Optional) An INTEGER initialization expression indicating the kind parameter of the result.

RETURN VALUE

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

EXAMPLE

Sample program:

    program demo_size
    integer :: arr(0:2,-5:5)=reshape([(((i-1)*11+j,i=1,3),j=1,11)],[3,11])
       write(*,*) ’SIZE of simple one-dimensional array=’,size([ 11, 22, 33 ])    ! 3

write(*,*)’body’ write(*,*)’SHAPE(arr) :’,shape(arr) write(*,*)’SIZE(arr) :’,size(arr) write(*,*)’SIZE(arr,DIM=1) :’,size(arr,dim=1) write(*,*)’SIZE(arr,DIM=2) :’,size(arr,dim=2) write(*,*)’note lower bound is not "1"’ write(*,*)’LBOUND(arr) :’,lbound(arr) write(*,*)’UBOUND(arr) :’,ubound(arr) write(*,*)’LBOUND(arr,DIM=1):’,lbound(arr,dim=1) write(*,*)’UBOUND(arr,DIM=1):’,ubound(arr,dim=1) write(*,*)’LBOUND(arr,DIM=2):’,lbound(arr,dim=2) write(*,*)’UBOUND(arr,DIM=2):’,ubound(arr,dim=2)

call interfaced(arr,arr) call nointerface(arr) contains

subroutine interfaced(arr,arr2) integer,intent(in) :: arr(:,:) integer,intent(in) :: arr2(2,*) write(*,*)’interfaced assumed-shape array’ write(*,*)’SHAPE(arr) :’,shape(arr) write(*,*)’SIZE(arr) :’,size(arr) write(*,*)’SIZE(arr,DIM=1) :’,size(arr,dim=1) write(*,*)’SIZE(arr,DIM=2) :’,size(arr,dim=2) write(*,*)’note lower bound is "1"’ write(*,*)’LBOUND(arr) :’,lbound(arr) write(*,*)’LBOUND(arr) :’,lbound(arr) write(*,*)’UBOUND(arr) :’,ubound(arr) write(*,*)’LBOUND(arr,DIM=1):’,lbound(arr,dim=1) write(*,*)’UBOUND(arr,DIM=1):’,ubound(arr,dim=1) write(*,*)’LBOUND(arr,DIM=2):’,lbound(arr,dim=2) write(*,*)’UBOUND(arr,DIM=2):’,ubound(arr,dim=2) write(*,*)’interfaced’ write(*,*)’SHAPE(arr) :’,shape(arr) write(*,*)’SIZE(arr) :’,size(arr) write(*,*)’SIZE(arr,DIM=1) :’,size(arr,dim=1) write(*,*)’SIZE(arr,DIM=2) :’,size(arr,dim=2) write(*,*)’note lower bound is "1"’ write(*,*)’LBOUND(arr) :’,lbound(arr) write(*,*)’LBOUND(arr) :’,lbound(arr) write(*,*)’UBOUND(arr) :’,ubound(arr) write(*,*)’LBOUND(arr,DIM=1):’,lbound(arr,dim=1) write(*,*)’UBOUND(arr,DIM=1):’,ubound(arr,dim=1) write(*,*)’LBOUND(arr,DIM=2):’,lbound(arr,dim=2) write(*,*)’UBOUND(arr,DIM=2):’,ubound(arr,dim=2) end subroutine interfaced !! ! NOTE: If NOINTERFACE(3f) had an assumed-shape argument with : for dimensions it ! could only be properly called with an explicit interface !! subroutine nointerface(arr) integer,intent(in) :: arr(3,*) write(*,*)’nointerface’ !!write(*,*)’SHAPE(arr) :’,shape(arr) !! SHAPE(3f) CANNOT BE USED ON AN ASSUMED SIZE ARRAY !!write(*,*)’SIZE(arr) :’,size(arr) write(*,*)’SIZE(arr,DIM=1) :’,size(arr,dim=1) !!write(*,*)’SIZE(arr,DIM=2) :’,size(arr,dim=2) !! CANNOT DETERMINE SIZE OF ASSUMED SIZE ARRAY LAST DIMENSION write(*,*)’note lower bound is "1"’ write(*,*)’LBOUND(arr) :’,lbound(arr) !!write(*,*)’UBOUND(arr) :’,ubound(arr) write(*,*)’LBOUND(arr,DIM=1):’,lbound(arr,dim=1) write(*,*)’UBOUND(arr,DIM=1):’,ubound(arr,dim=1) write(*,*)’LBOUND(arr,DIM=2):’,lbound(arr,dim=2) !!write(*,*)’UBOUND(arr,DIM=2):’,ubound(arr,dim=2) end subroutine nointerface !! end program demo_size

Expected results:

    SIZE of simple one-dimensional array=           3
    body
    SHAPE(arr)       :           3          11
    SIZE(arr)        :          33
    SIZE(arr,DIM=1)  :           3
    SIZE(arr,DIM=2)  :          11
    note lower bound is not "1"
    LBOUND(arr)      :           0          -5
    UBOUND(arr)      :           2           5
    LBOUND(arr,DIM=1):           0
    UBOUND(arr,DIM=1):           2
    LBOUND(arr,DIM=2):          -5
    UBOUND(arr,DIM=2):           5
    interfaced assumed-shape array
    SHAPE(arr)       :           3          11
    SIZE(arr)        :          33
    SIZE(arr,DIM=1)  :           3
    SIZE(arr,DIM=2)  :          11
    note lower bound is "1"
    LBOUND(arr)      :           1           1
    LBOUND(arr)      :           1           1
    UBOUND(arr)      :           3          11
    LBOUND(arr,DIM=1):           1
    UBOUND(arr,DIM=1):           3
    LBOUND(arr,DIM=2):           1
    UBOUND(arr,DIM=2):          11
    interfaced
    SHAPE(arr)       :           3          11
    SIZE(arr)        :          33
    SIZE(arr,DIM=1)  :           3
    SIZE(arr,DIM=2)  :          11
    note lower bound is "1"
    LBOUND(arr)      :           1           1
    LBOUND(arr)      :           1           1
    UBOUND(arr)      :           3          11
    LBOUND(arr,DIM=1):           1
    UBOUND(arr,DIM=1):           3
    LBOUND(arr,DIM=2):           1
    UBOUND(arr,DIM=2):          11
    nointerface
    SIZE(arr,DIM=1)  :           3
    note lower bound is "1"
    LBOUND(arr)      :           1           1
    LBOUND(arr,DIM=1):           1
    UBOUND(arr,DIM=1):           3
    LBOUND(arr,DIM=2):           1

STANDARD

[[Fortran 95]] and later, with KIND argument [[Fortran 2003]] and later

CLASS

[[Inquiry function]]

SEE ALSO

[[shape]], [[reshape]]


size (3) March 19, 2019
Generated by manServer 1.08 from 0521bec7-4d31-4d5f-919b-a3e2ed7da976 using man macros.