summaryrefslogtreecommitdiff
path: root/map65
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2026-09-26 23:24:03 +0200
committerChristoph Berg <myon@debian.org>2026-09-26 23:24:03 +0200
commit059831534c7e884f0a607ed86b582fd00d821731 (patch)
tree76bcb67a78f8aa2654fd34c2ad801a62136b0170 /map65
parentd83a420f0517d7fc47aeb288a6a0cf4891784fcc (diff)
New upstream version 3.2.0~rc1+dfsgupstream/3.2.0_rc1+dfsg
Diffstat (limited to 'map65')
-rw-r--r--map65/CMakeLists.txt19
-rw-r--r--map65/about.cpp15
-rw-r--r--map65/about.qrc6
-rw-r--r--map65/about.ui22
-rw-r--r--map65/about_icon.pngbin0 -> 19853 bytes
-rw-r--r--map65/commons.cpp3
-rw-r--r--map65/commons.h20
-rw-r--r--map65/devsetup.cpp94
-rw-r--r--map65/devsetup.h10
-rw-r--r--map65/devsetup.ui277
-rw-r--r--map65/globals.h1
-rw-r--r--map65/half_symbol_scheduler.h36
-rw-r--r--map65/libm65/CMakeLists.txt145
-rw-r--r--map65/libm65/afc65b.f90190
-rw-r--r--map65/libm65/astro.f9078
-rw-r--r--map65/libm65/astro0.f9034
-rw-r--r--map65/libm65/ccf65.f90123
-rw-r--r--map65/libm65/cgen65.f904
-rw-r--r--map65/libm65/datcom_ptrs_mod.f9041
-rw-r--r--map65/libm65/debug_log.f904
-rw-r--r--map65/libm65/decode0.f90143
-rw-r--r--map65/libm65/decode1a.f9085
-rw-r--r--map65/libm65/decode65b.f9023
-rw-r--r--map65/libm65/decode_request_mutex.cpp15
-rw-r--r--map65/libm65/decodes_mod.f9050
-rw-r--r--map65/libm65/deep65.f90300
-rw-r--r--map65/libm65/display.f9043
-rw-r--r--map65/libm65/extract.f9023
-rw-r--r--map65/libm65/fchisq.f9076
-rw-r--r--map65/libm65/filbig.f90126
-rw-r--r--map65/libm65/four2a.f903
-rw-r--r--map65/libm65/four2a_legacy_wrap.f9051
-rw-r--r--map65/libm65/ftnquit.f904
-rw-r--r--map65/libm65/ftrsd2.c19
-rw-r--r--map65/libm65/ftrsd2_mod.f906
-rw-r--r--map65/libm65/gen65.f902
-rw-r--r--map65/libm65/gen_q65_cwave.f9032
-rw-r--r--map65/libm65/gen_q65_wave.f9016
-rw-r--r--map65/libm65/getdphi.f908
-rw-r--r--map65/libm65/getpfx1.f901
-rw-r--r--map65/libm65/indexx.f9025
-rw-r--r--map65/libm65/init_rs.c2
-rw-r--r--map65/libm65/m65_mod.f9047
-rw-r--r--map65/libm65/m65a.f904
-rw-r--r--map65/libm65/map65_polarization_score.f9074
-rw-r--r--map65/libm65/map65a.f90854
-rw-r--r--map65/libm65/mapsim.f90122
-rw-r--r--map65/libm65/nchar.f901
-rw-r--r--map65/libm65/npar_ptrs_mod.f90515
-rw-r--r--map65/libm65/packjt.f9037
-rw-r--r--map65/libm65/ptt.c4
-rw-r--r--map65/libm65/ptt_unix.c17
-rw-r--r--map65/libm65/q65b.F90262
-rw-r--r--map65/libm65/recvpkt.f9074
-rw-r--r--map65/libm65/run_m65.f9072
-rw-r--r--map65/libm65/s3avg.f9031
-rw-r--r--map65/libm65/stdout_channel_mod.f9022
-rw-r--r--map65/libm65/stdout_shared_layout.h5
-rw-r--r--map65/libm65/stdout_shared_memory.cpp2
-rw-r--r--map65/libm65/symspec.f9069
-rw-r--r--map65/libm65/test_astro_pipeline.f9032
-rw-r--r--map65/libm65/tmoonsub.c6
-rw-r--r--map65/libm65/trimlist.f9070
-rw-r--r--map65/libm65/wideband_sync.f90325
-rw-r--r--map65/main.cpp60
-rw-r--r--map65/mainwindow.cpp489
-rw-r--r--map65/mainwindow.h23
-rw-r--r--map65/mainwindow.ui27
-rw-r--r--map65/map65.pro73
-rw-r--r--map65/map65_decode_display_filter.cpp95
-rw-r--r--map65/map65_decode_display_filter.h40
-rw-r--r--map65/map65_decode_lifecycle.txt453
-rw-r--r--map65/messages.cpp260
-rw-r--r--map65/messages.h13
-rw-r--r--map65/plotter.cpp112
-rw-r--r--map65/plotter.h9
-rw-r--r--map65/pskreporter_decode.cpp120
-rw-r--r--map65/pskreporter_decode.h23
-rw-r--r--map65/pskreporter_settings.cpp11
-rw-r--r--map65/pskreporter_settings.h14
-rw-r--r--map65/runtime_paths.cpp132
-rw-r--r--map65/runtime_paths.h24
-rw-r--r--map65/soundin.cpp74
-rw-r--r--map65/soundin.h5
-rw-r--r--map65/soundout.cpp62
-rw-r--r--map65/widegraph.cpp122
-rw-r--r--map65/widegraph.h7
-rw-r--r--map65/widegraph.ui28
-rw-r--r--map65/wsjt.icobin1078 -> 104774 bytes
89 files changed, 4775 insertions, 2321 deletions
diff --git a/map65/CMakeLists.txt b/map65/CMakeLists.txt
index 9d1b45bb..00de39fd 100644
--- a/map65/CMakeLists.txt
+++ b/map65/CMakeLists.txt
@@ -13,14 +13,19 @@ set (map65_CXXSRCS
getdev.cpp
# getfile.cpp
liveCQSender.cpp
+# map65_paths.cpp
main.cpp
mainwindow.cpp
+ map65_decode_display_filter.cpp
messages.cpp
meterwidget.cpp
plotter.cpp
+ pskreporter_decode.cpp
+ pskreporter_settings.cpp
+ Radio.cpp
+ runtime_paths.cpp
../Network/PSKReporter.cpp
../Network/PSKReporterIPFIX.cpp
- Radio.cpp
set570.cpp
signalmeter.cpp
soundin.cpp
@@ -53,12 +58,19 @@ add_subdirectory (libm65)
# UI generation
qt5_wrap_ui (map65_GENUISRCS ${map65_UISRCS})
+# windres doesn't track a .rc file's ICON directive as a dependency, so an icon-only edit needs this to trigger a rebuild.
+set_property (SOURCE map65.rc APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/wsjt.ico)
+
+# Resource generation (About dialog logo + GPL logo)
+qt5_add_resources (map65_RESOURCES_RCC about.qrc)
+
# Executable: only the .rc file is Windows-only
if (WIN32)
add_executable(map65
${map65_CXXSRCS}
${map65_CSRCS}
${map65_GENUISRCS}
+ ${map65_RESOURCES_RCC}
map65.rc
)
else()
@@ -66,6 +78,7 @@ else()
${map65_CXXSRCS}
${map65_CSRCS}
${map65_GENUISRCS}
+ ${map65_RESOURCES_RCC}
)
endif()
@@ -88,6 +101,10 @@ target_link_libraries(map65 PRIVATE
Usb::Usb
)
+if (APPLE)
+ target_link_libraries(map65 PRIVATE m65_qt)
+endif ()
+
# Linux needs libusb
# if (UNIX AND NOT APPLE)
# find_package(PkgConfig REQUIRED)
diff --git a/map65/about.cpp b/map65/about.cpp
index 1d92e0c3..6a1dde07 100644
--- a/map65/about.cpp
+++ b/map65/about.cpp
@@ -7,14 +7,21 @@ CAboutDlg::CAboutDlg(QWidget *parent) :
ui(new Ui::CAboutDlg)
{
ui->setupUi(this);
- ui->labelTxt->setText("<html><h2>" + QString {"MAP65 v"
+ ui->labelTxt->setText("<html><h2>" + QString {"MAP65™ v"
+ QCoreApplication::applicationVersion ()
+ " " + revision ()}.simplified () + "</h2><br />"
- "MAP65 implements a wideband polarization-matching receiver <br />"
+ "MAP65™ implements a wideband polarization-matching receiver <br />"
"for the JT65 and Q65 protocols, with a matching transmitting <br />"
"facility. It is primarily intended for amateur radio EME communication. <br /><br />"
- "Copyright 2001-2026 by Joe Taylor, K1JT, and the WSJT <br/>"
- "Develolpment Group.");
+ "Copyright 2001-2026 by Joe Taylor, K1JT, and the WSJT™ <br/>"
+ "Development Team.<br /><br />"
+ "MAP65 is licensed under the terms of Version 3 <br />"
+ "of the GNU General Public License (GPL) <br /><br />"
+ "<a href=" TO_STRING__ (PROJECT_HOMEPAGE) ">"
+ "<img src=\":/icon_128x128.png\" /></a>"
+ "<a href=\"https://www.gnu.org/licenses/gpl-3.0.txt\">"
+ "<img src=\":/gpl-v3-logo.svg\" height=\"80\" /><br />"
+ "https://www.gnu.org/licenses/gpl-3.0.txt</a>");
}
CAboutDlg::~CAboutDlg()
diff --git a/map65/about.qrc b/map65/about.qrc
new file mode 100644
index 00000000..9520adbc
--- /dev/null
+++ b/map65/about.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/">
+ <file alias="icon_128x128.png">about_icon.png</file>
+ <file alias="gpl-v3-logo.svg">../contrib/gpl-v3-logo.svg</file>
+ </qresource>
+</RCC>
diff --git a/map65/about.ui b/map65/about.ui
index fb20f48d..8141882d 100644
--- a/map65/about.ui
+++ b/map65/about.ui
@@ -5,22 +5,8 @@
<property name="windowModality">
<enum>Qt::NonModal</enum>
</property>
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>374</width>
- <height>164</height>
- </rect>
- </property>
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
<property name="windowTitle">
- <string>About MAP65</string>
+ <string>About MAP65™</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@@ -28,6 +14,12 @@
<property name="text">
<string/>
</property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
</widget>
</item>
</layout>
diff --git a/map65/about_icon.png b/map65/about_icon.png
new file mode 100644
index 00000000..68198d68
--- /dev/null
+++ b/map65/about_icon.png
Binary files differ
diff --git a/map65/commons.cpp b/map65/commons.cpp
index bbef8ed0..74c69b74 100644
--- a/map65/commons.cpp
+++ b/map65/commons.cpp
@@ -4,5 +4,8 @@ extern "C" {
float* dd = nullptr;
float* ss = nullptr;
float* savg = nullptr;
+ float* dd_old = nullptr;
+ float* ss_old = nullptr;
+ float* savg_old = nullptr;
}
diff --git a/map65/commons.h b/map65/commons.h
index d717f82c..888e922b 100644
--- a/map65/commons.h
+++ b/map65/commons.h
@@ -2,8 +2,12 @@
#define COMMONS_H
#define NFFT 32768
+#define BASELINE_RATE 96000
+#define BASELINE_NFFT 32768
+
#include <QString>
+#include <cstdint>
// This header defines the C++ interface to the Fortran datcom_ptrs_mod module.
// It replaces the legacy common block interface with explicit setter/getter functions.
@@ -53,12 +57,17 @@ extern struct { //This is "common/datcom/..." in Fortran
extern float* dd;
extern float* ss;
extern float* savg;
+ extern float* dd_old;
+ extern float* ss_old;
+ extern float* savg_old;
+ extern int manualDecodeFlag ;
double get_fcenter();
void get_mycall(char*);
void get_hiscall(char*);
void get_mygrid(char*);
void get_hisgrid(char*);
void get_datetime(char*);
+ int get_manual_decode_flag();
int get_nutc();
int get_ndop00();
int get_nkeep();
@@ -91,6 +100,9 @@ extern struct { //This is "common/datcom/..." in Fortran
void set_dd_ptr(void* ptr, int dim1, int dim2);
void set_ss_ptr(void* ptr, int dim1, int dim2, int dim3);
void set_savg_ptr(void* ptr, int dim1, int dim2);
+ void set_dd_old_ptr(void* ptr, int dim1, int dim2);
+ void set_ss_old_ptr(void* ptr, int dim1, int dim2, int dim3);
+ void set_savg_old_ptr(void* ptr, int dim1, int dim2);
void set_fcenter(double);
void set_map65RxLog(int);
void set_nutc(int);
@@ -130,11 +142,17 @@ extern struct { //This is "common/datcom/..." in Fortran
void run_m65_(int* pol, int* sample_rate);
void set_stop_m65(int val);
void set_decoder_ready(int val);
+ std::int64_t publish_decode_request();
+ void cancel_pending_decode_requests();
+ void advance_live_input_generation();
+ bool is_current_decode_request(std::int64_t request_id);
void set_wsjtx_dir_(const char* path, int path_len);
void set_stdout_channel(void* buf_ptr,
void* hdr_ptr,
int buf_size,
intptr_t event_handle);
+ void set_manual_decode_flag(int);
+ void snapshot_buffers();
}
extern QStringList allDecodes;
@@ -143,8 +161,6 @@ extern QString guiDate;
extern bool m_w3szUrl;
extern QString m_otherUrl;
-extern bool m_spot_to_psk_reporter;
-extern bool m_psk_reporter_tcpip;
// Scalar getters
inline int getNutc() { return get_nutc(); }
diff --git a/map65/devsetup.cpp b/map65/devsetup.cpp
index 2b1e9e8f..4fae12ea 100644
--- a/map65/devsetup.cpp
+++ b/map65/devsetup.cpp
@@ -9,6 +9,9 @@
#include <QStringList>
#include <QSerialPortInfo>
#include <QRegularExpression>
+#include <QSignalBlocker>
+#include <QSettings>
+#include "SettingsGroup.hpp"
#if !defined(Q_OS_WIN)
extern "C" {
@@ -54,8 +57,17 @@ DevSetup::DevSetup(MainWindow *parent)
mw(parent)
{
ui.setupUi(this); //setup the dialog form
+
+ {
+ QSettings settings(mw->m_settings_filename, QSettings::IniFormat);
+ SettingsGroup g {&settings, "DevSetup"};
+ restoreGeometry(settings.value("geometry").toByteArray());
+ }
+
m_restartSoundIn=false;
m_restartSoundOut=false;
+ m_restartRequired=false;
+ m_pendingFs96000=-1;
QButtonGroup *buttonGroup = new QButtonGroup(this);
buttonGroup->addButton(ui.w3szBut);
@@ -74,6 +86,18 @@ DevSetup::~DevSetup()
{
}
+void DevSetup::done(int r)
+{
+ // accept()/reject() (OK, Cancel, and the title-bar close button, which
+ // triggers reject() internally) all funnel through here -- unlike
+ // closeEvent(), which only fires for the title-bar close button, not
+ // for accept()/reject() called directly from button clicks.
+ QSettings settings(mw->m_settings_filename, QSettings::IniFormat);
+ SettingsGroup g {&settings, "DevSetup"};
+ settings.setValue("geometry", saveGeometry());
+ QDialog::done(r);
+}
+
void DevSetup::initDlg()
{
int k,id;
@@ -105,9 +129,10 @@ getDev(&numDevices,
k = 0;
for (id = 0; id < numDevices; id++) {
- if (!(96000 >= minSpeed[id] && 96000 <= maxSpeed[id]))
+ if (!(g_sampleRate >= minSpeed[id] && g_sampleRate <= maxSpeed[id]))
continue;
+
#ifdef _WIN32
if (!QString(hostAPI_DeviceName[id].name).contains("MME"))
continue;
@@ -201,6 +226,14 @@ for (id = 0; id < numDevices; id++) {
ptt_set_override(nullptr);
#endif
+ if (mw->m_fs96000 == 2)
+ oldSampleRate = 192000;
+ else if (mw->m_fs96000 == 1)
+ oldSampleRate = 96000;
+ else if (mw->m_fs96000 == 0)
+ oldSampleRate = 95238;
+ else oldSampleRate = 96000;
+
ui.astroFont->setValue(mw->m_astroFont);
ui.cbXpol->setChecked(mw->m_xpol);
ui.rbAntennaX->setChecked(mw->m_xpolx);
@@ -212,10 +245,16 @@ for (id = 0; id < numDevices; id++) {
ui.dPhiSpinBox->setValue(mw->m_dPhi);
ui.fCalSpinBox->setValue(mw->m_fCal);
ui.faddEntry->setText(QString::number(mw->m_fAdd,'f',3));
- ui.networkRadioButton->setChecked(mw->m_network);
- ui.soundCardRadioButton->setChecked(!mw->m_network);
- ui.rb96000->setChecked(mw->m_fs96000);
- ui.rb95238->setChecked(!mw->m_fs96000);
+ {
+ QSignalBlocker blockNetwork {ui.networkRadioButton};
+ QSignalBlocker blockSoundCard {ui.soundCardRadioButton};
+ ui.networkRadioButton->setChecked(mw->m_network);
+ ui.soundCardRadioButton->setChecked(!mw->m_network);
+ }
+ ui.rb192000->setChecked(mw->m_fs96000 == 2);
+ ui.rb96000->setChecked(mw->m_fs96000 == 1);
+ ui.rb95238->setChecked(mw->m_fs96000 == 0);
+ on_soundCardRadioButton_toggled(ui.soundCardRadioButton->isChecked());
ui.rbIQXT->setChecked(mw->m_bIQxt);
ui.rbSi570->setChecked(!mw->m_bIQxt);
ui.mult570TxSpinBox->setEnabled(mw->m_bIQxt);
@@ -267,10 +306,26 @@ void DevSetup::accept()
// Check to see whether SoundInThread must be restarted,
// and save user parameters.
+ int newSampleRate = ui.rb192000->isChecked() ? 192000 :
+ ui.rb96000->isChecked() ? 96000 :
+ 95238;
+ int newFs96000 = ui.rb192000->isChecked() ? 2 :
+ ui.rb96000->isChecked() ? 1 :
+ 0;
+ double const newFAdd = ui.faddEntry->text().toDouble();
+
+ m_restartRequired = oldSampleRate != newSampleRate;
+ if (m_restartRequired) {
+ m_pendingFs96000 = newFs96000;
+ } else {
+ emit sampleRateChanged(newSampleRate);
+ }
+
if(mw->m_network!=ui.networkRadioButton->isChecked() or
mw->m_nDevIn!=ui.comboBoxSndIn->currentIndex() or
mw->m_paInDevice!=m_inDevList[mw->m_nDevIn] or
mw->m_xpol!=ui.cbXpol->isChecked() or
+ mw->m_fAdd!=newFAdd or
mw->m_udpPort!=ui.sbPort->value()) m_restartSoundIn=true;
if(mw->m_nDevOut!=ui.comboBoxSndOut->currentIndex() or
@@ -303,9 +358,11 @@ void DevSetup::accept()
mw->m_timeout=ui.timeoutSpinBox->value();
mw->m_dPhi=ui.dPhiSpinBox->value();
mw->m_fCal=ui.fCalSpinBox->value();
- mw->m_fAdd=ui.faddEntry->text().toDouble();
+ mw->m_fAdd=newFAdd;
mw->m_network=ui.networkRadioButton->isChecked();
- mw->m_fs96000=ui.rb96000->isChecked();
+ if (!m_restartRequired) {
+ mw->m_fs96000 = newFs96000;
+ }
mw->m_bIQxt=ui.rbIQXT->isChecked();
mw->m_nDevIn=ui.comboBoxSndIn->currentIndex();
mw->m_paInDevice=m_inDevList[mw->m_nDevIn];
@@ -325,13 +382,34 @@ void DevSetup::accept()
mw->m_spot_to_psk_reporter = ui.pskBox->isChecked();
mw->m_psk_reporter_tcpip = ui.pskReporterTcpIpBox->isChecked();
+ if (m_restartRequired) {
+ QMessageBox::information(this,
+ "Restart Required",
+ "Changing sample rate requires MAP65 to be restarted.\n"
+ "Please exit MAP65 and start it again.");
+ }
+
+ // Normal path
QDialog::accept();
+
}
void DevSetup::on_soundCardRadioButton_toggled(bool checked)
{
ui.comboBoxSndIn->setEnabled(ui.soundCardRadioButton->isChecked());
- ui.rb96000->setChecked(checked);
+ int fs96000 = ui.rb192000->isChecked() ? 2 :
+ ui.rb95238->isChecked() ? 0 :
+ 1;
+ if(checked) {
+ if(fs96000 == 0) fs96000 = 1;
+ ui.rb95238->setEnabled(false);
+ }
+ else {
+ ui.rb95238->setEnabled(true);
+ }
+ ui.rb192000->setChecked(fs96000 == 2);
+ ui.rb96000->setChecked(fs96000 == 1);
+ ui.rb95238->setChecked(fs96000 == 0);
ui.rb95238->setEnabled(!checked);
ui.label_InputDev->setEnabled(checked);
ui.label_Port->setEnabled(!checked);
diff --git a/map65/devsetup.h b/map65/devsetup.h
index 9ae4bad9..64acd572 100644
--- a/map65/devsetup.h
+++ b/map65/devsetup.h
@@ -16,13 +16,20 @@ public:
~DevSetup();
void initDlg();
+
qint32 m_inDevList[1024];
qint32 m_outDevList[1024];
bool m_restartSoundIn;
bool m_restartSoundOut;
+ bool m_restartRequired;
+ int m_pendingFs96000;
+
+signals:
+ void sampleRateChanged(int newRate);
public slots:
- void accept();
+ void accept() override;
+ void done(int r) override;
void onButtonClicked();
private slots:
@@ -56,6 +63,7 @@ private:
MainWindow *mw;
int r,g,b,r0,g0,b0,r1,g1,b1,r2,g2,b2,r3,g3,b3;
Ui::DialogSndCard ui;
+ int oldSampleRate;
};
#endif // DEVSETUP_H
diff --git a/map65/devsetup.ui b/map65/devsetup.ui
index e9d2746c..fa87164a 100644
--- a/map65/devsetup.ui
+++ b/map65/devsetup.ui
@@ -324,17 +324,11 @@
<item>
<widget class="QGroupBox" name="antennaGroupBox">
<property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Maximum">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>55</height>
- </size>
- </property>
<property name="title">
<string>Antennas:</string>
</property>
@@ -799,6 +793,29 @@
</spacer>
</item>
<item>
+ <widget class="QRadioButton" name="rb192000">
+ <property name="text">
+ <string>192000 Hz</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_6">
+ <property name="orientation">
+ <enum>Qt::Orientation::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
<widget class="QRadioButton" name="rb96000">
<property name="text">
<string>96000 Hz</string>
@@ -809,7 +826,7 @@
</widget>
</item>
<item>
- <spacer name="horizontalSpacer_6">
+ <spacer name="horizontalSpacer_61">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
@@ -923,104 +940,39 @@
</widget>
</item>
<item>
- <layout class="QHBoxLayout" name="horizontalLayout_17">
- <item>
- <spacer name="horizontalSpacer_17">
- <property name="orientation">
- <enum>Qt::Orientation::Horizontal</enum>
- </property>
- <property name="sizeType">
- <enum>QSizePolicy::Policy::Fixed</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>80</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
+ <layout class="QGridLayout" name="colorsGridLayout">
+ <item row="0" column="1">
<widget class="QLabel" name="label_20">
<property name="text">
<string>Red</string>
</property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer_19">
- <property name="orientation">
- <enum>Qt::Orientation::Horizontal</enum>
- </property>
- <property name="sizeType">
- <enum>QSizePolicy::Policy::Fixed</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>31</width>
- <height>20</height>
- </size>
+ <property name="alignment">
+ <set>Qt::AlignmentFlag::AlignCenter</set>
</property>
- </spacer>
+ </widget>
</item>
- <item>
+ <item row="0" column="2">
<widget class="QLabel" name="label_21">
<property name="text">
<string>Green</string>
</property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer_20">
- <property name="orientation">
- <enum>Qt::Orientation::Horizontal</enum>
- </property>
- <property name="sizeType">
- <enum>QSizePolicy::Policy::Fixed</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>34</width>
- <height>20</height>
- </size>
+ <property name="alignment">
+ <set>Qt::AlignmentFlag::AlignCenter</set>
</property>
- </spacer>
+ </widget>
</item>
- <item>
+ <item row="0" column="3">
<widget class="QLabel" name="label_22">
<property name="text">
<string>Blue</string>
</property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer_18">
- <property name="orientation">
- <enum>Qt::Orientation::Horizontal</enum>
- </property>
- <property name="sizeType">
- <enum>QSizePolicy::Policy::Fixed</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>80</width>
- <height>20</height>
- </size>
+ <property name="alignment">
+ <set>Qt::AlignmentFlag::AlignCenter</set>
</property>
- </spacer>
+ </widget>
</item>
- </layout>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_11">
- <item>
+ <item row="1" column="0">
<widget class="QLabel" name="label_15">
- <property name="maximumSize">
- <size>
- <width>60</width>
- <height>16777215</height>
- </size>
- </property>
<property name="text">
<string>Background</string>
</property>
@@ -1029,21 +981,21 @@
</property>
</widget>
</item>
- <item>
+ <item row="1" column="1">
<widget class="QSpinBox" name="sbBackgroundRed">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
- <item>
+ <item row="1" column="2">
<widget class="QSpinBox" name="sbBackgroundGreen">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
- <item>
+ <item row="1" column="3">
<widget class="QSpinBox" name="sbBackgroundBlue">
<property name="maximum">
<number>255</number>
@@ -1053,34 +1005,8 @@
</property>
</widget>
</item>
- <item>
- <spacer name="horizontalSpacer_14">
- <property name="orientation">
- <enum>Qt::Orientation::Horizontal</enum>
- </property>
- <property name="sizeType">
- <enum>QSizePolicy::Policy::Fixed</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>55</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_12">
- <item>
+ <item row="2" column="0">
<widget class="QLabel" name="label_16">
- <property name="maximumSize">
- <size>
- <width>60</width>
- <height>16777215</height>
- </size>
- </property>
<property name="text">
<string>Newest</string>
</property>
@@ -1089,7 +1015,7 @@
</property>
</widget>
</item>
- <item>
+ <item row="2" column="1">
<widget class="QSpinBox" name="sbRed0">
<property name="maximum">
<number>255</number>
@@ -1099,34 +1025,28 @@
</property>
</widget>
</item>
- <item>
+ <item row="2" column="2">
<widget class="QSpinBox" name="sbGreen0">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
- <item>
+ <item row="2" column="3">
<widget class="QSpinBox" name="sbBlue0">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
- <item>
+ <item row="2" column="4">
<widget class="QLabel" name="lab0">
<property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
<property name="font">
<font>
<family>Courier New</family>
@@ -1138,18 +1058,8 @@
</property>
</widget>
</item>
- </layout>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_13">
- <item>
+ <item row="3" column="0">
<widget class="QLabel" name="label_17">
- <property name="maximumSize">
- <size>
- <width>60</width>
- <height>16777215</height>
- </size>
- </property>
<property name="text">
<string>2nd</string>
</property>
@@ -1158,7 +1068,7 @@
</property>
</widget>
</item>
- <item>
+ <item row="3" column="1">
<widget class="QSpinBox" name="sbRed1">
<property name="maximum">
<number>255</number>
@@ -1168,7 +1078,7 @@
</property>
</widget>
</item>
- <item>
+ <item row="3" column="2">
<widget class="QSpinBox" name="sbGreen1">
<property name="maximum">
<number>255</number>
@@ -1178,27 +1088,21 @@
</property>
</widget>
</item>
- <item>
+ <item row="3" column="3">
<widget class="QSpinBox" name="sbBlue1">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
- <item>
+ <item row="3" column="4">
<widget class="QLabel" name="lab1">
<property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
<property name="font">
<font>
<family>Courier New</family>
@@ -1210,18 +1114,8 @@
</property>
</widget>
</item>
- </layout>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_14">
- <item>
+ <item row="4" column="0">
<widget class="QLabel" name="label_18">
- <property name="maximumSize">
- <size>
- <width>60</width>
- <height>16777215</height>
- </size>
- </property>
<property name="text">
<string>3rd</string>
</property>
@@ -1230,7 +1124,7 @@
</property>
</widget>
</item>
- <item>
+ <item row="4" column="1">
<widget class="QSpinBox" name="sbRed2">
<property name="maximum">
<number>255</number>
@@ -1240,7 +1134,7 @@
</property>
</widget>
</item>
- <item>
+ <item row="4" column="2">
<widget class="QSpinBox" name="sbGreen2">
<property name="maximum">
<number>255</number>
@@ -1250,7 +1144,7 @@
</property>
</widget>
</item>
- <item>
+ <item row="4" column="3">
<widget class="QSpinBox" name="sbBlue2">
<property name="maximum">
<number>255</number>
@@ -1260,20 +1154,14 @@
</property>
</widget>
</item>
- <item>
+ <item row="4" column="4">
<widget class="QLabel" name="lab2">
<property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
<property name="font">
<font>
<family>Courier New</family>
@@ -1285,18 +1173,8 @@
</property>
</widget>
</item>
- </layout>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_15">
- <item>
+ <item row="5" column="0">
<widget class="QLabel" name="label_19">
- <property name="maximumSize">
- <size>
- <width>60</width>
- <height>16777215</height>
- </size>
- </property>
<property name="text">
<string>Oldest</string>
</property>
@@ -1305,7 +1183,7 @@
</property>
</widget>
</item>
- <item>
+ <item row="5" column="1">
<widget class="QSpinBox" name="sbRed3">
<property name="maximum">
<number>255</number>
@@ -1315,7 +1193,7 @@
</property>
</widget>
</item>
- <item>
+ <item row="5" column="2">
<widget class="QSpinBox" name="sbGreen3">
<property name="maximum">
<number>255</number>
@@ -1325,7 +1203,7 @@
</property>
</widget>
</item>
- <item>
+ <item row="5" column="3">
<widget class="QSpinBox" name="sbBlue3">
<property name="maximum">
<number>255</number>
@@ -1335,20 +1213,14 @@
</property>
</widget>
</item>
- <item>
+ <item row="5" column="4">
<widget class="QLabel" name="lab3">
<property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
<property name="font">
<font>
<family>Courier New</family>
@@ -1714,13 +1586,6 @@
</property>
</widget>
</item>
- <item row="4" column="0">
- <widget class="QCheckBox" name="pskReporterTcpIpBox">
- <property name="text">
- <string>Use TCP/IP for PSKReporter</string>
- </property>
- </widget>
- </item>
<item row="5" column="0">
<spacer name="verticalSpacer_7">
<property name="orientation">
@@ -1734,6 +1599,16 @@
</property>
</spacer>
</item>
+ <item row="4" column="0">
+ <widget class="QCheckBox" name="pskReporterTcpIpBox">
+ <property name="toolTip">
+ <string>Transport changes take effect the next time MAP65 starts.</string>
+ </property>
+ <property name="text">
+ <string>Use TCP for PSK Reporter</string>
+ </property>
+ </widget>
+ </item>
<item row="1" column="0">
<widget class="QGroupBox" name="LiveCQ_groupBox">
<property name="title">
diff --git a/map65/globals.h b/map65/globals.h
new file mode 100644
index 00000000..c9fa80d8
--- /dev/null
+++ b/map65/globals.h
@@ -0,0 +1 @@
+extern int g_activeNfft;
diff --git a/map65/half_symbol_scheduler.h b/map65/half_symbol_scheduler.h
new file mode 100644
index 00000000..b4b1e2b5
--- /dev/null
+++ b/map65/half_symbol_scheduler.h
@@ -0,0 +1,36 @@
+#ifndef MAP65_HALF_SYMBOL_SCHEDULER_H
+#define MAP65_HALF_SYMBOL_SCHEDULER_H
+
+#include <atomic>
+
+class Map65HalfSymbolScheduler
+{
+public:
+ void reset () noexcept { scheduled_half_symbol_ = 0; }
+
+ bool claim_next (int available_half_symbol, std::atomic_bool& busy) noexcept
+ {
+ if (available_half_symbol <= scheduled_half_symbol_)
+ {
+ return false;
+ }
+
+ bool expected = false;
+ if (!busy.compare_exchange_strong (expected, true,
+ std::memory_order_acq_rel,
+ std::memory_order_acquire))
+ {
+ return false;
+ }
+
+ ++scheduled_half_symbol_;
+ return true;
+ }
+
+ int scheduled_half_symbol () const noexcept { return scheduled_half_symbol_; }
+
+private:
+ int scheduled_half_symbol_ {0};
+};
+
+#endif
diff --git a/map65/libm65/CMakeLists.txt b/map65/libm65/CMakeLists.txt
index 67e4961e..c0361b44 100644
--- a/map65/libm65/CMakeLists.txt
+++ b/map65/libm65/CMakeLists.txt
@@ -6,6 +6,7 @@ set (libm65_FSRCS
extract_shared_mod.f90
gran_interface.f90
m65_mod.f90
+ map65_polarization_score.f90
four2a_legacy_wrap.f90
npar_ptrs_mod.f90
pfx_mod.f90
@@ -91,7 +92,6 @@ set (libm65_FSRCS
smo.f90
sun.f90
symspec.f90
- test_astro_pipeline.f90
# timer.f90
timf2.f90
tm2.f90
@@ -113,6 +113,7 @@ set (libm65_ka9q_CSRCS
set_source_files_properties (${libm65_ka9q_CSRCS} PROPERTIES COMPILE_FLAGS -Wno-sign-compare)
set (libm65_CSRCS
+ decode_request_mutex.cpp
${libm65_ka9q_CSRCS}
ftrsd2.c
# gran.c
@@ -137,12 +138,24 @@ else ()
)
endif ()
+if (APPLE)
+ # Keep Apple's framework include flags out of m65impl's Fortran sources.
+ list (REMOVE_ITEM libm65_CSRCS stdout_shared_memory.cpp)
+ add_library (m65_qt STATIC stdout_shared_memory.cpp)
+ target_link_libraries (m65_qt PRIVATE Qt5::Core)
+endif ()
+
#set (libm65_CXXSRCS
# ipcomm.cpp
# )
add_definitions (-DBIGSYM=1)
set_source_files_properties (sec_midn.f90 PROPERTIES COMPILE_FLAGS -fno-second-underscore)
+# pol is genuine C-supplied state (bind(C, name='run_m65_'), called from
+# MAP65's audio callback) that the current implementation doesn't happen
+# to reference; removing it would mean touching the C++ caller too, so we
+# suppress the warning instead.
+set_source_files_properties (run_m65.f90 PROPERTIES COMPILE_FLAGS "-Wno-unused-dummy-argument")
if(Qt6_FOUND)
set_source_files_properties(m65a.f90 PROPERTIES COMPILE_FLAGS "-Wno-aliasing -fallow-argument-mismatch")
else()
@@ -179,14 +192,130 @@ set_source_files_properties(stdout_channel_mod.f90 PROPERTIES
Fortran_PREPROCESS ON
)
-# MAP65 should not choose between wsjt_fort and wsjt_fort_omp locally. The
-# common interface target keeps the variant policy in one place and still
-# resolves to wsjt_fort_omp when OPENMP_ONLY leaves no non-OpenMP library.
-# Default BOTH builds intentionally use the non-OpenMP common target here;
-# release Windows and Linux builds pin OPENMP_ONLY when MAP65 needs OpenMP.
-target_link_libraries (m65impl PUBLIC Qt5::Core)
+# MAP65 uses OpenMP critical regions to protect shared FFTW planning state,
+# independently of which common Fortran library variant it consumes.
+if (NOT TARGET wsjt_fortran_openmp)
+ message (FATAL_ERROR "MAP65 requires Fortran OpenMP support")
+endif ()
+if (NOT APPLE)
+ target_link_libraries (m65impl PUBLIC Qt5::Core)
+endif ()
+if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ target_link_libraries (m65impl PRIVATE rt)
+endif ()
+target_link_libraries (m65impl PRIVATE wsjt_fortran_openmp)
wsjt_link_common_fortran (m65impl)
+if (WSJT_ENABLE_TESTS)
+ add_subdirectory (${CMAKE_SOURCE_DIR}/tests/unit/map65/decode_history
+ ${CMAKE_CURRENT_BINARY_DIR}/decode_history)
+
+ add_executable (test_map65_deep_search_cache
+ ${CMAKE_SOURCE_DIR}/tests/unit/map65/test_map65_deep_search_cache.f90)
+ target_include_directories (test_map65_deep_search_cache PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ target_link_libraries (test_map65_deep_search_cache PRIVATE m65impl)
+ file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/deep_search_cache)
+ add_test (NAME test_map65_deep_search_cache COMMAND test_map65_deep_search_cache)
+ set_tests_properties (test_map65_deep_search_cache PROPERTIES
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/deep_search_cache TIMEOUT 30)
+
+ add_executable (test_map65_decode_requests
+ ${CMAKE_SOURCE_DIR}/tests/unit/map65/test_map65_decode_requests.f90)
+ target_include_directories (test_map65_decode_requests PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ target_link_libraries (test_map65_decode_requests PRIVATE m65impl)
+ add_test (NAME test_map65_decode_requests COMMAND test_map65_decode_requests)
+
+ add_executable (test_map65_astro
+ ${CMAKE_SOURCE_DIR}/tests/unit/map65/test_map65_astro.f90)
+ target_include_directories (test_map65_astro PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ target_link_libraries (test_map65_astro PRIVATE m65impl)
+ add_test (NAME test_map65_astro COMMAND test_map65_astro)
+ set_tests_properties (test_map65_astro PROPERTIES TIMEOUT 180)
+
+ add_executable (test_map65_jt65_handoff
+ ${CMAKE_SOURCE_DIR}/tests/unit/jt65/jt65_test_fixture.f90
+ ${CMAKE_SOURCE_DIR}/tests/unit/jt65/test_map65_jt65_handoff.f90)
+ target_include_directories (test_map65_jt65_handoff PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ target_link_libraries (test_map65_jt65_handoff PRIVATE m65impl jt65_test_vectors)
+ add_test (NAME test_map65_jt65_handoff COMMAND test_map65_jt65_handoff)
+ set_tests_properties (test_map65_jt65_handoff PROPERTIES TIMEOUT 180)
+
+ add_executable (test_q65_waveform_generator
+ ${CMAKE_SOURCE_DIR}/tests/unit/q65/test_q65_waveform_generator.f90)
+ target_include_directories (test_q65_waveform_generator PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ target_link_libraries (test_q65_waveform_generator PRIVATE m65impl)
+ add_test (NAME test_q65_waveform_generator COMMAND test_q65_waveform_generator)
+ set_tests_properties (test_q65_waveform_generator PROPERTIES TIMEOUT 180)
+
+ add_executable (test_map65_wideband_sync_rows
+ ${CMAKE_SOURCE_DIR}/tests/unit/q65/test_map65_wideband_sync_rows.f90)
+ target_include_directories (test_map65_wideband_sync_rows PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ target_link_libraries (test_map65_wideband_sync_rows PRIVATE m65impl)
+ add_test (NAME test_map65_wideband_sync_rows COMMAND test_map65_wideband_sync_rows)
+ set_tests_properties (test_map65_wideband_sync_rows PROPERTIES TIMEOUT 180)
+
+ add_executable (test_map65_polarization_score
+ ${CMAKE_SOURCE_DIR}/tests/unit/q65/test_map65_polarization_score.f90)
+ target_include_directories (test_map65_polarization_score PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ target_link_libraries (test_map65_polarization_score PRIVATE m65impl)
+ add_test (NAME test_map65_polarization_score COMMAND test_map65_polarization_score)
+
+ add_executable (test_ccf65_correlator
+ ${CMAKE_SOURCE_DIR}/tests/unit/jt65/test_ccf65_correlator.f90)
+ target_include_directories (test_ccf65_correlator PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ target_link_libraries (test_ccf65_correlator PRIVATE m65impl)
+ add_test (NAME test_ccf65_correlator COMMAND test_ccf65_correlator)
+ set_tests_properties (test_ccf65_correlator PROPERTIES TIMEOUT 180)
+
+ add_executable (test_map65_s3avg_contracts
+ ${CMAKE_SOURCE_DIR}/tests/unit/jt65/test_map65_s3avg_contracts.f90)
+ target_include_directories (test_map65_s3avg_contracts PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ target_link_libraries (test_map65_s3avg_contracts PRIVATE m65impl)
+ add_test (NAME test_map65_s3avg_contracts COMMAND test_map65_s3avg_contracts)
+ set_tests_properties (test_map65_s3avg_contracts PROPERTIES TIMEOUT 180)
+
+ add_executable (test_map65_jt65_message_validity
+ ${CMAKE_SOURCE_DIR}/tests/unit/jt65/test_map65_jt65_message_validity.f90)
+ target_include_directories (test_map65_jt65_message_validity PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ target_link_libraries (test_map65_jt65_message_validity PRIVATE m65impl)
+ add_test (NAME test_map65_jt65_message_validity COMMAND test_map65_jt65_message_validity)
+ set_tests_properties (test_map65_jt65_message_validity PROPERTIES TIMEOUT 180)
+
+ add_executable (test_map65_jt65_candidate_consistency
+ ${CMAKE_SOURCE_DIR}/tests/unit/jt65/test_map65_jt65_candidate_consistency.f90)
+ target_include_directories (test_map65_jt65_candidate_consistency PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ target_link_libraries (test_map65_jt65_candidate_consistency PRIVATE m65impl)
+ add_test (NAME test_map65_jt65_candidate_consistency COMMAND test_map65_jt65_candidate_consistency)
+ set_tests_properties (test_map65_jt65_candidate_consistency PROPERTIES TIMEOUT 180)
+
+ add_executable (test_map65_result_selection
+ ${CMAKE_SOURCE_DIR}/tests/unit/map65/test_map65_result_selection.f90)
+ target_include_directories (test_map65_result_selection PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ target_link_libraries (test_map65_result_selection PRIVATE m65impl)
+ add_test (NAME test_map65_result_selection COMMAND test_map65_result_selection)
+ set_tests_properties (test_map65_result_selection PROPERTIES TIMEOUT 180)
+
+ add_executable (test_map65_q65b_timeout
+ ${CMAKE_SOURCE_DIR}/tests/unit/map65/test_map65_q65b_timeout.f90)
+ target_include_directories (test_map65_q65b_timeout PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ target_link_libraries (test_map65_q65b_timeout PRIVATE m65impl)
+ add_test (NAME test_map65_q65b_timeout COMMAND test_map65_q65b_timeout)
+ set_tests_properties (test_map65_q65b_timeout PROPERTIES TIMEOUT 180)
+
+ add_executable (test_map65_q65_dphi
+ ${CMAKE_SOURCE_DIR}/tests/unit/map65/test_map65_q65_dphi.f90)
+ target_include_directories (test_map65_q65_dphi PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ target_link_libraries (test_map65_q65_dphi PRIVATE m65impl)
+ file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test-map65-q65-dphi)
+ add_test (NAME test_map65_q65_dphi COMMAND test_map65_q65_dphi)
+ set_tests_properties (test_map65_q65_dphi PROPERTIES
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test-map65-q65-dphi
+ ENVIRONMENT "OMP_NUM_THREADS=1"
+ RUN_SERIAL TRUE
+ TIMEOUT 180)
+
+endif ()
+
if (WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
target_compile_definitions(m65impl PRIVATE _WIN32)
elseif (WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 8)
@@ -199,8 +328,8 @@ endif()
add_executable (mapsim mapsim.f90)
add_dependencies(mapsim m65impl)
-target_include_directories(mapsim PRIVATE ${CMAKE_BINARY_DIR}/mod )
target_link_libraries (mapsim m65impl ${FFTW3_LIBRARIES})
+wsjt_add_simulator_usage_test (mapsim "Usage:[ ]+mapsim")
#add_executable (synctest synctest.f90)
#target_link_libraries (synctest m65impl ${FFTW3_LIBRARIES})
diff --git a/map65/libm65/afc65b.f90 b/map65/libm65/afc65b.f90
index 8083d924..e0ebfbc0 100644
--- a/map65/libm65/afc65b.f90
+++ b/map65/libm65/afc65b.f90
@@ -3,20 +3,31 @@ module afc65b_mod
contains
subroutine afc65b(cx,cy,npts,fsample,nflip,ipol,xpol,ndphi,a,ccfbest,dtbest)
- use debug_log
use fchisq_mod
+ use, intrinsic :: ieee_arithmetic, only: ieee_is_finite
implicit none
-
- logical :: xpol
- integer :: npts, nflip, ipol, ndphi
- complex :: cx(npts), cy(npts)
- real :: a(5), deltaa(5)
- integer :: iter, j, nterms
- real :: ccfbest, dtbest
- real :: chisq1, chisq2, chisq3, chisqr, chisqr0
- real :: delta, dtmax, fn, tmp
- real :: fsample, ccfmax
+
+ integer, parameter :: MAX_STEP_TRIES = 200
+ integer, parameter :: MAX_DOWNHILL_STEPS = 200
+ real, parameter :: MIN_STEP = 1.0e-4
+ real, parameter :: OBJECTIVE_REL_TOL = 1.0e-6
+
+ logical, intent(in) :: xpol
+ integer, intent(in) :: npts, nflip, ndphi
+ integer, intent(inout) :: ipol
+ complex, intent(in) :: cx(npts), cy(npts)
+ real, intent(inout) :: a(5)
+ real :: deltaa(5)
+ integer :: iter, j, nterms, step, downhill_steps
+ real, intent(out) :: ccfbest, dtbest
+ real :: chisq1, chisq2, chisqr, chisqr0
+ real :: delta, dtmax
+ real, intent(in) :: fsample
+ real :: ccfmax
+ real :: x0, xlast, xprev, xbest, xnext, candidate
+ real :: flast, fprev, fbest, fnext, fcandidate, curvature, tolerance
+ logical :: bracketed, improved, have_previous
! Initial parameter guesses
a(1) = 0.0
@@ -33,78 +44,143 @@ subroutine afc65b(cx,cy,npts,fsample,nflip,ipol,xpol,ndphi,a,ccfbest,dtbest)
nterms = 3
if (xpol) nterms = 4
+ if (ndphi /= 0) nterms = 3 ! don't fit pol when solving for dphi
- ! Don't fit polarization when solving for dphi
- if (ndphi /= 0) nterms = 3
+ ccfbest = 0.0
+ dtbest = 0.0
+ chisqr0 = 0.0
+ have_previous = .false.
- ! Start the iteration
- chisqr = 0.0
- chisqr0 = 1.0e6
+ if (npts < 1 .or. fsample <= 0.0 .or. .not. ieee_is_finite(fsample)) return
- do iter = 1, 3 ! One iteration is enough?
+ do iter = 1, 3
do j = 1, nterms
+ x0 = a(j)
chisq1 = fchisq(cx,cy,npts,fsample,nflip,a,ccfmax,dtmax)
- fn = 0.0
- delta = deltaa(j)
+ if (.not. ieee_is_finite(chisq1)) then
+ a(j) = x0
+ cycle
+ endif
- ! Find first step where chisq changes
- do
- a(j) = a(j) + delta
+ delta = abs(deltaa(j))
+ if (.not. ieee_is_finite(delta) .or. delta < MIN_STEP) delta = MIN_STEP
+ improved = .false.
+ xlast = x0
+ flast = chisq1
+ xnext = xlast
+
+ do step = 1, MAX_STEP_TRIES
+ xnext = xlast + delta
+ a(j) = xnext
chisq2 = fchisq(cx,cy,npts,fsample,nflip,a,ccfmax,dtmax)
- if (chisq2 /= chisq1) exit
+ if (.not. ieee_is_finite(chisq2)) exit
+ tolerance = OBJECTIVE_REL_TOL * max(1.0, abs(chisq1), abs(chisq2))
+ if (abs(chisq2 - chisq1) > tolerance) then
+ xprev = xlast
+ fprev = flast
+ improved = .true.
+ exit
+ endif
+ xlast = xnext
+ flast = chisq2
end do
- ! If we stepped uphill, reverse direction and swap labels
+ if (.not. improved) then
+ a(j) = x0
+ deltaa(j) = max(MIN_STEP, 0.5*delta)
+ cycle
+ endif
+
if (chisq2 > chisq1) then
- delta = -delta
- a(j) = a(j) + delta
- tmp = chisq1
- chisq1 = chisq2
- chisq2 = tmp
+ delta = -delta
+ xnext = x0 + delta
+ a(j) = xnext
+ chisq2 = fchisq(cx,cy,npts,fsample,nflip,a,ccfmax,dtmax)
+ tolerance = OBJECTIVE_REL_TOL * max(1.0, abs(chisq1), abs(chisq2))
+ if (.not. ieee_is_finite(chisq2) .or. chisq2 >= chisq1 - tolerance) then
+ a(j) = x0
+ deltaa(j) = max(MIN_STEP, 0.5*abs(delta))
+ cycle
+ endif
+ xprev = x0
+ fprev = chisq1
endif
- ! Walk while chisq keeps improving
- do
- fn = fn + 1.0
- a(j) = a(j) + delta
- chisq3 = fchisq(cx,cy,npts,fsample,nflip,a,ccfmax,dtmax)
- if (chisq3 < chisq2) then
- chisq1 = chisq2
- chisq2 = chisq3
+ xbest = xnext
+ fbest = chisq2
+ downhill_steps = 0
+ bracketed = .false.
+
+ do step = 1, MAX_DOWNHILL_STEPS
+ xnext = xbest + delta
+ a(j) = xnext
+ fnext = fchisq(cx,cy,npts,fsample,nflip,a,ccfmax,dtmax)
+ if (.not. ieee_is_finite(fnext)) then
+ a(j) = xbest
+ exit
+ endif
+
+ tolerance = OBJECTIVE_REL_TOL * max(1.0, abs(fbest), abs(fnext))
+ if (fnext < fbest - tolerance) then
+ xprev = xbest
+ fprev = fbest
+ xbest = xnext
+ fbest = fnext
+ downhill_steps = downhill_steps + 1
else
+ a(j) = xbest
+ bracketed = .true.
exit
endif
end do
- ! Guard against division by zero in flat regions
- if (chisq3 == chisq2) cycle
+ if (bracketed) then
+ curvature = fprev - 2.0*fbest + fnext
+ tolerance = OBJECTIVE_REL_TOL * max(1.0, abs(fprev), abs(fbest), abs(fnext))
+ if (curvature > tolerance) then
+ candidate = xbest + 0.5*delta*(fprev - fnext)/curvature
+ if (ieee_is_finite(candidate) .and. candidate > min(xprev, xnext) .and. &
+ candidate < max(xprev, xnext)) then
+ a(j) = candidate
+ fcandidate = fchisq(cx,cy,npts,fsample,nflip,a,ccfmax,dtmax)
+ if (ieee_is_finite(fcandidate)) then
+ tolerance = OBJECTIVE_REL_TOL * max(1.0, abs(fbest), abs(fcandidate))
+ if (fcandidate < fbest - tolerance) then
+ xbest = candidate
+ fbest = fcandidate
+ endif
+ endif
+ endif
+ endif
+ endif
- ! Find minimum of parabola defined by last three points
- delta = delta*(1.0/(1.0 + (chisq1 - chisq2)/(chisq3 - chisq2)) + 0.5)
- a(j) = a(j) - delta
- deltaa(j) = deltaa(j)*fn/3.0
+ a(j) = xbest
+ if (downhill_steps < 3) then
+ deltaa(j) = max(MIN_STEP, abs(delta)*max(1, downhill_steps)/3.0)
+ else
+ deltaa(j) = abs(delta)
+ endif
enddo
chisqr = fchisq(cx,cy,npts,fsample,nflip,a,ccfmax,dtmax)
- if (chisqr/chisqr0 > 0.9999) exit
+ if (.not. ieee_is_finite(chisqr)) exit
+ if (have_previous) then
+ tolerance = OBJECTIVE_REL_TOL * max(1.0, abs(chisqr), abs(chisqr0))
+ if (abs(chisqr - chisqr0) <= tolerance) exit
+ endif
chisqr0 = chisqr
+ have_previous = .true.
enddo
- ccfbest = ccfmax * (1378.125/fsample)**2
- dtbest = dtmax
-
- ! Wrap polarization angle into [0,180)
- if (a(4) < 0.0) a(4) = a(4) + 180.0
- if (a(4) >= 180.) a(4) = a(4) - 180.0
- if (nint(a(4)) == 180) a(4) = 0.0
+ if (ieee_is_finite(ccfmax)) ccfbest = max(0.0, ccfmax * (1378.125/fsample)**2)
+ if (ieee_is_finite(dtmax)) dtbest = dtmax
+ if (.not. ieee_is_finite(ccfbest)) ccfbest = 0.0
+ if (.not. ieee_is_finite(dtbest)) dtbest = 0.0
- if (a(4) < 0.0 .or. a(4) >= 180.0) then
- ! print *, 'afc65b: bad a(4) after wrap, set to 0. was ', a(4)
- a(4) = 0.0
- endif
+ if (.not. ieee_is_finite(a(4))) a(4) = 0.0
+ a(4) = modulo(a(4), 180.0)
- ipol = nint(a(4)/45.0) + 1
- if (ipol > 4) ipol = ipol - 4
+ ipol = modulo(nint(a(4)/45.0), 4) + 1
end subroutine afc65b
diff --git a/map65/libm65/astro.f90 b/map65/libm65/astro.f90
index d8304671..9ec92045 100644
--- a/map65/libm65/astro.f90
+++ b/map65/libm65/astro.f90
@@ -4,24 +4,24 @@ module astro_mod
! Sky temperature lookup table (was integer*2 nt144 + DATA + SAVE)
integer(int16), parameter :: nt144(180) = [ &
- 234_int16, 246_int16, 257_int16, 267_int16, 275_int16, 280_int16, 283_int16, 286_int16, 291_int16, 298_int16, &
- 305_int16, 313_int16, 322_int16, 331_int16, 341_int16, 351_int16, 361_int16, 369_int16, 376_int16, 381_int16, &
- 383_int16, 382_int16, 379_int16, 374_int16, 370_int16, 366_int16, 363_int16, 361_int16, 363_int16, 368_int16, &
- 376_int16, 388_int16, 401_int16, 415_int16, 428_int16, 440_int16, 453_int16, 467_int16, 487_int16, 512_int16, &
- 544_int16, 579_int16, 607_int16, 618_int16, 609_int16, 588_int16, 563_int16, 539_int16, 512_int16, 482_int16, &
- 450_int16, 422_int16, 398_int16, 379_int16, 363_int16, 349_int16, 334_int16, 319_int16, 302_int16, 282_int16, &
- 262_int16, 242_int16, 226_int16, 213_int16, 205_int16, 200_int16, 198_int16, 197_int16, 196_int16, 197_int16, &
- 200_int16, 202_int16, 204_int16, 205_int16, 204_int16, 203_int16, 202_int16, 201_int16, 203_int16, 206_int16, &
- 212_int16, 218_int16, 223_int16, 227_int16, 231_int16, 236_int16, 240_int16, 243_int16, 247_int16, 257_int16, &
- 276_int16, 301_int16, 324_int16, 339_int16, 346_int16, 344_int16, 339_int16, 331_int16, 323_int16, 316_int16, &
- 312_int16, 310_int16, 312_int16, 317_int16, 327_int16, 341_int16, 358_int16, 375_int16, 392_int16, 407_int16, &
- 422_int16, 437_int16, 451_int16, 466_int16, 480_int16, 494_int16, 511_int16, 530_int16, 552_int16, 579_int16, &
- 612_int16, 653_int16, 702_int16, 768_int16, 863_int16,1008_int16,1232_int16,1557_int16,1966_int16,2385_int16, &
- 2719_int16,2924_int16,3018_int16,3038_int16,2986_int16,2836_int16,2570_int16,2213_int16,1823_int16,1461_int16, &
- 1163_int16, 939_int16, 783_int16, 677_int16, 602_int16, 543_int16, 494_int16, 452_int16, 419_int16, 392_int16, &
- 373_int16, 360_int16, 353_int16, 350_int16, 350_int16, 350_int16, 350_int16, 350_int16, 350_int16, 348_int16, &
- 344_int16, 337_int16, 329_int16, 319_int16, 307_int16, 295_int16, 284_int16, 276_int16, 272_int16, 272_int16, &
- 273_int16, 274_int16, 274_int16, 271_int16, 266_int16, 260_int16, 252_int16, 245_int16, 238_int16, 231_int16 ]
+ 234, 246, 257, 267, 275, 280, 283, 286, 291, 298, &
+ 305, 313, 322, 331, 341, 351, 361, 369, 376, 381, &
+ 383, 382, 379, 374, 370, 366, 363, 361, 363, 368, &
+ 376, 388, 401, 415, 428, 440, 453, 467, 487, 512, &
+ 544, 579, 607, 618, 609, 588, 563, 539, 512, 482, &
+ 450, 422, 398, 379, 363, 349, 334, 319, 302, 282, &
+ 262, 242, 226, 213, 205, 200, 198, 197, 196, 197, &
+ 200, 202, 204, 205, 204, 203, 202, 201, 203, 206, &
+ 212, 218, 223, 227, 231, 236, 240, 243, 247, 257, &
+ 276, 301, 324, 339, 346, 344, 339, 331, 323, 316, &
+ 312, 310, 312, 317, 327, 341, 358, 375, 392, 407, &
+ 422, 437, 451, 466, 480, 494, 511, 530, 552, 579, &
+ 612, 653, 702, 768, 863,1008,1232,1557,1966,2385, &
+ 2719,2924,3018,3038,2986,2836,2570,2213,1823,1461, &
+ 1163, 939, 783, 677, 602, 543, 494, 452, 419, 392, &
+ 373, 360, 353, 350, 350, 350, 350, 350, 350, 348, &
+ 344, 337, 329, 319, 307, 295, 284, 276, 272, 272, &
+ 273, 274, 274, 271, 266, 260, 252, 245, 238, 231 ]
real(real32), parameter :: RAD2DEG = 57.2957795130823
real(real32), parameter :: C_KM_S = 2.99792458e5
@@ -56,7 +56,7 @@ contains
real(real64) :: freq
real :: RASun, DecSun
real :: AzMoon, ElMoon, vr, dist
- real(real64) :: xx, yy, poloffset1 = 0.0_real64, poloffset2 = 0.0_real64
+ real(real64) :: xx, yy, poloffset1 = 0.0, poloffset2 = 0.0
real(real64) :: techo
real(real32) :: el, eb
integer :: longecl_half, t144
@@ -91,11 +91,7 @@ contains
lon = -elon
call sun(nyear,month,nday,uth,lon,lat,RASun,DecSun,LST,AzSun,ElSun,mjd,day)
-
- freq = real(nfreq,real64)*1.0e6_real64
- if (nfreq == 2) freq = 1.8e6_real64
- if (nfreq == 4) freq = 3.5e6_real64
-
+ freq = nfreq*1.0d6
call MoonDop(nyear,month,nday,uth,lon,lat,RAMoon,DecMoon,LST,HA, &
AzMoon,ElMoon,vr,dist)
@@ -106,40 +102,40 @@ contains
if (NStation == 1) poloffset1 = RAD2DEG*atan2(yy,xx)
if (NStation == 2) poloffset2 = RAD2DEG*atan2(yy,xx)
- techo = 2.0_real64 * dist / C_KM_S
+ techo = 2.0 * dist / C_KM_S
doppler = -freq*vr / C_KM_S
call coord(0.,0.,-1.570796,1.161639, &
RAMoon/RAD2DEG,DecMoon/RAD2DEG,el,eb)
- longecl_half = nint(RAD2DEG*el/2.0_real64)
+ longecl_half = nint(RAD2DEG*el/2.0)
if (longecl_half < 1 .or. longecl_half > 180) longecl_half = 180
t144 = nt144(longecl_half)
- tsky = (real(t144,real64)-2.7_real64)*(144.0_real64/freq*1.0e-6_real64)**2.6_real64 + 2.7_real64
+ tsky = (t144-2.7)*(144.0e6/freq)**2.6 + 2.7
xdop(NStation) = doppler
if (NStation == 2) then
HisGrid = MyGrid
else
- doppler00 = 2.0_real64*xdop(1)
+ doppler00 = 2.0*xdop(1)
doppler = xdop(1) + xdop(2)
- dbMoon = -40.0_real64*log10(dist/356903.0_real64)
- sd = 16.23_real64*370152.0_real64/dist
-
- if (NStation == 1 .and. MoonDX /= 0.0_real64) then
- poloffset = mod(poloffset2-poloffset1+720.0_real64,180.0_real64)
- if (poloffset > 90.0_real64) poloffset = poloffset - 180.0_real64
- x1 = abs(cos(2.0_real64*poloffset/RAD2DEG))
- if (x1 < 0.056234_real64) x1 = 0.056234_real64
- xnr = -20.0_real64*log10(x1)
- if (HisGrid(1:1) < 'A' .or. HisGrid(1:1) > 'R') xnr = 0.0_real64
+ dbMoon = -40.0*log10(dist/356903.0)
+ sd = 16.23*370152.0/dist
+
+ if (NStation == 1 .and. MoonDX /= 0.0) then
+ poloffset = mod(poloffset2-poloffset1+720.d0,180.d0)
+ if (poloffset > 90.0) poloffset = poloffset - 180.0
+ x1 = abs(cos(2.0*poloffset/RAD2DEG))
+ if (x1 < 0.056234) x1 = 0.056234
+ xnr = -20.0*log10(x1)
+ if (HisGrid(1:1) < 'A' .or. HisGrid(1:1) > 'R') xnr = 0.0
end if
- tr = 80.0_real64
- tskymin = 13.0_real64*(408.0_real64/freq*1.0e-6_real64)**2.6_real64
+ tr = 80.0
+ tskymin = 13.0*(408.0e6/freq)**2.6
tsysmin = tskymin + tr
tsys = tsky + tr
- Dgrd = -10.0_real64*log10(tsys/tsysmin) + dbMoon
+ Dgrd = -10.0*log10(tsys/tsysmin) + dbMoon
end if
AzMoon0 = AzMoon
diff --git a/map65/libm65/astro0.f90 b/map65/libm65/astro0.f90
index 1501e2dc..f84c8bba 100644
--- a/map65/libm65/astro0.f90
+++ b/map65/libm65/astro0.f90
@@ -1,9 +1,9 @@
module astro0_state_mod
use iso_fortran_env, only: real64
implicit none
- real(real64) :: uth8z = 0.0_real64
- real(real64) :: dopplerz = 0.0_real64
- real(real64) :: doppler00z = 0.0_real64
+ real(real64) :: uth8z = 0.0
+ real(real64) :: dopplerz = 0.0
+ real(real64) :: doppler00z = 0.0
end module astro0_state_mod
@@ -77,7 +77,7 @@ contains
AzMoon8 = AzMoon
ElMoon8 = ElMoon
dbMoon8 = dbMoon
- RAMoon8 = RAMoon/15.0_real64
+ RAMoon8 = RAMoon/15.0
DecMoon8 = DecMoon
HA8 = HA
Dgrd8 = Dgrd
@@ -95,34 +95,34 @@ contains
call tm2(real(day,8)+1.0/1440.0,xlat1,xlon1,xl1a,b1a)
call tm2(real(day,8)+1.0/1440.0,xlat2,xlon2,xl2a,b2a)
- fghz = 0.001_real64*real(nfreq,real64)
+ fghz = 0.001*real(nfreq,real64)
dldt1 = DEGS*(xl1a-xl1)
dbdt1 = DEGS*(b1a-b1)
dldt2 = DEGS*(xl2a-xl2)
dbdt2 = DEGS*(b2a-b2)
- rate1 = 2.0_real64*sqrt(dldt1**2 + dbdt1**2)
- width1 = 0.5_real64*6741.0_real64*fghz*rate1
+ rate1 = 2.0*sqrt(dldt1**2 + dbdt1**2)
+ width1 = 0.5*6741.0*fghz*rate1
rate2 = sqrt((dldt1+dldt2)**2 + (dbdt1+dbdt2)**2)
- width2 = 0.5_real64*6741.0_real64*fghz*rate2
+ width2 = 0.5*6741.0*fghz*rate2
- fbend = 0.7_real64
- a2 = 0.0045_real64*log(fghz/fbend)/log(1.05_real64)
- if (fghz < fbend) a2 = 0.0_real64
- f50 = 0.19_real64 * (fghz/fbend)**a2
- if (f50 > 1.0_real64) f50 = 1.0_real64
+ fbend = 0.7
+ a2 = 0.0045*log(fghz/fbend)/log(1.05)
+ if (fghz < fbend) a2 = 0.0
+ f50 = 0.19 * (fghz/fbend)**a2
+ if (f50 > 1.0) f50 = 1.0
w501 = f50*width1
w502 = f50*width2
! df/dt using persistent state in astro0_state_mod
- if (uth8z == 0.0_real64) then
- uth8z = uth8 - 1.0_real64/3600.0_real64
+ if (uth8z == 0.0) then
+ uth8z = uth8 - 1.0/3600.0
dopplerz = ndop_loc
doppler00z = doppler00_loc
end if
- dt = 60.0_real64*(uth8-uth8z)
- if (dt <= 0.0_real64) dt = 1.0_real64/60.0_real64
+ dt = 60.0*(uth8-uth8z)
+ if (dt <= 0.0) dt = 1.0/60.0
dfdt = (ndop_loc - dopplerz )/dt
dfdt0 = (doppler00_loc - doppler00z)/dt
diff --git a/map65/libm65/ccf65.f90 b/map65/libm65/ccf65.f90
index 27a41f2f..2aa5228a 100644
--- a/map65/libm65/ccf65.f90
+++ b/map65/libm65/ccf65.f90
@@ -1,29 +1,37 @@
!------------------------------------------------------------------------------
-! NOTE: This module intentionally preserves the original legacy WSJT/MAP65
-! ccf65 implementation. Modernizing this routine changes the numerical
-! behavior of the JT65 correlation (FFT layout, half-spectrum handling,
-! baseline statistics, and sync metrics), which in turn produces a
-! different false-positive/false-negative profile. Extensive testing
-! shows that the legacy algorithm yields the correct and expected
-! decode behavior, so it is retained here without modification.
+! NOTE: This routine preserves the legacy JT65 correlation core. Its boundary
+! validation and output defaults make degenerate inputs deterministic
+! without changing the normal signal-processing path.
!------------------------------------------------------------------------------
module ccf65_legacy_mod
+ implicit none
contains
subroutine ccf65(ss_plane, nhsym, ssmax, sync1, ipol1, jpz, dt1, flipk, &
syncshort, snr2, ipol2, dt2)
- use four2a_legacy_wrap_mod, only: r2c_legacy, c2r_legacy
+ use four2a_legacy_wrap_mod, only: r2c_legacy, c2r_legacy, JT65_NFFT, JT65_NH
use pctile_mod, only: pctile
+ use, intrinsic :: ieee_arithmetic, only: ieee_is_finite
+
+ implicit none
+
+ integer, parameter :: NFFT = JT65_NFFT
+ integer, parameter :: NH = JT65_NH
+ integer, parameter :: MAX_NHSYM = 322
+
+ integer, intent(in) :: nhsym, jpz
+ real, intent(in) :: ssmax
+ real, intent(out) :: sync1, dt1, flipk, syncshort, snr2, dt2
+ integer, intent(out) :: ipol1, ipol2
- parameter (NFFT=512,NH=NFFT/2)
! Modern interface:
! ss_plane(4,322) is passed as a proper 2-D slice (ss(:,:,i))
- real, intent(in) :: ss_plane(4,322)
+ real, intent(in) :: ss_plane(4,MAX_NHSYM)
! Legacy expects: real ss(4,322) passed by reference from ss(1,1,i)
- real :: ss(4,322)
+ real :: ss(4,MAX_NHSYM)
! time-domain
real :: s(NFFT) ! CCF = ss*pr
@@ -37,12 +45,11 @@ subroutine ccf65(ss_plane, nhsym, ssmax, sync1, ipol1, jpz, dt1, flipk, &
complex :: cpr(0:NH) ! Complex FT of pr
complex :: cpr2(0:NH) ! Complex FT of pr2
- real tmp1(322)
+ real tmp1(MAX_NHSYM)
real ccf(-11:54,4)
- logical first
integer npr(126)
- data first/.true./
- save s,s2,pr,pr2,cs,cs2,cpr,cpr2
+ integer :: i, j, k, ip, lag, lagpk, lagpk2, npol
+ real :: fac, base, ccfbest, ccfbest2, ccf2, sumccf, sq, rms
! The JT65 pseudo-random sync pattern:
data npr/ &
@@ -54,40 +61,48 @@ subroutine ccf65(ss_plane, nhsym, ssmax, sync1, ipol1, jpz, dt1, flipk, &
0,1,0,1,0,0,1,1,0,0,1,0,0,1,0,0,0,0,1,1, &
1,1,1,1,1,1/
- logical :: debug
- debug = .false. ! (nhsym .gt. 300)
-
- ss = ss_plane
-
- if(first) then
- fac=1.0/NFFT
- do i=1,NFFT
- pr(i)=0.
- pr2(i)=0.
- k=2*mod((i-1)/8,2)-1
- if(i.le.NH) pr2(i)=fac*k
- enddo
- do i=1,126
- j=2*i
- pr(j)=fac*(2*npr(i)-1)
-! pr(j-1)=pr(j)
- enddo
+ sync1 = -4.0
+ syncshort = -4.0
+ snr2 = 0.01
+ dt1 = 0.0
+ dt2 = 0.0
+ flipk = 1.0
+ ipol1 = 1
+ ipol2 = 1
- call r2c_legacy(pr, cpr, NFFT)
- call r2c_legacy(pr2, cpr2, NFFT)
+ if (nhsym < 2 .or. nhsym > MAX_NHSYM) return
+ if (jpz < 1 .or. jpz > 4) return
+ if (.not. ieee_is_finite(ssmax)) return
- first=.false.
- endif
+ npol = jpz
+ ss = ss_plane
+ if (.not. all(ieee_is_finite(ss(1:npol,1:nhsym)))) return
+
+ fac = 1.0/NFFT
+ do i=1,NFFT
+ pr(i)=0.
+ pr2(i)=0.
+ k=2*mod((i-1)/8,2)-1
+ if(i.le.NH) pr2(i)=fac*k
+ enddo
+ do i=1,126
+ j=2*i
+ pr(j)=fac*(2*npr(i)-1)
+ enddo
+
+ call r2c_legacy(pr, cpr)
+ call r2c_legacy(pr2, cpr2)
- syncshort=0.
- snr2=0.
+ ccf = 0.0
! Look for JT65 sync pattern and shorthand square-wave pattern.
ccfbest=0.
ccfbest2=0.
ipol1=1
ipol2=1
- do ip=1,jpz !Do jpz polarizations
+ lagpk=0
+ lagpk2=0
+ do ip=1,npol !Do npol polarizations
do i=1,nhsym-1
! s(i)=ss(ip,i)+ss(ip,i+1)
s(i)=min(ssmax,ss(ip,i)+ss(ip,i+1))
@@ -97,17 +112,17 @@ subroutine ccf65(ss_plane, nhsym, ssmax, sync1, ipol1, jpz, dt1, flipk, &
s(nhsym:NFFT)=0.
! === Forward FFT: real ? packed half-spectrum ===
- call r2c_legacy(s, cs, NFFT)
+ call r2c_legacy(s, cs)
! === Multiply by sync patterns in frequency domain ===
do i=0,NH
- cs2(i) = cs(i)*conjg(cpr2(i))
- cs(i) = cs(i)*conjg(cpr(i))
- enddo
+ cs2(i) = cs(i) * conjg(cpr2(i))
+ cs(i) = cs(i) * conjg(cpr(i))
+ enddo
! === Inverse FFT: packed half-spectrum ? real ===
- call c2r_legacy(cs, s, NFFT)
- call c2r_legacy(cs2, s2, NFFT)
+ call c2r_legacy(cs, s)
+ call c2r_legacy(cs2, s2)
do lag=-11,54 !Check for best JT65 sync
j=lag
@@ -122,9 +137,6 @@ subroutine ccf65(ss_plane, nhsym, ssmax, sync1, ipol1, jpz, dt1, flipk, &
endif
enddo
-!### Not sure why this is ever true???
- if(sum(ccf).eq.0.0) return
-!###
do lag=-11,54 !Check for best shorthand
ccf2=s2(lag+28)
if(ccf2.gt.ccfbest2) then
@@ -136,6 +148,8 @@ subroutine ccf65(ss_plane, nhsym, ssmax, sync1, ipol1, jpz, dt1, flipk, &
enddo
+ if (.not. ieee_is_finite(ccfbest) .or. ccfbest <= 0.0) return
+
! Find rms level on baseline of "ccfblue", for normalization.
sumccf=0.
do lag=-11,54
@@ -147,8 +161,10 @@ subroutine ccf65(ss_plane, nhsym, ssmax, sync1, ipol1, jpz, dt1, flipk, &
if(abs(lag-lagpk).gt.1) sq=sq + (ccf(lag,ipol1)-base)**2
enddo
rms=sqrt(sq/49.0)
- sync1=-4.0
- if(rms.gt.0.0) sync1=ccfbest/rms - 4.0
+ if (ieee_is_finite(rms) .and. rms > 0.0) then
+ sync1=ccfbest/rms - 4.0
+ syncshort=0.5*ccfbest2/rms - 4.0
+ endif
dt1=lagpk*(2048.0/11025.0) - 2.5
! Find base level for normalizing snr2.
@@ -158,10 +174,11 @@ subroutine ccf65(ss_plane, nhsym, ssmax, sync1, ipol1, jpz, dt1, flipk, &
call pctile(tmp1,nhsym,40,base)
snr2=0.01
if(base.gt.0.0) snr2=0.398107*ccfbest2/base !### empirical
- syncshort=0.5*ccfbest2/rms - 4.0 !### better normalizer than rms?
dt2=2.5 + lagpk2*(2048.0/11025.0)
- if (debug) write(logunit,*) 'QT?', 'sync1=', sync1, ' lagpk=', lagpk, ' dt1=', dt1,' snr2=',snr2
+ if (.not. ieee_is_finite(sync1)) sync1 = -4.0
+ if (.not. ieee_is_finite(syncshort)) syncshort = -4.0
+ if (.not. ieee_is_finite(snr2)) snr2 = 0.01
return
end subroutine ccf65
diff --git a/map65/libm65/cgen65.f90 b/map65/libm65/cgen65.f90
index ac0c14b2..6fcf98d6 100644
--- a/map65/libm65/cgen65.f90
+++ b/map65/libm65/cgen65.f90
@@ -21,7 +21,7 @@ subroutine cgen65(message,mode65,samfac,nsendingsh,msgsent,cwave,nwave)
integer, intent(out) :: nsendingsh
character(len=22),intent(out) :: msgsent
- complex, intent(out) :: cwave(NMAX)
+ complex, intent(out) :: cwave(:)
integer, intent(out) :: nwave
!--------------------------------------------------------------------
@@ -106,7 +106,7 @@ subroutine cgen65(message,mode65,samfac,nsendingsh,msgsent,cwave,nwave)
!--------------------------------------------------------------------
do i = 1, ndata
t = t + dt
- j = int(t / tsymbol) + 1
+ j = min(nsym, int(t / tsymbol) + 1)
if (j .ne. j0) then
f = f0
diff --git a/map65/libm65/datcom_ptrs_mod.f90 b/map65/libm65/datcom_ptrs_mod.f90
index bcc8d41a..a507168e 100644
--- a/map65/libm65/datcom_ptrs_mod.f90
+++ b/map65/libm65/datcom_ptrs_mod.f90
@@ -6,6 +6,14 @@ module datcom_ptrs_mod
real(c_float), pointer, contiguous :: dd(:,:) => null() ! [4, 5760000]
real(c_float), pointer, contiguous :: ss(:,:,:) => null() ! [4, 322, NFFT]
real(c_float), pointer, contiguous :: savg(:,:) => null() ! [4, NFFT]
+ real(c_float), pointer, contiguous :: dd_old(:,:) => null() ! [4, 5760000]
+ real(c_float), pointer, contiguous :: ss_old(:,:,:) => null() ! [4, 322, NFFT]
+ real(c_float), pointer, contiguous :: savg_old(:,:) => null() ! [4, NFFT]
+
+ ! Pointers used by decode0 / narrowband decoder
+ real(c_float), pointer, contiguous :: dd_use(:,:) => null()
+ real(c_float), pointer, contiguous :: ss_use(:,:,:)=> null()
+ real(c_float), pointer, contiguous :: savg_use(:,:)=> null()
! Scalar values
integer, parameter :: NFFT=32768 !Length of FFTs
@@ -13,6 +21,12 @@ module datcom_ptrs_mod
contains
+ subroutine snapshot_buffers() bind(C)
+ dd_old(:,:) = dd(:,:)
+ ss_old(:,:,:) = ss(:,:,:)
+ savg_old(:,:) = savg(:,:)
+ end subroutine
+
! Helper subroutine to copy fixed-length Fortran string to C buffer
subroutine move_chars(dest, dest_len, src)
integer(c_int), intent(in) :: dest_len
@@ -53,6 +67,33 @@ contains
print *, "Fortran: savg pointer associated with dimensions", dim1, dim2
end subroutine
+ subroutine set_dd_old_ptr(ptr, dim1, dim2) bind(C, name="set_dd_old_ptr")
+ use iso_c_binding
+ implicit none
+ type(c_ptr), value :: ptr
+ integer(c_int), value :: dim1, dim2
+ call c_f_pointer(ptr, dd_old, [dim1, dim2])
+ print *, "Fortran: dd_old pointer associated with dimensions", dim1, dim2
+ end subroutine
+
+ subroutine set_ss_old_ptr(ptr, dim1, dim2, dim3) bind(C, name="set_ss_old_ptr")
+ use iso_c_binding
+ implicit none
+ type(c_ptr), value :: ptr
+ integer(c_int), value :: dim1, dim2, dim3
+ call c_f_pointer(ptr, ss_old, [dim1, dim2, dim3])
+ print *, "Fortran: ss_old pointer associated with dimensions", dim1, dim2, dim3
+ end subroutine
+
+ subroutine set_savg_old_ptr(ptr, dim1, dim2) bind(C, name="set_savg_old_ptr")
+ use iso_c_binding
+ implicit none
+ type(c_ptr), value :: ptr
+ integer(c_int), value :: dim1, dim2
+ call c_f_pointer(ptr, savg_old, [dim1, dim2])
+ print *, "Fortran: savg_old pointer associated with dimensions", dim1, dim2
+ end subroutine
+
function get_junk1() bind(C, name="get_junk1")
integer(c_int) :: get_junk1
get_junk1 = junk1
diff --git a/map65/libm65/debug_log.f90 b/map65/libm65/debug_log.f90
index 6b6a39e7..d91b969b 100644
--- a/map65/libm65/debug_log.f90
+++ b/map65/libm65/debug_log.f90
@@ -2,6 +2,7 @@ module debug_log
implicit none
integer, save :: dbg_unit = -1
logical, save :: dbg_opened = .false.
+ logical, save :: dbg_enabled = .false. ! master switch; set .true./.false. from run_m65 to enable/disable all dbg() output
contains
subroutine ensure_log_open()
if (.not. dbg_opened) then
@@ -10,9 +11,10 @@ contains
dbg_opened = .true.
end if
end subroutine ensure_log_open
-
+
subroutine dbg(msg)
character(len=*), intent(in) :: msg
+ if (.not. dbg_enabled) return
call ensure_log_open()
write(dbg_unit,'(A)') trim(msg)
flush(dbg_unit)
diff --git a/map65/libm65/decode0.f90 b/map65/libm65/decode0.f90
index a84f67ea..26a90366 100644
--- a/map65/libm65/decode0.f90
+++ b/map65/libm65/decode0.f90
@@ -7,8 +7,9 @@ contains
use iso_c_binding, only: c_int
use timer_module, only: timer
use npar_ptrs_mod
- use datcom_ptrs_mod, only: NFFT, dd
- use debug_log
+ use datcom_ptrs_mod, only: NFFT, dd, dd_old, dd_use, ss, ss_old, savg, savg_old, ss_use, savg_use
+ use debug_log, only: dbg, itoa, rtoa
+ use sec_midn_mod, only: sec_midn
use map65a_mod
use stdout_channel_mod, only: write_stdout
use decodes_mod, only: ndecodes, nhsym1, nhsym2
@@ -16,34 +17,77 @@ contains
implicit none
- integer, parameter :: NSMAX = 60*96000
integer(c_int), intent(in) :: nstandalone
integer hist(0:32768)
integer i, j1, j2, j3, j4, m, mcall3b, ndphi, neme0, nsum
integer :: ndecdone
real :: tdec, tquick, rmsdd
integer nz
+ integer :: nhsym0
+ integer :: newdat0
character(len=128) :: line
character mycall0*12, hiscall0*12, hisgrid0*6
- data neme0/-99/, mcall3b/1/, mycall0/' '/, hiscall0/' '/, hisgrid0/' '/
+ logical :: first_mcall3b_check
+
+ data neme0/-99/, mcall3b/0/, mycall0/' '/, hiscall0/' '/, hisgrid0/' '/
+ data first_mcall3b_check/.true./
save
+ ! The decoder owns the claimed parameters until this call returns.
+ nhsym0 = nhsym
+ newdat0 = newdat
+
+ ! TEMP diagnostic 2026-09-10 for the missing-final-pass / incomplete-
+ ! data-set investigation.
+ call dbg('decode0: ENTRY at t=' // rtoa(sec_midn()) // &
+ ' nhsym0=' // itoa(nhsym0) // ' newdat0=' // itoa(newdat0) // &
+ ' manualDecodeFlag=' // itoa(manualDecodeFlag) // &
+ ' nagain=' // itoa(nagain) // ' ndiskdat=' // itoa(ndiskdat))
+
+ ! newdat is forced to 1 by decode() for every call (manual or
+ ! automatic); it does not by itself mean "the live buffers just
+ ! finished a fresh accumulation." nagain=1 marks a manual repeat
+ ! (Decode button / Find Delta Phi), which must not refresh dd_old
+ ! from a live buffer that may still be mid-fill.
+ if (newdat0 /= 0 .and. manualDecodeFlag == 0 .and. nagain == 0) then
+ dd_old = dd
+ ss_old = ss
+ savg_old = savg
+ call dbg('decode0: dd_old REFRESHED from live dd at t=' // rtoa(sec_midn()) // ' nhsym0=' // itoa(nhsym0))
+ else
+ call dbg('decode0: dd_old NOT refreshed (reusing prior snapshot) at t=' // rtoa(sec_midn()) // &
+ ' nhsym0=' // itoa(nhsym0) // ' nagain=' // itoa(nagain))
+ endif
+
nkeep = 20
call sec0(0, tquick)
call timer('decode0 ', 0)
- if (newdat .ne. 0) then
- nz = int(96000.0*nhsym/5.3833)
+
+ ! Always decode from the snapshot (dd_old/ss_old/savg_old) taken above,
+ ! never the live dd/ss/savg. The nhsym2 pass routinely runs past the
+ ! minute boundary (several seconds), and symspec_() on the GUI thread
+ ! resets/overwrites the live buffers for the next cycle unconditionally
+ ! as soon as new UDP data arrives -- with no lock between the two
+ ! threads. Without this, a still-running decode reads a mix of this
+ ! cycle's and next cycle's data for candidates it hasn't reached yet
+ ! in its frequency sweep.
+ dd_use => dd_old
+ ss_use => ss_old
+ savg_use => savg_old
+
+ if (newdat0 .ne. 0 .or. manualDecodeFlag /= 0) then
+ nz = int( real(nrate_active, kind=real64) * nhsym0 / 5.3833_real64 )
hist = 0
do i = 1, nz
- j1 = int(min(abs(dd(1, i)), 32768.0))
+ j1 = int(min(abs(dd_use(1, i)), 32768.0))
hist(j1) = hist(j1) + 1
- j2 = int(min(abs(dd(2, i)), 32768.0))
+ j2 = int(min(abs(dd_use(2, i)), 32768.0))
hist(j2) = hist(j2) + 1
- j3 = int(min(abs(dd(3, i)), 32768.0))
+ j3 = int(min(abs(dd_use(3, i)), 32768.0))
hist(j3) = hist(j3) + 1
- j4 = int(min(abs(dd(4, i)), 32768.0))
+ j4 = int(min(abs(dd_use(4, i)), 32768.0))
hist(j4) = hist(j4) + 1
enddo
m = 0
@@ -56,6 +100,17 @@ contains
ndphi = 0
if (iand(nrxlog, 8) .ne. 0) ndphi = 1
+ ! Seed mycall0/hiscall0/hisgrid0/neme0 from the real values on the
+ ! first call instead of blank sentinels, so the mismatch check below
+ ! only fires on a genuine later change, not on startup.
+ if (first_mcall3b_check) then
+ mycall0 = mycall
+ hiscall0 = hiscall
+ hisgrid0 = hisgrid
+ neme0 = neme
+ first_mcall3b_check = .false.
+ endif
+
if (mycall .ne. mycall0 .or. hiscall .ne. hiscall0 .or. &
hisgrid .ne. hisgrid0 .or. mcall3 .ne. 0 .or. neme .ne. neme0) mcall3b = 1
@@ -64,30 +119,82 @@ contains
hisgrid0 = hisgrid
neme0 = neme
+ ! Manual decode: force a single nhsym2-style cycle and always emit DecodeFinished
+ if (manualDecodeFlag /= 0) then
+ nhsym0 = nhsym2
+ call announce_decode_pass('manual')
+
+ call timer('map65a ', 0)
+ call map65a(dd_use, newdat0, nutc, fcenter, ntol, idphi, nfa, nfb, &
+ mousedf, mousefqso, nagain, ndecdone, nfshift, ndphi, max_drift, &
+ nfcal, nkeep, mcall3b, nsum, nsave, nxant, mycall, mygrid, &
+ neme, ndepth, nstandalone, hiscall, hisgrid, nhsym0, nfsample, &
+ ndiskdat, nxpol, nmode, ndop00)
+ call timer('map65a ', 1)
+ call timer('decode0 ', 1)
+
+ call sec0(1, tdec)
+
+ write (line, '("<DecodeFinished>",3I4,I6,F6.2,I5,1X,I0)') &
+ nsum, nsave, nstandalone, nhsym0, tdec, ndecodes, active_request_id
+ call write_stdout(trim(line)//new_line('a'))
+
+ call dbg('decode0: MANUAL path RETURNING at t=' // rtoa(sec_midn()))
+
+ return
+
+ else
+
+ ! Normal wideband path: nhsym1 (EarlyFinished) + nhsym2 (DecodeFinished)
+ if (ndiskdat /= 0) then
+ call announce_decode_pass('disk')
+ else if (nhsym0 == nhsym1) then
+ call announce_decode_pass('early')
+ else if (nhsym0 == nhsym2) then
+ call announce_decode_pass('final')
+ else
+ call announce_decode_pass('unknown')
+ endif
call timer('map65a ', 0)
- call map65a(dd, newdat, nutc, fcenter, ntol, idphi, nfa, nfb, &
+ call map65a(dd_use, newdat0, nutc, fcenter, ntol, idphi, nfa, nfb, &
mousedf, mousefqso, nagain, ndecdone, nfshift, ndphi, max_drift, &
nfcal, nkeep, mcall3b, nsum, nsave, nxant, mycall, mygrid, &
- neme, ndepth, nstandalone, hiscall, hisgrid, nhsym, nfsample, &
+ neme, ndepth, nstandalone, hiscall, hisgrid, nhsym0, nfsample, &
ndiskdat, nxpol, nmode, ndop00)
call timer('map65a ', 1)
call timer('decode0 ', 1)
call sec0(1, tdec)
- if (nhsym == nhsym1) then
+ if (nhsym0 == nhsym1) then
write (line, '("<EarlyFinished>",3I4,I6,F6.2)') &
- nsum, nsave, nstandalone, nhsym, tdec
+ nsum, nsave, nstandalone, nhsym0, tdec
call write_stdout(trim(line)//new_line('a'))
end if
- if (nhsym == nhsym2) then
- write (line, '("<DecodeFinished>",3I4,I6,F6.2,I5)') &
- nsum, nsave, nstandalone, nhsym, tdec, ndecodes
+ ! A manual repeat decode (Decode button / Find Delta Phi) is always a
+ ! single, complete request regardless of nhsym, which only reflects
+ ! the automatic per-minute cycle and may never equal nhsym2 if no
+ ! automatic decode has run yet this session.
+ if (nhsym0 == nhsym2 .or. nagain /= 0) then
+ write (line, '("<DecodeFinished>",3I4,I6,F6.2,I5,1X,I0)') &
+ nsum, nsave, nstandalone, nhsym0, tdec, ndecodes, active_request_id
call write_stdout(trim(line)//new_line('a'))
end if
-! print *, 'nhsym is: ',nhsym,' nhsym1 is: ',nhsym1,' nhsym2 is: ',nhsym2
+
+ call dbg('decode0: WIDEBAND path RETURNING at t=' // rtoa(sec_midn()))
+
return
+ end if
end subroutine decode0
+ subroutine announce_decode_pass(pass_name)
+ use stdout_channel_mod, only: write_stdout
+ implicit none
+
+ character(len=*), intent(in) :: pass_name
+
+ call write_stdout('<Map65DecodePass> '//trim(pass_name)//new_line('a'))
+ end subroutine announce_decode_pass
+
end module decode0_mod
diff --git a/map65/libm65/decode1a.f90 b/map65/libm65/decode1a.f90
index ab981524..691593fd 100644
--- a/map65/libm65/decode1a.f90
+++ b/map65/libm65/decode1a.f90
@@ -21,11 +21,12 @@ subroutine decode1a(dd,newdat,f0,nflip,mode65,nfsample,xpol, &
use timf2_mod
use fil6521_mod
use twkfreq_xy_mod
+ use npar_ptrs_mod, only: nsmax_active
+ use sec_midn_mod, only: sec_midn
implicit none
- integer, parameter :: NMAX = 60*96000 !Samples per 60 s
- real(real32), intent(in) :: dd(4, NMAX) !92 MB: raw data from Linrad timf2
+ real(real32), intent(in) :: dd(4, nsmax_active) !92 MB: raw data from Linrad timf2
integer, intent(in) :: nflip, mode65, nfsample
logical, intent(in) :: xpol
character(len=12), intent(in) :: mycall, hiscall
@@ -33,40 +34,47 @@ subroutine decode1a(dd,newdat,f0,nflip,mode65,nfsample,xpol, &
integer, intent(in) :: neme, ndepth, nqd, ndphi
real, intent(in) :: dphi
real(real64), intent(in) :: f0
- integer, intent(in) :: nutc, nkhz, ndf, ipol, ntol
+ integer, intent(in) :: nutc, nkhz, ndf, ntol
+ integer, intent(inout) :: ipol
real, intent(inout):: sync2, a(5), dt, pol, qual
integer, intent(inout):: nkv, nhist, nsum, nsave, newdat
character(len=22), intent(out) :: decoded
- complex cx(NMAX/64), cy(NMAX/64) !Data at 1378.125 samples/s
- complex c5x(NMAX/256),c5y(NMAX/256) !Data at 344.53125 Hz
+ complex cx(nsmax_active/64), cy(nsmax_active/64) !Data at 1378.125 samples/s
+ complex c5x(nsmax_active/256), c5y(nsmax_active/256) !Data at 344.53125 Hz
+
complex c5a(512)
complex z
real s2(66,126)
real s3(64,63),sy(63)
real :: aa, bb, ccfbest, dt00, flip
- real :: dtbest, fsample, sq0, sqa, sqb, syncbest, xdt
+ real :: dtbest, fsample, sq0, sqa, sqb, syncbest
integer :: i, i0, ihzdiff, j, jj, jjjmax, jjjmin, k, n, n5
integer :: n6, nadd, nfft, nhz, nhz0, npol, nsym, nutc0, nz
logical first
+
+! real(kind=8) :: s2sum, s2mean
+! integer :: ii,kk
! real(c_double), dimension(*) :: dd
data first/.true./,jjjmin/1000/,jjjmax/-1000/
data nutc0/-999/,nhz0/-9999999/
save
-
+
! Mix sync tone to baseband, low-pass filter, downsample to 1378.125 Hz
dt00=dt
call timer('filbig ',0)
-
+
if (.not. ieee_is_finite(f0)) then
write(*,*) 'DECODE1A: bad f0, skipping filbig. f0=', f0
return
end if
- call filbig(dd,NMAX,f0,newdat,nfsample,xpol,cx,cy,n5)
-! NB: cx, cy have sample rate 96000*77125/5376000 = 1378.125 Hz
+ call filbig(dd, nsmax_active, f0, newdat, nfsample, xpol, cx, cy, n5)
+
call timer('filbig ',1)
+
+! NB: cx, cy have sample rate 96000*77125/5376000 = 1378.125 Hz
if(mode65.eq.0) return
sqa=0.
sqb=0.
@@ -89,10 +97,14 @@ subroutine decode1a(dd,newdat,f0,nflip,mode65,nfsample,xpol, &
if(xpol) then
c5y(:nadd)=0.
call fil6521(cy,n5,c5y(nadd+1),n6)
+ else
+ c5y(:n6+nadd)=0.
endif
n6=n6+nadd
- fsample=1378.125/4.
+ ! JT65 uses quarter-rate for symbol timing
+ fsample = 1378.125/4.0
+
a(5)=dt00
i0=nint((a(5)+0.5)*fsample) - 2 + nadd
if(i0.lt.1) then
@@ -102,16 +114,43 @@ subroutine decode1a(dd,newdat,f0,nflip,mode65,nfsample,xpol, &
endif
nz=n6+1-i0
+ ! 2026-09-12: instrumentation for the "identical anomalous dtbest despite
+ ! identical, legitimate dt00" investigation. dt00 itself is now confirmed
+ ! correct and consistent between working (nqd=1) and failing (nqd=0)
+ ! decodes of the same signal (traced to ccf65's lagpk, a genuine
+ ! correlation-peak lag, not a fallback constant) -- so the actual sample
+ ! window afc65b searches (c5x/c5y from i0 to i0+nz-1) is the next place to
+ ! look. Logging i0/nz and a cheap fingerprint (sum of magnitudes) of that
+ ! exact window so a live capture can show directly whether the underlying
+ ! data itself differs between a working and failing case.
+ if (nz .ge. 1 .and. i0 .ge. 1 .and. i0 + nz - 1 .le. nsmax_active/256) then
+ call dbg('decode1a: pre-afc65b at t=' // rtoa(sec_midn()) // &
+ ' i0=' // itoa(i0) // ' nz=' // itoa(nz) // ' n5=' // itoa(n5) // &
+ ' n6=' // itoa(n6) // ' dt00=' // rtoa(dt00) // &
+ ' c5x_sum_abs=' // rtoa(sum(abs(c5x(i0:i0+nz-1)))) // &
+ ' c5x_i0=' // rtoa(real(c5x(i0))) // ',' // rtoa(aimag(c5x(i0))))
+ else
+ call dbg('decode1a: pre-afc65b at t=' // rtoa(sec_midn()) // &
+ ' i0=' // itoa(i0) // ' nz=' // itoa(nz) // ' (OUT OF RANGE, skipping fingerprint)')
+ endif
+
! We're looking only at sync tone here... so why not downsample by another
! factor of 1/8, say? Should be a significant execution speed-up.
! Best fit for DF, f1, f2, pol
- call afc65b(c5x(i0),c5y(i0),nz,fsample,nflip,ipol,xpol,ndphi,a,ccfbest,dtbest)
+call afc65b(c5x(i0), c5y(i0), nz, fsample, nflip, ipol, xpol, ndphi, a, ccfbest, dtbest)
pol=a(4)/57.2957795
aa=cos(pol)
bb=sin(pol)
sq0=aa*aa*sqa + bb*bb*sqb
sync2=3.7*ccfbest/sq0
+
+ ! TEMP diagnostic 2026-09-10 for the freq/time-sync-vs-false-decode investigation.
+ call dbg('decode1a: afc65b fit at t=' // rtoa(sec_midn()) // &
+ ' f0=' // rtoa(real(f0)) // ' dt00=' // rtoa(dt00) // ' dtbest=' // rtoa(dtbest) // &
+ ' ccfbest=' // rtoa(ccfbest) // ' a1(df)=' // rtoa(a(1)) // ' a2=' // rtoa(a(2)) // &
+ ' a3=' // rtoa(a(3)) // ' a4(pol_deg)=' // rtoa(a(4)) // ' sync2=' // rtoa(sync2) // &
+ ' nflip=' // itoa(nflip) // ' ipol=' // itoa(ipol))
! Apply AFC corrections to the time-domain signal
! Now we are back to using the 1378.125 Hz sample rate, enough to
@@ -126,7 +165,9 @@ subroutine decode1a(dd,newdat,f0,nflip,mode65,nfsample,xpol, &
nsym=126
nfft=512
- j=(dt00+dtbest+2.685)*1378.125
+ j = (dt00 + dtbest + 2.685)*1378.125
+! fs_out = real(n5) / 60.0 ! actual sample rate from filbig
+! j = (dt00 + dtbest + 2.685) * fs_out
if(j.lt.0) j=0
@@ -137,7 +178,7 @@ subroutine decode1a(dd,newdat,f0,nflip,mode65,nfsample,xpol, &
! do n=1,mode65
do n=1,1
do i=1,nfft
- j=min(j+1,NMAX/64)
+ j = min(j+1, nsmax_active/64)
c5a(i)=aa*cx(j) + bb*cy(j)
enddo
call four2a(c5a,nfft,1,1,1)
@@ -159,8 +200,22 @@ subroutine decode1a(dd,newdat,f0,nflip,mode65,nfsample,xpol, &
flip=nflip
call timer('dec65b ',0)
+
+! After filling s2(66,126), just before:
+! call decode65b(...)
+
+!s2sum = 0.0d0
+!do kk = 1, nsym
+! do ii = 1, 66
+! s2sum = s2sum + dble(s2(ii,kk))
+! end do
+!end do
+
+!s2mean = s2sum / dble(66*nsym)
+
call decode65b(s2,flip,mycall,hiscall,hisgrid,mode65,neme,ndepth, &
nqd,nkv,nhist,qual,decoded,s3,sy)
+
dt=dt00 + dtbest + 1.7
call timer('dec65b ',1)
@@ -173,7 +228,7 @@ subroutine decode1a(dd,newdat,f0,nflip,mode65,nfsample,xpol, &
nsave=mod(nsave-1,64)+1
npol=nint(57.296*pol)
- call s3avg(nsave,mode65,nutc,nhz,xdt,npol,ntol,s3,nsum,nkv,decoded)
+ call s3avg(nsave,mode65,nutc,nhz,dt,npol,nflip,ntol,s3,nsum,nkv,decoded)
syncbest=sync2
nhz0=nhz
endif
diff --git a/map65/libm65/decode65b.f90 b/map65/libm65/decode65b.f90
index 93166de0..694cbccb 100644
--- a/map65/libm65/decode65b.f90
+++ b/map65/libm65/decode65b.f90
@@ -9,6 +9,7 @@ subroutine decode65b(s2,flip,mycall,hiscall,hisgrid,mode65,neme,ndepth, &
use extract_mod
use pr_mod
use setup65_mod
+ use debug_log, only: dbg, itoa
real, intent(in) :: s2(66,126)
real, intent(out) :: s3(64,63), sy(63)
@@ -61,13 +62,33 @@ subroutine decode65b(s2,flip,mycall,hiscall,hisgrid,mode65,neme,ndepth, &
decoded=' '
endif
+ ! TEMP diagnostic 2026-09-10 for the false-JT65-decode investigation.
+ call dbg('decode65b: extract() done, ncount=' // itoa(ncount) // ' nkv=' // itoa(nkv) // &
+ ' hard_decoded="' // trim(decoded) // '" nqd=' // itoa(nqd) // ' flip=' // itoa(nint(flip)) // &
+ ' ndepth=' // itoa(ndepth) // &
+ ' will_run_deep65=' // itoa(merge(1,0, ndepth.ge.1 .and. (nqd.eq.1 .or. flip.eq.1.0))))
+
qual=0.
if(ndepth.ge.1 .and. (nqd.eq.1 .or. flip.eq.1.0)) then
call deep65(s3,mode65,neme,flip,mycall,hiscall,hisgrid,deepmsg,qual,mrs,mrs2)
if(nqd.ne.1 .and. qual.lt.10.0) qual=0.0
if(ndepth.lt.2 .and. qual.lt.6.0) qual=0.0
endif
- if(nkv.eq.0 .and. qual.ge.1.0) decoded=deepmsg
+
+ ! Deep Search's AP guess overrides extract()'s hard decode whenever
+ ! qual.ge.1.0, regardless of nkv (whether extract() itself reported
+ ! success). A "successful" hard Reed-Solomon decode doesn't guarantee a
+ ! real message -- JT65's RS code has a nonzero false-positive rate, and a
+ ! qual.ge.1.0 Deep Search match is far more likely to be correct than a
+ ! false RS accept. This cutoff is not immune to a low-but-nonzero
+ ! marginal-qual false accept of its own; see the PR's false-decode-rate
+ ! discussion for known residual cases.
+ if (qual.ge.1.0) then
+ decoded=deepmsg
+ nkv=0
+ endif
+
+ call dbg('decode65b: final decoded="' // trim(decoded) // '" nkv=' // itoa(nkv) // ' qual=' // itoa(nint(qual)))
return
end subroutine decode65b
diff --git a/map65/libm65/decode_request_mutex.cpp b/map65/libm65/decode_request_mutex.cpp
new file mode 100644
index 00000000..999512e6
--- /dev/null
+++ b/map65/libm65/decode_request_mutex.cpp
@@ -0,0 +1,15 @@
+#include <mutex>
+
+namespace {
+std::mutex request_mutex;
+}
+
+extern "C" void lock_decode_requests()
+{
+ request_mutex.lock();
+}
+
+extern "C" void unlock_decode_requests()
+{
+ request_mutex.unlock();
+}
diff --git a/map65/libm65/decodes_mod.f90 b/map65/libm65/decodes_mod.f90
index 03c84069..3479fbb4 100644
--- a/map65/libm65/decodes_mod.f90
+++ b/map65/libm65/decodes_mod.f90
@@ -1,23 +1,43 @@
module decodes_mod
- implicit none
+ use npar_ptrs_mod, only: nfft_active
- integer, parameter :: NLD = 32768
- ! from decodes
- integer :: ndecodes = 0
-
- !from early
- integer :: nhsym1 = 0, nhsym2 = 0
+ implicit none
- logical, allocatable :: ldecoded(:)
-
- !from c3com
- integer :: mcall3a = 0
+ integer :: ndecodes = 0
+ integer :: nhsym1 = 0, nhsym2 = 0
+ logical, allocatable :: ldecoded(:)
+ ! JT65 bins already decoded in this accumulation cycle. Retaining them
+ ! across early/final calls avoids reporting the same signal twice;
+ ! select_unique_decodes() only compares results within one call.
+ logical, allocatable :: ljt65decoded(:)
+ integer :: mcall3a = 0
- contains
+contains
- subroutine decodes_init()
- if (.not. allocated(ldecoded)) allocate(ldecoded(NLD))
- end subroutine decodes_init
+ subroutine decodes_init()
+ ! (Re)allocate ldecoded/ljt65decoded to match the active symspec FFT length.
+ if (allocated(ldecoded)) then
+ if (size(ldecoded) /= nfft_active) then
+ deallocate(ldecoded)
+ end if
+ end if
+
+ if (.not. allocated(ldecoded)) then
+ allocate(ldecoded(nfft_active))
+ ldecoded = .false.
+ end if
+
+ if (allocated(ljt65decoded)) then
+ if (size(ljt65decoded) /= nfft_active) then
+ deallocate(ljt65decoded)
+ end if
+ end if
+
+ if (.not. allocated(ljt65decoded)) then
+ allocate(ljt65decoded(nfft_active))
+ ljt65decoded = .false.
+ end if
+ end subroutine decodes_init
end module decodes_mod
diff --git a/map65/libm65/deep65.f90 b/map65/libm65/deep65.f90
index ccd04d26..dfe83751 100644
--- a/map65/libm65/deep65.f90
+++ b/map65/libm65/deep65.f90
@@ -1,12 +1,185 @@
module deep65_mod
implicit none
+
+ ! MAXCALLS/testmsg/ncode/callgrid/pp/ntot are module-scoped so that a
+ ! separate subroutine, build_call3_candidates() below, can be called once
+ ! eagerly from run_m65.f90 at startup and build the same cached candidate
+ ! list before the decoder ever needs it, instead of the first real decode
+ ! paying for it.
+ integer, parameter :: MAXRPT = 63
+ integer, save :: MAXCALLS = 0, narr = 0, ntot = 0
+ character(len=22), allocatable, save :: testmsg(:)
+ character(len=15), allocatable, save :: callgrid(:)
+ integer, allocatable, save :: ncode(:,:)
+ real, allocatable, save :: pp(:)
+ character(len=12), save :: cached_mycall = '', cached_hiscall = ''
+ character(len=6), save :: cached_hisgrid = ''
+ integer, save :: cached_neme = 0
+
contains
+ ! Encoding the full CALL3.TXT list is expensive. Reuse candidates only
+ ! while the file and their station settings match.
+ subroutine build_call3_candidates(mycall, hiscall, hisgrid, neme)
+ use decodes_mod, only: mcall3a
+ use encode65_mod
+ use debug_log, only: dbg, itoa, rtoa
+ use sec_midn_mod, only: sec_midn
+ use timer_module, only: timer
+ implicit none
+
+ character(len=12), intent(in) :: mycall, hiscall
+ character(len=6), intent(in) :: hisgrid
+ integer, intent(in) :: neme
+
+ character callsign*12, grid*4, message*22, ceme*3
+ character(len=180) line
+ character(len=4) :: rpt(MAXRPT)
+ integer :: nlines_in_file, ios
+ integer :: i, i1, i2, i3, icall, k, j1, j2, j3, j4, m, mz, n
+
+ data rpt/'-01','-02','-03','-04','-05', &
+ '-06','-07','-08','-09','-10', &
+ '-11','-12','-13','-14','-15', &
+ '-16','-17','-18','-19','-20', &
+ '-21','-22','-23','-24','-25', &
+ '-26','-27','-28','-29','-30', &
+ 'R-01','R-02','R-03','R-04','R-05', &
+ 'R-06','R-07','R-08','R-09','R-10', &
+ 'R-11','R-12','R-13','R-14','R-15', &
+ 'R-16','R-17','R-18','R-19','R-20', &
+ 'R-21','R-22','R-23','R-24','R-25', &
+ 'R-26','R-27','R-28','R-29','R-30', &
+ 'RO','RRR','73'/
+ save rpt
+
+ call dbg('build_call3_candidates: entry, mcall3a=' // itoa(mcall3a) // ' cached ntot=' // itoa(ntot))
+
+ if (mcall3a.eq.0 .and. allocated(testmsg) .and. &
+ mycall.eq.cached_mycall .and. hiscall.eq.cached_hiscall .and. &
+ hisgrid.eq.cached_hisgrid .and. neme.eq.cached_neme) return
+
+ k = 0
+ ntot = 0
+
+ call timer('deep65a ', 0)
+ mcall3a = 0
+
+ ! CALL3.TXT is normally already open on unit 23 by the time map65a()
+ ! calls deep65() (see map65a.f90's own open() near its top, run before
+ ! every decode). When this is called eagerly from run_m65.f90, before
+ ! any decode has happened, nothing has opened it yet -- open it here
+ ! too. Re-opening an already-open unit on the same file is harmless.
+ !### Should use AppDir! ###
+ open (23, file='CALL3.TXT', status='unknown')
+
+ ! Count actual lines in CALL3.TXT so the candidate-list arrays can be
+ ! sized to fit the whole file, then size arrays large enough for every
+ ! line to become a real candidate, generously covering the n=1
+ ! (hiscall) special case that can expand into up to MAXRPT+1
+ ! report-message variants.
+ rewind 23
+ nlines_in_file = 0
+ do
+ read(23, '(A)', iostat=ios) line
+ if (ios /= 0) exit
+ nlines_in_file = nlines_in_file + 1
+ end do
+ rewind 23
+
+ MAXCALLS = max(nlines_in_file + 1, 100) ! +1 for the n=1 hiscall slot
+ narr = 2*(MAXCALLS + MAXRPT + 1)
+
+ if (allocated(testmsg)) deallocate(testmsg)
+ if (allocated(ncode)) deallocate(ncode)
+ if (allocated(callgrid)) deallocate(callgrid)
+ if (allocated(pp)) deallocate(pp)
+ allocate(testmsg(narr))
+ allocate(ncode(63,narr))
+ allocate(callgrid(MAXCALLS))
+ allocate(pp(narr))
+
+ call dbg('build_call3_candidates: rebuilding candidate list, nlines_in_file=' // itoa(nlines_in_file) // &
+ ' MAXCALLS=' // itoa(MAXCALLS))
+ call dbg('build_call3_candidates: candidate-encoding loop STARTING at t=' // rtoa(sec_midn()))
+
+ k=0
+ icall=0
+ do n=1,MAXCALLS
+ if(n.eq.1) then
+ callsign=hiscall
+ do i=4,12
+ if(ichar(callsign(i:i)).eq.0) callsign(i:i)=' '
+ enddo
+ grid=hisgrid(1:4)
+ if(ichar(grid(3:3)).eq.0) grid(3:3)=' '
+ if(ichar(grid(4:4)).eq.0) grid(4:4)=' '
+ else
+ read(23,1002,end=20) line
+1002 format (A80)
+ if(line(1:4).eq.'ZZZZ') go to 20
+ if(line(1:2).eq.'//') go to 10
+ i1=index(line,',')
+ if(i1.lt.4) go to 10
+ i2=index(line(i1+1:),',')
+ if(i2.lt.5) go to 10
+ i2=i2+i1
+ i3=index(line(i2+1:),',')
+ if(i3.lt.1) i3=index(line(i2+1:),' ')
+ i3=i2+i3
+ callsign=line(1:i1-1)
+ grid=line(i1+1:i2-1)
+ ceme=line(i2+1:i3-1)
+ if(neme.eq.1 .and. ceme.ne.'EME') go to 10
+ endif
+
+ icall=icall+1
+ j1=index(mycall,' ') - 1
+ if(j1.le.-1) j1=12
+ if(j1.lt.3) j1=6
+ j2=index(callsign,' ') - 1
+ if(j2.le.-1) j2=12
+ if(j2.lt.3) j2=6
+ j3=index(mycall,'/') ! j3>0 means compound mycall
+ j4=index(callsign,'/') ! j4>0 means compound hiscall
+ callgrid(icall)=callsign(1:j2)
+
+ mz=1
+! Allow MyCall + HisCall + rpt (?)
+ if(n.eq.1 .and. j3.lt.1 .and. j4.lt.1 .and. callsign(1:6).ne.' ') &
+ mz=MAXRPT+1
+ do m=1,mz
+ if(m.gt.1) grid=rpt(m-1)
+ if(j3.lt.1 .and.j4.lt.1) callgrid(icall)=callsign(1:j2)//' '//grid
+ message=mycall(1:j1)//' '//callgrid(icall)
+ k=k+1
+ testmsg(k)=message
+ call encode65(message,ncode(1,k))
+
+! Insert CQ message
+ if(j4.lt.1) callgrid(icall)=callsign(1:j2)//' '//grid
+ message='CQ '//callgrid(icall)
+ k=k+1
+ testmsg(k)=message
+ call encode65(message,ncode(1,k))
+ enddo
+10 continue
+ enddo
+
+20 continue
+ ntot=k
+ cached_mycall=mycall
+ cached_hiscall=hiscall
+ cached_hisgrid=hisgrid
+ cached_neme=neme
+ call timer('deep65a ',1)
+ call dbg('build_call3_candidates: candidate-encoding loop DONE at t=' // rtoa(sec_midn()) // ' ntot=' // itoa(ntot))
+ end subroutine build_call3_candidates
+
subroutine deep65(s3,mode65,neme,flip,mycall,hiscall,hisgrid,decoded,qual,mrs,mrs2)
- use timer_module, only: timer
- use decodes_mod, only: mcall3a
- use encode65_mod
+ use timer_module, only: timer
+ use debug_log, only: dbg, itoa
implicit none
real, intent(in) :: s3(64,63)
@@ -18,110 +191,28 @@ subroutine deep65(s3,mode65,neme,flip,mycall,hiscall,hisgrid,decoded,qual,mrs,mr
real, intent(out) :: qual
integer, intent(in) :: mrs(63), mrs2(63)
-
- integer,parameter :: MAXCALLS=10000,MAXRPT=63
- character callsign*12,grid*4,message*22,c*1,ceme*3
character(len=22) bestmsg
- character(len=22) testmsg(2*MAXCALLS + 2 + MAXRPT)
- character(len=15) callgrid(MAXCALLS)
- character(len=180) line
- character(len=4) rpt(MAXRPT)
- integer ncode(63,2*MAXCALLS + 2 + MAXRPT)
- integer i,i1,i2,i3,icall,ip1,k,j,j1,j2,j3,j4,m
- integer mz,n,ntot
+ character c*1
+ integer i,ip1,j,k
real bias,p,p1,p2,ref,ref0,sum
- real pp(2*MAXCALLS + 2 + MAXRPT)
- data rpt/'-01','-02','-03','-04','-05', &
- '-06','-07','-08','-09','-10', &
- '-11','-12','-13','-14','-15', &
- '-16','-17','-18','-19','-20', &
- '-21','-22','-23','-24','-25', &
- '-26','-27','-28','-29','-30', &
- 'R-01','R-02','R-03','R-04','R-05', &
- 'R-06','R-07','R-08','R-09','R-10', &
- 'R-11','R-12','R-13','R-14','R-15', &
- 'R-16','R-17','R-18','R-19','R-20', &
- 'R-21','R-22','R-23','R-24','R-25', &
- 'R-26','R-27','R-28','R-29','R-30', &
- 'RO','RRR','73'/
+ integer :: n_g4swx, n_dg2ycb
+ data ip1/1/ ! Default safety, in case ntot ends up 0 the very first time
save
- if(mcall3a.eq.0) go to 30
- k = 0
- ntot = 0
- ip1 = 1 ! Default safety
-
- call timer('deep65a ',0)
- mcall3a=0
- rewind 23
- k=0
- icall=0
- do n=1,MAXCALLS
- if(n.eq.1) then
- callsign=hiscall
- do i=4,12
- if(ichar(callsign(i:i)).eq.0) callsign(i:i)=' '
- enddo
- grid=hisgrid(1:4)
- if(ichar(grid(3:3)).eq.0) grid(3:3)=' '
- if(ichar(grid(4:4)).eq.0) grid(4:4)=' '
- else
- read(23,1002,end=20) line
-1002 format (A80)
- if(line(1:4).eq.'ZZZZ') go to 20
- if(line(1:2).eq.'//') go to 10
- i1=index(line,',')
- if(i1.lt.4) go to 10
- i2=index(line(i1+1:),',')
- if(i2.lt.5) go to 10
- i2=i2+i1
- i3=index(line(i2+1:),',')
- if(i3.lt.1) i3=index(line(i2+1:),' ')
- i3=i2+i3
- callsign=line(1:i1-1)
- grid=line(i1+1:i2-1)
- ceme=line(i2+1:i3-1)
- if(neme.eq.1 .and. ceme.ne.'EME') go to 10
- endif
+ call build_call3_candidates(mycall, hiscall, hisgrid, neme)
- icall=icall+1
- j1=index(mycall,' ') - 1
- if(j1.le.-1) j1=12
- if(j1.lt.3) j1=6
- j2=index(callsign,' ') - 1
- if(j2.le.-1) j2=12
- if(j2.lt.3) j2=6
- j3=index(mycall,'/') ! j3>0 means compound mycall
- j4=index(callsign,'/') ! j4>0 means compound hiscall
- callgrid(icall)=callsign(1:j2)
-
- mz=1
-! Allow MyCall + HisCall + rpt (?)
- if(n.eq.1 .and. j3.lt.1 .and. j4.lt.1 .and. callsign(1:6).ne.' ') &
- mz=MAXRPT+1
- do m=1,mz
- if(m.gt.1) grid=rpt(m-1)
- if(j3.lt.1 .and.j4.lt.1) callgrid(icall)=callsign(1:j2)//' '//grid
- message=mycall(1:j1)//' '//callgrid(icall)
- k=k+1
- testmsg(k)=message
- call encode65(message,ncode(1,k))
-
-! Insert CQ message
- if(j4.lt.1) callgrid(icall)=callsign(1:j2)//' '//grid
- message='CQ '//callgrid(icall)
- k=k+1
- testmsg(k)=message
- call encode65(message,ncode(1,k))
- enddo
-10 continue
- enddo
-
-20 continue
- ntot=k
- call timer('deep65a ',1)
-
-30 continue
+ ! TEMP diagnostic 2026-09-10: confirm whether the currently-loaded candidate
+ ! list (whether just rebuilt or reused from cache) actually contains the
+ ! callsigns known to be in CALL3.TXT right now.
+ n_g4swx = 0
+ n_dg2ycb = 0
+ do k = 1, ntot
+ if (index(testmsg(k), 'G4SWX') > 0) n_g4swx = n_g4swx + 1
+ if (index(testmsg(k), 'DG2YCB') > 0) n_dg2ycb = n_dg2ycb + 1
+ end do
+ call dbg('deep65: about to score, ntot=' // itoa(ntot) // &
+ ' n_g4swx_in_list=' // itoa(n_g4swx) // &
+ ' n_dg2ycb_in_list=' // itoa(n_dg2ycb))
call timer('deep65b ',0)
ref0=0.
do j=1,63
@@ -180,6 +271,11 @@ subroutine deep65(s3,mode65,neme,flip,mycall,hiscall,hisgrid,decoded,qual,mrs,mr
endif
decoded(22:22)=c
+ ! TEMP diagnostic 2026-09-10.
+ call dbg('deep65: result ip1=' // itoa(ip1) // ' p1=' // itoa(nint(100*p1)) // &
+ ' p2=' // itoa(nint(100*p2)) // ' bias=' // itoa(nint(100*bias)) // &
+ ' qual=' // itoa(nint(qual)) // ' bestmsg="' // trim(testmsg(max(ip1,1))) // '"')
+
! Make sure everything is upper case.
do i=1,22
if(decoded(i:i).ge.'a' .and. decoded(i:i).le.'z') &
diff --git a/map65/libm65/display.f90 b/map65/libm65/display.f90
index a7f71175..901313c8 100644
--- a/map65/libm65/display.f90
+++ b/map65/libm65/display.f90
@@ -6,6 +6,8 @@ subroutine display(nkeep, ftol)
use stdout_channel_mod, only: write_stdout
use iso_fortran_env, only: real64
use indexx_mod, only: indexx
+ use debug_log, only: dbg, itoa, rtoa
+ use sec_midn_mod, only: sec_midn
implicit none
! Arguments
@@ -27,7 +29,7 @@ subroutine display(nkeep, ftol)
! Hz offset within kHz) alongside cfreq0 in the "&" bandmap line.
! The C++ overlay handler (mainwindow.cpp processStdOut) reads
! both fields and places the tick at nkHz + ndf/1000 instead of
- ! integer kHz, which was up to ±500 Hz off on signals with
+ ! integer kHz, which was up to �500 Hz off on signals with
! non-zero ndf.
character(len=18) :: freqcall(MAXCALLS)
@@ -51,6 +53,12 @@ subroutine display(nkeep, ftol)
callsign0 = ' '
freqcall = ' '
+ ! TEMP diagnostic 2026-09-10 for the "decode reaches map65_rx.log but not
+ ! the Messages window" investigation -- this is the entry point for the
+ ! ENTIRE "@"/"&" (Messages/Band Map window) pipeline; nothing gets to
+ ! those windows except through here.
+ call dbg('display: ENTRY at t=' // rtoa(sec_midn()) // ' nkeep=' // itoa(nkeep))
+
!------------------ Read and filter valid lines ---------------------
rewind(26)
nz = 0
@@ -66,12 +74,16 @@ subroutine display(nkeep, ftol)
utc(i) = 60*nh + nm
freqkHz(i) = 1000.d0*(f0 - 144.d0) + 0.001d0*ndf
enddo
-
+
10 backspace(26)
nz = i -1
- utcz = utc(nz)
+ call dbg('display: read from unit 26, raw record count nz=' // itoa(nz))
+ if (nz >= 1) utcz = utc(nz)
nz=nz-1
- if (nz < 1) return
+ if (nz < 1) then
+ call dbg('display: EARLY RETURN, nz<1 after decrement -- no records to emit')
+ return
+ endif
nquad = max(nkeep/4, 3)
do i = 1, nz
nage = utcz - utc(i)
@@ -101,6 +113,18 @@ subroutine display(nkeep, ftol)
write(26,1022) line(i)
1022 format(a83)
enddo
+ ! Rewriting fewer records than the file previously held does not
+ ! shrink it -- the old, longer tail stays on disk past this point.
+ ! Without truncating here, a later rewind+read pass reads straight
+ ! through into that stale leftover data and resurrects entries this
+ ! trim was supposed to drop for good, causing unbounded growth of
+ ! the Messages window over a long session regardless of nkeep.
+ ! endfile leaves the file positioned after the EOF marker it just
+ ! wrote, and Fortran forbids further sequential I/O from there
+ ! without repositioning first -- backspace moves back onto that
+ ! marker so the next append (map65a.f90/q65b.F90) can write there.
+ endfile(26)
+ backspace(26)
endif
flush(26)
@@ -167,6 +191,7 @@ subroutine display(nkeep, ftol)
cfreq0=' '
nc = 0
callsign0=' '
+ call dbg('display: about to walk k3=' // itoa(k3) // ' sorted records for "@" emission')
do k = 1, k3
out = line3(k)(1:13)//line3(k)(28:31)//line3(k)(39:45)// &
line3(k)(35:38)//line3(k)(46:80)
@@ -180,7 +205,14 @@ subroutine display(nkeep, ftol)
livecq3 = out(1:61)//' '//livecq2(23:27)//' '//livecq2(79:83)
write(linenew,'("@",A)') trim(livecq3)
call write_stdout(trim(linenew)//new_line('a'))
+ call dbg('display: k=' // itoa(k) // ' "@" EMITTED freq=' // out(6:8) // &
+ ' utc=' // out(19:22) // ' msg="' // trim(out(31:55)) // '"')
out0 = out
+ else
+ call dbg('display: k=' // itoa(k) // ' "@" SUPPRESSED (matches out0) freq=' // out(6:8) // &
+ ' utc=' // out(19:22) // ' msg="' // trim(out(31:55)) // &
+ '" -- out0 was freq=' // out0(6:8) // ' utc=' // out0(19:22) // &
+ ' msg="' // trim(out0(31:55)) // '"')
endif
i1 = index(out(31:), ' ')
@@ -201,8 +233,11 @@ subroutine display(nkeep, ftol)
freqcall(nc) = cfreq0//line3(k)(9:13)//' '//callsign//line3(k)(79:80)
endif
endif
+ else
+ call dbg('display: k=' // itoa(k) // ' SKIPPED entirely (out(6:8) blank -- not a frequency record)')
endif
enddo
+ call dbg('display: done, nc(bandmap entries)=' // itoa(nc))
if(nc.lt.MAXCALLS) nc=nc+1
freqcall(nc)=' '
diff --git a/map65/libm65/extract.f90 b/map65/libm65/extract.f90
index 5c5c9033..c6b3345b 100644
--- a/map65/libm65/extract.f90
+++ b/map65/libm65/extract.f90
@@ -2,6 +2,17 @@ module extract_mod
implicit none
contains
+pure logical function jt65_candidate_is_consistent(nhard,ntotal,rtt,matched_power)
+ integer, intent(in) :: nhard,ntotal
+ real, intent(in) :: rtt,matched_power
+ logical :: high_power_mismatch,ambiguous_high_burden
+
+ high_power_mismatch=nhard.ge.42 .and. matched_power.ge.8.0
+ ambiguous_high_burden=ntotal.ge.80 .and. &
+ (matched_power.ge.7.5 .or. rtt.ge.0.87)
+ jt65_candidate_is_consistent=.not.(high_power_mismatch .or. ambiguous_high_burden)
+end function jt65_candidate_is_consistent
+
subroutine extract(s3,nadd,ncount,nhist,decoded,ltext,mrs,mrs2)
use iso_c_binding, only: c_int
@@ -36,7 +47,7 @@ subroutine extract(s3,nadd,ncount,nhist,decoded,ltext,mrs,mrs2)
integer :: i,ipk,naggressive,ncandidates,nd0,nerased,nfail,n
integer :: nft,nhard,nlow,nsec1,nsoft,ntest,ntotal,ntrials
integer(c_int) :: ntry(1)
- real :: base,qual,r00,rtt
+ real :: base,matched_power,qual,r00,rtt
! 0 1 2 3 4 5 6 7 8 9 10 11
data h0/41,42,43,43,44,45,46,47,48,48,49,49/
@@ -95,6 +106,7 @@ subroutine extract(s3,nadd,ncount,nhist,decoded,ltext,mrs,mrs2)
rtt=0.001*param(4)
ntotal=param(5)
qual=0.001*param(7)
+ matched_power=0.001*param(8)
nd0=81
r00=0.87
if(naggressive.eq.10) then
@@ -107,6 +119,7 @@ subroutine extract(s3,nadd,ncount,nhist,decoded,ltext,mrs,mrs2)
if(nhard.gt.h0(n)) nft=0
if(ntotal.gt.d0(n)) nft=0
if(rtt.gt.r0(n)) nft=0
+ if(.not.jt65_candidate_is_consistent(nhard,ntotal,rtt,matched_power)) nft=0
ncount=-1
decoded=' '
@@ -117,17 +130,17 @@ subroutine extract(s3,nadd,ncount,nhist,decoded,ltext,mrs,mrs2)
do i=1,12
dat4(i)=correct(13-i)
enddo
+ if (.not. is_valid_jt65_codeword(dat4)) then
+ nft=0
+ go to 900
+ endif
do i=1,63
itmp(i)=correct(64-i)
enddo
correct(1:63)=itmp(1:63)
call interleave63(correct,1)
call graycode65(correct,63,1)
- ! write(*,*) 'EXTRACT: nft=', nft, ' ncount=', ncount, ' nhist=', nhist
- ! write(*,*) 'EXTRACT: correct(1:20) = ', correct(1:20)
- ! write(*,*) 'EXTRACT: dat4(1:12) = ', dat4
call unpackmsg(dat4, decoded) !Unpack the user message
-! write(*,*) 'EXTRACT: decoded = "', decoded, '"'
ncount=0
if(iand(dat4(10),8).ne.0) ltext=.true.
endif
diff --git a/map65/libm65/fchisq.f90 b/map65/libm65/fchisq.f90
index 15a7d4d1..4d0a5ae0 100644
--- a/map65/libm65/fchisq.f90
+++ b/map65/libm65/fchisq.f90
@@ -13,28 +13,20 @@ real function fchisq(cx, cy, npts, fsample, nflip, a, ccfmax, dtmax)
integer, intent(in) :: npts, nflip
complex, intent(in) :: cx(npts), cy(npts)
real, intent(in) :: fsample
- real, intent(inout) :: a(5) ! a(1:3) used for AFC, a(4) for pol
+ real, intent(inout) :: a(5)
real, intent(out) :: ccfmax, dtmax
- !==== Local parameters =====================================================
- integer, parameter :: NMAX = 60*96000
-
!==== Local variables ======================================================
- complex :: w, wstep = (1.0, 0.0), za, zb, z
- real :: ss(3000)
- complex :: csx(0:NMAX/64), csy(0:NMAX/64)
+ complex :: w, wstep, za, zb, z
+ real, allocatable :: ss(:)
+ complex, allocatable :: csx(:), csy(:)
integer :: i, j, k, lagpk
integer :: ndiv, nout, nsph, nsps
- real :: a1, a2, a3
real :: dphi, dtstep, fac
real :: p2, pol, s, twopi, x, x0, baud
- !==== Saved state (explicitly initialized) =================================
- save a1, a2, a3
- data a1, a2, a3 / 99.0, 99.0, 99.0 /
-
!==== Initialize outputs ===================================================
ccfmax = 0.0
dtmax = 0.0
@@ -44,50 +36,48 @@ real function fchisq(cx, cy, npts, fsample, nflip, a, ccfmax, dtmax)
baud = 11025.0 / 4096.0
!==== Symbol timing ========================================================
- nsps = nint(fsample / baud) ! samples per symbol
- nsph = nsps / 2 ! samples per half-symbol
- ndiv = 16 ! ss() steps per symbol
- nout = ndiv * npts / nsps
+ nsps = nint(fsample / baud)
+ nsph = nsps / 2
+ ndiv = 16
+ nout = ndiv * npts / nsps
dtstep = 1.0 / (ndiv * baud)
+ !==== Allocate buffers =====================================================
+ allocate(csx(0:npts), csy(0:npts))
call timer('fchisq ', 0)
!===========================================================================
- ! MIX AND INTEGRATE (only if a(1:3) changed)
+ ! MIX AND INTEGRATE (always recompute)
!===========================================================================
- if (a(1) /= a1 .or. a(2) /= a2 .or. a(3) /= a3) then
- a1 = a(1)
- a2 = a(2)
- a3 = a(3)
+ csx(0) = (0.0, 0.0)
+ csy(0) = (0.0, 0.0)
- csx(0) = (0.0, 0.0)
- csy(0) = (0.0, 0.0)
+ wstep = (1.0, 0.0)
+ w = (1.0, 0.0)
+ x0 = 0.5*(npts + 1)
+ s = 2.0 / npts
- w = (1.0, 0.0)
- x0 = 0.5*(npts + 1)
- s = 2.0 / npts
+ do i = 1, npts
+ x = s*(i - x0)
- do i = 1, npts
- x = s*(i - x0)
-
- if (mod(i,100) == 1) then
- p2 = 1.5*x*x - 0.5
- dphi = (a(1) + x*a(2) + p2*a(3)) * (twopi/fsample)
- wstep = cmplx(cos(dphi), sin(dphi))
- end if
+ if (mod(i,100) == 1) then
+ p2 = 1.5*x*x - 0.5
+ dphi = (a(1) + x*a(2) + p2*a(3)) * (twopi/fsample)
+ wstep = cmplx(cos(dphi), sin(dphi))
+ end if
- w = w * wstep
- csx(i) = csx(i-1) + w*cx(i)
- csy(i) = csy(i-1) + w*cy(i)
- end do
- end if
+ w = w * wstep
+ csx(i) = csx(i-1) + w*cx(i)
+ csy(i) = csy(i-1) + w*cy(i)
+ end do
!===========================================================================
! COMPUTE HALF-SYMBOL POWERS
!===========================================================================
fac = 1.0e-4
pol = a(4) / 57.2957795
- ss = 0.0
+ allocate(ss(nout))
+ ss = 0.0
do i = 1, nout
j = i*nsps/ndiv
@@ -111,8 +101,12 @@ real function fchisq(cx, cy, npts, fsample, nflip, a, ccfmax, dtmax)
dtmax = lagpk * dtstep
fchisq = -ccfmax
- call timer('fchisq ', 1)
+ !==== Cleanup ==============================================================
+ deallocate(ss)
+ deallocate(csx, csy)
+ call timer('fchisq ', 1)
end function fchisq
end module fchisq_mod
+
diff --git a/map65/libm65/filbig.f90 b/map65/libm65/filbig.f90
index 79f49a8d..bfbaf7a5 100644
--- a/map65/libm65/filbig.f90
+++ b/map65/libm65/filbig.f90
@@ -4,17 +4,26 @@ module filbig_mod
use timer_module, only: timer
use debug_log
use cacb_mod
+ use npar_ptrs_mod, only: nrate_active, nfft_big_active
use fftw3_constants
use fftw3_f77_interfaces
+ use sec_midn_mod, only: sec_midn
implicit none
+
+ integer, parameter :: MAXFFT1 = 56*192000
+ integer, parameter :: MAXFFT2 = 2*77175
+
+ complex, save :: c4a_buf(MAXFFT2), c4b_buf(MAXFFT2), cfilt_buf(MAXFFT2)
+ integer(c_intptr_t), save :: plan1, plan2, plan3, plan4, plan5
+ logical, save :: filbig_first = .true.
+
contains
subroutine filbig(dd, nmax, f0, newdat, nfsample, xpol, c4a, c4b, n4)
! Filter and downsample complex data stored in array dd(4,nmax).
- ! Output is downsampled from 96000 Hz to 1375.125 Hz.
+ ! Output is downsampled from nrate_active Hz to 1378.125 Hz (same decimation ratio as 96 kHz).
- integer, parameter :: MAXFFT1 = 5376000, MAXFFT2 = 77175
integer, intent(in) :: nmax
real(real32), intent(in) :: dd(4, nmax)
real(real64), intent(in) :: f0
@@ -28,27 +37,61 @@ contains
real halfpulse(8) !Impulse response (one sided)
real base, fac, filtval
integer i, i0, j, nfft1, nfft2, nflags, nh, npatience, nz
- complex cfilt(MAXFFT2) !Filter in frequency domain
- integer(c_intptr_t) plan1, plan2, plan3, plan4, plan5
- logical first
- data first/.true./, npatience/1/
+ real(real64) :: decim
+ ! Filter in frequency domain; sized at max short-FFT length
+ data npatience/1/
data halfpulse/114.97547150, 36.57879257, -20.93789101, &
5.89886379, 1.59355187, -2.49138308, 0.60910773, -0.04248129/
save
- call init_cacb(5376000)
+ ! ca/cb storage is sized at MAXFFT1 in cacb_mod; the *active* big FFT
+ ! length is nfft_big_active, set from C++ via set_runtime_params_().
+ call init_cacb(MAXFFT1)
if (nmax .lt. 0) go to 900
- nfft1 = MAXFFT1
- nfft2 = MAXFFT2
+ ! Runtime big-FFT length: nfft_big_active is 56 * nrate_active, set
+ ! from C++ at startup. Clamp to MAXFFT1 for safety.
+ nfft1 = min(56*nrate_active, MAXFFT1)
+ decim = real(nrate_active, kind=real64) / 1378.125_real64
+ ! Preserve the original decimation ratio between nfft1 and nfft2.
+ ! At 96 kHz: nfft1 = 5376000, nfft2 = 77175 ? ratio � 69.64
+ ! At 192 kHz: nfft1 doubles, so nfft2 should double to keep the
+ ! same time span / bandwidth in the downsampled stream.
+ !
+ ! Use the 96 kHz baseline ratio to derive nfft2 for any rate:
+ ! nfft2 � nfft1 * (77175 / 5376000)
+
+ ! Choose nfft2 so that the time span in c4a is the same as in the 96 kHz case
+ ! Baseline: at 96 kHz, nfft1=5,376,000, nfft2=77,175
+ ! nfft2 = int( real(nfft1, kind=real64) * 77175.0_real64 / 5376000.0_real64 )
+ nfft2 = int(MAXFFT2/2)
+ nfft2 = min(nfft2, MAXFFT2)
+ if (nfft2 .gt. MAXFFT2) nfft2 = MAXFFT2
+
+ ! Preserve the legacy 95238 special case (Linrad odd rate); if you
+ ! still use it, override the derived sizes with the historical ones.
if (nfsample .eq. 95238) then
- nfft1 = 5120000
- nfft2 = 74088
+ nfft1 = min(5120000, MAXFFT1)
+ nfft2 = min(74088, MAXFFT2)
endif
- if (first) then
+ if (filbig_first) then
+ ! TEMP diagnostic 2026-09-10 for the "first decode cycle after
+ ! startup is degraded/missing" investigation. filbig_first is a
+ ! module-SAVEd flag -- true exactly once, for the life of the
+ ! process -- so this whole block runs on the very first filbig()
+ ! call and never again. That happens to line up exactly with when
+ ! the anomaly has been observed. FFTW plan creation (even the cheap
+ ! ESTIMATE_PATIENT mode used below) still does real work for a
+ ! multi-million-point transform; if it takes long enough to run
+ ! synchronously on this thread, it could delay real-time audio
+ ! capture on the GUI/audio thread for that whole span. Time it
+ ! directly rather than assuming either way.
+ call dbg('filbig: FIRST-EVER CALL, starting FFTW plan creation at t=' // rtoa(sec_midn()) // &
+ ' nfft1=' // itoa(nfft1) // ' nfft2=' // itoa(nfft2))
+
nflags = FFTW_ESTIMATE
if (npatience .eq. 1) nflags = FFTW_ESTIMATE_PATIENT
if (npatience .eq. 2) nflags = FFTW_MEASURE
@@ -56,31 +99,35 @@ contains
if (npatience .eq. 4) nflags = FFTW_EXHAUSTIVE
! Plan the FFTs just once
- call timer('FFTplans ', 0)
+ call timer('FFTplans', 0)
call sfftw_plan_dft_1d(plan1, nfft1, ca, ca, FFTW_BACKWARD, nflags)
call sfftw_plan_dft_1d(plan2, nfft1, cb, cb, FFTW_BACKWARD, nflags)
- call sfftw_plan_dft_1d(plan3, nfft2, c4a, c4a, FFTW_FORWARD, nflags)
- call sfftw_plan_dft_1d(plan4, nfft2, c4b, c4b, FFTW_FORWARD, nflags)
- call sfftw_plan_dft_1d(plan5, nfft2, cfilt, cfilt, FFTW_BACKWARD, nflags)
- call timer('FFTplans ', 1)
+ call sfftw_plan_dft_1d(plan3, nfft2, c4a_buf, c4a_buf, FFTW_FORWARD, nflags)
+ call sfftw_plan_dft_1d(plan4, nfft2, c4b_buf, c4b_buf, FFTW_FORWARD, nflags)
+ call sfftw_plan_dft_1d(plan5, nfft2, cfilt_buf,cfilt_buf,FFTW_BACKWARD, nflags)
+ call timer('FFTplans', 1)
+ call dbg('filbig: FFTW plan creation DONE at t=' // rtoa(sec_midn()))
! Convert impulse response to filter function
do i = 1, nfft2
- cfilt(i) = 0.0
+ cfilt_buf(i) = 0.0
enddo
fac = 0.00625/nfft1
- cfilt(1) = fac*halfpulse(1)
+ cfilt_buf(1) = fac*halfpulse(1)
do i = 2, 8
- cfilt(i) = fac*halfpulse(i)
- cfilt(nfft2 + 2 - i) = fac*halfpulse(i)
+ cfilt_buf(i) = fac*halfpulse(i)
+ cfilt_buf(nfft2 + 2 - i) = fac*halfpulse(i)
enddo
call sfftw_execute(plan5)
- base = real(cfilt(nfft2/2 + 1))
+ base = real(cfilt_buf(nfft2/2 + 1))
- df = 96000.d0/nfft1
- if (nfsample .eq. 95238) df = 95238.1d0/nfft1
- first = .false.
+ ! Bin width of the big FFT: use the active runtime rate instead
+ ! of a hardcoded 96000. The 95238 special case is preserved.
+ df = dble(nrate_active)/dble(nfft1)
+ if (nfsample .eq. 95238) df = 95238.1d0/dble(nfft1)
+ filbig_first = .false.
+ call dbg('filbig: entire one-time init (plans + filter) DONE at t=' // rtoa(sec_midn()))
endif
! When new data comes along, we need to compute a new "big FFT"
@@ -116,12 +163,12 @@ contains
do i = 1, nh
j = i0 + i - 1
if (j .ge. 1 .and. j .le. nfft1) then
- filtval = real(cfilt(i)) - base
- c4a(i) = filtval*ca(j)
- if (xpol) c4b(i) = filtval*cb(j)
+ filtval = real(cfilt_buf(i)) - base
+ c4a_buf(i) = filtval*ca(j)
+ if (xpol) c4b_buf(i) = filtval*cb(j)
else
- c4a(i) = 0.0
- if (xpol) c4b(i) = 0.0
+ c4a_buf(i) = 0.0
+ if (xpol) c4b_buf(i) = 0.0
endif
enddo
@@ -137,9 +184,9 @@ contains
stop 'FILBIG index OOB'
end if
- filtval = real(cfilt(i)) - base
- c4a(i) = filtval*ca(j)
- if (xpol) c4b(i) = filtval*cb(j)
+ filtval = real(cfilt_buf(i)) - base
+ c4a_buf(i) = filtval*ca(j)
+ if (xpol) c4b_buf(i) = filtval*cb(j)
enddo
! Do the short reverse transform, to go back to time domain.
@@ -147,7 +194,18 @@ contains
call sfftw_execute(plan3)
if (xpol) call sfftw_execute(plan4)
call timer('FFTsmall', 1)
- n4 = min(nmax/64, nfft2)
+
+ c4a(1:nfft2) = c4a_buf(1:nfft2)
+ if (xpol) then
+ c4b(1:nfft2) = c4b_buf(1:nfft2)
+ else
+ c4b(1:nfft2) = 0.0
+ endif
+
+ ! Number of valid output samples at ~1375 Hz
+ n4 = min( int( real(nmax, kind=real64) / decim ), nfft2 )
+ n4 = min( int( real(nmax, kind=real64) / decim ), nfft2 )
+
go to 999
900 call sfftw_destroy_plan(plan1)
diff --git a/map65/libm65/four2a.f90 b/map65/libm65/four2a.f90
index ad1da4a1..91be0f48 100644
--- a/map65/libm65/four2a.f90
+++ b/map65/libm65/four2a.f90
@@ -81,7 +81,8 @@ contains
nflags = FFTW_ESTIMATE
if (nfft <= NSMALL) then
- jz = merge(nfft/2, nfft, iform == 0)
+ jz = nfft
+ if (iform <= 0) jz = nfft/2 + 1
aa(1:jz) = a(1:jz)
endif
diff --git a/map65/libm65/four2a_legacy_wrap.f90 b/map65/libm65/four2a_legacy_wrap.f90
index f95a0589..d2c0028b 100644
--- a/map65/libm65/four2a_legacy_wrap.f90
+++ b/map65/libm65/four2a_legacy_wrap.f90
@@ -2,81 +2,76 @@ module four2a_legacy_wrap_mod
use iso_c_binding
use four2a_mod, only: four2a
implicit none
+
+ integer, parameter :: JT65_NFFT = 512
+ integer, parameter :: JT65_NH = JT65_NFFT/2
contains
-subroutine r2c_legacy(s_real, cs_half, nfft)
+subroutine r2c_legacy(s_real, cs_half)
use iso_c_binding
use four2a_mod, only: four2a
implicit none
- integer, intent(in) :: nfft
- real, intent(in) :: s_real(nfft)
- complex, intent(out) :: cs_half(0:nfft/2)
+ real, intent(in) :: s_real(JT65_NFFT)
+ complex, intent(out) :: cs_half(0:JT65_NH)
- integer :: nh, k
+ integer :: k
integer(c_int) :: nfft_c, ndim_c, isign_c, iform_c
- nh = nfft/2
-
block
- ! full complex buffer: nfft complex → 2*nfft reals
- real(c_float), target :: work(2*nfft)
+ real(c_float), save, target :: work(2*(JT65_NH+1))
complex(c_float_complex), pointer :: work_c(:)
- call c_f_pointer(c_loc(work), work_c, [nfft])
+ call c_f_pointer(c_loc(work), work_c, [JT65_NH+1])
- ! real input → first nfft reals
- work(1:nfft) = real(s_real(1:nfft), kind=c_float)
+ work(1:JT65_NFFT) = real(s_real, kind=c_float)
- nfft_c = nfft
+ nfft_c = JT65_NFFT
ndim_c = 1
isign_c = 1
iform_c = 0
call four2a(work_c, nfft_c, ndim_c, isign_c, iform_c)
- ! packed half-spectrum: cs_half(0..nh) ↔ work_c(1..nh+1)
- do k = 0, nh
+ do k = 0, JT65_NH
cs_half(k) = cmplx(real(work_c(k+1)), aimag(work_c(k+1)))
enddo
end block
end subroutine r2c_legacy
-subroutine c2r_legacy(cs_half, s_real, nfft)
+subroutine c2r_legacy(cs_half, s_real)
use iso_c_binding
use four2a_mod, only: four2a
implicit none
- integer, intent(in) :: nfft
- complex, intent(in) :: cs_half(0:nfft/2)
- real, intent(out) :: s_real(nfft)
+ complex, intent(in) :: cs_half(0:JT65_NH)
+ real, intent(out) :: s_real(JT65_NFFT)
- integer :: nh, k
+ integer :: k
integer(c_int) :: nfft_c, ndim_c, isign_c, iform_c
- nh = nfft/2
-
block
- real(c_float), target :: work(2*nfft)
+ real(c_float), target :: work(2*(JT65_NH+1))
complex(c_float_complex), pointer :: work_c(:)
- call c_f_pointer(c_loc(work), work_c, [nfft])
+ call c_f_pointer(c_loc(work), work_c, [JT65_NH+1])
! load packed half-spectrum: cs_half(0..nh) → work_c(1..nh+1)
- do k = 0, nh
+ do k = 0, JT65_NH
work_c(k+1) = cmplx(real(cs_half(k), kind=c_float), &
aimag(cs_half(k)), kind=c_float)
enddo
- nfft_c = nfft
+ ! c2r: iform = -1
+ nfft_c = JT65_NFFT
ndim_c = 1
isign_c = 1
iform_c = -1
call four2a(work_c, nfft_c, ndim_c, isign_c, iform_c)
! real output in first nfft reals
- s_real(1:nfft) = real(work(1:nfft))
+ s_real = real(work(1:JT65_NFFT))
end block
-end subroutine c2r_legacy
+end subroutine c2r_legacy
end module four2a_legacy_wrap_mod
diff --git a/map65/libm65/ftnquit.f90 b/map65/libm65/ftnquit.f90
index 573b2536..7543c19e 100644
--- a/map65/libm65/ftnquit.f90
+++ b/map65/libm65/ftnquit.f90
@@ -2,14 +2,14 @@ module ftnquit_mod
use filbig_mod
use four2a_mod
use iso_fortran_env, only: real64, real32
+ use filbig_mod, only: MAXFFT2
+
implicit none
contains
subroutine ftnquit
implicit none
- integer, parameter :: MAXFFT2 = 77175
-
real(real32) :: dd_dummy(1,1)
integer :: nmax_dummy = -1
real(real64) :: f0_dummy = 0.0d0
diff --git a/map65/libm65/ftrsd2.c b/map65/libm65/ftrsd2.c
index 7d8dd366..f281e72d 100644
--- a/map65/libm65/ftrsd2.c
+++ b/map65/libm65/ftrsd2.c
@@ -132,15 +132,14 @@ codeword is "best".
jj = (62-i)/8;
thresh0[i] = 1.3*perr[ii][jj];
}
- if(nsum<=0) return;
-
pp1=0.0;
pp2=0.0;
+ if (nsum>0) {
for (k=1; k<=ntrials; k++) {
memset(era_pos,0,51*sizeof(int));
memcpy(workdat,rxdat,sizeof(rxdat));
-/*
+/*
Mark a subset of the symbols as erasures.
Run through the ranked symbols, starting with the worst, i=0.
NB: j is the symbol-vector index of the symbol with rank i.
@@ -162,10 +161,10 @@ NB: j is the symbol-vector index of the symbol with rank i.
}
}
- nerr=decode_rs_int(rs,workdat,era_pos,numera,0);
+ nerr=decode_rs_int(rs,workdat,era_pos,numera,0);
if( nerr >= 0 ) {
// We have a candidate codeword. Find its hard and soft distance from
- // the received word. Also find pp1 and pp2 from the full array
+ // the received word. Also find pp1 and pp2 from the full array
// s3(64,63) of synchronized symbol spectra.
ncandidates=ncandidates+1;
nhard=0;
@@ -198,7 +197,15 @@ NB: j is the symbol-vector index of the symbol with rank i.
}
if(k == ntrials) ntry[0]=k;
}
-
+ }
+ // nsum<=0 (or no erasure trial found a valid codeword) falls through to
+ // here with ncandidates==0 and the *_min sentinels left at their "nothing
+ // found" initial values (32768) -- previously this case (nsum<=0) hit an
+ // early "return;" that skipped writing param[]/correct[]/ntry[] entirely,
+ // leaving the caller's pre-call param=0 in place, which incorrectly read
+ // as an accepted decode (ntotal=0 trivially clears the accept threshold)
+ // and unpacked whatever garbage was sitting in the uninitialized
+ // "correct" array as if it were a real message.
param[0]=ncandidates;
param[1]=nhard_min;
param[2]=nsoft_min;
diff --git a/map65/libm65/ftrsd2_mod.f90 b/map65/libm65/ftrsd2_mod.f90
index ad716070..0737e9c0 100644
--- a/map65/libm65/ftrsd2_mod.f90
+++ b/map65/libm65/ftrsd2_mod.f90
@@ -4,9 +4,9 @@ module ftrsd2_mod
interface
subroutine ftrsd2_(mrsym, mrprob, mr2sym, mr2prob, ntrials0, correct, param, ntry) bind(C, name="ftrsd2_")
use iso_c_binding
- integer(c_int), intent(in) :: mrsym(*), mrprob(*), mr2sym(*), mr2prob(*)
- integer(c_int), intent(in) :: ntrials0
- integer(c_int), intent(in) :: correct(*), param(*), ntry(*)
+ integer(c_int), intent(in) :: mrsym(*), mrprob(*), mr2sym(*), mr2prob(*)
+ integer(c_int), intent(in) :: ntrials0
+ integer(c_int), intent(out) :: correct(*), param(*), ntry(*)
end subroutine ftrsd2_
end interface
end module ftrsd2_mod
diff --git a/map65/libm65/gen65.f90 b/map65/libm65/gen65.f90
index 46f591f9..0be99fc4 100644
--- a/map65/libm65/gen65.f90
+++ b/map65/libm65/gen65.f90
@@ -178,7 +178,7 @@ subroutine gen65_c(msg, mode65, samfac, nsendingsh, msgsent_c, iwave_c, nwave) &
! Fortran locals
character(len=22) :: fmsg, fmsgsent
- integer(2), dimension(2*60*11025) :: fiwave
+ integer(2), save :: fiwave(2*60*11025)
integer :: i
! Copy C msg ? Fortran CHARACTER(22)
diff --git a/map65/libm65/gen_q65_cwave.f90 b/map65/libm65/gen_q65_cwave.f90
index 474e291f..2f5c1262 100644
--- a/map65/libm65/gen_q65_cwave.f90
+++ b/map65/libm65/gen_q65_cwave.f90
@@ -2,28 +2,28 @@ module gen_q65_cwave_mod
implicit none
contains
-subroutine gen_q65_cwave(msg,ntxfreq,ntone_spacing,msgsent,cwave,nwave)
+subroutine gen_q65_cwave(msg,ntxfreq,ntone_spacing,fsample,msgsent,cwave,nwave)
use packjt
use q65_encoding
use iso_fortran_env, only: real64
- integer, parameter :: NMAX = 60*96000
-
!--------------------------------------------------------------------
! Arguments (with correct intent and explicit types)
!--------------------------------------------------------------------
+ ! fsample is the actual sample rate in Hz
+ real(real64), intent(in) :: fsample
character*24, intent(in) :: msg
integer, intent(in) :: ntxfreq
integer, intent(in) :: ntone_spacing
character*24, intent(out) :: msgsent
- complex, intent(out) :: cwave(NMAX)
+ complex, intent(out) :: cwave(:)
integer, intent(out) :: nwave
!--------------------------------------------------------------------
! Local character variables
!--------------------------------------------------------------------
- character*37 :: msg37
+ character*37 :: msg37,msgsent37
!--------------------------------------------------------------------
! Explicit declarations for all formerly implicit variables
@@ -37,6 +37,7 @@ subroutine gen_q65_cwave(msg,ntxfreq,ntone_spacing,msgsent,cwave,nwave)
! Explicit locals
integer :: codeword(65), itone(85)
integer :: icos7(0:6)
+ logical :: success
data icos7 /2,5,6,0,4,1,3/
data twopi /6.283185307179586476d0/
@@ -45,31 +46,36 @@ subroutine gen_q65_cwave(msg,ntxfreq,ntone_spacing,msgsent,cwave,nwave)
!--------------------------------------------------------------------
! Begin logic (unchanged from legacy)
!--------------------------------------------------------------------
- msgsent = msg
msg37 = ''
msg37(1:24) = msg
- call get_q65_tones(msg37, codeword, itone)
+ call get_q65_tones(msg37, codeword, itone, msgsent37, success)
+ msgsent = msgsent37(1:len(msgsent))
+ if(.not.success) then
+ cwave=0
+ nwave=0
+ return
+ endif
! Constants
nsym = 85
- tsym = 7200.d0 / 12000.d0
- dt = 1.d0 / 96000.d0
+ tsym = 7200.d0 / 12000.d0 ! symbol duration (unchanged)
+ dt = 1.d0 / fsample ! sample interval
f0 = ntxfreq
- dfgen = ntone_spacing * 12000.d0 / 7200.d0
+ dfgen = ntone_spacing * 12000.d0 / 7200.d0 ! tone spacing in Hz (unchanged)
phi = 0.d0
dphi = twopi * dt * f0
- nwave = 85 * 7200 * 96000.d0 / 12000.d0
+ ! total samples for the 85-symbol Q65-60A waveform
+ nwave = int( nsym * tsym * fsample + 0.5d0 )
t = 0.d0
j0 = 0
do i = 1, nwave
t = t + dt
- j = t/tsym + 1
- if (j > 85) exit
+ j = min(nsym, int(t/tsym) + 1)
if (j /= j0) then
f = f0 + itone(j) * dfgen
diff --git a/map65/libm65/gen_q65_wave.f90 b/map65/libm65/gen_q65_wave.f90
index 38757113..cfdd04da 100644
--- a/map65/libm65/gen_q65_wave.f90
+++ b/map65/libm65/gen_q65_wave.f90
@@ -25,7 +25,7 @@ subroutine gen_q65_wave(msg,ntxfreq,mode65,msgsent,iwave,nwave)
!--------------------------------------------------------------------
! Local character
!--------------------------------------------------------------------
- character*37 :: msg37
+ character*37 :: msg37,msgsent37
!--------------------------------------------------------------------
! Explicit REAL*8 variables (as in original)
@@ -40,6 +40,7 @@ subroutine gen_q65_wave(msg,ntxfreq,mode65,msgsent,iwave,nwave)
integer :: codeword(65), itone(85)
integer :: icos7(0:6)
+ logical :: success
data icos7 /2,5,6,0,4,1,3/
data twopi /6.283185307179586476d0/
@@ -48,7 +49,6 @@ subroutine gen_q65_wave(msg,ntxfreq,mode65,msgsent,iwave,nwave)
!--------------------------------------------------------------------
! Logic (unchanged)
!--------------------------------------------------------------------
- msgsent = msg
msg37 = ''
msg37(1:22) = msg
@@ -59,7 +59,13 @@ subroutine gen_q65_wave(msg,ntxfreq,mode65,msgsent,iwave,nwave)
end if
end if
- call get_q65_tones(msg37, codeword, itone)
+ call get_q65_tones(msg37, codeword, itone, msgsent37, success)
+ msgsent = msgsent37(1:len(msgsent))
+ if(.not.success) then
+ iwave=0
+ nwave=0
+ return
+ endif
nsym = 85
tsym = 7200.d0/12000.d0
@@ -76,7 +82,7 @@ subroutine gen_q65_wave(msg,ntxfreq,mode65,msgsent,iwave,nwave)
do i = 1, iz
t = t + dt
- j = t/tsym + 1.0
+ j = min(nsym, int(t/tsym) + 1)
if (j /= j0) then
f = f0 + itone(j)*dfgen
dphi = twopi*dt*f
@@ -93,4 +99,4 @@ subroutine gen_q65_wave(msg,ntxfreq,mode65,msgsent,iwave,nwave)
end subroutine gen_q65_wave
-! does not require end module \ No newline at end of file
+! does not require end module
diff --git a/map65/libm65/getdphi.f90 b/map65/libm65/getdphi.f90
index 73439142..24cf0ab4 100644
--- a/map65/libm65/getdphi.f90
+++ b/map65/libm65/getdphi.f90
@@ -3,6 +3,7 @@ module getdphi_mod
contains
subroutine getdphi(qphi)
+ use stdout_channel_mod, only: write_stdout
implicit none
! Arguments
@@ -11,6 +12,7 @@ subroutine getdphi(qphi)
! Locals
real :: c, dphi, s, th
integer :: i
+ character(len=32) :: line
s = 0.0
c = 0.0
@@ -22,8 +24,12 @@ subroutine getdphi(qphi)
end do
dphi = 57.2957795 * atan2(s, c)
- write(*,1010) nint(dphi)
+ write(line,1010) nint(dphi)
1010 format('!Best-fit Dphi =', i4, ' deg')
+ ! Plain write(*,...) went to real process stdout, which nothing reads any
+ ! more -- the GUI now gets decoder output through the write_stdout shared-
+ ! memory channel instead, so this line never reached the Messages window.
+ call write_stdout(trim(line)//new_line('a'))
end subroutine getdphi
diff --git a/map65/libm65/getpfx1.f90 b/map65/libm65/getpfx1.f90
index d49d63e1..ba7faa37 100644
--- a/map65/libm65/getpfx1.f90
+++ b/map65/libm65/getpfx1.f90
@@ -63,6 +63,7 @@ subroutine getpfx1(callsign, k, nv2)
! Original JT65 would force this compound callsign to be treated as
! plain text. In JT65v2, we will encode the prefix or suffix into nc1.
! The task here is to compute the proper value of k.
+! TODO: Reject invalid compound characters before nchar can stop MAP65.
lof=callsign0(:islash-1)
rof=callsign0(islash+1:)
llof=len_trim(lof)
diff --git a/map65/libm65/indexx.f90 b/map65/libm65/indexx.f90
index a81c1712..53eca25c 100644
--- a/map65/libm65/indexx.f90
+++ b/map65/libm65/indexx.f90
@@ -68,38 +68,37 @@ contains
! Partition loop replacing labels 3 and 4
do
- ! Move i right
+ ! Move i right
do
i = i + 1
- if (i > ir) exit ! exit inner loop
+ if (i > ir) exit ! exit inner loop
if (arr(indx(i)) >= a) exit
end do
- ! Move j left
+ ! Move j left
do
j = j - 1
- if (j < l) then
- exit ! exit inner loop
- end if
+ if (j < l) then
+ exit ! exit inner loop
+ end if
if (arr(indx(j)) <= a) exit
end do
! If j < i, partition is done
if (j < i) exit
- ! Swap
- itemp = indx(i)
- indx(i) = indx(j)
- indx(j) = itemp
+ ! Swap
+ itemp = indx(i)
+ indx(i) = indx(j)
+ indx(j) = itemp
end do
- ! But now j might be < l, so clamp it:
- if (j < l) j = l
+ ! But now j might be < l, so clamp it:
+ if (j < l) j = l
indx(l) = indx(j)
indx(j) = indxt
-
! Push larger segment, process smaller first
jstack = jstack + 2
if (jstack > NSTACK) stop 'NSTACK too small in indexx'
diff --git a/map65/libm65/init_rs.c b/map65/libm65/init_rs.c
index 876819f8..6dff0392 100644
--- a/map65/libm65/init_rs.c
+++ b/map65/libm65/init_rs.c
@@ -35,7 +35,7 @@ void *INIT_RS(unsigned int symsize,unsigned int gfpoly,unsigned fcr,unsigned pri
int i, j, sr,root,iprim;
/* Check parameter ranges */
- if(symsize < 0 || symsize > (int)(8*sizeof(DTYPE)))
+ if(symsize > (int)(8*sizeof(DTYPE)))
return NULL; /* Need version with ints rather than chars */
if(fcr >= (1<<symsize))
diff --git a/map65/libm65/m65_mod.f90 b/map65/libm65/m65_mod.f90
index 7d4cbd3e..7710293f 100644
--- a/map65/libm65/m65_mod.f90
+++ b/map65/libm65/m65_mod.f90
@@ -1,6 +1,6 @@
module m65_mod
-use iso_c_binding, only: c_int8_t,c_int,c_loc, c_ptr
+use iso_c_binding, only: c_int8_t,c_int,c_loc,c_ptr,c_int64_t
use decodes_mod, only: nhsym1,nhsym2,ldecoded
implicit none
@@ -9,20 +9,57 @@ contains
subroutine m65c() bind(C)
use decode0_mod
- use npar_ptrs_mod, only: nhsym, nrxlog, datetime
+ use npar_ptrs_mod, only: nhsym, nrxlog, datetime, active_input_generation, nagain, ndiskdat, manualDecodeFlag
+ use debug_log, only: dbg, itoa, rtoa
+ use sec_midn_mod, only: sec_midn
integer :: npatience, nstandalone
-
+ integer, save :: nhsym_prev_m65c = -1
+ integer(c_int64_t), save :: previous_input_generation = -1
+
npatience=1
+ call dbg('m65c: ENTRY at t=' // rtoa(sec_midn()) // ' nhsym=' // itoa(nhsym) // &
+ ' nrxlog=' // itoa(nrxlog) // ' bit4_set=' // itoa(merge(1,0,iand(nrxlog,4).ne.0)))
if(nhsym.eq.nhsym1 .and. iand(nrxlog,1).ne.0) then
write(21,1000) datetime(1:17)
1000 format(/'UTC Date: ', a17, /78('-'))
flush(21)
endif
- if(iand(nrxlog,2).ne.0) rewind(21)
+ ! Consume the erase request once, independent of the decode pass.
+ if(iand(nrxlog,2).ne.0) then
+ rewind(21)
+ endfile(21)
+ backspace(21)
+ nrxlog = ibclr(nrxlog,1)
+ endif
if(iand(nrxlog,4).ne.0) then
- if(nhsym.eq.nhsym1) rewind(26)
+ ! rewind alone only repositions to record 1 for writing; it does not
+ ! shrink the file, so old history beyond whatever gets written this
+ ! cycle would stay on disk and could resurface via display.f90's own
+ ! rewind+read the same way the missing endfile there did (see
+ ! set_map65RxLog in npar_ptrs_mod.f90 for how Erase reaches here).
+ ! endfile makes this an immediate, real truncation to empty -- but it
+ ! leaves the file positioned after the EOF marker it just wrote, and
+ ! Fortran forbids further sequential I/O from there without
+ ! repositioning first, so backspace right away to land back on that
+ ! marker, ready for the next append.
+ !
+ ! An expired final request must not hide the next accumulation cycle.
+ if(nhsym.eq.nhsym1 .and. (nhsym_prev_m65c.ne.nhsym1 .or. &
+ previous_input_generation.ne.active_input_generation)) then
+ call dbg('m65c: UNIT26 TRUNCATED (endfile) at t=' // rtoa(sec_midn()) // &
+ ' nhsym=' // itoa(nhsym) // ' nrxlog=' // itoa(nrxlog))
+ rewind(26)
+ endfile(26)
+ backspace(26)
+ else if (nhsym.eq.nhsym1) then
+ call dbg('m65c: UNIT26 truncation SKIPPED (repeat call at nhsym1) at t=' // &
+ rtoa(sec_midn()) // ' nrxlog=' // itoa(nrxlog))
+ endif
if(nhsym.eq.nhsym2) backspace(26)
endif
+ nhsym_prev_m65c = nhsym
+ if(nagain.eq.0 .and. ndiskdat.eq.0 .and. manualDecodeFlag.eq.0) &
+ previous_input_generation = active_input_generation
nstandalone=0
diff --git a/map65/libm65/m65a.f90 b/map65/libm65/m65a.f90
index b337562f..ab2af114 100644
--- a/map65/libm65/m65a.f90
+++ b/map65/libm65/m65a.f90
@@ -6,7 +6,7 @@ subroutine m65a()
use timer_module, only: timer
use, intrinsic :: iso_c_binding, only: C_NULL_CHAR
- use npar_ptrs_mod
+ use npar_ptrs_mod, only: wsjtx_dir
use datcom_ptrs_mod, only: dd,ss,savg
use m65_mod
use FFTW3
@@ -15,7 +15,7 @@ subroutine m65a()
implicit none
character(len=256) cwd
-
+
cwd = trim(wsjtx_dir)
if (len_trim(cwd) == 0) then
diff --git a/map65/libm65/map65_polarization_score.f90 b/map65/libm65/map65_polarization_score.f90
new file mode 100644
index 00000000..24fa9a6f
--- /dev/null
+++ b/map65/libm65/map65_polarization_score.f90
@@ -0,0 +1,74 @@
+module map65_polarization_score_mod
+ use iso_fortran_env, only: real64
+ implicit none
+ private
+
+ real(real64), parameter :: pi=acos(-1.0_real64)
+ real(real64), parameter :: correlation_margin=1.0e-6_real64
+
+ public :: generalized_polarization_score
+ public :: polarization_matrix
+
+contains
+
+ pure subroutine polarization_matrix(projections,g00,g11,g01)
+ real(real64), intent(in) :: projections(4)
+ real(real64), intent(out) :: g00,g11,g01
+
+ g00=projections(1)
+ g11=projections(3)
+ g01=0.5_real64*(projections(2)-projections(4))
+ end subroutine polarization_matrix
+
+ pure subroutine generalized_polarization_score(g00,g11,g01,n00,n11,n01,score, &
+ physical_angle_degrees,combine_angle_degrees,valid)
+ real(real64), intent(in) :: g00,g11,g01,n00,n11,n01
+ real(real64), intent(out) :: score,physical_angle_degrees,combine_angle_degrees
+ logical, intent(out) :: valid
+ real(real64) :: alpha,ell,h00,h01,h11,m00,m01,m11,rho,sx,sy
+ real(real64) :: ux,uy,vx,vy,w0,w1
+
+ score=0.0_real64
+ physical_angle_degrees=0.0_real64
+ combine_angle_degrees=0.0_real64
+ valid=.false.
+ if (n00 <= tiny(1.0_real64) .or. n11 <= tiny(1.0_real64)) return
+
+ sx=sqrt(n00)
+ sy=sqrt(n11)
+ rho=n01/(sx*sy)
+ if (.not.(abs(rho) < huge(1.0_real64))) return
+ if (abs(rho) > 1.0_real64+correlation_margin) return
+ if (abs(rho) >= 1.0_real64-correlation_margin) then
+ rho=sign(1.0_real64-correlation_margin,rho)
+ endif
+ ell=sqrt(max(correlation_margin,1.0_real64-rho*rho))
+
+ m00=g00/n00
+ m01=g01/(sx*sy)
+ m11=g11/n11
+ h00=m00
+ h01=(m01-rho*m00)/ell
+ h11=(m11-2.0_real64*rho*m01+rho*rho*m00)/(ell*ell)
+ score=max(0.0_real64,0.5_real64*(h00+h11)+ &
+ hypot(0.5_real64*(h00-h11),h01))
+
+ alpha=0.5_real64*atan2(2.0_real64*h01,h00-h11)
+ w0=cos(alpha)
+ w1=sin(alpha)
+ vx=(w0-rho*w1/ell)/sx
+ vy=(w1/ell)/sy
+ ux=sx*w0
+ uy=sy*(rho*w0+ell*w1)
+ combine_angle_degrees=half_circle_angle(vx,vy)
+ physical_angle_degrees=half_circle_angle(ux,uy)
+ valid=.true.
+ end subroutine generalized_polarization_score
+
+ pure real(real64) function half_circle_angle(x,y)
+ real(real64), intent(in) :: x,y
+
+ half_circle_angle=modulo(atan2(y,x)*180.0_real64/pi,180.0_real64)
+ end function half_circle_angle
+
+end module map65_polarization_score_mod
diff --git a/map65/libm65/map65a.f90 b/map65/libm65/map65a.f90
index e9ee7c4a..cece6ec9 100644
--- a/map65/libm65/map65a.f90
+++ b/map65/libm65/map65a.f90
@@ -10,51 +10,56 @@ contains
nfcal, nkeep, mcall3b, nsum, nsave, nxant, mycall, mygrid, &
neme, ndepth, nstandalone, hiscall, hisgrid, nhsym, nfsample, &
ndiskdat, nxpol, nmode, ndop00)
-! Processes timf2 data from Linrad to find and decode JT65 signals.
+
use iso_c_binding
use wideband_sync
use timer_module, only: timer
- use debug_log
+ use debug_log, only: dbg, itoa, rtoa
+ use sec_midn_mod, only: sec_midn
use q65b_mod
use decode1a_mod
use ccf65_legacy_mod
use pctile_mod
use stdout_channel_mod, only: write_stdout
- use decodes_mod, only: nhsym1, nhsym2, ldecoded, ndecodes, mcall3a, decodes_init
+ use decodes_mod, only: nhsym1, ldecoded, ljt65decoded, ndecodes, mcall3a, decodes_init
use display_mod
use timf2_mod
use getdphi_mod
- use datcom_ptrs_mod, only: ss, savg
+ use datcom_ptrs_mod, only: ss_old, savg_old
+ use npar_ptrs_mod, only: nsmax_active, nrate_active, nfft_active, t_start, abort_decode, &
+ manualDecodeFlag, active_input_generation
use sec0_mod, only: sec0
+ use q65_decode, only: nsnr0, msg0, xdt0, nfreq0
implicit none
-
- integer, parameter :: MAXMSG = 1000 !Size of decoded message list
- integer, parameter :: NSMAX = 60*96000
- real, intent(in) :: dd(4,NSMAX)
- ! real*4, intent(in) :: ss(4,322,NFFT), savg(4,NFFT)
+ integer, parameter :: MAXMSG = 1000
+ real, parameter :: RESULT_DT_TOLERANCE = 0.2
+ ! Neighborhood radius (in symspec FFT bins) for ljt65decoded's
+ ! cross-call "already decoded" check/mark, below. At df ~= 2.9 Hz/bin
+ ! this is ~+/-15 Hz, covering the couple-of-bin spread a single real
+ ! JT65 signal can show across separate automatic calls.
+ integer, parameter :: JT65_LOCAL_BINS = 5
+ real, intent(in) :: dd(4, nsmax_active)
integer, intent(inout) :: newdat
integer, intent(inout) :: nutc
- real(real64), intent(in) :: fcenter
- integer, intent(in) :: ntol, idphi, nfa, nfb
- integer, intent(in) :: mousedf, mousefqso, nagain
+ real(real64), intent(in) :: fcenter
+ integer, intent(in) :: ntol, idphi, nfa, nfb
+ integer, intent(in) :: mousedf, mousefqso, nagain
integer, intent(inout) :: ndecdone
- integer, intent(in) :: nfshift
+ integer, intent(in) :: nfshift
integer, intent(inout) :: ndphi
- integer, intent(in) :: max_drift, nfcal, nkeep
+ integer, intent(in) :: max_drift, nfcal, nkeep
integer, intent(inout) :: mcall3b
integer, intent(inout) :: nsum, nsave
- integer, intent(in) :: nxant
+ integer, intent(in) :: nxant
character(len=12), intent(in) :: mycall, hiscall
- character(len=6), intent(in) :: mygrid, hisgrid
- integer, intent(in) :: neme, ndepth, nstandalone
- integer, intent(in) :: nhsym, nfsample, ndiskdat, nxpol, nmode, ndop00
-
- real tavg(-50:50) !Temp for finding local base level
- real base(4) !Local basel level at 4 pol'ns
- real sig(MAXMSG, 30) !Parameters of detected signals
- real a(5)
+ character(len=6), intent(in) :: mygrid, hisgrid
+ integer, intent(in) :: neme, ndepth, nstandalone
+ integer, intent(in) :: nhsym, nfsample, ndiskdat, nxpol, nmode, ndop00
+
+ ! --- local variables (unchanged) ---
+ real tavg(-50:50), base(4), sig(MAXMSG,30), a(5)
real :: df, dphi, dt, dt2, fa, fb, flip, flipk, foffset, freq, freq0, fshort
real :: ftol, pol, qual, s2db, smax, snr2, ssmax, sync1, sync10, sync2, syncshort
real :: tdec, thresh0, thresh1, tsec0, fshort0, fqso, syncshort0
@@ -62,108 +67,571 @@ contains
character(len=22) msg(MAXMSG)
character(len=3) shmsg0(4)
character(len=1) :: cp, cm
- integer indx(MAXMSG), nsiz(MAXMSG)
+ integer indx(MAXMSG)
integer :: ipol, mode65
- integer :: i, ia, ib, i0, icand, idf, ifile, ifile0, ifreq, ii, iii, ikhz, ilatest, iloop
- integer :: ip000, ip001, ipol2, j, jp, jpmax, jpz, k, km, m, mfa, mfb, mhz, mode_q65
- integer :: mousefqso0, n, ncand, ndf, ndf0, ndf1, ndf2, nfile, nflip, nhist
- integer :: nhzdiff, nid, nkhz, nkm, nkv, noffset, npol, nqd, nqual, nsync1
- integer :: nsync2, ntry, nts_jt65, nts_q65, ntxpol, nutc0, nwrite, nwrite_q65, nz
+ integer :: i, ia, ib, i0, icand, idf, ifreq, ii, iii, ikhz
+ integer :: iloop, ip000, ip001, ipol2, j, jp, jpmax, jpz
+ integer :: k, km, mfa, mfb, mhz, mode_q65
+ integer :: mousefqso0, n, ncand, ndf, ndf0, ndf1, ndf2
+ integer :: nfile, nflip, nhist, nhzdiff, nid, nkhz, nkm, nkv
+ integer :: noffset, npol, nqd, nqual, nsync1, nsync2, ntry
+ integer :: nts_jt65, nts_q65, ntxpol, nutc0, nwrite, nwrite_q65, nz
integer :: idec
- logical done(MAXMSG)
logical xpol, bq65, q65b_called
logical candec(MAX_CANDIDATES)
- character(len=22) decoded
- character(len=22) blank
+ character(len=22) decoded, blank, decoded_jt65
character(len=2) cmode
- real short(3, NFFT) !SNR dt ipol for potential shorthands
+ real short(3, nfft_active)
real qphi(12)
type(candidate) :: cand(MAX_CANDIDATES)
real(real64) :: f00
character(len=256) :: line
+ integer :: n_rms, i2
+ real*8 :: rms, sumsq, v
+ real*4 :: tsec_mod
+ integer :: t_now, t_rate
+ logical :: m65_inited = .false.
+ logical :: abort_saved
+ integer :: icenter
+ logical :: initialization_only, shorthand_detected, jt65_success, q65_success
+ logical :: already_decoded_nearby
+ real :: best_sync1, best_dt, best_flipk, best_syncshort, best_snr2, best_dt2
+ integer :: best_i, best_ipol2
+ real :: sync1_tmp, dt_tmp, flipk_tmp, syncshort_tmp, snr2_tmp, dt2_tmp
+ integer :: ipol_tmp, ipol2_tmp,ftol_bins, manualDecodeFlag_initial
+ real :: freq_q65
+ integer :: nhsym_prev_call
+ integer(c_int64_t) :: previous_input_generation = -1
- logical :: m65_inited = .false. ! added with modernization
-
data blank/' '/, cm/'#'/
- data shmsg0/'ATT', 'RO ', 'RRR', '73 '/
+ data shmsg0/'ATT','RO ','RRR','73 '/
data nfile/0/, nutc0/-999/, nid/0/, ip000/1/, ip001/1/, mousefqso0/-999/
+ data nhsym_prev_call/-1/
save
+ real(c_float), pointer :: ss_dec(:,:,:)
+ real(c_float), pointer :: savg_dec(:,:)
+
+ manualDecodeFlag_initial = manualDecodeFlag
+
+!------------------------------------------------------------
+! BUFFER SELECTION
+!------------------------------------------------------------
+ ! Always use the snapshot (see decode0.f90) -- ss/savg are live and
+ ! can be reset/overwritten mid-decode by symspec_() on the GUI thread
+ ! once the next cycle's UDP data starts arriving.
+ ss_dec => ss_old
+ savg_dec => savg_old
+
+ abort_decode = .false.
+
if (.not. m65_inited) then
call decodes_init()
- call init_wideband_sync(NFFT)
+ call init_wideband_sync()
m65_inited = .true.
endif
-
+
rewind 12
ndecodes = 0
-
+ km = 0
ipol = 1
-! Clean start for Q65 at early decode
- if (nhsym .eq. nhsym1 .or. nagain .ne. 0) ldecoded = .false.
- if (ndiskdat .eq. 1) ldecoded = .false.
+!------------------------------------------------------------
+! BASIC DECODE SETUP (shared by manual + wideband)
+!------------------------------------------------------------
+ ! Share the ledger across early/final passes, but start a new cycle
+ ! even when the preceding final request expired before execution.
+ if ((nhsym .eq. nhsym1 .and. (nhsym_prev_call .ne. nhsym1 .or. &
+ previous_input_generation .ne. active_input_generation)) .or. nagain .ne. 0) then
+ ldecoded = .false.
+ ljt65decoded = .false.
+ call dbg('map65a: ldecoded/ljt65decoded RESET at t=' // rtoa(sec_midn()) // &
+ ' nhsym=' // itoa(nhsym) // ' nhsym_prev_call=' // itoa(nhsym_prev_call) // &
+ ' nagain=' // itoa(nagain))
+ else if (nhsym .eq. nhsym1) then
+ call dbg('map65a: ldecoded/ljt65decoded NOT reset (repeat call at nhsym1) at t=' // rtoa(sec_midn()) // &
+ ' nhsym=' // itoa(nhsym))
+ endif
+ nhsym_prev_call = nhsym
+ if (nagain .eq. 0 .and. ndiskdat .eq. 0 .and. manualDecodeFlag .eq. 0) &
+ previous_input_generation = active_input_generation
+ if (ndiskdat .eq. 1) then
+ ldecoded = .false.
+ ljt65decoded = .false.
+ endif
+
+ df = real(nrate_active)/real(nfft_active)
+ if (nfsample .eq. 95238) df = 95238.1/real(nfft_active)
- nkhz_center = nint(1000.0*(fcenter - int(fcenter)))
- mfa = nfa - nkhz_center + 48
- mfb = nfb - nkhz_center + 48
- mode65 = mod(nmode, 10)
+ mode65 = mod(nmode,10)
if (mode65 .eq. 3) mode65 = 4
- mode_q65 = nmode/10
- nts_jt65 = mode65 !JT65 tone separation factor
- nts_q65 = 2**(mode_q65 - 1) !Q65 tone separation factor
+ mode_q65 = nmode/10
+ nts_jt65 = mode65
+ nts_q65 = 2**(mode_q65 - 1)
xpol = (nxpol .ne. 0)
-! No second decode for JT65? Can't use this guard with modern code
-! if (nhsym.eq.nhsym2 .and. nagain.eq.0 .and. ndiskdat.eq.0) mode65 = 0
-
- if (nagain .eq. 0) then
- call timer('get_cand', 0)
- call get_candidates(ss, savg, xpol, nhsym, mfa, mfb, nts_jt65, nts_q65, cand, ncand)
- call timer('get_cand', 1)
- candec = .false.
- endif
nwrite_q65 = 0
bq65 = mode_q65 .gt. 0
-
+
mcall3a = mcall3b
mousefqso0 = mousefqso
if (.not. xpol) ndphi = 0
nsum = 0
-!### Should use AppDir! ###
- open (23, file='CALL3.TXT', status='unknown')
-
- df = 96000.0/NFFT !df = 96000/NFFT = 2.930 Hz
- if (nfsample .eq. 95238) df = 95238.1/NFFT
- ftol = 0.010 !Frequency tolerance (kHz)
dphi = idphi/57.2957795
- foffset = 0.001*(1270 + nfcal) !Offset from sync tone, plus CAL
- fqso = mousefqso + foffset - 0.5*(nfa + nfb) + nfshift !fqso at baseband (khz)
+ foffset = 0.001*(1270 + nfcal)
iloop = 0
+ ! qphi is "save"d across calls (blanket SAVE above) but only gets
+ ! written for a trial (iloop=1..12) that actually decodes something;
+ ! without this reset, a trial that finds nothing leaves behind
+ ! whatever unrelated value qphi(iloop) held from an earlier Find-dPhi
+ ! run, silently mixing stale data into getdphi's best-fit calculation.
+ if (ndphi .eq. 1) qphi = 0.0
+
2 if (ndphi .eq. 1) dphi = 30*iloop/57.2957795
if (nutc .ne. nutc0) nfile = nfile + 1
nutc0 = nutc
+ !### Should use AppDir! ###
+ open (23, file='CALL3.TXT', status='unknown')
+
+!------------------------------------------------------------
+! MANUAL NARROWBAND DECODE PATH
+!------------------------------------------------------------
+ if (manualDecodeFlag /= 0) then
+ abort_saved = abort_decode
+ km = 0
+ icenter = nfft_active/2 + 1
+
+ ! JT65/Q65 RF frame (kHz)
+ foffset = 0.001*(1270 + nfcal)
+ fqso = mousefqso + foffset - 0.5*(nfa + nfb) + nfshift
+
+ ! Manual clicked RF (kHz)
+ freq = fqso + 0.001*mousedf
+
+ ! Bin index
+ i = nint(freq*1000.0/df) + icenter
+
+ ! Tolerance from GUI
+ ftol = real(ntol) ! Hz
+ ftol_bins = nint(ftol / df)
+
+ i = nint(freq*1000.0/df) + icenter ! bin corresponding to that RF
+ i = max(51, min(nfft_active - 51, i))
+
+ ! --- local search around clicked bin within ftol ---
+ ftol = real(ntol)
+ ftol_bins = nint(ftol / df)
+
+ jpz = merge(4,1,xpol)
+
+ best_sync1 = -1.e9
+ best_i = i
+ best_dt = 0.0
+ best_flipk = 0.0
+ best_syncshort = 0.0
+ best_snr2 = 0.0
+ best_ipol2 = 1
+ best_dt2 = 0.0
+
+ do ii = -ftol_bins, ftol_bins
+ iii = i + ii
+ if (iii < 51 .or. iii > nfft_active - 51) cycle
+
+ ssmax = 1.e30
+ call timer('ccf65 ',0)
+ call ccf65(ss_dec(:,:,iii), nhsym, ssmax, sync1_tmp, ipol_tmp, jpz, dt_tmp, flipk_tmp, &
+ syncshort_tmp, snr2_tmp, ipol2_tmp, dt2_tmp)
+ call timer('ccf65 ',1)
+
+ if (sync1_tmp > best_sync1) then
+ best_sync1 = sync1_tmp
+ best_i = iii
+ best_dt = dt_tmp
+ best_flipk = flipk_tmp
+ best_syncshort = syncshort_tmp
+ best_snr2 = snr2_tmp
+ best_ipol2 = ipol2_tmp
+ best_dt2 = dt2_tmp
+ endif
+ enddo
+
+ ! use best bin and metrics from the search
+ i = best_i
+ sync1 = best_sync1
+ dt = best_dt
+ flipk = best_flipk
+ syncshort = best_syncshort
+ snr2 = best_snr2
+ ipol2 = best_ipol2
+ dt2 = best_dt2
+
+ ! Match the 3.0.1 double-click ("quick decode", nqd=1) rule: use a
+ ! lower sync threshold at the clicked frequency when ftol <= 100 Hz.
+ ! A fixed 1.0 here gates the click exactly like the wideband pass,
+ ! so a signal the wideband pass missed could never be decoded.
+ thresh1 = 1.0
+ if (ntol .le. 100) thresh1 = 0.
+ nflip = nint(flipk)
+ call dbg('map65a manual: click nutc=' // itoa(nutc) // ' mousefqso=' // itoa(mousefqso) // &
+ ' mousedf=' // itoa(mousedf) // ' ntol=' // itoa(ntol) // &
+ ' best sync1=' // rtoa(sync1) // ' thresh1=' // rtoa(thresh1) // &
+ ' syncshort=' // rtoa(syncshort) // ' mode65=' // itoa(mode65))
+
+ !===========================
+ ! SHORTHAND DETECTION (JT65)
+ !===========================
+ shorthand_detected = .false.
+
+ thresh0 = 1.0
+ if (syncshort > thresh0 .and. mode65 > 0) then
+ shorthand_detected = .true.
+
+ km = 1
+ sig(1,1) = nfile
+ sig(1,2) = nutc
+ sig(1,3) = freq
+ sig(1,4) = syncshort
+ sig(1,5) = dt2
+ sig(1,6) = 45*(ipol2 - 1)/57.2957795
+ sig(1,7) = 0
+ sig(1,8) = snr2
+ sig(1,9) = 0
+ sig(1,10)= 0
+ sig(1,12)= savg_dec(ipol2,i)
+ msg(1) = shmsg0(1)
+ endif
+
+ ! Bin frequency for this click (for decode1a’s f00)
+ f00 = (i - 1)*df
+
+ ikhz = nint(freq + 0.5*(nfa + nfb) - foffset) - nfshift
+ idf = nint(1000.0*(freq + 0.5*(nfa + nfb) - foffset - (ikHz + nfshift)))
+
+ noffset = nint(1000.0*(freq - fqso) - mousedf)
+
+ ! JT65-specific rejects only when JT65 is active
+ if (mode65 > 0) then
+ if (sync1 <= thresh1) then
+
+ if (.not. bq65) then
+ ! JT65-only mode → real reject
+ newdat = 0
+ km = 0
+ ncand = 0
+ msg(1) = blank
+ msg(2) = blank
+ do j = 1, 30
+ sig(1,j) = 0.0
+ enddo
+ manualDecodeFlag = 0
+ return
+ endif
+
+ ! JT65 failed but Q65 is active → DO NOT RETURN
+ endif
+
+ if (abs(noffset) > ntol) then
+
+ if (.not. bq65) then
+ ! JT65-only mode → real reject
+
+ newdat = 0
+ km = 0
+ ncand = 0
+
+ msg(1) = blank
+ msg(2) = blank
+
+ do j = 1, 30
+ sig(1,j) = 0.0
+ enddo
+
+ manualDecodeFlag = 0
+ return
+ endif
+
+ ! JT65 failed but Q65 is active → DO NOT RETURN
+ endif
+ endif
+
+ !===========================
+ ! JT65 MANUAL DECODE (if active)
+ !===========================
+ jt65_success = .false.
+ decoded_jt65 = ' '
+
+ if (mode65 > 0 .and. sync1 > thresh1 .and. abs(noffset) <= ntol) then
+
+ call timer('decode1a',0)
+ ifreq = i
+
+ call decode1a(dd,newdat,f00,nflip,mode65,nfsample,xpol,mycall,hiscall, &
+ hisgrid,neme,ndepth,1,dphi,ndphi,nutc,ikHz,idf,ipol,ntol, &
+ sync2,a,dt,pol,nkv,nhist,nsum,nsave,qual,decoded_jt65)
+ call timer('decode1a',1)
+
+ abort_decode = abort_saved
+ ! Fit and averaging details, to tell a normal decode from a strange one
+ ! (e.g. an odd DT). dt_in is the DT decode1a was given (from ccf65 at the
+ ! best bin), dt_out the DT it returned. nsum > 0 means the single-period
+ ! decode failed and decode1a went on to try averaging saved spectra;
+ ! nkv >= 2 with a decode means the message came from that average.
+ call dbg('map65a manual: decode1a called, decoded=[' // trim(decoded_jt65) // ']' // &
+ ' dt_in=' // rtoa(best_dt) // ' dt_out=' // rtoa(dt) // &
+ ' sync2=' // rtoa(sync2) // ' a1_df=' // rtoa(a(1)) // &
+ ' nkv=' // itoa(nkv) // ' nsum=' // itoa(nsum) // ' nsave=' // itoa(nsave) // &
+ ' nhist=' // itoa(nhist) // ' qual=' // rtoa(qual) // &
+ ' nflip=' // itoa(nflip) // ' f00=' // rtoa(real(f00)))
+
+ if (decoded_jt65 /= ' ') then
+ jt65_success = .true.
+
+ km = km + 1
+ sig(km,1) = nfile
+ sig(km,2) = nutc
+ sig(km,3) = freq + 0.5*(nfa+nfb)
+ sig(km,4) = sync1
+ sig(km,5) = dt
+ sig(km,6) = pol
+ sig(km,7) = flipk
+ sig(km,8) = sync2
+ sig(km,9) = nkv
+ sig(km,10)= qual
+ sig(km,12)= savg_dec(ipol,i)
+ sig(km,13)= a(1)
+ sig(km,14)= a(2)
+ sig(km,15)= a(3)
+ sig(km,16)= a(4)
+ sig(km,18)= nhist
+ msg(km) = decoded_jt65
+ endif
+ endif
+
+ !===========================
+ ! Q65 MANUAL DECODE (if active)
+ !===========================
+ q65_success = .false.
+
+ if (bq65) then
+ ! Include mousedf (the sub-kHz part of the click) so the search
+ ! is centered on the actual clicked frequency, not just rounded
+ ! to the nearest kHz -- matters once q65b targets this exactly
+ ! (see the manualDecodeFlag handling around k0 in q65b.F90).
+ freq = mousefqso + 0.001*mousedf
+ freq_q65 = freq
+ f0 = freq_q65 - (nkhz_center - real(nrate_active)/2000.0 - 1.27046)
+ nqd = 1 ! target-frequency decode, like wideband's quick pass at
+ ! fQSO; also required so q65b's own write_stdout/output
+ ! path (gated on nqd==1) actually emits the result
+ ikhz = nint(freq_q65)
+ ! NB: mousedf must stay relative to mousefqso here, unmodified --
+ ! q65b.F90 also uses it (via f_mouse) to pick k0, the actual
+ ! sample-extraction point for the decode. A previous attempt to
+ ! re-reference it to ikhz here (for q65b's output gate, which
+ ! compares against ikhz-relative nq65df) fixed the gate but broke
+ ! k0/f_mouse, silently decoding whatever signal sits near the
+ ! *other* kHz bucket instead of the one actually clicked. The
+ ! gate's reference-frame mismatch is now fixed inside q65b.F90
+ ! itself instead, from f0 (already unambiguous), leaving this
+ ! mousedf untouched for f_mouse/k0 to keep working correctly.
+
+ call dbg('map65a manual: Q65 call nutc=' // itoa(nutc) // ' nqd=' // itoa(nqd) // &
+ ' ikhz=' // itoa(ikhz) // ' mousedf=' // itoa(mousedf) // ' ntol=' // itoa(ntol) // &
+ ' mode_q65=' // itoa(mode_q65) // ' f0=' // rtoa(real(f0)) // &
+ ' newdat=' // itoa(newdat) // ' nagain=' // itoa(nagain) // &
+ ' ndepth=' // itoa(ndepth) // ' max_drift=' // itoa(max_drift))
+
+ call timer('q65b ', 0)
+ call q65b(nutc, nqd, nxant, fcenter, nfcal, nfsample, ikhz, mousedf, &
+ ntol, xpol, idphi, mycall, mygrid, hiscall, hisgrid, mode_q65, f0, fqso, &
+ newdat, nagain, max_drift, ndop00, idec)
+ call timer('q65b ', 1)
+
+ call dbg('map65a manual: Q65 result idec=' // itoa(idec) // ' nsnr0=' // itoa(nsnr0) // &
+ ' nfreq0=' // itoa(nfreq0) // ' xdt0=' // rtoa(xdt0) // ' msg0=[' // trim(msg0) // ']')
+
+ ! NB: idec, as returned by q65b, is not a trustworthy success flag:
+ ! q65b derives it by parsing cq0(2:2) (see q65b.F90, label 900), and
+ ! cq0 is not reset on a failed attempt, so it can still read back
+ ! whatever digit was left over from an earlier, unrelated decode.
+ ! nsnr0 is q65b's own internal success test (freshly reset to -99
+ ! immediately before it attempts this decode), so use that instead.
+
+ q65_success = (nsnr0 .gt. -99)
+ ! On success, q65b has already written the decoded text itself
+ ! (write_stdout, plus units 26/21/12) because nqd=1 and the result
+ ! is within ntol of mousedf -- the same mechanism the wideband
+ ! quick-decode pass uses. Nothing further to add to km/msg/sig here.
+ endif
+
+ !===========================
+ ! EMIT DECODE(S) DIRECTLY
+ !===========================
+ ! NB: this used to "go to 600" to reuse the wideband write/rescan
+ ! block, but that block lives inside "do nqd = 1, 0, -1 ... enddo"
+ ! while this code is lexically outside that loop. Branching into
+ ! the interior of a DO construct from outside it is illegal and
+ ! was causing a stray re-entrant q65b call (via the stale, never-
+ ! populated "cand" array) plus a "if (mode65.eq.0) km = 0" reset
+ ! that silently discarded the manual Q65 decode before it could be
+ ! written. Emit the km/msg/sig entries here instead.
+ if (jt65_success .or. q65_success .or. shorthand_detected) then
+ nwrite = 0
+
+ do k = 1, km
+ decoded = msg(k)
+ if (decoded .ne. ' ') then
+ nutc = sig(k,2)
+ freq = sig(k,3)
+ sync1 = sig(k,4)
+ dt = sig(k,5)
+ npol = nint(57.2957795*sig(k,6))
+ flip = sig(k,7)
+ sync2 = sig(k,8)
+ nkv = sig(k,9)
+ nqual = sig(k,10)
+ if (flip .lt. 0.0) then
+ i = len_trim(decoded)
+ if (i .eq. 0) stop 'Error in message format'
+ if (i .le. 18) decoded(i + 2:i + 4) = 'OOO'
+ endif
+ nkHz = nint(freq - foffset) - nfshift
+ mhz = fcenter
+ f0 = mhz + 0.001*nkHz
+ ndf = nint(1000.0*(freq - foffset - (nkHz + nfshift)))
+ nsync1 = sync1
+ s2db = 10.0*log10(sync2) - 40
+ nsync2 = nint(s2db)
+ if (decoded(1:4) .eq. 'RO ' .or. decoded(1:4) .eq. 'RRR ' .or. &
+ decoded(1:4) .eq. '73 ') then
+ nsync2 = nint(1.33*s2db + 2.0)
+ endif
+
+ nwrite = nwrite + 1
+ if (nxant .ne. 0) then
+ npol = npol - 45
+ if (npol .lt. 0) npol = npol + 180
+ endif
+
+ call txpol(xpol, decoded, mygrid, npol, nxant, ntxpol, cp)
+
+ write (line, '("!",I3,I5,I4,I6.4,F5.1,I5,1X,A1,1X,A22,I2,I5,I5,1X,A1)') &
+ nkHz, ndf, npol, nutc, dt, nsync2, cm, decoded, nkv, nqual, ntxpol, cp
+ call write_stdout(trim(line)//new_line('a'))
+ endif
+ enddo ! k=1,km
+
+ manualDecodeFlag = 0
+ return
+ endif
+
+ newdat = 0
+ km = 0
+ ncand = 0
+ msg(1) = blank
+ msg(2) = blank
+ do j = 1, 30
+ sig(1,j) = 0.0
+ enddo
+ manualDecodeFlag = 0
+ return
+ endif
+
+
+!------------------------------------------------------------
+! WIDEBAND CODE RESUMES HERE
+!------------------------------------------------------------
+
+! km is "save"d across calls, but this point runs once per Find-dPhi trial
+! (iloop 0..12 via "go to 2" below) as well as once for a normal decode.
+! Without resetting it here, each later trial's "do k=1,km" write-out loop
+! replays every earlier trial's decode(s) again verbatim -- the repeated,
+! made-up-looking decodes seen with Find Delta Phi.
+km = 0
+
+! Only JT65 applies the trial phase; Q65 keeps the same input each time.
+if (ndphi .eq. 1) then
+ ljt65decoded = .false.
+endif
+
+ftol = 0.010
+fqso = mousefqso + foffset - 0.5*(nfa + nfb) + nfshift
+nkhz_center = nint(1000.0*(fcenter - int(fcenter)))
+mfa = nfa - nkhz_center + int(nrate_active/2000.0)
+mfb = nfb - nkhz_center + int(nrate_active/2000.0)
+
+tsec_mod = real(mod(t_start, 60), kind=4)
+! Number of samples to use for RMS check
+n_rms = min(322, 2048)
+
+sumsq = 0.0d0
+do i2 = 1, n_rms
+ v = ss_dec(1, i2, 1)
+ sumsq = sumsq + v*v
+end do
+
+if (n_rms > 0) then
+ rms = sqrt(sumsq / dble(n_rms))
+else
+ rms = 0.0d0
+endif
+
+if (nagain .eq. 0) then
+ call timer('get_cand', 0)
+ call get_candidates(ss_dec, savg_dec, xpol, nhsym, mfa, mfb, nts_jt65, nts_q65, cand, ncand)
+ call timer('get_cand', 1)
+ candec = .false.
+ ! TEMP diagnostic 2026-09-09 for the missing-upper-Q65-decode investigation.
+ call dbg('map65a: get_candidates done at t=' // rtoa(sec_midn()) // &
+ ' ncand=' // itoa(ncand) // ' n_q65cand=' // itoa(count(cand(1:max(ncand,0))%iflip == 0)) // &
+ ' bq65=' // itoa(merge(1,0,bq65)) // ' xpol=' // itoa(merge(1,0,xpol)) // &
+ ' nhsym=' // itoa(nhsym) // ' manualDecodeFlag_initial=' // itoa(manualDecodeFlag_initial))
+endif
+
do nqd = 1, 0, -1
+
+ call system_clock(t_now, t_rate)
+ call dbg('map65a: nqd loop top at t=' // rtoa(sec_midn()) // &
+ ' nqd=' // itoa(nqd) // ' elapsed=' // rtoa(real(t_now - t_start)/real(t_rate)) // &
+ ' manualDecodeFlag_initial=' // itoa(manualDecodeFlag_initial))
+ if (real(t_now - t_start)/real(t_rate) > 40.0) then
+ abort_decode = .true.
+ call dbg('map65a: ABORT (40s budget exceeded) at t=' // rtoa(sec_midn()) // ' nqd=' // itoa(nqd))
+ go to 700
+ endif
+
+ if (manualDecodeFlag_initial == 1 .and. nqd == 0) then
+ call dbg('map65a: nqd=0 CYCLE-skipped (manualDecodeFlag_initial=1) at t=' // rtoa(sec_midn()))
+ cycle
+ endif
+
+
if (nqd .eq. 1) then !Quick decode, at fQSO
fa = 1000.0*(fqso + 0.001*mousedf) - ntol
- fb = 1000.0*(fqso + 0.001*mousedf) + ntol + 4*53.8330078
+ fb = 1000.0*(fqso + 0.001*mousedf) + ntol + 4*(96000.0/1783.0)
else !Wideband decode at all freqs
fa = -1000*0.5*(nfb - nfa) + 1000*nfshift
fb = 1000*0.5*(nfb - nfa) + 1000*nfshift
+
+ ! Debug: report JT65 wideband search window
+
+!write(sfa, '(F20.6)') fa
+!write(sfb, '(F20.6)') fb
+!write(sspan, '(F20.6)') (fb-fa)/1000.0
+
endif
- ia = nint(fa/df) + 16385
- ib = nint(fb/df) + 16385
+ icenter = nfft_active/2 + 1
+ ia = nint(fa/df) + icenter
+ ib = nint(fb/df) + icenter
ia = max(51, ia)
- ib = min(32768 - 51, ib)
+ ib = min(nfft_active - 51, ib)
if (ndiskdat .eq. 1 .and. mode65 .eq. 0) ib = ia
- km = 0
nkm = 1
- nz = n/8
freq0 = -999.
sync10 = -999.
fshort0 = -999.
@@ -173,15 +641,36 @@ contains
jpz = 1
if (xpol) jpz = 4
+ ! TEMP diagnostic 2026-09-09 for the missing-other-JT65-signal investigation.
+ call dbg('map65a: JT65 sweep window at t=' // rtoa(sec_midn()) // &
+ ' nqd=' // itoa(nqd) // ' fa=' // rtoa(fa) // ' fb=' // rtoa(fb) // &
+ ' ia=' // itoa(ia) // ' ib=' // itoa(ib) // ' km_entering=' // itoa(km))
+
do i = ia, ib !Search over freq range
- freq = 0.001*(i - 16385)*df
+
+ call system_clock(t_now, t_rate)
+ if (real(t_now - t_start)/real(t_rate) > 40.0) then
+ call dbg('Decode abort: exceeded 40 seconds in do i = ia, ib pass, nqd=' // itoa(nqd) // ' i=' // itoa(i))
+ abort_decode = .true.
+ ! "go to 700" here used to jump past the Q65 candidate-decode
+ ! loop below (do icand = 1, ncand), which only runs after this
+ ! JT65 sweep completes -- so a slow JT65 sweep (e.g. many
+ ! birdie-triggered decode1a calls) could burn the whole 40 s
+ ! budget and starve Q65 of any decode attempt at all, even
+ ! though its candidates were already found by get_candidates()
+ ! before this loop started. Just stop scanning more JT65 bins
+ ! instead, so Q65 still gets its turn this pass.
+ exit
+ endif
+
+ freq = 0.001*(i - icenter)*df
! Find the local base level for each polarization; update every 10 bins.
if (mod(i - ia, 10) .eq. 0) then
do jp = 1, jpz
do ii = -50, 50
iii = i + ii
- if (iii .ge. 1 .and. iii .le. 32768) then
- tavg(ii) = savg(jp, iii)
+ if (iii .ge. 1 .and. iii .le. nfft_active) then
+ tavg(ii) = savg_dec(jp, iii)
else
write (13, *) 'Error in iii:', iii, ia, ib, fa, fb
flush (13)
@@ -196,8 +685,8 @@ contains
smax = 0.
jpmax = 1
do jp = 1, jpz
- if (savg(jp, i)/base(jp) .gt. smax) then
- smax = savg(jp, i)/base(jp)
+ if (savg_dec(jp, i)/base(jp) .gt. smax) then
+ smax = savg_dec(jp, i)/base(jp)
jpmax = jp
endif
enddo
@@ -207,9 +696,18 @@ contains
! Look for JT65 sync patterns and shorthand square-wave patterns.
call timer('ccf65 ', 0)
ssmax = 1.e30
- call ccf65(ss(:,:,i), nhsym, ssmax, sync1, ipol, jpz, dt, flipk, &
+ call ccf65(ss_dec(:,:,i), nhsym, ssmax, sync1, ipol, jpz, dt, flipk, &
syncshort, snr2, ipol2, dt2)
call timer('ccf65 ', 1)
+ ! 2026-09-12: instrumentation for the "identical anomalous
+ ! dtbest across several consecutive nqd=0 candidates" investigation.
+ ! Logging ccf65's own per-candidate dt (the value that becomes
+ ! decode1a's dt00 input) so a live capture can show directly
+ ! whether the staleness/repetition already exists at THIS
+ ! input, before decode1a/afc65b ever runs.
+ call dbg('map65a: ccf65 result at t=' // rtoa(sec_midn()) // &
+ ' nqd=' // itoa(nqd) // ' i=' // itoa(i) // ' dt=' // rtoa(dt) // &
+ ' sync1=' // rtoa(sync1) // ' ntry=' // itoa(ntry))
if (mode65 .eq. 0) syncshort = -99.0 !If "No JT65", don't waste time
! ########################### Search for Shorthand Messages #################
@@ -229,7 +727,7 @@ contains
! Should this be i0 +/- 1, or just i0?
! Should we also insist that difference in DT be either 1.5 or -1.5 s?
if (short(1, i0) .gt. thresh0) then
- fshort = 0.001*(i0 - 16385)*df
+ fshort = 0.001*(i0 - icenter)*df
noffset = 0
if (nqd .eq. 1) noffset = nint(1000.0*(fshort - fqso) - mousedf)
if (abs(noffset) .le. ntol) then
@@ -252,7 +750,7 @@ contains
sig(km, 9) = 0
sig(km, 10) = 0
! sig(km,11)=rms0
- sig(km, 12) = savg(ipol2, i)
+ sig(km, 12) = savg_dec(ipol2, i)
sig(km, 13) = 0
sig(km, 14) = 0
sig(km, 15) = 0
@@ -277,11 +775,42 @@ contains
if (nqd .eq. 1 .and. ntol .le. 100) thresh1 = 0.
noffset = 0
if (nqd .ge. 1) noffset = nint(1000.0*(freq - fqso) - mousedf)
- if (newdat .eq. 1 .and. sync1 .gt. -99.0) then
+ initialization_only = .false.
+ if (newdat .eq. 1 .and. sync1 .gt. -99.0 .and. &
+ (sync1 .le. thresh1 .or. abs(noffset) .gt. ntol)) then
+ initialization_only = .true.
sync1 = thresh1 + 1.0
noffset = 0
endif
+ ! Computed once per candidate, before the "keep only best
+ ! within ftol" collapse logic just below -- see the SKIPPED
+ ! branch right after for why the ordering matters. Must be
+ ! false whenever initialization_only is true: that probe
+ ! doesn't accumulate anything regardless, but still needs
+ ! decode1a() called once per sweep for its own internal
+ ! state, so it must not be intercepted here.
+ already_decoded_nearby = (.not. initialization_only) .and. &
+ any(ljt65decoded(max(1,i-JT65_LOCAL_BINS):min(nfft_active,i+JT65_LOCAL_BINS)))
+
if (sync1 .gt. thresh1 .and. abs(noffset) .le. ntol) then
+ if (already_decoded_nearby) then
+ ! Skip a candidate whose bin (or a nearby one, within
+ ! JT65_LOCAL_BINS) already produced a real decode
+ ! earlier this same accumulation cycle, mirroring
+ ! Q65's ldecoded(ipk) (decodes_mod.f90) -- otherwise a
+ ! repeat automatic call re-discovers and re-emits the
+ ! same JT65 decode.
+ !
+ ! Must run before the "keep only best within ftol"
+ ! collapse logic below, not after: that logic's
+ ! "km=km-1" runs unconditionally, on the assumption
+ ! that accumulation always follows with a matching
+ ! "km=km+1" -- skipping AFTER that decrement leaves it
+ ! unmatched and silently drives km negative, hiding
+ ! the whole signal from this pass's output.
+ call dbg('map65a: JT65 i=' // itoa(i) // &
+ ' SKIPPED (already decoded nearby this cycle) at t=' // rtoa(sec_midn()))
+ else
! Keep only the best candidate within ftol.
! (Am I deleting any good decodes by doing this?)
if(freq-freq0.le.ftol .and. sync1.gt.sync10 .and. &
@@ -292,25 +821,52 @@ contains
ntry = ntry + 1
if ((nqd .eq. 1 .and. ntry .ge. 40) .or. &
(nqd .eq. 0 .and. ntry .ge. 400)) then
- ! Too many calls to decode1a!
+ ! Too many calls to decode1a for this pass -- stop scanning more
+ ! frequency bins for JT65 candidates here, but only here: exit just this
+ ! do i=ia,ib sweep. A "go to 900" used to jump all the way past the rest
+ ! of this pass (including the wideband Q65 full-decode loop further
+ ! below when nqd=0), all remaining nqd passes, and the post-loop
+ ! cleanup/display() -- silently costing Q65 a whole minute even though
+ ! the abort was tripped by JT65 candidate volume, not a Q65 problem.
+ call dbg('map65a: Signal too strong, decoding aborted, nqd=' // itoa(nqd) // &
+ ' ntry=' // itoa(ntry) // ' i=' // itoa(i))
call write_stdout('! Signal too strong, or suspect data? Decoding aborted.'//new_line('a'))
write (13, *) 'Signal too strong, or suspect data? Decoding aborted.'
flush (13)
- go to 900
+ exit
endif
call timer('decode1a', 0)
ifreq = i
ikhz = nint(freq + 0.5*(nfa + nfb) - foffset) - nfshift
idf = nint(1000.0*(freq + 0.5*(nfa + nfb) - foffset - (ikHz + nfshift)))
- call decode1a(dd, newdat, f00, nflip, mode65, nfsample, &
+
+ call decode1a(dd, newdat, f00, nflip, merge(0,mode65,initialization_only), nfsample, &
xpol, mycall, hiscall, hisgrid, neme, ndepth, nqd, dphi, &
ndphi, nutc, ikHz, idf, ipol, ntol, sync2, &
a, dt, pol, nkv, nhist, nsum, nsave, qual, decoded)
call timer('decode1a', 1)
+ ! 2026-09-12: paired with the ccf65 instrumentation above --
+ ! logs decode1a's OUTPUT dt (dt00+dtbest+1.7, so this
+ ! encodes dtbest even though dtbest itself isn't passed
+ ! back to this scope), the running real-candidate count
+ ! this pass (ntry, already used for the "signal too
+ ! strong" abort check), and elapsed wall-clock time, so a
+ ! live capture can show whether the anomaly correlates
+ ! with how many real candidates/how much time this pass
+ ! has already chewed through before reaching this one.
+ call dbg('map65a: decode1a call ' // itoa(ntry) // ' this pass at t=' // &
+ rtoa(sec_midn()) // ' nqd=' // itoa(nqd) // ' i=' // itoa(i) // &
+ ' f00=' // rtoa(real(f00)) // ' dt_out=' // rtoa(dt) // &
+ ' initialization_only=' // itoa(merge(1,0,initialization_only)) // &
+ ' decoded="' // trim(decoded) // '"')
+
+ call dbg('map65a: decode1a result at t=' // rtoa(sec_midn()) // &
+ ' nqd=' // itoa(nqd) // ' i=' // itoa(i) // ' freq=' // rtoa(freq) // &
+ ' sync1=' // rtoa(sync1) // ' initialization_only=' // itoa(merge(1,0,initialization_only)) // &
+ ' decoded="' // trim(decoded) // '"')
-! The case sync1=2.0 is just to make sure decode1a is called and bigfft done.
- if (mode65 .ne. 0 .and. sync1 .ne. 2.000000) then
+ if (mode65 .ne. 0 .and. .not. initialization_only) then
if (km .lt. MAXMSG) km = km + 1
sig(km, 1) = nfile
sig(km, 2) = nutc
@@ -323,7 +879,7 @@ contains
sig(km, 9) = nkv
sig(km, 10) = qual
! sig(km,11)=idphi
- sig(km, 12) = savg(ipol, i)
+ sig(km, 12) = savg_dec(ipol, i)
sig(km, 13) = a(1)
sig(km, 14) = a(2)
sig(km, 15) = a(3)
@@ -334,15 +890,24 @@ contains
freq0 = freq
sync10 = sync1
nkm = 1
+ ! The lookup supplies the neighborhood radius;
+ ! marking it here too would double the exclusion.
+ if (decoded .ne. ' ') &
+ ljt65decoded(i) = .true.
endif
endif
+ endif
endif
endif
enddo !i=ia,ib
-
+
+ call dbg('map65a: JT65 sweep done at t=' // rtoa(sec_midn()) // &
+ ' nqd=' // itoa(nqd) // ' km_exiting=' // itoa(km) // ' ntry=' // itoa(ntry))
+
if (nqd .eq. 1) then
nwrite = 0
if (mode65 .eq. 0) km = 0
+
do k = 1, km
decoded = msg(k)
if (decoded .ne. ' ') then
@@ -382,15 +947,16 @@ contains
endif
call txpol(xpol, decoded, mygrid, npol, nxant, ntxpol, cp)
-
+
if (ndphi .eq. 0) then
write (line, '("!",I3,I5,I4,I6.4,F5.1,I5,1X,A1,1X,A22,I2,I5,I5,1X,A1)') &
nkHz, ndf, npol, nutc, dt, nsync2, cm, decoded, nkv, nqual, ntxpol, cp
call write_stdout(trim(line)//new_line('a'))
else
if (iloop .ge. 1) qphi(iloop) = sig(k, 10)
+
write (line, '("!",I3,I5,I4,I6.4,F5.1,I5,1X,A1,1X,A22,I2,I5,I5,1X,A1)') &
- nkHz, ndf, npol, nutc, dt, nsync2, cm, decoded, nkv, nqual, 30*iloop
+ nkHz, ndf, npol, nutc, dt, nsync2, cm, decoded, nkv, nqual, 30*iloop, '-'
call write_stdout(trim(line)//new_line('a'))
write (27, 1011) 30*iloop, nkHz, ndf, npol, nutc, &
dt, sync2, nkv, nqual, cm, decoded
@@ -403,28 +969,40 @@ contains
q65b_called = .false.
do icand = 1, ncand
if (cand(icand)%iflip .ne. 0) cycle !Keep only Q65 candidates
- freq = cand(icand)%f + nkhz_center - 48.0 - 1.27046
+ freq = cand(icand)%f + nkhz_center - real(nrate_active)/2000.0 - 1.27046
nhzdiff = nint(1000.0*(freq - mousefqso) - mousedf) - nfcal
! Now looking for "quick decode" (nqd=1) candidates at cursor freq +/- ntol.
if (nqd .eq. 1 .and. abs(nhzdiff) .gt. ntol) cycle
ikhz = mousefqso
q65b_called = .true.
f0 = cand(icand)%f
- call timer('q65b ', 0)
+ call timer('q65b ', 0)
+
call q65b(nutc, nqd, nxant, fcenter, nfcal, nfsample, ikhz, mousedf, &
- ntol, xpol, mycall, mygrid, hiscall, hisgrid, mode_q65, f0, fqso, &
- newdat, nagain, max_drift, ndop00, idec)
+ ntol, xpol, idphi, mycall, mygrid, hiscall, hisgrid, mode_q65, f0, fqso, &
+ newdat, nagain, max_drift, ndop00, idec)
+
call timer('q65b ', 1)
- if (idec .ge. 0) candec(icand) = .true.
+
+ ! idec is not a trustworthy success flag here -- q65b
+ ! derives it from cq0(2:2), which is not reset on a
+ ! failed/no-op attempt, so a later candidate in this same
+ ! loop can falsely read back an earlier candidate's
+ ! leftover cq0 digit. nsnr0 is reset to -99 at the top of
+ ! every q65b() call (q65b.F90) and can't carry state
+ ! across candidates this way.
+ if (nsnr0 .gt. -99) candec(icand) = .true.
enddo
if (.not. q65b_called) then
freq = mousefqso + 0.001*mousedf
ikhz = mousefqso
- f0 = freq - (nkhz_center - 48.0 - 1.27046) !### ??? ###
+ f0 = freq - (nkhz_center - real(nrate_active)/2000.0 - 1.27046)
call timer('q65b ', 0)
+
call q65b(nutc, nqd, nxant, fcenter, nfcal, nfsample, ikhz, mousedf, &
- ntol, xpol, mycall, mygrid, hiscall, hisgrid, mode_q65, f0, fqso, &
- newdat, nagain, max_drift, ndop00, idec)
+ ntol, xpol, idphi, mycall, mygrid, hiscall, hisgrid, mode_q65, f0, fqso, &
+ newdat, nagain, max_drift, ndop00, idec, cursor_fallback=.true.)
+
call timer('q65b ', 1)
endif
endif
@@ -440,7 +1018,7 @@ contains
go to 2
endif
- if (ndphi .eq. 1 .and. iloop .eq. 12) call getdphi(qphi)
+ if (ndphi .eq. 1 .and. iloop .eq. 12 .and. nqd .eq. 1) call getdphi(qphi)
if (nqd .eq. 1) then
call sec0(1, tdec)
write (line, '("<QuickDecodeDone>",3I4,I6,F6.2)') &
@@ -454,55 +1032,66 @@ contains
close (16)
endif
call sec0(1, tsec0)
- if (nhsym .eq. nhsym1 .and. tsec0 .gt. 3.0) go to 700
- if (nqd .eq. 1 .and. nagain .eq. 1) go to 900
+ call dbg('map65a: end of nqd=' // itoa(nqd) // ' body at t=' // rtoa(sec_midn()) // &
+ ' tsec0=' // rtoa(tsec0) // ' nhsym=' // itoa(nhsym) // ' nagain=' // itoa(nagain))
+ if (nhsym .eq. nhsym1 .and. tsec0 .gt. 3.0) then
+ call dbg('map65a: ABORT (early-pass 3s budget) at t=' // rtoa(sec_midn()) // &
+ ' tsec0=' // rtoa(tsec0) // ' -- nqd=0 will NOT run this pass')
+ go to 700
+ endif
+ if (nqd .eq. 1 .and. nagain .eq. 1) then
+ call dbg('map65a: SKIP nqd=0 (nagain=1, manual repeat) at t=' // rtoa(sec_midn()))
+ go to 900
+ endif
if (nqd .eq. 0 .and. bq65) then
! Do the wideband Q65 decode
do icand = 1, ncand
if (cand(icand)%iflip .ne. 0) cycle !Do only Q65 candidates here
if (candec(icand)) cycle !Skip if already decoded
- freq = cand(icand)%f + nkhz_center - 48.0 - 1.27046
+ freq = cand(icand)%f + nkhz_center - real(nrate_active)/2000.0 - 1.27046
!###! If here at nqd=1, do only candidates at mousefqso +/- ntol
!### if(nqd.eq.1 .and. abs(freq-mousefqso).gt.0.001*ntol) cycle
ikhz = nint(freq)
f0 = cand(icand)%f
call timer('q65b ', 0)
- call q65b(nutc, nqd, nxant, fcenter, nfcal, nfsample, ikhz, mousedf, ntol, &
- xpol, mycall, mygrid, hiscall, hisgrid, mode_q65, f0, fqso, newdat, &
- nagain, max_drift, ndop00, idec)
+
+ call q65b(nutc, nqd, nxant, fcenter, nfcal, nfsample, ikhz, mousedf, &
+ ntol, xpol, idphi, mycall, mygrid, hiscall, hisgrid, mode_q65, f0, fqso, &
+ newdat, nagain, max_drift, ndop00, idec)
+
call timer('q65b ', 1)
- if (idec .ge. 0) candec(icand) = .true.
+
+ ! See the matching note on the nqd==1 candidate loop above --
+ ! idec is unreliable across back-to-back q65b() calls in the
+ ! same loop; use nsnr0 instead.
+ if (nsnr0 .gt. -99) candec(icand) = .true.
+ if (abort_decode) go to 700
enddo ! icand
- endif
+ endif
call sec0(1, tsec0)
+ call system_clock(t_now, t_rate)
+ if (real(t_now - t_start)/real(t_rate) > 40.0) then
+ call dbg('Decode abort: exceeded 40 seconds at end of do nqd = 1, 0, -1 pass, nqd=' // itoa(nqd))
+ abort_decode = .true.
+ go to 700
+ endif
+
enddo ! nqd
-! Trim the list and produce a sorted index and sizes of groups.
-! (Should trimlist remove all but best SNR for given UTC and message content?)
700 continue
- if (km < 0) km = 0 ! single safety clamp
- call trimlist(sig, km, ftol, indx, nsiz, nz)
+ ! TEMP diagnostic 2026-09-09 for the missing-other-signals-in-Messages investigation.
+ call dbg('map65a: reached label 700 at t=' // rtoa(sec_midn()) // &
+ ' km=' // itoa(km) // ' abort_decode=' // itoa(merge(1,0,abort_decode)) // &
+ ' nhsym=' // itoa(nhsym))
+ call select_unique_decodes(sig, msg, km, ftol, RESULT_DT_TOLERANCE, indx, nz)
+ call dbg('map65a: select_unique_decodes done at t=' // rtoa(sec_midn()) // &
+ ' km=' // itoa(km) // ' nz=' // itoa(nz))
- if (km .gt. 0) done(1:km) = .false.
- j = 0
- ilatest = -1
do n = 1, nz
- ifile0 = 0
- do m = 1, nsiz(n)
- i = indx(j + m)
- ifile = sig(i, 1)
- if (ifile .gt. ifile0 .and. msg(i) .ne. blank) then
- ilatest = i
- ifile0 = ifile
- endif
- enddo
- i = ilatest
-
+ i = indx(n)
if (i .ge. 1) then
- if (.not. done(i)) then
- done(i) = .true.
nutc = sig(i, 2)
freq = sig(i, 3)
sync1 = sig(i, 4)
@@ -546,9 +1135,9 @@ contains
npol = npol - 45
if (npol .lt. 0) npol = npol + 180
endif
-
+
call txpol(xpol, decoded, mygrid, npol, nxant, ntxpol, cp)
-
+
cmode = '#A'
if (mode65 .eq. 2) cmode = '#B'
if (mode65 .eq. 4) cmode = '#C'
@@ -559,11 +1148,8 @@ contains
write (21, 1100) f0, ndf, dt, npol, nsync2, nutc, decoded, '#', cp, &
cmode(1:1), cmode(2:2)! was decoded,cp,
1100 format(f8.3, i5, f5.1, 2i4, i5.4, 2x, a22, 7x, 2a1, 3x, a1, 1x, a1) ! was a22,2x,a1,1x,a1
- endif
-
endif
- j = j + nsiz(n)
- enddo !i=1,km
+ enddo
write (26, 1015) nutc
1015 format(37x, i6.4, ' ')
diff --git a/map65/libm65/mapsim.f90 b/map65/libm65/mapsim.f90
index 8b1d2aa6..9daa21ed 100644
--- a/map65/libm65/mapsim.f90
+++ b/map65/libm65/mapsim.f90
@@ -2,29 +2,32 @@ module dopspread_mod
implicit none
contains
- subroutine dopspread(cwave,fspread)
+ subroutine dopspread(cwave, npts, fsample, fspread)
use four2a_mod
use gran_interface
use iso_fortran_env, only: real32, real64
implicit none
- integer, parameter :: NMAX=60*96000
- integer, parameter :: NFFT=NMAX, NH=NFFT/2
- complex, intent(inout) :: cwave(NMAX)
- real(real64), intent(in) :: fspread
- complex, allocatable :: cspread(:)
+ integer, intent(in) :: npts
+ real(real64), intent(in) :: fsample, fspread
+ complex(real32), intent(inout) :: cwave(npts)
+
+ integer :: nfft, nh, i
+ complex(real32), allocatable :: cspread(:)
real(real32) :: twopi, df, b, f, x, a, phi1, phi2
real(real32) :: sum, p, avep, fac
- complex :: z
- integer :: i
-
- allocate(cspread(0:NMAX-1))
-
- twopi=8.0*atan(1.0)
- df=96000.0/nfft
+ complex(real32) :: z
+
+ nfft = npts
+ nh = nfft/2
+ allocate(cspread(0:nfft-1))
+
+ twopi = 8.0*atan(1.0)
+ df = real(fsample,real32)/real(nfft,real32)
+
cspread(0)=1.0
- cspread(NH)=0.
+ cspread(nh)=0.
b=6.0 !Use truncated Lorenzian shape for fspread
- do i=1,NH
+ do i=1,nh
f=i*df
x=b*f/fspread
z=0.
@@ -73,9 +76,9 @@ program mapsim
use iso_fortran_env, only: real32, real64, int16
implicit none
- integer, parameter :: NMAX=60*96000
+ integer :: NMAX
- real(real32) d4(4,NMAX) !Floating-point data
+ real(real32), allocatable :: d4(:,:) !Floating-point data
integer(int16), allocatable :: id4(:,:) !i*2 data, dual polarization
integer(int16), allocatable :: id2(:,:) !i*2 data, single polarization
complex(real32), allocatable :: cwave(:) !i*2 data, single polarization
@@ -97,6 +100,7 @@ program mapsim
integer :: nargs, nsigs, npol, nfiles, isig, nmin, ifile
integer :: ntone_spacing, ntxfreq, nsendingsh, nwave, npts
integer :: ilist, i0, i, j
+ integer :: sRatekHz
data msg_list/ &
! 'CQ K1WDG/R','CQ YL/EA8DBM','<YL/EA8DBM> OH3LWP KP11', &
@@ -133,14 +137,10 @@ program mapsim
'W7IYI K8JYJ EM54','W9KYK K0LYL EM55','G0MYM F1NYN JN56', &
'G2OYO F3PYP JN57','G4QYQ F5RYR JN58','G6SYS F7TYT JN59'/
- allocate(id4(4,NMAX)) !i*2 data, dual polarization
- allocate(id2(2,NMAX)) !i*2 data, single polarization
- allocate(cwave(NMAX)) !Generated complex waveform (no noise)
-
nargs=command_argument_count()
- if(nargs.ne.12) then
- print*,'Usage: mapsim "message" mode DT fa fb nsigs pol fDop SNR nfiles fcenter HHmm'
- print*,'Example: mapsim "CQ K1ABC FN42" B 2.5 -20 20 21 45 0.0 -20 1 1296.1 1803'
+ if(nargs.ne.13) then
+ print*,'Usage: mapsim "message" mode DT fa fb nsigs pol fDop SNR nfiles fcenter HHmm sRatekHz'
+ print*,'Example: mapsim "CQ K1ABC FN42" B 2.5 -20 20 21 45 0.0 -20 1 1296.1 1803 96'
print*,' '
print*,' mode = A B C for JT65; QA-QE for Q65-60A'
print*,' fa = lowest freq in kHz, relative to center'
@@ -148,6 +148,7 @@ program mapsim
print*,' message = "list" to use callsigns from list'
print*,' pol = -1 to generate a range of polarization angles.'
print*,' SNR = 0 to generate a range of SNRs.'
+ print*,' sRateKHz must be one of 96, 128, 192,256'
go to 999
endif
@@ -174,16 +175,31 @@ program mapsim
read(arg,*) fcenter ! added by w3sz
call get_command_argument(12,arg) ! added by w3sz
read(arg,*) hhmm ! added by w3sz
+ call get_command_argument(13,arg) ! added by w3sz
+ read(arg,*) sRatekHz ! added by w3sz
+
+ if (sRatekHz /= 96 .and. sRatekHz /= 128 .and. sRatekHz /= 192 .and. sRatekHz /= 256) then
+ write(*,*) 'ERROR: Invalid sample rate ', sRatekHz, ' kHz'
+ write(*,*) 'Allowed sample rates are: 96, 128, 192, 256 kHz'
+ stop
+ endif
+
+ fsample = 1000.d0 * sRatekHz
+ dt = 1.d0 / fsample
+ NMAX = 60 * sRatekHz * 1000
+ npts = NMAX
+ allocate(d4(4, NMAX))
+ allocate(id4(4,NMAX))
+ allocate(id2(2,NMAX))
+ allocate(cwave(NMAX))
message=msg0 !Transmitted message
rmsdb=25.
rms=10.0**(0.05*rmsdb)
! w3sz fcenter=144.125d0 !Center frequency (MHz)
- fsample=96000.d0 !Sample rate (Hz)
- dt=1.d0/fsample !Sample interval (s)
twopi=8.d0*atan(1.d0)
rad=360.0/twopi
- samfac=1.d0
+ samfac = fsample / 96000.d0
bq65=(mode(1:1).eq.'Q')
ntone_spacing=1
ntxfreq=1270
@@ -192,7 +208,6 @@ program mapsim
if(mode(1:1).eq.'C' .or. mode(2:2).eq.'C') ntone_spacing=4
if(mode(2:2).eq.'D') ntone_spacing=8
if(mode(2:2).eq.'E') ntone_spacing=16
- npts=NMAX
nsendingsh=0 ! Initialize nsendingsh (was implicit?)
write(*,1000)
@@ -203,35 +218,23 @@ program mapsim
nmin=ifile-1
if(mode(2:2).eq.' ') nmin=2*nmin
write(fname, '(I6.6, "_", I4.4)') ifile, hhmm !Create the output filenames ! w3sz was nmin
- open(10,file=fname//'.iq',access='stream',status='unknown')
- open(11,file=fname//'.tf2',access='stream',status='unknown')
+ open(10,file=fname//'.iq',access='stream',status='replace')
+ open(11,file=fname//'.tf2',access='stream',status='replace')
call noisegen(d4,npts) !Generate Gaussuian noise
if(msg0(1:4).ne.'list') then
- if(bq65) then
- call gen_q65_cwave(message,ntxfreq,ntone_spacing,msgsent, &
- cwave,nwave)
- else
- call cgen65(message,ntone_spacing,samfac,nsendingsh,msgsent, &
- cwave,nwave)
- endif
+ call generate_cwave(message,msgsent,cwave,nwave)
endif
- if(fdop.gt.0.0) call dopspread(cwave,fdop)
+ if(fdop.gt.0.0) call dopspread(cwave,npts,fsample,fdop)
do isig=1,nsigs
if(msg0(1:4).eq.'list') then
ilist=ilist+1
message=msg_list(ilist)
- if(bq65) then
- call gen_q65_cwave(message,ntxfreq,ntone_spacing,msgsent, &
- cwave,nwave)
- else
- call cgen65(message,ntone_spacing,samfac,nsendingsh,msgsent, &
- cwave,nwave)
- endif
+ call generate_cwave(message,msgsent,cwave,nwave)
endif
if(npol.lt.0) pol=(isig-1)*180.0/nsigs
@@ -243,7 +246,7 @@ program mapsim
snrdbx=snrdb
if(snrdb.eq.0.0) snrdbx=-15.0 - 15.0*(isig-1.0)/nsigs
- sig=sqrt(2.2*2500.0/96000.0) * 10.0**(0.05*snrdbx)
+ sig = sqrt(2.2*2500.0/fsample) * 10.0**(0.05*snrdbx)
write(*,1020) ifile,isig,mode,dt0,0.001*f,nint(pol),fDop,snrdbx,msgsent
1020 format(i3,i3,2x,a2,f6.2,f8.3,i5,2f7.1,2x,a24) !w3sz was a22
@@ -276,15 +279,38 @@ program mapsim
id2(2,i)=id4(2,i)
enddo
+ write(*,*) 'DEBUG: fsample =', fsample, ' sRatekHz =', sRatekHz, &
+ ' NMAX =', NMAX, ' npts =', npts
+
write(10) fcenter,id2(1:2,1:npts)
write(11) fcenter,id4(1:4,1:npts)
close(10)
close(11)
enddo
-
+ deallocate(d4)
deallocate(id4)
deallocate(id2)
deallocate(cwave)
-999 end program mapsim
+999 continue
+contains
+
+ subroutine generate_cwave(message,msgsent,cwave,nwave)
+ character(len=*),intent(inout) :: message
+ character(len=*),intent(out) :: msgsent
+ complex, intent(out) :: cwave(:)
+ integer, intent(out) :: nwave
+
+ ! cgen65 defines only 22 characters; blank-fill so the a24 output is fully defined
+ msgsent = ' '
+ if(bq65) then
+ call gen_q65_cwave(message,ntxfreq,ntone_spacing,fsample,msgsent, &
+ cwave,nwave)
+ else
+ call cgen65(message,ntone_spacing,samfac,nsendingsh,msgsent, &
+ cwave,nwave)
+ endif
+ end subroutine generate_cwave
+
+end program mapsim
diff --git a/map65/libm65/nchar.f90 b/map65/libm65/nchar.f90
index 1a7f2e11..5f8688f0 100644
--- a/map65/libm65/nchar.f90
+++ b/map65/libm65/nchar.f90
@@ -16,6 +16,7 @@ contains
else if(c.ge.' ') then
n=36
else
+ ! TODO: Return an invalid status instead of terminating MAP65.
! Print*,'Invalid character in callsign ',c,' ',ichar(c)
stop 1
endif
diff --git a/map65/libm65/npar_ptrs_mod.f90 b/map65/libm65/npar_ptrs_mod.f90
index ff8d4b0d..f33a92fc 100644
--- a/map65/libm65/npar_ptrs_mod.f90
+++ b/map65/libm65/npar_ptrs_mod.f90
@@ -2,27 +2,148 @@ module npar_ptrs_mod
use iso_c_binding
implicit none
- ! Scalar values
- real(c_double) :: fcenter ! RF center frequency (MHz)
- integer(c_int) :: nfa ! Low decode limit (kHz, RF-relative)
- integer(c_int) :: nfb ! High decode limit (kHz, RF-relative)
- integer(c_int) :: nfshift ! Display center shift (kHz, RF-relative)
- integer(c_int) :: nfcal ! Frequency calibration offset (Hz)
- integer(c_int) :: nutc, idphi, mousedf, mousefqso, nagain, ndepth
- integer(c_int) :: ndiskdat, neme, newdat,map65RxLog
- integer(c_int) :: mcall3, ntimeout, ntol, nxant, nfsample
- integer(c_int) :: nxpol, nmode, nsave, max_drift, nhsym
- integer(c_int) :: ndop00,nrxlog,nkeep
- character(len=12) :: mycall, hiscall
- character(len=6) :: mygrid, hisgrid
- character(len=20) :: datetime ! changed 1/4/26 to match legacy code
- integer(c_int) :: stop_m65 = 0
- integer(c_int) :: decoder_ready = 0
+ type :: decode_parameters
+ real(c_double) :: fcenter = 0
+ real(c_double) :: ftol_nb = 0
+ integer(c_int) :: nfa = 0
+ integer(c_int) :: nfb = 0
+ integer(c_int) :: nfshift = 0
+ integer(c_int) :: nfcal = 0
+ integer(c_int) :: nutc = 0
+ integer(c_int) :: idphi = 0
+ integer(c_int) :: mousedf = 0
+ integer(c_int) :: mousefqso = 0
+ integer(c_int) :: nagain = 0
+ integer(c_int) :: ndepth = 0
+ integer(c_int) :: ndiskdat = 0
+ integer(c_int) :: neme = 0
+ integer(c_int) :: newdat = 0
+ integer(c_int) :: map65RxLog = 0
+ integer(c_int) :: mcall3 = 0
+ integer(c_int) :: ntimeout = 0
+ integer(c_int) :: ntol = 0
+ integer(c_int) :: nxant = 0
+ integer(c_int) :: nfsample = 0
+ integer(c_int) :: nxpol = 0
+ integer(c_int) :: nmode = 0
+ integer(c_int) :: nsave = 0
+ integer(c_int) :: max_drift = 0
+ integer(c_int) :: nhsym = 0
+ integer(c_int) :: ndop00 = 0
+ integer(c_int) :: nrxlog = 0
+ integer(c_int) :: nkeep = 0
+ integer(c_int) :: manualDecodeFlag = 0
+ character(len=12) :: mycall = ''
+ character(len=12) :: hiscall = ''
+ character(len=6) :: mygrid = ''
+ character(len=6) :: hisgrid = ''
+ character(len=20) :: datetime = ''
+ end type
+
+ ! GUI setters prepare draft; only the decoder changes active after claiming a request.
+ type(decode_parameters), target, save :: active
+ type(decode_parameters), save :: draft
+ type :: decode_request
+ type(decode_parameters) :: parameters
+ integer(c_int64_t) :: id
+ integer(c_int64_t) :: input_generation
+ type(decode_request), pointer :: next => null()
+ end type
+ type(decode_request), pointer, save :: pending_head => null(), pending_tail => null()
+ integer(c_int64_t), save :: published_request_id = 0
+ integer(c_int64_t), save :: active_request_id = 0
+ integer(c_int64_t), save :: live_input_generation = 0
+ integer(c_int64_t), save :: active_input_generation = 0
+ logical, save :: active_request_expired = .false.
+
+ real(c_double), pointer :: fcenter => active%fcenter
+ real(c_double), pointer :: ftol_nb => active%ftol_nb
+ integer(c_int), pointer :: nfa => active%nfa
+ integer(c_int), pointer :: nfb => active%nfb
+ integer(c_int), pointer :: nfshift => active%nfshift
+ integer(c_int), pointer :: nfcal => active%nfcal
+ integer(c_int), pointer :: nutc => active%nutc
+ integer(c_int), pointer :: idphi => active%idphi
+ integer(c_int), pointer :: mousedf => active%mousedf
+ integer(c_int), pointer :: mousefqso => active%mousefqso
+ integer(c_int), pointer :: nagain => active%nagain
+ integer(c_int), pointer :: ndepth => active%ndepth
+ integer(c_int), pointer :: ndiskdat => active%ndiskdat
+ integer(c_int), pointer :: neme => active%neme
+ integer(c_int), pointer :: newdat => active%newdat
+ integer(c_int), pointer :: map65RxLog => active%map65RxLog
+ integer(c_int), pointer :: mcall3 => active%mcall3
+ integer(c_int), pointer :: ntimeout => active%ntimeout
+ integer(c_int), pointer :: ntol => active%ntol
+ integer(c_int), pointer :: nxant => active%nxant
+ integer(c_int), pointer :: nfsample => active%nfsample
+ integer(c_int), pointer :: nxpol => active%nxpol
+ integer(c_int), pointer :: nmode => active%nmode
+ integer(c_int), pointer :: nsave => active%nsave
+ integer(c_int), pointer :: max_drift => active%max_drift
+ integer(c_int), pointer :: nhsym => active%nhsym
+ integer(c_int), pointer :: ndop00 => active%ndop00
+ integer(c_int), pointer :: nrxlog => active%nrxlog
+ integer(c_int), pointer :: nkeep => active%nkeep
+ integer(c_int), pointer :: manualDecodeFlag => active%manualDecodeFlag
+ character(len=12), pointer :: mycall => active%mycall
+ character(len=12), pointer :: hiscall => active%hiscall
+ character(len=6), pointer :: mygrid => active%mygrid
+ character(len=6), pointer :: hisgrid => active%hisgrid
+ character(len=20), pointer :: datetime => active%datetime
+ integer(c_int) :: stop_m65 = 0
+ integer(c_int) :: decoder_ready = 0
character(len=512) :: wsjtx_dir = ''
-
+ integer(c_int) :: nrate_active = 96000
+ integer(c_int) :: nfft_active = 32768
+ integer(c_int) :: nsmax_active = 60*96000
+ integer(c_int) :: nfft_big_active = 56*96000
+ integer(c_int) :: t_start = -1
+ logical(c_bool) :: abort_decode = .false.
+
+ interface
+ subroutine lock_decode_requests() bind(C)
+ end subroutine
+ subroutine unlock_decode_requests() bind(C)
+ end subroutine
+ end interface
+
contains
+ subroutine set_manual_decode_flag(val) bind(C, name="set_manual_decode_flag")
+ integer(c_int), value :: val
+ call lock_decode_requests()
+ draft%manualDecodeFlag = val
+ call unlock_decode_requests()
+ end subroutine
+
+ function get_manual_decode_flag() bind(C, name="get_manual_decode_flag")
+ use iso_c_binding
+ integer(c_int) :: get_manual_decode_flag
+ call lock_decode_requests()
+ get_manual_decode_flag = draft%manualDecodeFlag
+ call unlock_decode_requests()
+ end function
+
+ subroutine set_ftol_nb(val) bind(C, name="set_ftol_nb")
+ integer(c_int), value :: val
+ call lock_decode_requests()
+ draft%ftol_nb = val
+ call unlock_decode_requests()
+ end subroutine
+
+ subroutine set_runtime_params(rate_hz, nfft, nfft_big) bind(C, name="set_runtime_params_")
+ use iso_c_binding
+ implicit none
+ integer(c_int), value :: rate_hz, nfft, nfft_big
+
+ nrate_active = rate_hz
+ nfft_active = nfft
+ nsmax_active = 60*rate_hz
+ nfft_big_active = nfft_big
+ end subroutine set_runtime_params
+
subroutine set_wsjtx_dir(path, path_len) bind(C, name="set_wsjtx_dir_")
use iso_c_binding
implicit none
@@ -41,48 +162,63 @@ contains
subroutine set_stop_m65(val) bind(C, name="set_stop_m65")
use iso_c_binding
integer(c_int), value :: val
+ call lock_decode_requests()
stop_m65 = 0
- if (val /= 0) stop_m65 = 1
+ if (val /= 0) then
+ stop_m65 = 1
+ call clear_pending_requests()
+ endif
+ call unlock_decode_requests()
end subroutine
subroutine set_decoder_ready(val) bind(C, name="set_decoder_ready")
use iso_c_binding
integer(c_int), value :: val
+ call lock_decode_requests()
decoder_ready = 0
if (val /= 0) decoder_ready = 1
+ call unlock_decode_requests()
end subroutine
subroutine get_mycall(buf) bind(C, name="get_mycall")
character(kind=c_char), intent(out) :: buf(12)
integer :: i
+ call lock_decode_requests()
do i = 1, 12
- buf(i) = mycall(i:i)
+ buf(i) = draft%mycall(i:i)
end do
+ call unlock_decode_requests()
end subroutine get_mycall
subroutine get_hiscall(buf) bind(C, name="get_hiscall")
character(kind=c_char), intent(out) :: buf(12)
integer :: i
+ call lock_decode_requests()
do i = 1, 12
- buf(i) = hiscall(i:i)
+ buf(i) = draft%hiscall(i:i)
end do
+ call unlock_decode_requests()
end subroutine
subroutine get_mygrid(buf) bind(C, name="get_mygrid")
character(kind=c_char), intent(out) :: buf(6)
integer :: i
+ call lock_decode_requests()
do i = 1, 6
- buf(i) = mygrid(i:i)
+ buf(i) = draft%mygrid(i:i)
end do
+ call unlock_decode_requests()
end subroutine
subroutine get_hisgrid(buf) bind(C, name="get_hisgrid")
character(kind=c_char), intent(out) :: buf(6)
integer :: i
+ call lock_decode_requests()
do i = 1, 6
- buf(i) = hisgrid(i:i)
+ buf(i) = draft%hisgrid(i:i)
end do
+ call unlock_decode_requests()
end subroutine
! NOTE ABOUT DATETIME LENGTH (17 vs 20)
@@ -103,9 +239,11 @@ contains
subroutine get_datetime(buf) bind(C, name="get_datetime")
character(kind=c_char), intent(out) :: buf(17)
integer :: i
+ call lock_decode_requests()
do i = 1, 17
- buf(i) = datetime(i:i)
+ buf(i) = draft%datetime(i:i)
end do
+ call unlock_decode_requests()
end subroutine
! Helper subroutine to copy fixed-length Fortran string to C buffer
@@ -123,344 +261,557 @@ contains
function get_fcenter() bind(C, name="get_fcenter")
real(c_double) :: get_fcenter
- get_fcenter = fcenter
+ call lock_decode_requests()
+ get_fcenter = draft%fcenter
+ call unlock_decode_requests()
end function
function get_nkeep() bind(C, name="get_nkeep")
integer(c_int) :: get_nkeep
- get_nkeep = nkeep
+ call lock_decode_requests()
+ get_nkeep = draft%nkeep
+ call unlock_decode_requests()
end function
function get_ndop00() bind(C, name="get_ndop00")
integer(c_int) :: get_ndop00
- get_ndop00 = ndop00
+ call lock_decode_requests()
+ get_ndop00 = draft%ndop00
+ call unlock_decode_requests()
end function
function get_map65RxLog() bind(C, name="get_map65RxLog")
integer(c_int) :: get_map65RxLog
- get_map65RxLog = map65RxLog
+ call lock_decode_requests()
+ get_map65RxLog = draft%map65RxLog
+ call unlock_decode_requests()
end function
function get_nutc() bind(C, name="get_nutc")
integer(c_int) :: get_nutc
- get_nutc = nutc
+ call lock_decode_requests()
+ get_nutc = draft%nutc
+ call unlock_decode_requests()
end function
function get_idphi() bind(C, name="get_idphi")
integer(c_int) :: get_idphi
- get_idphi = idphi
+ call lock_decode_requests()
+ get_idphi = draft%idphi
+ call unlock_decode_requests()
end function
function get_mousedf() bind(C, name="get_mousedf")
integer(c_int) :: get_mousedf
- get_mousedf = mousedf
+ call lock_decode_requests()
+ get_mousedf = draft%mousedf
+ call unlock_decode_requests()
end function
function get_mousefqso() bind(C, name="get_mousefqso")
integer(c_int) :: get_mousefqso
- get_mousefqso = mousefqso
+ call lock_decode_requests()
+ get_mousefqso = draft%mousefqso
+ call unlock_decode_requests()
end function
function get_nagain() bind(C, name="get_nagain")
integer(c_int) :: get_nagain
- get_nagain = nagain
+ call lock_decode_requests()
+ get_nagain = draft%nagain
+ call unlock_decode_requests()
end function
function get_ndepth() bind(C, name="get_ndepth")
integer(c_int) :: get_ndepth
- get_ndepth = ndepth
+ call lock_decode_requests()
+ get_ndepth = draft%ndepth
+ call unlock_decode_requests()
end function
function get_ndiskdat() bind(C, name="get_ndiskdat")
integer(c_int) :: get_ndiskdat
- get_ndiskdat = ndiskdat
+ call lock_decode_requests()
+ get_ndiskdat = draft%ndiskdat
+ call unlock_decode_requests()
end function
function get_neme() bind(C, name="get_neme")
integer(c_int) :: get_neme
- get_neme = neme
+ call lock_decode_requests()
+ get_neme = draft%neme
+ call unlock_decode_requests()
end function
function get_newdat() bind(C, name="get_newdat")
integer(c_int) :: get_newdat
- get_newdat = newdat
+ call lock_decode_requests()
+ get_newdat = draft%newdat
+ call unlock_decode_requests()
end function
function get_nfa() bind(C, name="get_nfa")
integer(c_int) :: get_nfa
- get_nfa = nfa
+ call lock_decode_requests()
+ get_nfa = draft%nfa
+ call unlock_decode_requests()
end function
function get_nfb() bind(C, name="get_nfb")
integer(c_int) :: get_nfb
- get_nfb = nfb
+ call lock_decode_requests()
+ get_nfb = draft%nfb
+ call unlock_decode_requests()
end function
function get_nfcal() bind(C, name="get_nfcal")
integer(c_int) :: get_nfcal
- get_nfcal = nfcal
+ call lock_decode_requests()
+ get_nfcal = draft%nfcal
+ call unlock_decode_requests()
end function
function get_nfshift() bind(C, name="get_nfshift")
integer(c_int) :: get_nfshift
- get_nfshift = nfshift
+ call lock_decode_requests()
+ get_nfshift = draft%nfshift
+ call unlock_decode_requests()
end function
function get_mcall3() bind(C, name="get_mcall3")
integer(c_int) :: get_mcall3
- get_mcall3 = mcall3
+ call lock_decode_requests()
+ get_mcall3 = draft%mcall3
+ call unlock_decode_requests()
end function
function get_ntimeout() bind(C, name="get_ntimeout")
integer(c_int) :: get_ntimeout
- get_ntimeout = ntimeout
+ call lock_decode_requests()
+ get_ntimeout = draft%ntimeout
+ call unlock_decode_requests()
end function
function get_ntol() bind(C, name="get_ntol")
integer(c_int) :: get_ntol
- get_ntol = ntol
+ call lock_decode_requests()
+ get_ntol = draft%ntol
+ call unlock_decode_requests()
end function
function get_nxant() bind(C, name="get_nxant")
integer(c_int) :: get_nxant
- get_nxant = nxant
+ call lock_decode_requests()
+ get_nxant = draft%nxant
+ call unlock_decode_requests()
end function
function get_nfsample() bind(C, name="get_nfsample")
integer(c_int) :: get_nfsample
- get_nfsample = nfsample
+ call lock_decode_requests()
+ get_nfsample = draft%nfsample
+ call unlock_decode_requests()
end function
function get_nxpol() bind(C, name="get_nxpol")
integer(c_int) :: get_nxpol
- get_nxpol = nxpol
+ call lock_decode_requests()
+ get_nxpol = draft%nxpol
+ call unlock_decode_requests()
end function
function get_nmode() bind(C, name="get_nmode")
integer(c_int) :: get_nmode
- get_nmode = nmode
+ call lock_decode_requests()
+ get_nmode = draft%nmode
+ call unlock_decode_requests()
end function
function get_nsave() bind(C, name="get_nsave")
integer(c_int) :: get_nsave
- get_nsave = nsave
+ call lock_decode_requests()
+ get_nsave = draft%nsave
+ call unlock_decode_requests()
end function
function get_max_drift() bind(C, name="get_max_drift")
integer(c_int) :: get_max_drift
- get_max_drift = max_drift
+ call lock_decode_requests()
+ get_max_drift = draft%max_drift
+ call unlock_decode_requests()
end function
function get_nhsym() bind(C, name="get_nhsym")
integer(c_int) :: get_nhsym
- get_nhsym = nhsym
+ call lock_decode_requests()
+ get_nhsym = draft%nhsym
+ call unlock_decode_requests()
end function
subroutine set_fcenter(val) bind(C, name="set_fcenter")
use iso_c_binding
real(c_double), value :: val
- fcenter = val
+ call lock_decode_requests()
+ draft%fcenter = val
+ call unlock_decode_requests()
end subroutine
subroutine set_nkeep(val) bind(C, name="set_nkeep")
use iso_c_binding
integer(c_int), value :: val
- nkeep = val
+ call lock_decode_requests()
+ draft%nkeep = val
+ call unlock_decode_requests()
end subroutine
subroutine set_ndop00(val) bind(C, name="set_ndop00")
use iso_c_binding
integer(c_int), value :: val
- ndop00 = val
+ call lock_decode_requests()
+ draft%ndop00 = val
+ call unlock_decode_requests()
end subroutine
subroutine set_map65RxLog(val) bind(C, name="set_map65RxLog")
use iso_c_binding
integer(c_int), value :: val
- map65RxLog = val
+ ! map65RxLog is read back by get_map65RxLog() for debug logging only.
+ ! nrxlog is the variable m65c()/decode0.f90 actually check (iand bits
+ ! 1/2/4/8) to write the date header, erase map65_rx.log, clear the
+ ! decode-history file on Erase, and force manual dPhi. Before this fix
+ ! nrxlog was never assigned anywhere, so all four of those flag bits
+ ! were permanently dead -- e.g. Erase Band Map and Messages never
+ ! actually cleared unit 26, so the next display() cycle just replayed
+ ! the full decode history back into the Messages window.
+ call lock_decode_requests()
+ draft%map65RxLog = val
+ draft%nrxlog = val
+ call unlock_decode_requests()
end subroutine
subroutine set_nutc(val) bind(C, name="set_nutc")
use iso_c_binding
integer(c_int), value :: val
- nutc = val
+ call lock_decode_requests()
+ draft%nutc = val
+ call unlock_decode_requests()
end subroutine
subroutine set_idphi(val) bind(C, name="set_idphi")
use iso_c_binding
integer(c_int), value :: val
- idphi = val
+ call lock_decode_requests()
+ draft%idphi = val
+ call unlock_decode_requests()
end subroutine
subroutine set_mousedf(val) bind(C, name="set_mousedf")
use iso_c_binding
integer(c_int), value :: val
- mousedf = val
+ call lock_decode_requests()
+ draft%mousedf = val
+ call unlock_decode_requests()
end subroutine
subroutine set_mousefqso(val) bind(C, name="set_mousefqso")
use iso_c_binding
integer(c_int), value :: val
- mousefqso = val
+ call lock_decode_requests()
+ draft%mousefqso = val
+ call unlock_decode_requests()
end subroutine
subroutine set_nagain(val) bind(C, name="set_nagain")
use iso_c_binding
integer(c_int), value :: val
- nagain = val
+ call lock_decode_requests()
+ draft%nagain = val
+ call unlock_decode_requests()
end subroutine
subroutine set_ndepth(val) bind(C, name="set_ndepth")
use iso_c_binding
integer(c_int), value :: val
- ndepth = val
+ call lock_decode_requests()
+ draft%ndepth = val
+ call unlock_decode_requests()
end subroutine
subroutine set_ndiskdat(val) bind(C, name="set_ndiskdat")
use iso_c_binding
integer(c_int), value :: val
- ndiskdat = val
+ call lock_decode_requests()
+ draft%ndiskdat = val
+ call unlock_decode_requests()
end subroutine
subroutine set_neme(val) bind(C, name="set_neme")
use iso_c_binding
integer(c_int), value :: val
- neme = val
+ call lock_decode_requests()
+ draft%neme = val
+ call unlock_decode_requests()
end subroutine
subroutine set_newdat(val) bind(C, name="set_newdat")
use iso_c_binding
integer(c_int), value :: val
- newdat = val
+ call lock_decode_requests()
+ draft%newdat = val
+ call unlock_decode_requests()
end subroutine
subroutine set_nfa(val) bind(C, name="set_nfa")
use iso_c_binding
integer(c_int), value :: val
- nfa = val
+ call lock_decode_requests()
+ draft%nfa = val
+ call unlock_decode_requests()
end subroutine
subroutine set_nfb(val) bind(C, name="set_nfb")
use iso_c_binding
integer(c_int), value :: val
- nfb = val
+ call lock_decode_requests()
+ draft%nfb = val
+ call unlock_decode_requests()
end subroutine
subroutine set_nfcal(val) bind(C, name="set_nfcal")
use iso_c_binding
integer(c_int), value :: val
- nfcal = val
+ call lock_decode_requests()
+ draft%nfcal = val
+ call unlock_decode_requests()
end subroutine
subroutine set_nfshift(val) bind(C, name="set_nfshift")
use iso_c_binding
integer(c_int), value :: val
- nfshift = val
+ call lock_decode_requests()
+ draft%nfshift = val
+ call unlock_decode_requests()
end subroutine
subroutine set_mcall3(val) bind(C, name="set_mcall3")
use iso_c_binding
integer(c_int), value :: val
- mcall3 = val
+ call lock_decode_requests()
+ draft%mcall3 = val
+ call unlock_decode_requests()
end subroutine
subroutine set_ntimeout(val) bind(C, name="set_ntimeout")
use iso_c_binding
integer(c_int), value :: val
- ntimeout = val
+ call lock_decode_requests()
+ draft%ntimeout = val
+ call unlock_decode_requests()
end subroutine
subroutine set_ntol(val) bind(C, name="set_ntol")
use iso_c_binding
integer(c_int), value :: val
- ntol = val
+ call lock_decode_requests()
+ draft%ntol = val
+ call unlock_decode_requests()
end subroutine
subroutine set_nxant(val) bind(C, name="set_nxant")
use iso_c_binding
integer(c_int), value :: val
- nxant = val
+ call lock_decode_requests()
+ draft%nxant = val
+ call unlock_decode_requests()
end subroutine
subroutine set_nfsample(val) bind(C, name="set_nfsample")
use iso_c_binding
integer(c_int), value :: val
- nfsample = val
+ call lock_decode_requests()
+ draft%nfsample = val
+ call unlock_decode_requests()
end subroutine
subroutine set_nxpol(val) bind(C, name="set_nxpol")
use iso_c_binding
integer(c_int), value :: val
- nxpol = val
+ call lock_decode_requests()
+ draft%nxpol = val
+ call unlock_decode_requests()
end subroutine
subroutine set_nmode(val) bind(C, name="set_nmode")
use iso_c_binding
integer(c_int), value :: val
- nmode = val
+ call lock_decode_requests()
+ draft%nmode = val
+ call unlock_decode_requests()
end subroutine
subroutine set_nsave(val) bind(C, name="set_nsave")
use iso_c_binding
integer(c_int), value :: val
- nsave = val
+ call lock_decode_requests()
+ draft%nsave = val
+ call unlock_decode_requests()
end subroutine
subroutine set_max_drift(val) bind(C, name="set_max_drift")
use iso_c_binding
integer(c_int), value :: val
- max_drift = val
+ call lock_decode_requests()
+ draft%max_drift = val
+ call unlock_decode_requests()
end subroutine
subroutine set_nhsym(val) bind(C, name="set_nhsym")
use iso_c_binding
integer(c_int), value :: val
- nhsym = val
+ call lock_decode_requests()
+ draft%nhsym = val
+ call unlock_decode_requests()
end subroutine
subroutine set_mycall(buf) bind(C, name="set_mycall")
use iso_c_binding
character(kind=c_char), intent(in) :: buf(12)
integer :: i
+ call lock_decode_requests()
do i = 1, 12
- mycall(i:i) = buf(i)
+ draft%mycall(i:i) = buf(i)
end do
+ call unlock_decode_requests()
end subroutine
subroutine set_hiscall(buf) bind(C, name="set_hiscall")
use iso_c_binding
character(kind=c_char), intent(in) :: buf(12)
integer :: i
+ call lock_decode_requests()
do i = 1, 12
- hiscall(i:i) = buf(i)
+ draft%hiscall(i:i) = buf(i)
end do
+ call unlock_decode_requests()
end subroutine
subroutine set_mygrid(buf) bind(C, name="set_mygrid")
use iso_c_binding
character(kind=c_char), intent(in) :: buf(6)
integer :: i
+ call lock_decode_requests()
do i = 1, 6
- mygrid(i:i) = buf(i)
+ draft%mygrid(i:i) = buf(i)
end do
+ call unlock_decode_requests()
end subroutine
subroutine set_hisgrid(buf) bind(C, name="set_hisgrid")
use iso_c_binding
character(kind=c_char), intent(in) :: buf(6)
integer :: i
+ call lock_decode_requests()
do i = 1, 6
- hisgrid(i:i) = buf(i)
+ draft%hisgrid(i:i) = buf(i)
end do
+ call unlock_decode_requests()
end subroutine
subroutine set_datetime(buf) bind(C, name="set_datetime")
use iso_c_binding
character(kind=c_char), intent(in) :: buf(17)
integer :: i
+ call lock_decode_requests()
do i = 1, 17
- datetime(i:i) = buf(i)
+ draft%datetime(i:i) = buf(i)
end do
+ call unlock_decode_requests()
end subroutine
+ function publish_decode_request() result(request_id) bind(C)
+ integer(c_int64_t) :: request_id
+ type(decode_request), pointer :: request
+
+ allocate(request)
+ call lock_decode_requests()
+ published_request_id = published_request_id + 1
+ request_id = published_request_id
+ request%id = request_id
+ request%input_generation = live_input_generation
+ request%parameters = draft
+ request%parameters%newdat = 1
+ if (associated(pending_tail)) then
+ pending_tail%next => request
+ else
+ pending_head => request
+ endif
+ pending_tail => request
+ decoder_ready = 1
+ draft%manualDecodeFlag = 0
+ call unlock_decode_requests()
+ end function
+
+ logical function claim_decode_request()
+ type(decode_request), pointer :: request
+
+ call lock_decode_requests()
+ claim_decode_request = decoder_ready /= 0 .and. associated(pending_head)
+ if (claim_decode_request) then
+ request => pending_head
+ pending_head => request%next
+ if (.not. associated(pending_head)) nullify(pending_tail)
+ active = request%parameters
+ active_request_id = request%id
+ active_input_generation = request%input_generation
+ active_request_expired = active%ndiskdat == 0 .and. active%nagain == 0 .and. &
+ active%manualDecodeFlag == 0 .and. request%input_generation /= live_input_generation
+ deallocate(request)
+ endif
+ call unlock_decode_requests()
+ end function
+
+ subroutine initialize_decode_parameters()
+ call lock_decode_requests()
+ active = draft
+ call unlock_decode_requests()
+ end subroutine
+
+ subroutine advance_live_input_generation() bind(C)
+ call lock_decode_requests()
+ live_input_generation = live_input_generation + 1
+ call unlock_decode_requests()
+ end subroutine
+
+ subroutine clear_pending_requests()
+ type(decode_request), pointer :: request
+ do while (associated(pending_head))
+ request => pending_head
+ pending_head => request%next
+ deallocate(request)
+ enddo
+ nullify(pending_tail)
+ end subroutine
+
+ subroutine cancel_pending_decode_requests() bind(C)
+ call lock_decode_requests()
+ call clear_pending_requests()
+ decoder_ready = 0
+ published_request_id = published_request_id + 1
+ call unlock_decode_requests()
+ end subroutine
+
+ function get_stop_m65() result(stopped)
+ integer(c_int) :: stopped
+ call lock_decode_requests()
+ stopped = stop_m65
+ call unlock_decode_requests()
+ end function
+
+ logical(c_bool) function is_current_decode_request(request_id) bind(C)
+ integer(c_int64_t), value :: request_id
+ call lock_decode_requests()
+ is_current_decode_request = request_id == published_request_id
+ call unlock_decode_requests()
+ end function
+
end module npar_ptrs_mod
diff --git a/map65/libm65/packjt.f90 b/map65/libm65/packjt.f90
index e42a1662..c9928208 100644
--- a/map65/libm65/packjt.f90
+++ b/map65/libm65/packjt.f90
@@ -2,6 +2,28 @@ module packjt
implicit none
contains
+pure logical function is_valid_jt65_codeword(dat)
+ integer, intent(in) :: dat(12)
+
+ integer, parameter :: NBASE = 37*36*10*27*27*27
+ integer, parameter :: LAST_V2_CALL = 267796945
+ integer :: nc1, nc2, ng
+
+ nc1 = ishft(dat(1),22) + ishft(dat(2),16) + ishft(dat(3),10) + &
+ ishft(dat(4),4) + iand(ishft(dat(5),-2),15)
+ nc2 = ishft(iand(dat(5),3),26) + ishft(dat(6),20) + &
+ ishft(dat(7),14) + ishft(dat(8),8) + ishft(dat(9),2) + &
+ iand(ishft(dat(10),-4),3)
+ ng = ishft(iand(dat(10),15),12) + ishft(dat(11),6) + dat(12)
+
+ if (ng >= 32768) then
+ is_valid_jt65_codeword = .true.
+ else
+ is_valid_jt65_codeword = nc1 /= NBASE .and. nc1 <= LAST_V2_CALL .and. &
+ nc2 < NBASE
+ endif
+end function is_valid_jt65_codeword
+
subroutine packbits(dbits,nsymd,m0,sym)
! Pack 0s and 1s from dbits() into sym() with m0 bits per word.
@@ -147,12 +169,13 @@ subroutine unpackcall(ncall, word, iv2, psfx)
character(len=37) :: c
integer, parameter :: NBASE = 37*36*10*27*27*27
+ integer, parameter :: LAST_V2_CALL = 267796945
data c /'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ '/
word = '......'
psfx = ' '
- if ((ncall < 0 .or. ncall >= 262177560) .and. ncall .ne. 262177561) then
+ if (ncall < 0 .or. ncall == NBASE .or. ncall > LAST_V2_CALL) then
write(*,*) 'unpackcall: ncall out of range = ', ncall
end if
@@ -496,10 +519,10 @@ end subroutine unpackcall
if(c3.eq.'OOO ') c3=' ' !Strip out the OOO flag
call getpfx1(c1,k1,nv2a)
if(nv2a.ge.4) go to 10
- call packcall(c1,nc1,text1)
+ call packcall(c1(1:6),nc1,text1)
if(text1) go to 10
call getpfx1(c2,k2,nv2b)
- call packcall(c2,nc2,text2)
+ call packcall(c2(1:6),nc2,text2)
if(text2) go to 10
if(nv2a.eq.2 .or. nv2a.eq.3 .or. nv2b.eq.2 .or. nv2b.eq.3) then
if(k1.lt.0 .or. k2.lt.0 .or. k1*k2.ne.0) go to 10
@@ -529,7 +552,7 @@ end subroutine unpackcall
! The message will be treated as plain text.
10 itype=6
- call packtext(msg,nc1,nc2,ng)
+ call packtext(msg(1:13),nc1,nc2,ng)
ng=ng+32768
! Encode data into 6-bit words
@@ -876,7 +899,7 @@ subroutine packpfx(call1, n1, ng, nadd)
if(call1(i1+2:i1+2).eq.' ') then
! Single-character add-on suffix (maybe also fourth suffix letter?)
call0=call1(:i1-1)
- call packcall(call0,n1,text)
+ call packcall(call0(1:6),n1,text)
nadd=1
nc=ichar(call1(i1+1:i1+1))
if(nc.ge.48 .and. nc.le.57) then
@@ -891,7 +914,7 @@ subroutine packpfx(call1, n1, ng, nadd)
else if(call1(i1+3:i1+3).eq.' ') then
! Two-character numerical suffix, /10 to /99
call0=call1(:i1-1)
- call packcall(call0,n1,text)
+ call packcall(call0(1:6),n1,text)
nadd=1
n=10*(ichar(call1(i1+1:i1+1))-48) + ichar(call1(i1+2:i1+2)) - 48
nadd=1
@@ -902,7 +925,7 @@ subroutine packpfx(call1, n1, ng, nadd)
if(pfx(3:3).eq.' ') pfx=' '//pfx(1:2)
if(pfx(3:3).eq.' ') pfx=' '//pfx(1:2)
call0=call1(i1+1:)
- call packcall(call0,n1,text)
+ call packcall(call0(1:6),n1,text)
ng=0
do i=1,3
diff --git a/map65/libm65/ptt.c b/map65/libm65/ptt.c
index 3170ab78..b2c6cb48 100644
--- a/map65/libm65/ptt.c
+++ b/map65/libm65/ptt.c
@@ -15,12 +15,12 @@ int ptt_(int *nport, int *ntx, int *iptt)
if(*ntx && (!open)) {
if (*nport < 10)
- snprintf(s, sizeof(s), "COM%d", *nport);
+ snprintf(s, sizeof(s), "COM%d", *nport);
else
snprintf(s, sizeof(s), "\\\\.\\COM%d", *nport);
hFile = CreateFileA(s, GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL, NULL);
+ FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile==INVALID_HANDLE_VALUE) {
// printf("PTT: Cannot open COM port %d.\n",*nport);
diff --git a/map65/libm65/ptt_unix.c b/map65/libm65/ptt_unix.c
index 5cefe9f5..0787308b 100644
--- a/map65/libm65/ptt_unix.c
+++ b/map65/libm65/ptt_unix.c
@@ -17,26 +17,11 @@
*/
# include <stdio.h>
# include <stdlib.h>
-# include <unistd.h>
+# include <unistd.h>
#include <fcntl.h>
# include <sys/ioctl.h>
#include <errno.h>
#include <string.h>
-#include <stdarg.h>
-
-static void ptt_log(const char *fmt, ...)
-{
- FILE *f = fopen("/tmp/map65_ptt.log", "a");
- if (!f) return;
-
- va_list ap;
- va_start(ap, fmt);
- vfprintf(f, fmt, ap);
- fprintf(f, "\n");
- va_end(ap);
- fflush(f);
- fclose(f);
-}
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
diff --git a/map65/libm65/q65b.F90 b/map65/libm65/q65b.F90
index 6dba967f..7f28f0f3 100644
--- a/map65/libm65/q65b.F90
+++ b/map65/libm65/q65b.F90
@@ -9,9 +9,31 @@
implicit none
contains
- subroutine q65b(nutc, nqd, nxant, fcenter, nfcal, nfsample, ikhz, mousedf, ntol, xpol, &
+ subroutine write_wav_header(unit, nsamp, fs)
+ integer, intent(in) :: unit, nsamp, fs
+ integer :: datasize, file_size
+
+ datasize = nsamp * 2 ! 16-bit samples
+ file_size = 36 + datasize
+
+ write(unit) 'RIFF'
+ write(unit) file_size
+ write(unit) 'WAVE'
+ write(unit) 'fmt '
+ write(unit) 16 ! PCM header size
+ write(unit) 1 ! PCM format
+ write(unit) 1 ! mono
+ write(unit) fs ! sample rate
+ write(unit) fs*2 ! byte rate
+ write(unit) 2 ! block align
+ write(unit) 16 ! bits per sample
+ write(unit) 'data'
+ write(unit) datasize
+ end subroutine write_wav_header
+
+ subroutine q65b(nutc, nqd, nxant, fcenter, nfcal, nfsample, ikhz, mousedf, ntol, xpol, configured_dphi_deg, &
mycall0, mygrid, hiscall0, hisgrid, mode_q65, f0, fqso, newdat, nagain, &
- max_drift, ndop00, idec)
+ max_drift, ndop00, idec, cursor_fallback)
use iso_c_binding
use q65_decode
@@ -25,6 +47,9 @@
use txpol_mod
use iso_fortran_env, only: real64, int16
use map65_mmdec_mod
+ use npar_ptrs_mod, only: nrate_active, nfft_big_active, nfft_active, t_start, abort_decode, &
+ manualDecodeFlag, ndepth
+ use sec_midn_mod, only: sec_midn
implicit none
@@ -39,6 +64,7 @@
integer, intent(in) :: mousedf
integer, intent(in) :: ntol
logical, intent(in) :: xpol
+ integer, intent(in) :: configured_dphi_deg
character(len=12), intent(in) :: mycall0
character(len=6), intent(in) :: mygrid
character(len=12), intent(in) :: hiscall0
@@ -51,10 +77,14 @@
integer, intent(in) :: max_drift
integer, intent(in) :: ndop00
integer, intent(out) :: idec
+ logical, optional, intent(in) :: cursor_fallback
!==== Local parameters ====================================================
- integer, parameter :: MAXFFT1 = 5376000
- integer, parameter :: MAXFFT2 = 336000
+ ! MAXFFT1/2 are *max* sizes; actual runtime sizes are derived below.
+ ! MAXFFT1 must be = nfft_big_active; MAXFFT2 must be = the
+ ! downsampled-FFT length at the highest supported rate.
+ integer, parameter :: MAXFFT1 = 56*192000
+ integer, parameter :: MAXFFT2 = 336000*2
integer, parameter :: NMAX = 60*12000
real(real64), parameter :: RAD = 57.2957795
@@ -62,12 +92,19 @@
integer(int16) :: iwave(300*12000)
complex :: cx(0:MAXFFT2-1), cy(0:MAXFFT2-1), cz(0:MAXFFT2)
integer :: ipk1(1)
+ ! Small, fixed bin radius for the automatic-candidate ipk search (see
+ ! the note below at "for a wideband candidate"). Deliberately
+ ! independent of the GUI's Ftol (ntol) -- this only needs to absorb
+ ! wb_sync's own low-SNR bin-selection noise, not accommodate arbitrary
+ ! user-configured search widths.
+ integer, parameter :: IPK_LOCAL_BINS = 5
integer :: i, ia, ib, ifreq, ikhz1, ipk, ipol
- integer :: j, ja, jb, k0, mhz, ndf, ndpth, nfft1, nfft2
+ integer :: j, ja, jb, k0, mhz, ndf, nfft1, nfft2
integer :: npol, nq65df, nsubmode, ntxpol, nutc00, nh
integer :: nfa, nfb
- real :: df, df3, f_ipk, f_mouse, fac
- real :: freq1_00, frx, fsked, poldeg, r, snr1
+ integer :: k0_click, mousedf_gate
+ real :: df, df3, dphi, f_ipk, f_mouse, fac
+ real :: combine_poldeg, freq1_00, frx, fsked, poldeg, r, snr1
real(real64) :: freq0, freq1
character(len=12) :: mycall, hiscall
character(len=4) :: grid4
@@ -76,6 +113,9 @@
character(len=2) :: cmode
character(len=256) :: linenew
+ integer :: t_now, t_rate
+ logical :: search_cursor
+
! From q65_decode / wideband_sync / globals:
! real :: xdt0
! integer :: nsnr0, nfreq0, nkhz_center
@@ -88,49 +128,149 @@
data msg00 /' '/
save
- call init_cacb(5376000)
+ idec = -1
+ nsnr0 = -99
+ msg0 = ' '
+ cq0 = ' '
+ xdt0 = 0.0
+ nfreq0 = 0
+ search_cursor = manualDecodeFlag .ne. 0
+ if (present(cursor_fallback)) search_cursor = search_cursor .or. cursor_fallback
+
+ call system_clock(t_now, t_rate)
+ if (real(t_now - t_start)/real(t_rate) > 40.0) then
+ abort_decode = .true.
+ return
+ endif
+
+ ! ca/cb storage is sized at MAXFFT1 in cacb_mod; the *active* big FFT
+ ! length is nfft_big_active, set from C++ via set_runtime_params_().
+ call init_cacb(MAXFFT1)
- call init_wideband_sync(NFFT)
+ ! wideband_sync expects the active symspec FFT length
+ call init_wideband_sync()
+
if (mycall0(1:1) .ne. ' ') mycall = mycall0
if (hiscall0(1:1) .ne. ' ') hiscall = hiscall0
if (hisgrid(1:4) .ne. ' ') grid4 = hisgrid(1:4)
! Find best frequency and ipol from sync_dat, the "orange sync curve".
- df3 = 96000.0/32768.0
+ ! df3 is the bin width of the symspec FFT (savg), based on the
+ ! active runtime rate and FFT length.
+ df3 = real(nrate_active)/real(nfft_active)
ifreq = nint((1000.0*f0)/df3)
- ia = nint(ifreq - ntol/df3)
- ib = nint(ifreq + ntol/df3)
- if (ia >= 1 .and. ia <= 32768 .and. ib >= 1 .and. ib <= 32768) then !if added qt6
- ipk1 = maxloc(sync(ia:ib)%ccfmax)
+ ! Candidate frequencies need only local bin refinement. Cursor
+ ! targets, including the no-candidate fallback, need the selected Ftol.
+ ! Bin-quantized weak-signal candidates can miss the true sync peak;
+ ! retain the local five-bin search rather than testing one exact bin.
+ if (search_cursor) then
+ ia = nint(ifreq - ntol/df3)
+ ib = nint(ifreq + ntol/df3)
+ if (ia >= 1 .and. ia <= nfft_active .and. ib >= 1 .and. ib <= nfft_active) then
+ ipk1 = maxloc(sync(ia:ib)%ccfmax)
+ else
+ go to 901
+ endif
+ ipk = ia + ipk1(1) - 1
else
- go to 901
+ ia = max(1, ifreq - IPK_LOCAL_BINS)
+ ib = min(nfft_active, ifreq + IPK_LOCAL_BINS)
+ if (ifreq >= 1 .and. ifreq <= nfft_active .and. ib >= ia) then
+ ipk1 = maxloc(sync(ia:ib)%ccfmax)
+ ipk = ia + ipk1(1) - 1
+ else
+ go to 901
+ endif
endif
+ snr1 = sync(ipk)%ccfmax
- ipk = ia + ipk1(1) - 1
- if (ldecoded(ipk)) go to 900
+ ! TEMP diagnostic 2026-09-09 for the two-close-Q65-signals investigation.
+ call dbg('q65b: ipk check at t=' // rtoa(sec_midn()) // &
+ ' nqd=' // itoa(nqd) // ' f0=' // rtoa(real(f0)) // ' ntol=' // itoa(ntol) // &
+ ' ifreq=' // itoa(ifreq) // ' ipk=' // itoa(ipk) // &
+ ' ldecoded(ipk)=' // itoa(merge(1,0,ldecoded(ipk))) // &
+ ' manualDecodeFlag=' // itoa(manualDecodeFlag) // ' nagain=' // itoa(nagain))
+ ! ldecoded(ipk) exists to keep the wideband scan from repeatedly
+ ! re-decoding a bin it already got a result from. A manual click is a
+ ! deliberate, targeted request to decode at this exact bin, so it must
+ ! not be skipped just because an earlier wideband pass happened to
+ ! visit the same bin first.
+ if (ldecoded(ipk) .and. manualDecodeFlag .eq. 0) then
+ call dbg('q65b: SKIPPED (ldecoded already set) at t=' // rtoa(sec_midn()) // &
+ ' ipk=' // itoa(ipk))
+ go to 900
+ endif
snr1 = sync(ipk)%ccfmax
! ipol was never declared and its value is never used
ipol = 1
if (xpol) ipol = sync(ipk)%ipol
- nfft1 = MAXFFT1
- nfft2 = MAXFFT2
- df = 96000.0/NFFT1
+ ! Runtime big-FFT length: nfft_big_active is 56 * nrate_active,
+ ! set from C++ at startup. Clamp to MAXFFT1 for safety.
+ nfft1 = min(nfft_big_active, MAXFFT1)
+
+ ! Use a fixed small-FFT length that matches the legacy 96 kHz
+ ! geometry and stays within MAXFFT2 at all supported rates.
+ nfft2 = min(336000, MAXFFT2)
+
+ ! Preserve the legacy 95238 special case; if you still use it,
+ ! override the derived sizes with the historical ones.
if (nfsample .eq. 95238) then
- nfft1 = 5120000
- nfft2 = 322560
- df = 96000.0/nfft1
+ nfft1 = min(5120000, MAXFFT1)
+ nfft2 = min(322560, MAXFFT2)
endif
+
+ ! Bin width of the big FFT: use the active runtime rate instead
+ ! of a hardcoded 96000. The 95238 special case is preserved.
+ df = real(nrate_active)/real(nfft1)
+ if (nfsample .eq. 95238) df = 96000.0/real(nfft1)
+
nh = nfft2/2
- f_mouse = 1000.0*(fqso + 48.0) + mousedf
+ f_mouse = 1000.0*(fqso + real(nrate_active/2000.0)) + mousedf
f_ipk = ipk*df3
- k0 = nint((ipk*df3 - 1000.0)/df)
- if (nagain .eq. 1) k0 = nint((f_mouse - 1000.0)/df)
-
- if (k0 .lt. nh .or. k0 .gt. MAXFFT1 - nfft2 + 1) go to 900
- if (snr1 .lt. 1.5) go to 900 !### Threshold needs work? ###
+ ! k0 used to come from f_ipk (ipk*df3), i.e. re-derived from the coarse,
+ ! JT65-oriented "orange sync curve" bin (df3 ~ 2.9 Hz resolution) rather
+ ! than from the candidate's own already-refined frequency. For a
+ ! wideband Q65 candidate, f0 (set by the caller from cand()%f, which
+ ! wb_sync already computed with sub-bin precision) is a strictly better
+ ! estimate of the true signal frequency than re-quantizing through ipk
+ ! -- and the difference matters here because the actual decode below
+ ! only searches a tight +/-10 Hz window (nfa=990..1010) around k0.
+ ! Use f0 directly, same as the manual-click/nagain path already does
+ ! via f_mouse below.
+ k0 = nint((1000.0*f0 - 1000.0)/df)
+ ! ipk (and therefore f_ipk) comes from maxloc'ing the JT65-oriented
+ ! "orange sync curve" over the whole +/-ntol window -- fine for a
+ ! wideband scan, but if a strong JT65 signal happens to sit anywhere
+ ! in that window it will always win, even over an equal-strength Q65
+ ! signal, because that curve doesn't score Q65 signals the same way.
+ ! A manual click already tells us exactly where to look, so center
+ ! the analysis window on the actual clicked frequency (f_mouse, which
+ ! properly includes mousedf) instead of trusting that curve.
+ ! nagain=1 (Decode button / Find Delta Phi repeat) runs the same
+ ! per-candidate loop over real, precise wb_sync candidates that
+ ! automatic decoding does -- f0 is not an imprecise mousefqso click
+ ! there, so forcing k0 to f_mouse would make every candidate in that
+ ! loop decode the same narrow window near the cursor instead of its
+ ! own frequency. The one nagain=1 case where f0 genuinely comes from
+ ! mousefqso (the "no candidate found" fallback in map65a.f90) already
+ ! sets f0 = mousefqso + mousedf directly, so the default k0 below
+ ! lands on the same point anyway.
+ if (manualDecodeFlag .ne. 0) k0 = nint((f_mouse - 1000.0)/df)
+
+ if (k0 .lt. nh .or. k0 .gt. nfft1 - nfft2 + 1) then
+ if (manualDecodeFlag .ne. 0) &
+ call dbg('q65b manual: NOT ATTEMPTED, k0=' // itoa(k0) // ' outside ' // &
+ itoa(nh) // '..' // itoa(nfft1 - nfft2 + 1))
+ go to 900
+ endif
+ ! Likewise, snr1 is the sync-curve strength at ipk, which for a manual
+ ! click may be the wrong bin entirely (see above) -- don't let it gate
+ ! a manual decode attempt. Let q65_decode's own Q65-native search
+ ! (below) determine success or failure instead.
+ if (snr1 .lt. 1.5 .and. manualDecodeFlag .eq. 0) go to 900 !### Threshold needs work? ###
fac = 1.0/nfft2
cx(0:nfft2 - 1) = ca(k0:k0 + nfft2 - 1)
@@ -138,6 +278,11 @@
if (xpol) then
cy(0:nfft2 - 1) = cb(k0:k0 + nfft2 - 1)
cy = fac*cy
+ if (configured_dphi_deg .ne. 0) then
+ dphi = configured_dphi_deg/RAD
+ ! The sync weights describe the phase-corrected basis from symspec.
+ cy(0:nfft2 - 1) = cmplx(cos(dphi), sin(dphi))*cy(0:nfft2 - 1)
+ endif
endif
! Here cx and cy (if xpol) are frequency-domain data around the selected
@@ -153,8 +298,12 @@
poldeg = 0.
if (xpol) then
+ ! NB: still uses the (possibly wrong-bin, see k0 above) ipk for
+ ! manual clicks in xpol mode -- not exercised by current testing,
+ ! but worth revisiting if xpol manual decode misbehaves similarly.
poldeg = sync(ipk)%pol
- cz(0:MAXFFT2 - 1) = cos(poldeg/RAD)*cx + sin(poldeg/RAD)*cy
+ combine_poldeg = sync(ipk)%combine_pol
+ cz(0:MAXFFT2 - 1) = cos(combine_poldeg/RAD)*cx + sin(combine_poldeg/RAD)*cy
else
cz(0:MAXFFT2 - 1) = cx
endif
@@ -177,34 +326,49 @@
iwave(2*i + 2) = int(max(-32768, min(32767, nint(real(cz(j))))), kind=2)
iwave(2*i + 1) = int(max(-32768, min(32767, nint(aimag(cz(j))))), kind=2)
enddo
- iwave(2*nfft2 + 1:) = 0
-! open(30,file='000000_0001.wav',status='unknown',access='stream')
-! h=default_header(12000,NMAX)
-! write(30) h,iwave
-! close(30)
+ iwave(2*nfft2 + 1:) = 0
nsubmode = mode_q65 - 1
nfa = 990 !Tight limits around ipk for the wideband decode
nfb = 1010
- if (nagain .eq. 1) then !For nagain=1, use limits of +/- ntol
+ if (search_cursor) then
nfa = max(100, 1000 - ntol)
nfb = min(2500, 1000 + ntol)
endif
- nsnr0 = -99 !Default snr for no decode
- ndpth = 3
! NB: Frequency of ipk is now shifted to 1000 Hz.
+
+ ! ndepth comes from npar_ptrs_mod, set from the GUI's Decode Depth
+ ! menu (see MainWindow::decode() -> setNdepth()). This used to be a
+ ! local variable "ndpth" hardwired to 3 here, which was never
+ ! connected to the GUI at all -- Q65 always ran at depth 3
+ ! regardless of what the user selected.
call map65_mmdec(nutc, iwave, nqd, 60, nsubmode, nfa, nfb, 1000, ntol, &
- newdat, nagain, max_drift, ndpth, mycall, hiscall0, hisgrid)
+ newdat, nagain, max_drift, ndepth, mycall, hiscall0, hisgrid)
MHz = fcenter
freq0 = MHz + 0.001d0*ikhz
+ call dbg('q65b: map65_mmdec result at t=' // rtoa(sec_midn()) // &
+ ' nqd=' // itoa(nqd) // ' f0=' // rtoa(real(f0)) // ' ipk=' // itoa(ipk) // &
+ ' nsnr0=' // itoa(nsnr0))
+
if (nsnr0 .gt. -99) then
ldecoded(ipk) = .true.
- nq65df = nint(1000*(0.001*k0*df + nkhz_center - 48.0 + 1.000 - 1.27046 - ikhz)) - nfcal
+ nq65df = nint(1000*( 0.001*k0*df + nkhz_center - real(nrate_active)/2000.0 + 1.000 - 1.27046 - ikhz )) - nfcal
nq65df = nq65df + nfreq0 - 1000
+ ! Gate comparison target, expressed in the same ikhz-relative frame
+ ! as nq65df above -- computed from f0 (the unambiguous target
+ ! frequency for this call, for both a manual click and a wideband
+ ! candidate) via the same k0/nq65df formula, rather than from raw
+ ! mousedf, which is relative to mousefqso and only matches ikhz's
+ ! frame when the target happens to already be sub-kHz. mousedf
+ ! itself is left untouched -- f_mouse/k0 above still need it in its
+ ! original, unmodified form.
+ k0_click = nint((1000.0*f0 - 1000.0)/df)
+ mousedf_gate = nint(1000*( 0.001*k0_click*df + nkhz_center - real(nrate_active)/2000.0 + &
+ 1.000 - 1.27046 - ikhz )) - nfcal
npol = nint(poldeg)
if (nxant .ne. 0) then
npol = npol - 45
@@ -216,11 +380,18 @@
if (ndf .gt. 500) ikhz1 = ikhz + (nq65df + 500)/1000
if (ndf .lt. -500) ikhz1 = ikhz + (nq65df - 500)/1000
ndf = nq65df - 1000*(ikhz1 - ikhz)
- if (nqd .eq. 1 .and. abs(nq65df - mousedf) .lt. ntol) then
+
+ if (manualDecodeFlag .ne. 0) &
+ call dbg('q65b manual: decoded nq65df=' // itoa(nq65df) // ' mousedf_gate=' // &
+ itoa(mousedf_gate) // ' ntol=' // itoa(ntol) // ' nqd=' // itoa(nqd) // &
+ ' display gate ' // merge('PASSED', 'FAILED', &
+ nqd .eq. 1 .and. abs(nq65df - mousedf_gate) .lt. ntol))
+
+ if (nqd .eq. 1 .and. abs(nq65df - mousedf_gate) .lt. ntol) then
+
write (linenew, '("!",I3.3,I5,I4,I6.4,F5.1,I5," : ",A28,A3,I4,1X,A1)') &
ikhz1, ndf, npol, nutc, xdt0, nsnr0, msg0(1:28), cq0, ntxpol, cp
call write_stdout(trim(linenew)//new_line('a'))
-
endif
! Write to lu 26, for Messages and Band Map windows
@@ -242,7 +413,7 @@
nutc00 = nutc
msg00 = msg0(1:28)
freq1_00 = freq1
- frx = 0.001*k0*df + nkhz_center - 48.0 + 1.0 - 0.001*nfcal
+ frx = 0.001*k0*df + nkhz_center - real(nrate_active/2000.0) + 1.0 - 0.001*nfcal
fsked = frx - 0.001*ndop00/2.0 - 1.5
write (12, 1120) nutc, fsked, xdt0, nsnr0, trim(msg0)
1120 format(i4.4, f9.3, f7.2, i5, 2x, a, i6)
@@ -252,7 +423,10 @@
900 close (13)
close (17)
idec = -1
- read (cq0(2:2), *) idec
+ ! cq0 is blank unless this call's own decode attempt set it (see the
+ ! reset at subroutine entry); only parse it when there's really a
+ ! digit there, otherwise there's nothing for READ to find.
+ if (cq0(2:2) .ne. ' ') read (cq0(2:2), *) idec
return
901 close (13)
close (17)
diff --git a/map65/libm65/recvpkt.f90 b/map65/libm65/recvpkt.f90
index 03ca5b1f..32900835 100644
--- a/map65/libm65/recvpkt.f90
+++ b/map65/libm65/recvpkt.f90
@@ -1,6 +1,6 @@
module recvpkt_mod
use datcom_ptrs_mod ! for dd
- use iso_fortran_env, only: real64, real32, int16
+ use iso_fortran_env, only: real64, real32, int16
implicit none
contains
@@ -8,7 +8,7 @@ subroutine recvpkt(nsam, nblock2, userx_no, k, buf4, buf8, buf16) &
bind(C, name="recvpkt_")
use iso_c_binding
- use datcom_ptrs_mod
+
integer(c_int), intent(in) :: nsam
integer(c_int16_t), intent(inout) :: nblock2
integer(c_int8_t), intent(in) :: userx_no
@@ -20,7 +20,6 @@ subroutine recvpkt(nsam, nblock2, userx_no, k, buf4, buf8, buf16) &
! ===== Locals =====
integer :: i
- integer, parameter :: NSMAX = 60*96000
! Silence unused warning
if (nblock2 .eq. -9999) nblock2 = -9998
@@ -34,41 +33,40 @@ subroutine recvpkt(nsam, nblock2, userx_no, k, buf4, buf8, buf16) &
do i = 1, 174
k = k + 1
call unpack_r8_to_r4(buf8(i), dd(1,k), dd(2,k))
- end do
-
- case (1)
- do i = 1, 348
- k = k + 1
- call unpack_r4_to_i2_as_r4(buf4(i), dd(1,k), dd(2,k))
- end do
-
- case (-2)
- do i = 1, 87
- k = k + 1
- call unpack_c16_to_r4(buf16(i), dd(1,k), dd(2,k), dd(3,k), dd(4,k))
- end do
-
- case (2)
- do i = 1, 174
- k = k + 1
- call unpack_r8_to_i2_as_r4(buf8(i), dd(1,k), dd(2,k), dd(3,k), dd(4,k))
- end do
-
- end select
-
- else
- ! nsam >= 0: special case for one RF channel, r*4 data
- if (userx_no .eq. 1) then
- do i = 1, nsam
- k = k + 1
- call unpack_r4_to_i2_as_r4(buf4(i), dd(1,k), dd(2,k))
-
- k = k + 1
- dd(1,k) = dd(1,k-1)
- dd(2,k) = dd(2,k-1)
- end do
- end if
- end if
+ end do
+
+ case (1)
+ do i = 1, 348
+ k = k + 1
+ call unpack_r4_to_i2_as_r4(buf4(i), dd(1,k), dd(2,k))
+ end do
+
+ case (-2)
+ do i = 1, 87
+ k = k + 1
+ call unpack_c16_to_r4(buf16(i), dd(1,k), dd(2,k), dd(3,k), dd(4,k))
+ end do
+
+ case (2)
+ do i = 1, 174
+ k = k + 1
+ call unpack_r8_to_i2_as_r4(buf8(i), dd(1,k), dd(2,k), dd(3,k), dd(4,k))
+ end do
+ end select
+
+ else
+ ! nsam >= 0: special case for one RF channel, r*4 data
+ if (userx_no .eq. 1) then
+ do i = 1, nsam
+ k = k + 1
+ call unpack_r4_to_i2_as_r4(buf4(i), dd(1,k), dd(2,k))
+
+ k = k + 1
+ dd(1,k) = dd(1,k-1)
+ dd(2,k) = dd(2,k-1)
+ end do
+ end if
+ end if
end subroutine recvpkt
diff --git a/map65/libm65/run_m65.f90 b/map65/libm65/run_m65.f90
index e927e33e..cc0ffe73 100644
--- a/map65/libm65/run_m65.f90
+++ b/map65/libm65/run_m65.f90
@@ -9,11 +9,14 @@ subroutine run_m65(pol, sample_rate_96000) bind(C, name='run_m65_')
use timer_impl, only: init_timer, fini_timer
use debug_log
use m65a_mod
- use datcom_ptrs_mod, only: dd, ss, savg
- use npar_ptrs_mod, only: newdat, stop_m65, decoder_ready
+ use npar_ptrs_mod, only: t_start, nhsym, mycall, hiscall, hisgrid, neme, &
+ initialize_decode_parameters, claim_decode_request, get_stop_m65, &
+ active_request_id, active_request_expired
use stdout_channel_mod, only: write_stdout
use decodes_mod, only: nhsym1,nhsym2
+ use deep65_mod, only: build_call3_candidates
use sleep_msec_mod
+ use sec_midn_mod, only: sec_midn
implicit none
@@ -22,17 +25,13 @@ subroutine run_m65(pol, sample_rate_96000) bind(C, name='run_m65_')
! Local variables
integer :: sample_rate
character(len=128) :: line
-
- ! timestamp variables
- character(len=8) :: d
- character(len=10) :: t
- integer :: v(8)
- character(len=32) :: timestamp
+ integer :: t_rate
+ integer :: t_now
nhsym1=280
- nhsym2=302
-
- ! call ensure_log_open() !uncomment this to enable logging to file
+ nhsym2=302
+
+ dbg_enabled = .false. ! flip to .true. to enable dbg() logging to w3sz_debug.log
if (sample_rate_96000 /=0) then
sample_rate = 96000
@@ -71,39 +70,30 @@ subroutine run_m65(pol, sample_rate_96000) bind(C, name='run_m65_')
!print *, 'IN RUN_M65, initial stop_m65 =', stop_m65
!flush(6)
- !call date_and_time(d, t, values=v)
-
- !write(timestamp, '(I4.4,"-",I2.2,"-",I2.2," ",I2.2,":",I2.2,":",I2.2,".",I3.3)') &
- ! v(1), v(2), v(3), v(5), v(6), v(7), v(8)
-
- !print *, trim(timestamp), ' CALLING M65A'
-
-
call init_timer()
-
- !print *, 'IN RUN_M65, just passed init_timer'
- do while (stop_m65 == 0)
- if (decoder_ready /=0 .and. newdat /= 0) then
- ! call date_and_time(d, t, values=v)
-
- ! write(timestamp, '(I4.4,"-",I2.2,"-",I2.2," ",I2.2,":",I2.2,":",I2.2,".",I3.3)') &
- ! v(1), v(2), v(3), v(5), v(6), v(7), v(8)
-
- ! print *, trim(timestamp), ' CALLING M65A'
- call m65a()
- end if
-!print *, ' ENTERING SLEEP_MSEC'
-call sleep_msec(50)
-!print *, ' RETURNED FROM SLEEP_MSEC'
-!print *, ' LOOP: stop_m65 =', stop_m65, &
-! ' decoder_ready=', decoder_ready, &
-! ' newdat=', newdat
-
-! stop_m65 = .true.
+ call initialize_decode_parameters()
+
+ ! Encode the CALL3.TXT candidates before the first decode's time budget starts.
+ ! deep65 rebuilds them when calls, grids, the EME filter, or CALL3.TXT change.
+ call dbg('run_m65: eager build_call3_candidates() STARTING at t=' // rtoa(sec_midn()))
+ call build_call3_candidates(mycall, hiscall, hisgrid, neme)
+ call dbg('run_m65: eager build_call3_candidates() DONE at t=' // rtoa(sec_midn()))
+
+ do while (get_stop_m65() == 0)
+ if (claim_decode_request()) then
+ if (active_request_expired) then
+ write(line, '(A,1X,I0)') '<DecodeSkipped>', active_request_id
+ call write_stdout(trim(line)//new_line('a'))
+ else
+ call system_clock(t_start, t_rate)
+ call m65a()
+ call system_clock(t_now)
+ call dbg('run_m65: request completed, elapsed=' // rtoa(real(t_now - t_start)/real(t_rate)))
+ endif
+ endif
+ call sleep_msec(50)
end do
-! print *, 'RUN_M65 exiting main loop.'
-! flush (6)
call fini_timer()
close(21)
diff --git a/map65/libm65/s3avg.f90 b/map65/libm65/s3avg.f90
index 780d8a4c..5a21c31f 100644
--- a/map65/libm65/s3avg.f90
+++ b/map65/libm65/s3avg.f90
@@ -2,7 +2,7 @@ module s3avg_mod
implicit none
contains
-subroutine s3avg(nsave, mode65, nutc, nhz, xdt, npol, ntol, s3, nsum, nkv, decoded)
+subroutine s3avg(nsave, mode65, nutc, nhz, xdt, npol, nflip, ntol, s3, nsum, nkv, decoded)
use extract_mod
implicit none
@@ -10,35 +10,39 @@ subroutine s3avg(nsave, mode65, nutc, nhz, xdt, npol, ntol, s3, nsum, nkv, decod
! decoding of average.
integer, intent(inout) :: nsave
- integer, intent(in) :: mode65, nutc, nhz, npol, ntol
+ integer, intent(in) :: mode65, nutc, nhz, npol, nflip, ntol
real, intent(in) :: xdt
real, intent(in) :: s3(64,63) !Synchronized spectra for 63 symbols
- integer, intent(inout) :: nsum, nkv
- character(len=22), intent(inout) :: decoded
+ integer, intent(out) :: nsum, nkv
+ character(len=22), intent(out) :: decoded
real s3a(64,63,64) !Saved spectra
real s3b(64,63) !Average spectra
- integer iutc(64),ihz(64),ipol(64)
+ integer iutc(64),ihz(64),ipol(64),iflip(64)
integer :: i,ihzdiff,nadd,ncount,nhist
integer :: mrs(63), mrs2(63) !Dummy arguments for extract
- real :: dtdiff
+ real, parameter :: dtdiff=0.2
real dt(64)
logical ltext,first
data first/.true./
- save
+ save first,iutc,ihz,ipol,iflip,s3a,dt
+
+ nsum=0
+ nkv=0
+ decoded=' '
+ ihzdiff=min(100,ntol)
if(first) then
iutc=-1
ihz=0
ipol=0
+ iflip=0
first=.false.
- ihzdiff=min(100,ntol)
- dtdiff=0.2
endif
do i=1,64
- if(nutc.eq.iutc(i) .and. abs(nhz-ihz(i)).lt.ihzdiff) then
- nsave=mod(nsave-1+64,64)+1
+ if(nutc.eq.iutc(i) .and. abs(nhz-ihz(i)).le.ihzdiff) then
+ nsave=mod(nsave-2+64,64)+1
go to 10
endif
enddo
@@ -46,6 +50,7 @@ subroutine s3avg(nsave, mode65, nutc, nhz, xdt, npol, ntol, s3, nsum, nkv, decod
iutc(nsave)=nutc !Save UTC
ihz(nsave)=nhz !Save freq in Hz
ipol(nsave)=npol !Save pol
+ iflip(nsave)=nflip
dt(nsave)=xdt !Save DT
s3a(1:64,1:63,nsave)=s3 !Save the spectra
@@ -55,11 +60,13 @@ subroutine s3avg(nsave, mode65, nutc, nhz, xdt, npol, ntol, s3, nsum, nkv, decod
if(mod(iutc(i),2).ne.mod(nutc,2)) cycle !Use only same sequence
if(abs(nhz-ihz(i)).gt.ihzdiff) cycle !Freq must match
if(abs(xdt-dt(i)).gt.dtdiff) cycle !DT must match
+ ! Opposite sync polarities map s3 columns to complementary symbol positions.
+ if(iflip(i).eq.0) cycle
+ if(nflip.ne.iflip(i)) cycle
s3b=s3b + s3a(1:64,1:63,i)
nsum=nsum+1
enddo
- decoded=' '
if(nsum.ge.2) then !Try decoding the sverage
nadd=mode65*nsum
call extract(s3b,nadd,ncount,nhist,decoded,ltext,mrs,mrs2) !Extract the message
diff --git a/map65/libm65/stdout_channel_mod.f90 b/map65/libm65/stdout_channel_mod.f90
index a5f3b01f..2dffdb95 100644
--- a/map65/libm65/stdout_channel_mod.f90
+++ b/map65/libm65/stdout_channel_mod.f90
@@ -8,7 +8,7 @@ module stdout_channel_mod
type, bind(C) :: StdoutSharedHeader
integer(c_int32_t) :: version
integer(c_int32_t) :: writeIndex
- integer(c_int32_t) :: dataSize
+ integer(c_int32_t) :: readIndex
integer(c_int32_t) :: seq
end type StdoutSharedHeader
@@ -75,6 +75,7 @@ end subroutine set_stdout_channel
!=========================================================
subroutine write_stdout(msg)
use iso_c_binding
+ use sleep_msec_mod, only: sleep_msec
implicit none
!==== Dummy argument =====================================================
@@ -82,7 +83,9 @@ subroutine write_stdout(msg)
!==== Local variables ====================================================
integer(c_int32_t) :: n, i, rc
- integer(c_int32_t) :: w, idx
+ integer(c_int32_t) :: w, idx, r, occupied, free_bytes
+ integer :: nwait
+ integer, parameter :: MAX_WAIT_ITERS = 2000 ! ~2 s at 1 ms/iter
character(kind=c_char) :: ch
if (.not. initialized) return
@@ -100,6 +103,21 @@ subroutine write_stdout(msg)
w = hdr%writeIndex
if (w < 0 .or. w >= g_buf_size) w = 0
+ ! Wait for the reader to make room rather than overwriting unread
+ ! data. One byte of the buffer is always kept empty so a full ring
+ ! can be told apart from an empty one. If the reader stalls for a
+ ! couple of seconds we give up waiting and write anyway, so a dead
+ ! or stuck reader can never hang the decoder.
+ do nwait = 1, MAX_WAIT_ITERS
+ r = hdr%readIndex
+ if (r < 0 .or. r >= g_buf_size) r = 0
+ occupied = w - r
+ if (occupied < 0) occupied = occupied + g_buf_size
+ free_bytes = g_buf_size - 1 - occupied
+ if (free_bytes >= n) exit
+ call sleep_msec(1)
+ end do
+
! Write bytes with wraparound, using 0-based idx and 1-based buf
do i = 0, n - 1
idx = w + i
diff --git a/map65/libm65/stdout_shared_layout.h b/map65/libm65/stdout_shared_layout.h
index c45d8852..4564678e 100644
--- a/map65/libm65/stdout_shared_layout.h
+++ b/map65/libm65/stdout_shared_layout.h
@@ -7,7 +7,10 @@ struct StdoutSharedHeader
{
std::uint32_t version; // For compatibility
std::uint32_t writeIndex; // Next write position in buffer
- std::uint32_t dataSize; // Bytes of new data just written
+ std::uint32_t readIndex; // Last position consumed by the reader thread;
+ // the writer uses this to compute free space
+ // and apply backpressure instead of
+ // overwriting unread data.
std::uint32_t seq; // Incremented each write (helps detect missed events)
};
diff --git a/map65/libm65/stdout_shared_memory.cpp b/map65/libm65/stdout_shared_memory.cpp
index 0fbcab3a..946ea187 100644
--- a/map65/libm65/stdout_shared_memory.cpp
+++ b/map65/libm65/stdout_shared_memory.cpp
@@ -163,7 +163,7 @@ StdoutSharedMemory::StdoutSharedMemory(const std::wstring &mappingName,
auto* region = getRegion();
region->header.version = 1;
region->header.writeIndex = 0;
- region->header.dataSize = 0;
+ region->header.readIndex = 0;
region->header.seq = 0;
}
diff --git a/map65/libm65/symspec.f90 b/map65/libm65/symspec.f90
index d1c27fc2..abab5ef0 100644
--- a/map65/libm65/symspec.f90
+++ b/map65/libm65/symspec.f90
@@ -2,13 +2,13 @@ module symspec_mod
implicit none
contains
-subroutine symspec(k,nxpol,ndiskdat,nb,nbslider,idphi,nfsample, &
+subroutine symspec(k,nxpol,ndiskdat,nb,nbslider,idphi, &
iqadjust,iqapply,gainx,gainy,phasex,phasey,rejectx,rejecty, &
pxdb,pydb,ssz5a,nkhz,ihsym,nzap,slimit,lstrong) bind(C, name='symspec_')
use iso_c_binding
use datcom_ptrs_mod
- use npar_ptrs_mod, only: fcenter
+ use npar_ptrs_mod, only: get_fcenter, nrate_active, nfft_active, nsmax_active
use four2a_mod
use timf2_mod
use iqcal_mod
@@ -17,7 +17,7 @@ subroutine symspec(k,nxpol,ndiskdat,nb,nbslider,idphi,nfsample, &
! C-facing arguments (keep these as in your modern version)
integer(c_int), intent(in) :: k, nxpol, ndiskdat, nb, nbslider
- integer(c_int), intent(in) :: idphi, nfsample
+ integer(c_int), intent(in) :: idphi
integer(c_int), intent(in) :: iqadjust, iqapply
real(c_float), intent(inout) :: gainx, gainy, phasex, phasey
real(c_float), intent(out) :: rejectx, rejecty, pxdb, pydb
@@ -27,6 +27,8 @@ subroutine symspec(k,nxpol,ndiskdat,nb,nbslider,idphi,nfsample, &
real(c_float), intent(inout) :: slimit
integer(c_signed_char), intent(out) :: lstrong(0:1023)
+ integer, parameter :: live_lookahead_samples=512
+
! ---- from legacy body, adapted to modules ----
! (no COMMON, no local fcenter, no logical*1 lstrong)
@@ -37,8 +39,12 @@ subroutine symspec(k,nxpol,ndiskdat,nb,nbslider,idphi,nfsample, &
mm, nadjx, nadjy, nblk, nblks, nfft2, npts, nsum, nwindow, n, nfast
real(real32) :: fac, faclim, peaklimit, px, py, q, rejectx0, rms, rmsx, rmsy, &
s135, s45, sigmas, sx, sy, u, x1, x2, x3, x4, dphi, pi
- real(real32) :: w(NFFT), w2a(NFFT), w2b(NFFT)
- complex :: z, zfac, zsumx, zsumy, cx(NFFT), cy(NFFT), cx00(NFFT), cy00(NFFT)
+
+ real(real32), allocatable :: w(:), w2a(:), w2b(:)
+ complex, allocatable :: cx(:), cy(:), cx00(:), cy00(:)
+
+ complex :: z, zfac, zsumx, zsumy
+ real(c_double) :: fcenter
complex :: cx0(0:1023), cx1(0:1023), cy0(0:1023), cy1(0:1023)
data rms/999.0/, k0/99999999/, k1/0/, nadjx/0/, nadjy/0/
@@ -46,18 +52,32 @@ subroutine symspec(k,nxpol,ndiskdat,nb,nbslider,idphi,nfsample, &
nfast = 1
-if (k.gt.5751000) goto 999
-if (k.lt.NFFT) then
+! Stop when we�re near the end of the allocated minute buffer.
+! nsmax_active = 60 * nrate_active, set from C++ at startup.
+if (k.gt.nsmax_active-9000) goto 999
+
+if (k.lt.nfft_active) then
ihsym = 0
goto 999
endif
if(k0.eq.99999999) then
+ ! First-time initialization: allocate buffers at runtime NFFT and
+ ! build the window(s). nfft_active is set from C++ via
+ ! set_runtime_params_() before any call into this routine.
+ if(.not.allocated(w)) allocate(w(nfft_active))
+ if(.not.allocated(w2a)) allocate(w2a(nfft_active))
+ if(.not.allocated(w2b)) allocate(w2b(nfft_active))
+ if(.not.allocated(cx)) allocate(cx(nfft_active))
+ if(.not.allocated(cy)) allocate(cy(nfft_active))
+ if(.not.allocated(cx00)) allocate(cx00(nfft_active))
+ if(.not.allocated(cy00)) allocate(cy00(nfft_active))
+
pi=4.0*atan(1.0)
w2a=0.
w2b=0.
- do i=1,NFFT
- w(i)=(sin(i*pi/NFFT))**2 !Window for nfast=1
+ do i=1,nfft_active
+ w(i)=(sin(i*pi/nfft_active))**2 !Window for nfast=1
if(i.lt.17833) w2a(i)=(sin(i*pi/17832.925))**2 !Window a for nfast=2
j=i-8916
if(j.gt.0 .and. j.lt.17833) w2b(i)=(sin(j*pi/17832.925))**2 ! b
@@ -66,8 +86,11 @@ endif
w2b=sqrt(2.0)*w2b
endif
- hsym=2048.d0*96000.d0/11025.d0
- if(nfsample.eq.95238) hsym=2048.d0*95238.1d0/11025.d0
+
+! Symbol length in samples, based on the active runtime rate.
+hsym = 2048.d0 * dble(nrate_active) / 11025.d0
+
+if(nrate_active.eq.95238) hsym=2048.d0*95238.1d0/11025.d0
if (k.lt.k0) then
! Perform the legacy reset
@@ -75,7 +98,8 @@ if (k.lt.k0) then
savg = 0.
ihsym = 0
k1 = 0
- if (ndiskdat.eq.0) dd(1:4,k+1:5760000)=0.
+ ! if (ndiskdat.eq.0) dd(1:4,k+1:5760000)=0.
+ if (ndiskdat.eq.0) dd(1:4,k+live_lookahead_samples+1:nsmax_active)=0.
endif
k0 = k
@@ -119,7 +143,7 @@ k0 = k
k1=k1+kstep
enddo
- npts=NFFT !Samples used in each half-symbol FFT
+ npts=nfft_active !Samples used in each half-symbol FFT
ts=ts+hsym
ja=ts ! ts already set from ihsym above; do not integrate it again !Index of first sample
@@ -178,22 +202,22 @@ k0 = k
endif
endif
- call four2a(cx,NFFT,1,1,1) !Second forward FFT (X)
+ call four2a(cx,nfft_active,1,1,1) !Second forward FFT (X)
if(iqadjust.eq.0) nadjx=0
- if(iqadjust.ne.0 .and. nadjx.lt.50) call iqcal(nadjx,cx,NFFT, &
+ if(iqadjust.ne.0 .and. nadjx.lt.50) call iqcal(nadjx,cx,nfft_active, &
gainx,phasex,zsumx,ipkx,rejectx0)
- if(iqapply.ne.0) call iqfix(cx,NFFT,gainx,phasex)
+ if(iqapply.ne.0) call iqfix(cx,nfft_active,gainx,phasex)
if(nxpol.ne.0) then
- call four2a(cy,NFFT,1,1,1) !Second forward FFT (Y)
+ call four2a(cy,nfft_active,1,1,1) !Second forward FFT (Y)
if(iqadjust.eq.0) nadjy=0
- if(iqadjust.ne.0 .and. nadjy.lt.50) call iqcal(nadjy,cy,NFFT, &
+ if(iqadjust.ne.0 .and. nadjy.lt.50) call iqcal(nadjy,cy,nfft_active, &
gainy,phasey,zsumy,ipky,rejecty)
- if(iqapply.ne.0) call iqfix(cy,NFFT,gainy,phasey)
+ if(iqapply.ne.0) call iqfix(cy,nfft_active,gainy,phasey)
endif
n=min(322,ihsym)
- do i=1,NFFT
+ do i=1,nfft_active
sx=real(cx(i))**2 + aimag(cx(i))**2
ss(1,n,i)=sx ! Pol = 0
savg(1,i)=savg(1,i) + sx
@@ -232,11 +256,12 @@ k0 = k
if(ihsym.eq.278) then
if(iqadjust.ne.0 .and. ipkx.ne.0 .and. ipky.ne.0) then
- rejectx=10.0*log10(savg(1,1+nfft-ipkx)/savg(1,1+ipkx))
- rejecty=10.0*log10(savg(3,1+nfft-ipky)/savg(3,1+ipky))
+ rejectx=10.0*log10(savg(1,1+nfft_active-ipkx)/savg(1,1+ipkx))
+ rejecty=10.0*log10(savg(3,1+nfft_active-ipky)/savg(3,1+ipky))
endif
endif
+ fcenter=get_fcenter()
nkhz=nint(1000.d0*(fcenter-int(fcenter)))
if(fcenter.eq.0.d0) nkhz=125
diff --git a/map65/libm65/test_astro_pipeline.f90 b/map65/libm65/test_astro_pipeline.f90
deleted file mode 100644
index 07a67ccc..00000000
--- a/map65/libm65/test_astro_pipeline.f90
+++ /dev/null
@@ -1,32 +0,0 @@
-program test_astro_pipeline
- use iso_fortran_env, only: real64
- use astrosub_mod
- implicit none
-
- integer :: nyear, month, nday, nfreq, ndop00
- real(real64) :: uth
- character(len=6) :: mygrid
-
- ! Simple test case
- nyear = 2025
- month = 1
- nday = 15
- uth = 12.0_real64 ! 12:00 UTC
- nfreq = 1440000000/1000000 ! e.g. 1440 MHz → 1440
- mygrid = 'FN20rx' ! or whatever grid you like
- ndop00 = 0
-
- call astrosub00(nyear,month,nday,uth,nfreq,mygrid,ndop00,len(mygrid))
-
- print *, 'Test astro pipeline:'
- print *, ' nyear =', nyear
- print *, ' month =', month
- print *, ' nday =', nday
- print *, ' uth =', uth
- print *, ' nfreq =', nfreq
- print *, ' mygrid =', mygrid
- print *, ' ndop00 =', ndop00
-
-end program test_astro_pipeline
-
-!does not require end module
diff --git a/map65/libm65/tmoonsub.c b/map65/libm65/tmoonsub.c
index 29ac28b4..f33dec0e 100644
--- a/map65/libm65/tmoonsub.c
+++ b/map65/libm65/tmoonsub.c
@@ -36,7 +36,7 @@ void tmoonsub_(double *day, double *glat, double *glong, double *moonalt,
double *mrv, double *l, double *b, double *paxis);
static const char
-*usage = " Usage: tmoon date[yyyymm] timz[+/-h.hh] long[+/-dddmm] lat[+/-ddmm]\n"
+usage[] = " Usage: tmoon date[yyyymm] timz[+/-h.hh] long[+/-dddmm] lat[+/-ddmm]\n"
"example: tmoon 200009 0 -00155 5230\n";
/*
@@ -360,6 +360,7 @@ void libration(double day, double lambda, double beta, double alpha, double *l,
*/
void illumination(double day, double lra, double ldec, double dr, double sra, double sdec, double *pabl, double *ill) {
double x, y, phi, i;
+ (void)day;
y = cos(sdec) * sin(sra - lra);
x = sin(sdec) * cos(ldec) - cos(sdec) * sin(ldec) * cos (sra - lra);
*pabl = atan22(y, x);
@@ -448,6 +449,7 @@ R is unchanged.
*/
void equatorial(double d, double *lon, double *lat, double *r) {
double eps, ceps, seps, l, b;
+ (void)r;
l = *lon;
b = * lat;
@@ -464,6 +466,8 @@ of above, but used to find topocentric ecliptic coords.
*/
void ecliptic(double d, double *lon, double *lat, double *r) {
double eps, ceps, seps, alp, dec;
+ (void)r;
+
alp = *lon;
dec = *lat;
eps = epsilon(d);
diff --git a/map65/libm65/trimlist.f90 b/map65/libm65/trimlist.f90
index 5017bc89..088a4221 100644
--- a/map65/libm65/trimlist.f90
+++ b/map65/libm65/trimlist.f90
@@ -1,39 +1,49 @@
module trimlist_mod
implicit none
contains
- subroutine trimlist(sig,km,ftol,indx,nsiz,nz)
+ subroutine select_unique_decodes(sig, msg, km, freq_tolerance, dt_tolerance, indx, nz)
use indexx_mod
implicit none
-
- integer, parameter :: MAXMSG=1000 !Size of decoded message list
- real, intent(in) :: sig(MAXMSG,30)
+
+ integer, parameter :: MAXMSG = 1000
+ real, intent(in) :: sig(MAXMSG, 30)
+ character(len=22), intent(in) :: msg(MAXMSG)
integer, intent(in) :: km
- real, intent(in) :: ftol
+ real, intent(in) :: freq_tolerance, dt_tolerance
integer, intent(out) :: indx(MAXMSG)
- integer, intent(out) :: nsiz(MAXMSG)
integer, intent(out) :: nz
-
- integer :: n, i0, i, j0, j
-
- ! 1 2 3 4 5 6 7 8
- ! nfile nutc freq snr dt ipol flip sync
-
- call indexx(sig(1,3),km,indx) !Sort list by frequency
-
- n=1
- i0=1
- do i=2,km
- j0=indx(i-1)
- j=indx(i)
- if(sig(j,3)-sig(j0,3).gt.ftol) then
- nsiz(n)=i-i0
- i0=i
- n=n+1
- endif
- enddo
- nz=n
- nsiz(nz)=km+1-i0
- nsiz(nz+1)=-1
-
- end subroutine trimlist
+
+ integer :: sorted(MAXMSG)
+ integer :: i, j, k
+ logical :: duplicate
+
+ nz = 0
+ if (km <= 0) return
+
+ call indexx(sig(:, 3), km, sorted)
+ do k = 1, km
+ i = sorted(k)
+ if (len_trim(msg(i)) == 0) cycle
+
+ duplicate = .false.
+ do j = 1, nz
+ if (nint(sig(i, 2)) /= nint(sig(indx(j), 2))) cycle
+ if (msg(i) /= msg(indx(j))) cycle
+ if (nint(sig(i, 7)) /= nint(sig(indx(j), 7))) cycle
+ if (abs(sig(i, 3) - sig(indx(j), 3)) > freq_tolerance) cycle
+ if (abs(sig(i, 5) - sig(indx(j), 5)) > dt_tolerance) cycle
+ duplicate = .true.
+ if (sig(i, 8) > sig(indx(j), 8) .or. &
+ (sig(i, 8) == sig(indx(j), 8) .and. sig(i, 4) > sig(indx(j), 4)) .or. &
+ (sig(i, 8) == sig(indx(j), 8) .and. sig(i, 4) == sig(indx(j), 4) .and. &
+ i > indx(j))) indx(j) = i
+ exit
+ end do
+
+ if (.not. duplicate) then
+ nz = nz + 1
+ indx(nz) = i
+ end if
+ end do
+ end subroutine select_unique_decodes
end module trimlist_mod
diff --git a/map65/libm65/wideband_sync.f90 b/map65/libm65/wideband_sync.f90
index a39b42f2..a8ae8a68 100644
--- a/map65/libm65/wideband_sync.f90
+++ b/map65/libm65/wideband_sync.f90
@@ -5,7 +5,7 @@ module wideband_sync
type candidate
real :: snr !Relative S/N of sync detection
real :: f !Freq of sync tone, 0 to 96000 Hz
- real :: xdt !DT of matching sync pattern, -1.0 to +4.0 s
+ real :: xdt !DT of matching sync pattern, -1.0 to +4.6 s
real :: pol !Polarization angle, degrees
integer :: ipol !Polarization angle, 1 to 4 ==> 0, 45, 90, 135 deg
integer :: iflip !Sync type: JT65 = +/- 1, Q65 = 0
@@ -15,30 +15,32 @@ module wideband_sync
real :: ccfmax
real :: xdt
real :: pol
+ real :: combine_pol
integer :: ipol
integer :: iflip
logical :: birdie
end type sync_dat
- integer, parameter :: NFFT = 32768
integer, parameter :: MAX_CANDIDATES = 50
real(real32), parameter :: SNR1_THRESHOLD = 4.5
type(sync_dat), allocatable :: sync(:) !NFFT
+ type(sync_dat), allocatable :: q65_generalized_sync(:)
integer nkhz_center
contains
subroutine get_candidates(ss, savg, xpol, jz, nfa, nfb, nts_jt65, nts_q65, cand, ncand)
use iso_c_binding
- use debug_log
+ use debug_log, only: dbg, itoa, rtoa
use indexx_mod, only: indexx
use iso_fortran_env, only: real64
+ use npar_ptrs_mod, only: nrate_active, nfft_active
implicit none
!==== Dummy arguments =====================================================
- real, intent(in) :: ss(4,322,NFFT)
- real, intent(in) :: savg(4,NFFT)
+ real, intent(in) :: ss(4,322,nfft_active)
+ real, intent(in) :: savg(4,nfft_active)
logical, intent(in) :: xpol
integer, intent(in) :: jz, nfa, nfb
integer, intent(in) :: nts_jt65, nts_q65
@@ -47,9 +49,11 @@ contains
! Search symbol spectra ss() over frequency range nfa to nfb (in kHz) for
-! JT65 and Q65 sync patterns. The nts_* variables are the submode tone
-! spacings: 1 2 4 8 16 for A B C D E. Birdies are detected and
-! excised. Candidates are returned in the structure array cand().
+! sync candidates. A valid generalized Q65 score replaces the legacy mixed-mode
+! surface, so that path returns Q65 candidates only; MAP65 discovers JT65
+! independently through ccf65(). Legacy paths may retain JT65 candidates.
+! The nts_* variables are the submode tone spacings: 1 2 4 8 16 for A B C D E.
+! Birdies are detected and excised. Candidates are returned in cand().
integer, parameter :: MAX_PEAKS = 100
real pavg(-20:20)
@@ -60,15 +64,16 @@ contains
integer, allocatable :: indx(:)
logical skip
- call wb_sync(ss, savg, xpol, jz, nfa, nfb) !Output to sync() array
+ call wb_sync(ss, savg, xpol, nts_q65.ne.0, jz, nfa, nfb) !Output to sync() array
tstep = 2048.0/11025.0 !0.185760 s: 0.5*tsym_jt65, 0.3096*tsym_q65
- df3 = 96000.0/NFFT
+ df3 = real(nrate_active)/real(nfft_active)
ia = nint(1000*nfa/df3) + 1
ib = nint(1000*nfb/df3) + 1
- if (ia .lt. 1) ia = 1
- if (ib .gt. NFFT - 1) ib = NFFT - 1
+ if (ia .lt. 21) ia = 21
+ if (ib .gt. nfft_active - 20) ib = nfft_active - 20
iz = ib - ia + 1
+
allocate (indx(iz))
! w3sz this if block should not be necessary but it is
@@ -83,7 +88,7 @@ contains
n_top = indx(iz) + ia - 1
snr_top = sync(n_top)%ccfmax
flip_top = sync(n_top)%iflip
-
+
k = 0
do i = 1, MAX_PEAKS
if ((iz + 1 - i) .lt. 1) cycle !w3sz debug
@@ -97,9 +102,10 @@ contains
if (sync(n)%birdie) cycle
! Test for signal outside of TxT range and set bw for this signal type
- j1 = int((sync(n)%xdt + 1.0)/tstep - 1.0)
- j2 = int((sync(n)%xdt + 52.0)/tstep + 1.0)
+ j1 = max(0,min(jz,int((sync(n)%xdt + 1.0)/tstep - 1.0)))
+ j2 = max(1,int((sync(n)%xdt + 52.0)/tstep + 1.0))
if (flip .ne. 0) j2 = int((sync(n)%xdt + 47.811)/tstep + 1.0)
+ j2 = max(1,j2)
ipol = sync(n)%ipol
pavg = 0.
do j = 1, j1
@@ -108,13 +114,16 @@ contains
do j = j2, jz
pavg = pavg + ss(ipol, j, n - 20:n + 20)
enddo
- jsum = j1 + (jz - j2 + 1)
- pmax = maxval(pavg(-2:2)) !### Why not just pavg(0) ?
- base = (sum(pavg) - pmax)/jsum
- pmax = pmax/base
- if (pmax .gt. 5.0) cycle
+ jsum = outside_row_count(j1,j2,jz)
+ if (jsum .gt. 0) then
+ pmax = maxval(pavg(-2:2)) !### Why not just pavg(0) ?
+ base = (sum(pavg) - pmax)/jsum
+ pmax = pmax/base
+ if (pmax .gt. 5.0) cycle
+ endif
skip = .false.
do m = 1, k !Skip false syncs within signal bw
+ if (cand(m)%iflip .ne. nint(flip)) cycle !only dedupe within the same type
diffhz = 1000.0*(f0 - cand(m)%f)
bw = nts_q65*110.0
if (cand(m)%iflip .ne. 0) bw = nts_jt65*178.0
@@ -128,40 +137,52 @@ contains
cand(k)%pol = sync(n)%pol
cand(k)%ipol = sync(n)%ipol
cand(k)%iflip = nint(flip)
- cand(k)%indx = n
+ cand(k)%indx = n
+
! write(50,3050) i,k,m,f0+32.0,diffhz,bw,snr1,db(snr1)
!3050 format(3i5,f8.3,2f8.0,2f8.2)
if (k .ge. MAX_CANDIDATES) exit
enddo
- ncand = k
+ ncand = k
return
end subroutine get_candidates
- subroutine wb_sync(ss, savg, xpol, jz, nfa, nfb)
+ subroutine wb_sync(ss, savg, xpol, q65_enabled, jz, nfa, nfb)
use iso_c_binding
+ use iso_fortran_env, only: real64
use debug_log
use indexx_mod
+ use map65_polarization_score_mod, only: generalized_polarization_score,polarization_matrix
use txpol_mod
use trimlist_mod
use pctile_mod
use polfit_mod
+ use npar_ptrs_mod, only: nrate_active, nfft_active
implicit none
!==== Dummy arguments =====================================================
- real, intent(in) :: ss(4,322,NFFT)
- real, intent(in) :: savg(4,NFFT)
- logical, intent(in) :: xpol
+ real, intent(in) :: ss(4,322,nfft_active)
+ real, intent(in) :: savg(4,nfft_active)
+ logical, intent(in) :: xpol,q65_enabled
integer, intent(in) :: jz, nfa, nfb
integer, parameter :: LAGMAX = 30
+ integer, parameter :: Q65_SYNC_ROWS = 3*22, JT65_SYNC_ROWS = 2*63
+ integer, parameter :: Q65_MIN_ROWS = Q65_SYNC_ROWS - 3
+ integer, parameter :: JT65_MIN_ROWS = JT65_SYNC_ROWS - 2
real(c_float) :: savg_med(4)
real ccf4(4), ccf4best(4), a(3)
- real base, bw, ccf, ccfmax, df3, fac, flip, poldeg, spk, syncmin, tstep
- integer i, i0, ia, ib, ipolbest, j, ja, jb, k, lag, lagbest
- integer nbw, nguard, npol, ipol
- logical first
+ real base, ccf, ccfmax, combine_poldeg, df3, fac, flip, poldeg, row_scale, tstep
+ real(real64) :: combine_angle,g00,g01,g11,n00,n01,n11,physical_angle
+ real(real64) :: projections(4),whitened_score
+ integer i, ia, ib, ipolbest, j, k, lag, lagbest, nrows
+ integer npol, ipol
+ logical first,generalized_available,score_valid
integer isync(22)
integer jsync0(63), jsync1(63)
+ integer q65_available(22,0:LAGMAX), q65_row_count(0:LAGMAX)
+ integer jt65_0_available(63,0:LAGMAX), jt65_0_row_count(0:LAGMAX)
+ integer jt65_1_available(63,0:LAGMAX), jt65_1_row_count(0:LAGMAX)
integer ip(1)
! --- JT65 wideband debugging probe ---
@@ -195,17 +216,48 @@ contains
first = .false.
endif
- df3 = 96000.0/NFFT
+ df3 = real(nrate_active)/real(nfft_active)
ia = nint(1000*nfa/df3) + 1 !Flat frequency range for WSE converters
ib = nint(1000*nfb/df3) + 1
if (ia .lt. 1) ia = 1
- if (ib .gt. NFFT - 1) ib = NFFT - 1
+ if (ib .gt. nfft_active - 1) ib = nfft_active - 1
npol = 1
if (xpol) npol = 4
+ q65_row_count = 0
+ jt65_0_row_count = 0
+ jt65_1_row_count = 0
+ do lag = 0, LAGMAX
+ do j = 1, 22
+ k = isync(j) + lag
+ q65_available(j,lag) = min(3,max(0,jz-k+1))
+ q65_row_count(lag) = q65_row_count(lag) + q65_available(j,lag)
+ enddo
+ do j = 1, 63
+ k = jsync0(j) + lag
+ jt65_0_available(j,lag) = min(2,max(0,jz-k+1))
+ jt65_0_row_count(lag) = jt65_0_row_count(lag) + jt65_0_available(j,lag)
+
+ k = jsync1(j) + lag
+ jt65_1_available(j,lag) = min(2,max(0,jz-k+1))
+ jt65_1_row_count(lag) = jt65_1_row_count(lag) + jt65_1_available(j,lag)
+ enddo
+ enddo
+
do i = 1, npol
call pctile(savg(i, ia:ib), ib - ia + 1, 50, savg_med(i))
enddo
+ n00=real(savg_med(1),real64)/real(jz,real64)
+ n11=n00
+ n01=0.0_real64
+ generalized_available=.false.
+ if (xpol .and. q65_enabled) then
+ n11=real(savg_med(3),real64)/real(jz,real64)
+ call pctile(0.5*(savg(2,ia:ib)-savg(4,ia:ib)),ib-ia+1,50,base)
+ n01=real(base,real64)/real(jz,real64)
+ call generalized_polarization_score(0.0_real64,0.0_real64,0.0_real64, &
+ n00,n11,n01,whitened_score,physical_angle,combine_angle,generalized_available)
+ endif
! do i=ia,ib
! write(14,3014) 0.001*(i-1)*df3,savg(1:npol,i)
!3014 format(5f10.3)
@@ -217,77 +269,131 @@ contains
do i = ia, ib
ccfmax = 0.
+ poldeg = 0.
+ combine_poldeg = 0.
+ q65_generalized_sync(i)%ccfmax=0.
+ q65_generalized_sync(i)%xdt=0.
+ q65_generalized_sync(i)%pol=0.
+ q65_generalized_sync(i)%combine_pol=0.
+ q65_generalized_sync(i)%ipol=1
+ q65_generalized_sync(i)%iflip=0
+ q65_generalized_sync(i)%birdie=.false.
do lag = 0, LAGMAX
- ccf = 0.
- ccf4 = 0.
- do j = 1, 22 !Test for Q65 sync
- k = isync(j) + lag
- ccf4(1:npol) = ccf4(1:npol) + ss(1:npol, k, i + 1) + &
- ss(1:npol, k + 1, i + 1) + ss(1:npol, k + 2, i + 1)
- enddo
- ccf4(1:npol) = ccf4(1:npol) - savg(1:npol, i + 1)*3*22/float(jz)
- ccf = maxval(ccf4)
- ip = maxloc(ccf4)
- ipol = ip(1)
- if (ccf .gt. ccfmax) then
- ipolbest = ipol
- lagbest = lag
- ccfmax = ccf
- ccf4best = ccf4
- flip = 0.
+ nrows = q65_row_count(lag)
+ if (nrows .ge. Q65_MIN_ROWS) then
+ ccf = 0.
+ ccf4 = 0.
+ do j = 1, 22 !Test for Q65 sync
+ k = isync(j) + lag
+ if (q65_available(j,lag) .ge. 1) &
+ ccf4(1:npol) = ccf4(1:npol) + ss(1:npol,k,i)
+ if (q65_available(j,lag) .ge. 2) &
+ ccf4(1:npol) = ccf4(1:npol) + ss(1:npol,k+1,i)
+ if (q65_available(j,lag) .ge. 3) &
+ ccf4(1:npol) = ccf4(1:npol) + ss(1:npol,k+2,i)
+ enddo
+ ccf4(1:npol) = ccf4(1:npol) - savg(1:npol,i)*real(nrows)/real(jz)
+ row_scale = sqrt(real(Q65_SYNC_ROWS)/real(nrows))
+ ccf4(1:npol) = row_scale*ccf4(1:npol)
+ ccf = maxval(ccf4)
+ ip = maxloc(ccf4)
+ ipol = ip(1)
+ if (generalized_available) then
+ projections=real(ccf4,real64)
+ call polarization_matrix(projections,g00,g11,g01)
+ call generalized_polarization_score(g00,g11,g01,n00,n11,n01, &
+ whitened_score,physical_angle,combine_angle,score_valid)
+ if (score_valid .and. whitened_score > &
+ real(q65_generalized_sync(i)%ccfmax,real64)) then
+ q65_generalized_sync(i)%ccfmax=real(whitened_score)
+ q65_generalized_sync(i)%xdt=lag*tstep-1.0
+ q65_generalized_sync(i)%pol=real(physical_angle)
+ q65_generalized_sync(i)%combine_pol=real(combine_angle)
+ q65_generalized_sync(i)%ipol=ipol
+ endif
+ endif
+ if (ccf .gt. ccfmax) then
+ ipolbest = ipol
+ lagbest = lag
+ ccfmax = ccf
+ ccf4best = ccf4
+ flip = 0.
+ endif
endif
- ccf = 0.
- ccf4 = 0.
- do j = 1, 63 !Test for JT65 sync, std msg
- k = jsync0(j) + lag
- ccf4(1:npol) = ccf4(1:npol) + ss(1:npol, k, i + 1) + ss(1:npol, k + 1, i + 1)
- enddo
- ccf4(1:npol) = ccf4(1:npol) - savg(1:npol, i + 1)*2*63/float(jz)
- ccf = maxval(ccf4)
- ip = maxloc(ccf4)
- ipol = ip(1)
- if (ccf .gt. ccfmax) then
- ipolbest = ipol
- lagbest = lag
- ccfmax = ccf
- ccf4best = ccf4
- flip = 1.0
+ nrows = jt65_0_row_count(lag)
+ if (nrows .ge. JT65_MIN_ROWS) then
+ ccf = 0.
+ ccf4 = 0.
+ do j = 1, 63 !Test for JT65 sync, std msg
+ k = jsync0(j) + lag
+ if (jt65_0_available(j,lag) .ge. 1) &
+ ccf4(1:npol) = ccf4(1:npol) + ss(1:npol,k,i)
+ if (jt65_0_available(j,lag) .ge. 2) &
+ ccf4(1:npol) = ccf4(1:npol) + ss(1:npol,k+1,i)
+ enddo
+ ccf4(1:npol) = ccf4(1:npol) - savg(1:npol,i)*real(nrows)/real(jz)
+ row_scale = sqrt(real(JT65_SYNC_ROWS)/real(nrows))
+ ccf4(1:npol) = row_scale*ccf4(1:npol)
+ ccf = maxval(ccf4)
+ ip = maxloc(ccf4)
+ ipol = ip(1)
+ if (ccf .gt. ccfmax) then
+ ipolbest = ipol
+ lagbest = lag
+ ccfmax = ccf
+ ccf4best = ccf4
+ flip = 1.0
+ endif
endif
- ccf = 0.
- ccf4 = 0.
- do j = 1, 63 !Test for JT65 sync, OOO msg
- k = jsync1(j) + lag
- ccf4(1:npol) = ccf4(1:npol) + ss(1:npol, k, i + 1) + ss(1:npol, k + 1, i + 1)
- enddo
- ccf4(1:npol) = ccf4(1:npol) - savg(1:npol, i + 1)*2*63/float(jz)
- ccf = maxval(ccf4)
- ip = maxloc(ccf4)
- ipol = ip(1)
- if (ccf .gt. ccfmax) then
- ipolbest = ipol
- lagbest = lag
- ccfmax = ccf
- ccf4best = ccf4
- flip = -1.0
+ nrows = jt65_1_row_count(lag)
+ if (nrows .ge. JT65_MIN_ROWS) then
+ ccf = 0.
+ ccf4 = 0.
+ do j = 1, 63 !Test for JT65 sync, OOO msg
+ k = jsync1(j) + lag
+ if (jt65_1_available(j,lag) .ge. 1) &
+ ccf4(1:npol) = ccf4(1:npol) + ss(1:npol,k,i)
+ if (jt65_1_available(j,lag) .ge. 2) &
+ ccf4(1:npol) = ccf4(1:npol) + ss(1:npol,k+1,i)
+ enddo
+ ccf4(1:npol) = ccf4(1:npol) - savg(1:npol,i)*real(nrows)/real(jz)
+ row_scale = sqrt(real(JT65_SYNC_ROWS)/real(nrows))
+ ccf4(1:npol) = row_scale*ccf4(1:npol)
+ ccf = maxval(ccf4)
+ ip = maxloc(ccf4)
+ ipol = ip(1)
+ if (ccf .gt. ccfmax) then
+ ipolbest = ipol
+ lagbest = lag
+ ccfmax = ccf
+ ccf4best = ccf4
+ flip = -1.0
+ endif
endif
enddo ! lag
- poldeg = 0.
if (xpol .and. ccfmax .ge. SNR1_THRESHOLD) then
call polfit(ccf4best, 4, a)
poldeg = a(3)
endif
+ combine_poldeg=poldeg
sync(i)%ccfmax = ccfmax
sync(i)%xdt = lagbest*tstep - 1.0
sync(i)%pol = poldeg
+ sync(i)%combine_pol = combine_poldeg
sync(i)%ipol = ipolbest
sync(i)%iflip = int(flip)
sync(i)%birdie = .false.
if (ccfmax/(savg(ipolbest, i)/savg_med(ipolbest)) .lt. 3.0) sync(i)%birdie = .true.
+ if (generalized_available) then
+ ipol=q65_generalized_sync(i)%ipol
+ if (q65_generalized_sync(i)%ccfmax/(savg(ipol,i)/savg_med(ipol)) .lt. 3.0) &
+ q65_generalized_sync(i)%birdie=.true.
+ endif
! --- JT65 wideband probe (new) ---
! freq_hz = 0.001 * (i - 1) * df3 ! convert FFT bin index to kHz
@@ -303,26 +409,28 @@ contains
call pctile(sync(ia:ib)%ccfmax, ib - ia + 1, 50, base)
sync(ia:ib)%ccfmax = sync(ia:ib)%ccfmax/base
+ if (generalized_available) then
+ call pctile(q65_generalized_sync(ia:ib)%ccfmax,ib-ia+1,50,base)
+ if (base > tiny(base)) then
+ q65_generalized_sync(ia:ib)%ccfmax=q65_generalized_sync(ia:ib)%ccfmax/base
+ sync(ia:ib)=q65_generalized_sync(ia:ib)
+ endif
+ endif
- bw = 65*4*1.66666667 !Q65-60C bandwidth
- nbw = int(bw/df3 + 1) !Number of bins to blank
- syncmin = 2.0
- nguard = 10
- do i = ia, ib
- if (sync(i)%ccfmax .lt. syncmin) cycle
- if ((i .lt. 1) .or. (i .gt. (NFFT - nbw))) cycle !w3sz debug
- spk = maxval(sync(i:i + nbw)%ccfmax)
- ip = maxloc(sync(i:i + nbw)%ccfmax)
- i0 = ip(1) + i - 1
- ja = min(i, i0 - nguard)
- jb = i0 + nbw + nguard
- if (ja .lt. 1) cycle !ja = 1 !w3sz debug
- if (jb .lt. 1) cycle !jb = 1 !w3sz debug
- if (ja .gt. NFFT) cycle !ja = NFFT !w3sz debug
- if (jb .gt. NFFT) cycle !jb = NFFT !w3sz debug
- sync(ja:jb)%ccfmax = 0.
- sync(i0)%ccfmax = spk
- enddo
+ ! A local-peak "collapse to single survivor" pass used to run here,
+ ! blanking a wide (~450 Hz) same-type swath around whatever bin its
+ ! own forward-only search happened to land on. Because that search
+ ! and blanking radius were not centered on the true global peak, it
+ ! could -- and, for closely-spaced real Q65 signals, did -- wipe out
+ ! a much stronger genuine peak in favor of a weaker one found earlier
+ ! in the frequency sweep, corrupting the candidate frequency reported
+ ! for that signal (confirmed via w3sz debug logging: a real Q65
+ ! signal's candidate frequency was off by ~150-200 Hz from its true
+ ! peak whenever this pass ran, and exactly correct with it removed).
+ ! get_candidates() below already does its own correct, strength-
+ ! ordered, same-type-only deduplication (skip a candidate within its
+ ! own signal bandwidth of an already-accepted stronger one), which
+ ! does not have this failure mode, so this pass is not needed.
! do i=ia,ib
! write(15,3015) 0.001*(i-1)*df3+32.0,sync(i)%ccfmax,sync(i)%xdt, &
@@ -333,10 +441,19 @@ contains
return
end subroutine wb_sync
- subroutine init_wideband_sync(n)
+ pure integer function outside_row_count(j1,j2,jz)
+ implicit none
+ integer, intent(in) :: j1,j2,jz
+
+ outside_row_count = max(0,min(j1,jz)) + max(0,jz-max(1,j2)+1)
+ end function outside_row_count
+
+ subroutine init_wideband_sync()
+ use npar_ptrs_mod, only: nfft_active
implicit none
- integer, intent(in) :: n
- if (.not. allocated(sync)) allocate (sync(n))
+ if (.not. allocated(sync)) allocate (sync(nfft_active))
+ if (.not. allocated(q65_generalized_sync)) &
+ allocate (q65_generalized_sync(nfft_active))
end subroutine init_wideband_sync
end module wideband_sync
diff --git a/map65/main.cpp b/map65/main.cpp
index 55ef209a..5c8de1d7 100644
--- a/map65/main.cpp
+++ b/map65/main.cpp
@@ -9,18 +9,25 @@
#include <windows.h>
#endif
-
#include "revision_utils.hpp"
#include "mainwindow.h"
#include "fortran_mutex.hpp"
+#include "globals.h"
+#include "runtime_paths.h"
#include <cstdio>
+extern "C" void set_runtime_params_(int rate_hz, int nfft, int nfft_big);
+
extern "C" {
// Fortran procedures we need
void four2a_ (_Complex float *, int * nfft, int * ndim, int * isign, int * iform, int len);
}
+extern int g_sampleRate;
+extern int active_nfft;
+int g_activeNfft = 32768; // default
+
int main(int argc, char *argv[])
{
#ifdef _WIN32
@@ -37,12 +44,55 @@ int main(int argc, char *argv[])
# endif
#endif
QApplication a {argc, argv};
-
- // Override programs executable basename as application name.
a.setApplicationName ("MAP65");
- a.setApplicationVersion ("3.6");
- // switch off as we share an Info.plist file with WSJT-X
+ a.setApplicationVersion ("3.8.2");
a.setAttribute (Qt::AA_DontUseNativeMenuBar);
+
+ QString appDir = QApplication::applicationDirPath();
+ QString dataDir = writableMap65DataDir();
+ QSettings settings(map65SettingsFile(appDir, dataDir), QSettings::IniFormat);
+ settings.beginGroup("Common");
+ int srFlag = readFSam96000(settings, 1);
+ settings.endGroup();
+ if(srFlag <= 1) g_sampleRate = 96000;
+ else if(srFlag == 2) g_sampleRate = 192000;
+ if (g_sampleRate != 96000 && g_sampleRate != 192000)
+ g_sampleRate = 96000;
+
+// ------------------------------------------------------------
+// NEW: compute active FFT sizes for MAP65
+// ------------------------------------------------------------
+int active_rate = g_sampleRate;
+
+// Keep ~3 Hz bin resolution like WSJT-X/QMAP
+auto round_pow2 = [](int x) {
+ int p = 1;
+ while (p < x) p <<= 1;
+ return p;
+};
+
+// symspec FFT size
+active_nfft = round_pow2(
+ static_cast<int>(
+ static_cast<long long>(BASELINE_NFFT) * active_rate / BASELINE_RATE
+ )
+);
+
+g_activeNfft = active_nfft;
+
+// big FFT size (56 symbols * sample rate)
+int active_nfft_big = 56 * active_rate;
+
+// ------------------------------------------------------------
+// Push runtime parameters into Fortran BEFORE MainWindow starts
+// ------------------------------------------------------------
+set_runtime_params_(active_rate, active_nfft, active_nfft_big);
+
+// ------------------------------------------------------------
+// allocate buffers now that sample rate is known
+// ------------------------------------------------------------
+id.resize(4 * 60 * g_sampleRate);
+
MainWindow w;
w.show ();
diff --git a/map65/mainwindow.cpp b/map65/mainwindow.cpp
index 7a47d5b6..3cb1e760 100644
--- a/map65/mainwindow.cpp
+++ b/map65/mainwindow.cpp
@@ -30,6 +30,7 @@
#include <QApplication>
#include <QDebug>
#include <QDateTime>
+#include <QTime>
#include <QFile>
#include <QTextStream>
#include <QString>
@@ -47,6 +48,8 @@
#include "stdout_channel.h"
#include "fortran_mutex.hpp"
+#include "pskreporter_settings.h"
+#include "runtime_paths.h"
#if !defined(Q_OS_WIN)
extern "C" {
@@ -66,51 +69,13 @@ extern "C" void ptt_close(void);
#undef MessageBox
#endif
-#define NFFT 32768
-
-
QByteArray g_TxTuneGeometry;
-namespace {
-struct Map65TxWaveStorage { short int samples[2*60*12000]; };
-struct Map65RxSamplesStorage { qint16 samples[4*60*96000]; };
-
-QString writableMap65DataDir()
-{
- QString dataDir = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
- if (dataDir.isEmpty()) {
- dataDir = QDir::home().absoluteFilePath(".map65");
- }
-
- if (!QDir{}.mkpath(dataDir)) {
- qWarning() << "Unable to create MAP65 data directory:" << dataDir;
- }
-
- QDir dir {dataDir};
- if (!dir.mkpath("save")) {
- qWarning() << "Unable to create MAP65 save directory:" << dir.absoluteFilePath("save");
- }
- return dataDir;
-}
-
-QString map65SettingsFile(QString const& appDir, QString const& dataDir)
-{
- QString settingsFile = QDir {dataDir}.absoluteFilePath("map65.ini");
- QString legacySettingsFile = QDir {appDir}.absoluteFilePath("map65.ini");
- if (!QFile::exists(settingsFile) && QFile::exists(legacySettingsFile)) {
- if (QFile::copy(legacySettingsFile, settingsFile)) {
- QFile::setPermissions(settingsFile, QFile::ReadOwner | QFile::WriteOwner
- | QFile::ReadGroup | QFile::ReadOther);
- } else {
- qWarning() << "Unable to migrate MAP65 settings from" << legacySettingsFile
- << "to" << settingsFile;
- }
- }
- return settingsFile;
-}
-} // namespace
+int g_sampleRate = 96000;
+int active_nfft;
+std::vector<qint16> id;
-short int (&iwave)[2*60*12000] = (new Map65TxWaveStorage{})->samples; //Wave file for Tx audio
+short int iwave[2*60*12000]; //Wave file for Tx audio
int nwave; //Length of Tx waveform
bool btxok; //True if OK to transmit
bool bTune;
@@ -119,14 +84,10 @@ double outputLatency; //Latency in seconds
int txPower;
int iqAmp;
int iqPhase;
-qint16 (&id)[4*60*96000] = (new Map65RxSamplesStorage{})->samples;
int pipefd[2]; // pipefd[0] = read end, pipefd[1] = write end
TxTune* g_pTxTune = NULL;
-extern const int RxDataFrequency = 96000;
-extern const int TxDataFrequency = 11025;
-
std::atomic<bool> stop_m65{false};
QString guiDate; //liveCQ
@@ -134,8 +95,6 @@ QStringList allDecodes; //liveCQ
QStringList allDecodes2; //liveCQ
QString m_otherUrl;
bool m_w3szUrl;
-bool m_spot_to_psk_reporter;
-bool m_psk_reporter_tcpip;
struct MainWindow::DecoderContext
{
@@ -149,7 +108,7 @@ MainWindow::DecoderContext::DecoderContext()
stdoutChan = new StdoutChannel(
L"MAP65_STDOUT_MAPPING",
L"MAP65_STDOUT_EVENT",
- 64 * 1024
+ 1024 * 1024
);
}
@@ -158,12 +117,43 @@ MainWindow::DecoderContext::~DecoderContext()
delete stdoutChan;
}
+// TEMP diagnostic 2026-09-10 for the "decode reaches map65_rx.log but not the
+// Messages window, only on the first decode cycle after MAP65 starts" report.
+// Writes to its own separate log file rather than the shared w3sz_debug.log
+// Fortran's dbg() uses -- the two processes/threads have no lock between
+// them, and sharing a file produces torn, interleaved lines. Timestamps use
+// the same sec_midn()-style local h*3600+m*60+s+ms/1000 format as the
+// Fortran log, so the two can still be correlated by eye. Strip both files'
+// worth of logging before merge.
+//
+// Mirrors run_m65.f90's dbg_enabled flag -- flip to true to re-enable this
+// log without touching any of the cppDbg(...) call sites scattered through
+// this file.
+static bool const cppDbgEnabled = false;
+
+static void cppDbg(const QString &msg)
+{
+ if (!cppDbgEnabled) return;
+ double const t = [] {
+ QTime const now = QTime::currentTime();
+ return now.hour() * 3600.0 + now.minute() * 60.0 + now.second() + now.msec() / 1000.0;
+ }();
+ QFile f("w3sz_debug_cpp.log");
+ if (f.open(QIODevice::Append | QIODevice::Text)) {
+ QTextStream out(&f);
+ out << "mainwindow: " << msg << " at t=" << QString::number(t, 'f', 3) << "\n";
+ }
+}
+
//-------------------------------------------------- MainWindow constructor
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
m_appDir {QApplication::applicationDirPath ()},
+ m_installedDataDir {installed_data_directory ().absolutePath ()},
m_dataDir {writableMap65DataDir ()},
+ m_eclipseFile {map65RuntimeSourceFile (m_appDir, m_installedDataDir, m_dataDir,
+ "eclipse.txt")},
m_settings_filename {map65SettingsFile (m_appDir, m_dataDir)},
m_astro_window {new Astro {m_settings_filename}},
m_band_map_window {new BandMap {m_settings_filename}},
@@ -171,13 +161,15 @@ MainWindow::MainWindow(QWidget *parent) :
m_wide_graph_window {new WideGraph {m_settings_filename}},
m_gui_timer {new QTimer {this}}
{
- qDebug() << "IN MainWindow Constructor NFFT IS: " << NFFT;
- // Legacy C++ and Fortran paths still use relative opens for runtime files.
+ qDebug() << "IN MainWindow Constructor active_nfft IS: " << active_nfft;
if (!QDir::setCurrent(m_dataDir)) {
qWarning() << "Unable to set MAP65 working directory:" << m_dataDir;
}
+ QByteArray dataDirBytes = m_dataDir.toLocal8Bit();
+ set_wsjtx_dir_(dataDirBytes.constData(), dataDirBytes.size());
+ ensureMap65RuntimeFile(m_appDir, m_installedDataDir, m_dataDir, "CALL3.TXT");
constexpr int baseSeconds = 56;
- constexpr int sampleRate = 96000;
+ const int sampleRate = g_sampleRate;
constexpr int channels = 4; // dd(1..4, t)
decoderCtx = new DecoderContext();
@@ -192,17 +184,28 @@ MainWindow::MainWindow(QWidget *parent) :
// Tell Fortran about the maximum shape (channels × pairsWorst)
set_dd_ptr(dd, channels, pairsWorst);
+ qDebug() << "g_sampleRate:" << g_sampleRate
+ << "sampleRate:" << sampleRate
+ << "id.size():" << id.size()
+ << "bytes:" << id.size() * sizeof(id[0]);
+
std::cout << "dd pointer set to: " << dd
<< " size: " << ddSize
<< " (channels=" << channels
<< ", pairsWorst=" << pairsWorst << ")\n";
- ss = new float[4 * 322 * NFFT];
- savg = new float[4 * NFFT];
- set_ss_ptr(ss, 4, 322, NFFT);
+ ss = new float[4 * 322 * active_nfft];
+ savg = new float[4 * active_nfft];
+ set_ss_ptr(ss, 4, 322, active_nfft);
std::cout << "ss pointer set to: " << ss << std::endl;
- set_savg_ptr(savg, 4, NFFT);
+ set_savg_ptr(savg, 4, active_nfft);
std::cout << "savg pointer set to: " << savg << std::endl;
+ dd_old = new float[ddSize];
+ set_dd_old_ptr(dd_old, channels, pairsWorst);
+ ss_old = new float[4 * 322 * active_nfft];
+ savg_old = new float[4 * active_nfft];
+ set_ss_old_ptr(ss_old, 4, 322, active_nfft);
+ set_savg_old_ptr(savg_old, 4, active_nfft);
qDebug() << "MAINWINDOW created dd ss savg ";
@@ -243,6 +246,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui->actionNo_Deep_Search->setActionGroup(DepthGroup);
ui->actionNormal_Deep_Search->setActionGroup(DepthGroup);
ui->actionAggressive_Deep_Search->setActionGroup(DepthGroup);
+ ui->actionFull_Deep_Search->setActionGroup(DepthGroup);
QButtonGroup* txMsgButtonGroup = new QButtonGroup;
txMsgButtonGroup->addButton(ui->txrb1,1);
@@ -343,7 +347,7 @@ MainWindow::MainWindow(QWidget *parent) :
wg, [wg]{ wg->setDecodeLabelPosition(DecodeLabelPosition::Bottom); });
}
- setWindowTitle (program_title ());
+ setWindowTitle (branded_program_title ());
qDebug() << "MAINWINDOW about to start soundInThread SIGNAL/SLOT connections";
connect(&soundInThread, SIGNAL(readyForFFT(int)),
@@ -388,7 +392,7 @@ MainWindow::MainWindow(QWidget *parent) :
m_NB=false;
m_mode="JT65B";
m_mode65=2;
- m_fs96000=true;
+ m_fs96000=1;
m_udpPort=50004;
m_adjustIQ=0;
m_applyIQcal=0;
@@ -411,11 +415,34 @@ MainWindow::MainWindow(QWidget *parent) :
fftwf_import_wisdom_from_filename (QDir {m_dataDir}.absoluteFilePath ("map65_wisdom.dat").toLocal8Bit ());
readSettings(); //Restore user's setup params
+
+ // Push mycall/mygrid/hiscall/hisgrid/neme to the Fortran side here, right
+ // after settings load, instead of waiting for the first
+ // MainWindow::decode() call to do it (decode() still pushes these on
+ // every cycle further down; this just makes the values available
+ // sooner). run_m65.f90 builds the deep65 CALL3.TXT candidate list eagerly
+ // before its decode loop starts (build_call3_candidates() in deep65.f90);
+ // without this, that eager build ran against Fortran's still-default/
+ // blank mycall/hiscall, and decode0.f90's genuine mycall-changed check
+ // then forced a second, redundant rebuild on the first real decode.
+ {
+ QString mcall = (m_myCall + " ").mid(0, 12);
+ QString mgrid = (m_myGrid + " ").mid(0, 6);
+ QString hcall = (ui->dxCallEntry->text() + " ").mid(0, 12);
+ QString hgrid = (ui->dxGridEntry->text() + " ").mid(0, 6);
+ setMyCall(mcall);
+ setMyGrid(mgrid);
+ setHisCall(hcall);
+ setHisGrid(hgrid);
+ setNeme(0);
+ if (ui->actionOnly_EME_calls->isChecked()) setNeme(1);
+ }
+
PaError paerr=Pa_Initialize(); //Initialize Portaudio
if(paerr!=paNoError) {
msgBox("Unable to initialize PortAudio.");
}
- QFile quitFile(QDir {m_dataDir}.absoluteFilePath (".quit"));
+ QFile quitFile(m_appDir + "/.quit");
quitFile.remove();
m_pbdecoding_style1="QPushButton{background-color: cyan; \
@@ -460,8 +487,9 @@ MainWindow::MainWindow(QWidget *parent) :
// Assign input device and start input thread
soundInThread.setInputDevice(m_paInDevice);
- if(m_fs96000) soundInThread.setRate(96000.0);
- if(!m_fs96000) soundInThread.setRate(95238.1);
+ if(m_fs96000 == 1) soundInThread.setRate(96000.0);
+ else if(m_fs96000 ==0) soundInThread.setRate(95238.1);
+ else if(m_fs96000 ==2) soundInThread.setRate(192000.0);
soundInThread.setBufSize(10*7056);
soundInThread.setNetwork(m_network);
soundInThread.setPort(m_udpPort);
@@ -473,11 +501,11 @@ MainWindow::MainWindow(QWidget *parent) :
soundOutThread.setOutputDevice(m_paOutDevice);
m_monitoring=true; // Start with Monitoring ON
+ qDebug() << "m_monitoring set to" << m_monitoring << "at" << Q_FUNC_INFO;
+
soundInThread.setMonitoring(m_monitoring);
m_diskData=false;
m_wide_graph_window->setFcal(m_fCal);
- if(m_fs96000) m_wide_graph_window->setFsample(96000);
- if(!m_fs96000) m_wide_graph_window->setFsample(95238);
m_wide_graph_window->m_mult570=m_mult570;
m_wide_graph_window->m_mult570Tx=m_mult570Tx;
m_wide_graph_window->m_cal570=m_cal570;
@@ -509,7 +537,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect (m_wide_graph_window.get (), &WideGraph::f11f12, this, &MainWindow::bumpDF);
QTimer::singleShot (0, this,[this]() {
- m_messages_window = new Messages(m_settings_filename);
+ m_messages_window = new Messages(m_settings_filename, m_eclipseFile);
m_messages_window->show();
on_actionMessages_triggered();
connect (m_messages_window, &Messages::click2OnCallsign, this, &MainWindow::doubleClickOnMessages);
@@ -570,32 +598,33 @@ void MainWindow::startDecoder()
{
qDebug() << "MAINWINDOW calling run_m65_ ";
- QByteArray runtimeDir = QDir::toNativeSeparators(m_dataDir).toLocal8Bit();
- set_wsjtx_dir_(runtimeDir.constData(), runtimeDir.size());
-
QFutureWatcher<void>* watcher_m65 = new QFutureWatcher<void>(this);
connect(watcher_m65, &QFutureWatcher<void>::finished,
this, &MainWindow::onRunM65Finished);
watcher_m65->setFuture(QtConcurrent::run([=]() {
- // Hook up shared stdout channel for Fortran
- StdoutSharedRegion* region =
- decoderCtx->stdoutChan->shared.getRegion();
- void* bufPtr = static_cast<void*>(region->buffer);
- void* hdrPtr = static_cast<void*>(&region->header);
- int bufSize = static_cast<int>(decoderCtx->stdoutChan->shared.getBufferSize());
- intptr_t eventH = reinterpret_cast<intptr_t>(decoderCtx->stdoutChan->eventHandle);
+ qDebug() << "DECODE: starting run_m65_() with m_fs96000=" << m_fs96000;
+
+ // Hook up shared stdout channel for Fortran
+ StdoutSharedRegion* region =
+ decoderCtx->stdoutChan->shared.getRegion();
- set_stdout_channel(bufPtr, hdrPtr, bufSize, eventH);
+ void* bufPtr = static_cast<void*>(region->buffer);
+ void* hdrPtr = static_cast<void*>(&region->header);
+ int bufSize = static_cast<int>(decoderCtx->stdoutChan->shared.getBufferSize());
+ intptr_t eventH = reinterpret_cast<intptr_t>(decoderCtx->stdoutChan->eventHandle);
- // Now run the decoder
- std::lock_guard<std::mutex> lock(g_fortran_decode_mutex);
- int xpol_flag = m_xpol ? 1 : 0;
- int rate_flag = m_fs96000 ? 1 : 0;
- run_m65_(&xpol_flag, &rate_flag);
+ set_stdout_channel(bufPtr, hdrPtr, bufSize, eventH);
+ // Now run the decoder
+ std::lock_guard<std::mutex> lock(g_fortran_decode_mutex);
+ int xpol_flag = m_xpol ? 1 : 0;
+ run_m65_(&xpol_flag, &m_fs96000);
+
+ qDebug() << "DECODE: run_m65_() returned";
}));
+
}
void MainWindow::startSharedMemoryStdoutReader(DecoderContext* ctx)
@@ -619,6 +648,17 @@ void MainWindow::startSharedMemoryStdoutReader(DecoderContext* ctx)
std::uint32_t readIndex = h0.writeIndex;
if (readIndex >= bufSize)
readIndex = 0;
+ region->header.readIndex = readIndex;
+
+ // TEMP diagnostic 2026-09-10: h0.writeIndex should always be 0 here --
+ // StdoutSharedMemory's constructor unconditionally zeroes writeIndex/
+ // readIndex right after mapping (see stdout_shared_memory.cpp), and
+ // that happens synchronously on the main thread before this reader
+ // thread is even spawned. If this ever logs a nonzero value, that
+ // assumption is wrong and this "start from current writeIndex" line
+ // is silently skipping over real data written before this point.
+ cppDbg(QString("stdout reader INIT readIndex=%1 (h0.writeIndex=%2) bufSize=%3")
+ .arg(readIndex).arg(h0.writeIndex).arg(bufSize));
std::string lineBuffer;
@@ -652,16 +692,43 @@ void MainWindow::startSharedMemoryStdoutReader(DecoderContext* ctx)
);
}
}
+
+ // Publish how far we've drained so the Fortran writer can
+ // compute free space and wait for room instead of wrapping
+ // around and overwriting data we haven't read yet.
+ region->header.readIndex = readIndex;
}
});
}
void MainWindow::processStdOut(QString t)
-{
-
+{
+
// qDebug().noquote() << QDateTime::currentMSecsSinceEpoch() << "PROCESS STDOUT:" << t;
+ // TEMP diagnostic 2026-09-10: confirms whether a decode line that made it
+ // into map65_rx.log (written Fortran-side, independent of this whole
+ // path) ever actually arrived here on the GUI thread. If a "!"-prefixed
+ // line is missing from this log around the time of a report-vs-rx.log
+ // mismatch, the loss is upstream (shared-memory ring buffer / reader
+ // thread); if it IS here but never appended to the Messages window, the
+ // loss is in handleControlLine/shouldDisplay below.
+ cppDbg(QString("processStdOut RECV \"%1\"").arg(t.trimmed()));
+
+ if (m_decodeDisplayFilter.handleControlLine(t)) return;
+
+ if (t.startsWith("<DecodeSkipped>")) {
+ bool validRequestId = false;
+ auto requestId = t.trimmed().section(' ', -1).toLongLong(&validRequestId);
+ if (validRequestId && is_current_decode_request(requestId)) {
+ m_decodeDisplayFilter.completeCycle();
+ decodeBusy(false);
+ ui->DecodeButton->setStyleSheet("");
+ }
+ return;
+ }
+
//qDebug() << "in processStdOut STDOUT:" << t;
if (t.indexOf("<QuickDecodeDone>") >= 0) {
@@ -677,6 +744,17 @@ if (t.indexOf("<QuickDecodeDone>") >= 0) {
// --- <EarlyFinished> / <DecodeFinished> ---
if (t.indexOf("<EarlyFinished>") >= 0 || t.indexOf("<DecodeFinished>") >= 0) {
+ if (t.indexOf("<DecodeFinished>") >= 0) {
+ bool validRequestId = false;
+ auto requestId = t.trimmed().section(' ', -1).toLongLong(&validRequestId);
+ if (!validRequestId || !is_current_decode_request(requestId)) return;
+ }
+
+ if (t.indexOf("<EarlyFinished>") >= 0)
+ m_decodeDisplayFilter.completeEarlyPass();
+ if (t.indexOf("<DecodeFinished>") >= 0)
+ m_decodeDisplayFilter.completeCycle();
+
if (m_widebandDecode) {
if (m_messages_window)
m_messages_window->setText(m_messagesText, m_bandmapText);
@@ -687,16 +765,21 @@ if (t.indexOf("<QuickDecodeDone>") >= 0) {
if (t.indexOf("<DecodeFinished>") >= 0) {
++m_decodeFinishedCount;
- decodeBusy(false);
+ decodeBusy(false);
// qDebug().noquote() << QDateTime::currentMSecsSinceEpoch() << "decodeBusy(false)";
if (m_diskData) onDiskDecodeFinished();
int ndecodes = t.mid(40,5).toInt();
- lab5->setText(QString::number(ndecodes));
- m_map65RxLog = 0;
+ lab8->setText(QString::number(ndecodes));
+ m_map65RxLog = 0;
+
+ // Only clear the button's "busy" styling on <DecodeFinished>, not
+ // <EarlyFinished> -- decodeBusy(false) is likewise gated on
+ // <DecodeFinished> alone, and the final pass can legitimately take
+ // many seconds longer than the early pass, during which the button
+ // must keep showing busy while more decodes are still arriving.
+ ui->DecodeButton->setStyleSheet("");
}
-
- ui->DecodeButton->setStyleSheet("");
return;
}
@@ -710,11 +793,23 @@ if (t.indexOf("<QuickDecodeDone>") >= 0) {
#ifdef WIN32
m = 3;
#endif
- const QString decode_line = t.mid(1, n - m);
-
- // Suppress *second* narrowband GUI entry, but keep everything else
- if (m_RxState != 2 || m_diskData) {
- if (n >= 30 || t.indexOf("Best-fit") >= 0)
+ // The m=2/m=3 trim above assumes a normal decode line's fixed
+ // layout, whose last field is disposable padding/polarization --
+ // Find Delta Phi's "!Best-fit Dphi = NNN deg" summary line ends on
+ // real content instead (the "g" of "deg"), so the same trim chops
+ // it to "...de". Just trim the line terminator for this one case.
+ const QString decode_line = (t.indexOf("Best-fit") >= 0)
+ ? t.mid(1).trimmed()
+ : t.mid(1, n - m);
+
+ if (n >= 30 || t.indexOf("Best-fit") >= 0) {
+ bool const display = m_decodeDisplayFilter.shouldDisplay(decode_line);
+ // TEMP diagnostic 2026-09-10 -- see the matching note at the top
+ // of processStdOut(). If display=false here for a line that has
+ // no legitimate earlier-pass duplicate, the display filter itself
+ // (map65_decode_display_filter.cpp) is the culprit.
+ cppDbg(QString("shouldDisplay=%1 for \"%2\"").arg(display ? "true" : "false").arg(decode_line));
+ if (display)
ui->decodedTextBrowser->append(decode_line);
}
@@ -857,12 +952,13 @@ if (t.indexOf("<QuickDecodeDone>") >= 0) {
void MainWindow::onRunM65Finished() {
// Do something when run_m65 finishes
+ // qDebug() << "DECODE: onRunM65Finished()";
}
void MainWindow::onDiskDecodeFinished()
{
if (!m_path.isEmpty())
- setWindowTitle("MAP65 - " + QFileInfo(m_path).fileName());
+ setWindowTitle("MAP65™ - " + QFileInfo(m_path).fileName());
if (m_loopall)
on_actionOpen_next_in_directory_triggered();
@@ -901,7 +997,7 @@ void MainWindow::writeSettings()
settings.setValue("Fcal",m_fCal);
settings.setValue("Fadd",m_fAdd);
settings.setValue("NetworkInput", m_network);
- settings.setValue("FSam96000", m_fs96000);
+ settings.setValue("FSam96000", QString::number(m_pendingFs96000 >= 0 ? m_pendingFs96000 : m_fs96000));
settings.setValue("SoundInIndex",m_nDevIn);
settings.setValue("paInDevice",m_paInDevice);
settings.setValue("SoundOutIndex",m_nDevOut);
@@ -958,12 +1054,13 @@ void MainWindow::writeSettings()
void MainWindow::readSettings()
{
QSettings settings(m_settings_filename, QSettings::IniFormat);
+ auto const pskReporterSettings = readMap65PSKReporterSettings(settings);
{
SettingsGroup g {&settings, "MainWindow"};
restoreGeometry(settings.value("geometry").toByteArray());
ui->dxCallEntry->setText(settings.value("DXcall","").toString());
ui->dxGridEntry->setText(settings.value("DXgrid","").toString());
- m_path = settings.value("MRUdir", QDir {m_dataDir}.absoluteFilePath("save")).toString();
+ m_path = settings.value("MRUdir", m_appDir + "/save").toString();
m_txFirst = settings.value("TxFirst",false).toBool();
ui->txFirstCheckBox->setChecked(m_txFirst);
}
@@ -984,6 +1081,19 @@ void MainWindow::readSettings()
m_xpolx=settings.value("XpolX",false).toBool();
m_saveDir=settings.value("SaveDir",QDir {m_dataDir}.absoluteFilePath("save")).toString();
m_azelDir=settings.value("AzElDir",m_dataDir).toString();
+ if (!settings.value("AzElDirMigratedToDataDir",false).toBool()) {
+ // One-time migration: earlier versions defaulted AzElDir to the
+ // application/bin directory instead of the user data directory, and
+ // that default got persisted the first time settings were saved. An
+ // exact-match check against the *current* m_appDir can't catch this,
+ // since the saved value may point at some older build's bin directory
+ // that no longer matches this run's m_appDir at all. So instead: force
+ // everyone onto the new default exactly once, unconditionally, then
+ // remember it's done so a deliberate later customization (via the
+ // Setup dialog's AzEl Directory field) is never overwritten again.
+ m_azelDir = m_dataDir;
+ settings.setValue("AzElDirMigratedToDataDir",true);
+ }
m_editorCommand=settings.value("Editor","notepad").toString();
m_dxccPfx=settings.value("DXCCpfx","").toString();
m_timeout=settings.value("Timeout",20).toInt();
@@ -994,7 +1104,8 @@ void MainWindow::readSettings()
m_fAdd=settings.value("Fadd",0).toDouble();
soundInThread.setFadd(m_fAdd);
m_network = settings.value("NetworkInput",true).toBool();
- m_fs96000 = settings.value("FSam96000",true).toBool();
+ m_fs96000 = readFSam96000(settings,1);
+ qDebug() << "In MainWindow::readSettings FSam96000 is read as:" << m_fs96000;
m_nDevIn = settings.value("SoundInIndex", 0).toInt();
m_paInDevice = settings.value("paInDevice",0).toInt();
m_nDevOut = settings.value("SoundOutIndex", 0).toInt();
@@ -1060,10 +1171,11 @@ void MainWindow::readSettings()
if(m_ndepth==0) ui->actionNo_Deep_Search->setChecked(true);
if(m_ndepth==1) ui->actionNormal_Deep_Search->setChecked(true);
if(m_ndepth==2) ui->actionAggressive_Deep_Search->setChecked(true);
+ if(m_ndepth==3) ui->actionFull_Deep_Search->setChecked(true);
m_w3szUrl=settings.value("w3szUrl",true).toBool();
m_otherUrl=settings.value("otherUrl","").toString();
- m_spot_to_psk_reporter=settings.value("spotPSK",true).toBool();
- m_psk_reporter_tcpip=settings.value("PSKReporterTCPIP",false).toBool();
+ m_spot_to_psk_reporter = pskReporterSettings.enabled;
+ m_psk_reporter_tcpip = pskReporterSettings.use_tcpip;
m_tol=settings.value("FTol",500).toInt();
m_wide_graph_window->setTol(m_tol);
@@ -1072,7 +1184,7 @@ void MainWindow::readSettings()
if(m_tol==50) i=2;
if(m_tol==100) i=3;
if(m_tol==200) i=4;
-// if(m_tol==500) i=5;
+ if(m_tol==500) i=5;
if(m_tol==1000) i=6;
ui->labTol1->setText(QString::number(m_tol));
ui->tolSpinBox->setValue(i);
@@ -1099,13 +1211,20 @@ void MainWindow::readSettings()
//-------------------------------------------------------------- dataSink()
void MainWindow::dataSink(int k)
{
- static float s[NFFT],splot[NFFT];
+ static float* s = nullptr;
+ static float* splot = nullptr;
+ if (!s) {
+ s = new float[active_nfft];
+ splot = new float[active_nfft];
+ }
static int n=0;
static int ihsym=0;
static int nzap=0;
static int ntrz=0;
static int nkhz;
- int nfsample= m_fs96000 ? 96000 : 95238;
+ int nfsample = 96000;
+ if (m_fs96000 == 0) nfsample = 95238;
+ else if(m_fs96000 == 2) nfsample = 192000;
setNfsample(nfsample);
int nxpol= m_xpol ? 1 : 0;
setNxpol(nxpol);
@@ -1115,7 +1234,8 @@ void MainWindow::dataSink(int k)
static int nb;
static int nadj=0;
static float px=0.0,py=0.0;
- static uchar lstrong[1024];
+ constexpr int lstrongSize = 1024;
+ static uchar lstrong[lstrongSize];
static float rejectx;
static float rejecty;
static float slimit;
@@ -1133,15 +1253,13 @@ void MainWindow::dataSink(int k)
// Get x and y power, polarized spectrum, nkhz, and ihsym
nb=0;
if(m_NB) nb=1;
- nfsample=96000;
- if(!m_fs96000) nfsample=95238;
nxpol=0;
if(m_xpol) nxpol=1;
nadj++;
if(m_adjustIQ==0) nadj=0;
-
+
symspec_(&k, &nxpol, &ndiskdat, &nb, &m_NBslider, &m_dPhi,
- &nfsample, &m_adjustIQ, &m_applyIQcal,
+ &m_adjustIQ, &m_applyIQcal,
&m_gainx, &m_gainy, &m_phasex, &m_phasey, &rejectx, &rejecty,
&px, &py, s, &nkhz, &ihsym, &nzap, &slimit, lstrong);
@@ -1176,8 +1294,9 @@ void MainWindow::dataSink(int k)
}
xSignalMeter->setValue(px); // Update the signal meters
ySignalMeter->setValue(py);
+
if(m_monitoring || m_diskData) {
- m_wide_graph_window->dataSink2(s,nkhz,ihsym,m_diskData,lstrong);
+ m_wide_graph_window->dataSink2(s,nkhz,ihsym,m_diskData,lstrong,lstrongSize);
}
if(nadj == 10) {
@@ -1201,16 +1320,16 @@ void MainWindow::dataSink(int k)
//Average over specified number of spectra
if (n==0) {
- for (int i=0; i<NFFT; i++)
+ for (int i=0; i<active_nfft; i++)
splot[i]=s[i];
} else {
- for (int i=0; i<NFFT; i++)
+ for (int i=0; i<active_nfft; i++)
splot[i] += s[i];
}
n++;
if (n>=m_waterfallAvg) {
- for (int i=0; i<NFFT; i++) {
+ for (int i=0; i<active_nfft; i++) {
splot[i] /= n; //Normalize the average
}
@@ -1218,7 +1337,7 @@ void MainWindow::dataSink(int k)
qint64 ms = QDateTime::currentMSecsSinceEpoch() % 86400000;
int ntr1 = (ms/1000) % m_TRperiod;
if((m_diskData && ihsym <= m_waterfallAvg) || (!m_diskData && ntr1<ntrz)) {
- for (int i=0; i<NFFT; i++) {
+ for (int i=0; i<active_nfft; i++) {
splot[i] = 1.e30;
}
}
@@ -1233,7 +1352,7 @@ void MainWindow::dataSink(int k)
setDecoderReady(0);
setNewdat(1);
setNagain(0);
- setNhsym(ihsym);
+ setNhsym(280);
QDateTime t = QDateTime::currentDateTimeUtc();
m_dateTime=t.toString("yyyy-MMM-dd hh:mm");
decode(); //Start the decoder
@@ -1245,7 +1364,7 @@ void MainWindow::dataSink(int k)
setDecoderReady(0);
setNewdat(1);
setNagain(0);
- setNhsym(ihsym);
+ setNhsym(302);
QDateTime t = QDateTime::currentDateTimeUtc();
m_dateTime=t.toString("yyyy-MMM-dd hh:mm");
decode(); //Start the decoder
@@ -1262,7 +1381,7 @@ void MainWindow::dataSink(int k)
watcher2->setFuture(*future2);
}
}
- soundInThread.m_dataSinkBusy=false;
+ soundInThread.m_dataSinkBusy.store (false, std::memory_order_release);
}
/* Generate gaussian random float with mean=0 and std_dev=1 */
@@ -1298,7 +1417,7 @@ float* MainWindow::getDd() const
void MainWindow::savetf2(QString fname, bool xpol)
{
- int npts=2*56*96000;
+ int npts=2*56*g_sampleRate;
if(xpol) npts=2*npts;
FILE* fp = fopen(fname.toUtf8().constData(), "wb");
@@ -1334,15 +1453,15 @@ void MainWindow::savetf2(QString fname, bool xpol)
void MainWindow::getfile(QString fname, bool xpol, int dbDgrd)
{
- setDecoderReady(0);
- int npts = 2 * 56 * 96000;
+ cancel_pending_decode_requests();
+ int npts = 2 * 56 * g_sampleRate;
if (xpol) npts = 2 * npts;
// j indexes dd[], which has 4 channels per pair
int j = 0;
// Clear id[] properly
- memset(id, 0, npts * sizeof(id[0]));
+ memset(id.data(), 0, npts * sizeof(id[0]));
// Open file
FILE* fp = fopen(fname.toUtf8().constData(), "rb");
@@ -1351,6 +1470,11 @@ void MainWindow::getfile(QString fname, bool xpol, int dbDgrd)
return;
}
+ qDebug().noquote() << QString("NEWFILE: nfsample=%1 nrate_active=%2")
+ .arg(active_nfft)
+ .arg(g_sampleRate);
+
+
// Read fcenter
double fcenter = 0.0;
if (fread(&fcenter, sizeof(fcenter), 1, fp) != 1) {
@@ -1360,16 +1484,20 @@ void MainWindow::getfile(QString fname, bool xpol, int dbDgrd)
setFcenter(fcenter);
- // Skip the 8-byte zero padding
- uint64_t pad = 0;
- if (fread(&pad, sizeof(pad), 1, fp) != 1) {
- fclose(fp);
- return;
- }
+ qint64 sampleBytes = static_cast<qint64>(npts) * static_cast<qint64>(sizeof(id[0]));
+ qint64 expectedPaddedSize = static_cast<qint64>(sizeof(fcenter)) +
+ static_cast<qint64>(sizeof(uint64_t)) + sampleBytes;
+ if (QFileInfo {fname}.size() == expectedPaddedSize) {
+ uint64_t pad = 0;
+ if (fread(&pad, sizeof(pad), 1, fp) != 1) {
+ fclose(fp);
+ return;
+ }
+ }
// Read raw samples
- size_t nRead = fread(id, sizeof(id[0]), npts, fp);
+ size_t nRead = fread(id.data(), sizeof(id[0]), npts, fp);
qDebug() << "fread read" << nRead << "samples, expected" << npts;
fclose(fp);
@@ -1424,10 +1552,25 @@ void MainWindow::showStatusMessage(const QString& statusMsg)
void MainWindow::on_actionDeviceSetup_triggered()
{
DevSetup dlg(this);
+
+ connect(&dlg, &DevSetup::sampleRateChanged,
+ this, &MainWindow::onSampleRateChanged);
+
dlg.initDlg();
if (dlg.exec() == QDialog::Accepted)
{
+ if (dlg.m_restartRequired)
+ {
+ m_pendingFs96000 = dlg.m_pendingFs96000;
+ writeSettings();
+ if (m_messages_window) {
+ m_messages_window->setPSKReportingEnabled(m_spot_to_psk_reporter);
+ }
+ return;
+ }
+ m_pendingFs96000 = -1;
+
//
// Apply runtime effects for SoundIn
//
@@ -1439,7 +1582,9 @@ void MainWindow::on_actionDeviceSetup_triggered()
soundInThread.setInputDevice(m_paInDevice);
soundInThread.setNetwork(m_network);
soundInThread.setFadd(m_fAdd);
- soundInThread.setRate(m_fs96000 ? 96000.0 : 95238.1);
+ if (m_fs96000 == 1) soundInThread.setRate(96000.0);
+ else if (m_fs96000 == 0) soundInThread.setRate(95238.1);
+ else if (m_fs96000 == 2) soundInThread.setRate(192000.0);
soundInThread.setSwapIQ(m_IQswap);
soundInThread.setScale(m_dB);
soundInThread.setPort(m_udpPort);
@@ -1483,15 +1628,33 @@ void MainWindow::on_actionDeviceSetup_triggered()
// Save to disk
//
writeSettings();
+ if (m_messages_window) {
+ m_messages_window->setPSKReportingEnabled(m_spot_to_psk_reporter);
+ }
}
}
+void MainWindow::onSampleRateChanged(int newRate)
+{
+ if (!m_wide_graph_window)
+ return;
+
+ if (newRate == 96000 || newRate == 95238)
+ m_wide_graph_window->setFreqSpanLimits(60, 90);
+ else
+ m_wide_graph_window->setFreqSpanLimits(60, 190);
+
+ m_wide_graph_window->updateSpanFromSpinbox();
+}
+
void MainWindow::on_monitorButton_clicked() //Monitor
{
m_monitoring=true;
+ qDebug() << "m_monitoring set to" << m_monitoring << "at" << Q_FUNC_INFO;
soundInThread.setMonitoring(true);
m_diskData=false;
+
}
void MainWindow::on_actionLinrad_triggered() //Linrad palette
{
@@ -1662,6 +1825,12 @@ void MainWindow::createStatusBar() //createStatusBar
lab7->setMinimumSize(QSize(50,10));
lab7->setFrameStyle(QFrame::Panel | QFrame::Sunken);
statusBar()->addWidget(lab7);
+
+ lab8 = new QLabel("QSOs: 0");
+ lab8->setAlignment(Qt::AlignHCenter);
+ lab8->setMinimumSize(QSize(50,10));
+ lab8->setFrameStyle(QFrame::Panel | QFrame::Sunken);
+ statusBar()->addWidget(lab8);
}
void MainWindow::on_tolSpinBox_valueChanged(int i) //tolSpinBox
@@ -1683,7 +1852,7 @@ void MainWindow::closeEvent(QCloseEvent *e)
if (m_gui_timer) m_gui_timer->stop();
m_wide_graph_window->saveSettings();
- QFile quitFile(QDir {m_dataDir}.absoluteFilePath (".quit"));
+ QFile quitFile(m_appDir + "/.quit");
(void)quitFile.open(QFileDevice::ReadWrite);
setQuitID(quitFile.handle());
@@ -1713,6 +1882,7 @@ void MainWindow::closeEvent(QCloseEvent *e)
void MainWindow::on_stopButton_clicked() //stopButton
{
m_monitoring=false;
+ qDebug() << "m_monitoring set to" << m_monitoring << "at" << Q_FUNC_INFO;
soundInThread.setMonitoring(m_monitoring);
m_loopall=false;
}
@@ -1757,6 +1927,16 @@ void MainWindow::on_actionQ65_Sensitivity_in_MAP65_3_0_triggered()
QDesktopServices::openUrl (QUrl {"https://wsjt.sourceforge.io/Q65_Sensitivity_in_MAP65.pdf"});
}
+void MainWindow::on_actionCopyright_Notice_triggered()
+{
+ MessageBox::warning_message (this, copyright_notice_text ());
+}
+
+void MainWindow::on_actionTrademark_Policy_triggered()
+{
+ QDesktopServices::openUrl (QUrl {"https://wsjtx.github.io/wsjtx/trademark.html"});
+}
+
void MainWindow::on_actionAstro_Data_triggered() //Display Astro
{
if (m_astro_window ) m_astro_window->show();
@@ -1780,6 +1960,8 @@ void MainWindow::on_actionMessages_triggered() //Display Messages
void MainWindow::on_actionOpen_triggered() //Open File
{
m_monitoring=false;
+ qDebug() << "m_monitoring set to" << m_monitoring << "at" << Q_FUNC_INFO;
+
soundInThread.setMonitoring(m_monitoring);
// Wipe waterfall callsign overlay so stale labels from the previous
// file (or live capture) don't linger over the new decode.
@@ -1851,7 +2033,7 @@ void MainWindow::on_actionOpen_next_in_directory_triggered() //Open Next
*future1 = QtConcurrent::run([this](QString fname, bool xpol, int dbDgrd) {
this->getfile(fname, xpol, dbDgrd);
}, fname, m_xpol, dbDgrd);
- // qDebug() << "MainWindow::on_actionOpen_next_in_directory_triggered Reading wav file: " << m_path;
+ qDebug() << "MainWindow::on_actionOpen_next_in_directory_triggered Reading wav file: " << m_path;
watcher1->setFuture(*future1);
return;
}
@@ -1874,8 +2056,9 @@ void MainWindow::diskDat() //diskDat()
setFcenter(m_wide_graph_window->m_dForceCenterFreq);
}
- if(m_fs96000) hsym=2048.0*96000.0/11025.0; //Samples per JT65 half-symbol
- if(!m_fs96000) hsym=2048.0*95238.1/11025.0;
+ hsym=2048.0*96000.0/11025.0; //Samples per JT65 half-symbol if SR = 96000
+ if(m_fs96000 == 0) hsym=2048.0*95238.1/11025.0; // Samples per JT65 half-symbol if SR = 95238.1
+ else if(m_fs96000 == 2) hsym=2048.0*192000.0/11025.0; //Samples per JT65 half-symbol if SR = 192000
for(int i=0; i<304; i++) { // Do the half-symbol FFTs
int k = i*hsym + 2048.5;
dataSink(k);
@@ -1915,6 +2098,14 @@ void MainWindow::on_actionErase_Band_Map_and_Messages_triggered()
{
m_band_map_window->setText("");
m_messages_window->setText("","");
+ // m_messagesText/m_bandmapText accumulate across decode cycles and are
+ // only reset when a "!" line arrives (processStdOut). Without clearing
+ // them here too, the next <EarlyFinished>/<DecodeFinished> redisplay
+ // (or a cycle with no fresh decodes) repaints the stale pre-erase text
+ // right back into the windows.
+ m_messagesText.clear();
+ m_bandmapText.clear();
+ m_widebandDecode = false;
m_map65RxLog |= 4;
}
@@ -1954,6 +2145,11 @@ void MainWindow::on_actionAggressive_Deep_Search_triggered() //Aggressive DS
m_ndepth=2;
}
+void MainWindow::on_actionFull_Deep_Search_triggered() //Full DS
+{
+ m_ndepth=3;
+}
+
void MainWindow::on_actionNone_triggered() //Save None
{
m_saveAll=false;
@@ -2005,6 +2201,7 @@ void MainWindow::freezeDecode(int n) //freezeDecode()
if(!m_decoderBusy) {
setNagain(1);
setNewdat(0);
+ set_manual_decode_flag(1);
decode();
}
}
@@ -2035,7 +2232,6 @@ void MainWindow::decode() //decode()
if(m_diskData) {
if(m_myGrid.trimmed().length()>=6) {
setNdiskdat(1);
- setNagain(0);
int i0=m_path.indexOf(".tf2");
if(i0<0) i0=m_path.indexOf(".iq");
if(i0>0) {
@@ -2087,8 +2283,10 @@ void MainWindow::decode() //decode()
if(getNutc() < m_nutc0) m_map65RxLog |= 1; //Date and Time to map65_rx.log
m_nutc0=getNutc();
setMap65RxLog(m_map65RxLog);
- setNfsample(96000);
- if(!m_fs96000) setNfsample(95238);
+ if(m_fs96000 == 1) setNfsample(96000);
+ if(m_fs96000 == 0) setNfsample(95238);
+ else if(m_fs96000 == 2) setNfsample(192000);
+ // qDebug() << "MainWindow::decode setting nfsample to " << m_fs96000;
setNxpol(0);
if(m_xpol) setNxpol(1);
setNmode(10*m_modeQ65 + m_modeJT65);
@@ -2110,9 +2308,8 @@ QString hgrid = (ui->dxGridEntry->text() + " ").mid(0, 6);
setJunk1(1234);
setJunk2(5678);
- setNagain(0); //added 12-30-25 to agree with legacy
if (!m_diskData) setNdiskdat(0); //added 12-30-25 to agree with legacy
- setDecoderReady(1);
+ publish_decode_request();
m_map65RxLog=0;
m_call3Modified=false;
// qDebug() << QDateTime::currentMSecsSinceEpoch() << "finished MainWindow::decode()";
@@ -2240,6 +2437,8 @@ void MainWindow::guiUpdate()
if(bTune0 and !bTune) {
btxok=false;
m_monitoring=bMonitoring0;
+ // qDebug() << "m_monitoring set to" << m_monitoring << "at" << Q_FUNC_INFO;
+
soundInThread.setMonitoring(m_monitoring);
}
if(bTune and !bTune0) bMonitoring0=m_monitoring;
@@ -2292,7 +2491,7 @@ void MainWindow::guiUpdate()
int mode65=m_mode65;
int ntxFreq=1000;
double samfac=1.0;
- qDebug() << mode65 << samfac;
+ // qDebug() << mode65 << samfac;
if(m_modeTx=="JT65") {
gen65_(message,&mode65,&samfac,&nsendingsh,msgsent,iwave,
&nwave,len1,len1);
@@ -2330,6 +2529,8 @@ void MainWindow::guiUpdate()
xSignalMeter->setValue(0);
ySignalMeter->setValue(0);
m_monitoring=false;
+ // qDebug() << "m_monitoring set to" << m_monitoring << "at" << Q_FUNC_INFO;
+
soundInThread.setMonitoring(false);
btxok=true;
m_transmitting=true;
@@ -2369,6 +2570,8 @@ void MainWindow::guiUpdate()
m_wide_graph_window->enableSetRxHardware(true);
if(m_auto) {
m_monitoring=true;
+ // qDebug() << "m_monitoring set to" << m_monitoring << "at" << Q_FUNC_INFO;
+
soundInThread.setMonitoring(m_monitoring);
}
}
@@ -2653,14 +2856,7 @@ void MainWindow::genStdMsgs(QString rpt) //genStdMsgs()
QString MainWindow::call3Path() const
{
- QString writablePath = QDir {m_dataDir}.absoluteFilePath("CALL3.TXT");
- if (!QFile::exists(writablePath)) {
- QString bundledPath = QDir {m_appDir}.absoluteFilePath("CALL3.TXT");
- if (QFile::exists(bundledPath)) {
- QFile::copy(bundledPath, writablePath);
- }
- }
- return writablePath;
+ return ensureMap65RuntimeFile(m_appDir, m_installedDataDir, m_dataDir, "CALL3.TXT");
}
void MainWindow::lookup() //lookup()
@@ -3075,8 +3271,7 @@ void MainWindow::on_actionFUNcube_Dongle_triggered()
void MainWindow::on_actionEdit_wsjt_log_triggered()
{
- proc_editor.start (QDir::toNativeSeparators (m_editorCommand),
- {QDir::toNativeSeparators (QDir {m_dataDir}.absoluteFilePath ("wsjt.log")), });
+ proc_editor.start (QDir::toNativeSeparators (m_editorCommand), {QDir::toNativeSeparators (m_appDir + "/wsjt.log"), });
}
void MainWindow::on_actionTx_Tune_triggered()
@@ -3121,7 +3316,7 @@ void MainWindow::read_log()
// Update "m_worked" by reading wsjtx.log
m_worked.clear(); //Start from scratch
QFile f("wsjtx.log");
-// qDebug() << "MainWindow::read_log File open result:" << f.open(QFileDevice::ReadOnly);
+ qDebug() << "MainWindow::read_log File open result:" << f.open(QFileDevice::ReadOnly);
if(f.isOpen()) {
QTextStream in(&f);
QString line,callsign;
diff --git a/map65/mainwindow.h b/map65/mainwindow.h
index d60e1239..0262e0ac 100644
--- a/map65/mainwindow.h
+++ b/map65/mainwindow.h
@@ -12,11 +12,11 @@
#include "soundout.h"
#include "signalmeter.h"
#include "commons.h"
+#include "map65_decode_display_filter.h"
#include "sleep.h"
#include <QtConcurrent/QtConcurrent>
#include <QByteArray>
-#define NFFT 32768
#define NSMAX 5760000
@@ -53,13 +53,16 @@ public:
float* getDd() const;
std::thread stdoutReaderThread;
std::atomic<bool> stdoutReaderStop {false};
+ void writeSettings();
bool m_network;
int m_pttPortNumber = 0;
QString m_pttPath;
QString m_appDir;
+ QString m_installedDataDir;
QString m_dataDir;
+ QString m_eclipseFile;
QString m_settings_filename;
qint32 m_nDevIn;
qint32 m_nDevOut;
@@ -84,7 +87,8 @@ public:
bool m_xpol;
bool m_xpolx;
- bool m_fs96000;
+ int m_fs96000;
+ int m_pendingFs96000 {-1};
bool m_IQswap;
bool m_initIQplus;
bool m_bIQxt;
@@ -139,6 +143,8 @@ private slots:
void on_actionQSG_Q65_triggered();
void on_actionQSG_MAP65_v3_triggered();
void on_actionQ65_Sensitivity_in_MAP65_3_0_triggered();
+ void on_actionCopyright_Notice_triggered();
+ void on_actionTrademark_Policy_triggered();
void on_actionWide_Waterfall_triggered();
void on_actionBand_Map_triggered();
void on_actionMessages_triggered();
@@ -154,6 +160,7 @@ private slots:
void on_actionNo_Deep_Search_triggered();
void on_actionNormal_Deep_Search_triggered();
void on_actionAggressive_Deep_Search_triggered();
+ void on_actionFull_Deep_Search_triggered();
void on_actionNone_triggered();
void on_actionSave_all_triggered();
void on_actionKeyboard_shortcuts_triggered();
@@ -202,12 +209,13 @@ private slots:
void on_actionQ65D_triggered();
void on_actionQ65E_triggered();
void on_pbTxMode_clicked();
+ void onSampleRateChanged(int newRate);
private:
+ QString call3Path() const;
virtual void keyPressEvent (QKeyEvent *) override;
virtual bool eventFilter (QObject *, QEvent *) override;
virtual void closeEvent (QCloseEvent *) override;
- QString call3Path() const;
QScopedPointer<Astro> m_astro_window;
QScopedPointer<BandMap> m_band_map_window;
@@ -263,6 +271,7 @@ private:
QString m_pbAutoOn_style;
QString m_messagesText;
QString m_bandmapText;
+ Map65DecodeDisplayFilter m_decodeDisplayFilter;
QString m_hisCall;
QString m_hisGrid;
QString m_palette;
@@ -290,6 +299,7 @@ private:
QLabel* lab5;
QLabel* lab6;
QLabel* lab7;
+ QLabel* lab8;
QMessageBox msgBox0;
@@ -323,7 +333,6 @@ private:
//---------------------------------------------------- private functions
void readSettings();
- void writeSettings();
void createStatusBar();
void updateStatusBar();
void msgBox(QString t);
@@ -343,6 +352,10 @@ private:
void createMessagesWindow();
};
+extern int g_sampleRate;
+extern int active_nfft;
+extern std::vector<qint16> id;
+
extern void getDev(int* numDevices,char hostAPI_DeviceName[][50],
int minChan[], int maxChan[],
int minSpeed[], int maxSpeed[]);
@@ -350,7 +363,7 @@ extern void getDev(int* numDevices,char hostAPI_DeviceName[][50],
extern "C" {
//----------------------------------------------------- C and Fortran routines
void symspec_(int* k, int* nxpol, int* ndiskdat, int* nb,
- int* m_NBslider, int* idphi, int* nfsample,
+ int* m_NBslider, int* idphi,
int* iqadjust, int* iqapply, float* gainx, float* gainy,
float* phasex, float* phasey, float* rejectx, float* rejecty,
float* px, float* py, float s[], int* nkhz, int* nhsym,
diff --git a/map65/mainwindow.ui b/map65/mainwindow.ui
index 1f6b27f6..fb09f4e1 100644
--- a/map65/mainwindow.ui
+++ b/map65/mainwindow.ui
@@ -1382,6 +1382,7 @@ p, li { white-space: pre-wrap; }
<addaction name="actionNo_Deep_Search"/>
<addaction name="actionNormal_Deep_Search"/>
<addaction name="actionAggressive_Deep_Search"/>
+ <addaction name="actionFull_Deep_Search"/>
<addaction name="separator"/>
</widget>
<widget class="QMenu" name="menuSave">
@@ -1403,6 +1404,10 @@ p, li { white-space: pre-wrap; }
<addaction name="actionKeyboard_shortcuts"/>
<addaction name="actionSpecial_mouse_commands"/>
<addaction name="actionAvailable_suffixes_and_add_on_prefixes"/>
+ <addaction name="separator"/>
+ <addaction name="actionCopyright_Notice"/>
+ <addaction name="actionTrademark_Policy"/>
+ <addaction name="separator"/>
<addaction name="actionAbout"/>
</widget>
<widget class="QMenu" name="menuMode">
@@ -1453,12 +1458,22 @@ p, li { white-space: pre-wrap; }
</action>
<action name="actionAbout">
<property name="text">
- <string>About MAP65</string>
+ <string>About MAP65™</string>
</property>
<property name="shortcut">
<string>Ctrl+F1</string>
</property>
</action>
+ <action name="actionCopyright_Notice">
+ <property name="text">
+ <string>Copyright notice</string>
+ </property>
+ </action>
+ <action name="actionTrademark_Policy">
+ <property name="text">
+ <string>Trademark policy</string>
+ </property>
+ </action>
<action name="actionAstro_Data">
<property name="text">
<string>Astro Data</string>
@@ -1696,6 +1711,14 @@ p, li { white-space: pre-wrap; }
<string>Aggressive Deep Search</string>
</property>
</action>
+ <action name="actionFull_Deep_Search">
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ <property name="text">
+ <string>Full Deep Search</string>
+ </property>
+ </action>
<action name="actionNone">
<property name="checkable">
<bool>true</bool>
@@ -1972,7 +1995,7 @@ p, li { white-space: pre-wrap; }
<customwidget>
<class>DisplayText</class>
<extends>QTextBrowser</extends>
- <header>widgets/displaytext.h</header>
+ <header>displaytext.h</header>
</customwidget>
</customwidgets>
<resources/>
diff --git a/map65/map65.pro b/map65/map65.pro
deleted file mode 100644
index b71140d6..00000000
--- a/map65/map65.pro
+++ /dev/null
@@ -1,73 +0,0 @@
-#-------------------------------------------------
-#
-# Project created by QtCreator 2011-07-07T08:39:24
-#
-#-------------------------------------------------
-
-QT += core gui network
-greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
-CONFIG += thread
-#CONFIG += console
-
-TARGET = map65
-VERSION = 2.5.0
-TEMPLATE = app
-DEFINES = QT5
-DESTDIR = /MAP65_2.9
-
-F90 = gfortran
-gfortran.output = ${QMAKE_FILE_BASE}.o
-gfortran.commands = $$F90 -c -O2 -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
-gfortran.input = F90_SOURCES
-QMAKE_EXTRA_COMPILERS += gfortran
-
-win32 {
-DEFINES = WIN32
-}
-
-unix {
-DEFINES = UNIX
-}
-
-SOURCES += main.cpp mainwindow.cpp plotter.cpp about.cpp \
- soundin.cpp soundout.cpp devsetup.cpp \
- widegraph.cpp getfile.cpp messages.cpp bandmap.cpp \
- astro.cpp displaytext.cpp getdev.cpp \
- txtune.cpp meterwidget.cpp signalmeter.cpp \
- cqdatasender.cpp liveCQSender.cpp Radio.cpp \
- ../Network/PSKReporter.cpp ../Network/PSKReporterIPFIX.cpp
-
-win32 {
-SOURCES += set570.cpp
-}
-
-HEADERS += mainwindow.h plotter.h soundin.h soundout.h \
- about.h devsetup.h widegraph.h getfile.h messages.h \
- bandmap.h commons.h sleep.h astro.h displaytext.h \
- txtune.h meterwidget.h signalmeter.h cqdatasender.h \
- liveCQSender.hpp Radio.hpp ../Network/PSKReporter.hpp ../Network/PSKReporterIPFIX.hpp
-
-FORMS += mainwindow.ui about.ui devsetup.ui widegraph.ui \
- messages.ui bandmap.ui astro.ui \
- txtune.ui
-
-RC_FILE = map65.rc
-
-unix {
-LIBS += ../map65/libm65/libm65.a
-LIBS += -lfftw3f -lportaudio -lgfortran
-#LIBS +- -lusb
-}
-
-win32 {
-LIBS += ../map65/libm65/libm65.a
-LIBS += ../map65/libfftw3f_win.a
-LIBS += ../map65/palir-02.dll
-LIBS += libwsock32
-#LIBS += C:/MinGW/lib/libf95.a
-LIBS += -lgfortran
-#LIBS += -lusb
-LIBS += ../map65/libusb.a
-#LIBS += -lQt5Concurrent
-#LIBS += c:\JTSDK-QT\Qt5\Tools\mingw48_32\i686-w64-mingw32\lib\libmingwex.a
-}
diff --git a/map65/map65_decode_display_filter.cpp b/map65/map65_decode_display_filter.cpp
new file mode 100644
index 00000000..107001d4
--- /dev/null
+++ b/map65/map65_decode_display_filter.cpp
@@ -0,0 +1,95 @@
+#include "map65_decode_display_filter.h"
+
+#include <QtGlobal>
+
+namespace
+{
+QString const passMarker {"<Map65DecodePass>"};
+constexpr int duplicateFrequencyToleranceHz = 20;
+}
+
+bool Map65DecodeDisplayFilter::handleControlLine(QString const& line)
+{
+ if (!line.startsWith(passMarker)) return false;
+
+ QString const pass = line.mid(passMarker.size()).trimmed().toLower();
+ if (pass == "early")
+ {
+ pass_ = Pass::Early;
+ earlyDecodes_.clear();
+ }
+ else if (pass == "final") pass_ = Pass::Final;
+ else if (pass == "manual") pass_ = Pass::Manual;
+ else if (pass == "disk") pass_ = Pass::Disk;
+ else pass_ = Pass::Unknown;
+
+ return true;
+}
+
+bool Map65DecodeDisplayFilter::shouldDisplay(QString const& decodeLine)
+{
+ if (pass_ == Pass::Manual || pass_ == Pass::Disk || pass_ == Pass::Unknown)
+ return true;
+
+ Identity identity;
+ if (!parseIdentity(decodeLine, &identity)) return true;
+
+ for (auto const& earlyDecode : earlyDecodes_)
+ {
+ if (pass_ == Pass::Final && matches(earlyDecode, identity)) return false;
+ }
+
+ if (pass_ == Pass::Early) earlyDecodes_.append(identity);
+ return true;
+}
+
+void Map65DecodeDisplayFilter::completeEarlyPass()
+{
+ pass_ = Pass::Unknown;
+}
+
+void Map65DecodeDisplayFilter::completeCycle()
+{
+ pass_ = Pass::Unknown;
+ earlyDecodes_.clear();
+}
+
+bool Map65DecodeDisplayFilter::parseIdentity(QString const& input, Identity * identity)
+{
+ QString line = input;
+ if (line.startsWith('!')) line.remove(0, 1);
+ if (line.size() < 53) return false;
+
+ bool khzOk = false;
+ bool dfOk = false;
+ bool utcOk = false;
+ int const khz = line.mid(0, 3).trimmed().toInt(&khzOk);
+ int const df = line.mid(3, 5).trimmed().toInt(&dfOk);
+ int const utc = line.mid(12, 6).trimmed().toInt(&utcOk);
+ int const hour = utc / 100;
+ int const minute = utc % 100;
+ if (!khzOk || !dfOk || !utcOk || hour < 0 || hour > 23
+ || minute < 0 || minute > 59)
+ return false;
+
+ QString const separator = line.mid(28, 3);
+ if (separator != " : " && separator != " # ") return false;
+ bool const q65 = separator == " : ";
+ int const messageLength = q65 ? 28 : 22;
+ if (line.size() < 31 + messageLength) return false;
+ QString const message = line.mid(31, messageLength).simplified().toUpper();
+ if (message.isEmpty()) return false;
+
+ identity->q65 = q65;
+ identity->utc = utc;
+ identity->frequencyHz = 1000 * khz + df;
+ identity->message = message;
+ return true;
+}
+
+bool Map65DecodeDisplayFilter::matches(Identity const& left, Identity const& right)
+{
+ return left.q65 == right.q65 && left.utc == right.utc
+ && left.message == right.message
+ && qAbs(left.frequencyHz - right.frequencyHz) <= duplicateFrequencyToleranceHz;
+}
diff --git a/map65/map65_decode_display_filter.h b/map65/map65_decode_display_filter.h
new file mode 100644
index 00000000..72130a07
--- /dev/null
+++ b/map65/map65_decode_display_filter.h
@@ -0,0 +1,40 @@
+#ifndef MAP65_DECODE_DISPLAY_FILTER_H
+#define MAP65_DECODE_DISPLAY_FILTER_H
+
+#include <QString>
+#include <QVector>
+
+class Map65DecodeDisplayFilter
+{
+public:
+ bool handleControlLine(QString const& line);
+ bool shouldDisplay(QString const& decodeLine);
+ void completeEarlyPass();
+ void completeCycle();
+
+private:
+ enum class Pass
+ {
+ Unknown,
+ Early,
+ Final,
+ Manual,
+ Disk
+ };
+
+ struct Identity
+ {
+ bool q65;
+ int utc;
+ int frequencyHz;
+ QString message;
+ };
+
+ static bool parseIdentity(QString const& line, Identity * identity);
+ static bool matches(Identity const& left, Identity const& right);
+
+ Pass pass_ {Pass::Unknown};
+ QVector<Identity> earlyDecodes_;
+};
+
+#endif
diff --git a/map65/map65_decode_lifecycle.txt b/map65/map65_decode_lifecycle.txt
index d3aaba57..95296fbb 100644
--- a/map65/map65_decode_lifecycle.txt
+++ b/map65/map65_decode_lifecycle.txt
@@ -1,385 +1,68 @@
-/*
-===============================================================================
- MAP65 DECODE LIFECYCLE — MODERNIZED AND LEGACY‑ACCURATE
-===============================================================================
-
- This document describes the sequencing rules for disk and live-input decoding
- in modern MAP65. The goal is deterministic, race‑free behavior that matches
- the legacy MAP65 decode pipeline while eliminating timing-dependent behavior.
-
--------------------------------------------------------------------------------
- OVERVIEW
--------------------------------------------------------------------------------
- A decode cycle consists of:
- 1. Preparing input data (disk or live)
- 2. Preparing decode parameters (C++ decode())
- 3. Triggering the Fortran decoder loop (newdat + decoder_ready)
- 4. Receiving <DecodeFinished> from stdout
- 5. Detecting decoder silence (idle timer)
- 6. Clearing busy and optionally auto‑advancing
-
- The Fortran decoder loop runs ONLY when:
- decoder_ready == 1 AND newdat == 1
-
--------------------------------------------------------------------------------
- STATE FLAGS
--------------------------------------------------------------------------------
- newdat:
- - Set to 1 by the caller (disk or live) BEFORE calling decode().
- - Indicates that new data is ready for decoding.
- - Cleared internally by the decoder after each pass.
- - Only one pass per file/minute is expected (legacy behavior).
-
- decoder_ready:
- - Set to 0 BEFORE calling decode() (disk or live).
- - Set to 1 at the END of decode() after all parameters are prepared.
- - Prevents the decoder loop from running early with stale parameters.
-
- decoderBusy:
- - Set to true ONLY inside decode().
- - Set to false ONLY in the idle timer after <DecodeFinished> + silence.
- - Reflects actual decoder activity, not file loading.
-
--------------------------------------------------------------------------------
- DISK INPUT SEQUENCE
--------------------------------------------------------------------------------
- getfile():
- setDecoderReady(0); // block decoder loop
- load file data
- setNewdat(1); // legacy behavior
- decode(); // prepares parameters, sets decoder_ready=1
-
--------------------------------------------------------------------------------
- LIVE INPUT SEQUENCE
--------------------------------------------------------------------------------
- dataSink():
- when a full 60s block is ready:
- setDecoderReady(0); // block decoder loop
- setNewdat(1); // legacy behavior
- decode(); // prepares parameters, sets decoder_ready=1
-
--------------------------------------------------------------------------------
- DECODE() SEQUENCE
--------------------------------------------------------------------------------
- decode():
- decodeBusy(true); // decoder is now officially active
- prepare all decode parameters (nfa, nfb, nfshift, mode, etc.)
- setDecoderReady(1); // allow decoder loop to run
- // newdat was already set by caller
-
--------------------------------------------------------------------------------
- FORTRAN LOOP
--------------------------------------------------------------------------------
- do while (.not. stop_m65)
- if (decoder_ready .and. newdat .ne. 0) call m65a()
- call sleep_msec(50)
- end do
-
--------------------------------------------------------------------------------
- STDOUT PROCESSING
--------------------------------------------------------------------------------
- processStdOut():
- On "<DecodeFinished>":
- m_decodeFinishedCount++
- // no second pass expected (legacy behavior)
-
--------------------------------------------------------------------------------
- IDLE TIMER
--------------------------------------------------------------------------------
- Idle timer fires when decoder stdout is silent:
- if (m_decodeFinishedCount == 0)
- ignore (decoder not finished yet)
-
- decodeBusy(false); // decoder is done
-
- if (m_loopall && m_diskData)
- on_actionOpen_next_in_directory_triggered();
-
--------------------------------------------------------------------------------
- NOTES
--------------------------------------------------------------------------------
- - Only ONE decode pass per file/minute is expected (legacy MAP65 behavior).
- - No second-pass logic is required.
- - No failsafe timer is required.
- - This lifecycle eliminates all timing races present in earlier versions.
-===============================================================================
-*/
-/*
-===============================================================================
- LIVE MODE VS DISK MODE — BUSY‑CLEARING RULES
-===============================================================================
-
- Modern MAP65 supports two fundamentally different input modes:
-
- 1. Disk mode (file-based decoding)
- 2. Live mode (real-time network or audio decoding)
-
- These modes differ in how decoder stdout behaves, and therefore require
- different rules for clearing the decoderBusy flag.
-
--------------------------------------------------------------------------------
- DISK MODE (FILE INPUT)
--------------------------------------------------------------------------------
- - Decoder stdout is finite.
- - After <DecodeFinished>, the decoder emits a tail of late decodes,
- bandmap lines, and summary lines.
- - Once this tail completes, stdout becomes silent.
- - The idle timer detects this silence (~2500 ms) and clears busy.
-
- Correct behavior in disk mode:
- Wait for <DecodeFinished>
- THEN wait for ~2500 ms of silence
- THEN clear busy
- THEN auto-advance (if loopall is enabled)
-
- This reproduces legacy MAP65’s blocking behavior exactly.
-
--------------------------------------------------------------------------------
- LIVE MODE (REAL-TIME INPUT)
--------------------------------------------------------------------------------
- In live mode, the decoder *never* becomes silent:
-
- - The decoder emits continuous tracking lines (e.g., "@1296.xxx") every
- 120 ms throughout the entire minute.
- - These lines continue even after <DecodeFinished>.
- - Therefore, the idle timer will NEVER observe a 2500 ms silent period.
- - If busy were cleared only by the idle timer, it would remain stuck TRUE
- forever, causing the GUI to remain greyed out.
-
- To match legacy behavior and maintain correct GUI state, MAP65 must clear
- busy *immediately* upon receiving <DecodeFinished> in live mode.
-
- Correct behavior in live mode:
- On <DecodeFinished>:
- clear busy immediately
- (do NOT wait for silence)
- (do NOT auto-advance)
-
- This mirrors legacy MAP65, where the blocking read returned immediately
- after <DecodeFinished> during live decoding.
-
--------------------------------------------------------------------------------
- SUMMARY OF BUSY‑CLEARING RULES
--------------------------------------------------------------------------------
- Disk mode:
- <DecodeFinished> → wait for silence → busy = false → auto-advance
-
- Live mode:
- <DecodeFinished> → busy = false immediately (no idle timer)
-
--------------------------------------------------------------------------------
- RATIONALE
--------------------------------------------------------------------------------
- - Disk mode produces finite stdout; silence detection is meaningful.
- - Live mode produces continuous stdout; silence detection is impossible.
- - Legacy MAP65 implicitly handled both cases correctly via blocking I/O.
- - Modern MAP65 must explicitly differentiate the two modes to reproduce
- legacy behavior and avoid GUI lockout.
-
-===============================================================================
-*/
-
-/*
-===============================================================================
- WHY LEGACY MAP65 DID NOT NEED AN IDLE TIMER
-===============================================================================
-
- Legacy MAP65 used a synchronous, blocking I/O model for running the decoder.
- This architecture *implicitly* waited for the decoder to finish producing ALL
- stdout before advancing to the next file. No timers, heuristics, or silence
- detection were required.
-
--------------------------------------------------------------------------------
- LEGACY ARCHITECTURE (SYNCHRONOUS / BLOCKING)
--------------------------------------------------------------------------------
- - The decoder was launched as a child process.
- - MAP65 read stdout using a blocking read loop.
- - The read call did not return until the decoder flushed all output.
- - The program could not proceed until stdout was fully drained.
- - <DecodeFinished> was just a marker, not a signal to advance.
- - Late decodes, bandmap lines, and summary lines always arrived before the
- blocking read returned.
-
- Result:
- Legacy MAP65 *automatically* waited long enough to capture all decodes,
- including those emitted 1–3 seconds after <DecodeFinished>.
-
--------------------------------------------------------------------------------
- MODERN ARCHITECTURE (ASYNCHRONOUS / EVENT-DRIVEN)
--------------------------------------------------------------------------------
- Modern MAP65 uses Qt's QProcess, which delivers decoder stdout asynchronously:
-
- - stdout arrives in bursts via readyReadStandardOutput() signals
- - the GUI thread continues running while the decoder works
- - <DecodeFinished> does NOT mean the decoder is done talking
- - late decodes and summary lines may arrive up to ~2500 ms later
- - the decoder does not close stdout between passes or files
-
- Because the program is no longer blocked waiting for stdout, MAP65 must
- explicitly detect when the decoder has gone silent.
-
--------------------------------------------------------------------------------
- WHY AN IDLE TIMER IS REQUIRED
--------------------------------------------------------------------------------
- In the asynchronous model, MAP65 must decide when the decoder is "done."
- The correct criterion is:
-
- <DecodeFinished> has been seen
- AND
- no stdout has arrived for ~2500 ms
-
- This silence window reproduces the behavior of legacy MAP65's blocking read:
- it ensures that all late decodes, bandmap lines, and summary lines have been
- received before auto-advancing.
-
--------------------------------------------------------------------------------
- SUMMARY
--------------------------------------------------------------------------------
- Legacy MAP65:
- - Blocking I/O naturally waited for all decoder output.
- - No idle timer needed.
-
- Modern MAP65:
- - Asynchronous I/O requires explicit silence detection.
- - A 2500 ms idle window faithfully reproduces legacy behavior.
-
-===============================================================================
-*/
-/*
-===============================================================================
- FILE INPUT MODE DECODER OUTPUT TIMING DIAGRAM
-===============================================================================
-
- This diagram illustrates the typical sequence of decoder stdout during a
- single decode pass when using file input. It shows why legacy MAP65 naturally
- waited for all output, and why modern MAP65 must explicitly wait for a period
- of silence.
-
- Time flows left → right.
-
--------------------------------------------------------------------------------
- LEGEND
--------------------------------------------------------------------------------
- |====| Decoder producing stdout
- <DF> "<DecodeFinished>" marker
- .... Silence (no stdout)
- [2500 ms silence] Idle timer threshold in modern MAP65
-
--------------------------------------------------------------------------------
- TYPICAL DECODER STDOUT TIMELINE
--------------------------------------------------------------------------------
-
- QuickDecode FullDecode Post-Processing
- (fast) (heavy FFT) (late decodes, bandmap, summary)
- |====================|====================|====================|
- ^ ^ ^ ^
- | | | |
- Start <DF> Late output Final flush
- continues then silence
-
- 0 ms ~800–1200 ms ~1200–2200 ms ~2200–2500+ ms
- ---------------------------------------------------------------------------→ time
-
- After <DecodeFinished>, the decoder may continue emitting:
- - late decodes
- - bandmap lines
- - candidate summaries
- - sync statistics
- - final housekeeping output
-
- This tail can last up to ~2500 ms depending on CPU speed and decode load.
-
--------------------------------------------------------------------------------
- LEGACY MAP65 BEHAVIOR (BLOCKING I/O)
--------------------------------------------------------------------------------
- Legacy MAP65 used a blocking read loop:
- - It did not return until ALL stdout was flushed.
- - It implicitly waited for the entire tail of output.
- - It always captured all decodes.
-
- No idle timer was needed.
-
--------------------------------------------------------------------------------
- MODERN MAP65 BEHAVIOR (ASYNCHRONOUS I/O)
--------------------------------------------------------------------------------
- Modern MAP65 receives stdout via Qt signals:
- - <DecodeFinished> does NOT mean the decoder is done.
- - Late output arrives asynchronously after <DF>.
- - The GUI thread continues running.
- - MAP65 must explicitly detect when the decoder has gone silent.
-
- Correct behavior:
- - Wait for <DecodeFinished>
- - THEN wait for ~2500 ms of silence
- - THEN auto-advance
-
- This reproduces legacy behavior exactly.
-
-===============================================================================
-*/
-/*
-===============================================================================
- LIVE MODE TIMING DIAGRAM (REAL‑TIME NETWORK / AUDIO INPUT)
-===============================================================================
-
- This diagram illustrates why live-mode decoding cannot rely on the idle timer
- to detect decoder completion. Unlike disk-mode decoding, live-mode produces
- continuous stdout throughout the entire minute, even AFTER <DecodeFinished>.
-
- Time flows left → right.
-
--------------------------------------------------------------------------------
- LEGEND
--------------------------------------------------------------------------------
- |====| Decoder producing stdout (continuous live tracking output)
- <DF> "<DecodeFinished>" marker for early or full decode
- .... (Never occurs in live mode — no silence)
- [X] Idle timer never fires in live mode
-
--------------------------------------------------------------------------------
- LIVE-MODE STDOUT TIMELINE (52s + 56s DECODE CYCLES)
--------------------------------------------------------------------------------
-
- Live tracking output (continuous @1296.xxx lines every ~120 ms)
- |=========================================================================|
- ^ ^
- | |
- Start of minute End of minute
-
- Early Decode (~52s) Full Decode (~56s)
- |====================| |====================|
- ^ ^ ^ ^
- | | | |
- Trigger <DF> Trigger <DF>
- (ihsym>=280) EarlyFinished (ihsym>=302) DecodeFinished
-
- ---------------------------------------------------------------------------→ time
-
- IMPORTANT:
- - Live tracking output continues uninterrupted across BOTH decode cycles.
- - There is NO period of silence after <DecodeFinished>.
- - Therefore the idle timer NEVER observes a 2500 ms quiet window.
- - If busy were cleared only by the idle timer, it would remain TRUE forever.
-
--------------------------------------------------------------------------------
- CORRECT LIVE-MODE BEHAVIOR
--------------------------------------------------------------------------------
- On <DecodeFinished> (early or full):
- - Clear busy IMMEDIATELY.
- - Do NOT wait for silence (there is none).
- - Do NOT auto-advance (live mode never advances files).
-
- This matches legacy MAP65, where the blocking read returned immediately after
- <DecodeFinished> during live decoding.
-
--------------------------------------------------------------------------------
- SUMMARY
--------------------------------------------------------------------------------
- Disk mode:
- <DecodeFinished> → wait for silence → busy=false → auto-advance
-
- Live mode:
- <DecodeFinished> → busy=false immediately (no idle timer)
-
-===============================================================================
-*/
+MAP65 decode request lifecycle
+==============================
+
+Parameter ownership
+-------------------
+The C-facing getters and setters in npar_ptrs_mod operate on a draft
+parameter record. MainWindow::decode prepares that record, then calls
+publish_decode_request. Publication copies the complete record into a FIFO
+queue and assigns it a monotonically increasing request ID.
+
+A dedicated mutex protects draft access, publication, cancellation and
+claiming. It is separate from g_fortran_decode_mutex, which is held for the
+decoder thread's entire lifetime.
+
+run_m65 claims one queued request before calling m65a. Claiming removes that
+request from the queue and copies its parameters into decoder-owned active
+storage. All decoder routines use those active parameters until the call
+returns. GUI updates can prepare and publish subsequent requests without
+changing the active pass.
+
+The live waterfall reads the draft center frequency through get_fcenter.
+Runtime sample-rate/FFT sizes and the working directory are initialized
+before decoding and are not per-request parameters.
+
+Triggers and completion
+-----------------------
+Automatic live decoding publishes an early request at 280 half-symbols and a
+final request at 302 half-symbols. Disk input publishes the final request.
+The FIFO preserves both requests if the early pass is delayed or has not
+started when the final trigger arrives.
+
+The live input generation advances when the sound/UDP input resets its
+write pointer, before writing the next interval's samples. Each request
+records that generation. An automatic live
+request still pending after rollover expires instead of decoding another
+interval's samples. The decoder emits <DecodeSkipped> with the expired
+request ID; the GUI clears busy only for the latest request, without
+changing decode counts or advancing a disk sequence. Manual repeats and
+disk requests do not expire on live rollover.
+
+newdat belongs to the active request and starts at 1. The DSP receives its
+own copy for FFT-cache invalidation. Clearing that copy or finishing a pass
+cannot erase or repeat a pending request.
+
+The Decode button sets nagain to reuse the previous sample snapshot.
+Freeze-decode also sets manualDecodeFlag. Publication consumes the draft
+manual flag, so it cannot leak into the next automatic request.
+
+An early pass emits <EarlyFinished>. A final or manual pass emits
+<DecodeFinished> with its request ID appended after the existing fixed-width
+fields. The GUI accepts final completion only when that ID still matches the
+latest published request. An older completion cannot clear busy state or
+advance a disk sequence while newer work is pending.
+
+decoder_ready temporarily prevents claims while input/parameters are being
+prepared; publication enables claims. Loading another file cancels queued
+requests and invalidates older completion IDs. Shutdown frees queued
+requests. Neither operation interrupts an already active DSP call.
+
+Sample-buffer boundary
+----------------------
+The request queue owns scalar parameters and strings, not sample buffers.
+decode0 copies live dd/ss/savg into the existing snapshot when an automatic
+request starts; manual repeats reuse that snapshot. Requests claimed before
+rollover still have the existing race between the sample copy and buffer
+updates. Generation checks reject already obsolete pending requests; they
+do not establish ownership of a claimed request's samples or synchronize
+its sample copy.
diff --git a/map65/messages.cpp b/map65/messages.cpp
index 876c04f0..4ded52c2 100644
--- a/map65/messages.cpp
+++ b/map65/messages.cpp
@@ -5,9 +5,10 @@
#include "mainwindow.h"
#include "qt_helpers.hpp"
#include "../revision_utils.hpp"
-#include "../Logger.hpp"
#include "../Network/PSKReporter.hpp"
#include "liveCQSender.hpp"
+#include "pskreporter_decode.h"
+#include "pskreporter_settings.h"
#include <QCoreApplication> //liveCQ
#include <QNetworkAccessManager> //liveCQ
@@ -21,11 +22,8 @@
#include <QThread>
#include <QDebug>
-#include <iostream>
-#include <string>
-#include <memory>
-
-Messages::Messages (QString const& settings_filename, QWidget * parent) :
+Messages::Messages (QString const& settings_filename, QString const& eclipse_filename,
+ QWidget * parent) :
QDialog {parent},
ui {new Ui::Messages},
m_settings_filename {settings_filename}
@@ -42,11 +40,13 @@ Messages::Messages (QString const& settings_filename, QWidget * parent) :
ui->messagesTextBrowser->clear();
QSettings settings2 {m_settings_filename, QSettings::IniFormat};
+ auto const pskReporterSettings = readMap65PSKReporterSettings(settings2);
SettingsGroup h {&settings2, "Common"};
bool m_w3szUrl = settings2.value("w3szUrl",true).toBool();
QString m_otherUrl = settings2.value("otherUrl","").toString();
QString m_myCall=settings2.value("MyCall","").toString();
QString m_myGrid=settings2.value("MyGrid","").toString();
+ m_spot_to_psk_reporter = pskReporterSettings.enabled;
QString theUrl;
if(m_w3szUrl) {
@@ -78,16 +78,18 @@ Messages::Messages (QString const& settings_filename, QWidget * parent) :
});
connect(livecqThread, &QThread::finished, livecqThread, &QObject::deleteLater);
livecqThread->start();
-
- pskReporter_.reset (new PSKReporter {
- {settings2.value ("PSKReporterTCPIP", false).toBool (),
- QCoreApplication::applicationDirPath () + "/eclipse.txt",
- QString {"MAP65 v" + QCoreApplication::applicationVersion () + " " + revision ()}.simplified ()}
- });
- if (m_spot_to_psk_reporter)
- {
- initializePSKReporting ();
- }
+
+ m_psk_reporter.reset(new PSKReporter({
+ pskReporterSettings.use_tcpip,
+ eclipse_filename,
+ QString {"MAP65 v" + QCoreApplication::applicationVersion()
+ + " " + revision()}.simplified()
+ }));
+ connect(m_psk_reporter.get(), &PSKReporter::errorOccurred,
+ this, &Messages::errorOccurred);
+ if (m_spot_to_psk_reporter) {
+ initializePSKReporting();
+ }
}
Messages::~Messages()
@@ -95,6 +97,9 @@ Messages::~Messages()
//QSettings settings {m_settings_filename, QSettings::IniFormat};
//SettingsGroup g {&settings, "MainWindow"};
//settings.setValue ("MessagesGeom", geometry ());
+ if (m_psk_reporter) {
+ m_psk_reporter->sendReport(true);
+ }
delete ui;
}
@@ -120,10 +125,19 @@ void Messages::initializePSKReporting()
SettingsGroup g {&settings, "Common"};
QString receiverCallsign=settings.value("MyCall","").toString();
QString receiverLocator=settings.value("MyGrid","").toString();
- if (pskReporter_)
- {
- pskReporter_->setLocalStation(receiverCallsign, receiverLocator, "N/A", "N/A (MAP65)");
- }
+ m_psk_reporter->setLocalStation(receiverCallsign, receiverLocator,
+ "N/A", "N/A (MAP65)");
+}
+
+void Messages::setPSKReportingEnabled(bool enabled)
+{
+ auto const was_enabled = m_spot_to_psk_reporter;
+ m_spot_to_psk_reporter = enabled;
+ if (enabled) {
+ initializePSKReporting();
+ } else if (was_enabled) {
+ m_psk_reporter->sendReport(true);
+ }
}
void Messages::sendLiveCQData(QStringList decodeList) {
@@ -145,7 +159,7 @@ void Messages::sendLiveCQData(QStringList decodeList) {
else return;
for (const QString &theLine : decodeList) {
QStringList thePostLine = theLine.split(" ",SkipEmptyParts);
- if((thePostLine.at(5) == "CQ" || thePostLine.at(5) == "QRZ" || thePostLine.at(5) == "CQV" || thePostLine.at(5) == "CQH" || thePostLine.at(5) == "QRT") && m_myCall.length() >=3 && m_myGrid.length()>=4) {
+ if((thePostLine.at(5).trimmed() == "CQ" || thePostLine.at(5).trimmed() == "QRZ" || thePostLine.at(5).trimmed() == "CQV" || thePostLine.at(5) == "CQH" || thePostLine.at(5).trimmed() == "QRT") && m_myCall.length() >=3 && m_myGrid.length()>=4) {
if(allDecodes.filter(theLine.mid(0,53)).length() == 0) {
allDecodes.append(theLine);
QString freq = thePostLine.at(0).trimmed();
@@ -166,7 +180,7 @@ void Messages::sendLiveCQData(QStringList decodeList) {
// Handle CQ CALL but NO GRID -- dot at 7
if(thePostLine.at(7).contains(".")) {
callsign = thePostLine.at(6).trimmed().toUpper();
- bool isCall = testCall(callsign);
+ bool isCall = Map65PSKReporter::isValidMap65Callsign(callsign);
if(!isCall) continue;
dT =thePostLine.at(7).trimmed();
modeChar = thePostLine.at(8).trimmed();
@@ -183,13 +197,13 @@ void Messages::sendLiveCQData(QStringList decodeList) {
} else if (thePostLine.at(8).contains(".")) {
// Test for callsign at thePostLine(6)
callsign = thePostLine.at(6).trimmed().toUpper();
- bool isCall = testCall(callsign);
+ bool isCall = Map65PSKReporter::isValidMap65Callsign(callsign);
if(isCall) {
grid = thePostLine.at(7).trimmed();
// Handle CQ XXX CALL
} else {
callsign = thePostLine.at(7).trimmed().toUpper();
- bool isCall = testCall(callsign);
+ bool isCall = Map65PSKReporter::isValidMap65Callsign(callsign);
if(!isCall) continue;
}
dT =thePostLine.at(8).trimmed();
@@ -219,7 +233,7 @@ void Messages::sendLiveCQData(QStringList decodeList) {
// Handle CQ XXX CALL GRID
} else if(thePostLine.at(9).contains(".")) {
callsign = thePostLine.at(7).trimmed().toUpper();
- bool isCall = testCall(callsign);
+ bool isCall = Map65PSKReporter::isValidMap65Callsign(callsign);
if(!isCall) continue;
grid = thePostLine.at(8).trimmed();
@@ -262,63 +276,6 @@ void Messages::sendLiveCQData(QStringList decodeList) {
}
}
-bool Messages::testCall(QString w)
-{
-// Check "callsign" to see if it could be a valid standard callsign or a valid
-// compound callsign.
-// Return a logical "call ok" indicator.
- if(w.indexOf('.') >= 0) return false;
- if(w.indexOf('+') >= 0) return false;
- if(w.indexOf('-') >= 0) return false;
- if(w.indexOf('?') >= 0) return false;
- w = w.replace('<',"");
- w = w.replace('>',"");
- int n1=w.length();
- if(n1 > 11) return false;
- QString bc = QString();
- QStringList wSplit = w.split("/");
- if(wSplit.length() > 1) {
- if(wSplit.at(0).length() > wSplit.at(1).length()) {
- bc = wSplit.at(0);
- }
- else {
- bc = wSplit.at(1);
- }
- }
- else {
- bc = w;
- }
- int nbc=bc.trimmed().length();
- if(nbc > 8) return false; //Base call should have no more than 8 characters e.g. YW18FIFA
-
-// One of first two characters must be a letter
- if((!bc[0].isLetter()) && (!bc[1].isLetter())) return false;
-// Real calls don't start with Q, but we'll allow the placeholder
-// callsign QU1RK to be considered a standard call:
- if(bc[0]=='Q' && bc.mid(0,5) != "QU1RK") return false;
-
-// Must have a digit in 2nd or 3rd or 4th position
- int i1=0;
- if(bc[1].isDigit()) i1=1;
- if(bc[2].isDigit()) i1=2;
- if(bc[3].isDigit()) i1=3;
- if(i1==0) return false;
-
-// Callsign must have a suffix of 1-4 letters e.g. YW18FIFA
- if(i1==nbc) return false;
- int n=0;
- QChar j=QChar();
- for (int i=i1+1; i<=nbc-1; ++i) {
- j=bc[i];
- if(j<QChar('A') || j > QChar('Z')) return false;
- n=n+1;
- }
- if(n >= 1 && n <= 4) return true;
-
- return false;
-}
-
-
void Messages::onFinished(QNetworkReply *reply)
{
if (reply->error() == QNetworkReply::NoError) {
@@ -379,135 +336,20 @@ void Messages::setText(QString t, QString t2)
}
}
-void Messages::sendPSKReporterData(QStringList decodeList) {
-
- QSettings settings(m_settings_filename, QSettings::IniFormat);
+void Messages::sendPSKReporterData(QStringList decodeList) {
+ QSettings settings {m_settings_filename, QSettings::IniFormat};
SettingsGroup g {&settings, "Common"};
-
- //QRZ parameters (3)
- QString receiverCallsign=settings.value("MyCall","").toString();
- QString receiverLocator=settings.value("MyGrid","").toString();
- m_spot_to_psk_reporter = settings.value("spotPSK",true).toBool();
- //QRZ parameters (8)
- QString senderCallsign;
- QString senderLocator;
- double doubleFreq = 0.0; //(Hz)
- qint64 frequency = 0.0;
- int sNR = -10;
- QString mode = "";
- bool ok = false;
-
- for (const QString &theLine : decodeList) {
- QStringList thePostLine = theLine.split(" ",SkipEmptyParts);
- if((thePostLine.at(5) == "CQ" || thePostLine.at(5) == "QRZ" || thePostLine.at(5) == "CQV" || thePostLine.at(5) == "CQH" || thePostLine.at(5) == "QRT") && receiverCallsign.length() >=3 && receiverLocator.length()>=4) {
- if(allDecodes2.filter(theLine.mid(0,53)).length() == 0) {
- allDecodes2.append(theLine);
- QString freq = thePostLine.at(0).trimmed();
- doubleFreq = freq.toDouble(&ok);
- frequency = qRound64(doubleFreq * 1000000);
- QString dF = thePostLine.at(1).trimmed();
- QString dB = thePostLine.at(4).trimmed();
- sNR = dB.toInt(&ok);
- QString msgType = thePostLine.at(5).trimmed().toUpper();
- senderCallsign = "";
- senderLocator = "--";
- mode="";
- sNR=-10;
- QString modeChar = "";
+ auto const spots = Map65PSKReporter::parseMap65PSKReporterSpots(
+ decodeList,
+ settings.value("MyCall", "").toString(),
+ settings.value("MyGrid", "").toString(),
+ QDateTime::currentDateTimeUtc(),
+ allDecodes2);
- int m_TRperiod = 60;
- QString sTimeString = (thePostLine.at(3).trimmed() + "00");
- int sTime = sTimeString.toInt();
- int h=sTimeString.mid(0,2).toInt();
- int m=sTimeString.mid(2,2).toInt();
- int s=sTimeString.mid(4,2).toInt();
- QTime time2(h, m, s);
- QDateTime qSpotTime;
- if (sTime + m_TRperiod < 236000) {
- #if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
- qSpotTime = QDateTime(
- QDateTime::currentDateTimeUtc().date(),
- time2,
- QTimeZone::UTC
- );
- #else
- qSpotTime = QDateTime(
- QDateTime::currentDateTimeUtc().date(),
- time2,
- Qt::UTC
- );
- #endif
- }
- else {
- #if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
- qSpotTime = QDateTime(
- QDateTime::currentDateTimeUtc().addDays(-1).date(),
- time2,
- QTimeZone::UTC
- );
- #else
- qSpotTime = QDateTime(
- QDateTime::currentDateTimeUtc().addDays(-1).date(),
- time2,
- Qt::UTC
- );
- #endif
- }
-
- // Handle CQ CALL but NO GRID -- dot at 7
- if(thePostLine.at(7).contains(".")) {
- senderCallsign = thePostLine.at(6).trimmed().toUpper();
- bool isCall = testCall(senderCallsign);
- if(!isCall) continue;
- modeChar = thePostLine.at(8).trimmed();
- if(modeChar.contains("#")) mode = QString("JT65") + modeChar.back();
- else if(modeChar.contains(":")) mode = QString("Q65-60") + modeChar.back();
-
- // Handle CQ CALL GRID or CQ XXX CALL -- dot at 8
- } else if (thePostLine.at(8).contains(".")) {
- // Test for callsign at thePostLine(6)
- senderCallsign = thePostLine.at(6).trimmed().toUpper();
- bool isCall = testCall(senderCallsign);
- if(isCall) {
- senderLocator = thePostLine.at(7).trimmed();
- // Handle CQ XXX CALL
- } else {
- senderCallsign = thePostLine.at(7).trimmed().toUpper();
- bool isCall = testCall(senderCallsign);
- if(!isCall) continue;
- }
- modeChar = thePostLine.at(9).trimmed();
- if(modeChar.contains("#"))
- {
- mode = QString("JT65") + modeChar.back();
- } else if(modeChar.contains(":")) {
- mode = QString("Q65-60") + modeChar.back();
- }
- // Handle CQ XXX CALL GRID
- } else if(thePostLine.at(9).contains(".")) {
- senderCallsign = thePostLine.at(7).trimmed().toUpper();
- bool isCall = testCall(senderCallsign);
- if(!isCall) continue;
- senderLocator = thePostLine.at(8).trimmed();
-
- modeChar = thePostLine.at(10).trimmed();
- if(modeChar.contains("#"))
- {
- mode = QString("JT65") + modeChar.back();
- } else if(modeChar.contains(":")) {
- mode = QString("Q65-60") + modeChar.back();
- }
- }
- else {
- continue;
- }
-
- if (pskReporter_)
- {
- pskReporter_->addRemoteStation(senderCallsign, senderLocator, frequency, mode, sNR, qSpotTime);
- }
- }
- }
+ for (auto const& spot : spots) {
+ m_psk_reporter->addRemoteStation(spot.callsign, spot.locator,
+ spot.frequency, spot.mode, spot.snr,
+ spot.time);
}
}
diff --git a/map65/messages.h b/map65/messages.h
index 67973c53..5b27157a 100644
--- a/map65/messages.h
+++ b/map65/messages.h
@@ -3,26 +3,25 @@
#include <QDialog>
#include "commons.h"
-#include "../Network/PSKReporter.hpp"
#include <memory>
#include <QNetworkReply>
-#include <QDateTime>
namespace Ui {
class Messages;
}
-class PSKReporter; // Forward declaration — avoids including PSKReporter.h here
+class PSKReporter;
class Messages : public QDialog
{
Q_OBJECT
public:
- explicit Messages (QString const& settings_filename, QWidget * parent = nullptr);
+ explicit Messages (QString const& settings_filename, QString const& eclipse_filename,
+ QWidget * parent = nullptr);
void setText(QString t, QString t2);
void setColors(QString t);
- void init_psk_reporter(bool const& param1, bool const& param2, QString const& param3);
+ void setPSKReportingEnabled(bool enabled);
void setClosingForShutdown(bool value) { m_closingForShutdown = value; }
~Messages();
@@ -53,8 +52,8 @@ private:
QString m_color2;
QString m_color3;
- std::unique_ptr<PSKReporter> pskReporter_;
QThread* livecqThread;
+ std::unique_ptr<PSKReporter> m_psk_reporter;
bool m_closingForShutdown = false;
bool m_cqOnly;
@@ -64,7 +63,7 @@ private:
void sendPSKReporterData(QStringList decodeList); //PSKReporter
void sendLiveCQData(QStringList decodeList); // This will trigger the web request
void initializePSKReporting();
- bool testCall(QString w); //liveCQ
+ bool m_spot_to_psk_reporter {false};
QString w3szUrlAddr="https://w3sz.com/livecq_update.php"; //liveCQ
diff --git a/map65/plotter.cpp b/map65/plotter.cpp
index 1c158928..6397222b 100644
--- a/map65/plotter.cpp
+++ b/map65/plotter.cpp
@@ -11,6 +11,8 @@
#define MAX_SCREENSIZE 2048
+extern int g_sampleRate;
+extern int g_activeNfft;
CPlotter::CPlotter(QWidget *parent) : //CPlotter Constructor
QFrame(parent)
@@ -39,7 +41,6 @@ CPlotter::CPlotter(QWidget *parent) : //CPlotter Constructor
m_fQSO = 125;
m_TXkHz = m_fQSO;
m_line = 0;
- m_fSample = 96000;
m_paintAllZoom = false;
m_TxDF=0;
m_bDecodeFinished=false;
@@ -47,6 +48,18 @@ CPlotter::CPlotter(QWidget *parent) : //CPlotter Constructor
CPlotter::~CPlotter() { } // Destructor
+void CPlotter::ensureWaterfallHistory(int rows)
+{
+ rows = std::max(0, rows);
+ int stride = std::max(0, g_activeNfft);
+ size_t size = static_cast<size_t>(stride) * static_cast<size_t>(rows);
+ if (m_waterfallStride != stride || m_waterfallRows != rows || m_zwf.size() != size) {
+ m_zwf.assign(size, 0);
+ m_waterfallStride = stride;
+ m_waterfallRows = rows;
+ }
+}
+
QSize CPlotter::minimumSizeHint() const
{
return QSize(50, 50);
@@ -64,14 +77,14 @@ void CPlotter::resizeEvent(QResizeEvent* ) //resizeEvent()
//if changed, resize pixmaps to new screensize
m_Size = size();
int w = m_Size.width();
- int h = (m_Size.height()-60)/2;
+ int h = std::max(0, (m_Size.height()-60)/2);
m_WaterfallPixmap = QPixmap(w,h);
m_ZoomWaterfallPixmap = QPixmap(w,h);
m_2DPixmap = QPixmap(w,h);
m_WaterfallPixmap.fill(Qt::black);
m_ZoomWaterfallPixmap.fill(Qt::black);
m_2DPixmap.fill(Qt::black);
- memset(m_zwf,0,32768*h);
+ ensureWaterfallHistory(h);
m_ScalePixmap = QPixmap(w,30);
m_ZoomScalePixmap = QPixmap(w,30); //(no change on resize...)
m_ScalePixmap.fill(Qt::white);
@@ -106,24 +119,34 @@ void CPlotter::paintEvent(QPaintEvent *) // paintEvent()
QRect source(0,0,w,30);
painter.drawPixmap(target,m_ZoomScalePixmap,source);
- float df=m_fSample/32768.0;
- int x0=16384 + (0.001*(m_ZoomStartFreq+m_fCal)+m_fQSO-m_nkhz+1.27046) * \
+ float df = float(g_sampleRate) / float(g_activeNfft);
+ int x0 = g_activeNfft/2 + (0.001*(m_ZoomStartFreq+m_fCal)+m_fQSO-m_nkhz+1.27046) * \
1000.0/df + 0.5;
QPainter painter1(&m_WaterfallPixmap);
QPainter painter2(&m_ZoomWaterfallPixmap);
for(int i=0; i<w; i++) { //Paint the top row
- painter2.setPen(m_ColorTbl[m_zwf[x0+i]]);
+ int idx = x0 + i;
+ unsigned char color = 0;
+ if (idx >= 0 && idx < m_waterfallStride && !m_zwf.empty()) {
+ color = m_zwf[static_cast<size_t>(idx)];
+ }
+ painter2.setPen(m_ColorTbl[color]);
painter2.drawPoint(i,0);
}
if(m_paintAllZoom or (x0 != x00 and x00 != -99)) {
// If new fQSO, paint all rows
int k=x0;
for(int j=1; j<h; j++) {
- k += 32768;
+ k += g_activeNfft;
if(x0 != x00 and x00 != -99) {
for(int i=0; i<w; i++) {
- painter2.setPen(m_ColorTbl[m_zwf[i+k]]);
+ int idx = k + i;
+ unsigned char color = 0;
+ if (idx >= 0 && static_cast<size_t>(idx) < m_zwf.size()) {
+ color = m_zwf[static_cast<size_t>(idx)];
+ }
+ painter2.setPen(m_ColorTbl[color]);
painter2.drawPoint(i,j);
}
}
@@ -196,13 +219,17 @@ void CPlotter::draw(float s[], int i0, float splot[]) //draw()
m_i0=i0;
w = m_WaterfallPixmap.width();
h = m_WaterfallPixmap.height();
+ ensureWaterfallHistory(h);
double gain = pow(10.0,0.05*(m_plotGain+7));
//move current data down one line
//(must do this before attaching a QPainter object)
m_WaterfallPixmap.scroll(0,1,0,0,w,h);
m_ZoomWaterfallPixmap.scroll(0,1,0,0, w, h);
- memmove(&m_zwf[32768],m_zwf,32768*(h-1));
+ if (m_waterfallStride > 0 && m_waterfallRows > 1) {
+ size_t stride = static_cast<size_t>(m_waterfallStride);
+ memmove(&m_zwf[stride], m_zwf.data(), stride * static_cast<size_t>(m_waterfallRows - 1));
+ }
QPainter painter1(&m_WaterfallPixmap);
QPainter painter2D(&m_2DPixmap);
@@ -251,14 +278,17 @@ void CPlotter::draw(float s[], int i0, float splot[]) //draw()
}
}
- for(i=0; i<32768; i++) {
+ int rowBins = std::min(g_activeNfft, m_waterfallStride);
+ for (i = 0; i < rowBins; i++) {
y = 10.0*log10(splot[i]);
int y1 = 5.0*gain*(y + 30 - m_plotZero);
if (y1<0) y1=0;
if (y1>254) y1=254;
if (splot[i]>1.e29) y1=255;
m_hist2[y1]++;
- m_zwf[i]=y1;
+ if (!m_zwf.empty()) {
+ m_zwf[static_cast<size_t>(i)] = static_cast<unsigned char>(y1);
+ }
}
if(s[0]>1.0e29) m_line=0;
@@ -305,10 +335,17 @@ void CPlotter::DrawOverlay() //DrawOverlay()
painter0.setFont(Font);
painter0.setPen(Qt::black);
- m_binsPerPixel = m_nSpan * 32768.0/(w*0.001*m_fSample) + 0.5;
double FreqPerDiv=5.0;
- double df = m_binsPerPixel*0.001*m_fSample/32768.0;
- m_hdivs = w*df/FreqPerDiv + 0.9999;
+ double df = m_binsPerPixel * 0.001 * double(g_sampleRate) / double(g_activeNfft);
+ m_fSpan = w * df;
+
+ m_hdivs = int(w * df / FreqPerDiv + 0.9999);
+ // Clamp to array size
+ const int MAX_HDIVS = 482;
+ if (m_hdivs < 0) m_hdivs = 0;
+ if (m_hdivs > MAX_HDIVS) m_hdivs = MAX_HDIVS;
+
+
m_fSpan = w*df;
m_ScalePixmap.fill(Qt::white);
painter0.drawRect(0, 0, w, 30);
@@ -355,7 +392,7 @@ void CPlotter::DrawOverlay() //DrawOverlay()
painter0.setPen(pen0);
x = m_xClick;
painter0.drawLine(x,15,x,30);
- int x0=(16384-m_i0)/m_binsPerPixel;
+ int x0=((g_activeNfft/2) - m_i0)/m_binsPerPixel;
m_fGreen=(x-x0)*df;
x0 += (x0-x);
QPen pen3(Qt::red, 3);
@@ -379,8 +416,10 @@ void CPlotter::DrawOverlay() //DrawOverlay()
painter3.setPen(Qt::black);
FreqPerDiv=0.2;
- df = 0.001*m_fSample/32768.0;
- m_hdivs = 32768*df/FreqPerDiv + 0.9999;
+ df = 0.001f * float(g_sampleRate) / float(g_activeNfft);
+ m_hdivs = int(g_activeNfft * df / FreqPerDiv + 0.9999);
+ if (m_hdivs < 0) m_hdivs = 0;
+ if (m_hdivs > MAX_HDIVS) m_hdivs = MAX_HDIVS;
int nlabs=df*w/0.2 + 1.0;
m_ZoomScalePixmap.fill(Qt::white);
painter3.drawRect(0, 0, w, 30);
@@ -402,7 +441,7 @@ void CPlotter::DrawOverlay() //DrawOverlay()
m_HDivText[i]);
}
- df=m_fSample/32768.0;
+ df = float(g_sampleRate) / float(g_activeNfft);
if(m_bLockTxRx) m_TxDF=m_DF;
x = (m_DF + m_mode65*66*11025.0/4096.0 - m_ZoomStartFreq)/df;
QPen pen2(Qt::darkGreen, 3); //Mark top JT65B tone with dark Green tick
@@ -431,6 +470,7 @@ void CPlotter::DrawOverlay() //DrawOverlay()
void CPlotter::MakeFrequencyStrs() //MakeFrequencyStrs
{
+
float StartFreq = m_StartFreq;
float freq;
int i,j;
@@ -440,7 +480,7 @@ void CPlotter::MakeFrequencyStrs() //MakeFrequencyStrs
m_FreqUnits = 1;
FreqPerDiv = 200;
int w = m_WaterfallPixmap.width();
- float df=m_fSample/32768.0;
+ float df = float(g_sampleRate) / float(g_activeNfft);
StartFreq = -w*df/2;
int n=StartFreq/FreqPerDiv;
StartFreq=n*200;
@@ -631,8 +671,9 @@ void CPlotter::mousePressEvent(QMouseEvent *event) //mousePressEvent
m_TXfreq = floor(static_cast<int>(getFcenter())) + 0.001*m_TXkHz;
}
} else { // Zoomed waterfall
- if(button==1) m_DF=int(m_ZoomStartFreq + x*m_fSample/32768.0);
- if(button==2 and !m_bLockTxRx) m_TxDF=int(m_ZoomStartFreq + x*m_fSample/32768.0);
+ float df = float(g_sampleRate) / float(g_activeNfft);
+ if (button == 1) m_DF = int(m_ZoomStartFreq + x * df);
+ if (button == 2 && !m_bLockTxRx) m_TxDF = int(m_ZoomStartFreq + x * df);
if(m_bLockTxRx) m_TxDF=m_DF;
}
DrawOverlay();
@@ -657,7 +698,8 @@ void CPlotter::mouseDoubleClickEvent(QMouseEvent *event) //mouse2click
setFQSO(x,false);
emit freezeDecode1(2); //### ???
} else {
- float f = m_ZoomStartFreq + x*m_fSample/32768.0;
+ float df = float(g_sampleRate) / float(g_activeNfft);
+ float f = m_ZoomStartFreq + x * df;
m_DF=int(f);
emit freezeDecode1(1);
DrawOverlay();
@@ -679,7 +721,7 @@ int CPlotter::autoZero() //autoZero()
int sum2=0;
for(int i=0; i<256; i++) {
sum2 += m_hist2[i];
- if(sum2 > 16384) {
+ if (sum2 > g_activeNfft/2) {
m_z2=i;
break;
}
@@ -694,8 +736,23 @@ int CPlotter::autoZero() //autoZero()
void CPlotter::setNSpan(int n) //setNSpan()
{
m_nSpan=n;
+// ui->widePlot->resetWaterfall();
}
+/*
+void CPlotter::resetWaterfall()
+{
+ int w = m_WaterfallPixmap.width();
+ int h = m_WaterfallPixmap.height();
+
+ m_WaterfallPixmap = QPixmap(w, h);
+ m_WaterfallPixmap.fill(Qt::black);
+
+ m_ScalePixmap = QPixmap(w, 30);
+ m_ScalePixmap.fill(Qt::white);
+ m_lastWaterfallLine = 0;
+}
+*/
void CPlotter::setPalette(QString palette) //setPalette()
{
if(palette=="Linrad") {
@@ -754,11 +811,6 @@ void CPlotter::setPalette(QString palette) //setPalette()
}
}
-void CPlotter::setFsample(int n)
-{
- m_fSample=n;
-}
-
void CPlotter::setMode65(int n)
{
m_mode65=n;
@@ -805,8 +857,8 @@ void CPlotter::mouseMoveEvent (QMouseEvent * event)
#endif
bool lower=(y > 30+h);
float freq=FreqfromX(x);
- float df=m_fSample/32768.0;
- int ndf=x*df + m_ZoomStartFreq;
+ float df = float(g_sampleRate) / float(g_activeNfft);
+ int ndf = int(x * df + m_ZoomStartFreq + 0.5f);
if(lower) {
QToolTip::showText(
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
diff --git a/map65/plotter.h b/map65/plotter.h
index 1147b12e..e7ff1f82 100644
--- a/map65/plotter.h
+++ b/map65/plotter.h
@@ -13,6 +13,7 @@
#include <QList>
#include <QToolTip>
#include <cstring>
+#include <vector>
#include "commons.h"
#include "decode_label.h"
@@ -68,13 +69,13 @@ public:
int DF();
int autoZero();
void setPalette(QString palette);
- void setFsample(int n);
void setMode65(int n);
void set2Dspec(bool b);
double fGreen();
void setLockTxRx(bool b);
double rxFreq();
double txFreq();
+// void resetWaterfall()
// void updateFreqLabel();
// Decoded-callsign overlay (N6NU 2026-05-12, ported from QMAP).
@@ -114,6 +115,7 @@ private:
int XfromFreq(float f);
float FreqfromX(int x);
qint64 RoundFreq(qint64 freq, int resolution);
+ void ensureWaterfallHistory(int rows);
// Render m_decodeLabels overlay on top of the waterfall pixmap.
// Stacks colliding labels vertically (max 5 rows) so a busy band
// doesn't paint labels on top of each other.
@@ -130,7 +132,9 @@ private:
QPixmap m_WaterfallPixmap;
QPixmap m_ZoomWaterfallPixmap;
QPixmap m_2DPixmap;
- unsigned char m_zwf[32768*400];
+ std::vector<unsigned char> m_zwf;
+ int m_waterfallStride {0};
+ int m_waterfallRows {0};
QPixmap m_ScalePixmap;
QPixmap m_ZoomScalePixmap;
QSize m_Size;
@@ -158,7 +162,6 @@ private:
qint32 m_z1;
qint32 m_z2;
qint32 m_nkhz;
- qint32 m_fSample;
qint32 m_mode65;
qint32 m_i0;
qint32 m_xClick;
diff --git a/map65/pskreporter_decode.cpp b/map65/pskreporter_decode.cpp
new file mode 100644
index 00000000..85b51b58
--- /dev/null
+++ b/map65/pskreporter_decode.cpp
@@ -0,0 +1,120 @@
+#include "pskreporter_decode.h"
+
+#include "../validators/LiveCQCallsign.hpp"
+#include "../Network/DecodedTime.hpp"
+
+#include <QtGlobal>
+
+namespace
+{
+ bool isReportableMessageType(QString const& messageType)
+ {
+ return messageType == "CQ" || messageType == "QRZ"
+ || messageType == "CQV" || messageType == "CQH"
+ || messageType == "QRT";
+ }
+
+ bool parseSpot(QStringList const& tokens,
+ QString const& receiverCallsign,
+ QString const& receiverLocator,
+ QDateTime const& nowUtc,
+ PSKReporterIPFIX::Spot& spot)
+ {
+ if (tokens.size() < 9 || receiverCallsign.length() < 3
+ || receiverLocator.length() < 4
+ || !isReportableMessageType(tokens.at(5).trimmed())) {
+ return false;
+ }
+
+ bool ok = false;
+ auto const frequencyMHz = tokens.at(0).trimmed().toDouble(&ok);
+ if (!ok) {
+ return false;
+ }
+
+ auto const spotTime = DecodedTime::spotTime(tokens.at(3).trimmed(), nowUtc, 60);
+ if (!spotTime.isValid()) {
+ return false;
+ }
+
+ QString callsign;
+ QString locator = "--";
+ QString mode;
+ QString modeToken;
+
+ if (tokens.at(7).contains('.')) {
+ callsign = tokens.at(6).trimmed().toUpper();
+ modeToken = tokens.at(8).trimmed();
+ } else if (tokens.size() >= 10 && tokens.at(8).contains('.')) {
+ callsign = tokens.at(6).trimmed().toUpper();
+ if (Map65PSKReporter::isValidMap65Callsign(callsign)) {
+ locator = tokens.at(7).trimmed();
+ } else {
+ callsign = tokens.at(7).trimmed().toUpper();
+ }
+ modeToken = tokens.at(9).trimmed();
+ } else if (tokens.size() >= 11 && tokens.at(9).contains('.')) {
+ callsign = tokens.at(7).trimmed().toUpper();
+ locator = tokens.at(8).trimmed();
+ modeToken = tokens.at(10).trimmed();
+ } else {
+ return false;
+ }
+
+ if (!Map65PSKReporter::isValidMap65Callsign(callsign)) {
+ return false;
+ }
+ if (modeToken.contains('#')) {
+ mode = "JT65" + modeToken.back();
+ } else if (modeToken.contains(':')) {
+ mode = "Q65-60" + modeToken.back();
+ } else {
+ return false;
+ }
+
+ spot = {
+ callsign,
+ locator,
+ -10,
+ static_cast<Radio::Frequency>(qRound64(frequencyMHz * 1000000)),
+ mode,
+ spotTime
+ };
+ return true;
+ }
+}
+
+namespace Map65PSKReporter
+{
+ bool isValidMap65Callsign(QString const& callsign)
+ {
+ return LiveCQ::isValidCallsign(callsign);
+ }
+
+ QList<PSKReporterIPFIX::Spot> parseMap65PSKReporterSpots(
+ QStringList const& decodeLines,
+ QString const& receiverCallsign,
+ QString const& receiverLocator,
+ QDateTime const& nowUtc,
+ QStringList& seenDecodes)
+ {
+ QList<PSKReporterIPFIX::Spot> spots;
+ for (auto const& line : decodeLines) {
+ auto const tokens = line.split(' ', Qt::SkipEmptyParts);
+ if (tokens.size() < 6
+ || !isReportableMessageType(tokens.at(5).trimmed())
+ || receiverCallsign.length() < 3
+ || receiverLocator.length() < 4
+ || !seenDecodes.filter(line.left(53)).isEmpty()) {
+ continue;
+ }
+
+ seenDecodes.append(line);
+ PSKReporterIPFIX::Spot spot;
+ if (parseSpot(tokens, receiverCallsign, receiverLocator, nowUtc, spot)) {
+ spots.append(spot);
+ }
+ }
+ return spots;
+ }
+}
diff --git a/map65/pskreporter_decode.h b/map65/pskreporter_decode.h
new file mode 100644
index 00000000..55a47b6b
--- /dev/null
+++ b/map65/pskreporter_decode.h
@@ -0,0 +1,23 @@
+#ifndef MAP65_PSKREPORTER_DECODE_H
+#define MAP65_PSKREPORTER_DECODE_H
+
+#include <QDateTime>
+#include <QList>
+#include <QString>
+#include <QStringList>
+
+#include "../Network/PSKReporterIPFIX.hpp"
+
+namespace Map65PSKReporter
+{
+ bool isValidMap65Callsign(QString const& callsign);
+
+ QList<PSKReporterIPFIX::Spot> parseMap65PSKReporterSpots(
+ QStringList const& decodeLines,
+ QString const& receiverCallsign,
+ QString const& receiverLocator,
+ QDateTime const& nowUtc,
+ QStringList& seenDecodes);
+}
+
+#endif
diff --git a/map65/pskreporter_settings.cpp b/map65/pskreporter_settings.cpp
new file mode 100644
index 00000000..0df138b7
--- /dev/null
+++ b/map65/pskreporter_settings.cpp
@@ -0,0 +1,11 @@
+#include "pskreporter_settings.h"
+
+#include <QSettings>
+
+Map65PSKReporterSettings readMap65PSKReporterSettings(QSettings const& settings)
+{
+ return {
+ settings.value ("Common/spotPSK", true).toBool (),
+ settings.value ("Common/PSKReporterTCPIP", false).toBool ()
+ };
+}
diff --git a/map65/pskreporter_settings.h b/map65/pskreporter_settings.h
new file mode 100644
index 00000000..9e6e2d66
--- /dev/null
+++ b/map65/pskreporter_settings.h
@@ -0,0 +1,14 @@
+#ifndef MAP65_PSKREPORTER_SETTINGS_H
+#define MAP65_PSKREPORTER_SETTINGS_H
+
+class QSettings;
+
+struct Map65PSKReporterSettings
+{
+ bool enabled;
+ bool use_tcpip;
+};
+
+Map65PSKReporterSettings readMap65PSKReporterSettings(QSettings const& settings);
+
+#endif
diff --git a/map65/runtime_paths.cpp b/map65/runtime_paths.cpp
new file mode 100644
index 00000000..eabf2296
--- /dev/null
+++ b/map65/runtime_paths.cpp
@@ -0,0 +1,132 @@
+#include "runtime_paths.h"
+
+#include <QDir>
+#include <QFile>
+#include <QFileInfo>
+#include <QStandardPaths>
+#include <QDebug>
+#include <QStringList>
+#include <QSettings>
+#include <QVariant>
+
+namespace
+{
+ QStringList runtimeSourceCandidates(QString const& appDir, QString const& installedDataDir,
+ QString const& fileName)
+ {
+ QDir app {appDir};
+ QDir cwd {QDir::currentPath()};
+
+ return {
+ QDir {installedDataDir}.absoluteFilePath(fileName),
+ app.absoluteFilePath(fileName),
+ app.absoluteFilePath("resources/" + fileName),
+ app.absoluteFilePath("../" + fileName),
+ app.absoluteFilePath("../map65/resources/" + fileName),
+ cwd.absoluteFilePath(fileName),
+ cwd.absoluteFilePath("map65/resources/" + fileName)
+ };
+ }
+}
+
+QString writableMap65DataDir()
+{
+ QString dataDir = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
+ if (dataDir.isEmpty()) {
+ dataDir = QDir::home().absoluteFilePath(".map65");
+ }
+
+ if (!QDir{}.mkpath(dataDir)) {
+ qWarning() << "Unable to create MAP65 data directory:" << dataDir;
+ }
+
+ QDir dir {dataDir};
+ if (!dir.mkpath("save")) {
+ qWarning() << "Unable to create MAP65 save directory:" << dir.absoluteFilePath("save");
+ }
+ return dataDir;
+}
+
+QString map65SettingsFile(QString const& appDir, QString const& dataDir)
+{
+ QString settingsFile = QDir {dataDir}.absoluteFilePath("map65.ini");
+ QString legacySettingsFile = QDir {appDir}.absoluteFilePath("map65.ini");
+ if (!QFile::exists(settingsFile) && QFile::exists(legacySettingsFile)) {
+ if (QFile::copy(legacySettingsFile, settingsFile)) {
+ QFile::setPermissions(settingsFile, QFile::ReadOwner | QFile::WriteOwner
+ | QFile::ReadGroup | QFile::ReadOther);
+ } else {
+ qWarning() << "Unable to migrate MAP65 settings from" << legacySettingsFile
+ << "to" << settingsFile;
+ }
+ }
+ return settingsFile;
+}
+
+int readFSam96000(QSettings const& settings, int defaultValue)
+{
+ QString text = settings.value("FSam96000", QString::number(defaultValue)).toString();
+ if (text.compare("true", Qt::CaseInsensitive) == 0) return 1; // legacy bool: true == 96000
+ if (text.compare("false", Qt::CaseInsensitive) == 0) return 0; // legacy bool: false == 95238
+ bool ok = false;
+ int value = text.toInt(&ok);
+ if (ok && value >= 0 && value <= 2) return value; // current int: 0/1/2
+ return defaultValue;
+}
+
+QString map65RuntimeFile(QString const& dataDir, QString const& fileName)
+{
+ return QDir {dataDir}.absoluteFilePath(fileName);
+}
+
+QString map65RuntimeSourceFile(QString const& appDir, QString const& installedDataDir,
+ QString const& writableDataDir, QString const& fileName)
+{
+ QString const writablePath = map65RuntimeFile(writableDataDir, fileName);
+ QString const writableCanonicalPath = QFileInfo {writablePath}.canonicalFilePath();
+ auto const candidates = runtimeSourceCandidates(appDir, installedDataDir, fileName);
+ for (auto const& sourcePath : candidates) {
+ QFileInfo sourceInfo {sourcePath};
+ if (!sourceInfo.exists() || !sourceInfo.isFile() || sourceInfo.size() == 0) {
+ continue;
+ }
+ if (sourceInfo.absoluteFilePath() == writablePath
+ || (!writableCanonicalPath.isEmpty()
+ && sourceInfo.canonicalFilePath() == writableCanonicalPath)) {
+ continue;
+ }
+ return sourceInfo.absoluteFilePath();
+ }
+
+ return candidates.front();
+}
+
+QString ensureMap65RuntimeFile(QString const& appDir, QString const& installedDataDir,
+ QString const& writableDataDir, QString const& fileName)
+{
+ QString const writablePath = map65RuntimeFile(writableDataDir, fileName);
+ QFileInfo writableInfo {writablePath};
+ if (writableInfo.exists() && writableInfo.size() > 0) {
+ return writablePath;
+ }
+
+ QString const sourcePath = map65RuntimeSourceFile(appDir, installedDataDir,
+ writableDataDir, fileName);
+ QFileInfo sourceInfo {sourcePath};
+ if (sourceInfo.exists() && sourceInfo.isFile() && sourceInfo.size() > 0) {
+ if (writableInfo.exists()) {
+ QFile::remove(writablePath);
+ }
+
+ if (QFile::copy(sourceInfo.absoluteFilePath(), writablePath)) {
+ QFile::setPermissions(writablePath, QFile::ReadOwner | QFile::WriteOwner
+ | QFile::ReadGroup | QFile::ReadOther);
+ return writablePath;
+ }
+
+ qWarning() << "Unable to migrate MAP65 runtime file from" << sourcePath
+ << "to" << writablePath;
+ }
+
+ return writablePath;
+}
diff --git a/map65/runtime_paths.h b/map65/runtime_paths.h
new file mode 100644
index 00000000..4c786c4a
--- /dev/null
+++ b/map65/runtime_paths.h
@@ -0,0 +1,24 @@
+#ifndef MAP65_RUNTIME_PATHS_H
+#define MAP65_RUNTIME_PATHS_H
+
+#include <QString>
+
+class QSettings;
+
+QString writableMap65DataDir();
+QString map65SettingsFile(QString const& appDir, QString const& dataDir);
+QString map65RuntimeFile(QString const& dataDir, QString const& fileName);
+QString map65RuntimeSourceFile(QString const& appDir, QString const& installedDataDir,
+ QString const& writableDataDir, QString const& fileName);
+QString ensureMap65RuntimeFile(QString const& appDir, QString const& installedDataDir,
+ QString const& writableDataDir, QString const& fileName);
+
+// Reads the "FSam96000" key (expected to already be scoped, e.g. via
+// settings.beginGroup("Common") / SettingsGroup) as text and interprets it
+// under both conventions that have shared a single map65.ini across
+// versions: legacy MAP65 stored this as a bool (true==96000, false==95238);
+// current MAP65 stores it as an integer (0==95238, 1==96000, 2==192000).
+// Returns defaultValue if the stored text doesn't match either convention.
+int readFSam96000(QSettings const& settings, int defaultValue = 1);
+
+#endif
diff --git a/map65/soundin.cpp b/map65/soundin.cpp
index ff233d20..ee1886e8 100644
--- a/map65/soundin.cpp
+++ b/map65/soundin.cpp
@@ -10,7 +10,6 @@
#include <sys/socket.h>
#endif
-#define NFFT 32768
#define FRAMES_PER_BUFFER 1024
#include <portaudio.h>
@@ -50,6 +49,7 @@ extern "C" int a2dCallback(const void* inputBuffer, void* outputBuffer,
}
if (udata->bzero) { // Start of a new minute
+ advance_live_input_generation();
udata->kin = 0; // Reset buffer pointer
udata->bzero = false;
}
@@ -114,6 +114,14 @@ extern "C" int a2dCallback(const void* inputBuffer, void* outputBuffer,
namespace
{
+ constexpr int symspecLookaheadSamples = 512;
+
+ int symspecReadyPointer(int acquiredSamples)
+ {
+ // symspec's final 1024-sample window extends one 512-sample hop past k.
+ return acquiredSamples - symspecLookaheadSamples;
+ }
+
struct COMWrapper
{
explicit COMWrapper ()
@@ -173,7 +181,7 @@ void SoundInThread::run() //SoundInThread::run()
inParam.suggestedLatency=device_info->defaultHighInputLatency;
inParam.hostApiSpecificStreamInfo=NULL;
- paerr=Pa_IsFormatSupported(&inParam,NULL,96000.0);
+ paerr=Pa_IsFormatSupported(&inParam,NULL,double(g_sampleRate));
if(paerr<0) {
QString error_message;
if (paUnanticipatedHostError == paerr)
@@ -191,7 +199,7 @@ void SoundInThread::run() //SoundInThread::run()
&inStream,
&inParam,
NULL,
- 96000.0,
+ double(g_sampleRate),
FRAMES_PER_BUFFER,
paClipOff,
a2dCallback,
@@ -208,47 +216,44 @@ void SoundInThread::run() //SoundInThread::run()
int k=0;
int nsec;
int ntr;
- int nhsym0=0;
+ Map65HalfSymbolScheduler spectrumScheduler;
//---------------------------------------------- Soundcard input loop
while (!qe) {
qe = quitExecution;
if (qe) break;
+
qint64 ms = QDateTime::currentMSecsSinceEpoch() % 86400000;
- nsec = ms/1000; // Time according to this computer
+ nsec = ms/1000;
ntr = nsec % m_TRperiod;
-// Reset buffer pointer and symbol number at start of minute
if(ntr < ntr0 or !m_monitoring or m_TRperiod!=m_TRperiod0) {
- nhsym0=0;
+ spectrumScheduler.reset ();
udata.bzero=true;
m_TRperiod0=m_TRperiod;
}
+
k=udata.kin;
+
udata.iqswap= (m_IQswap != 0);
udata.dB=m_dB;
+
if(m_monitoring) {
- double fcenter;
- if(m_bForceCenterFreq) {
- fcenter = m_dForceCenterFreq;
- } else {
- fcenter = 144.125; // default center
- }
+ double fcenter = m_bForceCenterFreq ? m_dForceCenterFreq : 144.125;
set_fcenter(fcenter);
- m_hsym=(k-2048)*11025.0/(2048.0*m_rate);
- if(m_hsym != nhsym0) {
- if(m_dataSinkBusy) {
- } else {
- m_dataSinkBusy=true;
- emit readyForFFT(k); //Signal to compute new FFTs
- }
- nhsym0=m_hsym;
+ int const fftPointer=symspecReadyPointer(k);
+ m_hsym=(fftPointer-2048)*11025.0/(2048.0*m_rate);
+
+ if (spectrumScheduler.claim_next (m_hsym, m_dataSinkBusy)) {
+ emit readyForFFT(fftPointer);
}
}
+
msleep(100);
ntr0=ntr;
}
+
Pa_StopStream(inStream);
Pa_CloseStream(inStream);
}
@@ -304,12 +309,15 @@ void SoundInThread::setNetwork(bool b) //setNetwork()
void SoundInThread::setMonitoring(bool b) //setMonitoring()
{
m_monitoring = b;
+ qDebug() << "m_monitoring set to" << m_monitoring << "at" << Q_FUNC_INFO;
+
}
void SoundInThread::setForceCenterFreqBool(bool b)
{
m_bForceCenterFreq=b;
+
}
void SoundInThread::setForceCenterFreqMHz(double d)
@@ -368,7 +376,7 @@ void SoundInThread::inputUDP()
int k=0;
int nsec;
int ntr;
- int nhsym0=0;
+ Map65HalfSymbolScheduler spectrumScheduler;
int iz=174;
// Main loop for input of UDP packets over the network:
@@ -390,8 +398,9 @@ void SoundInThread::inputUDP()
// Reset buffer pointer and symbol number at start of minute
if(ntr < ntr0 or !m_monitoring or m_TRperiod!=m_TRperiod0) {
+ advance_live_input_generation();
k=0;
- nhsym0=0;
+ spectrumScheduler.reset ();
m_TRperiod0=m_TRperiod;
}
ntr0=ntr;
@@ -404,7 +413,7 @@ void SoundInThread::inputUDP()
if(m_nrx == -2) iz=87; // Two RF channels, r*4 data
// If buffer will not overflow, move data into datcom_
- if ((k+iz) <= 60*96000) {
+ if ((k + iz) <= 60 * m_rate) {
int nsam=-1;
recvpkt_(&nsam, &b.iblk, &b.nrx, &k, b.d8, b.d8, b.d8);
double fcenter;
@@ -416,18 +425,11 @@ void SoundInThread::inputUDP()
set_fcenter(fcenter);
}
-m_hsym = (k-2048)*11025.0/(2048.0*m_rate);
-if (m_hsym != nhsym0) {
- if (m_dataSinkBusy) {
- } else {
- m_dataSinkBusy = true;
-
- QDateTime now = QDateTime::currentDateTime();
- QString ts = now.toString("yyyy-MM-dd hh:mm:ss.zzz");
-
- emit readyForFFT(k);
- }
- nhsym0 = m_hsym;
+double hsym = 2048.0 * m_rate / 11025.0;
+int const fftPointer=symspecReadyPointer(k);
+m_hsym = (fftPointer - 2048) / hsym;
+if (spectrumScheduler.claim_next (m_hsym, m_dataSinkBusy)) {
+ emit readyForFFT(fftPointer);
}
}
diff --git a/map65/soundin.h b/map65/soundin.h
index 7dc78839..0f45acea 100644
--- a/map65/soundin.h
+++ b/map65/soundin.h
@@ -4,8 +4,11 @@
#include <QtCore>
#include <QtNetwork/QUdpSocket>
#include <QDebug>
+#include <atomic>
#include <valarray>
+#include "half_symbol_scheduler.h"
+
class MainWindow; //Forward declaration
// Thread gets audio data from soundcard and signals when a buffer of
@@ -21,7 +24,7 @@ protected:
virtual void run();
public:
- bool m_dataSinkBusy;
+ std::atomic_bool m_dataSinkBusy;
SoundInThread():
quitExecution(false),
diff --git a/map65/soundout.cpp b/map65/soundout.cpp
index 0828afe4..baa0d129 100644
--- a/map65/soundout.cpp
+++ b/map65/soundout.cpp
@@ -7,7 +7,7 @@
#include <portaudio.h>
extern float gran();
-extern short int (&iwave)[2*60*12000];
+extern short int iwave[2*60*12000]; //was 11025
extern int nwave;
extern bool btxok;
extern bool bTune;
@@ -37,24 +37,17 @@ extern "C" int d2aCallback(const void * /*inputBuffer*/, void *outputBuffer,
// step is ~0.229 for 48k ASIO, and exactly 1.0 for 11k MME
// Calculate step once outside the loop
- double step = 11025.0 / udata->streamSampleRate;
-
- // Debug: Check this value in your console once to ensure it's ~0.229 for ASIO
- static bool debugOnce = true;
- if(debugOnce) {
- qDebug() << "Stream Rate:" << udata->streamSampleRate << "Step:" << step;
- qDebug() << "channels:" << channels;
- debugOnce = false;
- }
-
+ double step = 11025.0 / udata->streamSampleRate;
+ const int waveCapacity = sizeof(iwave) / sizeof(iwave[0]);
static double ic_exact = 0.0;
static bool btxok0 = false;
static bool bTune0 = false;
static int nStart = 0;
static double phi = 0.;
-
- double tsec, tstart, dphi;
+
+ double tsec, tstart;
+ double dphi = 0.0;
int nsec;
int nTRperiod = udata->nTRperiod;
@@ -68,9 +61,9 @@ extern "C" int d2aCallback(const void * /*inputBuffer*/, void *outputBuffer,
qreal yAmp = txPower * 295.00 * amp;
static int nsec0 = 0;
- if(bTune) {
+ if(bTune) {
ic_exact = 0;
- // CHANGE: Use the actual stream sample rate, not 11025
+ // Use the actual stream sample rate, not 11025
dphi = 6.28318530718 * 1270.46 / udata->streamSampleRate;
}
@@ -104,34 +97,27 @@ extern "C" int d2aCallback(const void * /*inputBuffer*/, void *outputBuffer,
short int i2a = 0;
short int i2b = 0;
- // 2. Linear Interpolation to clean up the noise
-if (btxok && (2 * i1 + 1) < 1440000) {
+ int i0a = 2 * i0;
+ int i0b = i0a + 1;
+ int i1a = 2 * i1;
+ int i1b = i1a + 1;
+ bool haveWaveformSample = i1b < nwave && i1b < waveCapacity;
- // Interpolate message waveform
- qreal I = (1.0 - frac) * iwave[2*i0] + frac * iwave[2*i1];
- qreal Q = (1.0 - frac) * iwave[2*i0 + 1] + frac * iwave[2*i1 + 1];
+ if(btxok && (bTune || haveWaveformSample)) {
- if (bTune) {
- // --- TUNE MODE (unchanged) ---
+ if(bTune) {
phi += dphi;
- I = xAmp * qCos(phi);
- Q = yAmp * qSin(phi + dPhase);
-
- } else {
- // --- MESSAGE TX: scale using the Tune slider percentage ---
- qreal gain = txPower / 100.0; // 0.0 ? 1.0
-
- I *= gain;
- Q *= gain;
+ } else {
+ // 2. Linear Interpolation to clean up the noise
+ // Blend current sample (i0) and next sample (i1) based on frac
+ i2a = (short int)((1.0 - frac) * iwave[i0a] + frac * iwave[i1a]);
+ i2b = (short int)((1.0 - frac) * iwave[i0b] + frac * iwave[i1b]);
+ phi = qAtan2(qreal(i2b), qreal(i2a));
+ }
+ i2a = xAmp * qCos(phi);
+ i2b = yAmp * qSin(phi + dPhase);
}
- // Clamp to 16-bit
- i2a = short(qBound(-32768.0, I, 32767.0));
- i2b = short(qBound(-32768.0, Q, 32767.0));
-}
-
-
-
*wptr++ = i2b; // Left
*wptr++ = i2a; // Right
diff --git a/map65/widegraph.cpp b/map65/widegraph.cpp
index 40b650f2..ff3650b0 100644
--- a/map65/widegraph.cpp
+++ b/map65/widegraph.cpp
@@ -10,8 +10,9 @@
#include <QVBoxLayout>
#include "SettingsGroup.hpp"
#include "ui_widegraph.h"
+#include "globals.h"
-#define NFFT 32768
+extern int g_sampleRate;
WideGraph::WideGraph (QString const& settings_filename, QWidget * parent)
: QDialog {parent},
@@ -44,8 +45,20 @@ WideGraph::WideGraph (QString const& settings_filename, QWidget * parent)
int n = settings.value("FreqSpan",60).toInt();
int w = settings.value("PlotWidth",1000).toInt();
ui->freqSpanSpinBox->setValue(n);
+
+ if (g_sampleRate == 96000 || g_sampleRate == 95238)
+ setFreqSpanLimits(60, 90);
+ else
+ setFreqSpanLimits(60, 190);
+ updateSpanFromSpinbox();
+
+ extern int g_sampleRate; // at top of widegraph.cpp
ui->widePlot->setNSpan(n);
- int nbpp = n * 32768.0/(w*96.0) + 0.5;
+ double sr_kHz = g_sampleRate / 1000.0; // 96.0 or 192.0
+ int sr_display = int(sr_kHz + 0.5);
+ ui->srValueLabel->setText(QString::number(sr_display));
+ int nbpp = int(n * g_activeNfft / (w * sr_kHz) + 0.5);
+ if (nbpp < 1) nbpp = 1; // safety
ui->widePlot->setBinsPerPixel(nbpp);
m_waterfallAvg = settings.value("WaterfallAvg",10).toInt();
ui->waterfallAvgSpinBox->setValue(m_waterfallAvg);
@@ -172,6 +185,7 @@ void WideGraph::resizeEvent(QResizeEvent* ) //resizeEvent()
int w = size().width();
int h = size().height();
ui->labFreq->setGeometry(QRect(w-256,h-100,227,41));
+ updateSpanFromSpinbox();
}
void WideGraph::saveSettings()
@@ -211,7 +225,7 @@ void WideGraph::addDecodeLabel(double freq_khz, const QString& callsign,
lab.last_seen_ms = now;
// Only overwrite freq when the caller has sub-kHz precision.
// The "&" bandmap tap only has 3-char integer-kHz precision
- // (display.f90 cfreq0 is character(3) — no ndf field), so it
+ // (display.f90 cfreq0 is character(3) � no ndf field), so it
// would otherwise stomp on a precise "!" tick that already
// includes ndf, leaving the tick up to ~500 Hz off the signal.
if (freq_reliable) lab.freq_khz = freq_khz;
@@ -309,9 +323,9 @@ void WideGraph::setDecodeLabelPosition(DecodeLabelPosition p)
}
void WideGraph::dataSink2(float s[], int nkhz, int ihsym, int ndiskdata,
- uchar lstrong[])
+ uchar lstrong[], int lstrongSize)
{
- static float splot[NFFT];
+ static std::vector<float> splot;
float swide[2048];
float smax;
double df;
@@ -319,7 +333,10 @@ void WideGraph::dataSink2(float s[], int nkhz, int ihsym, int ndiskdata,
static int n=0;
static int nkhz0=-999;
static int ntrz=0;
- df = m_fSample/32768.0;
+
+ if ((int)splot.size() != g_activeNfft)
+ splot.assign(g_activeNfft, 0.0f);
+ df = double(g_sampleRate) / double(g_activeNfft);
if(nkhz != nkhz0) {
ui->widePlot->setNkhz(nkhz); //Why do we need both?
ui->widePlot->SetCenterFreq(nkhz); //Why do we need both?
@@ -329,35 +346,59 @@ void WideGraph::dataSink2(float s[], int nkhz, int ihsym, int ndiskdata,
//Average spectra over specified number, m_waterfallAvg
if (n==0) {
- for (int i=0; i<NFFT; i++)
+ for (int i=0; i<g_activeNfft; i++)
splot[i]=s[i];
} else {
- for (int i=0; i<NFFT; i++)
+ for (int i=0; i<g_activeNfft; i++)
splot[i] += s[i];
}
n++;
if (n>=m_waterfallAvg) {
- for (int i=0; i<NFFT; i++)
+ for (int i=0; i<g_activeNfft; i++)
splot[i] /= n; //Normalize the average
n=0;
int w=ui->widePlot->plotWidth();
qint64 sf = nkhz + ui->widePlot->freqOffset() - 0.5*w*nbpp*df/1000.0;
- if(sf != ui->widePlot->startFreq()) ui->widePlot->SetStartFreq(sf);
- int i0=16384.0+(ui->widePlot->startFreq()-nkhz+1.27046+0.001*m_fCal) *
- 1000.0/df + 0.5;
+ if (sf != ui->widePlot->startFreq())
+ ui->widePlot->SetStartFreq(sf);
+
+ int i0 = (g_activeNfft/2)
+ + (ui->widePlot->startFreq() - nkhz + 1.27046 + 0.001*m_fCal) * 1000.0/df
+ + 0.5;
+
+ // Clamp i0 into [0, g_activeNfft-1]
+ if (i0 < 0) i0 = 0;
+ if (i0 > g_activeNfft-1) i0 = g_activeNfft-1;
+
int i=i0;
- for (int j=0; j<2048; j++) {
- smax=0;
- for (int k=0; k<nbpp; k++) {
- i++;
+
+ // How many bins can we safely consume?
+ int maxBins = g_activeNfft - 1 - i0;
+ int maxCols = maxBins > 0 ? maxBins / nbpp : 0;
+ if (maxCols > 2048) maxCols = 2048;
+
+ for (int j = 0; j < maxCols; ++j) {
+ smax = 0.0f;
+ for (int k = 0; k < nbpp; ++k) {
+ ++i;
+ if (i >= g_activeNfft) break;
if(splot[i]>smax) smax=splot[i];
}
swide[j]=smax;
- if(lstrong[1 + i/32]!=0) swide[j]=-smax; //Tag strong signals
+
+ int binsPerStrongFlag = std::max(1, g_activeNfft / lstrongSize);
+ int li = 1 + i / binsPerStrongFlag;
+ if (li >= 0 && li < lstrongSize && lstrong[li] != 0)
+ swide[j] = -smax;
}
+ // Optionally zero any remaining swide entries if j < 2048
+ for (int j = maxCols; j < 2048; ++j)
+ swide[j] = 0.0f;
+
+
// Time according to this computer
qint64 ms = QDateTime::currentMSecsSinceEpoch() % 86400000;
int ntr = (ms/1000) % m_TRperiod;
@@ -366,12 +407,12 @@ void WideGraph::dataSink2(float s[], int nkhz, int ihsym, int ndiskdata,
for (int i=0; i<2048; i++) {
swide[i] = 1.e30;
}
- for (int i=0; i<32768; i++) {
+ for (int i=0; i<g_activeNfft; i++) {
splot[i] = 1.e30;
}
}
ntrz=ntr;
- ui->widePlot->draw(swide,i0,splot);
+ ui->widePlot->draw(swide,i0,splot.data());
}
}
@@ -380,15 +421,19 @@ void WideGraph::on_freqOffsetSpinBox_valueChanged(int f)
ui->widePlot->SetFreqOffset(f);
}
-void WideGraph::on_freqSpanSpinBox_valueChanged(int n)
+void WideGraph::on_freqSpanSpinBox_valueChanged(int)
{
- ui->widePlot->setNSpan(n);
- int w = ui->widePlot->plotWidth();
- int nbpp = n * 32768.0/(w*96.0) + 0.5;
- if(nbpp < 1) nbpp=1;
- if(w > 0) {
- ui->widePlot->setBinsPerPixel(nbpp);
- }
+ updateSpanFromSpinbox();
+}
+
+void WideGraph::setFreqSpanLimits(int min, int max)
+{
+ ui->freqSpanSpinBox->setMinimum(min);
+ ui->freqSpanSpinBox->setMaximum(max);
+
+ int v = ui->freqSpanSpinBox->value();
+ if (v < min) ui->freqSpanSpinBox->setValue(min);
+ if (v > max) ui->freqSpanSpinBox->setValue(max);
}
void WideGraph::on_waterfallAvgSpinBox_valueChanged(int n)
@@ -491,11 +536,6 @@ void WideGraph::setPalette(QString palette)
{
ui->widePlot->setPalette(palette);
}
-void WideGraph::setFsample(int n)
-{
- m_fSample=n;
- ui->widePlot->setFsample(n);
-}
void WideGraph::setMode65(int n)
{
@@ -607,3 +647,21 @@ void WideGraph::enableSetRxHardware(bool b)
{
ui->pbSetRxHardware->setEnabled(b);
}
+
+void WideGraph::updateSpanFromSpinbox()
+{
+ int n = ui->freqSpanSpinBox->value();
+
+ // Update NSpan
+ ui->widePlot->setNSpan(n);
+
+ // Recompute bins-per-pixel
+ int w = ui->widePlot->plotWidth();
+ int nbpp = int(n * g_activeNfft / (w * (g_sampleRate / 1000.0)) + 0.5);
+ if (nbpp < 1) nbpp = 1;
+
+ if (w > 0)
+ ui->widePlot->setBinsPerPixel(nbpp);
+}
+
+
diff --git a/map65/widegraph.h b/map65/widegraph.h
index 81f804a3..e96cb2c2 100644
--- a/map65/widegraph.h
+++ b/map65/widegraph.h
@@ -21,7 +21,7 @@ public:
~WideGraph();
void dataSink2(float s[], int nkhz, int ihsym, int ndiskdata,
- uchar lstrong[]);
+ uchar lstrong[], int lstrongSize);
int QSOfreq();
int nSpan();
int nStartFreq();
@@ -33,7 +33,6 @@ public:
void setTol(int n);
void setFcal(int n);
void setPalette(QString palette);
- void setFsample(int n);
void setMode65(int n);
void setPeriod(int n);
void setDecodeFinished();
@@ -42,6 +41,9 @@ public:
void tx570();
void updateFreqLabel();
void enableSetRxHardware(bool b);
+ void setFreqSpanLimits(int min, int max);
+ void updateSpanFromSpinbox();
+
// Decoded-callsign overlay (N6NU 2026-05-12, port of QMAP feature).
// mainwindow calls addDecodeLabel for each decoded line (after
@@ -125,7 +127,6 @@ private:
bool m_bIQxt;
qint32 m_waterfallAvg;
qint32 m_fCal;
- qint32 m_fSample;
qint32 m_mode65;
qint32 m_TRperiod=60;
diff --git a/map65/widegraph.ui b/map65/widegraph.ui
index 38f90d47..ca14671a 100644
--- a/map65/widegraph.ui
+++ b/map65/widegraph.ui
@@ -74,6 +74,32 @@ Tx: 144.127.317</string>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QLabel" name="srLabel">
+ <property name="text">
+ <string>SR</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="srValueLabel">
+ <property name="minimumSize">
+ <size>
+ <width>30</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>96</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignLeft|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
@@ -157,7 +183,7 @@ Tx: 144.127.317</string>
<number>5</number>
</property>
<property name="maximum">
- <number>90</number>
+ <number>190</number>
</property>
<property name="singleStep">
<number>5</number>
diff --git a/map65/wsjt.ico b/map65/wsjt.ico
index 8a55550f..3f736a9c 100644
--- a/map65/wsjt.ico
+++ b/map65/wsjt.ico
Binary files differ