Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 9/08/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Assumed-Length Type Parameters for Parameterized Derived Types

The length type parameter is assumed when an asterisk is used as a type-param-value in a type-param-spec. An asterisk may be used only in the declaration of a dummy argument, in the associate name in a SELECT TYPE statement, or in the allocation of a dummy argument. The value is taken from that of the actual argument.

Type(matrix(KIND(0d0), 10, :)), pointer :: y(:)
Call print_matrix(y)
...
Subroutine print_matrix(x)

  ! d1 here is assumed and its value '10' is obtained from the actual argument
  Type(matrix(k= KIND(0d0), d1=*, d2=:), pointer :: x(:)
  ALLOCATE(matrix(KIND(0.0), *, 10) :: x(10))
  ...
End Subroutine

All length type parameters of the dummy argument must be assumed for a final subroutine. All length type parameters of the first dummy argument to a user-defined I/O subroutine must be assumed. All of the length type parameters of a passed-object dummy argument must be assumed. In a SELECT TYPE construct, each length type parameter in a type-guard-stmt must be assumed.

Array Constructors

If type-spec in an array constructor specifies a parameterized derived type, all ac-value expressions in the array constructor must be of that derived type and must have the same kind type parameter values as specified by type-spec. Also, type-spec specifies the declared type and type parameters of the array constructor.

Each ac-value expression in the array constructor must be compatible with intrinsic assignment to a variable of this type and type parameter. Each value is converted to the type parameters of the array constructor in accordance with the rules of intrinsic assignment.

If type-spec is omitted, each ac-value expression in the array constructor must have the same length type parameters; in which case, the declared type and type parameters of the array constructor are those of the ac-value expressions.

Type Parameter Inquiry

The value of a derived-type parameter can be accessed from outside the type definition, using the same notation as component access.

print *,’No: of Rows =’,my_matrix%d1
print *,’No: of Columns =’,my_matrix%d2

Unlike components, a type parameter inquiry cannot be used on the left-hand side of an assignment, and type parameters are effectively always public. The value of a deferred type parameter of an unallocated allocatable, or of a pointer that is not associated with a target, is undefined and must not be inquired about. The length type parameters of an optional dummy argument that is not present must not be the subject of an inquiry.

The type parameters of intrinsic types can also be inquired using this syntax. The result is always scalar, even if the object is an array.

REAL(selected_real_kind(10,20)) :: z(100)
..
PRINT *,z%kind ! A single value is printed

This is same as calling KIND(z). However, the type parameter inquiry can be used even when the intrinsic function is not available.

Subroutine write_centered(ch, len)
  Character(*), intent(inout) :: ch
  Integer, intent(in) :: len
  Integer :: i
  Do i=1, (len – ch%len)/2
  ...
! The inquiry ch%len cannot be replaced with len(ch) since len is the 
! name of a dummy argument