Lahey/Fujitsu Fortran

USE Statement

Description

The USE statement specifies that a module is accessible from the current scoping unit. It also provides a means of renaming or limiting the accessibility of entities in the module.

Syntax

USE module [, rename-list]

or

USE module, ONLY: [only-list]

Where:

module is the name of a module.

rename-list is a comma-separated list of local-name => use-name

only-list is a comma-separated list of access-id or [local-name => use-name]

local-name is the local name for the entity specified by use-name

use-name is the name of a public entity in the specified module

access-id is use-name

or generic-spec

generic-spec is generic-name

or OPERATOR (defined-operator)

or ASSIGNMENT (=)

generic-name is the name of a generic procedure.

defined-operator is one of the intrinsic operators

or .op-name.

.op-name. is a user-defined name for the operation.

Remarks

A USE statement without ONLY provides access to all PUBLIC entities in the specified module.

A USE statement with ONLY provides access only to those entities that appear in the only-list.

If more than one USE statement appears in a scoping unit, the rename-lists and only-lists are treated as one concatenated rename-list.

If two or more generic interfaces that are accessible in the same scoping unit have the same name, same operator, or are assignments, they are interpreted as a single generic interface.

Two or more accessible entities, other than generic interfaces, can have the same name only if no entity is referenced by this name in the scoping unit.

If local-name is absent, the use-name is available by use association.

An entity can be accessed by more than one local-name.

A local-name must not be declared with different attributes in the scoping unit that contains the USE statement, except that it can appear in a PUBLIC or PRIVATE statement in the scoping unit of a module.

Forward references to modules are not allowed in LF95. That is, if a module is used in the same source file in which it resides, the module program unit must appear before its use.

Example

module mod1 integer :: i,j,k real :: a,b,c end module mod1 subroutine sub1() use mod1 ! a,b,c,i,j,k all available by use association end subroutine sub1 subroutine sub2() use mod1, only: a,b ! a,b are available, c,i,j,k not available end subroutine sub2 subroutine sub3() use mod1, aa=>a ! a is known as aa within the scope of sub3 end subroutine sub3