linear_renormalise Subroutine

public subroutine linear_renormalise(input, min, max)

Renormalise input data to a specified range

Arguments

Type IntentOptional Attributes Name
real(kind=real32), intent(inout), dimension(:) :: input

Input data to be renormalised

real(kind=real32), intent(in), optional :: min

Minimum and maximum values for renormalisation

real(kind=real32), intent(in), optional :: max

Minimum and maximum values for renormalisation


Source Code

  subroutine linear_renormalise(input, min, max)
    !! Renormalise input data to a specified range
    implicit none

    ! Arguments
    real(real32), dimension(:), intent(inout) :: input
    !! Input data to be renormalised
    real(real32), optional, intent(in) :: min, max
    !! Minimum and maximum values for renormalisation

    ! Local variables
    real(real32) :: lower, width
    !! Lower bound and width of the range
    real(real32) :: min_val, max_val
    !! Minimum and maximum values of the input data

    min_val = minval(input)
    max_val = maxval(input)

    if(present(min))then
       lower = min
    else
       lower = -1._real32
    end if
    if(present(max))then
       width = max - min
    else
       width = 2._real32
    end if

    input = lower + width * (input - min_val)/(max_val - min_val)
  end subroutine linear_renormalise