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.

quantity
procedure_partition.f90
Replay: real traced execution (multi-file project)
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 = 4
    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 = 1
    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 = 6
    call compute_total(quantity, 7, total)
    print '(I0, 1X, I0)', quantity, total
end program procedure_partition_demo
  1. quantity ← 4

    18quantity = 419call compute_total(quantity, 7, total)
    values this step4quantity
  2. total ← 28

    18quantity = 419call compute_total(quantity, 7, total)20print '(I0, 1X, I0)', quantity, total
    values this step28total4quantity7unit_price
  3. print '(I0, 1X, I0)', quantity, total

    19    call compute_total(quantity, 7, total)20    print '(I0, 1X, I0)', quantity, total21end program procedure_partition_demo
    output4 28
    values this step4quantity28total
  1. quantity ← 1

    18quantity = 119call compute_total(quantity, 7, total)
    values this step1quantity
  2. total ← 7

    18quantity = 119call compute_total(quantity, 7, total)20print '(I0, 1X, I0)', quantity, total
    values this step7total1quantity7unit_price
  3. print '(I0, 1X, I0)', quantity, total

    19    call compute_total(quantity, 7, total)20    print '(I0, 1X, I0)', quantity, total21end program procedure_partition_demo
    output1 7
    values this step1quantity7total
  1. quantity ← 6

    18quantity = 619call compute_total(quantity, 7, total)
    values this step6quantity
  2. total ← 42

    18quantity = 619call compute_total(quantity, 7, total)20print '(I0, 1X, I0)', quantity, total
    values this step42total6quantity7unit_price
  3. print '(I0, 1X, I0)', quantity, total

    19    call compute_total(quantity, 7, total)20    print '(I0, 1X, I0)', quantity, total21end program procedure_partition_demo
    output6 42
    values this step6quantity42total
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.