AngDiff Function

public function AngDiff(x, y, e)

Compute y - x. x and y must both lie in [-180, 180]. The result is equivalent to computing the difference exactly, reducing it to (-180, 180] and rounding the result. Note that this prescription allows -180 to be returned (e.g., if x is tiny and negative and y = 180). The error in the difference is returned in e

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: x
real(kind=wp), intent(in) :: y
real(kind=wp), intent(out) :: e

Return Value real(kind=wp)


Source Code

    real(wp) function AngDiff(x, y, e)

    real(wp),intent(in) :: x, y
    real(wp),intent(out) :: e

    real(wp) d, t

    d = sumx(remx(-x, 360.0_wp), remx(y, 360.0_wp), t)
    d = sumx(remx(d, 360.0_wp), t, e)
    if (d == 0 .or. abs(d) == 180) then
        if (e == 0) then
            d = sign(d, y - x)
        else
            d = sign(d, -e)
        end if
    end if
    AngDiff = d

    end function AngDiff