HP Fortran Programmer's Reference (September 2007)

Program units and procedures
Modules
Chapter 7 193
The renaming feature can be used to resolve name conflicts when more than one module
contains an entity with the same name. Consider a program unit that has access by use
association to two modules: mod_defs1 mod_defs2. The names of the entities in mod_defs1
are a, b, and c; and the names of the entities in mod_defs2 are b, c, and d. The following USE
statements will avoid name conflicts within the using program unit:
USE mod_defs1
USE mod_defs2, b => local_b, c => local_c
The ONLY clause provides an additional level of control over access to module entities. As
described in “Module program unit” on page 190, the PRIVATE and PUBLIC attributes control
access to module entities in all using program units. The ONLY clause controls access within a
specific program unit.
For example, consider a module named mod_defs that contains the entities ent_x, ent_y, and
ent_z. If a program unit contains the following USE statement:
USE mod_defs, ONLY : ent_x, entry += local_y
it has access to ent_x and ent_y only. Furthermore, it must access ent_y by the name
local_y.
A program unit may have more than one USE statement specifying the same module:
If one of the USE statements is without the ONLY clause, then all module entities with the
PUBLIC attribute are accessible. Furthermore, all
local-names
from the
rename-lists
and
access-lists
are interpreted as a single concatenated
rename-list
.
If all of the USE statements have the ONLY clause, all of the
access-lists
are interpreted
as a single concatenated
access-list
.
For more information, see “USE” on page 488.
Program example
The following example program consists of three files:
main.f90
precision.f90
lin_eq_slv.f90
The file main.f90 is the driver that has access to entities in two modules—precision and
linear_equation_solver—by use association. The modules are the other two files.