From 57b6b2dca146cad94dfe1b926bb6f1eb4e86759c Mon Sep 17 00:00:00 2001
From: Joe Taylor <joe@princeton.edu>
Date: Fri, 8 Jan 2021 09:42:07 -0500
Subject: [PATCH] Set the "b90" search range once (in q65_decocd.f90) and share
 valies through q65.mod.

---
 lib/q65_decode.f90        | 12 ++++++++++--
 lib/qra/q65/q65.f90       |  2 +-
 lib/qra/q65/q65_avg.f90   |  4 +---
 lib/qra/q65/q65_loops.f90 | 12 ++++--------
 lib/qra/q65/q65_sync.f90  |  5 ++---
 5 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/lib/q65_decode.f90 b/lib/q65_decode.f90
index 896a52ac7..f1fb0364d 100644
--- a/lib/q65_decode.f90
+++ b/lib/q65_decode.f90
@@ -85,10 +85,18 @@ contains
     else
        stop 'Invalid TR period'
     endif
+
     baud=12000.0/nsps
     df1=12000.0/nfft1
     this%callback => callback
     nFadingModel=1
+    ibwa=max(1,int(1.8*log(baud*mode65)) + 2)
+    ibwb=min(10,ibwa+4)
+    if(iand(ndepth,3).eq.3) then
+       ibwa=max(1,ibwa-1)
+       ibwb=min(10,ibwb+1)
+    endif
+    
 ! Set up the codewords for full-AP list decoding    
     call q65_set_list(mycall,hiscall,hisgrid,codewords,ncw) 
     dgen=0
@@ -103,7 +111,7 @@ contains
        f1=f0
        go to 100
     endif
-    
+
     if(snr1.lt.2.8) then
        xdt1=0.                   !No reliable sync, abandon decoding attempt
        f1=0.
@@ -161,7 +169,7 @@ contains
     if(iand(ndepth,16).eq.16) then
 ! Try for an average decode.
        call q65_avg2(ntrperiod,ntol,baud,nsubmode,nQSOprogress,lapcqonly, &
-            ibwa,ibwb,codewords,ncw,xdt,f0,snr1,snr2,dat4,idec)
+            codewords,ncw,xdt,f0,snr1,snr2,dat4,idec)
     endif
     
 100 decoded='                                     '
diff --git a/lib/qra/q65/q65.f90 b/lib/qra/q65/q65.f90
index d56ae6f4c..056608ba8 100644
--- a/lib/qra/q65/q65.f90
+++ b/lib/qra/q65/q65.f90
@@ -8,7 +8,7 @@ module q65
   integer listutc(10)
   integer apsym0(58),aph10(10)
   integer apmask(13),apsymbols(13)
-  integer navg
+  integer navg,ibwa,ibwb
   real    f0save(MAXAVE)
   real    xdtsave(MAXAVE)
   real    snr1save(MAXAVE)
diff --git a/lib/qra/q65/q65_avg.f90 b/lib/qra/q65/q65_avg.f90
index d6dd07de2..c3e1d386f 100644
--- a/lib/qra/q65/q65_avg.f90
+++ b/lib/qra/q65/q65_avg.f90
@@ -71,12 +71,10 @@ subroutine q65_avg(nutc,ntrperiod,LL,nfqso,ntol,lclearave,xdt,f0,snr1,s3)
 10 return
 
   entry q65_avg2(ntrperiod,ntol,baud,nsubmode,nQSOprogress,lapcqonly, &
-       ibwa,ibwb,codewords,ncw,xdt,f0,snr1,snr2,dat4,idec)
+       codewords,ncw,xdt,f0,snr1,snr2,dat4,idec)
 
   mode_q65=2**nsubmode
   f0diff=baud*mode_q65
-  ibwa=1.8*log(baud*mode_q65) + 2
-  ibwb=min(10,ibwa+4)
   snr1sum=0.
   xdtsum=0.
   fsum=0.
diff --git a/lib/qra/q65/q65_loops.f90 b/lib/qra/q65/q65_loops.f90
index ce476c0fb..22dbd5196 100644
--- a/lib/qra/q65/q65_loops.f90
+++ b/lib/qra/q65/q65_loops.f90
@@ -3,6 +3,8 @@ subroutine q65_loops(c00,npts2,nsps,mode_q65,nsubmode,ndepth,jpk0,    &
 
   use packjt77
   use timer_module, only: timer
+  use q65
+  
   parameter (NN=63)
   parameter (LN=1152*63)           !LN=LL*NN; LL=64*(mode_q65+2), NN=63
   complex c00(0:npts2-1)           !Analytic representation of dd(), 6000 Hz
@@ -28,8 +30,6 @@ subroutine q65_loops(c00,npts2,nsps,mode_q65,nsubmode,ndepth,jpk0,    &
 
   idfmax=3
   idtmax=3
-  ibwa=max(1,int(1.8*log(baud*mode_q65)) + 2)
-  ibwb=min(10,ibwa+4)
   ibw0=(ibwa+ibwb)/2
   maxdist=5
   if(iand(ndepth,3).ge.2) then
@@ -37,12 +37,8 @@ subroutine q65_loops(c00,npts2,nsps,mode_q65,nsubmode,ndepth,jpk0,    &
      idtmax=5
      maxdist=10
   endif
-  if(iand(ndepth,3).eq.3) then
-     maxdist=15
-     ibwa=max(1,ibwa-1)
-     ibwb=min(10,ibwb+1)
-  endif
-  
+  if(iand(ndepth,3).eq.3) maxdist=15
+
   LL=64*(mode_q65+2)
   napmin=99
   xdt1=xdt0
diff --git a/lib/qra/q65/q65_sync.f90 b/lib/qra/q65/q65_sync.f90
index f83fa4806..ed85b03ef 100644
--- a/lib/qra/q65/q65_sync.f90
+++ b/lib/qra/q65/q65_sync.f90
@@ -15,9 +15,10 @@ subroutine q65_sync(nutc,iwave,ntrperiod,mode_q65,codewords,ncw,nsps,   &
 
   use packjt77
   use timer_module, only: timer
+  use q65
+
   parameter (NSTEP=8)                    !Step size nsps/NSTEP
   parameter (LN=2176*63)           !LN=LL*NN; LL=64*(mode_q65+2), NN=63
-  parameter (PLOG_MIN=-240.0)            !List decoding threshold
   integer*2 iwave(0:12000*ntrperiod-1)   !Raw data
   integer isync(22)                      !Indices of sync symbols
   integer itone(85)
@@ -183,8 +184,6 @@ subroutine q65_sync(nutc,iwave,ntrperiod,mode_q65,codewords,ncw,nsps,   &
   if(mode_q65.eq.16) nsubmode=4
   nFadingModel=1
   baud=12000.0/nsps
-  ibwa=1.8*log(baud*mode_q65) + 2
-  ibwb=min(10,ibwa+4)
 
   do ibw=ibwa,ibwb
      b90=1.72**ibw