Data Validation Pipelines
Range Clamp
Keep Values Inside Bounds
Validation pipelines often bound values before the next calculation step. max and min make that clamp explicit.
Program
Play the program to choose the upper bound and see which readings are clipped.
range_clamp.f90
program range_clamp_demo
implicit none
integer :: raw(4)
integer :: lower_bound
integer :: upper_bound
integer :: clipped(4)
integer :: clipped_total
raw = [-2, 4, 11, 15]
lower_bound = 0
upper_bound =
clipped = min(max(raw, lower_bound), upper_bound)
clipped_total = sum(clipped)
print '(I0, 1X, I0)', clipped(4), clipped_total
end program range_clamp_demo
program range_clamp_demo
implicit none
integer :: raw(4)
integer :: lower_bound
integer :: upper_bound
integer :: clipped(4)
integer :: clipped_total
raw = [-2, 4, 11, 15]
lower_bound = 0
upper_bound =
clipped = min(max(raw, lower_bound), upper_bound)
clipped_total = sum(clipped)
print '(I0, 1X, I0)', clipped(4), clipped_total
end program range_clamp_demo
program range_clamp_demo
implicit none
integer :: raw(4)
integer :: lower_bound
integer :: upper_bound
integer :: clipped(4)
integer :: clipped_total
raw = [-2, 4, 11, 15]
lower_bound = 0
upper_bound =
clipped = min(max(raw, lower_bound), upper_bound)
clipped_total = sum(clipped)
print '(I0, 1X, I0)', clipped(4), clipped_total
end program range_clamp_demo
bounds
Lower and upper bounds define the accepted numeric interval.
elemental max/min
`max` and `min` apply element by element to the array.
clipped total
A summary after clamping can be compared across bound choices.