SELECT TYPE construct
Standard: F77 F90 F95 F2003
  Example Program
<Syntax>
select-type-stmt
    [ type-guard-stmt
      block ]...
end-select-stmt

The syntax of the SELECT TYPE statement is as follows.

[ c-name : ] SELECT TYPE ( selector )

selector::=variable-name
 | associate-name => variable
 | associate-name => expr

If the SELECT TYPE statement has a construct name c-name, the END SELECT statement shall have the same construct name.
type-guard-stmt::=class-is-stmt
 | type-is-stmt
 | class-default-stmt

<Semantics>
The SELECT TYPE tests the dynamic type of a polymorphic variable or expression (the “selector”), and selects at most a single block for execution based on that type.

A TYPE IS block is executed if and only if the dynamic type is the type named in the TYPE IS statement. A CLASS IS block is executed if no TYPE IS statement matches, the dynamic type is an extension of the type named in the CLASS IS statement, and no more specific CLASS IS statement appears in the construct. A CLASS DEFAULT block is executed if no other block is executed.

The associate-name of a SELECT TYPE construct is local to the construct; its type and rank are determined by the construct and are unaffected by any declaration outside the construct. If the selector is variable-name, the associate name is considered to be the same as the variable-name.

Throughout the construct, the associate name is a variable if and only if the selector is a variable-name or variable; any changes to the associate name affect the variable with which it is associated. If it is associated with an expression (expr), the associate name is not permitted to appear in any context that requires a variable.

Within a TYPE IS block, the associate name is not polymorphic and has the type specified in the TYPE IS statement. Within a CLASS IS block, the associate name is polymorphic; it has the declared type specified in the CLASS IS statement. Within a CLASS DEFAULT block, the associate name is polymorphic, and has the same declared type as the selector.

In all cases, the associate name has the same dynamic type, rank and array bounds as the selector.

If the selector is a pointer or allocatable, it must be associated or allocated; the associate name does not have the POINTER or ALLOCATABLE attribute.
<Related>
CLASS specifier, CLASS DEFAULT statement, CLASS IS statement, TYPE statement, TYPE IS statement