A batch summary can filter accepted values, count them, and compute an average for reporting.

Program

Play the program to choose a quality limit and watch the accepted count and average change.

limit
batch_summary_case.f90
Replay: real traced execution (multi-file project)
program batch_summary_case_demo
    implicit none
    integer :: values(4)
    integer :: limit
    integer :: accepted_count
    integer :: total
    real :: average
    integer :: i

    values = [4, 8, 11, 15]
    limit = 10
    accepted_count = 0
    total = 0
    do i = 1, 4
        if (values(i) <= limit) then
            accepted_count = accepted_count + 1
            total = total + values(i)
        end if
    end do
    average = real(total) / real(max(1, accepted_count))
    print '(I0, 1X, F0.1)', accepted_count, average
end program batch_summary_case_demo
program batch_summary_case_demo
    implicit none
    integer :: values(4)
    integer :: limit
    integer :: accepted_count
    integer :: total
    real :: average
    integer :: i

    values = [4, 8, 11, 15]
    limit = 8
    accepted_count = 0
    total = 0
    do i = 1, 4
        if (values(i) <= limit) then
            accepted_count = accepted_count + 1
            total = total + values(i)
        end if
    end do
    average = real(total) / real(max(1, accepted_count))
    print '(I0, 1X, F0.1)', accepted_count, average
end program batch_summary_case_demo
program batch_summary_case_demo
    implicit none
    integer :: values(4)
    integer :: limit
    integer :: accepted_count
    integer :: total
    real :: average
    integer :: i

    values = [4, 8, 11, 15]
    limit = 12
    accepted_count = 0
    total = 0
    do i = 1, 4
        if (values(i) <= limit) then
            accepted_count = accepted_count + 1
            total = total + values(i)
        end if
    end do
    average = real(total) / real(max(1, accepted_count))
    print '(I0, 1X, F0.1)', accepted_count, average
end program batch_summary_case_demo
  1. values ← [4, 8, 11, 15]

    10values = [4, 8, 11, 15]11limit = 10
    values this step[4, 8, 11, 15]values
  2. limit ← 10

    10values = [4, 8, 11, 15]11limit = 1012accepted_count = 0
    values this step10limit
  3. accepted_count ← 0

    11limit = 1012accepted_count = 013total = 0
    values this step0accepted_count
  4. total ← 0

    12accepted_count = 013total = 014do i = 1, 4
    values this step0total
  5. i ← 1

    13total = 014do i = 1, 415    if (values(i) <= limit) then
    values this step1i
  6. if (values(i) <= limit) then

    14do i = 1, 415    if (values(i) <= limit) then16        accepted_count = accepted_count + 1
    values this step.true.values(1) <= limit
  7. accepted_count ← 1

    15if (values(i) <= limit) then16    accepted_count = accepted_count + 117    total = total + values(i)
    values this step1accepted_count
  8. total ← 4

    16    accepted_count = accepted_count + 117    total = total + values(i)18end if
    values this step4total
  9. i ← 2

    13total = 014do i = 1, 415    if (values(i) <= limit) then
    values this step2i
  10. if (values(i) <= limit) then

    14do i = 1, 415    if (values(i) <= limit) then16        accepted_count = accepted_count + 1
    values this step.true.values(2) <= limit
  11. accepted_count ← 2

    15if (values(i) <= limit) then16    accepted_count = accepted_count + 117    total = total + values(i)
    values this step2accepted_count
  12. total ← 12

    16    accepted_count = accepted_count + 117    total = total + values(i)18end if
    values this step12total
  13. i ← 3

    13total = 014do i = 1, 415    if (values(i) <= limit) then
    values this step3i
  14. if (values(i) <= limit) then

    14do i = 1, 415    if (values(i) <= limit) then16        accepted_count = accepted_count + 1
    values this step.false.values(3) <= limit
  15. i ← 4

    13total = 014do i = 1, 415    if (values(i) <= limit) then
    values this step4i
  16. if (values(i) <= limit) then

    14do i = 1, 415    if (values(i) <= limit) then16        accepted_count = accepted_count + 1
    values this step.false.values(4) <= limit
  17. average ← 6.0

    19end do20average = real(total) / real(max(1, accepted_count))21print '(I0, 1X, F0.1)', accepted_count, average
    values this step6.0average12total2accepted_count
  18. print '(I0, 1X, F0.1)', accepted_count, average

    20    average = real(total) / real(max(1, accepted_count))21    print '(I0, 1X, F0.1)', accepted_count, average22end program batch_summary_case_demo
    output2 6.0
    values this step2accepted_count6.0average
  1. values ← [4, 8, 11, 15]

    10values = [4, 8, 11, 15]11limit = 8
    values this step[4, 8, 11, 15]values
  2. limit ← 8

    10values = [4, 8, 11, 15]11limit = 812accepted_count = 0
    values this step8limit
  3. accepted_count ← 0

    11limit = 812accepted_count = 013total = 0
    values this step0accepted_count
  4. total ← 0

    12accepted_count = 013total = 014do i = 1, 4
    values this step0total
  5. i ← 1

    13total = 014do i = 1, 415    if (values(i) <= limit) then
    values this step1i
  6. if (values(i) <= limit) then

    14do i = 1, 415    if (values(i) <= limit) then16        accepted_count = accepted_count + 1
    values this step.true.values(1) <= limit
  7. accepted_count ← 1

    15if (values(i) <= limit) then16    accepted_count = accepted_count + 117    total = total + values(i)
    values this step1accepted_count
  8. total ← 4

    16    accepted_count = accepted_count + 117    total = total + values(i)18end if
    values this step4total
  9. i ← 2

    13total = 014do i = 1, 415    if (values(i) <= limit) then
    values this step2i
  10. if (values(i) <= limit) then

    14do i = 1, 415    if (values(i) <= limit) then16        accepted_count = accepted_count + 1
    values this step.true.values(2) <= limit
  11. accepted_count ← 2

    15if (values(i) <= limit) then16    accepted_count = accepted_count + 117    total = total + values(i)
    values this step2accepted_count
  12. total ← 12

    16    accepted_count = accepted_count + 117    total = total + values(i)18end if
    values this step12total
  13. i ← 3

    13total = 014do i = 1, 415    if (values(i) <= limit) then
    values this step3i
  14. if (values(i) <= limit) then

    14do i = 1, 415    if (values(i) <= limit) then16        accepted_count = accepted_count + 1
    values this step.false.values(3) <= limit
  15. i ← 4

    13total = 014do i = 1, 415    if (values(i) <= limit) then
    values this step4i
  16. if (values(i) <= limit) then

    14do i = 1, 415    if (values(i) <= limit) then16        accepted_count = accepted_count + 1
    values this step.false.values(4) <= limit
  17. average ← 6.0

    19end do20average = real(total) / real(max(1, accepted_count))21print '(I0, 1X, F0.1)', accepted_count, average
    values this step6.0average12total2accepted_count
  18. print '(I0, 1X, F0.1)', accepted_count, average

    20    average = real(total) / real(max(1, accepted_count))21    print '(I0, 1X, F0.1)', accepted_count, average22end program batch_summary_case_demo
    output2 6.0
    values this step2accepted_count6.0average
  1. values ← [4, 8, 11, 15]

    10values = [4, 8, 11, 15]11limit = 12
    values this step[4, 8, 11, 15]values
  2. limit ← 12

    10values = [4, 8, 11, 15]11limit = 1212accepted_count = 0
    values this step12limit
  3. accepted_count ← 0

    11limit = 1212accepted_count = 013total = 0
    values this step0accepted_count
  4. total ← 0

    12accepted_count = 013total = 014do i = 1, 4
    values this step0total
  5. i ← 1

    13total = 014do i = 1, 415    if (values(i) <= limit) then
    values this step1i
  6. if (values(i) <= limit) then

    14do i = 1, 415    if (values(i) <= limit) then16        accepted_count = accepted_count + 1
    values this step.true.values(1) <= limit
  7. accepted_count ← 1

    15if (values(i) <= limit) then16    accepted_count = accepted_count + 117    total = total + values(i)
    values this step1accepted_count
  8. total ← 4

    16    accepted_count = accepted_count + 117    total = total + values(i)18end if
    values this step4total
  9. i ← 2

    13total = 014do i = 1, 415    if (values(i) <= limit) then
    values this step2i
  10. if (values(i) <= limit) then

    14do i = 1, 415    if (values(i) <= limit) then16        accepted_count = accepted_count + 1
    values this step.true.values(2) <= limit
  11. accepted_count ← 2

    15if (values(i) <= limit) then16    accepted_count = accepted_count + 117    total = total + values(i)
    values this step2accepted_count
  12. total ← 12

    16    accepted_count = accepted_count + 117    total = total + values(i)18end if
    values this step12total
  13. i ← 3

    13total = 014do i = 1, 415    if (values(i) <= limit) then
    values this step3i
  14. if (values(i) <= limit) then

    14do i = 1, 415    if (values(i) <= limit) then16        accepted_count = accepted_count + 1
    values this step.true.values(3) <= limit
  15. accepted_count ← 3

    15if (values(i) <= limit) then16    accepted_count = accepted_count + 117    total = total + values(i)
    values this step3accepted_count
  16. total ← 23

    16    accepted_count = accepted_count + 117    total = total + values(i)18end if
    values this step23total
  17. i ← 4

    13total = 014do i = 1, 415    if (values(i) <= limit) then
    values this step4i
  18. if (values(i) <= limit) then

    14do i = 1, 415    if (values(i) <= limit) then16        accepted_count = accepted_count + 1
    values this step.false.values(4) <= limit
  19. average ← 7.7

    19end do20average = real(total) / real(max(1, accepted_count))21print '(I0, 1X, F0.1)', accepted_count, average
    values this step7.7average23total3accepted_count
  20. print '(I0, 1X, F0.1)', accepted_count, average

    20    average = real(total) / real(max(1, accepted_count))21    print '(I0, 1X, F0.1)', accepted_count, average22end program batch_summary_case_demo
    output3 7.7
    values this step3accepted_count7.7average
filter `values(i) <= limit` chooses which readings belong in the summary.
safe average `max(1, accepted_count)` avoids division by zero.
case composition The example combines arrays, loops, guards, and reporting.