2020-03-19 13:20:07 -04:00
|
|
|
subroutine sync65(nfa,nfb,ntol,nqsym,ca,ncand,nrobust,bVHF)
|
2015-11-17 20:28:12 -05:00
|
|
|
|
|
|
|
parameter (NSZ=3413,NFFT=8192,MAXCAND=300)
|
2017-10-21 20:09:01 -04:00
|
|
|
real ss(552,NSZ)
|
|
|
|
real ccfblue(-32:82) !CCF with pseudorandom sequence
|
2016-03-18 19:29:10 -04:00
|
|
|
real ccfred(NSZ) !Peak of ccfblue, as function of freq
|
2016-10-24 16:48:24 -04:00
|
|
|
logical bVHF
|
2016-03-18 19:29:10 -04:00
|
|
|
|
2015-11-17 20:28:12 -05:00
|
|
|
type candidate
|
|
|
|
real freq
|
|
|
|
real dt
|
|
|
|
real sync
|
2016-05-03 12:10:22 -04:00
|
|
|
real flip
|
2015-11-17 20:28:12 -05:00
|
|
|
end type candidate
|
|
|
|
type(candidate) ca(MAXCAND)
|
|
|
|
|
|
|
|
common/steve/thresh0
|
2017-10-21 20:09:01 -04:00
|
|
|
common/sync/ss
|
2015-11-17 20:28:12 -05:00
|
|
|
|
2016-06-10 10:18:10 -04:00
|
|
|
if(ntol.eq.-99) stop !Silence compiler warning
|
2015-11-17 20:28:12 -05:00
|
|
|
call setup65
|
2017-10-21 20:09:01 -04:00
|
|
|
|
2015-12-18 14:58:10 -05:00
|
|
|
df=12000.0/NFFT !df = 12000.0/8192 = 1.465 Hz
|
2015-11-17 20:28:12 -05:00
|
|
|
ia=max(2,nint(nfa/df))
|
|
|
|
ib=min(NSZ-1,nint(nfb/df))
|
2017-10-21 20:09:01 -04:00
|
|
|
! lag1=-11
|
|
|
|
! lag2=59
|
|
|
|
! lag1=-22
|
|
|
|
! lag2=118
|
|
|
|
lag1=-32
|
|
|
|
lag2=82 !may need to be extended for EME
|
2015-11-17 20:28:12 -05:00
|
|
|
nsym=126
|
|
|
|
ncand=0
|
|
|
|
fdot=0.
|
|
|
|
ccfred=0.
|
|
|
|
ccfblue=0.
|
2015-12-18 14:58:10 -05:00
|
|
|
ccfmax=0.
|
|
|
|
ipk=0
|
2015-11-17 20:28:12 -05:00
|
|
|
do i=ia,ib
|
2017-10-21 20:09:01 -04:00
|
|
|
call xcor(i,nqsym,nsym,lag1,lag2,ccfblue,ccf0,lagpk0,flip,fdot,nrobust)
|
2015-11-17 20:28:12 -05:00
|
|
|
! Remove best-fit slope from ccfblue and normalize so baseline rms=1.0
|
2016-10-24 16:48:24 -04:00
|
|
|
if(.not.bVHF) call slope(ccfblue(lag1),lag2-lag1+1, &
|
2016-03-18 19:29:10 -04:00
|
|
|
lagpk0-lag1+1.0)
|
2015-11-17 20:28:12 -05:00
|
|
|
ccfred(i)=ccfblue(lagpk0)
|
2015-12-18 14:58:10 -05:00
|
|
|
if(ccfred(i).gt.ccfmax) then
|
|
|
|
ccfmax=ccfred(i)
|
|
|
|
ipk=i
|
|
|
|
endif
|
2015-11-17 20:28:12 -05:00
|
|
|
enddo
|
|
|
|
call pctile(ccfred(ia:ib),ib-ia+1,35,xmed)
|
|
|
|
ccfred(ia:ib)=ccfred(ia:ib)-xmed
|
|
|
|
ccfred(ia-1)=ccfred(ia)
|
|
|
|
ccfred(ib+1)=ccfred(ib)
|
|
|
|
|
|
|
|
do i=ia,ib
|
|
|
|
freq=i*df
|
|
|
|
itry=0
|
2016-04-12 10:24:55 -04:00
|
|
|
! if(naggressive.gt.0 .and. ntol.lt.1000 .and. ccfmax.ge.thresh0) then
|
2018-11-14 10:44:36 -05:00
|
|
|
! if(naggressive.gt.0 .and. ccfmax.ge.thresh0) then
|
|
|
|
if(bVHF) then
|
|
|
|
if(i.ne.ipk .or. ccfmax.lt.thresh0) cycle
|
2015-11-17 20:28:12 -05:00
|
|
|
itry=1
|
|
|
|
ncand=ncand+1
|
2015-12-18 14:58:10 -05:00
|
|
|
else
|
|
|
|
if(ccfred(i).ge.thresh0 .and. ccfred(i).gt.ccfred(i-1) .and. &
|
|
|
|
ccfred(i).gt.ccfred(i+1)) then
|
|
|
|
itry=1
|
|
|
|
ncand=ncand+1
|
|
|
|
endif
|
2015-11-17 20:28:12 -05:00
|
|
|
endif
|
|
|
|
if(itry.ne.0) then
|
2017-10-21 20:09:01 -04:00
|
|
|
call xcor(i,nqsym,nsym,lag1,lag2,ccfblue,ccf0,lagpk,flip,fdot,nrobust)
|
2016-10-24 16:48:24 -04:00
|
|
|
if(.not.bVHF) call slope(ccfblue(lag1),lag2-lag1+1, &
|
2016-03-18 19:29:10 -04:00
|
|
|
lagpk-lag1+1.0)
|
2015-11-17 20:28:12 -05:00
|
|
|
xlag=lagpk
|
|
|
|
if(lagpk.gt.lag1 .and. lagpk.lt.lag2) then
|
|
|
|
call peakup(ccfblue(lagpk-1),ccfmax,ccfblue(lagpk+1),dx2)
|
|
|
|
xlag=lagpk+dx2
|
|
|
|
endif
|
2017-10-21 20:09:01 -04:00
|
|
|
dtx=xlag*1024.0/11025.0
|
2015-11-17 20:28:12 -05:00
|
|
|
ccfblue(lag1)=0.
|
|
|
|
ccfblue(lag2)=0.
|
|
|
|
ca(ncand)%freq=freq
|
|
|
|
ca(ncand)%dt=dtx
|
2016-05-03 12:10:22 -04:00
|
|
|
ca(ncand)%flip=flip
|
2016-10-24 16:48:24 -04:00
|
|
|
if(bVHF) then
|
2016-03-18 19:29:10 -04:00
|
|
|
ca(ncand)%sync=db(ccfred(i)) - 16.0
|
|
|
|
else
|
|
|
|
ca(ncand)%sync=ccfred(i)
|
|
|
|
endif
|
2015-11-17 20:28:12 -05:00
|
|
|
endif
|
2016-05-03 12:10:22 -04:00
|
|
|
if(ncand.eq.MAXCAND) exit
|
2015-11-17 20:28:12 -05:00
|
|
|
enddo
|
|
|
|
|
|
|
|
return
|
|
|
|
end subroutine sync65
|