FUNCTION getSunTgtDist, hdr

;;-----------------------------------------------------------------------------
;; PURPOSE:
;;	Determines the distance in AU from the Sun to the image's target
;;
;; CALLING SEQUENCE:
;;	D = getSunTgtDist(time)
;;
;; REQUIRED INPUTS:
;;	hdr - Header for the image. Must contain spice data
;;
;; OUTPUTS:
;;	RETURN - the distance in AU from the sun to the target
;;
;; OPTIONAL INPUT KEYWORDS:
;;
;; EXAMPLE:
;;      IDL> D = getSunTgtDist(hdr)
;;
;; PROCEDURES USED (i.e. called directly!):
;;
;; MODIFICATION HISTORY:
;;   2004-07-22  M. Desnoyer    Created
;;   2005-02-22  M. Desnoyer    Calculated distance from info in the header
;;   2005-06-02  M. Desnoyer    Return 0 if the distance is unknown
;;
;;-----------------------------------------------------------------------------

;; Get the info from the header
dist = dblarr(3,/nozero)

dist[0] = sxpar(hdr,'TARSUNRX',count=c1)
dist[1] = sxpar(hdr,'TARSUNRY',count=c2)
dist[2] = sxpar(hdr,'TARSUNRZ',count=c3)

;; If any of the distances are -999, then we should really return 0 because the distance
;; is unknown
IF max(dist EQ -999) THEN return, 0

;; Verify that data is ok
IF (min([c1,c2,c3]) EQ 0) THEN message, 'Invalid SPICE Information in FITS Header'

;; Calculate the distance in au
dist = norm(dist)/149597870.691d; 

RETURN, dist

END