1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
! Shared params init — factored from WAV-path (jt9.f90:474-554),
! stream-mode dispatch arm (jt9.f90:298-388), and streaming_io.f90:130-190.
!
! Eliminates the structural drift surface that arose from hand-copying
! a baseline-init block into streaming_io.f90. Now both the WAV-decoder and
! streaming-decoder paths route through one source of truth.
!
! Scope discipline:
! - init_default_params sets ONLY fields the pre-refactor WAV path was
! setting (the "common" subset). This preserves WAV byte-identical
! behavior under run-golden-fixtures.sh — the regression gate.
! - init_streaming_extra_fields sets the additional fields the pre-refactor
! streaming dispatch arm (jt9.f90:298-388) set beyond the common set.
! Streaming callers do init_default_params THEN init_streaming_extra_fields.
! - The WAV multift8-only block at jt9.f90:519-554 stays inline (out of
! scope). It sets some of the same fields init_streaming_extra_fields
! sets, but with multift8-specific logic; not factored here.
!
! Public surface:
! init_default_params(params, mode, TRperiod, args)
! Common-subset init. Always called first.
!
! init_streaming_extra_fields(params, args)
! Extra fields needed by the streaming subprocess path. Streaming
! callers call this AFTER init_default_params.
!
! apply_per_mode_policy(params, mode, TRperiod)
! Per-mode ntol cap + Q65 60s emedelay. Called from init_default_params,
! and from streaming_apply's apply_configure_fields on mode/trperiod change.
!
! Per-mode invariants preserved (each documented inline at the policy site):
! - FST4/FST4W (mode 241/242): ntol = min(ntol, 100)
! - JT65+JT9 combined (mode 74): ntol hard = 20 unless -F supplied (have_ntol)
! - Q65 (mode 66): ntol hard = 10 unless -F supplied; emedelay = 2.5 when TRperiod = 60
! - All other modes: ntol = min(ntol, 1000)
! - FST4 60s (mode 240): kin = 720000 (init-only; not in policy sub)
! - JT9 with explicit -S<HZ> (mode 9 ∧ fsplit ≠ 2700): nfa = fsplit
! (init-only; not in policy sub since fsplit isn't in apply_configure_fields'
! scope today)
module jt9_params_init
use, intrinsic :: iso_c_binding, only: c_int, c_short, c_float, c_char, c_bool
include 'jt9com.f90'
private
public :: init_default_params
public :: init_streaming_extra_fields
public :: apply_per_mode_policy
public :: cli_args_t
! CLI-arg bundle threaded through to the params init. Defaults match
! jt9.f90's local-var defaults (lines 30-32) so a bare call (with all
! args at default) produces the same shape as un-flagged jt9 invocation.
type :: cli_args_t
integer :: flow = 200
integer :: fsplit = 2700
integer :: fhigh = 4000
integer :: nrxfreq = 1500
integer :: ndepth = 1
integer :: ntol = 1000 ! caller pre-clamps; per-mode policy applies on top
integer :: nQSOProg = 0
integer :: nexp_decode = 0
integer :: ncycles = 3
integer :: nft8rxfsens = 3
integer :: nmt = 0
integer :: ndecoderstart = 3
integer :: nsubmode = 0
character(len=12) :: mycall = ' '
character(len=12) :: hiscall = ' '
character(len=6) :: mygrid = ' '
character(len=6) :: hisgrid = ' '
character(len=20) :: datetime = '2026-Apr-25 00:00 '
logical :: tx9 = .false.
logical :: multift8 = .false.
logical :: hidedupes = .false.
logical :: lft8lowth = .true.
logical :: lft8subpass = .true.
logical :: lwidedxcsearch = .true.
logical :: have_ntol = .false. ! tracks whether -F was supplied
logical :: nexp_decode_set = .false. ! tracks whether --exp-decode was supplied
end type cli_args_t
contains
! Common-subset init. Sets the fields the pre-refactor WAV path was
! setting, plus the per-mode policy outcomes (ntol cap, emedelay,
! kin mode=240 override, nfa mode=9-fsplit override).
!
! Caller-specific overrides happen AFTER the call:
! - WAV path: nutc (filename), ndiskdat=.true., nzhsym=nhsym (per-period),
! nmode=65+9 if mode=0
! - Streaming dispatch: ndiskdat=.false. (default; jt9_stream overrides
! via init_streaming_extra_fields side-effect or its own override)
subroutine init_default_params(params, mode, TRperiod, args)
type(params_block), intent(out) :: params
integer, intent(in) :: mode
real(8), intent(in) :: TRperiod
type(cli_args_t), intent(in) :: args
! Common-subset structural defaults (preserves pre-refactor WAV scope).
params%nutc = 0 ! caller may overwrite (filename)
params%ndiskdat = .false. ! caller may overwrite
params%ntr = int(TRperiod)
params%nQSOProgress = args%nQSOProg
params%nfqso = args%nrxfreq
params%newdat = .true.
params%npts8 = 74736
params%nfa = args%flow
params%nfsplit = args%fsplit
params%nfb = args%fhigh
params%ntol = args%ntol ! per-mode policy applies below
params%kin = 64800 ! mode=240 override below
params%nzhsym = 50 ! caller may overwrite per-period
params%nsubmode = args%nsubmode
params%nagain = .false.
params%b_even_seq = .false.
params%b_superfox = .false.
params%ndepth = args%ndepth
params%lft8apon = .true.
params%lapcqonly = .false.
params%ljt65apon = .true.
params%napwid = 75
if (args%tx9) then
params%ntxmode = 9
else
params%ntxmode = 65
end if
params%nmode = mode ! caller may overwrite (WAV mode=0 → 65+9)
params%nclearave = .false.
params%emedelay = 0.0 ! per-mode policy may override
params%dttol = 3.
params%n2pass = 2
params%nranera = 6
params%naggressive = 0
params%nrobust = .false.
params%nexp_decode = args%nexp_decode
params%datetime = transfer(args%datetime, params%datetime)
params%mycall = transfer(args%mycall, params%mycall)
params%mygrid = transfer(args%mygrid, params%mygrid)
params%hiscall = transfer(args%hiscall, params%hiscall)
params%hisgrid = transfer(args%hisgrid, params%hisgrid)
params%lmultift8 = args%multift8
! Per-mode init-only adjustments (NOT folded into apply_per_mode_policy
! because they reference CLI args (fsplit) or are mode-specific to a
! degree the post-configure policy doesn't need to revisit).
! FST4 60s period uses a larger sample window (jt9.f90:485 in WAV path).
if (mode .eq. 240) params%kin = 720000
if(mode==4) then
params%kin=624000
params%minw=0
params%minsync=0
endif
! JT9 with explicit -S<HZ>: remap nfa to fsplit (jt9.f90:386, :560).
if (mode .eq. 9 .and. args%fsplit .ne. 2700) params%nfa = args%fsplit
! Init-time ntol cap (per-mode). Streaming-config-time ntol policy
! lives in apply_configure_fields where it can branch on consumer-set vs
! mode-default (see streaming_apply.f90).
if (mode .eq. 241 .or. mode .eq. 242) then
params%ntol = min(args%ntol, 100) ! FST4/FST4W
else if (mode .eq. 65 + 9 .and. .not. args%have_ntol) then
params%ntol = 20 ! JT65+JT9 hard (unless -F given)
else if (mode .eq. 66 .and. .not. args%have_ntol) then
params%ntol = 10 ! Q65 hard (unless -F given)
else
params%ntol = min(args%ntol, 1000) ! FT8/FT4/etc
end if
! Q65 60s emedelay (the only piece left in apply_per_mode_policy
! — ntol moved out).
call apply_per_mode_policy(params, mode, TRperiod)
end subroutine init_default_params
! Streaming-only extras. Mirrors fields the pre-refactor stream-dispatch
! arm (jt9.f90:298-388) set beyond the common set. NOT called by WAV
! callers — those leave these fields at their bind(C) default state
! (matching pre-refactor WAV behavior; the multift8-only block in WAV
! will set a subset of these for multift8 mode).
subroutine init_streaming_extra_fields(params, args)
type(params_block), intent(inout) :: params
type(cli_args_t), intent(in) :: args
! Tx-side companion to nfqso (WAV path leaves this uninit; streaming sets it).
params%nftx = args%nrxfreq
params%minw = 1
if(params%nmode==4.and.params%nsubmode==0) params%minw=0
params%minsync = 0
params%nlist = 0
params%max_drift = 0
params%lft8lowth = args%lft8lowth
params%lft8subpass = args%lft8subpass
params%lwidedxcsearch = args%lwidedxcsearch
params%lhound = .false.
params%lcommonft8b = .true.
params%lhideft8dupes = args%hidedupes
params%nft8cycles = args%ncycles
params%nft8rxfsens = args%nft8rxfsens
params%nmt = args%nmt
params%ndecoderstart = args%ndecoderstart
params%ncandthin = 100
params%ndtcenter = 0
params%nharmonicsdepth = 0
params%nprepass = 4
params%nsdecatt = 1
params%nlasttx = 0
params%ndelay = 0
params%nsecbandchanged = 0
params%nagainfil = .false.
params%nstophint = .false.
params%nhint = .false.
params%fmaskact = .false.
params%ltxing = .false.
params%lmycallstd = .true.
params%lhiscallstd = .true.
params%lapmyc = .false.
params%lmodechanged = .false.
params%lbandchanged = .false.
params%lenabledxcsearch= .true.
params%lmultinst = .false.
params%lskiptx1 = .false.
end subroutine init_streaming_extra_fields
! Per-mode policy that runs both at init AND on configure-frame mode/trperiod
! changes. Currently only Q65 60s emedelay (ntol was moved out since the
! cap-vs-restore semantics differ between init and config-time).
! Idempotent.
subroutine apply_per_mode_policy(params, mode, TRperiod)
type(params_block), intent(inout) :: params
integer, intent(in) :: mode
real(8), intent(in) :: TRperiod
! Q65 60s mode requires 2.5s eme-delay; other modes 0.0.
if (mode .eq. 66 .and. TRperiod .eq. 60.d0) then
params%emedelay = 2.5
else
params%emedelay = 0.0
end if
end subroutine apply_per_mode_policy
end module jt9_params_init
|