| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  | module ft8_decode
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   type :: ft8_decoder
 | 
					
						
							|  |  |  |      procedure(ft8_decode_callback), pointer :: callback
 | 
					
						
							|  |  |  |    contains
 | 
					
						
							|  |  |  |      procedure :: decode
 | 
					
						
							|  |  |  |   end type ft8_decoder
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   abstract interface
 | 
					
						
							| 
									
										
										
										
											2017-07-22 17:12:48 +00:00
										 |  |  |      subroutine ft8_decode_callback (this,sync,snr,dt,freq,decoded,nap,qual)
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  |        import ft8_decoder
 | 
					
						
							|  |  |  |        implicit none
 | 
					
						
							|  |  |  |        class(ft8_decoder), intent(inout) :: this
 | 
					
						
							|  |  |  |        real, intent(in) :: sync
 | 
					
						
							|  |  |  |        integer, intent(in) :: snr
 | 
					
						
							|  |  |  |        real, intent(in) :: dt
 | 
					
						
							|  |  |  |        real, intent(in) :: freq
 | 
					
						
							|  |  |  |        character(len=22), intent(in) :: decoded
 | 
					
						
							| 
									
										
										
										
											2017-07-22 17:12:48 +00:00
										 |  |  |        integer, intent(in) :: nap 
 | 
					
						
							|  |  |  |        real, intent(in) :: qual 
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  |      end subroutine ft8_decode_callback
 | 
					
						
							|  |  |  |   end interface
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | contains
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-28 15:50:13 +00:00
										 |  |  |   subroutine decode(this,callback,iwave,nQSOProgress,nfqso,nftx,newdat,    &
 | 
					
						
							| 
									
										
										
										
											2017-08-02 14:05:37 +00:00
										 |  |  |        nutc,nfa,nfb,nexp_decode,ndepth,nagain,lapon,napwid,mycall12,       &
 | 
					
						
							|  |  |  |        mygrid6,hiscall12,hisgrid6)
 | 
					
						
							| 
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 |  |  | !    use wavhdr
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  |     use timer_module, only: timer
 | 
					
						
							|  |  |  |     include 'fsk4hf/ft8_params.f90'
 | 
					
						
							| 
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 |  |  | !    type(hdr) h
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     class(ft8_decoder), intent(inout) :: this
 | 
					
						
							|  |  |  |     procedure(ft8_decode_callback) :: callback
 | 
					
						
							|  |  |  |     real s(NH1,NHSYM)
 | 
					
						
							|  |  |  |     real candidate(3,200)
 | 
					
						
							|  |  |  |     real dd(15*12000)
 | 
					
						
							| 
									
										
										
										
											2017-08-02 14:05:37 +00:00
										 |  |  |     logical, intent(in) :: lapon,nagain
 | 
					
						
							| 
									
										
										
										
											2017-07-28 15:50:13 +00:00
										 |  |  |     logical newdat,lsubtract,ldupe,bcontest
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  |     character*12 mycall12, hiscall12
 | 
					
						
							| 
									
										
										
										
											2017-07-28 15:50:13 +00:00
										 |  |  |     character*6 mygrid6,hisgrid6
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  |     integer*2 iwave(15*12000)
 | 
					
						
							|  |  |  |     integer apsym(KK)
 | 
					
						
							|  |  |  |     character datetime*13,message*22
 | 
					
						
							| 
									
										
										
										
											2017-07-20 21:08:36 +00:00
										 |  |  |     character*22 allmessages(100)
 | 
					
						
							|  |  |  |     integer allsnrs(100)
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  |     save s,dd
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-28 15:50:13 +00:00
										 |  |  |     bcontest=iand(nexp_decode,128).ne.0
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  |     this%callback => callback
 | 
					
						
							|  |  |  |     write(datetime,1001) nutc        !### TEMPORARY ###
 | 
					
						
							|  |  |  | 1001 format("000000_",i6.6)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-28 15:50:13 +00:00
										 |  |  |     call ft8apset(mycall12,mygrid6,hiscall12,hisgrid6,bcontest,apsym,iaptype)
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  |     dd=iwave
 | 
					
						
							| 
									
										
										
										
											2017-07-20 21:08:36 +00:00
										 |  |  |     ndecodes=0
 | 
					
						
							|  |  |  |     allmessages='                      '
 | 
					
						
							|  |  |  |     allsnrs=0
 | 
					
						
							| 
									
										
										
										
											2017-08-02 14:05:37 +00:00
										 |  |  |     ifa=nfa
 | 
					
						
							|  |  |  |     ifb=nfb
 | 
					
						
							|  |  |  |     if(nagain) then
 | 
					
						
							|  |  |  |        ifa=nfqso-10
 | 
					
						
							|  |  |  |        ifb=nfqso+10
 | 
					
						
							|  |  |  |     endif
 | 
					
						
							| 
									
										
										
										
											2017-07-20 21:08:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 |  |  | ! For now:
 | 
					
						
							|  |  |  | ! ndepth=1: no subtraction, 1 pass, belief propagation only
 | 
					
						
							|  |  |  | ! ndepth=2: subtraction, 2 passes, belief propagation only
 | 
					
						
							|  |  |  | ! ndepth=3: subtraction, 2 passes, bp+osd2 at and near nfqso
 | 
					
						
							|  |  |  |     if(ndepth.eq.1) npass=1
 | 
					
						
							|  |  |  |     if(ndepth.ge.2) npass=2
 | 
					
						
							|  |  |  |     do ipass=1,npass
 | 
					
						
							|  |  |  |       newdat=.true.  ! Is this a problem? I hijacked newdat.
 | 
					
						
							|  |  |  |       if(ipass.eq.1) then
 | 
					
						
							|  |  |  |         lsubtract=.true.
 | 
					
						
							|  |  |  |         if(ndepth.eq.1) lsubtract=.false.
 | 
					
						
							| 
									
										
										
										
											2017-07-16 15:56:06 +00:00
										 |  |  |         syncmin=1.5
 | 
					
						
							| 
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 |  |  |       else
 | 
					
						
							|  |  |  |         lsubtract=.false.
 | 
					
						
							| 
									
										
										
										
											2017-07-16 15:56:06 +00:00
										 |  |  |         syncmin=1.5
 | 
					
						
							| 
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 |  |  |       endif 
 | 
					
						
							|  |  |  |       call timer('sync8   ',0)
 | 
					
						
							| 
									
										
										
										
											2017-08-02 14:05:37 +00:00
										 |  |  |       call sync8(dd,ifa,ifb,syncmin,nfqso,s,candidate,ncand)
 | 
					
						
							| 
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 |  |  |       call timer('sync8   ',1)
 | 
					
						
							|  |  |  |       do icand=1,ncand
 | 
					
						
							|  |  |  |         sync=candidate(3,icand)
 | 
					
						
							|  |  |  |         f1=candidate(1,icand)
 | 
					
						
							|  |  |  |         xdt=candidate(2,icand)
 | 
					
						
							|  |  |  |         nsnr0=min(99,nint(10.0*log10(sync) - 25.5))    !### empirical ###
 | 
					
						
							|  |  |  |         call timer('ft8b    ',0)
 | 
					
						
							| 
									
										
										
										
											2017-07-27 15:35:40 +00:00
										 |  |  |         call ft8b(dd,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,napwid,    &
 | 
					
						
							| 
									
										
										
										
											2017-08-03 14:46:21 +00:00
										 |  |  |              lsubtract,nagain,iaptype,mygrid6,bcontest,sync,f1,xdt,apsym,   &
 | 
					
						
							| 
									
										
										
										
											2017-07-28 15:50:13 +00:00
										 |  |  |              nharderrors,dmin,nbadcrc,iappass,iera,message,xsnr)
 | 
					
						
							| 
									
										
										
										
											2017-07-16 17:08:09 +00:00
										 |  |  |         nsnr=nint(xsnr) 
 | 
					
						
							| 
									
										
										
										
											2017-07-18 15:22:20 +00:00
										 |  |  |         xdt=xdt-0.5
 | 
					
						
							| 
									
										
										
										
											2017-07-20 15:15:00 +00:00
										 |  |  |         hd=nharderrors+dmin
 | 
					
						
							| 
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 |  |  |         call timer('ft8b    ',1)
 | 
					
						
							| 
									
										
										
										
											2017-07-20 15:15:00 +00:00
										 |  |  |         if(nbadcrc.eq.0) then
 | 
					
						
							| 
									
										
										
										
											2017-08-09 15:22:54 +00:00
										 |  |  | !           call jtmsg(message,iflag)
 | 
					
						
							| 
									
										
										
										
											2017-07-28 15:50:13 +00:00
										 |  |  |            if(bcontest) call fix_contest_msg(mygrid6,message)
 | 
					
						
							| 
									
										
										
										
											2017-08-09 15:22:54 +00:00
										 |  |  | !           if(iand(iflag,31).ne.0) message(22:22)='?'
 | 
					
						
							|  |  |  |            ldupe=.false.
 | 
					
						
							|  |  |  |            do id=1,ndecodes
 | 
					
						
							|  |  |  |               if(message.eq.allmessages(id).and.nsnr.le.allsnrs(id)) ldupe=.true.
 | 
					
						
							|  |  |  |            enddo
 | 
					
						
							|  |  |  |            if(.not.ldupe) then
 | 
					
						
							|  |  |  |               ndecodes=ndecodes+1
 | 
					
						
							|  |  |  |               allmessages(ndecodes)=message
 | 
					
						
							|  |  |  |               allsnrs(ndecodes)=nsnr
 | 
					
						
							|  |  |  |            endif
 | 
					
						
							|  |  |  | !           write(81,1004) nutc,ncand,icand,ipass,iaptype,iappass,        &
 | 
					
						
							|  |  |  | !                nharderrors,dmin,hd,min(sync,999.0),nint(xsnr),          &
 | 
					
						
							|  |  |  | !                xdt,nint(f1),message
 | 
					
						
							|  |  |  | !1004          format(i6.6,2i4,3i2,i3,3f6.1,i4,f6.2,i5,2x,a22)
 | 
					
						
							|  |  |  | !           flush(81)
 | 
					
						
							|  |  |  |            if(.not.ldupe .and. associated(this%callback)) then
 | 
					
						
							|  |  |  |               qual=1.0-(nharderrors+dmin)/60.0 ! scale qual to [0.0,1.0]
 | 
					
						
							|  |  |  |               call this%callback(sync,nsnr,xdt,f1,message,iaptype,qual)
 | 
					
						
							| 
									
										
										
										
											2017-07-20 15:15:00 +00:00
										 |  |  |            endif
 | 
					
						
							| 
									
										
										
										
											2017-07-14 16:02:01 +00:00
										 |  |  |         endif
 | 
					
						
							| 
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 |  |  |       enddo
 | 
					
						
							|  |  |  | !     h=default_header(12000,NMAX)
 | 
					
						
							|  |  |  | !     open(10,file='subtract.wav',status='unknown',access='stream')
 | 
					
						
							|  |  |  | !     iwave=nint(dd)
 | 
					
						
							|  |  |  | !     write(10) h,iwave
 | 
					
						
							|  |  |  | !     close(10)
 | 
					
						
							|  |  |  |   enddo
 | 
					
						
							|  |  |  |   return
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  |   end subroutine decode
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | end module ft8_decode
 |