summaryrefslogtreecommitdiff
path: root/lib/fst4
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2026-10-09 14:12:35 +0200
committerChristoph Berg <myon@debian.org>2026-10-09 14:12:35 +0200
commitffc62c792c9a5196cb4ce7a353287dfe20db6524 (patch)
tree1269efa852935b183daae4bb33a58d1b4d2ffb53 /lib/fst4
parent059831534c7e884f0a607ed86b582fd00d821731 (diff)
New upstream version 3.3.0~beta1+dfsgupstream/3.3.0_beta1+dfsg
Diffstat (limited to 'lib/fst4')
-rw-r--r--lib/fst4/decode240_101.f9024
-rw-r--r--lib/fst4/decode240_74.f9024
-rw-r--r--lib/fst4/fastosd240_74.f90108
-rw-r--r--lib/fst4/fst4_baseline.f9018
-rw-r--r--lib/fst4/fst4_osd_workspace.f9040
-rw-r--r--lib/fst4/gen_fst4wave.f90128
-rw-r--r--lib/fst4/get_fst4_bitmetrics.f9087
-rw-r--r--lib/fst4/osd240_101.f90188
-rw-r--r--lib/fst4/osd240_74.f90188
9 files changed, 534 insertions, 271 deletions
diff --git a/lib/fst4/decode240_101.f90 b/lib/fst4/decode240_101.f90
index 4271a464..8e5ac504 100644
--- a/lib/fst4/decode240_101.f90
+++ b/lib/fst4/decode240_101.f90
@@ -1,4 +1,10 @@
-subroutine decode240_101(llr,Keff,maxosd,norder,apmask,message101,cw,ntype,nharderror,dmin)
+module fst4_ldpc_101
+ use fst4_osd_workspace, only: fst4_osd_workspace_type
+ use osd240_101_module, only: osd240_101_owned
+ private
+ public :: decode240_101_owned
+contains
+subroutine decode240_101_owned(work,llr,Keff,maxosd,norder,apmask,message101,cw,ntype,nharderror,dmin)
!
! A hybrid bp/osd decoder for the (240,101) code.
!
@@ -7,6 +13,7 @@ subroutine decode240_101(llr,Keff,maxosd,norder,apmask,message101,cw,ntype,nhard
! maxosd>1: do bp and then call osd maxosd times with saved bp outputs
! norder : osd decoding depth
!
+ type(fst4_osd_workspace_type), intent(inout), target :: work
integer, parameter:: N=240, K=101, M=N-K
integer*1 cw(N),apmask(N)
integer*1 nxor(N),hdec(N)
@@ -135,7 +142,7 @@ subroutine decode240_101(llr,Keff,maxosd,norder,apmask,message101,cw,ntype,nhard
do i=1,nosd
zn=zsave(:,i)
- call osd240_101(zn,Keff,apmask,norder,message101,cw,nharderror,dminosd)
+ call osd240_101_owned(work,zn,Keff,apmask,norder,message101,cw,nharderror,dminosd)
if(nharderror.gt.0) then
hdec=0
where(llr .ge. 0) hdec=1
@@ -152,4 +159,15 @@ subroutine decode240_101(llr,Keff,maxosd,norder,apmask,message101,cw,ntype,nhard
dminosd=0.0
return
-end subroutine decode240_101
+end subroutine decode240_101_owned
+
+end module fst4_ldpc_101
+
+subroutine decode240_101(llr,Keff,maxosd,norder,apmask,message101,cw,ntype,nharderror,dmin)
+ use fst4_ldpc_101, only: decode240_101_owned
+ use fst4_osd_workspace, only: fst4_osd_workspace_type
+ type(fst4_osd_workspace_type), save :: legacy
+ real llr(240),dmin
+ integer*1 apmask(240),message101(101),cw(240)
+ call decode240_101_owned(legacy,llr,Keff,maxosd,norder,apmask,message101,cw,ntype,nharderror,dmin)
+end subroutine
diff --git a/lib/fst4/decode240_74.f90 b/lib/fst4/decode240_74.f90
index f5aac2e1..a4bf3ea7 100644
--- a/lib/fst4/decode240_74.f90
+++ b/lib/fst4/decode240_74.f90
@@ -1,4 +1,10 @@
-subroutine decode240_74(llr,Keff,maxosd,norder,apmask,message74,cw,ntype,nharderror,dmin)
+module fst4_ldpc_74
+ use fst4_osd_workspace, only: fst4_osd_workspace_type
+ use fastosd240_74_module, only: fastosd240_74_owned
+ private
+ public :: decode240_74_owned
+contains
+subroutine decode240_74_owned(work,llr,Keff,maxosd,norder,apmask,message74,cw,ntype,nharderror,dmin)
!
! A hybrid bp/osd decoder for the (240,74) code.
!
@@ -7,6 +13,7 @@ subroutine decode240_74(llr,Keff,maxosd,norder,apmask,message74,cw,ntype,nharder
! maxosd>1: do bp and then call osd maxosd times with saved bp outputs
! norder : osd decoding depth
!
+ type(fst4_osd_workspace_type), intent(inout), target :: work
integer, parameter:: N=240, K=74, M=N-K
integer*1 cw(N),apmask(N)
integer*1 nxor(N),hdec(N)
@@ -141,7 +148,7 @@ subroutine decode240_74(llr,Keff,maxosd,norder,apmask,message74,cw,ntype,nharder
do i=1,nosd
zn=zsave(:,i)
! call osd240_74(zn,Keff,apmask,norder,message74,cw,nharderror,dminosd)
- call fastosd240_74(zn,Keff,apmask,norder,message74,cw,nharderror,dminosd)
+ call fastosd240_74_owned(work,zn,Keff,apmask,norder,message74,cw,nharderror,dminosd)
if(nharderror.gt.0) then
hdec=0
where(llr .ge. 0) hdec=1
@@ -158,4 +165,15 @@ subroutine decode240_74(llr,Keff,maxosd,norder,apmask,message74,cw,ntype,nharder
dminosd=0.0
return
-end subroutine decode240_74
+end subroutine decode240_74_owned
+
+end module fst4_ldpc_74
+
+subroutine decode240_74(llr,Keff,maxosd,norder,apmask,message74,cw,ntype,nharderror,dmin)
+ use fst4_ldpc_74, only: decode240_74_owned
+ use fst4_osd_workspace, only: fst4_osd_workspace_type
+ type(fst4_osd_workspace_type), save :: legacy
+ real llr(240),dmin
+ integer*1 apmask(240),message74(74),cw(240)
+ call decode240_74_owned(legacy,llr,Keff,maxosd,norder,apmask,message74,cw,ntype,nharderror,dmin)
+end subroutine
diff --git a/lib/fst4/fastosd240_74.f90 b/lib/fst4/fastosd240_74.f90
index 9af0f4e9..50843a0f 100644
--- a/lib/fst4/fastosd240_74.f90
+++ b/lib/fst4/fastosd240_74.f90
@@ -1,4 +1,9 @@
-subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
+module fastosd240_74_module
+ use fst4_osd_workspace, only: fst4_osd_workspace_type
+ private
+ public :: fastosd240_74_owned
+contains
+subroutine fastosd240_74_owned(work,llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
!
! An ordered-statistics decoder for the (240,74) code.
! Message payload is 50 bits. Any or all of a 24-bit CRC can be
@@ -12,29 +17,35 @@ subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
!
! Valid values for k are in the range [50,74].
!
+ type(fst4_osd_workspace_type), intent(inout), target :: work
+ integer :: iscratch,jscratch
character*24 c24
integer, parameter:: N=240
integer*1 apmask(N),apmaskr(N)
- integer*1, allocatable, save :: gen(:,:)
- integer*1, allocatable :: genmrb(:,:),g2(:,:)
- integer*1, allocatable :: temp(:),temprow(:),m0(:),me(:),mi(:)
+ integer*1, pointer, contiguous :: gen(:,:)
+ integer*1, pointer, contiguous :: genmrb(:,:),g2(:,:)
+ integer*1, pointer, contiguous :: temp(:),temprow(:),m0(:),me(:),mi(:)
integer indices(N),indices2(N),nxor(N)
integer*1 cw(N),ce(N),c0(N),hdec(N)
- integer*1, allocatable :: decoded(:)
+ integer*1, pointer, contiguous :: decoded(:)
integer*1 message74(74)
- integer*1, allocatable :: sp(:)
- integer indx(N),ksave
+ integer*1, pointer, contiguous :: sp(:)
+ integer indx(N)
real llr(N),rx(N),absrx(N)
- logical first
- data first/.true./,ksave/64/
- save first,ksave
- allocate( genmrb(k,N), g2(N,k) )
- allocate( temp(k), temprow(n), m0(k), me(k), mi(k) )
- allocate( decoded(k) )
- if( first .or. k.ne.ksave) then ! fill the generator matrix
+ call work%ensure()
+ genmrb(1:k,1:N)=>work%matrix(1:k*N)
+ g2(1:N,1:k)=>work%transpose_matrix(1:k*N)
+ temp=>work%vectors(1:k,1)
+ temprow=>work%vectors(1:N,2)
+ m0=>work%vectors(1:k,3)
+ me=>work%vectors(1:k,4)
+ mi=>work%vectors(1:k,5)
+ decoded=>work%vectors(1:k,6)
+ sp=>work%vectors(1:32,7)
+ if(.not.allocated(work%generator(k)%matrix)) then ! fill the generator matrix
!
! Create generator matrix for partial CRC cascaded with LDPC code.
!
@@ -44,8 +55,8 @@ subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
!
! The first p1=k-50 CRC24 bits will be used for error detection.
!
- if( allocated(gen) ) deallocate(gen)
- allocate( gen(k,N) )
+ allocate(work%generator(k)%matrix(k,N))
+ gen=>work%generator(k)%matrix
gen=0
do i=1,k
message74=0
@@ -60,10 +71,10 @@ subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
gen(i,:)=cw
enddo
- first=.false.
- ksave=k
endif
+ gen=>work%generator(k)%matrix
+
! Use best k elements from the sorted list for the first basis. For the 2nd basis replace
! the nswap lowest quality symbols with the best nswap elements from the parity symbols.
nswap=20
@@ -82,15 +93,19 @@ subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
! 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))
+ do jscratch=1,k
+ genmrb(jscratch,i)=gen(jscratch,indx(N+1-i))
+ enddo
indices(i)=indx(N+1-i)
enddo
if(ibasis.eq.2) then
do i=k-nswap+1,k
- temp(1:k)=genmrb(1:k,i)
- genmrb(1:k,i)=genmrb(1:k,i+nswap)
- genmrb(1:k,i+nswap)=temp(1:k)
+ do jscratch=1,k
+ temp(jscratch)=genmrb(jscratch,i)
+ genmrb(jscratch,i)=genmrb(jscratch,i+nswap)
+ genmrb(jscratch,i+nswap)=temp(jscratch)
+ enddo
itmp=indices(i)
indices(i)=indices(i+nswap)
indices(i+nswap)=itmp
@@ -109,9 +124,11 @@ subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
if(genmrb(id,icol).ne.1) then
do j=id+1,k
if(genmrb(j,icol).eq.1) then
- temprow=genmrb(id,:)
- genmrb(id,:)=genmrb(j,:)
- genmrb(j,:)=temprow
+ do jscratch=1,N
+ temprow(jscratch)=genmrb(id,jscratch)
+ genmrb(id,jscratch)=genmrb(j,jscratch)
+ genmrb(j,jscratch)=temprow(jscratch)
+ enddo
iflag=1
endif
enddo
@@ -127,7 +144,9 @@ subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
indices2(id)=icol
do j=1,k
if(id.ne.j .and. genmrb(j,icol).eq.1) then
- genmrb(j,:)=ieor(genmrb(id,:),genmrb(j,:))
+ do jscratch=1,N
+ genmrb(j,jscratch)=ieor(genmrb(id,jscratch),genmrb(j,jscratch))
+ enddo
endif
enddo
icol=icol+1
@@ -135,11 +154,22 @@ subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
do i=k+nskipped+1,240
indices2(i)=i
enddo
- genmrb(1:k,:)=genmrb(1:k,indices2)
+ do iscratch=1,k
+ do jscratch=1,N
+ temprow(jscratch)=genmrb(iscratch,jscratch)
+ enddo
+ do jscratch=1,N
+ genmrb(iscratch,jscratch)=temprow(indices2(jscratch))
+ enddo
+ enddo
indices=indices(indices2)
!************************************
- g2=transpose(genmrb)
+ do iscratch=1,k
+ do jscratch=1,N
+ g2(jscratch,iscratch)=genmrb(iscratch,jscratch)
+ enddo
+ enddo
! 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.
@@ -159,7 +189,6 @@ subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
nhardmin=sum(nxor)
dmin=sum(nxor*absrx)
np=32
- if(ibasis.eq.1) allocate(sp(np))
cw=c0
ntotal=0
@@ -202,7 +231,9 @@ subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
iflag=k-iorder+1
do while(iflag .ge.0)
ntotal=ntotal+1
- me=ieor(m0,mi)
+ do iscratch=1,k
+ me(iscratch)=ieor(m0(iscratch),mi(iscratch))
+ enddo
d1=sum(mi(1:k)*absrx(1:k))
if(d1.gt.rhodmin) exit
call partial_syndrome(me,sp,np,g2,N,K)
@@ -234,7 +265,7 @@ subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
nhardmin=-nhardmin
enddo ! basis loop
return
-end subroutine fastosd240_74
+end subroutine fastosd240_74_owned
subroutine mrbencode74(me,codeword,g2,N,K)
integer*1 me(K),codeword(N),g2(N,K)
@@ -261,7 +292,7 @@ subroutine partial_syndrome(me,sp,np,g2,N,K)
end subroutine partial_syndrome
subroutine nextpat74(mi,k,iorder,iflag)
- integer*1 mi(k),ms(k)
+ integer*1 mi(k),ms(101)
! generate the next test error pattern
ind=-1
do i=1,k-1
@@ -279,7 +310,7 @@ subroutine nextpat74(mi,k,iorder,iflag)
nz=iorder-sum(ms)
ms(k-nz+1:k)=1
endif
- mi=ms
+ mi=ms(1:k)
do i=1,k ! iflag will point to the lowest-index 1 in mi
if(mi(i).eq.1) then
iflag=i
@@ -289,3 +320,14 @@ subroutine nextpat74(mi,k,iorder,iflag)
return
end subroutine nextpat74
+
+end module fastosd240_74_module
+
+subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
+ use fastosd240_74_module, only: fastosd240_74_owned
+ use fst4_osd_workspace, only: fst4_osd_workspace_type
+ type(fst4_osd_workspace_type), save :: legacy
+ real llr(240),dmin
+ integer*1 apmask(240),message74(74),cw(240)
+ call fastosd240_74_owned(legacy,llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
+end subroutine
diff --git a/lib/fst4/fst4_baseline.f90 b/lib/fst4/fst4_baseline.f90
index 0000fa65..5c3ed1ed 100644
--- a/lib/fst4/fst4_baseline.f90
+++ b/lib/fst4/fst4_baseline.f90
@@ -1,11 +1,14 @@
-subroutine fst4_baseline(s,np,ia,ib,npct,sbase)
+module fst4_baseline_workspace
+contains
+subroutine fst4_baseline_owned(s,np,ia,ib,npct,sbase,sw)
! Fit baseline to spectrum (for FST4)
! Input: s(npts) Linear scale in power
! Output: sbase(npts) Baseline
implicit real*8 (a-h,o-z)
- real*4 s(np),sw(np)
+ real*4 s(np)
+ real*4 :: sw(np)
real*4 sbase(np)
real*4 base
real*8 x(1000),y(1000),a(5)
@@ -45,4 +48,13 @@ subroutine fst4_baseline(s,np,ia,ib,npct,sbase)
sbase=10**(sbase/10.0)
return
-end subroutine fst4_baseline
+end subroutine fst4_baseline_owned
+end module fst4_baseline_workspace
+
+subroutine fst4_baseline(s,np,ia,ib,npct,sbase)
+ use fst4_baseline_workspace, only: fst4_baseline_owned
+ real s(np),sbase(np)
+ real, allocatable :: scratch(:)
+ allocate(scratch(np))
+ call fst4_baseline_owned(s,np,ia,ib,npct,sbase,scratch)
+end subroutine
diff --git a/lib/fst4/fst4_osd_workspace.f90 b/lib/fst4/fst4_osd_workspace.f90
new file mode 100644
index 00000000..137fc05c
--- /dev/null
+++ b/lib/fst4/fst4_osd_workspace.f90
@@ -0,0 +1,40 @@
+module fst4_osd_workspace
+ implicit none
+ private
+ public :: fst4_osd_workspace_type
+ type generator_cache
+ integer(kind=1), allocatable :: matrix(:,:)
+ end type
+ type fst4_osd_workspace_type
+ type(generator_cache) :: generator(0:101)
+ integer(kind=1), allocatable :: matrix(:),transpose_matrix(:),vectors(:,:)
+ integer, allocatable :: box_indices(:,:),box_first(:),box_next(:)
+ integer :: last_pattern=-1,next_index=-1
+ contains
+ procedure :: ensure
+ procedure :: ensure_boxes
+ procedure :: destroy
+ end type
+contains
+ subroutine ensure(this)
+ class(fst4_osd_workspace_type), intent(inout) :: this
+ if(allocated(this%matrix)) return
+ allocate(this%matrix(240*101),this%transpose_matrix(240*101),this%vectors(240,12))
+ end subroutine
+ subroutine ensure_boxes(this)
+ class(fst4_osd_workspace_type), intent(inout) :: this
+ if(allocated(this%box_indices)) return
+ allocate(this%box_indices(5000,2),this%box_first(0:525000),this%box_next(5000))
+ end subroutine
+ subroutine destroy(this)
+ class(fst4_osd_workspace_type), intent(inout) :: this
+ integer i
+ do i=lbound(this%generator,1),ubound(this%generator,1)
+ if(allocated(this%generator(i)%matrix)) deallocate(this%generator(i)%matrix)
+ enddo
+ if(allocated(this%matrix)) deallocate(this%matrix,this%transpose_matrix,this%vectors)
+ if(allocated(this%box_indices)) deallocate(this%box_indices,this%box_first,this%box_next)
+ this%last_pattern=-1
+ this%next_index=-1
+ end subroutine
+end module
diff --git a/lib/fst4/gen_fst4wave.f90 b/lib/fst4/gen_fst4wave.f90
index 516bf722..5f55ca9b 100644
--- a/lib/fst4/gen_fst4wave.f90
+++ b/lib/fst4/gen_fst4wave.f90
@@ -1,95 +1,113 @@
-subroutine gen_fst4wave(itone,nsym,nsps,nwave,fsample,hmod,f0, &
+module fst4_wavegen
+ private
+ public :: fst4_wavegen_workspace,gen_fst4wave_owned
+ type fst4_wavegen_workspace
+ complex, allocatable :: ctab(:)
+ real, allocatable :: pulse(:),dphi(:),scaled_pulse(:)
+ integer :: nsps=0
+ real :: twopi=0,dt=0,tsym=0
+ logical :: first=.true.,shape=.true.
+ end type
+contains
+subroutine gen_fst4wave_owned(work,itone,nsym,nsps,nwave,fsample,hmod,f0, &
icmplx,cwave,wave)
- use prog_args
+ type(fst4_wavegen_workspace), intent(inout) :: work
parameter(NTAB=65536)
- real wave(nwave)
- complex cwave(nwave),ctab(0:NTAB-1)
+ real wave(*)
+ complex cwave(*)
character(len=1) :: cvalue
- real, allocatable, save :: pulse(:)
- real, allocatable :: dphi(:), scaled_pulse(:)
integer hmod
integer itone(nsym)
- logical first, lshape
- data first/.true./
- data nsps0/-99/
- data lshape/.true./
- save first,twopi,dt,tsym,nsps0,ctab,lshape
- if(first) then
- twopi=8.0*atan(1.0)
+ if(work%first) then
+ allocate(work%ctab(0:NTAB-1))
+ work%twopi=8.0*atan(1.0)
do i=0,NTAB-1
- phi=i*twopi/NTAB
- ctab(i)=cmplx(cos(phi),sin(phi))
+ phi=i*work%twopi/NTAB
+ work%ctab(i)=cmplx(cos(phi),sin(phi))
enddo
call get_environment_variable("FST4_NOSHAPING",cvalue,nlen)
- if(nlen.eq.1 .and. cvalue.eq."1") lshape=.false.
+ if(nlen.eq.1 .and. cvalue.eq."1") work%shape=.false.
endif
- if(first.or.nsps.ne.nsps0) then
- if(allocated(pulse)) deallocate(pulse)
- allocate(pulse(1:3*nsps))
- dt=1.0/fsample
- tsym=nsps/fsample
+ if(work%first.or.nsps.ne.work%nsps) then
+ if(allocated(work%pulse)) then
+ if(size(work%pulse)<3*nsps) deallocate(work%pulse,work%dphi,work%scaled_pulse)
+ endif
+ if(.not.allocated(work%pulse)) &
+ allocate(work%pulse(1:3*nsps),work%dphi(0:nsps-1),work%scaled_pulse(3*nsps))
+ work%dt=1.0/fsample
+ work%tsym=nsps/fsample
! Compute the smoothed frequency-deviation pulse
do i=1,3*nsps
tt=(i-1.5*nsps)/real(nsps)
- pulse(i)=gfsk_pulse(2.0,tt)
+ work%pulse(i)=gfsk_pulse(2.0,tt)
enddo
- first=.false.
- nsps0=nsps
+ work%first=.false.
+ work%nsps=nsps
endif
! Generate one symbol at a time, retaining phase across symbol boundaries.
- allocate(dphi(0:nsps-1))
- dphi_peak=twopi*hmod/real(nsps)
- allocate(scaled_pulse(3*nsps))
- scaled_pulse=dphi_peak*pulse
- carrier=twopi*(f0-1.5*hmod/tsym)*dt
+ dphi_peak=work%twopi*hmod/real(nsps)
+ work%scaled_pulse(1:3*nsps)=dphi_peak*work%pulse(1:3*nsps)
+ carrier=work%twopi*(f0-1.5*hmod/work%tsym)*work%dt
if(icmplx.eq.0) wave(nsym*nsps+1:nwave)=0.
if(icmplx.eq.1) cwave(nsym*nsps+1:nwave)=0.
phi=0.0
k=0
do iblock=1,nsym
- dphi=0.0
+ work%dphi(0:nsps-1)=0.0
! Accumulate overlapping pulses in tone order to preserve phase rounding.
do j=max(1,iblock-1),min(nsym,iblock+1)
ip=(iblock-j+1)*nsps+1
- dphi=dphi+scaled_pulse(ip:ip+nsps-1)*itone(j)
+ work%dphi(0:nsps-1)=work%dphi(0:nsps-1)+work%scaled_pulse(ip:ip+nsps-1)*itone(j)
enddo
- dphi=dphi+carrier
+ work%dphi(0:nsps-1)=work%dphi(0:nsps-1)+carrier
do j=0,nsps-1
k=k+1
- i=phi*float(NTAB)/twopi
+ i=phi*float(NTAB)/work%twopi
i=iand(i,NTAB-1)
if(icmplx.eq.0) then
- wave(k)=aimag(ctab(i))
+ wave(k)=aimag(work%ctab(i))
else
- cwave(k)=ctab(i)
+ cwave(k)=work%ctab(i)
endif
- phi=phi+dphi(j)
- if(phi.gt.twopi) phi=phi-twopi
+ phi=phi+work%dphi(j)
+ if(phi.gt.work%twopi) phi=phi-work%twopi
enddo
enddo
-! Compute the ramp-up and ramp-down symbols
- if(icmplx.eq.0) then
- if(lshape) then
- wave(1:nsps/4)=wave(1:nsps/4) * &
- (1.0-cos(twopi*(/(i,i=0,nsps/4-1)/)/real(nsps/2)))/2.0
- k1=(nsym-1)*nsps+3*nsps/4+1
- wave(k1:k1+nsps/4)=wave(k1:k1+nsps/4) * &
- (1.0+cos(twopi*(/(i,i=0,nsps/4)/)/real(nsps/2)))/2.0
- endif
- else
- if(lshape) then
- cwave(1:nsps/4)=cwave(1:nsps/4) * &
- (1.0-cos(twopi*(/(i,i=0,nsps/4-1)/)/real(nsps/2)))/2.0
- k1=(nsym-1)*nsps+3*nsps/4+1
- cwave(k1:k1+nsps/4)=cwave(k1:k1+nsps/4) * &
- (1.0+cos(twopi*(/(i,i=0,nsps/4)/)/real(nsps/2)))/2.0
- endif
+! Apply the symbol amplitude envelope.
+ if(work%shape) then
+ k1=(nsym-1)*nsps+3*nsps/4+1
+ do i=0,nsps/4-1
+ envelope=(1.0-cos(work%twopi*i/real(nsps/2)))/2.0
+ if(icmplx.eq.0) then
+ wave(i+1)=wave(i+1)*envelope
+ else
+ cwave(i+1)=cwave(i+1)*envelope
+ endif
+ enddo
+ do i=0,nsps/4
+ envelope=(1.0+cos(work%twopi*i/real(nsps/2)))/2.0
+ if(icmplx.eq.0) then
+ wave(k1+i)=wave(k1+i)*envelope
+ else
+ cwave(k1+i)=cwave(k1+i)*envelope
+ endif
+ enddo
endif
return
-end subroutine gen_fst4wave
+end subroutine gen_fst4wave_owned
+end module fst4_wavegen
+
+subroutine gen_fst4wave(itone,nsym,nsps,nwave,fsample,hmod,f0,icmplx,cwave,wave)
+ use fst4_wavegen, only: fst4_wavegen_workspace,gen_fst4wave_owned
+ type(fst4_wavegen_workspace), save :: legacy
+ integer itone(nsym),hmod
+ real wave(*),fsample,f0
+ complex cwave(*)
+ call gen_fst4wave_owned(legacy,itone,nsym,nsps,nwave,fsample,hmod,f0,icmplx,cwave,wave)
+end subroutine
diff --git a/lib/fst4/get_fst4_bitmetrics.f90 b/lib/fst4/get_fst4_bitmetrics.f90
index 762daa25..0d5be313 100644
--- a/lib/fst4/get_fst4_bitmetrics.f90
+++ b/lib/fst4/get_fst4_bitmetrics.f90
@@ -1,56 +1,63 @@
-subroutine get_fst4_bitmetrics(cd,nss,bitmetrics,s4,nsync_qual,badsync)
+module fst4_bitmetrics
+ implicit none
+ type fst4_bitmetrics_workspace
+ complex, allocatable :: ci(:,:)
+ logical, allocatable :: one(:,:),zero(:,:)
+ real, allocatable :: s2(:)
+ integer :: nss=0
+ end type
+contains
+subroutine get_fst4_bitmetrics_owned(work,cd,nss,bitmetrics,s4,nsync_qual,badsync)
use timer_module, only: timer
+ implicit real(a-h,o-z)
+ implicit integer(i-n)
include 'fst4_params.f90'
complex cd(0:NN*nss-1)
complex cs(0:3,NN)
- complex csymb(nss)
- complex, allocatable, save :: ci(:,:) ! ideal waveforms, 20 samples per symbol, 4 tones
+ type(fst4_bitmetrics_workspace), intent(inout), target :: work
complex c1(4,8),c2(16,4),c4(256,2)
integer isyncword1(0:7),isyncword2(0:7)
integer graymap(0:3)
integer ip(1)
integer hbits(2*NN)
- logical one(0:65535,0:15) ! 65536 8-symbol sequences, 16 bits
- logical first
logical badsync
real bitmetrics(2*NN,4)
- real, save :: s2(0:65535)
real s4(0:3,NN)
data isyncword1/0,1,3,2,1,0,2,3/
data isyncword2/2,3,1,0,3,2,0,1/
data graymap/0,1,3,2/
- data first/.true./,nss0/-1/
- save first,one,nss0
-
- if(nss.ne.nss0 .and. allocated(ci)) deallocate(ci)
-
- if(first .or. nss.ne.nss0) then
- allocate(ci(nss,0:3))
- one=.false.
+ if(.not.allocated(work%one)) then
+ allocate(work%one(0:65535,0:15),work%zero(0:65535,0:15),work%s2(0:65535))
do i=0,65535
do j=0,15
- if(iand(i,2**j).ne.0) one(i,j)=.true.
+ work%one(i,j)=btest(i,j)
+ work%zero(i,j)=.not.work%one(i,j)
enddo
enddo
+ endif
+ if(nss.ne.work%nss) then
+ if(allocated(work%ci)) then
+ if(size(work%ci,1)<nss) deallocate(work%ci)
+ endif
+ if(.not.allocated(work%ci)) allocate(work%ci(nss,0:3))
twopi=8.0*atan(1.0)
dphi=twopi/nss
do itone=0,3
dp=(itone-1.5)*dphi
phi=0.0
do j=1,nss
- ci(j,itone)=cmplx(cos(phi),sin(phi))
+ work%ci(j,itone)=cmplx(cos(phi),sin(phi))
phi=mod(phi+dp,twopi)
enddo
enddo
- first=.false.
+ work%nss=nss
endif
do k=1,NN
i1=(k-1)*NSS
- csymb=cd(i1:i1+NSS-1)
do itone=0,3
- cs(itone,k)=sum(csymb*conjg(ci(:,itone)))
+ cs(itone,k)=sum(cd(i1:i1+nss-1)*conjg(work%ci(1:nss,itone)))
enddo
s4(0:3,k)=abs(cs(0:3,k))**2
enddo
@@ -94,67 +101,64 @@ subroutine get_fst4_bitmetrics(cd,nss,bitmetrics,s4,nsync_qual,badsync)
do k=1,NN,8
do m=1,8 ! do 4 1-symbol correlations for each of 8 symbs
- s2=0
do n=1,4
c1(n,m)=cs(graymap(n-1),k+m-1)
- s2(n-1)=abs(c1(n,m))
+ work%s2(n-1)=abs(c1(n,m))
enddo
ipt=(k-1)*2+2*(m-1)+1
do ib=0,1
- bm=maxval(s2(0:3),one(0:3,1-ib)) - &
- maxval(s2(0:3),.not.one(0:3,1-ib))
+ bm=maxval(work%s2(0:3),work%one(0:3,1-ib)) - &
+ maxval(work%s2(0:3),work%zero(0:3,1-ib))
if(ipt+ib.gt.2*NN) cycle
bitmetrics(ipt+ib,1)=bm
enddo
enddo
do m=1,4 ! do 16 2-symbol correlations for each of 4 2-symbol groups
- s2=0
do i=1,4
do j=1,4
is=(i-1)*4+j
c2(is,m)=c1(i,2*m-1)-c1(j,2*m)
- s2(is-1)=abs(c2(is,m))
+ work%s2(is-1)=abs(c2(is,m))
enddo
enddo
ipt=(k-1)*2+4*(m-1)+1
do ib=0,3
- bm=maxval(s2(0:15),one(0:15,3-ib)) - &
- maxval(s2(0:15),.not.one(0:15,3-ib))
+ bm=maxval(work%s2(0:15),work%one(0:15,3-ib)) - &
+ maxval(work%s2(0:15),work%zero(0:15,3-ib))
if(ipt+ib.gt.2*NN) cycle
bitmetrics(ipt+ib,2)=bm
enddo
enddo
do m=1,2 ! do 256 4-symbol corrs for each of 2 4-symbol groups
- s2=0
do i=1,16
do j=1,16
is=(i-1)*16+j
c4(is,m)=c2(i,2*m-1)+c2(j,2*m)
- s2(is-1)=abs(c4(is,m))
+ work%s2(is-1)=abs(c4(is,m))
enddo
enddo
ipt=(k-1)*2+8*(m-1)+1
do ib=0,7
- bm=maxval(s2(0:255),one(0:255,7-ib)) - &
- maxval(s2(0:255),.not.one(0:255,7-ib))
+ bm=maxval(work%s2(0:255),work%one(0:255,7-ib)) - &
+ maxval(work%s2(0:255),work%zero(0:255,7-ib))
if(ipt+ib.gt.2*NN) cycle
bitmetrics(ipt+ib,3)=bm
enddo
enddo
- s2=0 ! do 65536 8-symbol correlations for the entire group
+ ! Combine the two four-symbol groups into eight-symbol correlations.
do i=1,256
do j=1,256
is=(i-1)*256+j
- s2(is-1)=abs(c4(i,1)+c4(j,2))
+ work%s2(is-1)=abs(c4(i,1)+c4(j,2))
enddo
enddo
ipt=(k-1)*2+1
do ib=0,15
- bm=maxval(s2(0:65535),one(0:65535,15-ib)) - &
- maxval(s2(0:65535),.not.one(0:65535,15-ib))
+ bm=maxval(work%s2(0:65535),work%one(0:65535,15-ib)) - &
+ maxval(work%s2(0:65535),work%zero(0:65535,15-ib))
if(ipt+ib.gt.2*NN) cycle
bitmetrics(ipt+ib,4)=bm
enddo
@@ -187,4 +191,15 @@ subroutine get_fst4_bitmetrics(cd,nss,bitmetrics,s4,nsync_qual,badsync)
return
-end subroutine get_fst4_bitmetrics
+end subroutine get_fst4_bitmetrics_owned
+
+end module fst4_bitmetrics
+
+subroutine get_fst4_bitmetrics(cd,nss,bitmetrics,s4,nsync_qual,badsync)
+ use fst4_bitmetrics
+ type(fst4_bitmetrics_workspace), save :: legacy
+ complex cd(0:160*nss-1)
+ real bitmetrics(320,4),s4(0:3,160)
+ logical badsync
+ call get_fst4_bitmetrics_owned(legacy,cd,nss,bitmetrics,s4,nsync_qual,badsync)
+end subroutine
diff --git a/lib/fst4/osd240_101.f90 b/lib/fst4/osd240_101.f90
index 199b27a8..7ca50fca 100644
--- a/lib/fst4/osd240_101.f90
+++ b/lib/fst4/osd240_101.f90
@@ -1,4 +1,9 @@
-subroutine osd240_101(llr,k,apmask,ndeep,message101,cw,nhardmin,dmin)
+module osd240_101_module
+ use fst4_osd_workspace, only: fst4_osd_workspace_type
+ private
+ public :: osd240_101_owned
+contains
+subroutine osd240_101_owned(work,llr,k,apmask,ndeep,message101,cw,nhardmin,dmin)
!
! An ordered-statistics decoder for the (240,101) code.
! Message payload is 77 bits. Any or all of a 24-bit CRC can be
@@ -12,29 +17,38 @@ subroutine osd240_101(llr,k,apmask,ndeep,message101,cw,nhardmin,dmin)
!
! Valid values for k are in the range [77,101].
!
+ type(fst4_osd_workspace_type), intent(inout), target :: work
+ integer :: iscratch,jscratch
character*24 c24
integer, parameter:: N=240
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*1, pointer, contiguous :: gen(:,:)
+ integer*1, pointer, contiguous :: genmrb(:,:),g2(:,:)
+ integer*1, pointer, contiguous :: temp(:),m0(:),me(:),mi(:),misub(:),e2sub(:),e2(:),ui(:)
+ integer*1, pointer, contiguous :: r2pat(:)
integer indices(N),nxor(N)
integer*1 cw(N),ce(N),c0(N),hdec(N)
- integer*1, allocatable :: decoded(:)
+ integer*1, pointer, contiguous :: decoded(:)
integer*1 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) )
+ logical reset
- if( first ) then ! fill the generator matrix
+ call work%ensure()
+ genmrb(1:k,1:N)=>work%matrix(1:k*N)
+ g2(1:N,1:k)=>work%transpose_matrix(1:k*N)
+ temp=>work%vectors(1:k,1)
+ m0=>work%vectors(1:k,2)
+ me=>work%vectors(1:k,3)
+ mi=>work%vectors(1:k,4)
+ misub=>work%vectors(1:k,5)
+ e2sub=>work%vectors(1:N-k,6)
+ e2=>work%vectors(1:N-k,7)
+ ui=>work%vectors(1:N-k,8)
+ r2pat=>work%vectors(1:N-k,9)
+ decoded=>work%vectors(1:k,10)
+ if(.not.allocated(work%generator(k)%matrix)) then ! fill the generator matrix
!
! Create generator matrix for partial CRC cascaded with LDPC code.
!
@@ -44,7 +58,8 @@ subroutine osd240_101(llr,k,apmask,ndeep,message101,cw,nhardmin,dmin)
!
! The first p1=k-77 CRC24 bits will be used for error detection.
!
- allocate( gen(k,N) )
+ allocate(work%generator(k)%matrix(k,N))
+ gen=>work%generator(k)%matrix
gen=0
do i=1,k
message101=0
@@ -59,9 +74,10 @@ subroutine osd240_101(llr,k,apmask,ndeep,message101,cw,nhardmin,dmin)
gen(i,:)=cw
enddo
- first=.false.
endif
+ gen=>work%generator(k)%matrix
+
rx=llr
apmaskr=apmask
@@ -75,7 +91,9 @@ subroutine osd240_101(llr,k,apmask,ndeep,message101,cw,nhardmin,dmin)
! 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))
+ do jscratch=1,k
+ genmrb(jscratch,i)=gen(jscratch,indx(N+1-i))
+ enddo
indices(i)=indx(N+1-i)
enddo
@@ -87,16 +105,20 @@ subroutine osd240_101(llr,k,apmask,ndeep,message101,cw,nhardmin,dmin)
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)
+ do jscratch=1,k
+ temp(jscratch)=genmrb(jscratch,id)
+ genmrb(jscratch,id)=genmrb(jscratch,icol)
+ genmrb(jscratch,icol)=temp(jscratch)
+ enddo
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))
+ do jscratch=1,N
+ genmrb(ii,jscratch)=ieor(genmrb(ii,jscratch),genmrb(id,jscratch))
+ enddo
endif
enddo
exit
@@ -104,7 +126,11 @@ subroutine osd240_101(llr,k,apmask,ndeep,message101,cw,nhardmin,dmin)
enddo
enddo
- g2=transpose(genmrb)
+ do iscratch=1,k
+ do jscratch=1,N
+ g2(jscratch,iscratch)=genmrb(iscratch,jscratch)
+ enddo
+ enddo
! 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.
@@ -187,19 +213,27 @@ subroutine osd240_101(llr,k,apmask,ndeep,message101,cw,nhardmin,dmin)
endif
d1=0.
do n1=iflag,iend,-1
- mi=misub
+ do iscratch=1,k
+ mi(iscratch)=misub(iscratch)
+ enddo
mi(n1)=1
if(any(iand(apmaskr(1:k),mi).eq.1)) cycle
ntotal=ntotal+1
- me=ieor(m0,mi)
+ do iscratch=1,k
+ me(iscratch)=ieor(m0(iscratch),mi(iscratch))
+ enddo
if(n1.eq.iflag) then
call mrbencode101(me,ce,g2,N,k)
e2sub=ieor(ce(k+1:N),hdec(k+1:N))
- e2=e2sub
+ do iscratch=1,N-k
+ e2(iscratch)=e2sub(iscratch)
+ enddo
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))
+ do iscratch=1,N-k
+ e2(iscratch)=ieor(e2sub(iscratch),g2(k+iscratch,n1))
+ enddo
nd1kpt=sum(e2(1:nt))+2
endif
if(nd1kpt .le. ntheta) then
@@ -232,8 +266,10 @@ subroutine osd240_101(llr,k,apmask,ndeep,message101,cw,nhardmin,dmin)
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)
+ do iscratch=1,ntau
+ mi(iscratch)=ieor(g2(k+iscratch,i1),g2(k+iscratch,i2))
+ enddo
+ call boxit101(work,reset,mi(1:ntau),ntau,ntotal,i1,i2)
enddo
enddo
@@ -245,23 +281,31 @@ subroutine osd240_101(llr,k,apmask,ndeep,message101,cw,nhardmin,dmin)
misub(k-nord+1:k)=1
iflag=k-nord+1
do while(iflag .ge.0)
- me=ieor(m0,misub)
+ do iscratch=1,k
+ me(iscratch)=ieor(m0(iscratch),misub(iscratch))
+ enddo
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)
+ do iscratch=1,N-k
+ r2pat(iscratch)=ieor(e2sub(iscratch),ui(iscratch))
+ enddo
778 continue
- call fetchit101(reset,r2pat(1:ntau),ntau,in1,in2)
+ call fetchit101(work,reset,r2pat(1:ntau),ntau,in1,in2)
if(in1.gt.0.and.in2.gt.0) then
ncount2=ncount2+1
- mi=misub
+ do iscratch=1,k
+ mi(iscratch)=misub(iscratch)
+ enddo
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)
+ do iscratch=1,k
+ me(iscratch)=ieor(m0(iscratch),mi(iscratch))
+ enddo
call mrbencode101(me,ce,g2,N,k)
nxor=ieor(ce,hdec)
dd=sum(nxor*absrx)
@@ -286,7 +330,7 @@ subroutine osd240_101(llr,k,apmask,ndeep,message101,cw,nhardmin,dmin)
if(nbadcrc.ne.0) nhardmin=-nhardmin
return
-end subroutine osd240_101
+end subroutine osd240_101_owned
subroutine mrbencode101(me,codeword,g2,N,K)
integer*1 me(K),codeword(N),g2(N,K)
@@ -301,7 +345,7 @@ subroutine mrbencode101(me,codeword,g2,N,K)
end subroutine mrbencode101
subroutine nextpat101(mi,k,iorder,iflag)
- integer*1 mi(k),ms(k)
+ integer*1 mi(k),ms(101)
! generate the next test error pattern
ind=-1
do i=1,k-1
@@ -319,7 +363,7 @@ subroutine nextpat101(mi,k,iorder,iflag)
nz=iorder-sum(ms)
ms(k-nz+1:k)=1
endif
- mi=ms
+ mi=ms(1:k)
do i=1,k ! iflag will point to the lowest-index 1 in mi
if(mi(i).eq.1) then
iflag=i
@@ -329,23 +373,21 @@ subroutine nextpat101(mi,k,iorder,iflag)
return
end subroutine nextpat101
-subroutine boxit101(reset,e2,ntau,npindex,i1,i2)
+subroutine boxit101(work,reset,e2,ntau,npindex,i1,i2)
+ type(fst4_osd_workspace_type), intent(inout) :: work
integer*1 e2(1:ntau)
- integer indexes(5000,2),fp(0:525000),np(5000)
logical reset
- common/boxes/indexes,fp,np
+ call work%ensure_boxes()
if(reset) then
- patterns=-1
- fp=-1
- np=-1
- sc=-1
- indexes=-1
+ work%box_first=-1
+ work%box_next=-1
+ work%box_indices=-1
reset=.false.
endif
- indexes(npindex,1)=i1
- indexes(npindex,2)=i2
+ work%box_indices(npindex,1)=i1
+ work%box_indices(npindex,2)=i2
ipat=0
do i=1,ntau
if(e2(i).eq.1) then
@@ -353,28 +395,25 @@ subroutine boxit101(reset,e2,ntau,npindex,i1,i2)
endif
enddo
- ip=fp(ipat) ! see what's currently stored in fp(ipat)
+ ip=work%box_first(ipat) ! see what's currently stored in work%box_first(ipat)
if(ip.eq.-1) then
- fp(ipat)=npindex
+ work%box_first(ipat)=npindex
else
- do while (np(ip).ne.-1)
- ip=np(ip)
+ do while (work%box_next(ip).ne.-1)
+ ip=work%box_next(ip)
enddo
- np(ip)=npindex
+ work%box_next(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
+subroutine fetchit101(work,reset,e2,ntau,i1,i2)
+ type(fst4_osd_workspace_type), intent(inout) :: work
integer*1 e2(ntau)
logical reset
- common/boxes/indexes,fp,np
- save lastpat,inext
if(reset) then
- lastpat=-1
+ work%last_pattern=-1
reset=.false.
endif
@@ -384,21 +423,32 @@ subroutine fetchit101(reset,e2,ntau,i1,i2)
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)
+ index=work%box_first(ipat)
+
+ if(work%last_pattern.ne.ipat .and. index.gt.0) then ! return first set of indices
+ i1=work%box_indices(index,1)
+ i2=work%box_indices(index,2)
+ work%next_index=work%box_next(index)
+ elseif(work%last_pattern.eq.ipat .and. work%next_index.gt.0) then
+ i1=work%box_indices(work%next_index,1)
+ i2=work%box_indices(work%next_index,2)
+ work%next_index=work%box_next(work%next_index)
else
i1=-1
i2=-1
- inext=-1
+ work%next_index=-1
endif
- lastpat=ipat
+ work%last_pattern=ipat
return
end subroutine fetchit101
+
+end module osd240_101_module
+
+subroutine osd240_101(llr,k,apmask,ndeep,message101,cw,nhardmin,dmin)
+ use osd240_101_module, only: osd240_101_owned
+ use fst4_osd_workspace, only: fst4_osd_workspace_type
+ type(fst4_osd_workspace_type), save :: legacy
+ real llr(240),dmin
+ integer*1 apmask(240),message101(101),cw(240)
+ call osd240_101_owned(legacy,llr,k,apmask,ndeep,message101,cw,nhardmin,dmin)
+end subroutine
diff --git a/lib/fst4/osd240_74.f90 b/lib/fst4/osd240_74.f90
index 74cb1a0e..4c4817da 100644
--- a/lib/fst4/osd240_74.f90
+++ b/lib/fst4/osd240_74.f90
@@ -1,4 +1,9 @@
-subroutine osd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
+module osd240_74_module
+ use fst4_osd_workspace, only: fst4_osd_workspace_type
+ private
+ public :: osd240_74_owned
+contains
+subroutine osd240_74_owned(work,llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
!
! An ordered-statistics decoder for the (240,74) code.
! Message payload is 50 bits. Any or all of a 24-bit CRC can be
@@ -12,29 +17,38 @@ subroutine osd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
!
! Valid values for k are in the range [50,74].
!
+ type(fst4_osd_workspace_type), intent(inout), target :: work
+ integer :: iscratch,jscratch
character*24 c24
integer, parameter:: N=240
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*1, pointer, contiguous :: gen(:,:)
+ integer*1, pointer, contiguous :: genmrb(:,:),g2(:,:)
+ integer*1, pointer, contiguous :: temp(:),m0(:),me(:),mi(:),misub(:),e2sub(:),e2(:),ui(:)
+ integer*1, pointer, contiguous :: r2pat(:)
integer indices(N),nxor(N)
integer*1 cw(N),ce(N),c0(N),hdec(N)
- integer*1, allocatable :: decoded(:)
+ integer*1, pointer, contiguous :: decoded(:)
integer*1 message74(74)
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) )
+ logical reset
- if( first ) then ! fill the generator matrix
+ call work%ensure()
+ genmrb(1:k,1:N)=>work%matrix(1:k*N)
+ g2(1:N,1:k)=>work%transpose_matrix(1:k*N)
+ temp=>work%vectors(1:k,1)
+ m0=>work%vectors(1:k,2)
+ me=>work%vectors(1:k,3)
+ mi=>work%vectors(1:k,4)
+ misub=>work%vectors(1:k,5)
+ e2sub=>work%vectors(1:N-k,6)
+ e2=>work%vectors(1:N-k,7)
+ ui=>work%vectors(1:N-k,8)
+ r2pat=>work%vectors(1:N-k,9)
+ decoded=>work%vectors(1:k,10)
+ if(.not.allocated(work%generator(k)%matrix)) then ! fill the generator matrix
!
! Create generator matrix for partial CRC cascaded with LDPC code.
!
@@ -44,7 +58,8 @@ subroutine osd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
!
! The first p1=k-50 CRC24 bits will be used for error detection.
!
- allocate( gen(k,N) )
+ allocate(work%generator(k)%matrix(k,N))
+ gen=>work%generator(k)%matrix
gen=0
do i=1,k
message74=0
@@ -59,9 +74,10 @@ subroutine osd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
gen(i,:)=cw
enddo
- first=.false.
endif
+ gen=>work%generator(k)%matrix
+
rx=llr
apmaskr=apmask
@@ -75,7 +91,9 @@ subroutine osd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
! 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))
+ do jscratch=1,k
+ genmrb(jscratch,i)=gen(jscratch,indx(N+1-i))
+ enddo
indices(i)=indx(N+1-i)
enddo
@@ -87,16 +105,20 @@ subroutine osd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
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)
+ do jscratch=1,k
+ temp(jscratch)=genmrb(jscratch,id)
+ genmrb(jscratch,id)=genmrb(jscratch,icol)
+ genmrb(jscratch,icol)=temp(jscratch)
+ enddo
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))
+ do jscratch=1,N
+ genmrb(ii,jscratch)=ieor(genmrb(ii,jscratch),genmrb(id,jscratch))
+ enddo
endif
enddo
exit
@@ -104,7 +126,11 @@ subroutine osd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
enddo
enddo
- g2=transpose(genmrb)
+ do iscratch=1,k
+ do jscratch=1,N
+ g2(jscratch,iscratch)=genmrb(iscratch,jscratch)
+ enddo
+ enddo
! 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.
@@ -187,19 +213,27 @@ subroutine osd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
endif
d1=0.
do n1=iflag,iend,-1
- mi=misub
+ do iscratch=1,k
+ mi(iscratch)=misub(iscratch)
+ enddo
mi(n1)=1
if(any(iand(apmaskr(1:k),mi).eq.1)) cycle
ntotal=ntotal+1
- me=ieor(m0,mi)
+ do iscratch=1,k
+ me(iscratch)=ieor(m0(iscratch),mi(iscratch))
+ enddo
if(n1.eq.iflag) then
call mrbencode74(me,ce,g2,N,k)
e2sub=ieor(ce(k+1:N),hdec(k+1:N))
- e2=e2sub
+ do iscratch=1,N-k
+ e2(iscratch)=e2sub(iscratch)
+ enddo
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))
+ do iscratch=1,N-k
+ e2(iscratch)=ieor(e2sub(iscratch),g2(k+iscratch,n1))
+ enddo
nd1kpt=sum(e2(1:nt))+2
endif
if(nd1kpt .le. ntheta) then
@@ -232,8 +266,10 @@ subroutine osd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
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 boxit74(reset,mi(1:ntau),ntau,ntotal,i1,i2)
+ do iscratch=1,ntau
+ mi(iscratch)=ieor(g2(k+iscratch,i1),g2(k+iscratch,i2))
+ enddo
+ call boxit74(work,reset,mi(1:ntau),ntau,ntotal,i1,i2)
enddo
enddo
@@ -245,23 +281,31 @@ subroutine osd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
misub(k-nord+1:k)=1
iflag=k-nord+1
do while(iflag .ge.0)
- me=ieor(m0,misub)
+ do iscratch=1,k
+ me(iscratch)=ieor(m0(iscratch),misub(iscratch))
+ enddo
call mrbencode74(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)
+ do iscratch=1,N-k
+ r2pat(iscratch)=ieor(e2sub(iscratch),ui(iscratch))
+ enddo
778 continue
- call fetchit74(reset,r2pat(1:ntau),ntau,in1,in2)
+ call fetchit74(work,reset,r2pat(1:ntau),ntau,in1,in2)
if(in1.gt.0.and.in2.gt.0) then
ncount2=ncount2+1
- mi=misub
+ do iscratch=1,k
+ mi(iscratch)=misub(iscratch)
+ enddo
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)
+ do iscratch=1,k
+ me(iscratch)=ieor(m0(iscratch),mi(iscratch))
+ enddo
call mrbencode74(me,ce,g2,N,k)
nxor=ieor(ce,hdec)
dd=sum(nxor*absrx)
@@ -286,7 +330,7 @@ subroutine osd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
if(nbadcrc.ne.0) nhardmin=-nhardmin
return
-end subroutine osd240_74
+end subroutine osd240_74_owned
subroutine mrbencode74(me,codeword,g2,N,K)
integer*1 me(K),codeword(N),g2(N,K)
@@ -301,7 +345,7 @@ subroutine mrbencode74(me,codeword,g2,N,K)
end subroutine mrbencode74
subroutine nextpat74(mi,k,iorder,iflag)
- integer*1 mi(k),ms(k)
+ integer*1 mi(k),ms(101)
! generate the next test error pattern
ind=-1
do i=1,k-1
@@ -319,7 +363,7 @@ subroutine nextpat74(mi,k,iorder,iflag)
nz=iorder-sum(ms)
ms(k-nz+1:k)=1
endif
- mi=ms
+ mi=ms(1:k)
do i=1,k ! iflag will point to the lowest-index 1 in mi
if(mi(i).eq.1) then
iflag=i
@@ -329,23 +373,21 @@ subroutine nextpat74(mi,k,iorder,iflag)
return
end subroutine nextpat74
-subroutine boxit74(reset,e2,ntau,npindex,i1,i2)
+subroutine boxit74(work,reset,e2,ntau,npindex,i1,i2)
+ type(fst4_osd_workspace_type), intent(inout) :: work
integer*1 e2(1:ntau)
- integer indexes(5000,2),fp(0:525000),np(5000)
logical reset
- common/boxes/indexes,fp,np
+ call work%ensure_boxes()
if(reset) then
- patterns=-1
- fp=-1
- np=-1
- sc=-1
- indexes=-1
+ work%box_first=-1
+ work%box_next=-1
+ work%box_indices=-1
reset=.false.
endif
- indexes(npindex,1)=i1
- indexes(npindex,2)=i2
+ work%box_indices(npindex,1)=i1
+ work%box_indices(npindex,2)=i2
ipat=0
do i=1,ntau
if(e2(i).eq.1) then
@@ -353,28 +395,25 @@ subroutine boxit74(reset,e2,ntau,npindex,i1,i2)
endif
enddo
- ip=fp(ipat) ! see what's currently stored in fp(ipat)
+ ip=work%box_first(ipat) ! see what's currently stored in work%box_first(ipat)
if(ip.eq.-1) then
- fp(ipat)=npindex
+ work%box_first(ipat)=npindex
else
- do while (np(ip).ne.-1)
- ip=np(ip)
+ do while (work%box_next(ip).ne.-1)
+ ip=work%box_next(ip)
enddo
- np(ip)=npindex
+ work%box_next(ip)=npindex
endif
return
end subroutine boxit74
-subroutine fetchit74(reset,e2,ntau,i1,i2)
- integer indexes(5000,2),fp(0:525000),np(5000)
- integer lastpat
+subroutine fetchit74(work,reset,e2,ntau,i1,i2)
+ type(fst4_osd_workspace_type), intent(inout) :: work
integer*1 e2(ntau)
logical reset
- common/boxes/indexes,fp,np
- save lastpat,inext
if(reset) then
- lastpat=-1
+ work%last_pattern=-1
reset=.false.
endif
@@ -384,21 +423,32 @@ subroutine fetchit74(reset,e2,ntau,i1,i2)
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)
+ index=work%box_first(ipat)
+
+ if(work%last_pattern.ne.ipat .and. index.gt.0) then ! return first set of indices
+ i1=work%box_indices(index,1)
+ i2=work%box_indices(index,2)
+ work%next_index=work%box_next(index)
+ elseif(work%last_pattern.eq.ipat .and. work%next_index.gt.0) then
+ i1=work%box_indices(work%next_index,1)
+ i2=work%box_indices(work%next_index,2)
+ work%next_index=work%box_next(work%next_index)
else
i1=-1
i2=-1
- inext=-1
+ work%next_index=-1
endif
- lastpat=ipat
+ work%last_pattern=ipat
return
end subroutine fetchit74
+
+end module osd240_74_module
+
+subroutine osd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
+ use osd240_74_module, only: osd240_74_owned
+ use fst4_osd_workspace, only: fst4_osd_workspace_type
+ type(fst4_osd_workspace_type), save :: legacy
+ real llr(240),dmin
+ integer*1 apmask(240),message74(74),cw(240)
+ call osd240_74_owned(legacy,llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
+end subroutine