function Jd2doy, jday

;+
; jd2doy
;	Return, [y,d,h,m,s] given a julian day.
;
; Usage:
;	time = jd2doy(jday)
;
; Argument:
;	jd	double	input	The julian day number to be converted.
;
; Restrictions:
;	Only works to the nearest millisecond: because of a cop-out
;	work around for a tendency to return exact hours
;	(e.g. 3:00:00.00) as (e.g.) 2:59:59.999998. It's not pretty
;	but it works.
;
; History:
;	Original: 3/12/99; SJT
;-

jd1980j1 = 2444239.5d0          ; January 1 1980 -- not Jan 0.0 as in
                                ; PJDS

tjday = jday - jd1980j1 + 1.
d1980 = long(tjday)
h = round((tjday - d1980)*24l*60l*60l*1000l)/(60.d0*60.*1000.)
ih = fix(h)
mins = (h - ih)*60
imins = fix(mins)
secs = (mins-imins)*60 + 1e-4

t = norm_time([1980, d1980, ih, imins, secs])
t[4] = round(t[4]*1e3)/1e3

return, t

end
