Modules at Scale
Renamed Import
Local Module Names
A use statement can rename an imported procedure so the local code reads clearly.
Program
Play the program to choose a meter count and call the imported function through its local name.
renamed_import.f90
Replay: real traced execution (multi-file project)
module unit_tools
implicit none
contains
function centimeters(meters) result(cm)
integer, intent(in) :: meters
integer :: cm
cm = meters * 100
end function centimeters
end module unit_tools
program renamed_import_demo
use unit_tools, only: to_cm => centimeters
implicit none
integer :: meters
integer :: total_cm
meters = 3
total_cm = to_cm(meters)
print '(I0)', total_cm
end program renamed_import_demo
module unit_tools
implicit none
contains
function centimeters(meters) result(cm)
integer, intent(in) :: meters
integer :: cm
cm = meters * 100
end function centimeters
end module unit_tools
program renamed_import_demo
use unit_tools, only: to_cm => centimeters
implicit none
integer :: meters
integer :: total_cm
meters = 1
total_cm = to_cm(meters)
print '(I0)', total_cm
end program renamed_import_demo
module unit_tools
implicit none
contains
function centimeters(meters) result(cm)
integer, intent(in) :: meters
integer :: cm
cm = meters * 100
end function centimeters
end module unit_tools
program renamed_import_demo
use unit_tools, only: to_cm => centimeters
implicit none
integer :: meters
integer :: total_cm
meters = 5
total_cm = to_cm(meters)
print '(I0)', total_cm
end program renamed_import_demo
meters ← 3
17meters = 318total_cm = to_cm(meters)values this step3meterstotal_cm ← 300
17meters = 318total_cm = to_cm(meters)19print '(I0)', total_cmvalues this step300total_cm3metersprint '(I0)', total_cm
18 total_cm = to_cm(meters)19 print '(I0)', total_cm20end program renamed_import_demooutput300values this step300total_cm
meters ← 1
17meters = 118total_cm = to_cm(meters)values this step1meterstotal_cm ← 100
17meters = 118total_cm = to_cm(meters)19print '(I0)', total_cmvalues this step100total_cm1metersprint '(I0)', total_cm
18 total_cm = to_cm(meters)19 print '(I0)', total_cm20end program renamed_import_demooutput100values this step100total_cm
meters ← 5
17meters = 518total_cm = to_cm(meters)values this step5meterstotal_cm ← 500
17meters = 518total_cm = to_cm(meters)19print '(I0)', total_cmvalues this step500total_cm5metersprint '(I0)', total_cm
18 total_cm = to_cm(meters)19 print '(I0)', total_cm20end program renamed_import_demooutput500values this step500total_cm
rename
`to_cm => centimeters` gives the imported function a local name.
module API
The original module still exports `centimeters`.
local clarity
The program can choose a shorter or domain-specific call name.