WSJT-X/lib/77bit/unpack28.f90

73 lines
1.7 KiB
Fortran

subroutine unpack28(n28_0,c13)
parameter (NTOKENS=2063592,MAX22=4194304)
integer nc(6)
character*13 c13
character*37 c1
character*36 c2
character*10 c3
character*27 c4
data c1/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
data c2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
data c3/'0123456789'/
data c4/' ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
data nc/37,36,19,27,27,27/
n28=n28_0
if(n28.lt.NTOKENS) then
! Special tokens DE, QRZ, CQ, CQ_nnn, CQ_aaaa
if(n28.eq.0) c13='DE '
if(n28.eq.1) c13='QRZ '
if(n28.eq.2) c13='CQ '
if(n28.le.2) go to 900
if(n28.le.1002) then
write(c13,1002) n28-3
1002 format('CQ_',i3.3)
go to 900
endif
if(n28.le.532443) then
n=n28-1003
n0=n
i1=n/(27*27*27)
n=n-27*27*27*i1
i2=n/(27*27)
n=n-27*27*i2
i3=n/27
i4=n-27*i3
c13=c4(i1+1:i1+1)//c4(i2+1:i2+1)//c4(i3+1:i3+1)//c4(i4+1:i4+1)
c13=adjustl(c13)
c13='CQ_'//c13(1:10)
go to 900
endif
endif
n28=n28-NTOKENS
if(n28.lt.MAX22) then
! This is a 22-bit hash of a callsign
n22=n28
call hash22(n22,c13,-1) !Retrieve callsign from hash table
if(c13(1:1).ne.'<') then
n=len(trim(c13))
c13='<'//c13(1:n)//'>'//' '
endif
go to 900
endif
! Standard callsign
n=n28 - MAX22
i1=n/(36*10*27*27*27)
n=n-36*10*27*27*27*i1
i2=n/(10*27*27*27)
n=n-10*27*27*27*i2
i3=n/(27*27*27)
n=n-27*27*27*i3
i4=n/(27*27)
n=n-27*27*i4
i5=n/27
i6=n-27*i5
c13=c1(i1+1:i1+1)//c2(i2+1:i2+1)//c3(i3+1:i3+1)//c4(i4+1:i4+1)// &
c4(i5+1:i5+1)//c4(i6+1:i6+1)//' '
c13=adjustl(c13)
900 return
end subroutine unpack28