;+
; NAME:
;	V4XHEL2CARR
; PURPOSE:
;	Convert heliographic to carrington coordinates
;	(normally called by V4XFORM based on the v4xforms structure)
; CALLING SEQUENCE:
;	out = V4XHEL2CARR(in,/verbose,index=ix,outdex=ox,ocoord=ocoord)
; INPUTS:
;	in - a V4 structure containing the Cartesian co-ordinates to 
;	     transform to spherical
; RETURNS:
;	The transformed vector (or array)
; KEYWORDS:
;	VERBOSE - Be chatty
;	INDEX   - A 4-array that re-orders the input vector
;	OUTDEX  - A 4-array that re-orders the output vector
;	OCOORD  - The coordinate system name for the output coordinates 
; 
; METHOD:
;	The "standard interpretation" is as follows:
;	I0 = time		O0 = time		
;	I1 = longitude		O1 = longitude		
;	I2 = latitude		O2 = latitude		
;	I3 = radius		O3 = radius		
;
; AUTHOR:
;	Craig DeForest
; HISTORY: 
;	Initial implementation, 7-Oct-1997
;-
function V4XHEL2CARR,in,verbose=v,index=ix,outdex=ox,ocoords=ocoords

;;;
;;; Check out input keywords for existence...
;;;
if not isvalid(ix) then ix=[0,1,2,3]
if not isvalid(ox) then ox=[0,1,2,3]
v = keyword_set(v)

iu = ix+5
ou = ox+5

;;;
;;; Convert to degrees, in a spare copy of the input...
i2 = in
out= in
zu = zunits("degrees",i2.(iu(1)))
i2.(ix(1)) = i2.(ix(1)) * zu
i2.(iu(1)) = "degrees"

if (zu eq 0) then message,"V4xhel2carr: Non-angular longitude!"

;;;
;;; Copy the non-transformed co-ordinates and, if desired, the coords keyword
out.(ox(0))	= in.(ix(0))
out.(ox(2)) 	= in.(ix(2))
out.(ox(3))	= in.(ix(3))

out.(ou(0))	= in.(iu(0))
out.(ou(2))	= in.(iu(2))
out.(ou(3))	= in.(iu(3))

if isvalid(ocoords) then out.coords=ocoords

;;;
;;; Do the actual transformation...
if nlm( (out.(ox(1)))) gt 1 then 	begin
	out.(ox(1)) =  tim2carr(in.(ix(0)),offset=in.(ix(1)))     	
end else begin
	out.(ox(1)) = (tim2carr(in.(ix(0)),offset=in.(ix(1))))(0)
end

return,out

end
