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
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 =
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 =
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 =
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
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.