02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Program units and procedures<br />

Modules<br />

The renaming feature can be used to resolve name conflicts when more than one module<br />

contains an entity with the same name. Consider a program unit that has access by use<br />

association to two modules: mod_defs1 mod_defs2. The names of the entities in mod_defs1<br />

are a, b, andc; and the names of the entities in mod_defs2 are b, c, andd. The following USE<br />

statements will avoid name conflicts within the using program unit:<br />

USE mod_defs1<br />

USE mod_defs2, b => local_b, c => local_c<br />

The ONLY clause provides an additional level of control over access to module entities. As<br />

described in “Module program unit” on page 158, the PRIVATE and PUBLIC attributes control<br />

access to module entities in all using program units. The ONLY clause controls access within a<br />

specific program unit.<br />

For example, consider a module named mod_defs that contains the entities ent_x, ent_y, and<br />

ent_z. If a program unit contains the following USE statement:<br />

USE mod_defs, ONLY : ent_x, entry += local_y<br />

ithasaccesstoent_x and ent_y only. Furthermore, it must access ent_y by the name<br />

local_y.<br />

A program unit may have more than one USE statement specifying the same module:<br />

If one of the USE statements is without the ONLY clause, then all module entities with the<br />

PUBLIC attribute are accessible. Furthermore, all local-names from the rename-lists<br />

and access-lists are interpreted as a single concatenated rename-list.<br />

If all of the USE statements have the ONLY clause, all of the access-lists are interpreted<br />

as a single concatenated access-list.<br />

For more information, see “USE” on page 454.<br />

Program example<br />

The following example program consists of three files:<br />

main.f90<br />

precision.f90<br />

lin_eq_slv.f90<br />

The file main.f90 is the driver that has access to entities in two modules—precision and<br />

linear_equation_solver—by use association. The modules are the other two files.<br />

Chapter 7 161

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!