2020-08-01 09:24:59 -04:00
|
|
|
module qra66_decode
|
|
|
|
|
|
|
|
type :: qra66_decoder
|
|
|
|
procedure(qra66_decode_callback), pointer :: callback
|
|
|
|
contains
|
|
|
|
procedure :: decode
|
|
|
|
end type qra66_decoder
|
|
|
|
|
|
|
|
abstract interface
|
|
|
|
subroutine qra66_decode_callback (this,nutc,sync,nsnr,dt,freq, &
|
|
|
|
decoded,nap,qual,ntrperiod,fmid,w50)
|
|
|
|
import qra66_decoder
|
|
|
|
implicit none
|
|
|
|
class(qra66_decoder), intent(inout) :: this
|
|
|
|
integer, intent(in) :: nutc
|
|
|
|
real, intent(in) :: sync
|
|
|
|
integer, intent(in) :: nsnr
|
|
|
|
real, intent(in) :: dt
|
|
|
|
real, intent(in) :: freq
|
|
|
|
character(len=37), intent(in) :: decoded
|
|
|
|
integer, intent(in) :: nap
|
|
|
|
real, intent(in) :: qual
|
|
|
|
integer, intent(in) :: ntrperiod
|
|
|
|
real, intent(in) :: fmid
|
|
|
|
real, intent(in) :: w50
|
|
|
|
end subroutine qra66_decode_callback
|
|
|
|
end interface
|
|
|
|
|
|
|
|
contains
|
|
|
|
|
2020-08-09 11:04:49 -04:00
|
|
|
subroutine decode(this,callback,iwave,nutc,ntrperiod,nsubmode,nfqso, &
|
|
|
|
ntol,ndepth,mycall,hiscall,hisgrid)
|
2020-08-01 09:24:59 -04:00
|
|
|
|
|
|
|
use timer_module, only: timer
|
|
|
|
use packjt
|
|
|
|
use, intrinsic :: iso_c_binding
|
2020-08-08 13:57:24 -04:00
|
|
|
parameter (NMAX=300*12000) !### Needs to be 300*12000 ###
|
2020-08-01 09:24:59 -04:00
|
|
|
class(qra66_decoder), intent(inout) :: this
|
|
|
|
procedure(qra66_decode_callback) :: callback
|
|
|
|
character(len=12) :: mycall, hiscall
|
|
|
|
character(len=6) :: hisgrid
|
|
|
|
character*37 decoded
|
2020-08-08 09:14:12 -04:00
|
|
|
integer*2 iwave(NMAX) !Raw data
|
2020-08-01 09:24:59 -04:00
|
|
|
integer dat4(12)
|
|
|
|
logical lapdx,ltext
|
2020-08-08 13:57:24 -04:00
|
|
|
complex, allocatable :: c0(:) !Analytic signal, 6000 S/s
|
2020-08-09 11:04:49 -04:00
|
|
|
real, allocatable, save :: s3(:,:) !Symbol spectra
|
|
|
|
real, allocatable, save :: s3a(:,:) !Symbol spectra for avg messages
|
2020-08-01 09:24:59 -04:00
|
|
|
real a(5)
|
2020-08-09 11:04:49 -04:00
|
|
|
data nc1z/-1/,nc2z/-1/,ng2z/-1/,maxaptypez/-1/,nsubmodez/-1/
|
|
|
|
save nc1z,nc2z,ng2z,maxaptypez,nsave,nsubmodez
|
2020-08-01 12:13:49 -04:00
|
|
|
|
2020-08-09 11:04:49 -04:00
|
|
|
mode66=2**nsubmode
|
2020-08-08 09:14:12 -04:00
|
|
|
nfft1=ntrperiod*12000
|
|
|
|
nfft2=ntrperiod*6000
|
2020-08-08 13:57:24 -04:00
|
|
|
allocate (c0(0:nfft1-1))
|
2020-08-09 11:04:49 -04:00
|
|
|
|
|
|
|
if(nsubmode.ne.nsubmodez) then
|
|
|
|
if(allocated(s3)) deallocate(s3)
|
|
|
|
if(allocated(s3a)) deallocate(s3a)
|
|
|
|
allocate(s3(-64:64*mode66+63,63))
|
|
|
|
allocate(s3a(-64:64*mode66+63,63))
|
|
|
|
endif
|
2020-08-08 13:57:24 -04:00
|
|
|
|
2020-08-08 09:14:12 -04:00
|
|
|
if(ntrperiod.eq.15) then
|
|
|
|
nsps=1800
|
|
|
|
else if(ntrperiod.eq.30) then
|
|
|
|
nsps=3600
|
|
|
|
else if(ntrperiod.eq.60) then
|
|
|
|
nsps=7680
|
|
|
|
else if(ntrperiod.eq.120) then
|
|
|
|
nsps=16000
|
|
|
|
else if(ntrperiod.eq.300) then
|
|
|
|
nsps=41472
|
|
|
|
else
|
|
|
|
stop 'Invalid TR period'
|
|
|
|
endif
|
2020-08-01 09:24:59 -04:00
|
|
|
baud=12000.0/nsps
|
2020-08-08 09:14:12 -04:00
|
|
|
df1=12000.0/nfft1
|
2020-08-08 13:57:24 -04:00
|
|
|
|
|
|
|
! do i=1,NMAX
|
|
|
|
! write(61,3061) i/12000.0,iwave(i)/32767.0
|
|
|
|
!3061 format(2f12.6)
|
|
|
|
! enddo
|
|
|
|
|
2020-08-08 09:14:12 -04:00
|
|
|
this%callback => callback
|
2020-08-01 09:24:59 -04:00
|
|
|
|
2020-08-01 15:12:37 -04:00
|
|
|
if(nutc.eq.-999) print*,lapdx,nfa,nfb,nfqso !Silence warning
|
2020-08-01 09:24:59 -04:00
|
|
|
|
|
|
|
! Prime the QRA decoder for possible use of AP
|
|
|
|
call packcall(mycall(1:6),nc1,ltext)
|
|
|
|
call packcall(hiscall(1:6),nc2,ltext)
|
|
|
|
call packgrid(hisgrid(1:4),ng2,ltext)
|
2020-08-04 10:49:14 -04:00
|
|
|
b90=20.0 !8 to 25 is OK; not very critical
|
2020-08-01 09:24:59 -04:00
|
|
|
nFadingModel=1
|
2020-08-02 11:15:10 -04:00
|
|
|
|
2020-08-04 11:52:29 -04:00
|
|
|
! AP control could be done differently, but this works well:
|
2020-08-02 11:15:10 -04:00
|
|
|
maxaptype=0
|
|
|
|
if(ndepth.eq.2) maxaptype=3
|
2020-08-02 11:40:03 -04:00
|
|
|
if(ndepth.eq.3) maxaptype=5
|
2020-08-02 11:15:10 -04:00
|
|
|
|
2020-08-01 09:24:59 -04:00
|
|
|
if(nc1.ne.nc1z .or. nc2.ne.nc2z .or. ng2.ne.ng2z .or. &
|
|
|
|
maxaptype.ne.maxaptypez) then
|
|
|
|
do naptype=0,maxaptype
|
|
|
|
if(naptype.eq.2 .and. maxaptype.eq.4) cycle
|
|
|
|
call qra64_dec(s3,nc1,nc2,ng2,naptype,1,nSubmode,b90, &
|
|
|
|
nFadingModel,dat4,snr2,irc)
|
|
|
|
enddo
|
|
|
|
nc1z=nc1
|
|
|
|
nc2z=nc2
|
|
|
|
ng2z=ng2
|
|
|
|
maxaptypez=maxaptype
|
2020-08-05 16:34:49 -04:00
|
|
|
s3a=0.
|
|
|
|
nsave=0
|
2020-08-01 09:24:59 -04:00
|
|
|
endif
|
|
|
|
naptype=maxaptype
|
|
|
|
|
2020-08-04 11:52:29 -04:00
|
|
|
! Downsample to give complex data at 6000 S/s
|
2020-08-08 09:14:12 -04:00
|
|
|
fac=2.0/nfft1
|
2020-08-08 13:57:24 -04:00
|
|
|
c0=fac*iwave(1:nfft1)
|
2020-08-08 09:14:12 -04:00
|
|
|
call four2a(c0,nfft1,1,-1,1) !Forward c2c FFT
|
|
|
|
c0(nfft2/2+1:nfft2)=0. !Zero the top half
|
2020-08-01 09:24:59 -04:00
|
|
|
c0(0)=0.5*c0(0)
|
|
|
|
call four2a(c0,nfft2,1,1,1) !Inverse c2c FFT
|
2020-08-04 11:58:09 -04:00
|
|
|
call timer('sync66 ',0)
|
2020-08-09 11:04:49 -04:00
|
|
|
call sync66(iwave,ntrperiod*12000,mode66,nsps,nfqso,ntol,xdt,f0,snr1)
|
2020-08-04 11:58:09 -04:00
|
|
|
call timer('sync66 ',1)
|
2020-08-09 11:04:49 -04:00
|
|
|
|
2020-08-08 13:57:24 -04:00
|
|
|
jpk=(xdt+0.5)*6000 - 384 !### Empirical ###
|
|
|
|
if(ntrperiod.ge.60) jpk=(xdt+1.0)*6000 - 384 !### TBD ###
|
2020-08-03 16:30:29 -04:00
|
|
|
if(jpk.lt.0) jpk=0
|
2020-08-01 09:24:59 -04:00
|
|
|
a=0.
|
2020-08-09 11:04:49 -04:00
|
|
|
a(1)=-(f0 + 2.0*mode66*baud) !Data tones start 2*mode66 bins higher
|
2020-08-08 13:57:24 -04:00
|
|
|
call twkfreq(c0,c0,ntrperiod*6000,6000.0,a)
|
2020-08-04 10:49:14 -04:00
|
|
|
xdt=jpk/6000.0 - 0.5
|
2020-08-09 11:04:49 -04:00
|
|
|
|
|
|
|
LL=64*(mode66+2)
|
|
|
|
NN=63
|
|
|
|
call spec66(c0(jpk:),nsps/2,s3,LL,NN) !Compute the synchronized symbol spectra
|
2020-08-03 16:30:29 -04:00
|
|
|
|
2020-08-04 11:52:29 -04:00
|
|
|
do j=1,63 !Normalize to symbol baseline
|
2020-08-09 11:04:49 -04:00
|
|
|
call pctile(s3(:,j),LL,40,base)
|
2020-08-04 10:49:14 -04:00
|
|
|
s3(:,j)=s3(:,j)/base
|
|
|
|
enddo
|
|
|
|
|
2020-08-09 11:04:49 -04:00
|
|
|
LL2=64*(mode66+1)-1
|
2020-08-04 10:49:14 -04:00
|
|
|
s3max=20.0
|
2020-08-04 11:52:29 -04:00
|
|
|
do j=1,63 !Apply AGC to suppress pings
|
2020-08-09 11:04:49 -04:00
|
|
|
xx=maxval(s3(-64:LL2,j))
|
|
|
|
if(xx.gt.s3max) s3(-64:LL2,j)=s3(-64:LL2,j)*s3max/xx
|
2020-08-04 10:49:14 -04:00
|
|
|
enddo
|
2020-08-04 11:52:29 -04:00
|
|
|
|
2020-08-05 16:34:49 -04:00
|
|
|
! Call Nico's QRA64 decoder
|
2020-08-04 11:58:09 -04:00
|
|
|
call timer('qra64_de',0)
|
2020-08-04 10:49:14 -04:00
|
|
|
call qra64_dec(s3,nc1,nc2,ng2,naptype,0,nSubmode,b90, &
|
2020-08-01 09:24:59 -04:00
|
|
|
nFadingModel,dat4,snr2,irc)
|
2020-08-04 11:58:09 -04:00
|
|
|
call timer('qra64_de',1)
|
2020-08-05 16:34:49 -04:00
|
|
|
|
|
|
|
if(irc.lt.0) then
|
|
|
|
! No luck so far. Try for an average decode.
|
|
|
|
call timer('qra64_av',0)
|
|
|
|
s3a=s3a+s3
|
|
|
|
nsave=nsave+1
|
|
|
|
if(nsave.ge.2) then
|
|
|
|
call qra64_dec(s3a,nc1,nc2,ng2,naptype,0,nSubmode,b90, &
|
|
|
|
nFadingModel,dat4,snr2,irc)
|
2020-08-08 09:14:12 -04:00
|
|
|
if(irc.ge.0) irc=100*nsave + irc
|
2020-08-05 16:34:49 -04:00
|
|
|
endif
|
|
|
|
call timer('qra64_av',1)
|
|
|
|
endif
|
2020-08-08 09:14:12 -04:00
|
|
|
snr2=snr2 + db(6912.0/nsps)
|
2020-08-01 09:24:59 -04:00
|
|
|
if(irc.gt.0) call badmsg(irc,dat4,nc1,nc2,ng2)
|
|
|
|
|
|
|
|
decoded=' '
|
|
|
|
if(irc.ge.0) then
|
2020-08-05 16:34:49 -04:00
|
|
|
nsave=0
|
|
|
|
s3a=0.
|
2020-08-01 09:24:59 -04:00
|
|
|
call unpackmsg(dat4,decoded) !Unpack the user message
|
|
|
|
call fmtmsg(decoded,iz)
|
|
|
|
if(index(decoded,"000AAA ").ge.1) then
|
|
|
|
! Suppress a certain type of garbage decode.
|
|
|
|
decoded=' '
|
|
|
|
irc=-1
|
|
|
|
endif
|
|
|
|
nsnr=nint(snr2)
|
2020-08-01 12:13:49 -04:00
|
|
|
call this%callback(nutc,sync,nsnr,xdt,f0,decoded, &
|
|
|
|
irc,qual,ntrperiod,fmid,w50)
|
2020-08-01 09:24:59 -04:00
|
|
|
else
|
|
|
|
snr2=0.
|
2020-08-05 11:16:56 -04:00
|
|
|
nsnr=-25
|
2020-08-01 15:12:37 -04:00
|
|
|
!### TEMPORARY? ###
|
|
|
|
call this%callback(nutc,sync,nsnr,xdt,f0,decoded, &
|
|
|
|
irc,qual,ntrperiod,fmid,w50)
|
|
|
|
!###
|
2020-08-01 09:24:59 -04:00
|
|
|
endif
|
2020-08-01 15:12:37 -04:00
|
|
|
|
2020-08-04 10:49:14 -04:00
|
|
|
! write(61,3061) nutc,irc,xdt,f0,snr1,snr2,trim(decoded)
|
|
|
|
!3061 format(i6.6,i4,4f10.2,2x,a)
|
|
|
|
|
2020-08-01 09:24:59 -04:00
|
|
|
return
|
|
|
|
end subroutine decode
|
|
|
|
|
|
|
|
end module qra66_decode
|