Case Studies
Batch Summary Case
Filtering and Averaging
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.
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
values ← [4, 8, 11, 15]
10values = [4, 8, 11, 15]11limit = 10values this step[4, 8, 11, 15]valueslimit ← 10
10values = [4, 8, 11, 15]11limit = 1012accepted_count = 0values this step10limitaccepted_count ← 0
11limit = 1012accepted_count = 013total = 0values this step0accepted_counttotal ← 0
12accepted_count = 013total = 014do i = 1, 4values this step0totali ← 1
13total = 014do i = 1, 415 if (values(i) <= limit) thenvalues this step1iif (values(i) <= limit) then
14do i = 1, 415 if (values(i) <= limit) then16 accepted_count = accepted_count + 1values this step.true.values(1) <= limitaccepted_count ← 1
15if (values(i) <= limit) then16 accepted_count = accepted_count + 117 total = total + values(i)values this step1accepted_counttotal ← 4
16 accepted_count = accepted_count + 117 total = total + values(i)18end ifvalues this step4totali ← 2
13total = 014do i = 1, 415 if (values(i) <= limit) thenvalues this step2iif (values(i) <= limit) then
14do i = 1, 415 if (values(i) <= limit) then16 accepted_count = accepted_count + 1values this step.true.values(2) <= limitaccepted_count ← 2
15if (values(i) <= limit) then16 accepted_count = accepted_count + 117 total = total + values(i)values this step2accepted_counttotal ← 12
16 accepted_count = accepted_count + 117 total = total + values(i)18end ifvalues this step12totali ← 3
13total = 014do i = 1, 415 if (values(i) <= limit) thenvalues this step3iif (values(i) <= limit) then
14do i = 1, 415 if (values(i) <= limit) then16 accepted_count = accepted_count + 1values this step.false.values(3) <= limiti ← 4
13total = 014do i = 1, 415 if (values(i) <= limit) thenvalues this step4iif (values(i) <= limit) then
14do i = 1, 415 if (values(i) <= limit) then16 accepted_count = accepted_count + 1values this step.false.values(4) <= limitaverage ← 6.0
19end do20average = real(total) / real(max(1, accepted_count))21print '(I0, 1X, F0.1)', accepted_count, averagevalues this step6.0average12total2accepted_countprint '(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_demooutput2 6.0values this step2accepted_count6.0average
values ← [4, 8, 11, 15]
10values = [4, 8, 11, 15]11limit = 8values this step[4, 8, 11, 15]valueslimit ← 8
10values = [4, 8, 11, 15]11limit = 812accepted_count = 0values this step8limitaccepted_count ← 0
11limit = 812accepted_count = 013total = 0values this step0accepted_counttotal ← 0
12accepted_count = 013total = 014do i = 1, 4values this step0totali ← 1
13total = 014do i = 1, 415 if (values(i) <= limit) thenvalues this step1iif (values(i) <= limit) then
14do i = 1, 415 if (values(i) <= limit) then16 accepted_count = accepted_count + 1values this step.true.values(1) <= limitaccepted_count ← 1
15if (values(i) <= limit) then16 accepted_count = accepted_count + 117 total = total + values(i)values this step1accepted_counttotal ← 4
16 accepted_count = accepted_count + 117 total = total + values(i)18end ifvalues this step4totali ← 2
13total = 014do i = 1, 415 if (values(i) <= limit) thenvalues this step2iif (values(i) <= limit) then
14do i = 1, 415 if (values(i) <= limit) then16 accepted_count = accepted_count + 1values this step.true.values(2) <= limitaccepted_count ← 2
15if (values(i) <= limit) then16 accepted_count = accepted_count + 117 total = total + values(i)values this step2accepted_counttotal ← 12
16 accepted_count = accepted_count + 117 total = total + values(i)18end ifvalues this step12totali ← 3
13total = 014do i = 1, 415 if (values(i) <= limit) thenvalues this step3iif (values(i) <= limit) then
14do i = 1, 415 if (values(i) <= limit) then16 accepted_count = accepted_count + 1values this step.false.values(3) <= limiti ← 4
13total = 014do i = 1, 415 if (values(i) <= limit) thenvalues this step4iif (values(i) <= limit) then
14do i = 1, 415 if (values(i) <= limit) then16 accepted_count = accepted_count + 1values this step.false.values(4) <= limitaverage ← 6.0
19end do20average = real(total) / real(max(1, accepted_count))21print '(I0, 1X, F0.1)', accepted_count, averagevalues this step6.0average12total2accepted_countprint '(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_demooutput2 6.0values this step2accepted_count6.0average
values ← [4, 8, 11, 15]
10values = [4, 8, 11, 15]11limit = 12values this step[4, 8, 11, 15]valueslimit ← 12
10values = [4, 8, 11, 15]11limit = 1212accepted_count = 0values this step12limitaccepted_count ← 0
11limit = 1212accepted_count = 013total = 0values this step0accepted_counttotal ← 0
12accepted_count = 013total = 014do i = 1, 4values this step0totali ← 1
13total = 014do i = 1, 415 if (values(i) <= limit) thenvalues this step1iif (values(i) <= limit) then
14do i = 1, 415 if (values(i) <= limit) then16 accepted_count = accepted_count + 1values this step.true.values(1) <= limitaccepted_count ← 1
15if (values(i) <= limit) then16 accepted_count = accepted_count + 117 total = total + values(i)values this step1accepted_counttotal ← 4
16 accepted_count = accepted_count + 117 total = total + values(i)18end ifvalues this step4totali ← 2
13total = 014do i = 1, 415 if (values(i) <= limit) thenvalues this step2iif (values(i) <= limit) then
14do i = 1, 415 if (values(i) <= limit) then16 accepted_count = accepted_count + 1values this step.true.values(2) <= limitaccepted_count ← 2
15if (values(i) <= limit) then16 accepted_count = accepted_count + 117 total = total + values(i)values this step2accepted_counttotal ← 12
16 accepted_count = accepted_count + 117 total = total + values(i)18end ifvalues this step12totali ← 3
13total = 014do i = 1, 415 if (values(i) <= limit) thenvalues this step3iif (values(i) <= limit) then
14do i = 1, 415 if (values(i) <= limit) then16 accepted_count = accepted_count + 1values this step.true.values(3) <= limitaccepted_count ← 3
15if (values(i) <= limit) then16 accepted_count = accepted_count + 117 total = total + values(i)values this step3accepted_counttotal ← 23
16 accepted_count = accepted_count + 117 total = total + values(i)18end ifvalues this step23totali ← 4
13total = 014do i = 1, 415 if (values(i) <= limit) thenvalues this step4iif (values(i) <= limit) then
14do i = 1, 415 if (values(i) <= limit) then16 accepted_count = accepted_count + 1values this step.false.values(4) <= limitaverage ← 7.7
19end do20average = real(total) / real(max(1, accepted_count))21print '(I0, 1X, F0.1)', accepted_count, averagevalues this step7.7average23total3accepted_countprint '(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_demooutput3 7.7values 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.