	pro ord_to_time,Date,Interf,Order,Channel, $
		Receiver,SUN,time_out,both=both,Radio=Radio

if keyword_set(both) or interf then J0=1 else J0=0
if n_elements(Radio) le 0 then Radio=1.175

DDTOR=!DPi/180
D=4.9D0	&	C=2.997925D8	&	Fi=51.7575D0*!DPi/180


if n_elements(SUN) le 0 then suneph,date,Time,SUN

	Declg=strmid(SUN.Current_date,12,2)
	DSign=strmid(SUN.Current_date,11,1)
	Declm=strmid(SUN.Current_date,15,2)
	Decls=strmid(SUN.Current_date,18,4)
	Ddelta=strmid(SUN.Current_date,62,6)*DDTOR/3600d0*24d0

Delta=HMS(Declg,Declm,Decls)*DDTOR
	for I=0,2 do IF(Dsign(I) EQ '-') then Delta(I)=-Delta(I)


F=chanfreq(Channel,receiver)
CosP=Order*C/(F*d)

P=acos(CosP)

CosP=cos([P-SUN.R*Radio,P,P+SUN.R*Radio])

Time='05 00 00'
time_out=strarr(3,J0+1)

		for j=0,J0 do begin

	for jj=0,2 do begin

	REPEAT BEGIN

Time0=Time

		H=SUN.W0*(Time-SUN.Tcul)*3600d0

Direction=H/(2*!DPi)

	IF(Direction LE 0) THEN $
Decl=Delta(1)+Direction*Ddelta(1) $
	- Direction^2*(DDelta(1)-DDelta(0))/2 ELSE $

Decl=Delta(1)+Direction*Ddelta(1) $
	+ Direction^2*(DDelta(2)-DDelta(1))/2

	Sin_Cos_H= $
(CosP(jj)+sin(Decl)*cos(Fi))/(cos(Decl)*sin(Fi))*Interf+ $
		CosP(jj)/cos(Decl)*(1-Interf)

	if abs(Sin_Cos_H) gt 1 then begin
print,'This order is not visible'	&	return
	endif

H=acos(Sin_Cos_H)*Interf+ $			; S-N
	asin(Sin_Cos_H)*(1-Interf)		; E-W

H=	H*(1-j)+ $				; 1st pass
	(-H*Interf+ $				; 2nd pass S-N
	(!dpi-abs(H))*sign(H)*(1-Interf))*j	; 2nd pass E-W

T1=SUN.Tcul*3600d0+H/SUN.w0

Time=smh(T1,ms=4)

	ENDREP UNTIL abs(T1-hms(time0)*3600d0) lt 0.001

time_out(jj,j)=Time
	endfor

		endfor

if (keyword_set(both) or interf) and $
	(not((CosP(1) gt 0) and not(interf))) $
		then time_out=time_out([[3,4,5],[0,1,2]])

end