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

ID 767251
Date 3/31/2023
Public

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

Document Table of Contents

IMPORT

Statement: Controls accessibility of host entities in a submodule, module procedure, a contained procedure, a block construct, or in the interface body of an interface block.

The IMPORT statement takes the following form:

IMPORT [[::] import-name-list]

IMPORT,ONLY: import-name-list

IMPORT,NONE

IMPORT,ALL

import-name-list

(Input) Is the name of one or more entities accessible in the host scoping unit.

An IMPORT statement can appear in a submodule, module procedure, a contained procedure, the specification part of a BLOCK construct, or in an interface body. It can not appear in the specification part of a main program, external procedure, module, or block data except in an interface body.

An IMPORT statement must appear after any USE statements, and before any other specification statements. Each of the named entities must be an accessible entity in the host scoping unit. Within an interface body each named entity must be explicitly declared before the interface body, or accessible by use or host association in the host containing the IMPORT statement.

If IMPORT, ONLY appears within a scoping unit, all other IMPORT statements in that scoping unit must be IMPORT, ONLY statements. An entity is host associated in a scoping unit which contains an IMPORT, ONLY statement if it appears in an import-name-list in that scoping unit.

If IMPORT, NONE is specified, no entities in the host are accessible by host association in that scoping unit. This is the default behavior for interface bodies for a dummy or external procedure. IMPORT, NONE must not appear in the specification part of a submodule.

If an IMPORT, ALL or an IMPORT, NONE statement appears in a scoping unit, it must be the only IMPORT statement in that scoping unit.

If import-name-list is not specified, and if ALL, ONLY, or NONE are not specified, all of the accessible named entities in the host scoping unit are imported unless they are made inaccessible by an entity of the same name in the local scope. This is the default behavior for a nested scoping unit, other than an interface body, for a dummy or external procedure.

If IMPORT, ALL is specified, all entities in the host are accessible by host association. If an entity is made accessible by an IMPORT, ALL statement or by its name appearing in an import-name-list, it cannot be made inaccessible by declaring another entity with the same name in the local scope.

If an IMPORT statement with an import-name-list appears, only the named entities are available by host association.

Examples

The following examples show how the IMPORT statement can be applied.

module mymod
type mytype
  integer comp
end type mytype
interface
  subroutine sub (arg)
    import
    type(mytype) :: arg
  end subroutine sub
end interface
end module mymod

module host
  integer  :: i, j, k
  contains
  subroutine sub1 ()
    import :: i, j
    k = i + j      ! only i and j are host associated, k is local to sub1
  end subroutine
  subroutine sub2 ()
    import, none
    k = i + j      ! i, j, and k are local to sub2
  end subroutine
  subroutine sub3 ()
    import all 
    k = i + j      ! i, j, and k are all host associated
  end subroutine
  subroutine sub4 ()
    import, only : i
    import, only : j
    k = i + j      ! i and j are host associated, k is local
  end subroutine
end module