Merge branch 'develop' of bitbucket.org:k1jt/wsjtx into develop

This commit is contained in:
Joe Taylor 2020-04-17 16:11:39 -04:00
commit 148e2f6538
12 changed files with 724 additions and 15 deletions

View File

@ -606,10 +606,14 @@ set (wsjt_FSRCS
# lib/ft8/decode174_91.f90 # lib/ft8/decode174_91.f90
lib/fsk4hf/ldpcsim174_91.f90 lib/fsk4hf/ldpcsim174_91.f90
lib/fsk4hf/ldpcsim174_74.f90 lib/fsk4hf/ldpcsim174_74.f90
lib/fsk4hf/ldpcsim174_101.f90
lib/fsk4hf/get_crc24.f90 lib/fsk4hf/get_crc24.f90
lib/fsk4hf/encode174_74.f90 lib/fsk4hf/encode174_74.f90
lib/fsk4hf/encode174_101.f90
lib/fsk4hf/bpdecode174_74.f90 lib/fsk4hf/bpdecode174_74.f90
lib/fsk4hf/bpdecode174_101.f90
lib/fsk4hf/osd174_74.f90 lib/fsk4hf/osd174_74.f90
lib/fsk4hf/osd174_101.f90
lib/fsk4hf/wspr4sim.f90 lib/fsk4hf/wspr4sim.f90
lib/fsk4hf/genwspr4.f90 lib/fsk4hf/genwspr4.f90
lib/fsk4hf/gen_wspr4wave.f90 lib/fsk4hf/gen_wspr4wave.f90
@ -1361,6 +1365,9 @@ target_link_libraries (ldpcsim174_91 wsjt_fort wsjt_cxx)
add_executable (ldpcsim174_74 lib/fsk4hf/ldpcsim174_74.f90 wsjtx.rc) add_executable (ldpcsim174_74 lib/fsk4hf/ldpcsim174_74.f90 wsjtx.rc)
target_link_libraries (ldpcsim174_74 wsjt_fort wsjt_cxx) target_link_libraries (ldpcsim174_74 wsjt_fort wsjt_cxx)
add_executable (ldpcsim174_101 lib/fsk4hf/ldpcsim174_101.f90 wsjtx.rc)
target_link_libraries (ldpcsim174_101 wsjt_fort wsjt_cxx)
add_executable (wspr4sim lib/fsk4hf/wspr4sim.f90 wsjtx.rc) add_executable (wspr4sim lib/fsk4hf/wspr4sim.f90 wsjtx.rc)
target_link_libraries (wspr4sim wsjt_fort wsjt_cxx) target_link_libraries (wspr4sim wsjt_fort wsjt_cxx)

View File

@ -0,0 +1,113 @@
subroutine bpdecode174_101(llr,apmask,maxiterations,message50,cw,nharderror,iter)
!
! A log-domain belief propagation decoder for the (174,101) code.
!
integer, parameter:: N=174, K=101, M=N-K
integer*1 cw(N),apmask(N)
integer*1 decoded(K)
integer*1 message77(77)
integer nrw(M),ncw
integer Nm(8,M)
integer Mn(3,N) ! 3 checks per bit
integer synd(M)
real tov(3,N)
real toc(8,M)
real tanhtoc(8,M)
real zn(N)
real llr(N)
real Tmn
include "ldpc_174_101_parity.f90"
decoded=0
toc=0
tov=0
tanhtoc=0
! initialize messages to checks
do j=1,M
do i=1,nrw(j)
toc(i,j)=llr((Nm(i,j)))
enddo
enddo
ncnt=0
nclast=0
do iter=0,maxiterations
! Update bit log likelihood ratios (tov=0 in iteration 0).
do i=1,N
if( apmask(i) .ne. 1 ) then
zn(i)=llr(i)+sum(tov(1:ncw,i))
else
zn(i)=llr(i)
endif
enddo
! Check to see if we have a codeword (check before we do any iteration).
cw=0
where( zn .gt. 0. ) cw=1
ncheck=0
do i=1,M
synd(i)=sum(cw(Nm(1:nrw(i),i)))
if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1
! if( mod(synd(i),2) .ne. 0 ) write(*,*) 'check ',i,' unsatisfied'
enddo
if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it
decoded=cw(1:101)
call get_crc24(decoded,101,nbadcrc)
nharderror=count( (2*cw-1)*llr .lt. 0.0 )
if(nbadcrc.eq.0) then
message77=decoded(1:77)
return
endif
endif
if( iter.gt.0 ) then ! this code block implements an early stopping criterion
! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion
nd=ncheck-nclast
if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased
ncnt=0 ! reset counter
else
ncnt=ncnt+1
endif
! write(*,*) iter,ncheck,nd,ncnt
if( ncnt .ge. 5 .and. iter .ge. 10 .and. ncheck .gt. 15) then
nharderror=-1
return
endif
endif
nclast=ncheck
! Send messages from bits to check nodes
do j=1,M
do i=1,nrw(j)
ibj=Nm(i,j)
toc(i,j)=zn(ibj)
do kk=1,ncw ! subtract off what the bit had received from the check
if( Mn(kk,ibj) .eq. j ) then
toc(i,j)=toc(i,j)-tov(kk,ibj)
endif
enddo
enddo
enddo
! send messages from check nodes to variable nodes
do i=1,M
tanhtoc(1:8,i)=tanh(-toc(1:8,i)/2)
enddo
do j=1,N
do i=1,ncw
ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j
Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j)
call platanh(-Tmn,y)
! y=atanh(-Tmn)
tov(i,j)=2*y
enddo
enddo
enddo
nharderror=-1
return
end subroutine bpdecode174_101

View File

@ -55,7 +55,7 @@ subroutine bpdecode174_74(llr,apmask,maxiterations,message50,cw,nharderror,iter)
enddo enddo
if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it
decoded=cw(1:74) decoded=cw(1:74)
call get_crc24(decoded,nbadcrc) call get_crc24(decoded,74,nbadcrc)
nharderror=count( (2*cw-1)*llr .lt. 0.0 ) nharderror=count( (2*cw-1)*llr .lt. 0.0 )
if(nbadcrc.eq.0) then if(nbadcrc.eq.0) then
message50=decoded(1:50) message50=decoded(1:50)

View File

@ -0,0 +1,46 @@
subroutine encode174_101(message,codeword)
use, intrinsic :: iso_c_binding
use iso_c_binding, only: c_loc,c_size_t
use crc
integer, parameter:: N=174, K=101, M=N-K
character*24 c24
integer*1 codeword(N)
integer*1 gen(M,K)
integer*1 message(K)
integer*1 pchecks(M)
integer*4 ncrc24
include "ldpc_174_101_generator.f90"
logical first
data first/.true./
save first,gen
if( first ) then ! fill the generator matrix
gen=0
do i=1,M
do j=1,26
read(g(i)(j:j),"(Z1)") istr
ibmax=4
if(j.eq.26) ibmax=1
do jj=1, ibmax
icol=(j-1)*4+jj
if( btest(istr,4-jj) ) gen(i,icol)=1
enddo
enddo
enddo
first=.false.
endif
do i=1,M
nsum=0
do j=1,K
nsum=nsum+message(j)*gen(i,j)
enddo
pchecks(i)=mod(nsum,2)
enddo
codeword(1:K)=message
codeword(K+1:N)=pchecks
return
end subroutine encode174_101

View File

@ -54,7 +54,7 @@ subroutine genwspr4(msg0,ichk,msgsent,msgbits,i4tone)
call unpack77(c77,0,msgsent,unpk77_success) !Unpack to get msgsent call unpack77(c77,0,msgsent,unpk77_success) !Unpack to get msgsent
msgbits=0 msgbits=0
read(c77,'(50i1)') msgbits(1:50) read(c77,'(50i1)') msgbits(1:50)
call get_crc24(msgbits,ncrc24) call get_crc24(msgbits,74,ncrc24)
write(c24,'(b24.24)') ncrc24 write(c24,'(b24.24)') ncrc24
read(c24,'(24i1)') msgbits(51:74) read(c24,'(24i1)') msgbits(51:74)

View File

@ -1,19 +1,19 @@
subroutine get_crc24(mc,ncrc) subroutine get_crc24(mc,len,ncrc)
! !
! 1. To calculate 24-bit CRC, mc(1:50) is the message and mc(51:74) are zero. ! 1. To calculate 24-bit CRC, mc(1:len-24) is the message and mc(len-23:len) are zero.
! 2. To check a received CRC, mc(1:74) is the received message plus CRC. ! 2. To check a received CRC, mc(1:len) is the received message plus CRC.
! ncrc will be zero if the received message/CRC are consistent. ! ncrc will be zero if the received message/CRC are consistent.
! !
character c24*24 character c24*24
integer*1 mc(len)
integer*1 mc(74),r(25),p(25) integer*1 r(25),p(25)
integer ncrc integer ncrc
! polynomial for 24-bit CRC 0x100065b ! polynomial for 24-bit CRC 0x100065b
data p/1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,0,1,1,0,1,1/ data p/1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,0,1,1,0,1,1/
! divide by polynomial ! divide by polynomial
r=mc(1:25) r=mc(1:25)
do i=0,49 do i=0,len-25
r(25)=mc(i+25) r(25)=mc(i+25)
r=mod(r+r(1)*p,2) r=mod(r+r(1)*p,2)
r=cshift(r,1) r=cshift(r,1)

View File

@ -0,0 +1,142 @@
program ldpcsim174_101
! End-to-end test of the (174,101)/crc24 encoder and decoders.
use packjt77
parameter(N=174, K=101, M=N-K)
character*8 arg
character*37 msg0,msg
character*77 c77
character*24 c24
integer*1 msgbits(101)
integer*1 apmask(174)
integer*1 cw(174)
integer*1 codeword(N),message(77)
integer ncrc24
real rxdata(N),llr(N)
real dllr(174),llrd(174)
logical first,unpk77_success
data first/.true./
nargs=iargc()
if(nargs.ne.5 .and. nargs.ne.6) then
print*,'Usage: ldpcsim niter ndeep #trials s K [msg]'
print*,'e.g. ldpcsim174_101 20 5 1000 0.85 91 "K9AN K1JT FN20"'
print*,'s : if negative, then value is ignored and sigma is calculated from SNR.'
print*,'niter: is the number of BP iterations.'
print*,'ndeep: -1 is BP only, ndeep>=0 is OSD order'
print*,'K :is the number of message+CRC bits and must be in the range [77,101]'
print*,'WSPR-format message is optional'
return
endif
call getarg(1,arg)
read(arg,*) max_iterations
call getarg(2,arg)
read(arg,*) ndeep
call getarg(3,arg)
read(arg,*) ntrials
call getarg(4,arg)
read(arg,*) s
call getarg(5,arg)
read(arg,*) Keff
msg0='K9AN K1JT FN20 '
if(nargs.eq.6) call getarg(6,msg0)
call pack77(msg0,i3,n3,c77)
rate=real(Keff)/real(N)
write(*,*) "code rate: ",rate
write(*,*) "niter : ",max_iterations
write(*,*) "ndeep : ",ndeep
write(*,*) "s : ",s
write(*,*) "K : ",Keff
msgbits=0
read(c77,'(77i1)') msgbits(1:77)
write(*,*) 'message'
write(*,'(77i1)') msgbits(1:77)
call get_crc24(msgbits,101,ncrc24)
write(c24,'(b24.24)') ncrc24
write(*,*) 'c24 ',c24
read(c24,'(24i1)') msgbits(78:101)
write(*,'(24i1)') msgbits(78:101)
write(*,*) 'message with crc24'
write(*,'(101i1)') msgbits(1:101)
call encode174_101(msgbits,codeword)
call init_random_seed()
call sgran()
write(*,*) 'codeword'
write(*,'(77i1,1x,24i1,1x,73i1)') codeword
write(*,*) "Eb/N0 Es/N0 ngood nundetected sigma symbol error rate"
do idb = 8,-3,-1
db=idb/2.0-1.0
sigma=1/sqrt( 2*rate*(10**(db/10.0)) ) ! to make db represent Eb/No
! sigma=1/sqrt( 2*(10**(db/10.0)) ) ! db represents Es/No
ngood=0
nue=0
nberr=0
do itrial=1, ntrials
! Create a realization of a noisy received word
do i=1,N
rxdata(i) = 2.0*codeword(i)-1.0 + sigma*gran()
enddo
nerr=0
do i=1,N
if( rxdata(i)*(2*codeword(i)-1.0) .lt. 0 ) nerr=nerr+1
enddo
nberr=nberr+nerr
rxav=sum(rxdata)/N
rx2av=sum(rxdata*rxdata)/N
rxsig=sqrt(rx2av-rxav*rxav)
rxdata=rxdata/rxsig
if( s .lt. 0 ) then
ss=sigma
else
ss=s
endif
llr=2.0*rxdata/(ss*ss)
apmask=0
! max_iterations is max number of belief propagation iterations
call bpdecode174_101(llr,apmask,max_iterations,message,cw,nharderror,niterations)
dmin=0.0
if( (nharderror .lt. 0) .and. (ndeep .ge. 0) ) then
call osd174_101(llr, Keff, apmask, ndeep, message, cw, nharderror, dmin)
endif
if(nharderror.ge.0) then
n2err=0
do i=1,N
if( cw(i)*(2*codeword(i)-1.0) .lt. 0 ) n2err=n2err+1
enddo
if(n2err.eq.0) then
ngood=ngood+1
else
nue=nue+1
endif
endif
enddo
! snr2500=db+10*log10(200.0/116.0/2500.0)
esn0=db+10*log10(rate)
pberr=real(nberr)/(real(ntrials*N))
write(*,"(f4.1,4x,f5.1,1x,i8,1x,i8,8x,f5.2,8x,e10.3)") db,esn0,ngood,nue,ss,pberr
if(first) then
write(c77,'(77i1)') message
call unpack77(c77,0,msg,unpk77_success)
if(unpk77_success) then
write(*,1100) msg(1:37)
1100 format('Decoded message: ',a37)
else
print*,'Error unpacking message'
endif
first=.false.
endif
enddo
end program ldpcsim174_101

View File

@ -64,7 +64,7 @@ program ldpcsim174_74
write(*,*) 'message' write(*,*) 'message'
write(*,'(74i1)') msgbits write(*,'(74i1)') msgbits
call get_crc24(msgbits,ncrc24) call get_crc24(msgbits,74,ncrc24)
write(c24,'(b24.24)') ncrc24 write(c24,'(b24.24)') ncrc24
read(c24,'(24i1)') msgbits(51:74) read(c24,'(24i1)') msgbits(51:74)
call encode174_74(msgbits,codeword) call encode174_74(msgbits,codeword)

403
lib/fsk4hf/osd174_101.f90 Normal file
View File

@ -0,0 +1,403 @@
subroutine osd174_101(llr,k,apmask,ndeep,message101,cw,nhardmin,dmin)
!
! An ordered-statistics decoder for the (174,101) code.
! Message payload is 77 bits. Any or all of a 24-bit CRC can be
! used for detecting incorrect codewords. The remaining CRC bits are
! cascaded with the LDPC code for the purpose of improving the
! distance spectrum of the code.
!
! If p1 (0.le.p1.le.24) is the number of CRC24 bits that are
! to be used for bad codeword detection, then the argument k should
! be set to 77+p1.
!
! Valid values for k are in the range [77,101].
!
character*24 c24
integer, parameter:: N=174
integer*1 apmask(N),apmaskr(N)
integer*1, allocatable, save :: gen(:,:)
integer*1, allocatable :: genmrb(:,:),g2(:,:)
integer*1, allocatable :: temp(:),m0(:),me(:),mi(:),misub(:),e2sub(:),e2(:),ui(:)
integer*1, allocatable :: r2pat(:)
integer indices(N),nxor(N)
integer*1 cw(N),ce(N),c0(N),hdec(N)
integer*1, allocatable :: decoded(:)
integer*1 message77(77),message101(101)
integer indx(N)
real llr(N),rx(N),absrx(N)
logical first,reset
data first/.true./
save first
allocate( genmrb(k,N), g2(N,k) )
allocate( temp(k), m0(k), me(k), mi(k), misub(k), e2sub(N-k), e2(N-k), ui(N-k) )
allocate( r2pat(N-k), decoded(k) )
if( first ) then ! fill the generator matrix
!
! Create generator matrix for partial CRC cascaded with LDPC code.
!
! Let p2=101-k and p1+p2=24.
!
! The last p2 bits of the CRC24 are cascaded with the LDPC code.
!
! The first p1=k-77 CRC24 bits will be used for error detection.
!
allocate( gen(k,N) )
gen=0
do i=1,k
message101=0
message101(i)=1
if(i.le.77) then
call get_crc24(message101,101,ncrc24)
write(c24,'(b24.24)') ncrc24
read(c24,'(24i1)') message101(78:101)
message101(78:k)=0
endif
call encode174_101(message101,cw)
gen(i,:)=cw
enddo
first=.false.
endif
rx=llr
apmaskr=apmask
! Hard decisions on the received word.
hdec=0
where(rx .ge. 0) hdec=1
! Use magnitude of received symbols as a measure of reliability.
absrx=abs(rx)
call indexx(absrx,N,indx)
! Re-order the columns of the generator matrix in order of decreasing reliability.
do i=1,N
genmrb(1:k,i)=gen(1:k,indx(N+1-i))
indices(i)=indx(N+1-i)
enddo
! Do gaussian elimination to create a generator matrix with the most reliable
! received bits in positions 1:k in order of decreasing reliability (more or less).
do id=1,k ! diagonal element indices
do icol=id,k+20 ! The 20 is ad hoc - beware
iflag=0
if( genmrb(id,icol) .eq. 1 ) then
iflag=1
if( icol .ne. id ) then ! reorder column
temp(1:k)=genmrb(1:k,id)
genmrb(1:k,id)=genmrb(1:k,icol)
genmrb(1:k,icol)=temp(1:k)
itmp=indices(id)
indices(id)=indices(icol)
indices(icol)=itmp
endif
do ii=1,k
if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then
genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N))
endif
enddo
exit
endif
enddo
enddo
g2=transpose(genmrb)
! The hard decisions for the k MRB bits define the order 0 message, m0.
! Encode m0 using the modified generator matrix to find the "order 0" codeword.
! Flip various combinations of bits in m0 and re-encode to generate a list of
! codewords. Return the member of the list that has the smallest Euclidean
! distance to the received word.
hdec=hdec(indices) ! hard decisions from received symbols
m0=hdec(1:k) ! zero'th order message
absrx=absrx(indices)
rx=rx(indices)
apmaskr=apmaskr(indices)
call mrbencode101(m0,c0,g2,N,k)
nxor=ieor(c0,hdec)
nhardmin=sum(nxor)
dmin=sum(nxor*absrx)
cw=c0
ntotal=0
nrejected=0
npre1=0
npre2=0
if(ndeep.eq.0) goto 998 ! norder=0
if(ndeep.gt.6) ndeep=6
if( ndeep.eq. 1) then
nord=1
npre1=0
npre2=0
nt=40
ntheta=12
elseif(ndeep.eq.2) then
nord=1
npre1=1
npre2=0
nt=40
ntheta=12
elseif(ndeep.eq.3) then
nord=1
npre1=1
npre2=1
nt=40
ntheta=12
ntau=14
elseif(ndeep.eq.4) then
nord=2
npre1=1
npre2=1
nt=40
ntheta=12
ntau=19
elseif(ndeep.eq.5) then
nord=3
npre1=1
npre2=1
nt=40
ntheta=12
ntau=19
elseif(ndeep.eq.6) then
nord=4
npre1=1
npre2=1
nt=40
ntheta=12
ntau=19
endif
do iorder=1,nord
misub(1:k-iorder)=0
misub(k-iorder+1:k)=1
iflag=k-iorder+1
do while(iflag .ge.0)
if(iorder.eq.nord .and. npre1.eq.0) then
iend=iflag
else
iend=1
endif
d1=0.
do n1=iflag,iend,-1
mi=misub
mi(n1)=1
if(any(iand(apmaskr(1:k),mi).eq.1)) cycle
ntotal=ntotal+1
me=ieor(m0,mi)
if(n1.eq.iflag) then
call mrbencode101(me,ce,g2,N,k)
e2sub=ieor(ce(k+1:N),hdec(k+1:N))
e2=e2sub
nd1kpt=sum(e2sub(1:nt))+1
d1=sum(ieor(me(1:k),hdec(1:k))*absrx(1:k))
else
e2=ieor(e2sub,g2(k+1:N,n1))
nd1kpt=sum(e2(1:nt))+2
endif
if(nd1kpt .le. ntheta) then
call mrbencode101(me,ce,g2,N,k)
nxor=ieor(ce,hdec)
if(n1.eq.iflag) then
dd=d1+sum(e2sub*absrx(k+1:N))
else
dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(k+1:N))
endif
if( dd .lt. dmin ) then
dmin=dd
cw=ce
nhardmin=sum(nxor)
nd1kptbest=nd1kpt
endif
else
nrejected=nrejected+1
endif
enddo
! Get the next test error pattern, iflag will go negative
! when the last pattern with weight iorder has been generated.
call nextpat101(misub,k,iorder,iflag)
enddo
enddo
if(npre2.eq.1) then
reset=.true.
ntotal=0
do i1=k,1,-1
do i2=i1-1,1,-1
ntotal=ntotal+1
mi(1:ntau)=ieor(g2(k+1:k+ntau,i1),g2(k+1:k+ntau,i2))
call boxit101(reset,mi(1:ntau),ntau,ntotal,i1,i2)
enddo
enddo
ncount2=0
ntotal2=0
reset=.true.
! Now run through again and do the second pre-processing rule
misub(1:k-nord)=0
misub(k-nord+1:k)=1
iflag=k-nord+1
do while(iflag .ge.0)
me=ieor(m0,misub)
call mrbencode101(me,ce,g2,N,k)
e2sub=ieor(ce(k+1:N),hdec(k+1:N))
do i2=0,ntau
ntotal2=ntotal2+1
ui=0
if(i2.gt.0) ui(i2)=1
r2pat=ieor(e2sub,ui)
778 continue
call fetchit101(reset,r2pat(1:ntau),ntau,in1,in2)
if(in1.gt.0.and.in2.gt.0) then
ncount2=ncount2+1
mi=misub
mi(in1)=1
mi(in2)=1
if(sum(mi).lt.nord+npre1+npre2.or.any(iand(apmaskr(1:k),mi).eq.1)) cycle
me=ieor(m0,mi)
call mrbencode101(me,ce,g2,N,k)
nxor=ieor(ce,hdec)
dd=sum(nxor*absrx)
if( dd .lt. dmin ) then
dmin=dd
cw=ce
nhardmin=sum(nxor)
endif
goto 778
endif
enddo
call nextpat101(misub,k,nord,iflag)
enddo
endif
998 continue
! Re-order the codeword to [message bits][parity bits] format.
cw(indices)=cw
hdec(indices)=hdec
message101=cw(1:101)
call get_crc24(message101,101,nbadcrc)
if(nbadcrc.ne.0) nhardmin=-nhardmin
return
end subroutine osd174_101
subroutine mrbencode101(me,codeword,g2,N,K)
integer*1 me(K),codeword(N),g2(N,K)
! fast encoding for low-weight test patterns
codeword=0
do i=1,K
if( me(i) .eq. 1 ) then
codeword=ieor(codeword,g2(1:N,i))
endif
enddo
return
end subroutine mrbencode101
subroutine nextpat101(mi,k,iorder,iflag)
integer*1 mi(k),ms(k)
! generate the next test error pattern
ind=-1
do i=1,k-1
if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i
enddo
if( ind .lt. 0 ) then ! no more patterns of this order
iflag=ind
return
endif
ms=0
ms(1:ind-1)=mi(1:ind-1)
ms(ind)=1
ms(ind+1)=0
if( ind+1 .lt. k ) then
nz=iorder-sum(ms)
ms(k-nz+1:k)=1
endif
mi=ms
do i=1,k ! iflag will point to the lowest-index 1 in mi
if(mi(i).eq.1) then
iflag=i
exit
endif
enddo
return
end subroutine nextpat101
subroutine boxit101(reset,e2,ntau,npindex,i1,i2)
integer*1 e2(1:ntau)
integer indexes(5000,2),fp(0:525000),np(5000)
logical reset
common/boxes/indexes,fp,np
if(reset) then
patterns=-1
fp=-1
np=-1
sc=-1
indexes=-1
reset=.false.
endif
indexes(npindex,1)=i1
indexes(npindex,2)=i2
ipat=0
do i=1,ntau
if(e2(i).eq.1) then
ipat=ipat+ishft(1,ntau-i)
endif
enddo
ip=fp(ipat) ! see what's currently stored in fp(ipat)
if(ip.eq.-1) then
fp(ipat)=npindex
else
do while (np(ip).ne.-1)
ip=np(ip)
enddo
np(ip)=npindex
endif
return
end subroutine boxit101
subroutine fetchit101(reset,e2,ntau,i1,i2)
integer indexes(5000,2),fp(0:525000),np(5000)
integer lastpat
integer*1 e2(ntau)
logical reset
common/boxes/indexes,fp,np
save lastpat,inext
if(reset) then
lastpat=-1
reset=.false.
endif
ipat=0
do i=1,ntau
if(e2(i).eq.1) then
ipat=ipat+ishft(1,ntau-i)
endif
enddo
index=fp(ipat)
if(lastpat.ne.ipat .and. index.gt.0) then ! return first set of indices
i1=indexes(index,1)
i2=indexes(index,2)
inext=np(index)
elseif(lastpat.eq.ipat .and. inext.gt.0) then
i1=indexes(inext,1)
i2=indexes(inext,2)
inext=np(inext)
else
i1=-1
i2=-1
inext=-1
endif
lastpat=ipat
return
end subroutine fetchit101

View File

@ -52,7 +52,7 @@ subroutine osd174_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
message74=0 message74=0
message74(i)=1 message74(i)=1
if(i.le.50) then if(i.le.50) then
call get_crc24(message74,ncrc24) call get_crc24(message74,74,ncrc24)
write(c24,'(b24.24)') ncrc24 write(c24,'(b24.24)') ncrc24
read(c24,'(24i1)') message74(51:74) read(c24,'(24i1)') message74(51:74)
message74(51:k)=0 message74(51:k)=0
@ -282,7 +282,7 @@ subroutine osd174_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
cw(indices)=cw cw(indices)=cw
hdec(indices)=hdec hdec(indices)=hdec
message74=cw(1:74) message74=cw(1:74)
call get_crc24(message74,nbadcrc) call get_crc24(message74,74,nbadcrc)
if(nbadcrc.ne.0) nhardmin=-nhardmin if(nbadcrc.ne.0) nhardmin=-nhardmin
return return

View File

@ -58,9 +58,7 @@ program wspr4d
open(13,file=trim(data_dir)//'/ALL_WSPR.TXT',status='unknown', & open(13,file=trim(data_dir)//'/ALL_WSPR.TXT',status='unknown', &
position='append') position='append')
nav=0
ngood=0 ngood=0
ngood=0
do ifile=iarg,nargs do ifile=iarg,nargs
call getarg(ifile,infile) call getarg(ifile,infile)
open(10,file=infile,status='old',access='stream') open(10,file=infile,status='old',access='stream')
@ -89,14 +87,14 @@ ngood=0
call getcandidate4(c2,npts,fs,fa,fb,ncand,candidates) !First approx for freq call getcandidate4(c2,npts,fs,fa,fb,ncand,candidates) !First approx for freq
ndecodes=0 ndecodes=0
do icand=1,1 do icand=1,ncand
fc0=candidates(icand,1) fc0=candidates(icand,1)
xsnr=candidates(icand,2) xsnr=candidates(icand,2)
xmax=-1e32 xmax=-1e32
smax=0.0 smax=0.0
fc1=fc0-1.50*(fs/416.0) fc1=fc0-1.50*(fs/416.0)
do if=-20,20 do if=-20,20
df=if*0.02 df=if*0.04
fc=fc1+df fc=fc1+df
do is=300,450,5 do is=300,450,5
call coherent_sync(c2,is,fc,1,sync) call coherent_sync(c2,is,fc,1,sync)