pro PREP_DF, aaaajjj, hd, hf, bande, vv,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 10 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
df1=where(z.df eq 11) & ndf=n_elements(df1) & df2=lonarr(ndf)
for i=0L,ndf-1L do begin
ii=df1(i) & i1=min([ii+1L,nz-1L]) & i2=min([ii+z(ii).filters,nz-1L])
jj=where(xf(i1:i2) eq xf(ii) and xts(i1:i2) eq xts(ii) $
and z(i1:i2).df eq 12)
jj=jj(0) & if jj ne -1 then jj=jj+i1
df2(i)=jj
endfor
test=where(df2 ne -1)
if n_elements(test) lt ndf then if test(0) ne -1 then begin
df1=df1(test) & df2=df2(test) & ndf=n_elements(df1)
endif
z1=z(df1) & z2=z(df2)
xf=xf(df1) & xts=xts(df1) & msec=z1.msec*10
vv=fltarr(ndf,8)
restore,getenv('ROOT_RPWS')+'/pro/phases.xdr'
buf=cal(z1.agc1,z1.auto1,z1.bande,z1.df-11b,z1.channel,z1.filters,z1.filter)
vv(*,0)=10.^(buf/10.)
buf=cal(z1.agc2,z1.auto2,z1.bande,z1.df-8b,z1.channel,z1.filters,z1.filter)
vv(*,1)=10.^(buf/10.)
buf=cal(z2.agc1,z2.auto1,z2.bande,z2.df-11b,z2.channel,z2.filters,z2.filter)
vv(*,2)=10.^(buf/10.)
buf=cal(z2.agc2,z2.auto2,z2.bande,z2.df-9b,z2.channel,z2.filters,z2.filter)
vv(*,3)=10.^(buf/10.)
ax=10.^(auto_db(z1.auto1)/10.) & az=10.^(auto_db(z1.auto2)/10.)
cr=z1.cross1 & cr=cr/abs(cr)*(10.^(auto_db(abs(cr))/10.))
ci=z1.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
ph=fltarr(ndf) & att=intarr(ndf)
if bande le 2 then for i=0L,ndf-1L do ph(i)=phases_abc(z1(i).filter, $
(z1(i).df mod 10)-1b,z1(i).bande, $
fix(alog(z1(i).filters*1.)/alog(2.)+0.5)-3)
if bande eq 3 then begin
freq=z1.channel
test=where(freq gt 4300)
if test(0) ne -1 then freq(test)=4300
for i=0L,ndf-1L do ph(i)=ph_h1((z1(i).df mod 10)-1b,fix(freq(i)/25),0)+ $
phases_h(z1(i).filter,fix(alog(z1(i).filters*1.)/alog(2.)+0.5))
endif
if bande eq 4 then begin
freq=z1.channel
test=where(freq gt 16075)
if test(0) ne -1 then freq(test)=16075
for i=0L,ndf-1L do $
ph(i)=ph_h2((z1(i).df mod 10)-1b,fix((freq(i)-25)/50),0)+ $
phases_h(z1(i).filter,fix(alog(z1(i).filters*1.)/alog(2.)+0.5))
endif
th=(thph-ph)/!radeg
cr=cm*cos(th)
ci=cm*sin(th)
vv(*,4)=cr
vv(*,5)=ci
ax=10.^(auto_db(z2.auto1)/10.) & az=10.^(auto_db(z2.auto2)/10.)
cr=z2.cross1 & cr=cr/abs(cr)*(10.^(auto_db(abs(cr))/10.))
ci=z2.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
ph=fltarr(ndf) & att=intarr(ndf)
if bande le 2 then for i=0L,ndf-1L do ph(i)=phases_abc(z2(i).filter, $
(z2(i).df mod 10)-1b,z2(i).bande, $
fix(alog(z2(i).filters*1.)/alog(2.)+0.5)-3)
if bande eq 3 then begin
freq=z2.channel
test=where(freq gt 4300)
if test(0) ne -1 then freq(test)=4300
for i=0L,ndf-1L do ph(i)=ph_h1((z2(i).df mod 10)-1b,fix(freq(i)/25),0)+ $
phases_h(z2(i).filter,fix(alog(z2(i).filters*1.)/alog(2.)+0.5))
endif
if bande eq 4 then begin
freq=z2.channel
test=where(freq gt 16075)
if test(0) ne -1 then freq(test)=16075
for i=0L,ndf-1L $
do ph(i)=ph_h2((z2(i).df mod 10)-1b,fix((freq(i)-25)/50),0)+ $
phases_h(z2(i).filter,fix(alog(z2(i).filters*1.)/alog(2.)+0.5))
endif
th=(thph-ph)/!radeg
cr=cm*cos(th)
ci=cm*sin(th)
vv(*,6)=cr
vv(*,7)=ci
help, vv,xts,xf,msec
return
end