Array Sections and Masks
Count Mask
Count True Values
A comparison over an array produces a logical array, and count tells how many entries are true.
Program
Play the program to change the passing cutoff and count matching scores.
count_mask.f90
Replay: real traced execution (multi-file project)
program count_mask_demo
implicit none
integer :: scores(5)
integer :: cutoff
logical :: passing(5)
integer :: total
scores = [70, 85, 90, 60, 75]
cutoff = 75
passing = scores >= cutoff
total = count(passing)
print '(I0)', total
end program count_mask_demo
program count_mask_demo
implicit none
integer :: scores(5)
integer :: cutoff
logical :: passing(5)
integer :: total
scores = [70, 85, 90, 60, 75]
cutoff = 65
passing = scores >= cutoff
total = count(passing)
print '(I0)', total
end program count_mask_demo
program count_mask_demo
implicit none
integer :: scores(5)
integer :: cutoff
logical :: passing(5)
integer :: total
scores = [70, 85, 90, 60, 75]
cutoff = 80
passing = scores >= cutoff
total = count(passing)
print '(I0)', total
end program count_mask_demo
scores ← [70, 85, 90, 60, 75]
8scores = [70, 85, 90, 60, 75]9cutoff = 75values this step[70, 85, 90, 60, 75]scorescutoff ← 75
8scores = [70, 85, 90, 60, 75]9cutoff = 7510passing = scores >= cutoffvalues this step75cutoffpassing ← [F, T, T, F, T]
9cutoff = 7510passing = scores >= cutoff11total = count(passing)values this step[F, T, T, F, T]passing75cutofftotal ← 3
10passing = scores >= cutoff11total = count(passing)12print '(I0)', totalvalues this step3total[F, T, T, F, T]passingprint '(I0)', total
11 total = count(passing)12 print '(I0)', total13end program count_mask_demooutput3values this step3total
scores ← [70, 85, 90, 60, 75]
8scores = [70, 85, 90, 60, 75]9cutoff = 65values this step[70, 85, 90, 60, 75]scorescutoff ← 65
8scores = [70, 85, 90, 60, 75]9cutoff = 6510passing = scores >= cutoffvalues this step65cutoffpassing ← [T, T, T, F, T]
9cutoff = 6510passing = scores >= cutoff11total = count(passing)values this step[T, T, T, F, T]passing65cutofftotal ← 4
10passing = scores >= cutoff11total = count(passing)12print '(I0)', totalvalues this step4total[T, T, T, F, T]passingprint '(I0)', total
11 total = count(passing)12 print '(I0)', total13end program count_mask_demooutput4values this step4total
scores ← [70, 85, 90, 60, 75]
8scores = [70, 85, 90, 60, 75]9cutoff = 80values this step[70, 85, 90, 60, 75]scorescutoff ← 80
8scores = [70, 85, 90, 60, 75]9cutoff = 8010passing = scores >= cutoffvalues this step80cutoffpassing ← [F, T, T, F, F]
9cutoff = 8010passing = scores >= cutoff11total = count(passing)values this step[F, T, T, F, F]passing80cutofftotal ← 2
10passing = scores >= cutoff11total = count(passing)12print '(I0)', totalvalues this step2total[F, T, T, F, F]passingprint '(I0)', total
11 total = count(passing)12 print '(I0)', total13end program count_mask_demooutput2values this step2total
logical array
`scores >= cutoff` compares each array element.
count
`count(passing)` returns how many logical values are true.
threshold
Changing the cutoff changes the mask before the count runs.