;+
; NAME:
;	SUNEARTHDIST
; PURPOSE:
;	Returns the distance from the Sun to the Earth
;	in a convenient calling package
; METHOD:
; 	Very cheesey.  We call PB0R and use the R coordinate
;	to calculate the solar distance.  There's almost
;	certainly a better way.
; CALLING SEQUENCE:
;	r = sunearthdist("12-Sep-1997")
; 	r = sunearthdist("12-Sep-1997","inches")
;
; RETURNS:
;	Distance from earth to Sun in kilometers, or in 
;	the unit you specify in the second parameter.
;
; AUTHOR:
;	Craig DeForest
; HISTORY:
;	9-Oct-1997 initial implementation
;	10-Oct-1997 made vector-safe.
;-
function sunearthdist,time,unit
if not isvalid(unit) then unit = "km"

;if nlm(time) gt 1 then begin
;	theta = fltarr(nlm(time))
;	for i=0,nlm(time)-1 do begin
;		pbr = pb0r(time(i),/retain)
;		theta(i) = pbr(2) * zunits("radians","arcmin")
;	end
;end else begin
	pbr = zpb0r(time)
	theta = pbr(2,*) * zunits("radians","arcmin")
;end

dist = zunits(unit,"solar-radii") / sin(theta)

if(dist(0) eq 0) then $
	print,"SUNEARTHDIST: don't recognize '",unit,"' as a unit of distance!"
	
if(nlm(dist) eq 1) then return,dist(0) else return,dist
end
