pro PREP_DF2, aaaajjj, hd, hf, bande, vv,xant,xts,xf,msec
common KRONOSCAL, a1h1,a1h2,ai,dbcal_abc,dbcal_h
LIT_HFR_LISTE, aaaajjj, hd, hf, bande, bande, z
print & print,'selection des donnees DF ...'
test=where(z.bande eq bande and z.df gt 0 and z.agc1 ne 255b and $
z.agc2 ne 255b and z.auto1 ne 255b and z.auto2 ne 255b and $
z.cross1 ne -999 and z.cross2 ne -999)
if test(0) ne -1 then z=z(test) else stop
help,z
nz = n_elements(z)
xts = dblarr(nz) & xf=fltarr(nz)
for i=0L,nz-1L do xts(i)=total(transpose(z(i).time)#[3600.0,60.0,1.0,0.01])
if bande le 2 then begin
nfilt=z(0).filters & freq = freq_ABC(nfilt)
for i=0L,nz-1L do begin
if z(i).filters ne nfilt then begin
nfilt=z(i).filters & freq = freq_ABC(nfilt)
endif
xf(i)=freq(bande*nfilt+z(i).filter)
endfor
endif else xf=z.channel+25*z.filter/z.filters
msec=z.msec*10
xant=z.df mod 10
vv=fltarr(nz,4)
buf=cal(z.agc1,z.auto1,z.bande,xant-1b,z.channel,z.filters,z.filter)
vv(*,0)=10.^(buf/10.)
buf=cal(z.agc2,z.auto2,z.bande,bytarr(nz)+3b,z.channel,z.filters,z.filter)
vv(*,1)=10.^(buf/10.)
ax=10.^(auto_db(z.auto1)/10.) & az=10.^(auto_db(z.auto2)/10.)
cr=z.cross1 & cr=cr/abs(cr)*(10.^(auto_db(abs(cr))/10.))
ci=z.cross2 & ci=ci/abs(ci)*(10.^(auto_db(abs(ci))/10.))
cr=cr/sqrt(ax*az)
ci=ci/sqrt(ax*az)
cm=sqrt(cr^2+ci^2)
thph=atan(ci,cr)*!radeg
restore,getenv('ROOT_RPWS')+'/pro/phases.xdr'
ph=fltarr(nz) & att=intarr(nz)
if bande le 2 then for i=0L,nz-1L do ph(i)=phases_abc(z(i).filter, $
xant(i)-1b,z(i).bande,fix(alog(z(i).filters*1.)/alog(2.)+0.5)-3)
if bande eq 3 then begin
freq=z.channel
test=where(freq gt 4300)
if test(0) ne -1 then freq(test)=4300
for i=0L,nz-1L do ph(i)=ph_h1(xant(i)-1b,fix(freq(i)/25),0)+ $
phases_h(z(i).filter,fix(alog(z(i).filters*1.)/alog(2.)+0.5))
endif
if bande eq 4 then begin
freq=z.channel
test=where(freq gt 16075)
if test(0) ne -1 then freq(test)=16075
for i=0L,nz-1L do ph(i)=ph_h2(xant(i)-1b,fix((freq(i)-25)/50),0)+ $
phases_h(z(i).filter,fix(alog(z(i).filters*1.)/alog(2.)+0.5))
endif
th=(thph-ph)/!radeg
cr=cm*cos(th)
ci=cm*sin(th)
vv(*,2)=cr
vv(*,3)=ci
help, vv,xant,xts,xf,msec
return
end