Normalize the input real array to the range [0, 1]
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(:) | :: | real_array | ||
real(kind=wp), | intent(in) | :: | a | |||
real(kind=wp), | intent(in) | :: | b |
pure function scale_real_real(real_array,a,b) result(real_scaled_array) real(wp), dimension(:), intent(in) :: real_array real(wp), intent(in) :: a, b real(wp), dimension(size(real_array)) :: real_scaled_array real(wp) :: minValue, maxValue real(wp), parameter :: tolerance = 1.0e-12_wp ! Find minimum and maximum values in the input real array minValue = minval(real_array) maxValue = maxval(real_array) if (abs(maxValue-minValue) < tolerance) then real_scaled_array = b else real_scaled_array = a + (b - a) * (real_array - minValue) / (maxValue - minValue) end if end function scale_real_real