def label_format_hms(deg, pos):
    """
    Format decimal->HH:MM:SS. Called by the label formatter. 
    """

    hrs = deg/15.0
    
    angle = abs(hrs)
    sign=1
    if angle!=0: sign = angle/hrs

    # Calcuate the hrsrees, min and sec
    dd = int(angle)
    rmndr = 60.0*(angle - dd)
    mm = int(rmndr)
    ss = 60.0*(rmndr-mm)

    # If rounding up to 60, carry to the next term
    if float("%05.2f" % ss) >=60.0:
        ss = 0.0
        mm+=1.0
    if float("%02d" % mm) >=60.0:
        mm = 0.0
        dd+=1.0

    if sign > 0:
        return "%02dh%02dm%02.0fs" % (sign*dd, mm, ss)
    else:
        return "%03dh%02dm%02.0fs" % (sign*dd, mm, ss)