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.

factor
only_import.f90
Replay: real traced execution (multi-file project)
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 = 4
    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 = 2
    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 = 5
    total = scale(10, factor)
    print '(I0)', total
end program only_import_demo
  1. factor ← 4

    20factor = 421total = scale(10, factor)
    values this step4factor
  2. total ← 40

    20factor = 421total = scale(10, factor)22print '(I0)', total
    values this step40total4factor
  3. print '(I0)', total

    21    total = scale(10, factor)22    print '(I0)', total23end program only_import_demo
    output40
    values this step40total
  1. factor ← 2

    20factor = 221total = scale(10, factor)
    values this step2factor
  2. total ← 20

    20factor = 221total = scale(10, factor)22print '(I0)', total
    values this step20total2factor
  3. print '(I0)', total

    21    total = scale(10, factor)22    print '(I0)', total23end program only_import_demo
    output20
    values this step20total
  1. factor ← 5

    20factor = 521total = scale(10, factor)
    values this step5factor
  2. total ← 50

    20factor = 521total = scale(10, factor)22print '(I0)', total
    values this step50total5factor
  3. print '(I0)', total

    21    total = scale(10, factor)22    print '(I0)', total23end program only_import_demo
    output50
    values this step50total
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.