SHAPE(3) - [ARRAY:INQUIRY] Determine the shape of an array or scalar
result = shape( source [,kind] )
integer(kind=KIND) function shape( source, KIND )type(TYPE(kind=**)),intent(in) :: source(..) integer(kind=**),intent(in),optional :: KIND
o a kind designated as ** may be any supported kind for the type o SOURCE is an array or scalar of any type. If SOURCE is a pointer it must be associated and allocatable arrays must be allocated. It shall not be an assumed-size array. o KIND is a constant integer initialization expression. o the result is an integer array of rank one with size equal to the rank of SOURCE of the kind specified by KIND if KIND is present, otherwise it has the default integer kind.
SHAPE(3) queries the shape of an array.
o SOURCE : an array or scalar of any type. If SOURCE is a pointer it must be associated and allocatable arrays must be allocated. o KIND : indicates the kind parameter of the result.
An integer array of rank one with as many elements as SOURCE has dimensions.
The elements of the resulting array correspond to the extent of SOURCE along the respective dimensions.
If SOURCE is a scalar, the result is an empty array (a rank-one array of size zero).
Sample program:
program demo_shape implicit none character(len=*),parameter :: all=(*(g0,1x)) integer, dimension(-1:1, -1:2) :: a print all, shape of array=,shape(a) print all, shape of constant=,shape(42) print all, size of shape of constant=,size(shape(42)) print all, ubound of array=,ubound(a) print all, lbound of array=,lbound(a) end program demo_shapeResults:
> shape of array= 3 4 > shape of constant= > size of shape of constant= 0 > ubound of array= 1 2 > lbound of array= -1 -1
Fortran 95 ; with KIND argument Fortran 2003
Array inquiry:
State Inquiry:
o SIZE(3) - Determine the size of an array o RANK(3) - Rank of a data object o UBOUND(3) - Upper dimension bounds of an array o LBOUND(3) - Lower dimension bounds of an array 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 | shape (3fortran) | November 02, 2024 |