From b84742b1fc3ac31ee2c3bc99152647619de20080 Mon Sep 17 00:00:00 2001
From: Joe Taylor <joe@princeton.edu>
Date: Mon, 22 Jan 2024 11:11:53 -0500
Subject: [PATCH] "Export .wav files" now working as intended in QMAP.

---
 qmap/libqmap/q65b.f90  |  6 +-----
 qmap/libqmap/qmapa.f90 | 17 ++++++++++++-----
 qmap/mainwindow.cpp    |  1 -
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/qmap/libqmap/q65b.f90 b/qmap/libqmap/q65b.f90
index 163df32ca..fff07e8fb 100644
--- a/qmap/libqmap/q65b.f90
+++ b/qmap/libqmap/q65b.f90
@@ -44,10 +44,7 @@ subroutine q65b(nutc,nqd,fcenter,nfcal,nfsample,ikhz,mousedf,ntol,          &
 ! Find best frequency from sync_dat, the "orange sync curve".
   df3=96000.0/32768.0
   ipk=(1000.0*f0-1.0)/df3
-  if(nagain.ge.2) then
-     f_mouse=1000.0*(fqso+ikhz-48.0) + mousedf - 1270.0
-     ipk = nint(f_mouse/df3)
-  endif
+  if(nagain.ge.2) ipk = nint(1000.0*(fqso-nkhz_center+48.0)/df3)
   nfft1=MAXFFT1
   nfft2=MAXFFT2
   df=96000.0/NFFT1
@@ -55,7 +52,6 @@ subroutine q65b(nutc,nqd,fcenter,nfcal,nfsample,ikhz,mousedf,ntol,          &
   k0=nint((ipk*df3-1000.0)/df)
   if(k0.lt.nh .or. k0.gt.MAXFFT1-nfft2+1) go to 900
   fac=1.0/nfft2
-  if(nagain.ge.2) print*,nagain,k0,k0*df
   cx(0:nfft2-1)=fac*ca(k0:k0+nfft2-1)
 
 ! Here cx is frequency-domain data around the selected
diff --git a/qmap/libqmap/qmapa.f90 b/qmap/libqmap/qmapa.f90
index dfb675c3c..6869cf8a5 100644
--- a/qmap/libqmap/qmapa.f90
+++ b/qmap/libqmap/qmapa.f90
@@ -48,11 +48,13 @@ subroutine qmapa(dd,ss,savg,newdat,nutc,fcenter,ntol,nfa,nfb,         &
   nts_q65=2**(mode_q65-1)             !Q65 tone separation factor
   f0_selected=fselected - nkhz_center + 48.0
 
-  call timer('get_cand',0)
-! Get a list of decoding candidates
-  call getcand2(ss,savg,nts_q65,nagain,nhsym,ntx30a,ntx30b,ntol,     &
-       f0_selected,bAlso30,cand,ncand)
-  call timer('get_cand',1)
+  if(nagain.le.1) then
+     call timer('get_cand',0)
+     ! Get a list of decoding candidates
+     call getcand2(ss,savg,nts_q65,nagain,nhsym,ntx30a,ntx30b,ntol,     &
+          f0_selected,bAlso30,cand,ncand)
+     call timer('get_cand',1)
+  endif
 
   nwrite_q65=0
   df=96000.0/NFFT                     !df = 96000/NFFT = 2.930 Hz
@@ -66,6 +68,11 @@ subroutine qmapa(dd,ss,savg,newdat,nutc,fcenter,ntol,nfa,nfb,         &
   call fftbig(dd,NSMAX) !Do the full-length FFT
   call timer('fftbig  ',1)
 
+  if(nagain.ge.2) then
+     ncand=1
+     fqso=fselected
+  endif
+
   do icand=1,ncand                        !Attempt to decode each candidate
      tsec=sec_midn() - tsec0
      if(ndiskdat.eq.0) then
diff --git a/qmap/mainwindow.cpp b/qmap/mainwindow.cpp
index 9a527498d..81e9d4247 100644
--- a/qmap/mainwindow.cpp
+++ b/qmap/mainwindow.cpp
@@ -951,7 +951,6 @@ void MainWindow::decode()                                       //decode()
   memcpy(savecom_.saveFileName, m_saveFileName.toLatin1(),len1);
 
   ui->actionExport_wav_file_at_fQSO->setEnabled(m_diskData);
-  qDebug() << "aa" << datcom2_.nagain;
   watcher3.setFuture(QtConcurrent::run (q65c_));
   decodeBusy(true);
 }