;+
; NAME:
;	V4XS2SC
; PURPOSE:
;	Convert Solar to Solar Cartesian coordinates
;	(normally called by V4XFORM based on the v4xforms structure)
; CALLING SEQUENCE:
;	out = V4XCART2SPH(in,/verbose,index=ix,outdex=ox,ocoord=ocoord)
; INPUTS:
;	in - a V4 structure containing the co-ordinates to 
;	     transform
; RETURNS:
;	The transformed vector (or array)
; KEYWORDS:
;	VERBOSE - Be chatty
;	INDEX   - A 4-array that re-orders the input vector  (IGNORED)
;	OUTDEX  - A 4-array that re-orders the output vector (IGNORED)
;	OCOORD  - The coordinate system name for the output coordinates 
; 
; METHOD:
;	Translates the Cartesian coordinates from Earth to the Sun, 
;	then calls V4XCART2SPH.	
;
;	The "standard interpretation" is as follows:
;	I0 = time		O0 = time		
;	I1 = W angle		O1 = X (west)		
;	I2 = N angle		O2 = Y (North)		
;	I3 = R (from Earth)	O3 = Z (toward Earth)	
;
;	(Note that "North" is "Solar North projected into the image plane")
; AUTHOR:
;	Craig DeForest
; HISTORY: 
;	Initial implementation, 7-Oct-1997
;
;-
function V4XS2SC,in,verbose=v,index=ix,outdex=ox,ocoords=ocoords

;;;
;;; Check out input keywords for existence...
;;;
if (isvalid(ix) or isvalid(ox)) then $
	if(total(where( (ix ne [0,1,2,3]) or (ox ne [0,1,2,3]) )) ge 0) then $
		print,"WARNING - V4XS2SC - ignoring indexing!"
v = keyword_set(v)

ix = [0,1,2,3]
ox = ix
iu = ix+5
ou = ox+5

;;;
;;; Calculate the Earth-Sun distance...
r = sunearthdist(in.(ix(0)),in.(iu(3)))
if(v) then print,"V4XCS2SC: earth-sun distance is ",r,in.(iu(3))

;;;
;;; Place the plane of the sky at the Sun if radius is undefined.
i2 = in
if(not (i2.defined)(3)) then i2.(3) = r

;;;
;;; Convert from Earth spherical to Earth-centered Cartesian...
i2 = v4xsph2cart(i2,v=v,index=[0,1,2,3],outdex=[0,3,1,2],ocoord="blecch")

if not data_chk(i2,/struct) then return,0

;;;
;;; Translate the origin from the Earth to the Sun...
i2.(ix(3)) = r - i2.(ix(3))

i2.coords="Solar Cartesian"

i2 = v4canon(i2)
return,i2
end
