2023-01-24 09:18:00 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								subroutine sync8(dd,nfa,nfb,syncmin,nfqso,maxcand,candidate,ncand,sbase)
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-15 12:09:53 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  include 'ft8_params.f90'
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-21 13:47:12 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  parameter (MAXPRECAND=1000)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								! Maximum sync correlation lag +/- 2.5s relative to 0.5s TX start time. 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								! 2.5s / 0.16s/symbol * 4 samples/symbol = 62.5 lag steps in 2.5s
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-13 00:46:16 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  parameter (JZ=62)                        
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-15 12:09:53 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  complex cx(0:NH1)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  real s(NH1,NHSYM)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  real savg(NH1)
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-26 16:30:47 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  real sbase(NH1)
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-15 12:09:53 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  real x(NFFT1)
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-19 20:15:43 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  real sync2d(NH1,-JZ:JZ)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  real red(NH1)
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-21 13:47:12 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  real red2(NH1)
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-09 14:03:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  real candidate0(3,MAXPRECAND)
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-05 11:59:48 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  real candidate(3,maxcand)
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-06 15:45:25 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  real dd(NMAX)
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-19 20:15:43 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  integer jpeak(NH1)
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-21 13:47:12 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  integer jpeak2(NH1)
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-19 20:15:43 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  integer indx(NH1)
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-21 13:47:12 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  integer indx2(NH1)
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-19 20:15:43 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  integer ii(1)
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-05 11:59:48 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  integer icos7(0:6)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  data icos7/3,1,4,0,6,5,2/                   !Costas 7x7 tone pattern
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-15 12:09:53 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  equivalence (x,cx)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								! Compute symbol spectra, stepping by NSTEP steps.  
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-15 12:09:53 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  savg=0.
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  tstep=NSTEP/12000.0                         
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-06 13:38:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  df=12000.0/NFFT1                            !3.125 Hz
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-15 12:09:53 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  fac=1.0/300.0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  do j=1,NHSYM
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								     ia=(j-1)*NSTEP + 1
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-15 12:09:53 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     ib=ia+NSPS-1
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-06 15:45:25 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								     x(1:NSPS)=fac*dd(ia:ib)
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-15 12:09:53 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     x(NSPS+1:)=0.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     call four2a(x,NFFT1,1,-1,0)              !r2c FFT
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     do i=1,NH1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        s(i,j)=real(cx(i))**2 + aimag(cx(i))**2
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     enddo
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-28 14:38:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								     savg=savg + s(1:NH1,j)                   !Average spectrum
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-15 12:09:53 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  enddo
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-27 15:58:52 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  call get_spectrum_baseline(dd,nfa,nfb,sbase)
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-15 12:09:53 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-28 18:48:31 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  ia=max(1,nint(nfa/df))
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-28 14:38:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  ib=nint(nfb/df)
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  nssy=NSPS/NSTEP   ! # steps per symbol
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  nfos=NFFT1/NSPS   ! # frequency bin oversampling factor
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-18 15:22:20 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  jstrt=0.5/tstep
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-05 16:37:29 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  candidate0=0.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  k=0
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-05 07:51:10 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-05 11:59:48 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  do i=ia,ib
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     do j=-JZ,+JZ
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-14 18:19:48 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        ta=0.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        tb=0.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        tc=0.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        t0a=0.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        t0b=0.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        t0c=0.
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-15 12:09:53 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        do n=0,6
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-05 16:37:29 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           m=j+jstrt+nssy*n
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           if(m.ge.1.and.m.le.NHSYM) then
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              ta=ta + s(i+nfos*icos7(n),m)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              t0a=t0a + sum(s(i:i+nfos*6:nfos,m))
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-28 14:38:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           endif
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-05 16:37:29 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tb=tb + s(i+nfos*icos7(n),m+nssy*36)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           t0b=t0b + sum(s(i:i+nfos*6:nfos,m+nssy*36))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           if(m+nssy*72.le.NHSYM) then
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              tc=tc + s(i+nfos*icos7(n),m+nssy*72)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              t0c=t0c + sum(s(i:i+nfos*6:nfos,m+nssy*72))
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-28 14:38:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           endif
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-15 12:09:53 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        enddo
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-14 18:19:48 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        t=ta+tb+tc
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        t0=t0a+t0b+t0c
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-28 14:38:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        t0=(t0-t)/6.0
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-14 18:19:48 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sync_abc=t/t0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        t=tb+tc
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        t0=t0b+t0c
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        t0=(t0-t)/6.0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sync_bc=t/t0
							 | 
						
					
						
							
								
									
										
										
										
											2022-11-08 20:43:42 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sync2d(i,j)=max(sync_abc,sync_bc)
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-05 11:59:48 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								     enddo
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  enddo
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-19 20:15:43 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-05 11:59:48 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  red=0.
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-21 13:47:12 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  red2=0.
							 | 
						
					
						
							
								
									
										
										
										
											2022-11-01 17:58:36 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  mlag=10
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-23 16:48:21 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  mlag2=JZ
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-05 11:59:48 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  do i=ia,ib
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-21 13:47:12 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								     ii=maxloc(sync2d(i,-mlag:mlag)) - 1 - mlag 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     jpeak(i)=ii(1)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     red(i)=sync2d(i,jpeak(i))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     ii=maxloc(sync2d(i,-mlag2:mlag2)) - 1 - mlag2
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     jpeak2(i)=ii(1)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     red2(i)=sync2d(i,jpeak2(i))
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-05 11:59:48 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  enddo
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  iz=ib-ia+1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  call indexx(red(ia:ib),iz,indx)
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-03 10:51:45 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  npctile=nint(0.40*iz)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  if(npctile.lt.1) then ! something is wrong; bail out
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ncand=0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  endif
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  ibase=indx(npctile) - 1 + ia
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-05 11:59:48 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  if(ibase.lt.1) ibase=1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  if(ibase.gt.nh1) ibase=nh1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  base=red(ibase)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  red=red/base
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-21 13:47:12 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  call indexx(red2(ia:ib),iz,indx2)
							 | 
						
					
						
							
								
									
										
										
										
											2022-11-01 17:58:36 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  ibase2=indx2(npctile) - 1 + ia
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  if(ibase2.lt.1) ibase2=1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  if(ibase2.gt.nh1) ibase2=nh1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  base2=red2(ibase2)
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-21 13:47:12 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  red2=red2/base2
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-09 14:03:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  do i=1,min(MAXPRECAND,iz)
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-05 11:59:48 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								     n=ia + indx(iz+1-i) - 1
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-21 13:47:12 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								     if(k.ge.MAXPRECAND) exit
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     if( (red(n).ge.syncmin) .and. (.not.isnan(red(n))) ) then 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        k=k+1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        candidate0(1,k)=n*df
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        candidate0(2,k)=(jpeak(n)-0.5)*tstep
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        candidate0(3,k)=red(n)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     endif
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     if(abs(jpeak2(n)-jpeak(n)).eq.0) cycle 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     if(k.ge.MAXPRECAND) exit
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     if( (red2(n).ge.syncmin) .and. (.not.isnan(red2(n))) ) then
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        k=k+1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        candidate0(1,k)=n*df
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        candidate0(2,k)=(jpeak2(n)-0.5)*tstep
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        candidate0(3,k)=red2(n)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     endif
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-05 11:59:48 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  enddo
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-07 15:27:15 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  ncand=k
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-28 14:38:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-09 14:03:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								! Save only the best of near-dupe freqs.  
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-28 14:38:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  do i=1,ncand
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     if(i.ge.2) then
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        do j=1,i-1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           fdiff=abs(candidate0(1,i))-abs(candidate0(1,j))
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-21 13:47:12 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tdiff=abs(candidate0(2,i)-candidate0(2,j))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           if(abs(fdiff).lt.4.0.and.tdiff.lt.0.04) then
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-28 14:38:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              if(candidate0(3,i).ge.candidate0(3,j)) candidate0(3,j)=0.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              if(candidate0(3,i).lt.candidate0(3,j)) candidate0(3,i)=0.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           endif
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        enddo
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     endif
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  enddo
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-19 20:15:43 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  fac=20.0/maxval(s)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  s=fac*s
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-15 12:09:53 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								! Sort by sync
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-08 12:03:52 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  call indexx(candidate0(3,1:ncand),ncand,indx)
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-09 14:03:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								! Place candidates within 10 Hz of nfqso at the top of the list
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  k=1
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-09 14:03:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  do i=1,ncand
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if( abs( candidate0(1,i)-nfqso ).le.10.0 .and. candidate0(3,i).ge.syncmin ) then
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      candidate(1:3,k)=candidate0(1:3,i)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      candidate0(3,i)=0.0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      k=k+1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    endif
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  enddo
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-08 12:03:52 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  do i=ncand,1,-1
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-28 14:38:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								     j=indx(i)
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-13 00:46:16 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								     if( candidate0(3,j) .ge. syncmin ) then
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-03 07:18:52 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       candidate(2:3,k)=candidate0(2:3,j)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       candidate(1,k)=abs(candidate0(1,j))
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       k=k+1
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-09 14:03:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       if(k.gt.maxcand) exit
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								     endif
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-28 14:38:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  enddo
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  ncand=k-1
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-15 12:09:53 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  return
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								end subroutine sync8
							 |