WSJT-X/lib/freqcal.f90
Joe Taylor 62f5447520 First usable-at-K1JT version of a semi-automated Frequency Calibration routine.
git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@7452 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
2017-01-05 20:20:43 +00:00

62 lines
1.4 KiB
Fortran

subroutine freqcal(id2,k,nkhz,noffset,ntol,line)
parameter (NZ=30*12000,NFFT=55296,NH=NFFT/2)
integer*2 id2(0:NZ-1)
real x(0:NFFT-1)
real s(NH)
character line*80,cflag*1
complex cx(0:NH)
equivalence (x,cx)
data n/0/,k0/9999999/
save n,k0
if(k.lt.NFFT) go to 900
if(k.lt.k0) n=0
k0=k
x=0.001*id2(k-NFFT:k-1)
call four2a(x,NFFT,1,-1,0) !Compute spectrum, r2c
df=12000.0/NFFT
ia=nint((noffset-ntol)/df)
ib=nint((noffset+ntol)/df)
smax=0.
s=0.
do i=ia,ib
s(i)=real(cx(i))**2 + aimag(cx(i))**2
if(s(i).gt.smax) then
smax=s(i)
ipk=i
endif
enddo
call peakup(s(ipk-1),s(ipk),s(ipk+1),dx)
fpeak=df * (ipk+dx)
sum=0.
nsum=0
do i=ia,ib
if(abs(i-ipk).gt.10) then
sum=sum+s(i)
nsum=nsum+1
endif
enddo
ave=sum/nsum
snr=db(smax/ave)
pave=db(ave) + 8.0
cflag=' '
if(snr.lt.20.0) cflag='*'
n=n+1
nsec=mod(time(),86400)
nhr=nsec/3600
nmin=mod(nsec/60,60)
nsec=mod(nsec,60)
ncal=1
ferr=fpeak-noffset
write(line,1100) nhr,nmin,nsec,nkhz,ncal,noffset,fpeak,ferr,pave, &
snr,callsign,cflag,char(0)
write(61,1100) nhr,nmin,nsec,nkhz,ncal,noffset,fpeak,ferr,pave, &
snr,callsign,cflag,char(0)
1100 format(i2.2,':',i2.2,':',i2.2,i7,i3,i6,2f10.3,2f7.1,2x,a6,2x,a1,a1)
900 return
end subroutine freqcal