summaryrefslogtreecommitdiff
path: root/map65/libm65/decode0.f90
diff options
context:
space:
mode:
Diffstat (limited to 'map65/libm65/decode0.f90')
-rw-r--r--map65/libm65/decode0.f90143
1 files changed, 125 insertions, 18 deletions
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