Fortran – Inquiry Functions

Fortran inquiry functions

In this guide, we will discuss Fortran Inquiry Functions. The following table describes the inquiry functions −

Sr.NoFunction & Description
1allocated(array)
It is a logical function which indicates if the array is allocated.
2lbound(array, dim)
It returns the lower dimension limit for the array. If dim (the dimension) is not given as an argument, you get an integer vector, if dim is included, you get the integer value with exactly that lower dimension limit, for which you asked.
3shape(source)
It returns the shape of an array source as an integer vector.
4size(array, dim)
It returns the number of elements in an array. If dim is not given, and the number of elements in the relevant dimension if dim is included.
5ubound(array, dim)
It returns the upper dimensional limits.

Example

The following example demonstrates the concept −

program arrayInquiry

   real, dimension(3,2) :: a 
   a = reshape( (/5,9,6,10,8,12/), (/3,2/) ) 
   
   Print *, lbound(a, dim = 1)
   Print *, ubound(a, dim = 1)
   Print *, shape(a)
   Print *, size(a,dim = 1)
   
end program arrayInquiry

When the above code is compiled and executed, it produces the following result −

1
3
3 2
3

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply