| 
									
										
										
										
											2015-11-18 01:28:12 +00:00
										 |  |  | subroutine ccf2(ss,nz,nflip,ccfbest,xlagpk)
 | 
					
						
							| 
									
										
										
										
											2013-07-08 13:17:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 20:46:00 +00:00
										 |  |  | !  parameter (LAGMIN=-86,LAGMAX=258)
 | 
					
						
							|  |  |  |   parameter (LAGMIN=-112,LAGMAX=258)  ! Look for DT from -3.6s to +5.0s
 | 
					
						
							| 
									
										
										
										
											2013-07-08 13:17:22 +00:00
										 |  |  |   real ss(nz)
 | 
					
						
							|  |  |  |   real ccf(-LAGMAX:LAGMAX)
 | 
					
						
							|  |  |  |   integer npr(126)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! The JT65 pseudo-random sync pattern:
 | 
					
						
							|  |  |  |   data npr/                                    &
 | 
					
						
							|  |  |  |       1,0,0,1,1,0,0,0,1,1,1,1,1,1,0,1,0,1,0,0, &
 | 
					
						
							|  |  |  |       0,1,0,1,1,0,0,1,0,0,0,1,1,1,0,0,1,1,1,1, &
 | 
					
						
							|  |  |  |       0,1,1,0,1,1,1,1,0,0,0,1,1,0,1,0,1,0,1,1, &
 | 
					
						
							|  |  |  |       0,0,1,1,0,1,0,1,0,1,0,0,1,0,0,0,0,0,0,1, &
 | 
					
						
							|  |  |  |       1,0,0,0,0,0,0,0,1,1,0,1,0,0,1,0,1,1,0,1, &
 | 
					
						
							|  |  |  |       0,1,0,1,0,0,1,1,0,0,1,0,0,1,0,0,0,0,1,1, &
 | 
					
						
							|  |  |  |       1,1,1,1,1,1/
 | 
					
						
							|  |  |  |   save
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ccfbest=0.
 | 
					
						
							| 
									
										
										
										
											2015-11-25 16:40:22 +00:00
										 |  |  |   lag1=LAGMIN
 | 
					
						
							| 
									
										
										
										
											2013-07-08 13:17:22 +00:00
										 |  |  |   lag2=LAGMAX
 | 
					
						
							|  |  |  |   do lag=lag1,lag2
 | 
					
						
							|  |  |  |      s0=0.
 | 
					
						
							|  |  |  |      s1=0.
 | 
					
						
							|  |  |  |      do i=1,126
 | 
					
						
							| 
									
										
										
										
											2015-11-18 01:28:12 +00:00
										 |  |  |         j=16*(i-1)+1 + lag
 | 
					
						
							| 
									
										
										
										
											2013-07-08 13:17:22 +00:00
										 |  |  |         if(j.ge.1 .and. j.le.nz-8) then
 | 
					
						
							| 
									
										
										
										
											2015-11-18 01:28:12 +00:00
										 |  |  |            x=ss(j)
 | 
					
						
							| 
									
										
										
										
											2013-07-08 13:17:22 +00:00
										 |  |  |            if(npr(i).eq.0) then
 | 
					
						
							|  |  |  |               s0=s0 + x
 | 
					
						
							|  |  |  |            else
 | 
					
						
							|  |  |  |               s1=s1 + x
 | 
					
						
							|  |  |  |            endif
 | 
					
						
							|  |  |  |         endif
 | 
					
						
							|  |  |  |      enddo
 | 
					
						
							|  |  |  |      ccf(lag)=nflip*(s1-s0)
 | 
					
						
							|  |  |  |      if(ccf(lag).gt.ccfbest) then
 | 
					
						
							|  |  |  |         ccfbest=ccf(lag)
 | 
					
						
							|  |  |  |         lagpk=lag
 | 
					
						
							| 
									
										
										
										
											2015-11-25 16:40:22 +00:00
										 |  |  |         xlagpk=lagpk
 | 
					
						
							| 
									
										
										
										
											2013-07-08 13:17:22 +00:00
										 |  |  |      endif
 | 
					
						
							|  |  |  |   enddo
 | 
					
						
							| 
									
										
										
										
											2015-11-18 01:28:12 +00:00
										 |  |  |   if( lagpk.gt.-LAGMAX .and. lagpk.lt.LAGMAX) then
 | 
					
						
							| 
									
										
										
										
											2015-11-25 16:40:22 +00:00
										 |  |  |      call peakup(ccf(lagpk-1),ccf(lagpk),ccf(lagpk+1),dx)
 | 
					
						
							|  |  |  |      xlagpk=lagpk+dx
 | 
					
						
							| 
									
										
										
										
											2015-11-18 01:28:12 +00:00
										 |  |  |   endif
 | 
					
						
							| 
									
										
										
										
											2013-07-08 13:17:22 +00:00
										 |  |  |   return
 | 
					
						
							|  |  |  | end subroutine ccf2
 |