Multi-File Program Structure
Procedure Partition
Keeping Work Behind Calls
A module subroutine can own the calculation while the caller passes data in and receives a result out.
Program
Play the program to choose a quantity and let the module procedure calculate the total.
procedure_partition.f90
module invoice_mod
implicit none
contains
subroutine compute_total(quantity, unit_price, total)
integer, intent(in) :: quantity
integer, intent(in) :: unit_price
integer, intent(out) :: total
total = quantity * unit_price
end subroutine compute_total
end module invoice_mod
program procedure_partition_demo
use invoice_mod, only: compute_total
implicit none
integer :: quantity
integer :: total
quantity =
call compute_total(quantity, 7, total)
print '(I0, 1X, I0)', quantity, total
end program procedure_partition_demo
module invoice_mod
implicit none
contains
subroutine compute_total(quantity, unit_price, total)
integer, intent(in) :: quantity
integer, intent(in) :: unit_price
integer, intent(out) :: total
total = quantity * unit_price
end subroutine compute_total
end module invoice_mod
program procedure_partition_demo
use invoice_mod, only: compute_total
implicit none
integer :: quantity
integer :: total
quantity =
call compute_total(quantity, 7, total)
print '(I0, 1X, I0)', quantity, total
end program procedure_partition_demo
module invoice_mod
implicit none
contains
subroutine compute_total(quantity, unit_price, total)
integer, intent(in) :: quantity
integer, intent(in) :: unit_price
integer, intent(out) :: total
total = quantity * unit_price
end subroutine compute_total
end module invoice_mod
program procedure_partition_demo
use invoice_mod, only: compute_total
implicit none
integer :: quantity
integer :: total
quantity =
call compute_total(quantity, 7, total)
print '(I0, 1X, I0)', quantity, total
end program procedure_partition_demo
subroutine
`compute_total` performs work through arguments instead of returning a value.
intent
`intent(in)` and `intent(out)` document data direction across the boundary.
partition
The caller stays small because the calculation lives behind a module call.