
pro rh_init_pos,x,y,z,echew,echns

@rh_common.inc

xew=1.0003*[1596.91,49.92,49.88,99.76,99.78,99.87,99.79,99.80, $
    99.85,99.81,99.81,99.81,99.84,99.77,99.82,99.82,99.81,99.64]
yew=1.0003*[8.92,8.81,8.78,8.78,8.79,8.77,8.78,8.77,8.75,8.75,8.82,8.78, $
	8.78,8.76,8.77,8.77,8.77,8.81,8.79]
zew=1.0003*[151.43,144.06,143.83,143.61,143.17,142.72,142.27,141.81,141.36, $
	140.91,140.54,140.07,139.61,139.16,138.71,138.28,137.86, $
	137.40,136.98]
x2=yew
x2(0)=0.
for i=1,18 do x2(i)=x2(i-1)+xew(i-1)
xew=x2-x2(10)
yew=yew-yew(10)
zew=zew-zew(10)                                            

tab=findgen(25)
tab(24)=46.
xns=tab*54.275*sin(0.0397)*sin(0.82642)
yns=-tab*54.275*cos(0.0397)*sin(0.82642)
zns=-tab*54.275*cos(0.82642)

x=reform([xew,xns],19+25)
y=reform([yew,yns],19+25)
z=reform([zew,zns],19+25)

x=(x(entfi.corel(1,*))-x(entfi.corel(0,*)))
y=(y(entfi.corel(1,*))-y(entfi.corel(0,*)))
z=(z(entfi.corel(1,*))-z(entfi.corel(0,*)))

end

PRO RH_CALC_PAR2,LAMB,D,NF,X,Y,Z,AU,BU,AV,BV,CV,AW,BW,CW

@rh_common.inc
Dec=!PI/180.*total(entfi.dec*[1.,1./60.,1./3600.,1./360000.])


du=128./60./180.*!PI

AU=du*reform(1./LAMB(nf)*y*COS(DEC),576)
BU=du*reform(X/LAMB(NF)*COS(DEC),576)

AV=du*reform(1./LAMB(nf)*sin(Dec)*x,576)
BV=du*reform(-y/LAMB(nf)*SIN(DEC),576)
CV=du*reform(-z*cos(Dec)/LAMB(nf),576)

AW=2.*!PI*reform(1./LAMB(nf)*COS(Dec)*x,576)
BW=2.*!PI*reform(-y/LAMB(nf)*COS(DEC),576)
CW=2.*!PI*reform(z*SIN(Dec)/LAMB(nf),576)


END

FUNCTION  RH_PHI_SELF,H,U,V,AU,BU,AV,BV,CV,aw,bw,cw,nf

; 
;  Procedure de calcul de phi et d'autres parametres
;
; ENTREE:
;	LAMB: tableau des longueur d'ondes utilises
;	H: heure de calcul
;	SOUR: structure contenant les parametres de la source observe
;	NS: nombres de sources elementaires composant la source observe
;
; SORTIE:
;	U,V: coordonne de chaque harmonique dans le plan U,V
;	PHA: dephasage aerien pour chaque harmonique
;

@rh_common.inc

ra=total(entfi.mer*[3600000.,60000.,1000.,10.])
LAT=0.0022448
H=(H-RA)*7.27220522D-8  - LAT

U=SIN(H)*au+cos(H)*bu
V=Sin(H)*av+cos(H)*bv+CV
RETURN,Sin(H)*aW+cos(H)*bW+CW

END

PRO rh_corec_phase, nf, pt, hy

@rh_common.inc 
; init de D
RH_INIT_PHA,RH,D,CYGNE,NS,NBANT,NBFREQ,LAMBDA
rh_init_pos,x,y,z


temp=dblarr(entfi.nf)
TEMP(*)=0.35D
TAB=WHERE(entfi.frq(*) GT 3850.,C)
IF C GT 0 THEN TEMP(tab)=-0.75D
LAMBDA=2997.925D/(ENTFI.FRQ(0:ENTFI.NF-1)*1D)
LAMBD2=LAMBDA-2997.925D/((ENTFI.FRQ(0:ENTFI.NF-1)+TEMP)*1D)
LAMBD2=1./LAMBD2

nh=entfi.nval/4
;PT=REFORM(PT,4,576)



	RH_CALC_PAR2,LAMBD2,D,NF,X,Y,Z,AU2,BU2,AV2,BV2,CCV2,aw2,bw2,cw2
	TP=total(HY(*)*[3600000.,60000.,1000.,10.])
	PHI=RH_PHI_SELF(TP,U2,V2,AU2,BU2,AV2,BV2,CCV2,aw2,bw2,cw2,NF)
	for NDS=0,1 do begin
		amp=REFORM(complex(pt(NDS*2,*),pt(NDS*2+1,*))* $
				complex(cos(phi),-sin(phi)),nh) 
		pt(NDS*2,*)=float(amp)
		pt(NDS*2+1,*)=imaginary(amp)
		END

END



