Error Handling Patterns
Validation Flag
Count Problems
Validation often records facts about the data instead of stopping at the first problem. A logical mask and count summarize which entries need review.
Program
Play the program to choose the limit and count readings above it.
validation_flag.f90
Replay: real traced execution (multi-file project)
program validation_flag_demo
implicit none
integer :: readings(3)
integer :: limit
logical :: too_high(3)
integer :: issue_count
character(len=8) :: label
readings = [4, 8, 12]
limit = 10
too_high = readings > limit
issue_count = count(too_high)
if (issue_count == 0) then
label = 'clean'
else
label = 'review'
end if
print '(A, 1X, I0)', trim(label), issue_count
end program validation_flag_demo
program validation_flag_demo
implicit none
integer :: readings(3)
integer :: limit
logical :: too_high(3)
integer :: issue_count
character(len=8) :: label
readings = [4, 8, 12]
limit = 5
too_high = readings > limit
issue_count = count(too_high)
if (issue_count == 0) then
label = 'clean'
else
label = 'review'
end if
print '(A, 1X, I0)', trim(label), issue_count
end program validation_flag_demo
program validation_flag_demo
implicit none
integer :: readings(3)
integer :: limit
logical :: too_high(3)
integer :: issue_count
character(len=8) :: label
readings = [4, 8, 12]
limit = 15
too_high = readings > limit
issue_count = count(too_high)
if (issue_count == 0) then
label = 'clean'
else
label = 'review'
end if
print '(A, 1X, I0)', trim(label), issue_count
end program validation_flag_demo
readings ← [4, 8, 12]
9readings = [4, 8, 12]10limit = 10values this step[4, 8, 12]readingslimit ← 10
9readings = [4, 8, 12]10limit = 1011too_high = readings > limitvalues this step10limittoo_high ← [F, F, T]
10limit = 1011too_high = readings > limit12issue_count = count(too_high)values this step[F, F, T]too_high10limitissue_count ← 1
11too_high = readings > limit12issue_count = count(too_high)13if (issue_count == 0) thenvalues this step1issue_count[F, F, T]too_highissue_count == 0 ← .false.
12issue_count = count(too_high)13if (issue_count == 0) then14 label = 'clean'values this step.false.issue_count == 01issue_countlabel ← review
15else16 label = 'review'17end ifvalues this stepreviewlabelprint '(A, 1X, I0)', trim(label), issue_count
17 end if18 print '(A, 1X, I0)', trim(label), issue_count19end program validation_flag_demooutputreview 1values this stepreviewlabel1issue_count
readings ← [4, 8, 12]
9readings = [4, 8, 12]10limit = 5values this step[4, 8, 12]readingslimit ← 5
9readings = [4, 8, 12]10limit = 511too_high = readings > limitvalues this step5limittoo_high ← [F, T, T]
10limit = 511too_high = readings > limit12issue_count = count(too_high)values this step[F, T, T]too_high5limitissue_count ← 2
11too_high = readings > limit12issue_count = count(too_high)13if (issue_count == 0) thenvalues this step2issue_count[F, T, T]too_highissue_count == 0 ← .false.
12issue_count = count(too_high)13if (issue_count == 0) then14 label = 'clean'values this step.false.issue_count == 02issue_countlabel ← review
15else16 label = 'review'17end ifvalues this stepreviewlabelprint '(A, 1X, I0)', trim(label), issue_count
17 end if18 print '(A, 1X, I0)', trim(label), issue_count19end program validation_flag_demooutputreview 2values this stepreviewlabel2issue_count
readings ← [4, 8, 12]
9readings = [4, 8, 12]10limit = 15values this step[4, 8, 12]readingslimit ← 15
9readings = [4, 8, 12]10limit = 1511too_high = readings > limitvalues this step15limittoo_high ← [F, F, F]
10limit = 1511too_high = readings > limit12issue_count = count(too_high)values this step[F, F, F]too_high15limitissue_count ← 0
11too_high = readings > limit12issue_count = count(too_high)13if (issue_count == 0) thenvalues this step0issue_count[F, F, F]too_highissue_count == 0 ← .true.
12issue_count = count(too_high)13if (issue_count == 0) then14 label = 'clean'values this step.true.issue_count == 00issue_countlabel ← clean
13if (issue_count == 0) then14 label = 'clean'15elsevalues this stepcleanlabelprint '(A, 1X, I0)', trim(label), issue_count
17 end if18 print '(A, 1X, I0)', trim(label), issue_count19end program validation_flag_demooutputclean 0values this stepcleanlabel0issue_count
logical mask
`readings > limit` compares every array element.
count
`count(too_high)` converts validation flags into a summary number.
review label
The final branch names whether the data is clean or needs review.