| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  | module ft8_decode
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:08 +00:00
										 |  |  |   parameter (MAXFOX=1000)
 | 
					
						
							|  |  |  |   character*12 c2fox(MAXFOX)
 | 
					
						
							|  |  |  |   character*4  g2fox(MAXFOX)
 | 
					
						
							|  |  |  |   integer nsnrfox(MAXFOX)
 | 
					
						
							|  |  |  |   integer nfreqfox(MAXFOX)
 | 
					
						
							| 
									
										
										
										
											2017-12-19 17:01:38 +00:00
										 |  |  |   integer n30fox(MAXFOX)
 | 
					
						
							|  |  |  |   integer n30z
 | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:08 +00:00
										 |  |  |   integer nfox
 | 
					
						
							|  |  |  |   
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  |   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
 | 
					
						
							| 
									
										
										
										
											2017-12-19 20:01:06 +00:00
										 |  |  |        character(len=37), 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-12-04 00:46:19 +00:00
										 |  |  |   subroutine decode(this,callback,iwave,nQSOProgress,nfqso,nftx,newdat,  &
 | 
					
						
							| 
									
										
										
										
											2018-11-05 14:40:55 -06:00
										 |  |  |        nutc,nfa,nfb,ndepth,ncontest,nagain,lft8apon,lapcqonly, &
 | 
					
						
							| 
									
										
										
										
											2018-07-27 09:30:00 -04:00
										 |  |  |        napwid,mycall12,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
 | 
					
						
							| 
									
										
										
										
											2017-10-30 21:30:14 +00:00
										 |  |  |     include 'ft8/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
 | 
					
						
							| 
									
										
										
										
											2018-08-08 16:05:21 +00:00
										 |  |  |     parameter (MAXCAND=300)
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  |     real s(NH1,NHSYM)
 | 
					
						
							| 
									
										
										
										
											2017-08-26 16:30:47 +00:00
										 |  |  |     real sbase(NH1)
 | 
					
						
							| 
									
										
										
										
											2018-11-05 11:59:48 -05:00
										 |  |  |     real candidate(3,MAXCAND)
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  |     real dd(15*12000)
 | 
					
						
							| 
									
										
										
										
											2018-11-05 14:40:55 -06:00
										 |  |  |     logical, intent(in) :: lft8apon,lapcqonly,nagain
 | 
					
						
							| 
									
										
										
										
											2018-07-10 15:32:59 -04:00
										 |  |  |     logical newdat,lsubtract,ldupe
 | 
					
						
							| 
									
										
										
										
											2018-07-30 15:46:25 -04:00
										 |  |  |     character*12 mycall12,hiscall12,mycall12_0
 | 
					
						
							| 
									
										
										
										
											2018-07-25 15:19:57 -04:00
										 |  |  |     character*6 hisgrid6
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  |     integer*2 iwave(15*12000)
 | 
					
						
							| 
									
										
										
										
											2018-12-03 07:18:52 -06:00
										 |  |  |     integer apsym2(58)
 | 
					
						
							| 
									
										
										
										
											2018-07-25 15:19:57 -04:00
										 |  |  |     character datetime*13,msg37*37
 | 
					
						
							|  |  |  | !   character message*22
 | 
					
						
							| 
									
										
										
										
											2018-07-04 16:20:12 -05:00
										 |  |  |     character*37 allmessages(100)
 | 
					
						
							| 
									
										
										
										
											2017-07-20 21:08:36 +00:00
										 |  |  |     integer allsnrs(100)
 | 
					
						
							| 
									
										
										
										
											2018-07-30 15:46:25 -04:00
										 |  |  |     data mycall12_0/'dummy'/
 | 
					
						
							|  |  |  |     save s,dd,mycall12_0
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if(mycall12.ne.mycall12_0) then
 | 
					
						
							|  |  |  |        mycall12_0=mycall12
 | 
					
						
							|  |  |  |     endif
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     this%callback => callback
 | 
					
						
							|  |  |  |     write(datetime,1001) nutc        !### TEMPORARY ###
 | 
					
						
							|  |  |  | 1001 format("000000_",i6.6)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-05 11:59:48 -05:00
										 |  |  |     call ft8apset(mycall12,hiscall12,apsym2)
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  |     dd=iwave
 | 
					
						
							| 
									
										
										
										
											2017-07-20 21:08:36 +00:00
										 |  |  |     ndecodes=0
 | 
					
						
							| 
									
										
										
										
											2018-07-04 16:20:12 -05:00
										 |  |  |     allmessages='                                     '
 | 
					
						
							| 
									
										
										
										
											2017-07-20 21:08:36 +00:00
										 |  |  |     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
 | 
					
						
							| 
									
										
										
										
											2017-08-31 20:16:38 +00:00
										 |  |  | ! ndepth=2: subtraction, 3 passes, belief propagation only
 | 
					
						
							|  |  |  | ! ndepth=3: subtraction, 3 passes, bp+osd
 | 
					
						
							| 
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 |  |  |     if(ndepth.eq.1) npass=1
 | 
					
						
							| 
									
										
										
										
											2017-08-22 00:14:51 +00:00
										 |  |  |     if(ndepth.ge.2) npass=3
 | 
					
						
							| 
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 |  |  |     do ipass=1,npass
 | 
					
						
							|  |  |  |       newdat=.true.  ! Is this a problem? I hijacked newdat.
 | 
					
						
							| 
									
										
										
										
											2017-08-22 00:14:51 +00:00
										 |  |  |       syncmin=1.5
 | 
					
						
							| 
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 |  |  |       if(ipass.eq.1) then
 | 
					
						
							|  |  |  |         lsubtract=.true.
 | 
					
						
							|  |  |  |         if(ndepth.eq.1) lsubtract=.false.
 | 
					
						
							| 
									
										
										
										
											2017-08-22 00:14:51 +00:00
										 |  |  |       elseif(ipass.eq.2) then
 | 
					
						
							|  |  |  |         n2=ndecodes
 | 
					
						
							|  |  |  |         if(ndecodes.eq.0) cycle
 | 
					
						
							|  |  |  |         lsubtract=.true.
 | 
					
						
							|  |  |  |       elseif(ipass.eq.3) then
 | 
					
						
							|  |  |  |         if((ndecodes-n2).eq.0) cycle
 | 
					
						
							|  |  |  |         lsubtract=.false. 
 | 
					
						
							| 
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 |  |  |       endif 
 | 
					
						
							|  |  |  |       call timer('sync8   ',0)
 | 
					
						
							| 
									
										
										
										
											2018-08-08 16:05:21 +00:00
										 |  |  |       maxc=MAXCAND
 | 
					
						
							| 
									
										
										
										
											2018-11-05 14:40:55 -06:00
										 |  |  |       call sync8(dd,ifa,ifb,syncmin,nfqso,maxc,s,candidate,   &
 | 
					
						
							| 
									
										
										
										
											2018-11-05 11:59:48 -05:00
										 |  |  |            ncand,sbase)
 | 
					
						
							| 
									
										
										
										
											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)
 | 
					
						
							| 
									
										
										
										
											2017-08-26 16:30:47 +00:00
										 |  |  |         xbase=10.0**(0.1*(sbase(nint(f1/3.125))-40.0))
 | 
					
						
							| 
									
										
										
										
											2017-07-12 21:49:39 +00:00
										 |  |  |         nsnr0=min(99,nint(10.0*log10(sync) - 25.5))    !### empirical ###
 | 
					
						
							|  |  |  |         call timer('ft8b    ',0)
 | 
					
						
							| 
									
										
										
										
											2018-11-05 11:59:48 -05:00
										 |  |  |         call ft8b(dd,newdat,nQSOProgress,nfqso,nftx,ndepth,lft8apon,      &
 | 
					
						
							|  |  |  |              lapcqonly,napwid,lsubtract,nagain,ncontest,iaptype,mycall12,   &
 | 
					
						
							|  |  |  |              hiscall12,sync,f1,xdt,xbase,apsym2,nharderrors,dmin,           &
 | 
					
						
							|  |  |  |              nbadcrc,iappass,iera,msg37,xsnr)
 | 
					
						
							|  |  |  |         call timer('ft8b    ',1)
 | 
					
						
							| 
									
										
										
										
											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
 | 
					
						
							|  |  |  |         if(nbadcrc.eq.0) then
 | 
					
						
							| 
									
										
										
										
											2017-08-09 15:22:54 +00:00
										 |  |  |            ldupe=.false.
 | 
					
						
							|  |  |  |            do id=1,ndecodes
 | 
					
						
							| 
									
										
										
										
											2018-07-04 16:20:12 -05:00
										 |  |  |               if(msg37.eq.allmessages(id).and.nsnr.le.allsnrs(id)) ldupe=.true.
 | 
					
						
							| 
									
										
										
										
											2017-08-09 15:22:54 +00:00
										 |  |  |            enddo
 | 
					
						
							|  |  |  |            if(.not.ldupe) then
 | 
					
						
							|  |  |  |               ndecodes=ndecodes+1
 | 
					
						
							| 
									
										
										
										
											2018-07-04 16:20:12 -05:00
										 |  |  |               allmessages(ndecodes)=msg37
 | 
					
						
							| 
									
										
										
										
											2017-08-09 15:22:54 +00:00
										 |  |  |               allsnrs(ndecodes)=nsnr
 | 
					
						
							|  |  |  |            endif
 | 
					
						
							| 
									
										
										
										
											2018-10-17 19:17:04 -05:00
										 |  |  | !           write(81,1004) nutc,ncand,icand,ipass,iaptype,iappass,        &
 | 
					
						
							|  |  |  | !                nharderrors,dmin,hd,min(sync,999.0),nint(xsnr),          &
 | 
					
						
							| 
									
										
										
										
											2018-11-05 11:59:48 -05:00
										 |  |  | !                xdt,nint(f1),msg37
 | 
					
						
							|  |  |  | !1004          format(i6.6,2i4,3i2,i3,3f6.1,i4,f6.2,i5,2x,a37)
 | 
					
						
							| 
									
										
										
										
											2018-10-17 19:17:04 -05:00
										 |  |  | !           flush(81)
 | 
					
						
							| 
									
										
										
										
											2017-08-09 15:22:54 +00:00
										 |  |  |            if(.not.ldupe .and. associated(this%callback)) then
 | 
					
						
							|  |  |  |               qual=1.0-(nharderrors+dmin)/60.0 ! scale qual to [0.0,1.0]
 | 
					
						
							| 
									
										
										
										
											2017-12-19 20:01:06 +00:00
										 |  |  |               call this%callback(sync,nsnr,xdt,f1,msg37,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
 | 
					
						
							|  |  |  |   enddo
 | 
					
						
							|  |  |  |   return
 | 
					
						
							| 
									
										
										
										
											2017-07-08 14:06:48 +00:00
										 |  |  |   end subroutine decode
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | end module ft8_decode
 |