renormalise_sum Subroutine

public subroutine renormalise_sum(input, norm, mirror, magnitude)

Renormalise input data to a unit sum

Arguments

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

Input data to be renormalised

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

Desired sum value

logical, intent(in), optional :: mirror

Booleans whether the data should be mirrored or use magnitude

logical, intent(in), optional :: magnitude

Booleans whether the data should be mirrored or use magnitude


Source Code

  subroutine renormalise_sum(input, norm, mirror, magnitude)
    !! Renormalise input data to a unit sum
    implicit none

    ! Arguments
    real(real32), dimension(:), intent(inout) :: input
    !! Input data to be renormalised
    real(real32), optional, intent(in) :: norm
    !! Desired sum value
    logical, optional, intent(in) :: mirror, magnitude
    !! Booleans whether the data should be mirrored or use magnitude

    ! Local variables
    logical :: magnitude_
    !! Flag to indicate if magnitude should be used
    real(real32) :: scale
    !! Scaling factor

    if(present(norm))then
       scale = norm
    else
       scale = 1._real32
    end if

    if(present(mirror))then
       if(mirror) call linear_renormalise(input)
    end if

    if(present(magnitude)) magnitude_ = magnitude
    if(present(magnitude))then
       scale = scale/sum(abs(input))
    else
       scale = scale/sum(input)
    end if
    input = input * scale
  end subroutine renormalise_sum