diff options
Diffstat (limited to 'lib/jt9.f90')
| -rw-r--r-- | lib/jt9.f90 | 308 |
1 files changed, 216 insertions, 92 deletions
diff --git a/lib/jt9.f90 b/lib/jt9.f90 index 64901c09..be09716b 100644 --- a/lib/jt9.f90 +++ b/lib/jt9.f90 @@ -10,11 +10,22 @@ program jt9 use timer_module, only: timer use timer_impl, only: init_timer, fini_timer use readwav + use jt9_input_validation, only: parse_integer, parse_real, parse_wav_filename_nutc + use, intrinsic :: iso_fortran_env, only: error_unit use ft8_mod1, only : dd8 use jt65_mod6, only : dd + use streaming_emit, only: streaming_emit_set_enabled, streaming_emit_error + use jt9_params_init, only: init_default_params, init_streaming_extra_fields, & + apply_per_mode_policy, cli_args_t include 'jt9com.f90' + interface + subroutine jt9_print_version() bind(C, name='jt9_print_version') + end subroutine jt9_print_version + end interface + + type(cli_args_t) :: args integer*2 id2a(180000) integer(C_INT) iret type(wav_header) wav @@ -28,18 +39,24 @@ program jt9 integer :: arglen,stat,offset,remain,mode=0,flow=200,fsplit=2700, & fhigh=4000,nrxfreq=1500,ndepth=1,nexp_decode=0,nQSOProg=0,ncycles=3, & - nft8rxfsens=3,nmt=0,nmtft8decsens=3,ndecoderstart=3 + nft8rxfsens=3,nmt=0,nmtft8decsens=3,ndecoderstart=3, samples_read, wav_status logical :: read_files = .true., tx9 = .false., display_help = .false., & + display_version = .false., & bLowSidelobes = .false., nexp_decode_set = .false., & have_ntol = .false.,multift8 = .false.,hidedupes = .false., & - lft8lowth = .true.,lft8subpass = .true.,lwidedxcsearch = .true. - type (option) :: long_options(41) = [ & + lft8lowth = .true.,lft8subpass = .true.,lwidedxcsearch = .true., & + stream_mode = .false. + type (option) :: long_options(43) = [ & option ('help', .false., 'h', 'Display this help message', ''), & + option ('version', .false., 'v', 'Display version and build revision', ''),& option ('shmem',.true.,'s','Use shared memory for sample data','KEY'), & + option ('stream', .false., '0', & + 'Read framed PCM samples from stdin', & + ''), & option ('tr-period', .true., 'p', 'Tx/Rx period, default SECONDS=60', & 'SECONDS'), & option ('executable-path', .true., 'e', & - 'Location of subordinate executables (KVASD) default PATH="."', & + 'Location of subordinate executables, default PATH="."', & 'PATH'), & option ('data-path', .true., 'a', & 'Location of writeable data files, default PATH="."', 'PATH'), & @@ -107,7 +124,6 @@ program jt9 'FLAGS') ] type(dec_data), allocatable :: shared_data - character(len=20) :: datetime='' character(len=12) :: mycall='K1ABC', hiscall='W9XYZ' character(len=6) :: mygrid='', hisgrid='EN37' common/patience/npatience,nthreads @@ -119,7 +135,7 @@ program jt9 TRperiod=60.d0 do - call getopt('hs:e:a:b:r:m:p:d:f:F:w:t:9876543WYqkTMUSZL:S:H:c:G:x:g:X:Q:C:R:N:E:D:', & + call getopt('hvs:e:a:b:r:m:p:d:f:F:w:t:9876543WYqkTMUSZL:S:H:c:G:x:g:X:Q:C:R:N:E:D:', & long_options,c,optarg,arglen,stat,offset,remain,.true.) if (stat .ne. 0) then exit @@ -127,48 +143,59 @@ program jt9 select case (c) case ('h') display_help = .true. + case ('v') + display_version = .true. case ('s') read_files = .false. shm_key = optarg(:arglen) + case ('0') + read_files = .false. + stream_mode = .true. + call streaming_emit_set_enabled(.true.) case ('e') exe_dir = optarg(:arglen) case ('a') data_dir = optarg(:arglen) + case ('r') + share_dir = optarg(:arglen) ! read-only shipped-data dir (cty.dat, ALLCALL7.TXT, ...) case ('b') nsubmode = ichar (optarg(:1)) - ichar ('A') case ('t') temp_dir = optarg(:arglen) case ('m') - read (optarg(:arglen), *) nthreads + call require_integer('m', optarg(:arglen), nthreads) case ('p') - read (optarg(:arglen), *) TRperiod + call require_real('p', optarg(:arglen), TRperiod) + if (TRperiod <= 0.d0 .or. TRperiod > dble(NTMAX)) then + call invalid_option('p', optarg(:arglen), 'must be between 0 and 1800 seconds') + end if case ('d') - read (optarg(:arglen), *) ndepth + call require_integer('d', optarg(:arglen), ndepth) case ('f') - read (optarg(:arglen), *) nrxfreq + call require_integer('f', optarg(:arglen), nrxfreq) case ('F') - read (optarg(:arglen), *) ntol + call require_integer('F', optarg(:arglen), ntol) have_ntol = .true. case ('L') - read (optarg(:arglen), *) flow + call require_integer('L', optarg(:arglen), flow) case ('S') - read (optarg(:arglen), *) fsplit + call require_integer('S', optarg(:arglen), fsplit) case ('H') - read (optarg(:arglen), *) fhigh + call require_integer('H', optarg(:arglen), fhigh) case ('M') multift8 = .true. case ('C') - read (optarg(:arglen), *) ncycles + call require_integer('C', optarg(:arglen), ncycles) case ('U') hidedupes = .true. case ('R') - read (optarg(:arglen), *) nft8rxfsens + call require_integer('R', optarg(:arglen), nft8rxfsens) case ('N') - read (optarg(:arglen), *) nmt + call require_integer('N', optarg(:arglen), nmt) case ('E') - read (optarg(:arglen), *) nmtft8decsens + call require_integer('E', optarg(:arglen), nmtft8decsens) case ('D') - read (optarg(:arglen), *) ndecoderstart + call require_integer('D', optarg(:arglen), ndecoderstart) case ('Z') lwidedxcsearch = .false. case ('q') @@ -176,7 +203,10 @@ program jt9 case ('k') mode = 144 case ('Q') - read (optarg(:arglen), *) nQSOProg + call require_integer('Q', optarg(:arglen), nQSOProg) + if (nQSOProg < 0 .or. nQSOProg > 5) then + call invalid_option('Q', optarg(:arglen), 'must be between 0 and 5') + end if case ('3') mode = 66 case ('4') @@ -194,7 +224,7 @@ program jt9 case ('T') tx9 = .true. case ('w') - read (optarg(:arglen), *) npatience + call require_integer('w', optarg(:arglen), npatience) case ('W') mode = 241 case ('Y') @@ -208,10 +238,15 @@ program jt9 case ('g') read (optarg(:arglen), *) hisgrid case ('X') - read (optarg(:arglen), *) nexp_decode + call require_integer('X', optarg(:arglen), nexp_decode) nexp_decode_set = .true. end select end do + + if (display_version) then + call jt9_print_version() + stop + endif if (display_help .or. stat .lt. 0 & .or. (.not. read_files .and. remain .gt. 0) & @@ -220,9 +255,12 @@ program jt9 print *, 'Usage: jt9 [OPTIONS] file1 [file2 ...]' print *, ' Reads data from *.wav files.' print *, '' - print *, ' jt9 -s <key> [-w patience] [-m threads] [-e path] [-a path] [-t path]' + print *, ' jt9 -s <key> [-w patience] [-m threads] [-e path] [-a path] [-t path] [-r path]' print *, ' Gets data from shared memory region with key==<key>' print *, '' + print *, ' cat <pcm-stream> | jt9 --stream' + print *, ' Reads framed PCM samples from stdin.' + print *, '' print *, 'OPTIONS:' print *, '' do i = 1, size (long_options) @@ -248,7 +286,67 @@ program jt9 numfano=0 if (.not. read_files) then - call jt9a() !We're running under control of WSJT-X + if (stream_mode) then + ! Streaming subprocess mode. Mirror the WAV path's shared_data setup, + ! then hand off to the streaming reader. + if (mode .eq. 0) then + mode = 8 ! default: FT8 + if (TRperiod .eq. 60.d0) TRperiod = 15.d0 + end if + if (mode .eq. 5 .and. TRperiod .eq. 60.d0) TRperiod = 7.5d0 ! FT4 + if (mode .eq. 144 .and. TRperiod .eq. 60.d0) TRperiod = 30.d0 ! MSK144 + + ! Per-mode ntol defaulting (mirrors WAV path lines 277–285). + if (mode .eq. 241 .or. mode .eq. 242) then + ntol = min(ntol, 100) + else if (mode .eq. 65 + 9 .and. .not. have_ntol) then + ntol = 20 + else if (mode .eq. 66 .and. .not. have_ntol) then + ntol = 10 + else + ntol = min(ntol, 1000) + end if + + ! Per-mode nexp_decode default (mirrors WAV path lines 287–291). + if (.not. nexp_decode_set) then + if (mode .eq. 240 .or. mode .eq. 241 .or. mode .eq. 242) then + nexp_decode = 3 * 256 ! FST4: single decode off, nb=0 + end if + end if + + if (mycall.eq.'b') mycall = ' ' + if (hiscall.eq.'b') then + hiscall = ' ' + hisgrid = ' ' + end if + allocate(shared_data) + call init_timer (trim(data_dir)//'/timer.out') + shared_data%id2 = 0 + + ! Common params first, then streaming-only fields. + args = cli_args_t( & + flow=flow, fsplit=fsplit, fhigh=fhigh, nrxfreq=nrxfreq, & + ndepth=ndepth, ntol=ntol, nQSOProg=nQSOProg, & + nexp_decode=nexp_decode, ncycles=ncycles, & + nft8rxfsens=nft8rxfsens, nmt=nmt, ndecoderstart=ndecoderstart, & + nsubmode=nsubmode, mycall=mycall, hiscall=hiscall, & + mygrid=mygrid, hisgrid=hisgrid, & + datetime='2026-Apr-25 00:00 ', & + tx9=tx9, multift8=.false., hidedupes=.false., & + lft8lowth=.true., lft8subpass=.true., & + lwidedxcsearch=lwidedxcsearch, have_ntol=have_ntol, & + nexp_decode_set=nexp_decode_set) + call init_default_params(shared_data%params, mode, TRperiod, args) + call init_streaming_extra_fields(shared_data%params, args) + + ! Streaming-side overrides post-init. + ! (mode=9 nfa=fsplit handled by init_default_params per-mode adjustment.) + ! (single-pass FT8 only in stream — already enforced via args.multift8=.false.) + + call jt9_stream(shared_data, mode, TRperiod) + else + call jt9a() !We're running under control of WSJT-X (shared memory) + end if go to 999 endif @@ -279,18 +377,20 @@ program jt9 do iarg = offset + 1, offset + remain call get_command_argument (iarg, optarg, arglen) infile = optarg(:arglen) - call wav%read (infile) + call wav%read (infile, wav_status, optarg) + if (wav_status /= 0) then + write(error_unit, '(A)') 'jt9: cannot read WAV file ' // trim(infile) // ': ' // trim(optarg) + stop 2 + end if nfsample=wav%audio_format%sample_rate - i1=index(infile,'.wav') - if(i1.lt.1) i1=index(infile,'.WAV') - if(infile(i1-5:i1-5).eq.'_') then - read(infile(i1-4:i1-1),*,err=1) nutc - else - read(infile(i1-6:i1-1),*,err=1) nutc - endif - go to 2 -1 nutc=0 -2 nsps=6912 + if (nfsample /= 12000 .and. .not. (mode == 4 .and. nfsample == 11025)) then + close(unit=wav%lun) + write(error_unit, '(A,I0,A)') 'jt9: unsupported ',nfsample, & + ' Hz WAV sample rate for the selected mode' + stop 2 + end if + call parse_wav_filename_nutc(infile, nutc) + nsps=6912 npts=TRperiod*12000.d0 kstep=nsps/2 k=0 @@ -301,18 +401,29 @@ program jt9 call timer('jt9 ',0) endif shared_data%id2=0 !??? Why is this necessary ??? + if(mode.eq.4) npts=52*nfsample if(mode.eq.5) npts=21*3456 if(mode.eq.66) npts=TRperiod*12000 - do iblk=1,npts/kstep - k=iblk*kstep + nblocks=npts/kstep + if(mode.eq.4) nblocks=(npts+kstep-1)/kstep + do iblk=1,nblocks + k0=(iblk-1)*kstep + k=min(iblk*kstep,npts) if(mode.eq.8 .and. k.gt.179712) exit call timer('read_wav',0) - read(unit=wav%lun,end=3) shared_data%id2(k-kstep+1:k) - go to 4 -3 call timer('read_wav',1) - print*,'EOF on input file ',trim(infile) - exit -4 call timer('read_wav',1) + call wav%read_samples(shared_data%id2(k0+1:k), samples_read, & + wav_status, optarg) + call timer('read_wav',1) + if (wav_status /= 0) then + close(unit=wav%lun) + write(error_unit, '(A)') 'jt9: cannot read WAV file ' // & + trim(infile) // ': ' // trim(optarg) + stop 2 + end if + if (samples_read == 0) then + print*,'EOF on input file ',trim(infile) + exit + end if nhsym=(k-2048)/kstep if(nhsym.ge.1 .and. nhsym.ne.nhsym0) then if(mode.eq.9 .or. mode.eq.74) then @@ -328,53 +439,38 @@ program jt9 if(nhsym.ge.181 .and. mode.ne.240 .and. mode.ne.241 .and. & mode.ne.242 .and. mode.ne.66) exit endif + if (samples_read < k-k0) then + print*,'EOF on input file ',trim(infile) + exit + end if enddo close(unit=wav%lun) - shared_data%params%nutc=nutc - shared_data%params%ndiskdat=.true. - shared_data%params%ntr=TRperiod - shared_data%params%nfqso=nrxfreq - shared_data%params%newdat=.true. - shared_data%params%npts8=74736 - shared_data%params%nfa=flow - shared_data%params%nfsplit=fsplit - shared_data%params%nfb=fhigh - shared_data%params%ntol=ntol - shared_data%params%kin=64800 - if(mode.eq.240) shared_data%params%kin=720000 !### 60 s periods ### - shared_data%params%nzhsym=nhsym - shared_data%params%ndepth=ndepth - shared_data%params%lft8apon=.true. - shared_data%params%ljt65apon=.true. - shared_data%params%napwid=75 - shared_data%params%dttol=3. - if(mode.eq.164 .and. nsubmode.lt.100) nsubmode=nsubmode+100 - shared_data%params%nagain=.false. - shared_data%params%nclearave=.false. - shared_data%params%lapcqonly=.false. - shared_data%params%naggressive=0 - shared_data%params%n2pass=2 - shared_data%params%nQSOprogress=nQSOProg - shared_data%params%nranera=6 !### ntrials=3000 - shared_data%params%nrobust=.false. - shared_data%params%nexp_decode=nexp_decode - shared_data%params%lmultift8=multift8 - shared_data%params%mycall=transfer(mycall,shared_data%params%mycall) - shared_data%params%mygrid=transfer(mygrid,shared_data%params%mygrid) - shared_data%params%hiscall=transfer(hiscall,shared_data%params%hiscall) - shared_data%params%hisgrid=transfer(hisgrid,shared_data%params%hisgrid) - if (tx9) then - shared_data%params%ntxmode=9 - else - shared_data%params%ntxmode=65 - end if - if (mode.eq.0) then - shared_data%params%nmode=65+9 - else - shared_data%params%nmode=mode - end if - shared_data%params%nsubmode=nsubmode + ! WAV-path-only mode adjustment (mode=164 with submode<100 bumps by 100). + ! Hoisted before init_default_params so the bumped value is threaded + ! through the args bundle. + if (mode.eq.164 .and. nsubmode.lt.100) nsubmode = nsubmode + 100 + + ! WAV mode initializes only fields historically set by this path. + args = cli_args_t( & + flow=flow, fsplit=fsplit, fhigh=fhigh, nrxfreq=nrxfreq, & + ndepth=ndepth, ntol=ntol, nQSOProg=nQSOProg, & + nexp_decode=nexp_decode, ncycles=ncycles, & + nft8rxfsens=nft8rxfsens, nmt=nmt, ndecoderstart=ndecoderstart, & + nsubmode=nsubmode, mycall=mycall, hiscall=hiscall, & + mygrid=mygrid, hisgrid=hisgrid, & + datetime='2013-Apr-16 15:13 ', & + tx9=tx9, multift8=multift8, hidedupes=hidedupes, & + lft8lowth=lft8lowth, lft8subpass=lft8subpass, & + lwidedxcsearch=lwidedxcsearch, have_ntol=have_ntol, & + nexp_decode_set=nexp_decode_set) + call init_default_params(shared_data%params, mode, TRperiod, args) + + ! WAV-path post-init overrides. + shared_data%params%nutc = nutc ! parsed from filename + shared_data%params%ndiskdat = .true. ! reading from disk + shared_data%params%nzhsym = nhsym ! per-period (matches former jt9.f90:486) + if (mode.eq.0) shared_data%params%nmode = 65 + 9 ! WAV-only mode=0 → JT65+JT9 if (multift8 .and. mode.eq.8) then shared_data%params%lft8subpass = .true. @@ -412,12 +508,9 @@ program jt9 shared_data%params%nsdecatt = 1 !print*,'lwidedxcsearch ',shared_data%params%lwidedxcsearch end if -!### temporary, for MAP65: - if(mode.eq.66 .and. TRperiod.eq.60) shared_data%params%emedelay=2.5 + ! emedelay (Q65 60s), datetime placeholder, and mode=9 nfa=fsplit + ! handled by init_default_params + apply_per_mode_policy above. - datetime="2013-Apr-16 15:13" !### Temp - shared_data%params%datetime=transfer(datetime,shared_data%params%datetime) - if(mode.eq.9 .and. fsplit.ne.2700) shared_data%params%nfa=fsplit nearly=50 if(mode.eq.8 .and. .not. shared_data%params%lmultift8) then ! "Early" decoding pass, FT8 only, when jt9 reads data from disk @@ -509,5 +602,36 @@ program jt9 endif call fftwf_cleanup_threads() call fftwf_cleanup() + if (allocated(shared_data)) deallocate(shared_data) + +contains + + subroutine require_integer(option, text, value) + character(len=*), intent(in) :: option, text + integer, intent(out) :: value + + logical :: ok + + call parse_integer(text, value, ok) + if (.not. ok) call invalid_option(option, text, 'must be an integer') + end subroutine require_integer + + subroutine require_real(option, text, value) + character(len=*), intent(in) :: option, text + real(kind=8), intent(out) :: value + + logical :: ok + + call parse_real(text, value, ok) + if (.not. ok) call invalid_option(option, text, 'must be a finite number') + end subroutine require_real + + subroutine invalid_option(option, text, reason) + character(len=*), intent(in) :: option, text, reason + + write(error_unit, '(A)') 'jt9: invalid value for -' // trim(option) // ': ' // & + trim(text) // ' (' // trim(reason) // ')' + stop 2 + end subroutine invalid_option end program jt9 |
