Modules at Scale
Only Import
Keeping Scope Small
use ..., only: imports selected public names from a module instead of bringing every public name into scope.
Program
Play the program to choose a factor and call only the imported scaling function.
only_import.f90
module scale_tools
implicit none
private
public :: scale
contains
function scale(value, factor) result(total)
integer, intent(in) :: value
integer, intent(in) :: factor
integer :: total
total = value * factor
end function scale
end module scale_tools
program only_import_demo
use scale_tools, only: scale
implicit none
integer :: factor
integer :: total
factor =
total = scale(10, factor)
print '(I0)', total
end program only_import_demo
module scale_tools
implicit none
private
public :: scale
contains
function scale(value, factor) result(total)
integer, intent(in) :: value
integer, intent(in) :: factor
integer :: total
total = value * factor
end function scale
end module scale_tools
program only_import_demo
use scale_tools, only: scale
implicit none
integer :: factor
integer :: total
factor =
total = scale(10, factor)
print '(I0)', total
end program only_import_demo
module scale_tools
implicit none
private
public :: scale
contains
function scale(value, factor) result(total)
integer, intent(in) :: value
integer, intent(in) :: factor
integer :: total
total = value * factor
end function scale
end module scale_tools
program only_import_demo
use scale_tools, only: scale
implicit none
integer :: factor
integer :: total
factor =
total = scale(10, factor)
print '(I0)', total
end program only_import_demo
only
`only: scale` imports just the names the program needs.
private default
`private` makes the module surface explicit.
public list
`public :: scale` documents the exported API.