| 
									
										
										
										
											2016-09-29 16:39:14 +00:00
										 |  |  | subroutine msk144sync(cdat,nframes,ntol,delf,navmask,npeaks,fc,fest,   &
 | 
					
						
							| 
									
										
										
										
											2016-10-03 17:08:02 +00:00
										 |  |  |      npklocs,nsuccess,xmax,c)
 | 
					
						
							| 
									
										
										
										
											2016-09-22 00:03:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-03 13:48:30 +00:00
										 |  |  | !$ use omp_lib
 | 
					
						
							| 
									
										
										
										
											2016-09-30 16:59:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-22 00:03:44 +00:00
										 |  |  |   parameter (NSPM=864)
 | 
					
						
							| 
									
										
										
										
											2016-09-23 22:28:11 +00:00
										 |  |  |   complex cdat(NSPM*nframes)
 | 
					
						
							| 
									
										
										
										
											2016-10-01 01:30:41 +00:00
										 |  |  |   complex cdat2(NSPM*nframes,8)
 | 
					
						
							| 
									
										
										
										
											2016-09-22 00:03:44 +00:00
										 |  |  |   complex c(NSPM)                    !Coherently averaged complex data
 | 
					
						
							| 
									
										
										
										
											2016-09-30 15:56:55 +00:00
										 |  |  |   complex cs(NSPM,8)
 | 
					
						
							| 
									
										
										
										
											2016-09-22 00:03:44 +00:00
										 |  |  |   complex cb(42)                     !Complex waveform for sync word 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   integer s8(8)
 | 
					
						
							|  |  |  |   integer iloc(1)
 | 
					
						
							| 
									
										
										
										
											2016-09-22 19:42:05 +00:00
										 |  |  |   integer npklocs(npeaks)
 | 
					
						
							| 
									
										
										
										
											2016-09-23 22:28:11 +00:00
										 |  |  |   integer navmask(nframes)                 ! defines which frames to average
 | 
					
						
							| 
									
										
										
										
											2016-09-22 00:03:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   real cbi(42),cbq(42)
 | 
					
						
							|  |  |  |   real pkamps(npeaks)
 | 
					
						
							|  |  |  |   real xcc(0:NSPM-1)
 | 
					
						
							| 
									
										
										
										
											2016-09-30 15:56:55 +00:00
										 |  |  |   real xccs(0:NSPM-1,8)
 | 
					
						
							|  |  |  |   real xm(8)
 | 
					
						
							|  |  |  |   real bf(8)
 | 
					
						
							| 
									
										
										
										
											2016-09-22 00:03:44 +00:00
										 |  |  |   real pp(12)                        !Half-sine pulse shape
 | 
					
						
							|  |  |  |   logical first
 | 
					
						
							|  |  |  |   data first/.true./
 | 
					
						
							|  |  |  |   data s8/0,1,1,1,0,0,1,0/
 | 
					
						
							| 
									
										
										
										
											2016-09-30 15:56:55 +00:00
										 |  |  |   save first,cb,fs,pi,twopi,dt,s8,pp
 | 
					
						
							| 
									
										
										
										
											2016-09-22 00:03:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if(first) then
 | 
					
						
							|  |  |  |      pi=4.0*atan(1.0)
 | 
					
						
							|  |  |  |      twopi=8.0*atan(1.0)
 | 
					
						
							|  |  |  |      fs=12000.0
 | 
					
						
							|  |  |  |      dt=1.0/fs
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |      do i=1,12                       !Define half-sine pulse
 | 
					
						
							|  |  |  |        angle=(i-1)*pi/12.0
 | 
					
						
							|  |  |  |        pp(i)=sin(angle)
 | 
					
						
							|  |  |  |      enddo
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! Define the sync word waveforms
 | 
					
						
							|  |  |  |      s8=2*s8-1  
 | 
					
						
							|  |  |  |      cbq(1:6)=pp(7:12)*s8(1)
 | 
					
						
							|  |  |  |      cbq(7:18)=pp*s8(3)
 | 
					
						
							|  |  |  |      cbq(19:30)=pp*s8(5)
 | 
					
						
							|  |  |  |      cbq(31:42)=pp*s8(7)
 | 
					
						
							|  |  |  |      cbi(1:12)=pp*s8(2)
 | 
					
						
							|  |  |  |      cbi(13:24)=pp*s8(4)
 | 
					
						
							|  |  |  |      cbi(25:36)=pp*s8(6)
 | 
					
						
							|  |  |  |      cbi(37:42)=pp(1:6)*s8(8)
 | 
					
						
							|  |  |  |      cb=cmplx(cbi,cbq)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |      first=.false.
 | 
					
						
							|  |  |  |   endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-30 15:56:55 +00:00
										 |  |  |   nfreqs=2*nint(ntol/delf) + 1
 | 
					
						
							| 
									
										
										
										
											2016-09-30 16:52:16 +00:00
										 |  |  |   xm=0.0
 | 
					
						
							|  |  |  |   bf=0.0
 | 
					
						
							| 
									
										
										
										
											2016-09-30 16:59:18 +00:00
										 |  |  |   nthreads=1
 | 
					
						
							| 
									
										
										
										
											2020-10-07 13:12:20 +01:00
										 |  |  | !$ nthreads=min(4,int(OMP_GET_MAX_THREADS(),4))
 | 
					
						
							| 
									
										
										
										
											2016-09-30 16:52:16 +00:00
										 |  |  |   nstep=nfreqs/nthreads
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-03 13:48:30 +00:00
										 |  |  | !$OMP PARALLEL NUM_THREADS(nthreads) PRIVATE(id,if1,if2)
 | 
					
						
							| 
									
										
										
										
											2016-09-30 16:59:18 +00:00
										 |  |  |   id=1
 | 
					
						
							| 
									
										
										
										
											2016-10-03 13:48:30 +00:00
										 |  |  | !$ id=OMP_GET_THREAD_NUM() + 1            !Thread id = 1,2,...
 | 
					
						
							| 
									
										
										
										
											2016-09-30 16:52:16 +00:00
										 |  |  |   if1=-nint(ntol/delf) + (id-1)*nstep
 | 
					
						
							|  |  |  |   if2=if1+nstep-1
 | 
					
						
							|  |  |  |   if(id.eq.nthreads) if2=nint(ntol/delf)
 | 
					
						
							|  |  |  |   call msk144_freq_search(cdat,fc,if1,if2,delf,nframes,navmask,cb,    &
 | 
					
						
							| 
									
										
										
										
											2016-10-01 01:30:41 +00:00
										 |  |  |        cdat2(1,id),xm(id),bf(id),cs(1,id),xccs(1,id))
 | 
					
						
							| 
									
										
										
										
											2016-10-03 13:48:30 +00:00
										 |  |  | !$OMP END PARALLEL
 | 
					
						
							| 
									
										
										
										
											2016-09-30 15:56:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-30 16:52:16 +00:00
										 |  |  |   xmax=xm(1)
 | 
					
						
							|  |  |  |   fest=fc+bf(1)
 | 
					
						
							|  |  |  |   c=cs(1:NSPM,1)
 | 
					
						
							|  |  |  |   xcc=xccs(0:NSPM-1,1)
 | 
					
						
							|  |  |  |   if(nthreads.gt.1) then
 | 
					
						
							| 
									
										
										
										
											2016-09-30 15:56:55 +00:00
										 |  |  |      do i=2,nthreads
 | 
					
						
							|  |  |  |         if(xm(i).gt.xmax) then
 | 
					
						
							|  |  |  |            xmax=xm(i)
 | 
					
						
							|  |  |  |            fest=fc+bf(i)
 | 
					
						
							|  |  |  |            c=cs(1:NSPM,i)
 | 
					
						
							|  |  |  |            xcc=xccs(0:NSPM-1,i)
 | 
					
						
							| 
									
										
										
										
											2016-09-22 00:03:44 +00:00
										 |  |  |         endif
 | 
					
						
							|  |  |  |      enddo
 | 
					
						
							| 
									
										
										
										
											2016-09-30 15:56:55 +00:00
										 |  |  |   endif
 | 
					
						
							| 
									
										
										
										
											2016-09-22 00:03:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Find npeaks largest peaks
 | 
					
						
							|  |  |  |   do ipk=1,npeaks
 | 
					
						
							|  |  |  |      iloc=maxloc(xcc)
 | 
					
						
							|  |  |  |      ic2=iloc(1)
 | 
					
						
							| 
									
										
										
										
											2016-09-22 19:42:05 +00:00
										 |  |  |      npklocs(ipk)=ic2
 | 
					
						
							| 
									
										
										
										
											2016-09-22 00:03:44 +00:00
										 |  |  |      pkamps(ipk)=xcc(ic2-1)
 | 
					
						
							|  |  |  |      xcc(max(0,ic2-7):min(NSPM-1,ic2+7))=0.0
 | 
					
						
							|  |  |  |   enddo
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-03 17:08:02 +00:00
										 |  |  |   nsuccess=0
 | 
					
						
							|  |  |  |   if(xmax.ge.1.3) nsuccess=1
 | 
					
						
							| 
									
										
										
										
											2016-09-29 16:39:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-22 00:03:44 +00:00
										 |  |  |   return
 | 
					
						
							|  |  |  | end subroutine msk144sync
 |