import math


def rad_to_hms(rad):
    """ convert radians to sexagesimal degrees

    This function converts a positive angle in radians to a sexagesimal
    angle in degrees, minutes, and seconds.

    It works for positive angles (take care of the negative part
    yourself.

INPUTS:
rad      I  input angle in radians

OUTPUTS: deg min sec
deg      O  degrees (integer)
min      O  minutes (integer)
sec      O  seconds (float)

    """
#   print('in  rad_to_hms')
    M_RAD2DEG = 180.0/math.pi
    if rad < 0:
      rad = 2.0 * math.pi + rad
    d = math.fabs(rad) * M_RAD2DEG * 24.0 / 360.0
    deg = int(d+2E-13)
    m = (d-deg) * 60.0
    min = int(m+1E-11)
    sec = (m - min) * 60.0
    return deg, min, sec