2014-04-16 12:43:52 -04:00
|
|
|
program jt9
|
|
|
|
|
|
|
|
! Decoder for JT9. Can run stand-alone, reading data from *.wav files;
|
|
|
|
! or as the back end of wsjt-x, with data placed in a shared memory region.
|
|
|
|
|
|
|
|
use options
|
|
|
|
use prog_args
|
2015-01-30 16:28:10 -05:00
|
|
|
use, intrinsic :: iso_c_binding
|
|
|
|
use FFTW3
|
2015-12-27 10:40:57 -05:00
|
|
|
use timer_module, only: timer
|
|
|
|
use timer_impl, only: init_timer, fini_timer
|
2016-01-02 09:29:02 -05:00
|
|
|
use readwav
|
2014-04-16 12:43:52 -04:00
|
|
|
|
2015-12-17 15:29:55 -05:00
|
|
|
include 'jt9com.f90'
|
|
|
|
|
2015-01-30 16:28:10 -05:00
|
|
|
integer(C_INT) iret
|
2016-01-02 09:29:02 -05:00
|
|
|
type(wav_header) wav
|
2014-04-16 12:43:52 -04:00
|
|
|
real*4 s(NSMAX)
|
|
|
|
character c
|
|
|
|
character(len=500) optarg, infile
|
2015-01-30 16:28:10 -05:00
|
|
|
character wisfile*80
|
2016-03-07 15:00:23 -05:00
|
|
|
!### ndepth was defined as 60001. Why???
|
2015-04-22 13:48:03 -04:00
|
|
|
integer :: arglen,stat,offset,remain,mode=0,flow=200,fsplit=2700, &
|
2016-03-07 15:00:23 -05:00
|
|
|
fhigh=4000,nrxfreq=1500,ntrperiod=1,ndepth=1,nexp_decode=0
|
2015-12-18 12:57:18 -05:00
|
|
|
logical :: read_files = .true., tx9 = .false., display_help = .false.
|
2017-06-30 09:55:19 -04:00
|
|
|
type (option) :: long_options(25) = [ &
|
2015-04-22 13:48:03 -04:00
|
|
|
option ('help', .false., 'h', 'Display this help message', ''), &
|
2015-12-15 10:35:04 -05:00
|
|
|
option ('shmem',.true.,'s','Use shared memory for sample data','KEY'), &
|
|
|
|
option ('tr-period', .true., 'p', 'Tx/Rx period, default MINUTES=1', &
|
|
|
|
'MINUTES'), &
|
|
|
|
option ('executable-path', .true., 'e', &
|
|
|
|
'Location of subordinate executables (KVASD) default PATH="."', &
|
|
|
|
'PATH'), &
|
|
|
|
option ('data-path', .true., 'a', &
|
|
|
|
'Location of writeable data files, default PATH="."', 'PATH'), &
|
|
|
|
option ('temp-path', .true., 't', &
|
|
|
|
'Temporary files path, default PATH="."', 'PATH'), &
|
|
|
|
option ('lowest', .true., 'L', &
|
|
|
|
'Lowest frequency decoded (JT65), default HERTZ=200', 'HERTZ'), &
|
|
|
|
option ('highest', .true., 'H', &
|
|
|
|
'Highest frequency decoded, default HERTZ=4007', 'HERTZ'), &
|
|
|
|
option ('split', .true., 'S', &
|
|
|
|
'Lowest JT9 frequency decoded, default HERTZ=2700', 'HERTZ'), &
|
|
|
|
option ('rx-frequency', .true., 'f', &
|
|
|
|
'Receive frequency offset, default HERTZ=1500', 'HERTZ'), &
|
|
|
|
option ('patience', .true., 'w', &
|
|
|
|
'FFTW3 planing patience (0-4), default PATIENCE=1', 'PATIENCE'), &
|
|
|
|
option ('fft-threads', .true., 'm', &
|
|
|
|
'Number of threads to process large FFTs, default THREADS=1', &
|
|
|
|
'THREADS'), &
|
|
|
|
option ('jt65', .false., '6', 'JT65 mode', ''), &
|
|
|
|
option ('jt9', .false., '9', 'JT9 mode', ''), &
|
2017-07-08 10:06:48 -04:00
|
|
|
option ('ft8', .false., '8', 'FT8 mode', ''), &
|
2015-12-15 10:35:04 -05:00
|
|
|
option ('jt4', .false., '4', 'JT4 mode', ''), &
|
2016-11-16 13:25:03 -05:00
|
|
|
option ('qra64', .false., 'q', 'QRA64 mode', ''), &
|
2015-12-29 18:52:55 -05:00
|
|
|
option ('sub-mode', .true., 'b', 'Sub mode, default SUBMODE=A', 'A'), &
|
2015-12-15 10:35:04 -05:00
|
|
|
option ('depth', .true., 'd', &
|
|
|
|
'JT9 decoding depth (1-3), default DEPTH=1', 'DEPTH'), &
|
2015-12-17 15:29:55 -05:00
|
|
|
option ('tx-jt9', .false., 'T', 'Tx mode is JT9', ''), &
|
|
|
|
option ('my-call', .true., 'c', 'my callsign', 'CALL'), &
|
|
|
|
option ('my-grid', .true., 'G', 'my grid locator', 'GRID'), &
|
|
|
|
option ('his-call', .true., 'x', 'his callsign', 'CALL'), &
|
|
|
|
option ('his-grid', .true., 'g', 'his grid locator', 'GRID'), &
|
|
|
|
option ('experience-decode', .true., 'X', &
|
|
|
|
'experience based decoding flags (1..n), default FLAGS=0', &
|
|
|
|
'FLAGS') ]
|
2015-04-22 13:48:03 -04:00
|
|
|
|
2015-12-17 15:29:55 -05:00
|
|
|
type(dec_data), allocatable :: shared_data
|
|
|
|
character(len=12) :: mycall, hiscall
|
|
|
|
character(len=6) :: mygrid, hisgrid
|
2015-01-30 16:28:10 -05:00
|
|
|
common/patience/npatience,nthreads
|
2015-11-17 20:28:12 -05:00
|
|
|
common/decstats/ntry65a,ntry65b,n65a,n65b,num9,numfano
|
2015-01-30 16:28:10 -05:00
|
|
|
data npatience/1/,nthreads/1/
|
2014-04-16 12:43:52 -04:00
|
|
|
|
2015-12-29 18:52:55 -05:00
|
|
|
nsubmode = 0
|
|
|
|
|
2014-04-16 12:43:52 -04:00
|
|
|
do
|
2017-06-30 09:55:19 -04:00
|
|
|
call getopt('hs:e:a:b:r:m:p:d:f:w:t:9864qTL:S:H:c:G:x:g:X:', &
|
|
|
|
long_options,c,optarg,arglen,stat,offset,remain,.true.)
|
2014-04-16 12:43:52 -04:00
|
|
|
if (stat .ne. 0) then
|
|
|
|
exit
|
|
|
|
end if
|
|
|
|
select case (c)
|
2015-02-10 09:04:54 -05:00
|
|
|
case ('h')
|
|
|
|
display_help = .true.
|
2014-04-16 12:43:52 -04:00
|
|
|
case ('s')
|
2015-12-18 12:57:18 -05:00
|
|
|
read_files = .false.
|
2014-04-16 12:43:52 -04:00
|
|
|
shm_key = optarg(:arglen)
|
|
|
|
case ('e')
|
|
|
|
exe_dir = optarg(:arglen)
|
|
|
|
case ('a')
|
|
|
|
data_dir = optarg(:arglen)
|
2015-12-29 18:52:55 -05:00
|
|
|
case ('b')
|
|
|
|
nsubmode = ichar (optarg(:1)) - ichar ('A')
|
2014-12-02 19:06:54 -05:00
|
|
|
case ('t')
|
|
|
|
temp_dir = optarg(:arglen)
|
2015-01-30 16:28:10 -05:00
|
|
|
case ('m')
|
|
|
|
read (optarg(:arglen), *) nthreads
|
2014-04-16 12:43:52 -04:00
|
|
|
case ('p')
|
2015-12-17 18:21:38 -05:00
|
|
|
read (optarg(:arglen), *) ntrperiod
|
2014-04-16 12:43:52 -04:00
|
|
|
case ('d')
|
|
|
|
read (optarg(:arglen), *) ndepth
|
|
|
|
case ('f')
|
|
|
|
read (optarg(:arglen), *) nrxfreq
|
2015-02-10 09:04:54 -05:00
|
|
|
case ('L')
|
|
|
|
read (optarg(:arglen), *) flow
|
|
|
|
case ('S')
|
|
|
|
read (optarg(:arglen), *) fsplit
|
|
|
|
case ('H')
|
|
|
|
read (optarg(:arglen), *) fhigh
|
2016-11-16 13:25:03 -05:00
|
|
|
case ('q')
|
|
|
|
mode = 164
|
2015-04-22 13:48:03 -04:00
|
|
|
case ('4')
|
|
|
|
mode = 4
|
2015-02-10 09:04:54 -05:00
|
|
|
case ('6')
|
|
|
|
if (mode.lt.65) mode = mode + 65
|
|
|
|
case ('9')
|
|
|
|
if (mode.lt.9.or.mode.eq.65) mode = mode + 9
|
2017-06-30 09:55:19 -04:00
|
|
|
case ('8')
|
|
|
|
mode = 8
|
2015-02-10 09:04:54 -05:00
|
|
|
case ('T')
|
|
|
|
tx9 = .true.
|
2014-11-20 13:48:53 -05:00
|
|
|
case ('w')
|
|
|
|
read (optarg(:arglen), *) npatience
|
2015-12-17 15:29:55 -05:00
|
|
|
case ('c')
|
|
|
|
read (optarg(:arglen), *) mycall
|
|
|
|
case ('G')
|
|
|
|
read (optarg(:arglen), *) mygrid
|
|
|
|
case ('x')
|
|
|
|
read (optarg(:arglen), *) hiscall
|
|
|
|
case ('g')
|
|
|
|
read (optarg(:arglen), *) hisgrid
|
|
|
|
case ('X')
|
|
|
|
read (optarg(:arglen), *) nexp_decode
|
2014-04-16 12:43:52 -04:00
|
|
|
end select
|
|
|
|
end do
|
|
|
|
|
2015-12-15 10:35:04 -05:00
|
|
|
if (display_help .or. stat .lt. 0 &
|
2015-12-18 12:57:18 -05:00
|
|
|
.or. (.not. read_files .and. remain .gt. 0) &
|
|
|
|
.or. (read_files .and. remain .lt. 1)) then
|
2015-04-22 13:48:03 -04:00
|
|
|
|
2015-12-15 10:35:04 -05:00
|
|
|
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 *, ' Gets data from shared memory region with key==<key>'
|
|
|
|
print *, ''
|
|
|
|
print *, 'OPTIONS:'
|
|
|
|
print *, ''
|
2015-02-10 09:04:54 -05:00
|
|
|
do i = 1, size (long_options)
|
|
|
|
call long_options(i) % print (6)
|
|
|
|
end do
|
2014-04-16 12:43:52 -04:00
|
|
|
go to 999
|
|
|
|
endif
|
2016-11-16 13:25:03 -05:00
|
|
|
|
2015-04-22 13:48:03 -04:00
|
|
|
iret=fftwf_init_threads() !Initialize FFTW threading
|
|
|
|
|
|
|
|
! Default to 1 thread, but use nthreads for the big ones
|
|
|
|
call fftwf_plan_with_nthreads(1)
|
|
|
|
|
2015-01-30 16:28:10 -05:00
|
|
|
! Import FFTW wisdom, if available
|
|
|
|
wisfile=trim(data_dir)//'/jt9_wisdom.dat'// C_NULL_CHAR
|
|
|
|
iret=fftwf_import_wisdom_from_filename(wisfile)
|
2014-11-20 13:48:53 -05:00
|
|
|
|
2015-11-17 20:28:12 -05:00
|
|
|
ntry65a=0
|
|
|
|
ntry65b=0
|
|
|
|
n65a=0
|
|
|
|
n65b=0
|
2015-02-13 09:22:54 -05:00
|
|
|
num9=0
|
|
|
|
numfano=0
|
|
|
|
|
2015-12-18 12:57:18 -05:00
|
|
|
if (.not. read_files) then
|
2015-04-22 13:48:03 -04:00
|
|
|
call jt9a() !We're running under control of WSJT-X
|
2014-04-16 12:43:52 -04:00
|
|
|
go to 999
|
|
|
|
endif
|
|
|
|
|
2015-12-17 15:29:55 -05:00
|
|
|
allocate(shared_data)
|
2015-02-04 16:42:49 -05:00
|
|
|
nflatten=0
|
2014-04-16 12:43:52 -04:00
|
|
|
|
|
|
|
do iarg = offset + 1, offset + remain
|
|
|
|
call get_command_argument (iarg, optarg, arglen)
|
|
|
|
infile = optarg(:arglen)
|
2016-01-02 09:29:02 -05:00
|
|
|
call wav%read (infile)
|
|
|
|
nfsample=wav%audio_format%sample_rate
|
2014-04-16 12:43:52 -04:00
|
|
|
i1=index(infile,'.wav')
|
2015-04-22 13:48:03 -04:00
|
|
|
if(i1.lt.1) i1=index(infile,'.WAV')
|
|
|
|
if(infile(i1-5:i1-5).eq.'_') then
|
2015-12-17 15:29:55 -05:00
|
|
|
read(infile(i1-4:i1-1),*,err=1) nutc
|
2015-04-22 13:48:03 -04:00
|
|
|
else
|
2017-07-14 14:19:48 -04:00
|
|
|
read(infile(i1-6:i1-1),*,err=1) nutc
|
2015-04-22 13:48:03 -04:00
|
|
|
endif
|
2014-04-16 12:43:52 -04:00
|
|
|
go to 2
|
2015-12-17 15:29:55 -05:00
|
|
|
1 nutc=0
|
2014-04-16 12:43:52 -04:00
|
|
|
2 nsps=0
|
2015-12-17 18:21:38 -05:00
|
|
|
if(ntrperiod.eq.1) then
|
2014-04-16 12:43:52 -04:00
|
|
|
nsps=6912
|
2015-12-17 15:29:55 -05:00
|
|
|
shared_data%params%nzhsym=181
|
2015-12-17 18:21:38 -05:00
|
|
|
else if(ntrperiod.eq.2) then
|
2014-04-16 12:43:52 -04:00
|
|
|
nsps=15360
|
2015-12-17 15:29:55 -05:00
|
|
|
shared_data%params%nzhsym=178
|
2015-12-17 18:21:38 -05:00
|
|
|
else if(ntrperiod.eq.5) then
|
2014-04-16 12:43:52 -04:00
|
|
|
nsps=40960
|
2015-12-17 15:29:55 -05:00
|
|
|
shared_data%params%nzhsym=172
|
2015-12-17 18:21:38 -05:00
|
|
|
else if(ntrperiod.eq.10) then
|
2014-04-16 12:43:52 -04:00
|
|
|
nsps=82944
|
2015-12-17 15:29:55 -05:00
|
|
|
shared_data%params%nzhsym=171
|
2015-12-17 18:21:38 -05:00
|
|
|
else if(ntrperiod.eq.30) then
|
2014-04-16 12:43:52 -04:00
|
|
|
nsps=252000
|
2015-12-17 15:29:55 -05:00
|
|
|
shared_data%params%nzhsym=167
|
2014-04-16 12:43:52 -04:00
|
|
|
endif
|
|
|
|
if(nsps.eq.0) stop 'Error: bad TRperiod'
|
|
|
|
|
|
|
|
kstep=nsps/2
|
|
|
|
k=0
|
|
|
|
nhsym0=-999
|
|
|
|
npts=(60*ntrperiod-6)*12000
|
|
|
|
if(iarg .eq. offset + 1) then
|
2015-12-27 10:40:57 -05:00
|
|
|
call init_timer (trim(data_dir)//'/timer.out')
|
2014-11-20 13:48:53 -05:00
|
|
|
call timer('jt9 ',0)
|
2014-04-16 12:43:52 -04:00
|
|
|
endif
|
|
|
|
|
2015-12-17 18:21:38 -05:00
|
|
|
shared_data%id2=0 !??? Why is this necessary ???
|
2014-04-16 12:43:52 -04:00
|
|
|
|
|
|
|
do iblk=1,npts/kstep
|
|
|
|
k=iblk*kstep
|
2017-06-30 09:55:19 -04:00
|
|
|
if(mode.eq.8 .and. k.gt.179712) exit
|
2014-04-16 12:43:52 -04:00
|
|
|
call timer('read_wav',0)
|
2016-01-02 09:29:02 -05:00
|
|
|
read(unit=wav%lun,end=3) shared_data%id2(k-kstep+1:k)
|
2015-04-22 13:48:03 -04:00
|
|
|
go to 4
|
|
|
|
3 call timer('read_wav',1)
|
|
|
|
print*,'EOF on input file ',infile
|
|
|
|
exit
|
|
|
|
4 call timer('read_wav',1)
|
2014-04-16 12:43:52 -04:00
|
|
|
nhsym=(k-2048)/kstep
|
|
|
|
if(nhsym.ge.1 .and. nhsym.ne.nhsym0) then
|
2015-04-22 13:48:03 -04:00
|
|
|
if(mode.eq.9 .or. mode.eq.74) then
|
|
|
|
! Compute rough symbol spectra for the JT9 decoder
|
|
|
|
ingain=0
|
|
|
|
call timer('symspec ',0)
|
2015-05-27 09:08:28 -04:00
|
|
|
nminw=1
|
2017-07-14 14:19:48 -04:00
|
|
|
call symspec(shared_data,k,ntrperiod,nsps,ingain,nminw,pxdb, &
|
|
|
|
s,df3,ihsym,npts8,pxdbmax)
|
2015-04-22 13:48:03 -04:00
|
|
|
call timer('symspec ',1)
|
|
|
|
endif
|
2014-04-16 12:43:52 -04:00
|
|
|
nhsym0=nhsym
|
2015-04-22 13:48:03 -04:00
|
|
|
if(nhsym.ge.181) exit
|
2014-04-16 12:43:52 -04:00
|
|
|
endif
|
|
|
|
enddo
|
2016-01-02 09:29:02 -05:00
|
|
|
close(unit=wav%lun)
|
2015-12-17 15:29:55 -05:00
|
|
|
shared_data%params%nutc=nutc
|
2015-12-29 18:52:55 -05:00
|
|
|
shared_data%params%ndiskdat=.true.
|
2015-12-17 15:29:55 -05:00
|
|
|
shared_data%params%ntr=60
|
|
|
|
shared_data%params%nfqso=nrxfreq
|
2015-12-29 18:52:55 -05:00
|
|
|
shared_data%params%newdat=.true.
|
2015-12-17 15:29:55 -05:00
|
|
|
shared_data%params%npts8=74736
|
|
|
|
shared_data%params%nfa=flow
|
|
|
|
shared_data%params%nfsplit=fsplit
|
|
|
|
shared_data%params%nfb=fhigh
|
|
|
|
shared_data%params%ntol=20
|
|
|
|
shared_data%params%kin=64800
|
|
|
|
shared_data%params%nzhsym=181
|
|
|
|
shared_data%params%ndepth=ndepth
|
2017-11-04 13:03:56 -04:00
|
|
|
shared_data%params%lft8apon=.true.
|
|
|
|
shared_data%params%ljt65apon=.true.
|
2017-07-21 23:01:09 -04:00
|
|
|
shared_data%params%napwid=75
|
2015-12-17 15:29:55 -05:00
|
|
|
shared_data%params%dttol=3.
|
2015-12-30 20:30:31 -05:00
|
|
|
|
2017-07-12 17:49:39 -04:00
|
|
|
! shared_data%params%minsync=0 !### TEST ONLY
|
2016-11-21 15:30:11 -05:00
|
|
|
! shared_data%params%nfqso=1500 !### TEST ONLY
|
2017-07-08 10:06:48 -04:00
|
|
|
! mycall="G3WDG " !### TEST ONLY
|
|
|
|
! hiscall="VK7MO " !### TEST ONLY
|
|
|
|
! hisgrid="QE37 " !### TEST ONLY
|
2016-11-16 13:25:03 -05:00
|
|
|
if(mode.eq.164 .and. nsubmode.lt.100) nsubmode=nsubmode+100
|
2015-12-30 20:30:31 -05:00
|
|
|
|
2017-02-27 15:47:31 -05:00
|
|
|
shared_data%params%naggressive=0
|
|
|
|
shared_data%params%n2pass=2
|
2016-03-08 16:04:05 -05:00
|
|
|
! shared_data%params%nranera=8 !### ntrials=10000
|
2017-02-27 15:47:31 -05:00
|
|
|
shared_data%params%nranera=6 !### ntrials=3000
|
2015-12-29 18:52:55 -05:00
|
|
|
shared_data%params%nrobust=.false.
|
2015-12-17 15:29:55 -05:00
|
|
|
shared_data%params%nexp_decode=nexp_decode
|
|
|
|
shared_data%params%mycall=mycall
|
|
|
|
shared_data%params%mygrid=mygrid
|
|
|
|
shared_data%params%hiscall=hiscall
|
|
|
|
shared_data%params%hisgrid=hisgrid
|
|
|
|
if (shared_data%params%mycall == '') shared_data%params%mycall='K1ABC'
|
|
|
|
if (shared_data%params%hiscall == '') shared_data%params%hiscall='W9XYZ'
|
|
|
|
if (shared_data%params%hisgrid == '') shared_data%params%hiscall='EN37'
|
|
|
|
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
|
2015-12-29 18:52:55 -05:00
|
|
|
shared_data%params%nsubmode=nsubmode
|
2015-12-17 15:29:55 -05:00
|
|
|
shared_data%params%datetime="2013-Apr-16 15:13" !### Temp
|
|
|
|
if(mode.eq.9 .and. fsplit.ne.2700) shared_data%params%nfa=fsplit
|
2015-12-29 18:52:55 -05:00
|
|
|
call multimode_decoder(shared_data%ss,shared_data%id2,shared_data%params,nfsample)
|
2014-04-16 12:43:52 -04:00
|
|
|
enddo
|
|
|
|
|
|
|
|
call timer('jt9 ',1)
|
|
|
|
call timer('jt9 ',101)
|
|
|
|
|
2014-11-20 13:48:53 -05:00
|
|
|
999 continue
|
2016-12-15 13:58:17 -05:00
|
|
|
! Output decoder statistics
|
2015-12-27 10:40:57 -05:00
|
|
|
call fini_timer ()
|
2016-12-15 13:58:17 -05:00
|
|
|
! open (unit=12, file=trim(data_dir)//'/timer.out', status='unknown', position='append')
|
|
|
|
! write(12,1100) n65a,ntry65a,n65b,ntry65b,numfano,num9
|
|
|
|
!1100 format(58('-')/' JT65_1 Tries_1 JT65_2 Tries_2 JT9 Tries'/ &
|
|
|
|
! 58('-')/6i8)
|
2015-02-13 09:22:54 -05:00
|
|
|
|
|
|
|
! Save wisdom and free memory
|
2015-01-30 16:28:10 -05:00
|
|
|
iret=fftwf_export_wisdom_to_filename(wisfile)
|
2015-02-03 20:41:26 -05:00
|
|
|
call four2a(a,-1,1,1,1)
|
2015-02-01 11:23:36 -05:00
|
|
|
call filbig(a,-1,1,0.0,0,0,0,0,0) !used for FFT plans
|
|
|
|
call fftwf_cleanup_threads()
|
|
|
|
call fftwf_cleanup()
|
2014-11-20 13:48:53 -05:00
|
|
|
end program jt9
|