summaryrefslogtreecommitdiff
path: root/map65/libm65/q65b.F90
diff options
context:
space:
mode:
Diffstat (limited to 'map65/libm65/q65b.F90')
-rw-r--r--map65/libm65/q65b.F90120
1 files changed, 63 insertions, 57 deletions
diff --git a/map65/libm65/q65b.F90 b/map65/libm65/q65b.F90
index 7f28f0f3..94ee0fb8 100644
--- a/map65/libm65/q65b.F90
+++ b/map65/libm65/q65b.F90
@@ -6,9 +6,61 @@
! on stdout.
module q65b_mod
+ use iso_fortran_env, only: int16, real64
implicit none
+ integer, parameter, private :: MAXFFT2 = 336000*2
contains
+ subroutine build_q65_samples(k0, nfft2, df, xpol, configured_dphi_deg, combine_poldeg, iwave)
+ use cacb_mod, only: ca, cb
+ use four2a_mod, only: four2a
+ integer, intent(in) :: k0, nfft2, configured_dphi_deg
+ real, intent(in) :: df, combine_poldeg
+ logical, intent(in) :: xpol
+ integer(int16), intent(out) :: iwave(:)
+ real(real64), parameter :: RAD = 57.2957795
+ complex :: cx(0:MAXFFT2-1), cy(0:MAXFFT2-1), cz(0:MAXFFT2)
+ save cx, cy, cz
+ integer :: i, j, ja, jb
+ real :: dphi, fac, r
+
+ fac = 1.0/nfft2
+ cx(0:nfft2 - 1) = ca(k0:k0 + nfft2 - 1)
+ cx = fac*cx
+ 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
+ cy(0:nfft2 - 1) = cmplx(cos(dphi), sin(dphi))*cy(0:nfft2 - 1)
+ endif
+ endif
+
+ if (xpol) then
+ cz(0:MAXFFT2 - 1) = cos(combine_poldeg/RAD)*cx + sin(combine_poldeg/RAD)*cy
+ else
+ cz(0:MAXFFT2 - 1) = cx
+ endif
+
+ cz(MAXFFT2) = 0.
+ ja = nint(500.0/df)
+ jb = nint(2500.0/df)
+ do i = 0, ja
+ r = 0.5*(1.0 + cos(i*3.14159/ja))
+ cz(ja - i) = r*cz(ja - i)
+ cz(jb + i) = r*cz(jb + i)
+ enddo
+ cz(ja + jb + 1:) = 0.
+
+ call four2a(cz, 2*nfft2, 1, 1, -1)
+ do i = 0, nfft2 - 1
+ j = nfft2 - 1 - i
+ 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
+ end subroutine build_q65_samples
+
subroutine write_wav_header(unit, nsamp, fs)
integer, intent(in) :: unit, nsamp, fs
integer :: datasize, file_size
@@ -41,6 +93,7 @@
use timer_module, only: timer
use debug_log
use stdout_channel_mod, only: write_stdout
+ use message_history_mod, only: append_message
use decodes_mod, only: ldecoded, ndecodes
use cacb_mod
use four2a_mod
@@ -84,13 +137,10 @@
! 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
!==== Local variables =====================================================
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
@@ -98,13 +148,13 @@
! 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, nfft1, nfft2
+ integer :: ia, ib, ifreq, ikhz1, ipk, ipol
+ integer :: k0, mhz, ndf, nfft1, nfft2
integer :: npol, nq65df, nsubmode, ntxpol, nutc00, nh
integer :: nfa, nfb
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 :: df, df3, f_ipk, f_mouse
+ real :: combine_poldeg, freq1_00, frx, fsked, poldeg, snr1
real(real64) :: freq0, freq1
character(len=12) :: mycall, hiscall
character(len=4) :: grid4
@@ -112,6 +162,7 @@
character(len=1) :: cp
character(len=2) :: cmode
character(len=256) :: linenew
+ character(len=83) :: history_line
integer :: t_now, t_rate
logical :: search_cursor
@@ -272,62 +323,16 @@
! (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)
- cx = fac*cx
- 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
-! QSO frequency, taken from the full-length FFT computed in filbig().
-! Values for fsample, nfft1, nfft2, df, and the downsampled data rate
-! are as follows:
-
-! fSample nfft1 df nfft2 fDownSampled
-! (Hz) (Hz) (Hz)
-!----------------------------------------------------
-! 96000 5376000 0.017857143 336000 6000.000
-! 95238 5120000 0.018601172 322560 5999.994
-
poldeg = 0.
+ combine_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
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
-
- cz(MAXFFT2) = 0.
-! Roll off below 500 Hz and above 2500 Hz.
- ja = nint(500.0/df)
- jb = nint(2500.0/df)
- do i = 0, ja
- r = 0.5*(1.0 + cos(i*3.14159/ja))
- cz(ja - i) = r*cz(ja - i)
- cz(jb + i) = r*cz(jb + i)
- enddo
- cz(ja + jb + 1:) = 0.
-
-!Transform to time domain (real), fsample=12000 Hz
- call four2a(cz, 2*nfft2, 1, 1, -1)
- do i = 0, nfft2 - 1
- j = nfft2 - 1 - i
- 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
+ call build_q65_samples(k0, nfft2, df, xpol, configured_dphi_deg, combine_poldeg, iwave)
nsubmode = mode_q65 - 1
nfa = 990 !Tight limits around ipk for the wideband decode
@@ -394,13 +399,14 @@
call write_stdout(trim(linenew)//new_line('a'))
endif
-! Write to lu 26, for Messages and Band Map windows
+! Retain wideband decodes for Messages and Band Map.
cmode = ': '
cmode(2:2) = char(ichar('A') + mode_q65 - 1)
freq1 = freq0 + 0.001d0*(ikhz1 - ikhz)
- write (26, 1014) freq1, ndf, 0, 0, 0, xdt0, npol, 0, nsnr0, nutc, msg0(1:28), &
+ write (history_line, 1014) freq1, ndf, 0, 0, 0, xdt0, npol, 0, nsnr0, nutc, msg0(1:28), &
':', cp, cmode ! was 1:22
1014 format(f8.3, i5, 3i3, f5.1, i4, i3, i4, i5.4, 4x, a28, 1x, 2a1, 2x, a2) ! was a22
+ call append_message(history_line, nutc, freq1, ndf)
! Suppress writing duplicates (same time, decoded message, and frequency)
! to map65_rx.log