summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristoph Berg <christoph.berg@credativ.de>2019-07-17 15:12:32 +0200
committerChristoph Berg <christoph.berg@credativ.de>2019-07-17 15:12:32 +0200
commit3d67be3023bf34eac7f93fa422f5ef569abb92a9 (patch)
treef3748d6a113c50d483882b60b732a9d211100cf8 /lib
parent62c0c627f4f8aec46a082bf098d4f1523a16d297 (diff)
New upstream version 2.1.0+repackupstream/2.1.0+repack
Diffstat (limited to 'lib')
-rw-r--r--lib/77bit/77bit.txt7
-rw-r--r--lib/77bit/messages.txt13
-rw-r--r--lib/77bit/packjt77.f9087
-rw-r--r--lib/astrosub.f90142
-rw-r--r--lib/decoder.f904
-rw-r--r--lib/fast_decode.f907
-rw-r--r--lib/ft4/averaged_mf.f9064
-rw-r--r--lib/ft4/ft4_downsample.f907
-rw-r--r--lib/ft4/ft4_params.f902
-rw-r--r--lib/ft4/ft4b.f90489
-rw-r--r--lib/ft4/ft4d.f9083
-rw-r--r--lib/ft4/genft4.f902
-rw-r--r--lib/ft4/get_ft4_bitmetrics.f90114
-rw-r--r--lib/ft4/getcandidates4.f9037
-rw-r--r--lib/ft4/sync4d.f9010
-rw-r--r--lib/ft4_decode.f90504
-rw-r--r--lib/ft8/ft8sim.f904
-rw-r--r--lib/ft8/subtractft8.f903
-rw-r--r--lib/jt9.f905
-rw-r--r--lib/readwav.f904
-rw-r--r--lib/rtty_spec.f90102
21 files changed, 663 insertions, 1027 deletions
diff --git a/lib/77bit/77bit.txt b/lib/77bit/77bit.txt
index ef370c11..89b481b6 100644
--- a/lib/77bit/77bit.txt
+++ b/lib/77bit/77bit.txt
@@ -22,15 +22,10 @@ i3.n3 Example message Bits Total Purpose
2 PA3XYZ/P GM4ABC/P R JO22 28 1 28 1 1 15 74 EU VHF contest
3 TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 ARRL RTTY Roundup
4 <WA9XYZ> PJ4/KA1ABC RR73 12 58 1 2 1 74 Nonstandard calls
-5 ... tbd
+5 TU; W9XYZ K1ABC R-07 FN 1 28 28 1 7 9 74 WWROF contest ?
6 ... tbd
7 ... tbd
----------------------------------------------------------------------------------
-In case we need them, later:
-
-5 TU; W9XYZ K1ABC R 579 8 MA 1 28 28 1 3 6 7 74 CQ WW RTTY
-6 TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 CQ WPX RTTY
-----------------------------------------------------------------------------------
NB: three 74-bit message types and two 71-bit message subtypes are still TBD.
----------------------------------------------------------------------------------
diff --git a/lib/77bit/messages.txt b/lib/77bit/messages.txt
index 54fd44b0..aa4ab078 100644
--- a/lib/77bit/messages.txt
+++ b/lib/77bit/messages.txt
@@ -72,7 +72,18 @@ CQ W9XYZ EN37
W9XYZ <YW18FIFA> R-09
YW18FIFA <W9XYZ> RRR
<W9XYZ> YW18FIFA 73
-10. Other stuff
+
+10. WWROF FT8/FT4 contest
+-----------------------------------------------------------
+CQ TEST K1ABC FN42
+ K1ABC W9XYZ -16 EN
+W9XYZ K1ABC R-07 FN
+ K1ABC W9XYZ RR73
+ K1ABC G3AAA -11 IO
+TU; G3AAA K1ABC R-09 FN
+ K1ABC G3AAA RR73
+
+11. Other stuff
-----------------------------------------------------------
TNX BOB 73 GL
CQ YW18FIFA
diff --git a/lib/77bit/packjt77.f90 b/lib/77bit/packjt77.f90
index 1ee37f5c..1f9ed9a1 100644
--- a/lib/77bit/packjt77.f90
+++ b/lib/77bit/packjt77.f90
@@ -172,6 +172,10 @@ subroutine pack77(msg0,i3,n3,c77)
call pack77_4(nwords,w,i3,n3,c77)
if(i3.ge.0) go to 900
+! Check Type 5 (WWROF contest exchange)
+ call pack77_5(nwords,w,i3,n3,c77)
+ if(i3.ge.0) go to 900
+
! It defaults to free text
800 i3=0
n3=0
@@ -204,6 +208,7 @@ subroutine unpack77(c77,nrx,msg,unpk77_success)
character*6 cexch,grid6
character*4 grid4,cserial
character*3 csec(NSEC)
+ character*2 cfield
character*38 c
integer hashmy10,hashmy12,hashmy22,hashdx10,hashdx12,hashdx22
logical unpk28_success,unpk77_success
@@ -491,8 +496,31 @@ subroutine unpack77(c77,nrx,msg,unpk77_success)
else
msg='CQ '//trim(call_2)
endif
+
+ else if(i3.eq.5) then
+! 5 TU; W9XYZ K1ABC R-09 FN 1 28 28 1 7 9 74 WWROF contest
+ read(c77,1041) itu,n28a,n28b,ir,irpt,nexch,i3
+1041 format(b1,2b28.28,b1,b7.7,b9.9,b3.3)
+ call unpack28(n28a,call_1,unpk28_success)
+ if(.not.unpk28_success) unpk77_success=.false.
+ call unpack28(n28b,call_2,unpk28_success)
+ if(.not.unpk28_success) unpk77_success=.false.
+ write(crpt,'(i3.2)') irpt-35
+ if(crpt(1:1).eq.' ') crpt(1:1)='+'
+ n1=nexch/18
+ n2=nexch - 18*n1
+ cfield(1:1)=char(ichar('A')+n1)
+ cfield(2:2)=char(ichar('A')+n2)
+ if(itu.eq.0 .and. ir.eq.0) msg=trim(call_1)//' '//trim(call_2)// &
+ ' '//crpt//' '//cfield
+ if(itu.eq.1 .and. ir.eq.0) msg='TU; '//trim(call_1)//' '//trim(call_2)// &
+ ' '//crpt//' '//cfield
+ if(itu.eq.0 .and. ir.eq.1) msg=trim(call_1)//' '//trim(call_2)// &
+ ' R'//crpt//' '//cfield
+ if(itu.eq.1 .and. ir.eq.1) msg='TU; '//trim(call_1)//' '//trim(call_2)// &
+ ' R'//crpt//' '//cfield
endif
- if(msg(1:4).eq.'CQ <') unpk77_success=.false.
+! if(msg(1:4).eq.'CQ <') unpk77_success=.false.
return
end subroutine unpack77
@@ -1040,12 +1068,11 @@ subroutine pack77_3(nwords,w,i3,n3,c77)
call chkcall(w(i1+1),bcall_2,ok2)
if(.not.ok1 .or. .not.ok2) go to 900
crpt=w(nwords-1)(1:3)
+ if(index(crpt,'-').ge.1 .or. index(crpt,'+').ge.1) go to 900
if(crpt(1:1).eq.'5' .and. crpt(2:2).ge.'2' .and. crpt(2:2).le.'9' .and. &
crpt(3:3).eq.'9') then
nserial=0
read(w(nwords),*,err=1) nserial
-!1 i3=3
-! n3=0
endif
1 mult=' '
imult=-1
@@ -1150,6 +1177,60 @@ subroutine pack77_4(nwords,w,i3,n3,c77)
900 return
end subroutine pack77_4
+subroutine pack77_5(nwords,w,i3,n3,c77)
+! Check Type 5 (WWROF contest exchange)
+
+ character*13 w(19)
+ character*77 c77
+ character*6 bcall_1,bcall_2
+ character*3 mult
+ character crpt*4
+ character c1*1,c2*2
+ logical ok1,ok2
+
+ if(nwords.eq.4 .or. nwords.eq.5 .or. nwords.eq.6) then
+ i1=1
+ if(trim(w(1)).eq.'TU;') i1=2
+ call chkcall(w(i1),bcall_1,ok1)
+ call chkcall(w(i1+1),bcall_2,ok2)
+ if(.not.ok1 .or. .not.ok2) go to 900
+ crpt=w(nwords-1)(1:4)
+ if(index(crpt,'-').lt.1 .and. index(crpt,'+').lt.1) go to 900
+
+ c1=crpt(1:1)
+ c2=crpt(1:2)
+ irpt=-1
+ if(c1.eq.'+' .or. c1.eq.'-') then
+ ir=0
+ read(w(nwords-1),*,err=900) irpt
+ irpt=irpt+35
+ else if(c2.eq.'R+' .or. c2.eq.'R-') then
+ ir=1
+ read(w(nwords-1)(2:),*) irpt
+ irpt=irpt+35
+ endif
+ if(irpt.eq.-1 .or. len(trim(w(nwords))).ne.2) go to 900
+ c2=w(nwords)(1:2)
+ n1=ichar(c2(1:1)) - ichar('A')
+ n2=ichar(c2(2:2)) - ichar('A')
+ if(n1.lt.0 .or. n1.gt.17) go to 900
+ if(n2.lt.0 .or. n2.gt.17) go to 900
+ nexch=18*n1 + n2
+ i3=5
+ n3=0
+ itu=0
+ if(trim(w(1)).eq.'TU;') itu=1
+ call pack28(w(1+itu),n28a)
+ call pack28(w(2+itu),n28b)
+! 5 TU; W9XYZ K1ABC R-09 FN 1 28 28 1 7 9 74 WWROF contest
+ write(c77,1010) itu,n28a,n28b,ir,irpt,nexch,i3
+1010 format(b1,2b28.28,b1,b7.7,b9.9,b3.3)
+
+ end if
+
+900 return
+end subroutine pack77_5
+
subroutine packtext77(c13,c71)
character*13 c13,w
diff --git a/lib/astrosub.f90 b/lib/astrosub.f90
index 49551ce3..0670d66d 100644
--- a/lib/astrosub.f90
+++ b/lib/astrosub.f90
@@ -1,55 +1,97 @@
-subroutine astrosub(nyear,month,nday,uth8,freq8,mygrid,hisgrid, &
- AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, &
- RAMoon8,DecMoon8,Dgrd8,poloffset8,xnr8,techo8,width1,width2,bTx, &
- AzElFileName,jpleph)
-
- implicit real*8 (a-h,o-z)
- character*6 mygrid,hisgrid,c1*1
- character*6 AzElFileName*(*),jpleph*(*)
- character*256 jpleph_file_name
- logical*1 bTx
- common/jplcom/jpleph_file_name
-
- jpleph_file_name=jpleph
-
- call astro0(nyear,month,nday,uth8,freq8,mygrid,hisgrid, &
- AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, &
- dbMoon8,RAMoon8,DecMoon8,HA8,Dgrd8,sd8,poloffset8,xnr8,dfdt,dfdt0, &
- width1,width2,xlst8,techo8)
-
- if (len_trim(AzElFileName) .eq. 0) go to 999
- imin=60*uth8
- isec=3600*uth8
- ih=uth8
- im=mod(imin,60)
- is=mod(isec,60)
- open(15,file=AzElFileName,status='unknown',err=900)
- c1='R'
- nRx=1
- if(bTx) then
- c1='T'
- nRx=0
- endif
- AzAux=0.
- ElAux=0.
- nfreq=freq8/1000000
- doppler=ndop
- doppler00=ndop00
- write(15,1010,err=10) ih,im,is,AzMoon8,ElMoon8, &
- ih,im,is,AzSun8,ElSun8, &
- ih,im,is,AzAux,ElAux, &
- nfreq,doppler,dfdt,doppler00,dfdt0,c1
-! TXFirst,TRPeriod,poloffset,Dgrd,xnr,ave,rms,nRx
+module astro_module
+ use, intrinsic :: iso_c_binding, only : c_int, c_double, c_bool, c_char, c_ptr, c_size_t, c_f_pointer
+ implicit none
+
+ private
+ public :: astrosub
+
+contains
+
+ subroutine astrosub(nyear,month,nday,uth8,freq8,mygrid_cp,mygrid_len, &
+ hisgrid_cp,hisgrid_len,AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8, &
+ ntsky,ndop,ndop00,RAMoon8,DecMoon8,Dgrd8,poloffset8,xnr8,techo8,width1, &
+ width2,bTx,AzElFileName_cp,AzElFileName_len,jpleph_cp,jpleph_len) &
+ bind (C, name="astrosub")
+
+ integer, parameter :: dp = selected_real_kind(15, 50)
+
+ integer(c_int), intent(in), value :: nyear, month, nday
+ real(c_double), intent(in), value :: uth8, freq8
+ real(c_double), intent(out) :: AzSun8, ElSun8, AzMoon8, ElMoon8, AzMoonB8, &
+ ElMoonB8, Ramoon8, DecMoon8, Dgrd8, poloffset8, xnr8, techo8, width1, &
+ width2
+ integer(c_int), intent(out) :: ntsky, ndop, ndop00
+ logical(c_bool), intent(in), value :: bTx
+ type(c_ptr), intent(in), value :: mygrid_cp, hisgrid_cp, AzElFileName_cp, jpleph_cp
+ integer(c_size_t), intent(in), value :: mygrid_len, hisgrid_len, AzElFileName_len, jpleph_len
+
+ character(len=6) :: mygrid, hisgrid
+ character(kind=c_char, len=:), allocatable :: AzElFileName
+ character(len=1) :: c1
+ integer :: ih, im, imin, is, isec, nfreq, nRx
+ real(dp) :: AzAux, ElAux, dbMoon8, dfdt, dfdt0, doppler, doppler00, HA8, sd8, xlst8
+ character*256 jpleph_file_name
+ common/jplcom/jpleph_file_name
+
+ block
+ character(kind=c_char, len=mygrid_len), pointer :: mygrid_fp
+ character(kind=c_char, len=hisgrid_len), pointer :: hisgrid_fp
+ character(kind=c_char, len=AzElFileName_len), pointer :: AzElFileName_fp
+ character(kind=c_char, len=jpleph_len), pointer :: jpleph_fp
+ call c_f_pointer(cptr=mygrid_cp, fptr=mygrid_fp)
+ mygrid = mygrid_fp
+ mygrid_fp => null()
+ call c_f_pointer(cptr=hisgrid_cp, fptr=hisgrid_fp)
+ hisgrid = hisgrid_fp
+ hisgrid_fp => null()
+ call c_f_pointer(cptr=AzElFileName_cp, fptr=AzElFileName_fp)
+ AzElFileName = AzElFileName_fp
+ AzElFileName_fp => null()
+ call c_f_pointer(cptr=jpleph_cp, fptr=jpleph_fp)
+ jpleph_file_name = jpleph_fp
+ jpleph_fp => null()
+ end block
+
+ call astro0(nyear,month,nday,uth8,freq8,mygrid,hisgrid, &
+ AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, &
+ dbMoon8,RAMoon8,DecMoon8,HA8,Dgrd8,sd8,poloffset8,xnr8,dfdt,dfdt0, &
+ width1,width2,xlst8,techo8)
+
+ if (len_trim(AzElFileName) .eq. 0) go to 999
+ imin=60*uth8
+ isec=3600*uth8
+ ih=uth8
+ im=mod(imin,60)
+ is=mod(isec,60)
+ open(15,file=AzElFileName,status='unknown',err=900)
+ c1='R'
+ nRx=1
+ if(bTx) then
+ c1='T'
+ nRx=0
+ endif
+ AzAux=0.
+ ElAux=0.
+ nfreq=freq8/1000000
+ doppler=ndop
+ doppler00=ndop00
+ write(15,1010,err=10) ih,im,is,AzMoon8,ElMoon8, &
+ ih,im,is,AzSun8,ElSun8, &
+ ih,im,is,AzAux,ElAux, &
+ nfreq,doppler,dfdt,doppler00,dfdt0,c1
+ ! TXFirst,TRPeriod,poloffset,Dgrd,xnr,ave,rms,nRx
1010 format( &
- i2.2,':',i2.2,':',i2.2,',',f5.1,',',f5.1,',Moon'/ &
- i2.2,':',i2.2,':',i2.2,',',f5.1,',',f5.1,',Sun'/ &
- i2.2,':',i2.2,':',i2.2,',',f5.1,',',f5.1,',Source'/ &
- i5,',',f8.1,',',f8.2,',',f8.1,',',f8.2,',Doppler, ',a1)
-! i1,',',i3,',',f8.1,','f8.1,',',f8.1,',',f12.3,',',f12.3,',',i1,',RPol')
-10 close(15)
- go to 999
+ i2.2,':',i2.2,':',i2.2,',',f5.1,',',f5.1,',Moon'/ &
+ i2.2,':',i2.2,':',i2.2,',',f5.1,',',f5.1,',Sun'/ &
+ i2.2,':',i2.2,':',i2.2,',',f5.1,',',f5.1,',Source'/ &
+ i5,',',f8.1,',',f8.2,',',f8.1,',',f8.2,',Doppler, ',a1)
+ ! i1,',',i3,',',f8.1,','f8.1,',',f8.1,',',f12.3,',',f12.3,',',i1,',RPol')
+10 close(15)
+ go to 999
900 print*,'Error opening azel.dat'
999 return
-end subroutine astrosub
+ end subroutine astrosub
+
+end module astro_module
diff --git a/lib/decoder.f90 b/lib/decoder.f90
index d3f1153f..8abdcb75 100644
--- a/lib/decoder.f90
+++ b/lib/decoder.f90
@@ -517,7 +517,7 @@ contains
decoded0=decoded
annot=' '
- if(ncontest.eq.0 .and. nap.ne.0) then
+ if(nap.ne.0) then
write(annot,'(a1,i1)') 'a',nap
if(qual.lt.0.17) decoded0(37:37)='?'
endif
@@ -598,7 +598,7 @@ contains
decoded0=decoded
annot=' '
- if(ncontest.eq.0 .and. nap.ne.0) then
+ if(nap.ne.0) then
write(annot,'(a1,i1)') 'a',nap
if(qual.lt.0.17) decoded0(37:37)='?'
endif
diff --git a/lib/fast_decode.f90 b/lib/fast_decode.f90
index eebb7310..c3cadb6a 100644
--- a/lib/fast_decode.f90
+++ b/lib/fast_decode.f90
@@ -1,4 +1,4 @@
-subroutine fast_decode(id2,narg,ntrperiod,line,mycall_12, &
+subroutine fast_decode(id2,narg,trperiod,line,mycall_12, &
hiscall_12)
parameter (NMAX=30*12000)
@@ -6,6 +6,7 @@ subroutine fast_decode(id2,narg,ntrperiod,line,mycall_12, &
integer*2 id2a(NMAX)
integer*2 id2b(NMAX)
integer narg(0:14)
+ double precision trperiod
real dat(30*12000)
complex cdat(262145),cdat2(262145)
real psavg(450)
@@ -41,7 +42,7 @@ subroutine fast_decode(id2,narg,ntrperiod,line,mycall_12, &
nhashcalls=narg(12)
line(1:100)(1:1)=char(0)
- if(t0.gt.float(ntrperiod)) go to 900
+ if(t0.gt.trperiod) go to 900
if(t0.gt.t1) go to 900
if(nmode.eq.102) then
@@ -53,7 +54,7 @@ subroutine fast_decode(id2,narg,ntrperiod,line,mycall_12, &
cdat2=cdat
ndat=ndat0
call wav11(id2,ndat,dat)
- nzz=11025*ntrperiod
+ nzz=11025*int(trperiod) !beware if fractional T/R period ever used here
if(ndat.lt.nzz) dat(ndat+1:nzz)=0.0
ndat=min(ndat,30*11025)
call ana932(dat,ndat,cdat,npts) !Make downsampled analytic signal
diff --git a/lib/ft4/averaged_mf.f90 b/lib/ft4/averaged_mf.f90
deleted file mode 100644
index 2986572b..00000000
--- a/lib/ft4/averaged_mf.f90
+++ /dev/null
@@ -1,64 +0,0 @@
-program averaged_mf
-
- parameter (nsps=32)
- complex cgfsk(3*nsps,64)
- complex clin(3*nsps,64)
- complex cavg(3*nsps,4)
- complex cavl(3*nsps,4)
- real pulse(3*nsps)
- real dphi(3*nsps)
-
- do i=1,3*NSPS
- t=(i-1.5*nsps)/real(nsps)
- pulse(i)=gfsk_pulse(1.0,t)
- enddo
-
- twopi=8.0*atan(1.0)
- hmod=1.0
- dphi_peak=twopi*hmod/real(nsps)
-
- do iwf=1,64
- i0=mod((iwf-1)/16,4)
- i1=mod((iwf-1)/4,4)
- i2=mod(iwf-1,4)
- dphi=0.0
- dphi(1:64)=dphi_peak*pulse(33:96)*i1
- dphi(1:96)=dphi(1:96)+dphi_peak*pulse(1:96)*i0
- dphi(33:96)=dphi(33:96)+dphi_peak*pulse(1:64)*i2
- phi=0.0
- do j=1,96
- cgfsk(j,iwf)=cmplx(cos(phi),sin(phi))
- phi=mod(phi+dphi(j),twopi)
- enddo
- cgfsk(:,iwf)=cgfsk(:,iwf)*conjg(cgfsk(48,iwf))
- enddo
-
- do iwf=1,64
- i0=mod((iwf-1)/16,4)
- i1=mod((iwf-1)/4,4)
- i2=mod(iwf-1,4)
- dphi=0.0
- dphi(1:32)=dphi_peak*i1
- dphi(33:64)=dphi_peak*i0
- dphi(65:96)=dphi_peak*i2
- phi=0.0
- do j=1,96
- clin(j,iwf)=cmplx(cos(phi),sin(phi))
- phi=mod(phi+dphi(j),twopi)
- enddo
- enddo
-
-
- do i=1,4
- ib=(i-1)*16+1
- ie=ib+15
- cavg(:,i)=sum(cgfsk(:,ib:ie),2)/16.0
- cavl(:,i)=sum(clin(:,ib:ie),2)/16.0
- do j=1,96
-write(*,*) j
-write(21,*) i,j,real(cavg(j,i)),imag(cavg(j,i)),real(cavl(j,i)),imag(cavl(j,i))
- enddo
- enddo
-
-end program averaged_mf
-
diff --git a/lib/ft4/ft4_downsample.f90 b/lib/ft4/ft4_downsample.f90
index ed55fb9a..bbe53a2a 100644
--- a/lib/ft4/ft4_downsample.f90
+++ b/lib/ft4/ft4_downsample.f90
@@ -1,8 +1,5 @@
subroutine ft4_downsample(dd,newdata,f0,c)
-! Input: real data in dd() at sample rate 12000 Hz
-! Output: Complex data in c(), sampled at 1200 Hz
-
include 'ft4_params.f90'
parameter (NFFT2=NMAX/NDOWN)
real dd(NMAX)
@@ -40,8 +37,8 @@ subroutine ft4_downsample(dd,newdata,f0,c)
c1=0.
if(i0.ge.0 .and. i0.le.NMAX/2) c1(0)=cx(i0)
do i=1,NFFT2/2
- if(i0+i.le.NMAX/2) c1(i)=cx(i0+i)
- if(i0-i.ge.0) c1(NFFT2-i)=cx(i0-i)
+ if(i0+i.ge.0 .and. i0+i.le.NMAX/2) c1(i)=cx(i0+i)
+ if(i0-i.ge.0 .and. i0-i.le.NMAX/2) c1(NFFT2-i)=cx(i0-i)
enddo
c1=c1*window/NFFT2
call four2a(c1,NFFT2,1,1,1) !c2c FFT back to time domain
diff --git a/lib/ft4/ft4_params.f90 b/lib/ft4/ft4_params.f90
index 2914260d..43abc573 100644
--- a/lib/ft4/ft4_params.f90
+++ b/lib/ft4/ft4_params.f90
@@ -1,5 +1,5 @@
! FT4
-! LDPC(174,91) code, four 4x4 Costas arrays for Sync
+! LDPC(174,91) code, four 4x4 Costas arrays for sync, ramp-up and ramp-down symbols
parameter (KK=91) !Information bits (77 + CRC14)
parameter (ND=87) !Data symbols
diff --git a/lib/ft4/ft4b.f90 b/lib/ft4/ft4b.f90
deleted file mode 100644
index d425277e..00000000
--- a/lib/ft4/ft4b.f90
+++ /dev/null
@@ -1,489 +0,0 @@
-subroutine ft4b(cdatetime0,tbuf,nfa,nfb,nQSOProgress,ncontest,nfqso, &
- iwave,ndecodes,mycall,hiscall,cqstr,line,data_dir)
-
- use packjt77
- include 'ft4_params.f90'
- parameter (NSS=NSPS/NDOWN)
-
- character message*37,msgsent*37,msg0*37
- character c77*77
- character*61 line,linex(100)
- character*37 decodes(100)
- character*512 data_dir,fname
- character*17 cdatetime0
- character*12 mycall,hiscall
- character*12 mycall0,hiscall0
- character*6 hhmmss
- character*4 cqstr,cqstr0
-
- complex cd2(0:NMAX/NDOWN-1) !Complex waveform
- complex cb(0:NMAX/NDOWN-1)
- complex cd(0:NN*NSS-1) !Complex waveform
- complex ctwk(2*NSS),ctwk2(2*NSS,-16:16)
- complex csymb(NSS)
- complex cs(0:3,NN)
- real s4(0:3,NN)
-
- real bmeta(2*NN),bmetb(2*NN),bmetc(2*NN)
- real a(5)
- real llr(2*ND),llra(2*ND),llrb(2*ND),llrc(2*ND),llrd(2*ND)
- real s2(0:255)
- real candidate(3,100)
- real savg(NH1),sbase(NH1)
-
- integer apbits(2*ND)
- integer apmy_ru(28),aphis_fd(28)
- integer icos4a(0:3),icos4b(0:3),icos4c(0:3),icos4d(0:3)
- integer*2 iwave(NMAX) !Raw received data
- integer*1 message77(77),rvec(77),apmask(2*ND),cw(2*ND)
- integer*1 hbits(2*NN)
- integer graymap(0:3)
- integer ip(1)
- integer nappasses(0:5) ! # of decoding passes for QSO States 0-5
- integer naptypes(0:5,4) ! nQSOProgress, decoding pass
- integer mcq(29)
- integer mrrr(19),m73(19),mrr73(19)
-
- logical nohiscall,unpk77_success
- logical one(0:255,0:7) ! 256 4-symbol sequences, 8 bits
- logical first, dobigfft
-
- data icos4a/0,1,3,2/
- data icos4b/1,0,2,3/
- data icos4c/2,3,1,0/
- data icos4d/3,2,0,1/
- data graymap/0,1,3,2/
- data msg0/' '/
- data first/.true./
- data mcq/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0/
- data mrrr/0,1,1,1,1,1,1,0,1,0,0,1,0,0,1,0,0,0,1/
- data m73/0,1,1,1,1,1,1,0,1,0,0,1,0,1,0,0,0,0,1/
- data mrr73/0,1,1,1,1,1,1,0,0,1,1,1,0,1,0,1,0,0,1/
- data rvec/0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,0,0,1,0,0,1,1,0,1,1,0, &
- 1,0,0,1,0,1,1,0,0,0,0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,0,1,0,1, &
- 0,1,0,1,0,1,1,0,1,1,1,1,1,0,0,0,1,0,1/
- save fs,dt,tt,txt,twopi,h,one,first,linex,apbits,nappasses,naptypes, &
- mycall0,hiscall0,msg0,cqstr0,ctwk2
-
- call clockit('ft4_deco',0)
- hhmmss=cdatetime0(8:13)
-
- if(first) then
- fs=12000.0/NDOWN !Sample rate after downsampling
- dt=1/fs !Sample interval after downsample (s)
- tt=NSPS*dt !Duration of "itone" symbols (s)
- txt=NZ*dt !Transmission length (s) without ramp up/down
- twopi=8.0*atan(1.0)
- h=1.0
- one=.false.
- do i=0,255
- do j=0,7
- if(iand(i,2**j).ne.0) one(i,j)=.true.
- enddo
- enddo
-
- do idf=-16,16
- a=0.
- a(1)=real(idf)
- ctwk=1.
- call clockit('twkfreq1',0)
- call twkfreq1(ctwk,2*NSS,fs/2.0,a,ctwk2(:,idf))
- call clockit('twkfreq1',1)
- enddo
-
- mrrr=2*mod(mrrr+rvec(59:77),2)-1
- m73=2*mod(m73+rvec(59:77),2)-1
- mrr73=2*mod(mrr73+rvec(59:77),2)-1
- nappasses(0)=2
- nappasses(1)=2
- nappasses(2)=2
- nappasses(3)=2
- nappasses(4)=2
- nappasses(5)=3
-
-! iaptype
-!------------------------
-! 1 CQ ??? ??? (29 ap bits)
-! 2 MyCall ??? ??? (29 ap bits)
-! 3 MyCall DxCall ??? (58 ap bits)
-! 4 MyCall DxCall RRR (77 ap bits)
-! 5 MyCall DxCall 73 (77 ap bits)
-! 6 MyCall DxCall RR73 (77 ap bits)
-!********
- naptypes(0,1:4)=(/1,2,0,0/) ! Tx6 selected (CQ)
- naptypes(1,1:4)=(/2,3,0,0/) ! Tx1
- naptypes(2,1:4)=(/2,3,0,0/) ! Tx2
- naptypes(3,1:4)=(/3,6,0,0/) ! Tx3
- naptypes(4,1:4)=(/3,6,0,0/) ! Tx4
- naptypes(5,1:4)=(/3,1,2,0/) ! Tx5
-
- mycall0=''
- hiscall0=''
- cqstr0=''
- first=.false.
- endif
-
- if(cqstr.ne.cqstr0) then
- i0=index(cqstr,' ')
- if(i0.le.1) then
- message='CQ A1AA AA01'
- else
- message='CQ '//cqstr(1:i0-1)//' A1AA AA01'
- endif
- i3=-1
- n3=-1
- call pack77(message,i3,n3,c77)
- call unpack77(c77,1,msgsent,unpk77_success)
- read(c77,'(29i1)') mcq
- mcq=2*mod(mcq+rvec(1:29),2)-1
- cqstr0=cqstr
- endif
-
- l1=index(mycall,char(0))
- if(l1.ne.0) mycall(l1:)=" "
- l1=index(hiscall,char(0))
- if(l1.ne.0) hiscall(l1:)=" "
- if(mycall.ne.mycall0 .or. hiscall.ne.hiscall0) then
- apbits=0
- apbits(1)=99
- apbits(30)=99
- apmy_ru=0
- aphis_fd=0
-
- if(len(trim(mycall)) .lt. 3) go to 10
-
- nohiscall=.false.
- hiscall0=hiscall
- if(len(trim(hiscall0)).lt.3) then
- hiscall0=mycall ! use mycall for dummy hiscall - mycall won't be hashed.
- nohiscall=.true.
- endif
- message=trim(mycall)//' '//trim(hiscall0)//' RR73'
- i3=-1
- n3=-1
- call pack77(message,i3,n3,c77)
- call unpack77(c77,1,msgsent,unpk77_success)
- if(i3.ne.1 .or. (message.ne.msgsent) .or. .not.unpk77_success) go to 10
- read(c77,'(77i1)') message77
- apmy_ru=2*mod(message77(1:28)+rvec(2:29),2)-1
- aphis_fd=2*mod(message77(30:57)+rvec(29:56),2)-1
- message77=mod(message77+rvec,2)
- call encode174_91(message77,cw)
- apbits=2*cw-1
- if(nohiscall) apbits(30)=99
-
-10 continue
- mycall0=mycall
- hiscall0=hiscall
- endif
- candidate=0.0
- ncand=0
- syncmin=1.2
- maxcand=100
-
- fa=nfa
- fb=nfb
- call clockit('getcand4',0)
- call getcandidates4(iwave,fa,fb,syncmin,nfqso,maxcand,savg,candidate, &
- ncand,sbase)
- call clockit('getcand4',1)
-
- ndecodes=0
- dobigfft=.true.
- do icand=1,ncand
- f0=candidate(1,icand)
- snr=candidate(3,icand)-1.0
- if( f0.le.10.0 .or. f0.ge.4990.0 ) cycle
- call clockit('ft4_down',0)
- call ft4_downsample(iwave,dobigfft,f0,cd2) !Downsample from 512 to 32 Sa/Symbol
- if(dobigfft) dobigfft=.false.
- call clockit('ft4_down',1)
-
- sum2=sum(cd2*conjg(cd2))/(real(NMAX)/real(NDOWN))
- if(sum2.gt.0.0) cd2=cd2/sqrt(sum2)
-! Sample rate is now 12000/16 = 750 samples/second
- do isync=1,2
- if(isync.eq.1) then
- idfmin=-12
- idfmax=12
- idfstp=3
- ibmin=0
- ibmax=216 !Max DT = 216/750 = 0.288 s
- ibstp=4
- else
- idfmin=idfbest-4
- idfmax=idfbest+4
- idfstp=1
- ibmin=max(0,ibest-5)
- ibmax=min(ibest+5,NMAX/NDOWN-1)
- ibstp=1
- endif
- ibest=-1
- smax=-99.
- idfbest=0
- do idf=idfmin,idfmax,idfstp
-
- call clockit('sync4d ',0)
- do istart=ibmin,ibmax,ibstp
- call sync4d(cd2,istart,ctwk2(:,idf),1,sync) !Find sync power
- if(sync.gt.smax) then
- smax=sync
- ibest=istart
- idfbest=idf
- endif
- enddo
- call clockit('sync4d ',1)
-
- enddo
- enddo
- f0=f0+real(idfbest)
- if( f0.le.10.0 .or. f0.ge.4990.0 ) cycle
-
- call clockit('ft4down ',0)
- call ft4_downsample(iwave,dobigfft,f0,cb) !Final downsample with corrected f0
- call clockit('ft4down ',1)
- sum2=sum(abs(cb)**2)/(real(NSS)*NN)
- if(sum2.gt.0.0) cb=cb/sqrt(sum2)
- cd=cb(ibest:ibest+NN*NSS-1)
- call clockit('four2a ',0)
- do k=1,NN
- i1=(k-1)*NSS
- csymb=cd(i1:i1+NSS-1)
- call four2a(csymb,NSS,1,-1,1)
- cs(0:3,k)=csymb(1:4)
- s4(0:3,k)=abs(csymb(1:4))
- enddo
- call clockit('four2a ',1)
-
-! Sync quality check
- is1=0
- is2=0
- is3=0
- is4=0
- do k=1,4
- ip=maxloc(s4(:,k))
- if(icos4a(k-1).eq.(ip(1)-1)) is1=is1+1
- ip=maxloc(s4(:,k+33))
- if(icos4b(k-1).eq.(ip(1)-1)) is2=is2+1
- ip=maxloc(s4(:,k+66))
- if(icos4c(k-1).eq.(ip(1)-1)) is3=is3+1
- ip=maxloc(s4(:,k+99))
- if(icos4d(k-1).eq.(ip(1)-1)) is4=is4+1
- enddo
- nsync=is1+is2+is3+is4 !Number of correct hard sync symbols, 0-16
- if(smax .lt. 0.7 .or. nsync .lt. 8) cycle
-
- do nseq=1,3 !Try coherent sequences of 1, 2, and 4 symbols
- if(nseq.eq.1) nsym=1
- if(nseq.eq.2) nsym=2
- if(nseq.eq.3) nsym=4
- nt=2**(2*nsym)
- do ks=1,NN-nsym+1,nsym !87+16=103 symbols.
- amax=-1.0
- do i=0,nt-1
- i1=i/64
- i2=iand(i,63)/16
- i3=iand(i,15)/4
- i4=iand(i,3)
- if(nsym.eq.1) then
- s2(i)=abs(cs(graymap(i4),ks))
- elseif(nsym.eq.2) then
- s2(i)=abs(cs(graymap(i3),ks)+cs(graymap(i4),ks+1))
- elseif(nsym.eq.4) then
- s2(i)=abs(cs(graymap(i1),ks ) + &
- cs(graymap(i2),ks+1) + &
- cs(graymap(i3),ks+2) + &
- cs(graymap(i4),ks+3) &
- )
- else
- print*,"Error - nsym must be 1, 2, or 4."
- endif
- enddo
- ipt=1+(ks-1)*2
- if(nsym.eq.1) ibmax=1
- if(nsym.eq.2) ibmax=3
- if(nsym.eq.4) ibmax=7
- do ib=0,ibmax
- bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - &
- maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib))
- if(ipt+ib.gt.2*NN) cycle
- if(nsym.eq.1) then
- bmeta(ipt+ib)=bm
- elseif(nsym.eq.2) then
- bmetb(ipt+ib)=bm
- elseif(nsym.eq.4) then
- bmetc(ipt+ib)=bm
- endif
- enddo
- enddo
- enddo
-
- bmetb(205:206)=bmeta(205:206)
- bmetc(201:204)=bmetb(201:204)
- bmetc(205:206)=bmeta(205:206)
-
- call clockit('normaliz',0)
- call normalizebmet(bmeta,2*NN)
- call normalizebmet(bmetb,2*NN)
- call normalizebmet(bmetc,2*NN)
- call clockit('normaliz',1)
-
- hbits=0
- where(bmeta.ge.0) hbits=1
- ns1=count(hbits( 1: 8).eq.(/0,0,0,1,1,0,1,1/))
- ns2=count(hbits( 67: 74).eq.(/0,1,0,0,1,1,1,0/))
- ns3=count(hbits(133:140).eq.(/1,1,1,0,0,1,0,0/))
- ns4=count(hbits(199:206).eq.(/1,0,1,1,0,0,0,1/))
- nsync_qual=ns1+ns2+ns3+ns4
- if(nsync_qual.lt. 20) cycle
-
- scalefac=2.83
- llra( 1: 58)=bmeta( 9: 66)
- llra( 59:116)=bmeta( 75:132)
- llra(117:174)=bmeta(141:198)
- llra=scalefac*llra
- llrb( 1: 58)=bmetb( 9: 66)
- llrb( 59:116)=bmetb( 75:132)
- llrb(117:174)=bmetb(141:198)
- llrb=scalefac*llrb
- llrc( 1: 58)=bmetc( 9: 66)
- llrc( 59:116)=bmetc( 75:132)
- llrc(117:174)=bmetc(141:198)
- llrc=scalefac*llrc
-
- apmag=maxval(abs(llra))*1.1
- npasses=3+nappasses(nQSOProgress)
- if(ncontest.ge.5) npasses=3 ! Don't support Fox and Hound
- do ipass=1,npasses
- if(ipass.eq.1) llr=llra
- if(ipass.eq.2) llr=llrb
- if(ipass.eq.3) llr=llrc
- if(ipass.le.3) then
- apmask=0
- iaptype=0
- endif
-
- if(ipass .gt. 3) then
- llrd=llrc
- iaptype=naptypes(nQSOProgress,ipass-3)
-
-! ncontest=0 : NONE
-! 1 : NA_VHF
-! 2 : EU_VHF
-! 3 : FIELD DAY
-! 4 : RTTY
-! 5 : FOX
-! 6 : HOUND
-!
-! Conditions that cause us to bail out of AP decoding
- napwid=50
- if(ncontest.le.4 .and. iaptype.ge.3 .and. (abs(f0-nfqso).gt.napwid) ) cycle
- if(iaptype.ge.2 .and. apbits(1).gt.1) cycle ! No, or nonstandard, mycall
- if(iaptype.ge.3 .and. apbits(30).gt.1) cycle ! No, or nonstandard, dxcall
-
- if(iaptype.eq.1) then ! CQ or CQ TEST or CQ FD or CQ RU or CQ SCC
- apmask=0
- apmask(1:29)=1
- llrd(1:29)=apmag*mcq(1:29)
- endif
-
- if(iaptype.eq.2) then ! MyCall,???,???
- apmask=0
- if(ncontest.eq.0.or.ncontest.eq.1) then
- apmask(1:29)=1
- llrd(1:29)=apmag*apbits(1:29)
- else if(ncontest.eq.2) then
- apmask(1:28)=1
- llrd(1:28)=apmag*apbits(1:28)
- else if(ncontest.eq.3) then
- apmask(1:28)=1
- llrd(1:28)=apmag*apbits(1:28)
- else if(ncontest.eq.4) then
- apmask(2:29)=1
- llrd(2:29)=apmag*apmy_ru(1:28)
- endif
- endif
-
- if(iaptype.eq.3) then ! MyCall,DxCall,???
- apmask=0
- if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.2) then
- apmask(1:58)=1
- llrd(1:58)=apmag*apbits(1:58)
- else if(ncontest.eq.3) then ! Field Day
- apmask(1:56)=1
- llrd(1:28)=apmag*apbits(1:28)
- llrd(29:56)=apmag*aphis_fd(1:28)
- else if(ncontest.eq.4) then ! RTTY RU
- apmask(2:57)=1
- llrd(2:29)=apmag*apmy_ru(1:28)
- llrd(30:57)=apmag*apbits(30:57)
- endif
- endif
-
- if(iaptype.eq.4 .or. iaptype.eq.5 .or. iaptype.eq.6) then
- apmask=0
- if(ncontest.le.4) then
- apmask(1:91)=1 ! mycall, hiscall, RRR|73|RR73
- if(iaptype.eq.6) llrd(1:91)=apmag*apbits(1:91)
- endif
- endif
-
- llr=llrd
- endif
- max_iterations=40
- message77=0
- call clockit('bpdecode',0)
- call bpdecode174_91(llr,apmask,max_iterations,message77, &
- cw,nharderror,niterations)
- call clockit('bpdecode',1)
- if(sum(message77).eq.0) cycle
- if( nharderror.ge.0 ) then
- message77=mod(message77+rvec,2) ! remove rvec scrambling
- write(c77,'(77i1)') message77(1:77)
- call unpack77(c77,1,message,unpk77_success)
- idupe=0
- do i=1,ndecodes
- if(decodes(i).eq.message) idupe=1
- enddo
- if(ibest.le.10 .and. message.eq.msg0) idupe=1 !Already decoded
- if(idupe.eq.1) exit
- ndecodes=ndecodes+1
- decodes(ndecodes)=message
- if(snr.gt.0.0) then
- xsnr=10*log10(snr)-14.0
- else
- xsnr=-20.0
- endif
- nsnr=nint(max(-20.0,xsnr))
- freq=f0
- tsig=mod(tbuf + ibest/750.0,100.0)
-
- write(line,1000) hhmmss,nsnr,tsig,nint(freq),message
-1000 format(a6,i4,f5.1,i5,' + ',1x,a37)
- l1=index(data_dir,char(0))-1
- if(l1.ge.1) data_dir(l1+1:l1+1)="/"
- fname=data_dir(1:l1+1)//'all_ft4.txt'
- open(24,file=trim(fname),status='unknown',position='append')
- write(24,1002) cdatetime0,nsnr,tsig,nint(freq),message, &
- nharderror,nsync_qual,ipass,niterations,iaptype,nsync
- if(hhmmss.eq.' ') write(*,1002) cdatetime0,nsnr, &
- tsig,nint(freq),message,nharderror,nsync_qual,ipass, &
- niterations,iaptype
-1002 format(a17,i4,f5.1,i5,' Rx ',a37,6i4)
- close(24)
- linex(ndecodes)=line
- if(ibest.ge.ibmax-15) msg0=message !Possible dupe candidate
- exit
- endif
- enddo !Sequence estimation
- enddo !Candidate list
- call clockit('ft4_deco',1)
- call clockit2(data_dir)
- call clockit('ft4_deco',101)
- return
-
- entry get_ft4msg(idecode,line)
- line=linex(idecode)
- return
-
- end subroutine ft4b
diff --git a/lib/ft4/ft4d.f90 b/lib/ft4/ft4d.f90
deleted file mode 100644
index a63e3e0a..00000000
--- a/lib/ft4/ft4d.f90
+++ /dev/null
@@ -1,83 +0,0 @@
-program ft4d
-
- include 'ft4_params.f90'
- character*8 arg
- character*17 cdatetime
- character*512 data_dir
- character*12 mycall
- character*12 hiscall
- character*80 infile
- character*61 line
- character*4 cqstr
- real*8 fMHz
- integer ihdr(11)
- integer*2 iwave(240000) !20*12000
-
- fs=12000.0/NDOWN !Sample rate
- dt=1/fs !Sample interval after downsample (s)
- tt=NSPS*dt !Duration of "itone" symbols (s)
- baud=1.0/tt !Keying rate for "itone" symbols (baud)
- txt=NZ*dt !Transmission length (s)
-
- nargs=iargc()
- if(nargs.lt.1) then
- print*,'Usage: ft4d [-a <data_dir>] [-f fMHz] [-n nQSOProgress] file1 [file2 ...]'
- go to 999
- endif
- iarg=1
- data_dir="."
- call getarg(iarg,arg)
- if(arg(1:2).eq.'-a') then
- call getarg(iarg+1,data_dir)
- iarg=iarg+2
- endif
- call getarg(iarg,arg)
- if(arg(1:2).eq.'-f') then
- call getarg(iarg+1,arg)
- read(arg,*) fMHz
- iarg=iarg+2
- endif
- nQSOProgress=0
- if(arg(1:2).eq.'-n') then
- call getarg(iarg+1,arg)
- read(arg,*) nQSOProgress
- iarg=iarg+2
- endif
- nfa=10
- nfb=4990
- ndecodes=0
- nfqso=1500
- mycall="K9AN"
- hiscall="K1JT"
- ncontest=4
- cqstr="RU "
-
- do ifile=iarg,nargs
- call getarg(ifile,infile)
- open(10,file=infile,status='old',access='stream')
- read(10) ihdr
- npts=min(ihdr(11)/2,180000)
- read(10) iwave(1:npts)
- close(10)
- cdatetime=infile
- j2=index(infile,'.wav')
- if(j2.ge.14) cdatetime=infile(j2-13:j2)//'000'
- istep=3456
- nsteps=(npts-52800)/istep + 1
- do n=1,nsteps
- i0=(n-1)*istep + 1
- tbuf=(i0-1)/12000.0
- call ft4b(cdatetime,tbuf,nfa,nfb,nQSOProgress,ncontest, &
- nfqso,iwave(i0),ndecodes,mycall,hiscall,cqstr,line,data_dir)
- do idecode=1,ndecodes
- call get_ft4msg(idecode,line)
- write(*,'(a61)') line
- enddo
- enddo !steps
- enddo !files
-
- call four2a(xx,-1,1,-1,1) !Destroy FFTW plans to free their memory
-
-999 end program ft4d
-
-
diff --git a/lib/ft4/genft4.f90 b/lib/ft4/genft4.f90
index f57ca59a..66e70a61 100644
--- a/lib/ft4/genft4.f90
+++ b/lib/ft4/genft4.f90
@@ -11,7 +11,7 @@ subroutine genft4(msg0,ichk,msgsent,msgbits,i4tone)
! s16 + 87symbols + 2 ramp up/down = 105 total channel symbols
! r1 + s4 + d29 + s4 + d29 + s4 + d29 + s4 + r1
-! Message duration: TxT = 105*512/12000 = 4.48 s
+! Message duration: TxT = 105*576/12000 = 5.04 s
! use iso_c_binding, only: c_loc,c_size_t
diff --git a/lib/ft4/get_ft4_bitmetrics.f90 b/lib/ft4/get_ft4_bitmetrics.f90
new file mode 100644
index 00000000..eba86a41
--- /dev/null
+++ b/lib/ft4/get_ft4_bitmetrics.f90
@@ -0,0 +1,114 @@
+subroutine get_ft4_bitmetrics(cd,bitmetrics,badsync)
+
+ include 'ft4_params.f90'
+ parameter (NSS=NSPS/NDOWN,NDMAX=NMAX/NDOWN)
+ complex cd(0:NN*NSS-1)
+ complex cs(0:3,NN)
+ complex csymb(NSS)
+ integer icos4a(0:3),icos4b(0:3),icos4c(0:3),icos4d(0:3)
+ integer graymap(0:3)
+ integer ip(1)
+ logical one(0:255,0:7) ! 256 4-symbol sequences, 8 bits
+ logical first
+ logical badsync
+ real bitmetrics(2*NN,3)
+ real s2(0:255)
+ real s4(0:3,NN)
+
+ data icos4a/0,1,3,2/
+ data icos4b/1,0,2,3/
+ data icos4c/2,3,1,0/
+ data icos4d/3,2,0,1/
+ data graymap/0,1,3,2/
+ data first/.true./
+ save first,one
+
+ if(first) then
+ one=.false.
+ do i=0,255
+ do j=0,7
+ if(iand(i,2**j).ne.0) one(i,j)=.true.
+ enddo
+ enddo
+ first=.false.
+ endif
+
+ do k=1,NN
+ i1=(k-1)*NSS
+ csymb=cd(i1:i1+NSS-1)
+ call four2a(csymb,NSS,1,-1,1)
+ cs(0:3,k)=csymb(1:4)
+ s4(0:3,k)=abs(csymb(1:4))
+ enddo
+
+! Sync quality check
+ is1=0
+ is2=0
+ is3=0
+ is4=0
+ badsync=.false.
+ do k=1,4
+ ip=maxloc(s4(:,k))
+ if(icos4a(k-1).eq.(ip(1)-1)) is1=is1+1
+ ip=maxloc(s4(:,k+33))
+ if(icos4b(k-1).eq.(ip(1)-1)) is2=is2+1
+ ip=maxloc(s4(:,k+66))
+ if(icos4c(k-1).eq.(ip(1)-1)) is3=is3+1
+ ip=maxloc(s4(:,k+99))
+ if(icos4d(k-1).eq.(ip(1)-1)) is4=is4+1
+ enddo
+ nsync=is1+is2+is3+is4 !Number of correct hard sync symbols, 0-16
+ if(nsync .lt. 8) then
+ badsync=.true.
+ return
+ endif
+
+ do nseq=1,3 !Try coherent sequences of 1, 2, and 4 symbols
+ if(nseq.eq.1) nsym=1
+ if(nseq.eq.2) nsym=2
+ if(nseq.eq.3) nsym=4
+ nt=2**(2*nsym)
+ do ks=1,NN-nsym+1,nsym !87+16=103 symbols.
+ amax=-1.0
+ do i=0,nt-1
+ i1=i/64
+ i2=iand(i,63)/16
+ i3=iand(i,15)/4
+ i4=iand(i,3)
+ if(nsym.eq.1) then
+ s2(i)=abs(cs(graymap(i4),ks))
+ elseif(nsym.eq.2) then
+ s2(i)=abs(cs(graymap(i3),ks)+cs(graymap(i4),ks+1))
+ elseif(nsym.eq.4) then
+ s2(i)=abs(cs(graymap(i1),ks ) + &
+ cs(graymap(i2),ks+1) + &
+ cs(graymap(i3),ks+2) + &
+ cs(graymap(i4),ks+3) &
+ )
+ else
+ print*,"Error - nsym must be 1, 2, or 4."
+ endif
+ enddo
+ ipt=1+(ks-1)*2
+ if(nsym.eq.1) ibmax=1
+ if(nsym.eq.2) ibmax=3
+ if(nsym.eq.4) ibmax=7
+ do ib=0,ibmax
+ bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - &
+ maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib))
+ if(ipt+ib.gt.2*NN) cycle
+ bitmetrics(ipt+ib,nseq)=bm
+ enddo
+ enddo
+ enddo
+
+ bitmetrics(205:206,2)=bitmetrics(205:206,1)
+ bitmetrics(201:204,3)=bitmetrics(201:204,2)
+ bitmetrics(205:206,3)=bitmetrics(205:206,1)
+
+ call normalizebmet(bitmetrics(:,1),2*NN)
+ call normalizebmet(bitmetrics(:,2),2*NN)
+ call normalizebmet(bitmetrics(:,3),2*NN)
+ return
+
+end subroutine get_ft4_bitmetrics
diff --git a/lib/ft4/getcandidates4.f90 b/lib/ft4/getcandidates4.f90
index f7cef02e..3f62e814 100644
--- a/lib/ft4/getcandidates4.f90
+++ b/lib/ft4/getcandidates4.f90
@@ -8,9 +8,8 @@ subroutine getcandidates4(dd,fa,fb,syncmin,nfqso,maxcand,savg,candidate, &
real x(NFFT1)
real window(NFFT1)
complex cx(0:NH1)
- real candidate(3,maxcand)
+ real candidate(2,maxcand),candidatet(2,maxcand)
real dd(NMAX)
- integer ipk(1)
equivalence (x,cx)
logical first
data first/.true./
@@ -33,9 +32,7 @@ subroutine getcandidates4(dd,fa,fb,syncmin,nfqso,maxcand,savg,candidate, &
if(ib.gt.NMAX) exit
x=fac*dd(ia:ib)*window
call four2a(x,NFFT1,1,-1,0) !r2c FFT
- do i=1,NH1
- s(i,j)=real(cx(i))**2 + aimag(cx(i))**2
- enddo
+ s(1:NH1,j)=abs(cx(1:NH1))**2
savg=savg + s(1:NH1,j) !Average spectrum
enddo
savg=savg/NHSYM
@@ -47,12 +44,13 @@ subroutine getcandidates4(dd,fa,fb,syncmin,nfqso,maxcand,savg,candidate, &
nfa=fa/df
if(nfa.lt.nint(200.0/df)) nfa=nint(200.0/df)
nfb=fb/df
- if(nfb.gt.nint(5000.0/df)) nfb=nint(5000.0/df)
- ncand=0
+ if(nfb.gt.nint(4910.0/df)) nfb=nint(4910.0/df)
call ft4_baseline(savg,nfa,nfb,sbase)
if(any(sbase(nfa:nfb).le.0)) return
savsm(nfa:nfb)=savsm(nfa:nfb)/sbase(nfa:nfb)
f_offset = -1.5*12000.0/NSPS
+ ncand=0
+ candidatet=0
do i=nfa+1,nfb-1
if(savsm(i).ge.savsm(i-1) .and. savsm(i).ge.savsm(i+1) .and. &
savsm(i).ge.syncmin) then
@@ -60,19 +58,26 @@ subroutine getcandidates4(dd,fa,fb,syncmin,nfqso,maxcand,savg,candidate, &
del=0.
if(den.ne.0.0) del=0.5*(savsm(i-1)-savsm(i+1))/den
fpeak=(i+del)*df+f_offset
- if(fpeak.lt.0.0 .or. fpeak.gt.4910.0) cycle
+ if(fpeak.lt.200.0 .or. fpeak.gt.4910.0) cycle
speak=savsm(i) - 0.25*(savsm(i-1)-savsm(i+1))*del
ncand=ncand+1
- if(ncand.gt.maxcand) then
- ncand=maxcand
- exit
- endif
- candidate(1,ncand)=fpeak
- candidate(2,ncand)=-99.99
- candidate(3,ncand)=speak
+ candidatet(1,ncand)=fpeak
+ candidatet(2,ncand)=speak
if(ncand.eq.maxcand) exit
endif
enddo
-
+ candidate=0
+ nq=count(abs(candidatet(1,1:ncand)-nfqso).le.20.0)
+ n1=1
+ n2=nq+1
+ do i=1,ncand
+ if(abs(candidatet(1,i)-nfqso).le.20.0) then
+ candidate(1:2,n1)=candidatet(1:2,i)
+ n1=n1+1
+ else
+ candidate(1:2,n2)=candidatet(1:2,i)
+ n2=n2+1
+ endif
+ enddo
return
end subroutine getcandidates4
diff --git a/lib/ft4/sync4d.f90 b/lib/ft4/sync4d.f90
index 28cb10b9..8d78f66a 100644
--- a/lib/ft4/sync4d.f90
+++ b/lib/ft4/sync4d.f90
@@ -9,7 +9,6 @@ subroutine sync4d(cd0,i0,ctwk,itwk,sync)
complex csync2(2*NSS)
complex ctwk(2*NSS)
complex z1,z2,z3,z4
- complex zz1,zz2,zz3,zz4
logical first
integer icos4a(0:3),icos4b(0:3),icos4c(0:3),icos4d(0:3)
data icos4a/0,1,3,2/
@@ -19,7 +18,7 @@ subroutine sync4d(cd0,i0,ctwk,itwk,sync)
data first/.true./
save first,twopi,csynca,csyncb,csyncc,csyncd,fac
- p(z1)=real(z1*fac)**2 + aimag(z1*fac)**2 !Statement function for power
+ p(z1)=(real(z1*fac)**2 + aimag(z1*fac)**2)**0.5 !Statement function for power
if( first ) then
twopi=8.0*atan(1.0)
@@ -60,11 +59,12 @@ subroutine sync4d(cd0,i0,ctwk,itwk,sync)
z4=0.
if(itwk.eq.1) csync2=ctwk*csynca !Tweak the frequency
+ z1=0.
if(i1.ge.0 .and. i1+4*NSS-1.le.NP-1) then
z1=sum(cd0(i1:i1+4*NSS-1:2)*conjg(csync2))
elseif( i1.lt.0 ) then
npts=(i1+4*NSS-1)/2
- if(npts.le.8) then
+ if(npts.le.16) then
z1=0.
else
z1=sum(cd0(0:i1+4*NSS-1:2)*conjg(csync2(2*NSS-npts:)))
@@ -78,16 +78,18 @@ subroutine sync4d(cd0,i0,ctwk,itwk,sync)
if(i3.ge.0 .and. i3+4*NSS-1.le.NP-1) z3=sum(cd0(i3:i3+4*NSS-1:2)*conjg(csync2))
if(itwk.eq.1) csync2=ctwk*csyncd !Tweak the frequency
+ z4=0.
if(i4.ge.0 .and. i4+4*NSS-1.le.NP-1) then
z4=sum(cd0(i4:i4+4*NSS-1:2)*conjg(csync2))
elseif( i4+4*NSS-1.gt.NP-1 ) then
npts=(NP-1-i4+1)/2
- if(npts.le.8) then
+ if(npts.le.16) then
z4=0.
else
z4=sum(cd0(i4:i4+2*npts-1:2)*conjg(csync2(1:npts)))
endif
endif
+
sync = p(z1) + p(z2) + p(z3) + p(z4)
return
diff --git a/lib/ft4_decode.f90 b/lib/ft4_decode.f90
index 50c9fa47..c60ee179 100644
--- a/lib/ft4_decode.f90
+++ b/lib/ft4_decode.f90
@@ -34,7 +34,6 @@ contains
character message*37,msgsent*37
character c77*77
character*37 decodes(100)
- character*512 data_dir,fname
character*17 cdatetime0
character*12 mycall,hiscall
character*12 mycall0,hiscall0
@@ -45,43 +44,31 @@ contains
complex cb(0:NDMAX-1)
complex cd(0:NN*NSS-1) !Complex waveform
complex ctwk(2*NSS),ctwk2(2*NSS,-16:16)
- complex csymb(NSS)
- complex cs(0:3,NN)
- real s4(0:3,NN)
- real bmeta(2*NN),bmetb(2*NN),bmetc(2*NN)
real a(5)
+ real bitmetrics(2*NN,3)
real dd(NMAX)
real llr(2*ND),llra(2*ND),llrb(2*ND),llrc(2*ND),llrd(2*ND)
- real s2(0:255)
- real candidate(3,100)
+ real candidate(2,100)
real savg(NH1),sbase(NH1)
integer apbits(2*ND)
integer apmy_ru(28),aphis_fd(28)
- integer icos4a(0:3),icos4b(0:3),icos4c(0:3),icos4d(0:3)
integer*2 iwave(NMAX) !Raw received data
integer*1 message77(77),rvec(77),apmask(2*ND),cw(2*ND)
integer*1 hbits(2*NN)
- integer graymap(0:3)
integer i4tone(103)
- integer ip(1)
integer nappasses(0:5) ! # of decoding passes for QSO States 0-5
integer naptypes(0:5,4) ! nQSOProgress, decoding pass
integer mcq(29)
integer mrrr(19),m73(19),mrr73(19)
logical nohiscall,unpk77_success
- logical one(0:255,0:7) ! 256 4-symbol sequences, 8 bits
logical first, dobigfft
logical dosubtract,doosd
+ logical badsync
logical, intent(in) :: lapcqonly
- data icos4a/0,1,3,2/
- data icos4b/1,0,2,3/
- data icos4c/2,3,1,0/
- data icos4d/3,2,0,1/
- data graymap/0,1,3,2/
data first/.true./
data mcq/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0/
data mrrr/0,1,1,1,1,1,1,0,1,0,0,1,0,0,1,0,0,0,1/
@@ -90,7 +77,7 @@ contains
data rvec/0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,0,0,1,0,0,1,1,0,1,1,0, &
1,0,0,1,0,1,1,0,0,0,0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,0,1,0,1, &
0,1,0,1,0,1,1,0,1,1,1,1,1,0,0,0,1,0,1/
- save fs,dt,tt,txt,twopi,h,one,first,apbits,nappasses,naptypes, &
+ save fs,dt,tt,txt,twopi,h,first,apbits,nappasses,naptypes, &
mycall0,hiscall0,cqstr0,ctwk2
this%callback => callback
@@ -105,12 +92,6 @@ contains
txt=NZ*dt !Transmission length (s) without ramp up/down
twopi=8.0*atan(1.0)
h=1.0
- one=.false.
- do i=0,255
- do j=0,7
- if(iand(i,2**j).ne.0) one(i,j)=.true.
- enddo
- enddo
do idf=-16,16
a=0.
@@ -212,7 +193,7 @@ contains
dd=iwave
! ndepth=3: 3 passes, bp+osd
-! ndepth=2: 3 passes, bp only
+! ndepth=2: 3 passes, bp only
! ndepth=1: 1 pass, no subtraction
max_iterations=40
@@ -221,23 +202,23 @@ contains
doosd=.true.
nsp=3
if(ndepth.eq.2) then
- doosd=.false.
+ doosd=.false.
endif
- if(ndepth.eq.1) then
- nsp=1
- dosubtract=.false.
- doosd=.false.
+ if(ndepth.eq.1) then
+ nsp=1
+ dosubtract=.false.
+ doosd=.false.
endif
-
+
do isp = 1,nsp
if(isp.eq.2) then
- if(ndecodes.eq.0) exit
- nd1=ndecodes
+ if(ndecodes.eq.0) exit
+ nd1=ndecodes
elseif(isp.eq.3) then
- nd2=ndecodes-nd1
- if(nd2.eq.0) exit
+ nd2=ndecodes-nd1
+ if(nd2.eq.0) exit
endif
-
+
candidate=0.0
ncand=0
call timer('getcand4',0)
@@ -247,7 +228,7 @@ contains
dobigfft=.true.
do icand=1,ncand
f0=candidate(1,icand)
- snr=candidate(3,icand)-1.0
+ snr=candidate(2,icand)-1.0
call timer('ft4_down',0)
call ft4_downsample(dd,dobigfft,f0,cd2) !Downsample to 32 Sam/Sym
call timer('ft4_down',1)
@@ -255,175 +236,113 @@ contains
sum2=sum(cd2*conjg(cd2))/(real(NMAX)/real(NDOWN))
if(sum2.gt.0.0) cd2=cd2/sqrt(sum2)
! Sample rate is now 12000/18 = 666.67 samples/second
- do isync=1,2
- if(isync.eq.1) then
- idfmin=-12
- idfmax=12
- idfstp=3
- ibmin=-344
- ibmax=1012
- ibstp=4
- else
- idfmin=idfbest-4
- idfmax=idfbest+4
- idfstp=1
- ibmin=ibest-5
- ibmax=ibest+5
- ibstp=1
- endif
- ibest=-1
- smax=-99.
- idfbest=0
- call timer('sync4d ',0)
- do idf=idfmin,idfmax,idfstp
- do istart=ibmin,ibmax,ibstp
- call sync4d(cd2,istart,ctwk2(:,idf),1,sync) !Find sync power
- if(sync.gt.smax) then
- smax=sync
- ibest=istart
- idfbest=idf
- endif
- enddo
- enddo
- call timer('sync4d ',1)
- enddo
- f0=f0+real(idfbest)
- if( f0.le.10.0 .or. f0.ge.4990.0 ) cycle
- call timer('ft4down ',0)
- call ft4_downsample(dd,dobigfft,f0,cb) !Final downsample, corrected f0
- call timer('ft4down ',1)
- sum2=sum(abs(cb)**2)/(real(NSS)*NN)
- if(sum2.gt.0.0) cb=cb/sqrt(sum2)
- cd=0.
- if(ibest.ge.0) then
- it=min(NDMAX-1,ibest+NN*NSS-1)
- np=it-ibest+1
- cd(0:np-1)=cb(ibest:it)
- else
- cd(-ibest:ibest+NN*NSS-1)=cb(0:NN*NSS+2*ibest-1)
- endif
- call timer('four2a ',0)
- do k=1,NN
- i1=(k-1)*NSS
- csymb=cd(i1:i1+NSS-1)
- call four2a(csymb,NSS,1,-1,1)
- cs(0:3,k)=csymb(1:4)
- s4(0:3,k)=abs(csymb(1:4))
- enddo
- call timer('four2a ',1)
-
-! Sync quality check
- is1=0
- is2=0
- is3=0
- is4=0
- do k=1,4
- ip=maxloc(s4(:,k))
- if(icos4a(k-1).eq.(ip(1)-1)) is1=is1+1
- ip=maxloc(s4(:,k+33))
- if(icos4b(k-1).eq.(ip(1)-1)) is2=is2+1
- ip=maxloc(s4(:,k+66))
- if(icos4c(k-1).eq.(ip(1)-1)) is3=is3+1
- ip=maxloc(s4(:,k+99))
- if(icos4d(k-1).eq.(ip(1)-1)) is4=is4+1
- enddo
- nsync=is1+is2+is3+is4 !Number of correct hard sync symbols, 0-16
- if(smax .lt. 0.7 .or. nsync .lt. 8) cycle
-
- do nseq=1,3 !Try coherent sequences of 1, 2, and 4 symbols
- if(nseq.eq.1) nsym=1
- if(nseq.eq.2) nsym=2
- if(nseq.eq.3) nsym=4
- nt=2**(2*nsym)
- do ks=1,NN-nsym+1,nsym !87+16=103 symbols.
- amax=-1.0
- do i=0,nt-1
- i1=i/64
- i2=iand(i,63)/16
- i3=iand(i,15)/4
- i4=iand(i,3)
- if(nsym.eq.1) then
- s2(i)=abs(cs(graymap(i4),ks))
- elseif(nsym.eq.2) then
- s2(i)=abs(cs(graymap(i3),ks)+cs(graymap(i4),ks+1))
- elseif(nsym.eq.4) then
- s2(i)=abs(cs(graymap(i1),ks ) + &
- cs(graymap(i2),ks+1) + &
- cs(graymap(i3),ks+2) + &
- cs(graymap(i4),ks+3) &
- )
- else
- print*,"Error - nsym must be 1, 2, or 4."
- endif
- enddo
- ipt=1+(ks-1)*2
- if(nsym.eq.1) ibmax=1
- if(nsym.eq.2) ibmax=3
- if(nsym.eq.4) ibmax=7
- do ib=0,ibmax
- bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - &
- maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib))
- if(ipt+ib.gt.2*NN) cycle
- if(nsym.eq.1) then
- bmeta(ipt+ib)=bm
- elseif(nsym.eq.2) then
- bmetb(ipt+ib)=bm
- elseif(nsym.eq.4) then
- bmetc(ipt+ib)=bm
+ do iseg=1,3 ! DT search is done over 3 segments
+ do isync=1,2
+ if(isync.eq.1) then
+ idfmin=-12
+ idfmax=12
+ idfstp=3
+ ibmin=-344
+ ibmax=1012
+ if(iseg.eq.1) then
+ ibmin=108
+ ibmax=560
+ elseif(iseg.eq.2) then
+ smax1=smax
+ ibmin=560
+ ibmax=1012
+ elseif(iseg.eq.3) then
+ ibmin=-344
+ ibmax=108
endif
+ ibstp=4
+ else
+ idfmin=idfbest-4
+ idfmax=idfbest+4
+ idfstp=1
+ ibmin=ibest-5
+ ibmax=ibest+5
+ ibstp=1
+ endif
+ ibest=-1
+ idfbest=0
+ smax=-99.
+ call timer('sync4d ',0)
+ do idf=idfmin,idfmax,idfstp
+ do istart=ibmin,ibmax,ibstp
+ call sync4d(cd2,istart,ctwk2(:,idf),1,sync) !Find sync power
+ if(sync.gt.smax) then
+ smax=sync
+ ibest=istart
+ idfbest=idf
+ endif
+ enddo
enddo
+ call timer('sync4d ',1)
enddo
- enddo
-
- bmetb(205:206)=bmeta(205:206)
- bmetc(201:204)=bmetb(201:204)
- bmetc(205:206)=bmeta(205:206)
-
- call normalizebmet(bmeta,2*NN)
- call normalizebmet(bmetb,2*NN)
- call normalizebmet(bmetc,2*NN)
-
- hbits=0
- where(bmeta.ge.0) hbits=1
- ns1=count(hbits( 1: 8).eq.(/0,0,0,1,1,0,1,1/))
- ns2=count(hbits( 67: 74).eq.(/0,1,0,0,1,1,1,0/))
- ns3=count(hbits(133:140).eq.(/1,1,1,0,0,1,0,0/))
- ns4=count(hbits(199:206).eq.(/1,0,1,1,0,0,0,1/))
- nsync_qual=ns1+ns2+ns3+ns4
- if(nsync_qual.lt. 20) cycle
-
- scalefac=2.83
- llra( 1: 58)=bmeta( 9: 66)
- llra( 59:116)=bmeta( 75:132)
- llra(117:174)=bmeta(141:198)
- llra=scalefac*llra
- llrb( 1: 58)=bmetb( 9: 66)
- llrb( 59:116)=bmetb( 75:132)
- llrb(117:174)=bmetb(141:198)
- llrb=scalefac*llrb
- llrc( 1: 58)=bmetc( 9: 66)
- llrc( 59:116)=bmetc( 75:132)
- llrc(117:174)=bmetc(141:198)
- llrc=scalefac*llrc
-
- apmag=maxval(abs(llra))*1.1
- npasses=3+nappasses(nQSOProgress)
- if(lapcqonly) npasses=4
- if(ndepth.eq.1) npasses=3
- if(ncontest.ge.5) npasses=3 ! Don't support Fox and Hound
- do ipass=1,npasses
- if(ipass.eq.1) llr=llra
- if(ipass.eq.2) llr=llrb
- if(ipass.eq.3) llr=llrc
- if(ipass.le.3) then
- apmask=0
- iaptype=0
+ if(iseg.eq.1) smax1=smax
+ if(smax.lt.1.2) cycle
+ if(iseg.gt.1 .and. smax.lt.smax1) cycle
+ f1=f0+real(idfbest)
+ if( f1.le.10.0 .or. f1.ge.4990.0 ) cycle
+ call timer('ft4down ',0)
+ call ft4_downsample(dd,dobigfft,f1,cb) !Final downsample, corrected f0
+ call timer('ft4down ',1)
+ sum2=sum(abs(cb)**2)/(real(NSS)*NN)
+ if(sum2.gt.0.0) cb=cb/sqrt(sum2)
+ cd=0.
+ if(ibest.ge.0) then
+ it=min(NDMAX-1,ibest+NN*NSS-1)
+ np=it-ibest+1
+ cd(0:np-1)=cb(ibest:it)
+ else
+ cd(-ibest:ibest+NN*NSS-1)=cb(0:NN*NSS+2*ibest-1)
endif
+ call timer('bitmet ',0)
+ call get_ft4_bitmetrics(cd,bitmetrics,badsync)
+ call timer('bitmet ',1)
+ if(badsync) cycle
+ hbits=0
+ where(bitmetrics(:,1).ge.0) hbits=1
+ ns1=count(hbits( 1: 8).eq.(/0,0,0,1,1,0,1,1/))
+ ns2=count(hbits( 67: 74).eq.(/0,1,0,0,1,1,1,0/))
+ ns3=count(hbits(133:140).eq.(/1,1,1,0,0,1,0,0/))
+ ns4=count(hbits(199:206).eq.(/1,0,1,1,0,0,0,1/))
+ nsync_qual=ns1+ns2+ns3+ns4
+ if(nsync_qual.lt. 20) cycle
+
+ scalefac=2.83
+ llra( 1: 58)=bitmetrics( 9: 66, 1)
+ llra( 59:116)=bitmetrics( 75:132, 1)
+ llra(117:174)=bitmetrics(141:198, 1)
+ llra=scalefac*llra
+ llrb( 1: 58)=bitmetrics( 9: 66, 2)
+ llrb( 59:116)=bitmetrics( 75:132, 2)
+ llrb(117:174)=bitmetrics(141:198, 2)
+ llrb=scalefac*llrb
+ llrc( 1: 58)=bitmetrics( 9: 66, 3)
+ llrc( 59:116)=bitmetrics( 75:132, 3)
+ llrc(117:174)=bitmetrics(141:198, 3)
+ llrc=scalefac*llrc
+
+ apmag=maxval(abs(llra))*1.1
+ npasses=3+nappasses(nQSOProgress)
+ if(lapcqonly) npasses=4
+ if(ndepth.eq.1) npasses=3
+ if(ncontest.ge.5) npasses=3 ! Don't support Fox and Hound
+ do ipass=1,npasses
+ if(ipass.eq.1) llr=llra
+ if(ipass.eq.2) llr=llrb
+ if(ipass.eq.3) llr=llrc
+ if(ipass.le.3) then
+ apmask=0
+ iaptype=0
+ endif
- if(ipass .gt. 3) then
- llrd=llra
- iaptype=naptypes(nQSOProgress,ipass-3)
- if(lapcqonly) iaptype=1
+ if(ipass .gt. 3) then
+ llrd=llra
+ iaptype=naptypes(nQSOProgress,ipass-3)
+ if(lapcqonly) iaptype=1
! ncontest=0 : NONE
! 1 : NA_VHF
@@ -434,108 +353,111 @@ contains
! 6 : HOUND
!
! Conditions that cause us to bail out of AP decoding
- napwid=50
- if(ncontest.le.4 .and. iaptype.ge.3 .and. (abs(f0-nfqso).gt.napwid) ) cycle
- if(iaptype.ge.2 .and. apbits(1).gt.1) cycle ! No, or nonstandard, mycall
- if(iaptype.ge.3 .and. apbits(30).gt.1) cycle ! No, or nonstandard, dxcall
-
- if(iaptype.eq.1) then ! CQ or CQ TEST or CQ FD or CQ RU or CQ SCC
- apmask=0
- apmask(1:29)=1
- llrd(1:29)=apmag*mcq(1:29)
- endif
+ napwid=50
+ if(ncontest.le.4 .and. iaptype.ge.3 .and. (abs(f1-nfqso).gt.napwid) ) cycle
+ if(iaptype.ge.2 .and. apbits(1).gt.1) cycle ! No, or nonstandard, mycall
+ if(iaptype.ge.3 .and. apbits(30).gt.1) cycle ! No, or nonstandard, dxcall
- if(iaptype.eq.2) then ! MyCall,???,???
- apmask=0
- if(ncontest.eq.0.or.ncontest.eq.1) then
+ if(iaptype.eq.1) then ! CQ or CQ TEST or CQ FD or CQ RU or CQ SCC
+ apmask=0
apmask(1:29)=1
- llrd(1:29)=apmag*apbits(1:29)
- else if(ncontest.eq.2) then
- apmask(1:28)=1
- llrd(1:28)=apmag*apbits(1:28)
- else if(ncontest.eq.3) then
- apmask(1:28)=1
- llrd(1:28)=apmag*apbits(1:28)
- else if(ncontest.eq.4) then
- apmask(2:29)=1
- llrd(2:29)=apmag*apmy_ru(1:28)
+ llrd(1:29)=apmag*mcq(1:29)
endif
- endif
- if(iaptype.eq.3) then ! MyCall,DxCall,???
- apmask=0
- if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.2) then
- apmask(1:58)=1
- llrd(1:58)=apmag*apbits(1:58)
- else if(ncontest.eq.3) then ! Field Day
- apmask(1:56)=1
- llrd(1:28)=apmag*apbits(1:28)
- llrd(29:56)=apmag*aphis_fd(1:28)
- else if(ncontest.eq.4) then ! RTTY RU
- apmask(2:57)=1
- llrd(2:29)=apmag*apmy_ru(1:28)
- llrd(30:57)=apmag*apbits(30:57)
+ if(iaptype.eq.2) then ! MyCall,???,???
+ apmask=0
+ if(ncontest.eq.0.or.ncontest.eq.1) then
+ apmask(1:29)=1
+ llrd(1:29)=apmag*apbits(1:29)
+ else if(ncontest.eq.2) then
+ apmask(1:28)=1
+ llrd(1:28)=apmag*apbits(1:28)
+ else if(ncontest.eq.3) then
+ apmask(1:28)=1
+ llrd(1:28)=apmag*apbits(1:28)
+ else if(ncontest.eq.4) then
+ apmask(2:29)=1
+ llrd(2:29)=apmag*apmy_ru(1:28)
+ endif
endif
- endif
- if(iaptype.eq.4 .or. iaptype.eq.5 .or. iaptype.eq.6) then
- apmask=0
- if(ncontest.le.4) then
- apmask(1:91)=1 ! mycall, hiscall, RRR|73|RR73
- if(iaptype.eq.6) llrd(1:91)=apmag*apbits(1:91)
+ if(iaptype.eq.3) then ! MyCall,DxCall,???
+ apmask=0
+ if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.2) then
+ apmask(1:58)=1
+ llrd(1:58)=apmag*apbits(1:58)
+ else if(ncontest.eq.3) then ! Field Day
+ apmask(1:56)=1
+ llrd(1:28)=apmag*apbits(1:28)
+ llrd(29:56)=apmag*aphis_fd(1:28)
+ else if(ncontest.eq.4) then ! RTTY RU
+ apmask(2:57)=1
+ llrd(2:29)=apmag*apmy_ru(1:28)
+ llrd(30:57)=apmag*apbits(30:57)
+ endif
endif
- endif
- llr=llrd
- endif
- message77=0
- dmin=0.0
- call timer('bpdec174',0)
- call bpdecode174_91(llr,apmask,max_iterations,message77, &
- cw,nharderror,niterations)
- call timer('bpdec174',1)
-
- if(doosd .and. nharderror.lt.0) then
- ndeep=3
- if(abs(nfqso-f1).le.napwid) then
- ndeep=4
- endif
- call timer('osd174_91 ',0)
- call osd174_91(llr,apmask,ndeep,message77,cw,nharderror,dmin)
- call timer('osd174_91 ',1)
- endif
+ if(iaptype.eq.4 .or. iaptype.eq.5 .or. iaptype.eq.6) then
+ apmask=0
+ if(ncontest.le.4) then
+ apmask(1:77)=1 ! mycall, hiscall, RRR|73|RR73
+ if(iaptype.eq.6) llrd(1:77)=apmag*apbits(1:77)
+ endif
+ endif
- if(sum(message77).eq.0) cycle
- if( nharderror.ge.0 ) then
- message77=mod(message77+rvec,2) ! remove rvec scrambling
- write(c77,'(77i1)') message77(1:77)
- call unpack77(c77,1,message,unpk77_success)
- if(unpk77_success.and.dosubtract) then
- call get_ft4_tones_from_77bits(message77,i4tone)
- dt=real(ibest)/666.67
- call timer('subtract',0)
- call subtractft4(dd,i4tone,f0,dt)
- call timer('subtract',1)
+ llr=llrd
endif
- idupe=0
- do i=1,ndecodes
- if(decodes(i).eq.message) idupe=1
- enddo
- if(idupe.eq.1) exit
- ndecodes=ndecodes+1
- decodes(ndecodes)=message
- if(snr.gt.0.0) then
- xsnr=10*log10(snr)-14.8
- else
- xsnr=-21.0
+ message77=0
+ dmin=0.0
+ call timer('bpdec174',0)
+ call bpdecode174_91(llr,apmask,max_iterations,message77, &
+ cw,nharderror,niterations)
+ call timer('bpdec174',1)
+
+ if(doosd .and. nharderror.lt.0) then
+ ndeep=3
+! if(abs(nfqso-f1).le.napwid) then
+! ndeep=4
+! endif
+ call timer('osd174_91 ',0)
+ call osd174_91(llr,apmask,ndeep,message77,cw,nharderror,dmin)
+ call timer('osd174_91 ',1)
endif
- nsnr=nint(max(-21.0,xsnr))
- xdt=ibest/666.67 - 0.5
-!write(21,'(i6.6,i5,2x,f4.1,i6,2x,a37,2x,f4.1,3i3,f5.1)') nutc,nsnr,xdt,nint(f0),message,sync,iaptype,ipass,isp,dmin
- call this%callback(sync,nsnr,xdt,f0,message,iaptype,qual)
- exit
- endif
- enddo !Sequence estimation
+
+ if(sum(message77).eq.0) cycle
+ if( nharderror.ge.0 ) then
+ message77=mod(message77+rvec,2) ! remove rvec scrambling
+ write(c77,'(77i1)') message77(1:77)
+ call unpack77(c77,1,message,unpk77_success)
+ if(unpk77_success.and.dosubtract) then
+ call get_ft4_tones_from_77bits(message77,i4tone)
+ dt=real(ibest)/666.67
+ call timer('subtract',0)
+ call subtractft4(dd,i4tone,f1,dt)
+ call timer('subtract',1)
+ endif
+ idupe=0
+ do i=1,ndecodes
+ if(decodes(i).eq.message) idupe=1
+ enddo
+ if(idupe.eq.1) exit
+ ndecodes=ndecodes+1
+ decodes(ndecodes)=message
+ if(snr.gt.0.0) then
+ xsnr=10*log10(snr)-14.8
+ else
+ xsnr=-21.0
+ endif
+ nsnr=nint(max(-21.0,xsnr))
+ xdt=ibest/666.67 - 0.5
+!write(21,'(i6.6,i5,2x,f4.1,i6,2x,a37,2x,f4.1,3i3,f5.1,i4,i4,i4)') &
+! nutc,nsnr,xdt,nint(f1),message,smax,iaptype,ipass,isp,dmin,nsync_qual,nharderror,iseg
+ call this%callback(smax,nsnr,xdt,f1,message,iaptype,qual)
+ exit
+ endif
+ enddo !Sequence estimation
+ if(nharderror.ge.0) exit
+ enddo !3 DT segments
enddo !Candidate list
enddo !Subtraction loop
return
diff --git a/lib/ft8/ft8sim.f90 b/lib/ft8/ft8sim.f90
index bbec600d..c5dd82bb 100644
--- a/lib/ft8/ft8sim.f90
+++ b/lib/ft8/ft8sim.f90
@@ -91,7 +91,7 @@ program ft8sim
msg0=msg
do ifile=1,nfiles
k=nint((xdt+0.5)/dt)
- ia=k
+ ia=max(1,k)
phi=0.0
c0=0.0
do j=1,NN !Generate complex waveform
@@ -105,7 +105,7 @@ program ft8sim
if(fspread.ne.0.0 .or. delay.ne.0.0) call watterson(c0,NMAX,NWAVE,fs,delay,fspread)
c=sig*c0
- ib=k
+ ib=min(k,NMAX)
wave=real(c)
peak=maxval(abs(wave(ia:ib)))
nslots=1
diff --git a/lib/ft8/subtractft8.f90 b/lib/ft8/subtractft8.f90
index 200139a2..ec0beea9 100644
--- a/lib/ft8/subtractft8.f90
+++ b/lib/ft8/subtractft8.f90
@@ -20,12 +20,11 @@ subroutine subtractft8(dd,itone,f0,dt)
save first
nstart=dt*12000+1
-! call genft8refsig(itone,cref,f0)
nsym=79
nsps=1920
fs=12000.0
icmplx=1
- bt=4.0 ! Temporary compromise?
+ bt=2.0
call gen_ft8wave(itone,nsym,nsps,bt,fs,f0,cref,xjunk,icmplx,NFRAME)
camp=0.
do i=1,nframe
diff --git a/lib/jt9.f90 b/lib/jt9.f90
index 67e7ac31..2e8dbd0f 100644
--- a/lib/jt9.f90
+++ b/lib/jt9.f90
@@ -139,7 +139,7 @@ program jt9
read (optarg(:arglen), *) nexp_decode
end select
end do
-
+
if (display_help .or. stat .lt. 0 &
.or. (.not. read_files .and. remain .gt. 0) &
.or. (read_files .and. remain .lt. 1)) then
@@ -179,7 +179,6 @@ program jt9
go to 999
endif
- if(mode.eq.5) ndepth=3
allocate(shared_data)
nflatten=0
@@ -234,7 +233,7 @@ program jt9
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 ',infile
+ print*,'EOF on input file ',trim(infile)
exit
4 call timer('read_wav',1)
nhsym=(k-2048)/kstep
diff --git a/lib/readwav.f90 b/lib/readwav.f90
index ebc30c9a..25369049 100644
--- a/lib/readwav.f90
+++ b/lib/readwav.f90
@@ -53,7 +53,8 @@ contains
type(riff_descriptor) :: desc
character(len=4) :: riff_type
- open (newunit=this%lun, file=filename, access='stream', form='unformatted', status='old')
+ this%lun=26
+ open (unit=this%lun, file=filename, access='stream',status='old')
read (unit=this%lun) desc,riff_type
inquire (unit=this%lun, pos=filepos)
do
@@ -67,5 +68,6 @@ contains
end if
filepos = filepos + (desc%size + 1) / 2 * 2 ! pad to even alignment
end do
+ return
end subroutine read
end module readwav
diff --git a/lib/rtty_spec.f90 b/lib/rtty_spec.f90
new file mode 100644
index 00000000..2ddc802f
--- /dev/null
+++ b/lib/rtty_spec.f90
@@ -0,0 +1,102 @@
+program rtty_spec
+
+! Generate simulated data for standard RTTY and WSJT-X modes FT8, FT4
+
+ use wavhdr
+ use packjt
+ parameter (NMAX=15*12000)
+ type(hdr) h
+ complex cwave(NMAX)
+ real wave(NMAX)
+ real*4 dat(NMAX) !Generated waveform
+ integer*2 iwave(NMAX) !Generated waveform
+ integer itone(680) !Channel symbols (values 0-1, 0-3, 0-7)
+ integer*1 msgbits(77)
+ character*37 msg37,msgsent37
+ character*8 arg
+
+ nargs=iargc()
+ if(nargs.ne.1) then
+ print*,'Usage: rtty_spec <snr>'
+ go to 999
+ endif
+ call getarg(1,arg)
+ read(arg,*) snrdb !S/N in dB (2500 hz reference BW)
+
+ rmsdb=25.
+ rms=10.0**(0.05*rmsdb)
+ sig=10.0**(0.05*snrdb)
+ npts=NMAX
+
+ do i=1,NMAX !Generate gaussian noise
+ dat(i)=gran()
+ enddo
+
+! Add the RTTY signal
+ fsample=12000.0 !Sample rate (Hz)
+ dt=1.0/fsample !Sample interval (s)
+ twopi=8.0*atan(1.0)
+ phi=0.
+ dphi=0.
+ j0=-1
+ do i=6001,NMAX-6000
+ j=nint(i*dt/0.022)
+ if(j.ne.j0) then
+ f0=1415.0
+ call random_number(rr)
+ if(rr.gt.0.5) f0=1585.0
+ dphi=twopi*f0*dt
+ j0=j
+ endif
+ phi=phi+dphi
+ if(phi.gt.twopi) phi=phi-twopi
+ dat(i)=dat(i) + sig*sin(phi)
+ enddo
+
+! FT8 signal (FSK)
+ i3=0
+ n3=0
+ msg37='WB9XYZ KA2ABC FN42'
+ call genft8(msg37,i3,n3,msgsent37,msgbits,itone)
+ nsym=79
+ nsps=1920
+ bt=99.0
+ f0=3500.0
+ icmplx=0
+ nwave=nsym*nsps
+ call gen_ft8wave(itone,nsym,nsps,bt,fsample,f0,cwave,wave,icmplx,nwave)
+ dat(6001:6000+nwave)=dat(6001:6000+nwave) + sig*wave(1:nwave)
+
+! FT8 signal (GFSK)
+ i3=0
+ n3=0
+ msg37='WB9XYZ KA2ABC FN42'
+ call genft8(msg37,i3,n3,msgsent37,msgbits,itone)
+ nsym=79
+ nsps=1920
+ bt=2.0
+ f0=4000.0
+ icmplx=0
+ nwave=nsym*nsps
+ call gen_ft8wave(itone,nsym,nsps,bt,fsample,f0,cwave,wave,icmplx,nwave)
+ dat(6001:6000+nwave)=dat(6001:6000+nwave) + sig*wave(1:nwave)
+
+! Add the FT4 signal
+ ichk=0
+ call genft4(msg37,ichk,msgsent37,msgbits,itone)
+ nsym=103
+ nsps=576
+ f0=4500.0
+ icmplx=0
+ nwave=(nsym+2)*nsps
+ call gen_ft4wave(itone,nsym,nsps,fsample,f0,cwave,wave,icmplx,nwave)
+ dat(6001:6000+nwave)=dat(6001:6000+nwave) + sig*wave(1:nwave)
+
+ h=default_header(12000,NMAX)
+ datmax=maxval(abs(dat))
+ iwave=nint(32767.0*dat/datmax)
+ open(10,file='000000_000001.wav',access='stream',status='unknown')
+ write(10) h,iwave
+ close(10)
+
+999 end program rtty_spec